Docs/Classes/MeshCraftApplication

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

SignatureUsage
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

MethodBehaviour
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)

FieldTypePurpose
document_Mc3::Mc3DocumentThe scene currently being edited.
currentFile_filesystem::pathPath of the open file (empty for new scenes).
modified_boolTrue when there are unsaved changes.
camera_EditorCamera3D viewport camera.
selection_SelectionManagerCurrent selection.
gizmo_TransformGizmoActive gizmo mode and drag state.
activeTool_ActiveToolWhich 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_stringName of the animation action being played/edited.
animTime_floatCurrent playback time in seconds.
animPlaying_boolWhether animation is playing.
showTimeline_boolWhether the Timeline panel is visible.
imguiTopH_intHeight of the menu bar + toolbar in pixels. Updated each frame.
showEdgeOverlay_boolAlt+W toggles black wireframe overlay.

Key Private Methods

MethodPurpose
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.