MeshCraftApplication
Central application class. Inherits from CNA's Microsoft::Xna::Framework::Game.
Header
include/MeshCraft/MeshCraftApplication.hpp
Source
src/MeshCraft/MeshCraftApplication.cpp
Namespace
MeshCraft
Purpose
MeshCraftApplication is the single owner of all editor state. It is the class that CNA's Game base calls in the game loop. Every editor operation — file I/O, selection, transformation, undo/redo, animation playback, export — is orchestrated here.
Constructors
| Signature | Usage |
|---|---|
MeshCraftApplication() | Starts with an empty scene. Used when no command-line path is given. |
MeshCraftApplication(filesystem::path filePath) | Loads the given .mc3.xml file on startup. |
MeshCraftApplication(filesystem::path filePath, string screenshotPath) | Loads file and enables auto-screenshot mode (exits after ~2 s, writes PPM). |
Game Loop Overrides
| Method | Behaviour |
|---|---|
LoadContent() | Creates GridRenderer, SceneRenderer, SceneHierarchyPanel, PropertiesPanel. Loads scene from currentFile_ if set. Initialises ImGui (SDL3 + OpenGL ES 3 backends). Loads recent-files list. |
BeginDraw() | Calls ImGui::NewFrame(), returns true. |
Update(GameTime&) | Polls keyboard/mouse. Calls handleKeyboardShortcuts() and handleMouseInput(). Advances animation clock if playing. |
Draw(const GameTime&) | Clears frame. Evaluates animation overrides. Draws grid and 3D scene. Calls drawImGuiUi() and optionally drawTimelinePanel(). |
EndDraw() | Calls ImGui::Render() + draw data flush. Writes screenshot if pendingScreenshot_. Calls Game::EndDraw(). |
Key Private Members (State)
| Field | Type | Purpose |
|---|---|---|
document_ | Mc3::Mc3Document | The scene currently being edited. |
currentFile_ | filesystem::path | Path of the open file (empty for new scenes). |
modified_ | bool | True when there are unsaved changes. |
camera_ | EditorCamera | 3D viewport camera. |
selection_ | SelectionManager | Current selection. |
gizmo_ | TransformGizmo | Active gizmo mode and drag state. |
activeTool_ | ActiveTool | Which tool is active (Select, Move, Rotate, Scale, Add*). |
undoStack_ | vector<Mc3Document> | Deep-copy snapshots for undo (max 20). |
redoStack_ | vector<Mc3Document> | Deep-copy snapshots for redo (max 20). |
clipboard_ | vector<shared_ptr<Mc3Object>> | Cut/copy clipboard. |
currentActionName_ | string | Name of the animation action being played/edited. |
animTime_ | float | Current playback time in seconds. |
animPlaying_ | bool | Whether animation is playing. |
showTimeline_ | bool | Whether the Timeline panel is visible. |
imguiTopH_ | int | Height of the menu bar + toolbar in pixels. Updated each frame. |
showEdgeOverlay_ | bool | Alt+W toggles black wireframe overlay. |
Key Private Methods
| Method | Purpose |
|---|---|
pushUndo() | Deep-copies document_ onto undoStack_. Clears redo stack. Clears CSG cache. Must be called before any document mutation. |
newScene() | Replaces document_ with an empty document. |
openFile() | Opens an MC3 XML file via the in-editor path dialog. |
saveFile() / saveFileAs() | Serializes document_ to XML using Mc3XmlWriter. |
exportGltf() | Finds the mc3togltf binary, shells out to it, exports to GLB. |
addPrimitive(ObjectType) | Creates a new primitive object, pushes undo, adds to scene root. |
deleteSelected() | Removes all selected objects from the scene tree (recursive search). |
duplicateSelected() | Deep-copies selected objects with a _copy name suffix. |
groupSelected() | Wraps selected objects in a new Group node. |
ungroupSelected() | Promotes group children to the group's parent level. |
evaluateAndPushAnimOverrides() | Evaluates all channels of the current action at animTime_, calls SceneRenderer::setAnimOverrides(). |
drawImGuiUi(screenW, screenH) | Draws all ImGui panels: menu bar, toolbar, hierarchy, properties, viewport overlay, status bar. |
drawTimelinePanel(screenW, screenH) | Draws the Timeline panel (Ctrl+T). |
handleKeyboardShortcuts(ks, prevKs) | Processes all keyboard shortcuts using edge-detection (prev vs current state). |
handleMouseInput(ms, prev) | Camera orbit/pan/zoom, ray-cast picking, gizmo drag. |
setStatusMsg(msg, isError, duration) | Shows a timed colored message in the status bar. |
Panel Layout Constants
static constexpr int kLeftPanelW = 220; // hierarchy panel width
static constexpr int kRightPanelW = 220; // properties panel width
static constexpr int kStatusH = 22; // status bar height
static constexpr int kTimelineH = 190; // timeline panel height
static constexpr int kUndoMax = 20; // max undo steps
Structural constraint
Do not refactor MeshCraftApplication.cpp structurally — it is large but functional. Splitting it would require careful coordination to preserve all ImGui state and the 1-frame lag between Draw and Update.