Repository navigation
Canonical glTF profile
Every mesh2gltf output follows this profile: a subset of glTF 2.0 that later processing can memory-map and read front to back, without handling OBJ, PLY or VRML quirks again.
Places where this profile reflects our opinions rather than strict correctness are highlighted in bold.
- One
.gltfJSON file, one external<stem>.binas its only buffer, and texture files. Or, for an output ending in.glb, one GLB file whose binary chunk is the only buffer. No data URIs. - In a
.gltf, everyuriis a relative path with no scheme, percent-encoded per path segment. - Copied or converted images are named
<stem>_texture_<n>.<ext>, next to the.gltf. Images kept in place keep their names and stay inside the output folder unless--trustedis set, in which case aurican start with... See Images. - In a
.glb, every image is a buffer view with amimeType, 4-byte aligned after the geometry, and nothing else is written beside the file. - The
.bincan exceed 4 GiB: read its lengths and offsets as 64-bit values. A.glbcan't, since the container's lengths are 32-bit. A larger model fails (exit code 1) rather than being split.
Every primitive is an indexed triangle list (mode 4) with float32 attributes and a material. A primitive holds a run of faces that share their mesh, their material, whether they have UVs and whether they show vertex colors.
| Attribute | Type | Present |
|---|---|---|
POSITION |
VEC3 float32, with min and max
|
Always |
NORMAL |
VEC3 float32, unit length | Always |
TEXCOORD_0 |
VEC2 float32, V flipped from the source | When the faces have UVs |
COLOR_0 |
VEC3 float32 | When the faces show vertex colors (see below) |
- Indices are
UNSIGNED_SHORTwhen a primitive has at most 65,535 vertices, otherwiseUNSIGNED_INT. - A primitive is split only where 32-bit indices run out (2^32 − 1 vertices). Geometry is never chunked, capped or duplicated otherwise.
- Vertices are welded within a primitive. Every primitive owns its buffer views; no vertex data is shared between primitives or meshes.
- Source normals are normalized. Missing or zero-length ones are generated by accumulating area-weighted triangle normals per source position. Flat-shaded faces and corners whose accumulated normal cancels out carry their own face normal and are never shared.
- Faces of zero area are dropped. Non-simple polygons may give overlapping triangles; see Triangulation.
- Not used: tangents,
TEXCOORD_1and higher, skins, morph targets, sparse or normalized accessors, and geometry compression.
Vertex colors replace the diffuse color, and a texture replaces them. This is the order of VRML97's lighting model (ISO/IEC 14772-1, 4.14.3, table 4.6) and of X3D. OBJ defines none, and glTF multiplies COLOR_0 into the base color and texture. Multiplying would darken a texture by the colors that photogrammetry exporters bake from that same texture, and darken colors by MTL's default Kd of 0.8.
- A face shows vertex colors when it has no texture (no
map_Kd, or no UVs) and any of its positions has a color. Its other positions are white. - Its material is a copy with a white
baseColorFactorand no texture, named<name>-vertex-colors. - A face whose positions have no color keeps its material, even in a file where other positions have one.
- Vertex colors on textured faces are dropped, with one counted warning. With
--no-color, they are dropped everywhere, and every face keeps its material. -
COLOR_0holds linear values. OBJ, PLY and VRML vertex colors are converted from sRGB.
The .bin, or a GLB's binary chunk, holds the primitives in JSON order, so it can be mapped once and read front to back. For each primitive:
- One interleaved vertex view (
target34962) withbyteStrideset: position at offset 0, normal at 12, then the UV and the color when present. The stride is 24, 32 with a UV, 36 with a color, or 44 with both. - Directly after it, the index view (
target34963). - Up to 2 bytes of zero padding, so the next vertex view starts 4-byte aligned.
Positions are float32 offsets from an origin recorded exactly, as decimal text. Source position = inverse axis rotation × (node transform × POSITION), plus the origin when centered is true.
- Units are the source's, assumed to be metres.
- With
--center, the origin is the center of the whole input's bounding box, and nodes have no translation. - Otherwise, the origin is 0, unless float32 would resolve less than 1/65,536 of the model's largest dimension. It is then the bounding-box center rounded to a power of ten, and every root node's
translationis the origin in output axes, so the model stays in place. See Georeferenced coordinates. - The axes are glTF's: right-handed, Y up. A Z-up source keeps its positions; each root node carries a −90° rotation about X instead.
See Georeferenced coordinates for precision and origin recovery.
- One mesh per source object, named after it. Objects without triangles are omitted.
-
Materials are metallic-roughness with
baseColorFactor,metallicFactor,roughnessFactorand at most abaseColorTexture;emissiveFactoranddoubleSidedare set.alphaModeisOPAQUEorBLEND. - Faces without UVs whose material has a texture use a copy of the material without it, named
<name>-untextured. Faces with vertex colors use a white copy named<name>-vertex-colors. - Samplers set only
wrapSandwrapT, toREPEATorCLAMP_TO_EDGE. Images are PNG or JPEG. - Extensions used (for OBJ imports):
KHR_texture_transform(required when used),KHR_materials_unlit,KHR_materials_specular,KHR_materials_iorandKHR_materials_transmission. Primitives carry none.
See Materials for how source materials map to these.