Editor Module
Camera control, object selection, and transform gizmo — the 3D viewport interaction layer.
Components
| Class | File | Role |
|---|---|---|
EditorCamera | include/MeshCraft/Editor/EditorCamera.hpp | Orbit / pan / zoom / focus camera model. Produces view + projection matrices. |
SelectionManager | include/MeshCraft/Editor/SelectionManager.hpp | Tracks the set of selected shared_ptr<Mc3Object>. Supports single and multi-select. |
TransformGizmo | include/MeshCraft/Editor/TransformGizmo.hpp | Holds the active gizmo mode (Move/Scale/Rotate) and per-axis drag state. |
EditorTool | include/MeshCraft/Editor/EditorTool.hpp | Tool state helpers (currently minimal). |
EditorViewport | include/MeshCraft/Editor/EditorViewport.hpp | Viewport rect calculation helpers. |
EditorCamera
Uses a spherical orbit model: yaw (horizontal), pitch (vertical, clamped to ±85°), and distance from a target point.
Key Methods
| Method | Description |
|---|---|
orbit(deltaYaw, deltaPitch) | Rotate around the target. Called on middle-mouse drag. |
pan(deltaX, deltaY) | Translate the target point in camera space. Called on right-mouse drag. |
zoom(delta) | Change the distance to target. Clamped to [0.5, 2000]. Called on scroll wheel. |
focusOn(x, y, z, radius) | Move the target to a world position and adjust distance to fit. Called on F key. |
reset() | Reset to default yaw=0, pitch=0.4, distance=15. |
viewMatrix() | Returns the view matrix from the orbit model. |
projectionMatrix(aspectRatio) | Returns a perspective projection (60° FOV, near=0.1, far=2000). |
screenRayDirection(ndcX, ndcY, aspect) | Unprojects a screen NDC coordinate to a world-space ray direction. Used for AABB picking. |
Object Picking
Ray-cast picking is implemented in MeshCraftApplication::handleMouseInput():
- On left-click in the 3D viewport, compute an NDC coordinate from the mouse position.
- Call
EditorCamera::screenRayDirection(ndcX, ndcY, aspectRatio)to get a world-space ray. - Recursively test each object's axis-aligned bounding box (AABB) — including nested children in groups, CSG nodes, and instances.
- Select the closest hit object. Ctrl+click toggles it in the selection set.
Selection
SelectionManager holds a std::set<std::shared_ptr<Mc3Object>>.
- Single select: left-click clears selection, then adds the picked object.
- Multi-select: Ctrl+click toggles the picked object.
- Select all: Ctrl+A selects all root objects (or all children if a single group is selected).
- Box select: right-drag in the viewport draws a rectangle; on release, all objects whose AABB projects inside are added to the selection.
Transform Gizmo
Three modes, activated by keyboard shortcuts:
| Mode | Key | Visual | Drag effect |
|---|---|---|---|
| Move | G | Colored axis arrows with cube tips | Translates position along the dragged axis |
| Scale | S | Colored axis lines with flat-square tips | Scales the object along the dragged axis |
| Rotate | R | Colored arcs in the three planes | Rotates the object around the dragged axis |
For multi-selection, the gizmo applies the delta to all selected objects simultaneously.
Arrow key nudge (0.1 step with Shift, 1.0 without) applies to the active tool. PageUp/PageDown nudge along the Z axis.