Repository navigation
Geometry and format support
mesh2gltf reads OBJ (.obj), PLY (.ply) and VRML (.wrl, .vrml). This page covers how each input is interpreted; data it can't represent is omitted with a counted warning, and input that would give wrong geometry is rejected. The resulting glTF is described in Canonical glTF profile.
- Keywords match whatever their case, as in obj2gltf and three.js. A trailing
\continues any statement on the next line, as in Blender. Comments are stripped first, so a comment line never continues. - Objects: until a file's first
o, eachgstarts an object named after the group, since many exporters write only groups; groups inside objects are not represented. A repeatedoorgname starts a new object rather than reopening the earlier one, as in obj2gltf. - Per-vertex colors written after the position (
v x y z r g b, as exported by RealityCapture, Metashape or MeshLab) are read as sRGB display values in[0,1]; values outside that range are clamped. They replaceKdon faces without a texture and are dropped under one; see Vertex colors.--no-colordrops them everywhere. - Omitted with a warning: unsupported records, faces with fewer than three corners (lines and points), a color alpha (
v x y z r g b a), a rational weight other than 1 (v x y z w), any other extravcomponent, and texture coordinates beyondu v. - Rejected: a face mixing corners with and without UVs or normals.
- ASCII and binary bodies, in either byte order, are read alike; only the reading of one value differs. ASCII coordinates go through the same fixed-point parser as OBJ's, so the digits written are kept whatever type the header declares. Binary
floatordoublecoordinates keep their exact value, to 1e-10 m. - Only meshes are read. A file without a
faceelement, or with an empty one, is rejected as a point cloud. - Vertices:
x y z, normalsnx ny nz, colorsred green blue, and texture coordinatess t,u v,texture_u texture_vortexture_s texture_t, the names three.js's PLYLoader reads. Faces:vertex_indices, orvertex_indexas in three.js and VTK, triangulated like OBJ polygons. - Per-corner texture coordinates, a face
texcoordlist ofu vper corner as MeshLab writes them, take precedence over per-vertex ones. Corners at one position with the same float32 UV share a vertex, as with an OBJvt. - Colors: integer channels span their type's range, 0–255 for
ucharas in three.js and MeshLab, and floating-point ones[0,1]. They are read as sRGB and follow the same rules as OBJ vertex colors. - Textures: each
comment TextureFile <name>, as MeshLab and other VCG-based exporters write it, becomes a material. A face picks one withtexnumber, the first by default. - Omitted with a warning: other properties (scalar fields, per-face colors, flags), other elements (edges, materials), color alpha when some is translucent, faces with fewer than three corners,
TextureFilecomments in a file without texture coordinates, the UVs of a face whosetexcoordlist doesn't match its corners, and the texture of a face whosetexnumbernames none. - Rejected: an unknown header line or type, vertices without
x y z, faces without vertex indices, an index outside the vertices, and data ending before the declared counts.
Smoothing groups only switch flat shading, as in three.js: faces after s off or s 0 get their own face normal and do not weigh on their neighbours' smooth normals. A group number or a bare s smooths faces together again; different numbers are not kept apart, as in three.js and Blender. Files without s, such as most scans, stay smooth (Blender would shade them flat). VRML crease angles do not disable smoothing.
Triangulation never aborts an import (src/triangulate.rs, one function per rule, each crediting its source):
- A corner at the same position as the previous one is dropped, as in earcut's point filtering.
- A face's plane is that of its Newell normal, or of its largest fan triangle when that normal vanishes (a bowtie).
- Ears are found with earcut's test, the library obj2gltf uses, so keyhole polygons triangulate exactly.
- A self-intersecting face with no ear is clipped anyway, following Blender's polygon filling and Held's FIST, and counted in a warning.
- Faces and triangles of zero area are skipped and counted.
Coverage is IndexedFaceSet geometry with inline Coordinate, TextureCoordinate, Normal, Color, Material and ImageTexture nodes; index arrays may arrive in any order. Non-identity transforms, USE references, other geometry nodes, conditional nodes, ccw FALSE and normalPerVertex FALSE are rejected rather than silently producing misplaced geometry. Color nodes follow the same rules as OBJ vertex colors, which match VRML's own lighting model, and are read as sRGB like them. They are used when they give one color per coordinate: colorPerVertex (the default) with no colorIndex, or one equal to coordIndex. Per-face colors, another colorIndex, or fewer colors than coordinates are omitted, with one counted warning. Texture transforms, generated UVs and animation are not implemented.