SceneRenderer
Renders the full MC3 scene into the 3D viewport using CNA's BasicEffect.
Header
include/MeshCraft/Renderer/SceneRenderer.hpp
Source
src/MeshCraft/Renderer/SceneRenderer.cpp
Namespace
MeshCraft::Renderer
Public API
| Method | Description |
|---|---|
SceneRenderer(GraphicsDevice&) |
Constructor. Builds all pre-computed unit meshes (box, sphere, cylinder, cone, plane) and wire shapes. Must be called after the GL context is ready. |
draw(doc, view, proj, selected) |
Renders the complete scene. Traverses doc.objects recursively. Also draws light/camera/CSG gizmos. |
clearCsgCache() |
Clears the cached Manifold CSG meshes. Must be called after any document mutation (done automatically in pushUndo()). |
setAnimOverrides(overrides) |
Injects per-object animation overrides. Called each frame before draw() when an animation is playing. |
drawGizmo(obj, view, proj, length) |
Draws the Move gizmo (axis arrows + cube tips) for the given object. |
drawScaleGizmo(obj, view, proj, length) |
Draws the Scale gizmo (axis lines + flat-square tips). |
drawRotateGizmo(obj, view, proj, length) |
Draws the Rotate gizmo (arc circles in XYZ planes). |
drawObjectWireframe(obj, view, proj, color) |
Draws a wireframe bounding box around an object in the given color. |
drawLightGizmos(lights, view, proj) |
Draws representative icons for each light in the scene. |
drawCameraGizmos(cameras, view, proj) |
Draws camera frustum icons. |
drawCsgGizmos(doc, view, proj) |
Draws per-CSG-node colored overlays. |
drawEdgeOverlay(doc, view, proj) |
Draws black wireframe lines over all visible objects (Alt+W toggle). |
Private Helper Methods
| Method | Description |
|---|---|
drawObject(obj, doc, parentWorld, …) | Recursive per-object render. Dispatches by ObjectType. |
drawMesh(mesh, world, view, proj, color) | Renders a RenderMesh with flat color using BasicEffect. |
drawMeshTextured(mesh, world, view, proj, color, tex) | Renders with a texture using BasicEffect in texture+lit mode. |
loadOrGetTexture(absPath) | Lazy-loads and caches a Texture2D from an absolute path. |
loadOrGetMesh(absPath) | Lazy-loads and caches an OBJ file via tinyobjloader. |
objectWorldMatrix(transform) | Builds the local world matrix using the pivot-compensated formula. |
materialColor(matId, doc) | Looks up the baseColor from the document's material map. Returns a default grey if not found. |
isSelected(obj, sel) | Returns true if the object pointer appears in the selection vector. |
Caches
map<string, Texture2D> textureCache_; // keyed by abs path
map<string, RenderMesh> meshCache_; // keyed by abs path (OBJ)
map<const Mc3Object*, RenderMesh> csgMeshCache_; // keyed by object pointer
unordered_map<string, AnimOverride> animOverrides_; // keyed by object name
The CSG cache (csgMeshCache_) is cleared on every pushUndo() call to ensure CSG geometry is re-evaluated after any edit. Texture and mesh caches are never cleared during a session.