Docs/Tutorials/Export to glTF/GLB

What is mc3togltf?

mc3togltf is a standalone command-line tool included in the MeshCraft repository. It reads an .mc3.xml file and writes a standard glTF 2.0 file (.gltf JSON + separate .bin) or a self-contained GLB binary (.glb).

The tool does not require the editor to be running — it can be used in automated pipelines and CI.

Step 1 — Build mc3togltf

The converter is built alongside the main editor when you use the default CMake target. You can also build only the converter:

cmake -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug .
cmake --build cmake-build-debug --target mc3togltf

The binary is placed at cmake-build-debug/mc3togltf/mc3togltf.

Step 2 — Run the Conversion

Export as glTF JSON

./cmake-build-debug/mc3togltf/mc3togltf scene.mc3.xml scene.gltf

This produces scene.gltf (JSON) and scene.bin (binary mesh data) in the same directory.

Export as GLB (single file)

./cmake-build-debug/mc3togltf/mc3togltf scene.mc3.xml scene.glb

The output format is determined from the file extension: .gltf → JSON+BIN, .glb → binary container.

Export the test house scene

./cmake-build-debug/mc3togltf/mc3togltf test/house.mc3.xml /tmp/house.glb

What Gets Exported

MC3 featureglTF equivalentStatus
Box, Sphere, Cylinder, Cone, Plane primitivesmesh with TRIANGLES primitiveExported
Extrude objectsmesh (tessellated geometry)Exported
Group (hierarchy)node with childrenExported
Instance (reference to definition)Separate node with copied meshExported
Transform (position, rotation, scale)node.translation/rotation/scaleExported
Pivot offsetBaked into node transformExported
PBR materials (baseColor, roughness, metallic)material.pbrMetallicRoughnessExported
Texture referencestexture + image entriesExported
Position/rotation/scale animation channelsanimation samplers + channelsExported
Directional and ambient lightsNot in base glTF — skippedSkipped
CSG objects (union/difference/intersection)Individual child meshes (not merged)Partial
visible / deform / material.* animationNo glTF equivalent — skippedSkipped

Verifying the Export

Open the exported file in any of these free tools:

Animation Export Notes

Keyframe animations in the <actions> section are exported as glTF animations[]. Some caveats apply:

Running the Test Suite

The mc3togltf module has its own CTest suite with 38 assertions that verify round-trip correctness:

cd cmake-build-debug
ctest -R mc3togltf --output-on-failure
ℹ️

Duplication note: mc3togltf contains its own local copy of the MC3 XML parser (mc3togltf/src/Mc3XmlParser.cpp) rather than linking against the mc3/ library. This is an architectural decision for standalone deployment. If you extend the MC3 format, you must update both parsers to keep them in sync.

Common Problems

ProblemLikely CauseFix
Output glTF has no meshesThe scene only contains groups, instances, or unsupported typesEnsure there are primitive or extrude objects in the scene
Textures not found in BlenderTexture paths in MC3 are relative to the .mc3.xml fileKeep texture files next to the MC3 file, or use GLB which embeds nothing — embed textures separately
mc3togltf segfaults on loadMalformed XML or missing required attributesValidate the MC3 file first by opening it in the editor
CSG geometry looks like individual piecesCSG is not resolved by mc3togltfBoolean evaluation is planned; workaround: export individual children and merge in Blender