MC3 Library (mc3/)
Pure-C++ scene data model, XML parser, XML writer, and animation system. No graphics dependency.
Purpose
The mc3/ directory builds as a static library (libMc3.a) that is shared between the
MeshCraft editor and the mc3togltf converter. It has no dependency on CNA, OpenGL, SDL, or ImGui — it is a pure data + I/O library.
Key Files
| File | Role |
|---|---|
include/MeshCraft/Mc3/Mc3Document.hpp | Top-level scene container. Holds all objects, materials, textures, lights, cameras, definitions, and actions. |
include/MeshCraft/Mc3/Mc3Object.hpp | Single scene graph node. Has ObjectType enum and optional primitive/extrude/CSG data + children. |
include/MeshCraft/Mc3/Mc3Transform.hpp | Position / rotation (XYZ Euler, degrees) / scale / pivot. |
include/MeshCraft/Mc3/Mc3Primitive.hpp | Shape parameters for box, sphere, cylinder, cone, plane. |
include/MeshCraft/Mc3/Mc3Extrude.hpp | Cross-section and path types for extrude objects. |
include/MeshCraft/Mc3/Mc3Material.hpp | PBR material: baseColor, roughness, metallic, emissive, texture slots. |
include/MeshCraft/Mc3/Mc3Texture.hpp | Texture definition: uri, wrap modes, filter, color space. |
include/MeshCraft/Mc3/Mc3Light.hpp | Ambient / Directional / Point / Spot light types. |
include/MeshCraft/Mc3/Mc3Camera.hpp | Perspective / orthographic camera with position, target, FOV. |
include/MeshCraft/Mc3/Mc3Animation.hpp | Action / Channel / Keyframe types, interpolation modes, evaluateChannel(). |
src/Mc3XmlParser.hpp/.cpp | Reads .mc3.xml into the data model using tinyxml2. |
src/Mc3XmlWriter.hpp/.cpp | Serializes the data model back to XML (used by Save/Save As). |
src/MathUtils.hpp | Inline helpers: degree/radian conversion, vector normalization. |
mc3.xsd | XML Schema Definition for the MC3 format v0.3. |
MC3_FORMAT.md | Authoritative format specification (version 0.3). |
test/roundtrip_test.cpp | 114 assertions that verify every field round-trips through XML without loss. |
Data Model Hierarchy
Mc3Document
├── version: string (e.g. "0.3")
├── model: string (scene name)
├── unit: string (e.g. "meter")
├── sourcePath: filesystem::path
│
├── environment: optional<Mc3Environment>
│ └── background (color, texture), fog (mode, color, start, end, density)
│
├── lights: vector<Mc3Light>
│ └── type (Ambient/Directional/Point/Spot), name, color, brightness, ...
│
├── cameras: vector<Mc3Camera>
│ └── type, name, position, target, fov, near, far, ...
│
├── textures: map<string, Mc3Texture>
│ └── uri, wrapU, wrapV, filter, colorSpace, mipMaps
│
├── materials: map<string, Mc3Material>
│ └── baseColor[4], roughness, metallic, emissive[3], texture slots, alphaMode
│
├── definitions: map<string, shared_ptr<Mc3Object>>
│
├── objects: vector<shared_ptr<Mc3Object>>
│ └── (scene graph roots)
│
└── actions: map<string, Mc3Action>
└── duration, loop, channels (target + property + keyframes)
Mc3Object
├── type: ObjectType (Box, Sphere, Cylinder, Cone, Plane, Mesh,
│ Extrude, Group, Instance, Union,
│ Difference, Intersection, Area)
├── name, id, material (IDREF)
├── transform: Mc3Transform (position, rotation[XYZ Euler °], scale, pivot)
├── deform: optional<Mc3Deform>
├── primitive: optional<Mc3Primitive>
├── extrude: optional<Mc3Extrude>
├── csgOperation: optional<Mc3CsgOperation>
├── isCutter: bool
├── definition: string (type == Instance)
├── meshSource: string (type == Mesh)
├── visible, collision, tags
└── children: vector<shared_ptr<Mc3Object>>
XML Parsing
Mc3XmlParser uses tinyxml2. It parses the document top-down:
- Reads root
<mc3>attributes (version, model, unit, rotation_units, euler_order) - Reads each top-level section:
<environment>,<lights>,<cameras>,<textures>,<materials>,<definitions>,<objects>,<actions> - Each object element is parsed recursively, building the child tree
- Sets
Mc3Document.sourcePathto the directory of the XML file (used for resolving relative texture/mesh paths)
The mc3togltf/ converter has its own copy of the XML parser (mc3togltf/src/Mc3XmlParser.*) rather than linking the mc3/ library. This keeps the converter self-contained. If you change the MC3 format, update both parsers.
Animation System
Defined in Mc3Animation.hpp:
Mc3Action— a named clip with a duration, loop flag, and list of channels.Mc3Channel— animates oneAnimatedPropertyof one named object.Mc3Keyframe— time, value, interpolation mode, and optional Bézier tangent handles.evaluateChannel(ch, time)— evaluates a channel at a given time using the correct interpolation (Step, Linear, or Cubic Bézier).
See Animation API Reference for the full list of animatable properties.
Known Limitations
Areas still needing work
- UV mapping (
<uv_mapping>) is parsed but not yet fully wired into the editor UI (noted as TODO inMc3Object.hpp). - Object states (
<states>) are defined in the format spec but not yet in the C++ data model. - Action triggers (
<triggers>) are spec'd but not implemented. - The
Mc3Document::versionfield defaults to "0.1" even though the active format is v0.3 — needs updating.