Skip to content

Geometry and format support

Sebastien DUMETZ edited this page Nov 17, 2026 · 5 revisions

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.

OBJ

  • 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, each g starts an object named after the group, since many exporters write only groups; groups inside objects are not represented. A repeated o or g name 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 replace Kd on faces without a texture and are dropped under one; see Vertex colors. --no-color drops 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 extra v component, and texture coordinates beyond u v.
  • Rejected: a face mixing corners with and without UVs or normals.

PLY

  • 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 float or double coordinates keep their exact value, to 1e-10 m.
  • Only meshes are read. A file without a face element, or with an empty one, is rejected as a point cloud.
  • Vertices: x y z, normals nx ny nz, colors red green blue, and texture coordinates s t, u v, texture_u texture_v or texture_s texture_t, the names three.js's PLYLoader reads. Faces: vertex_indices, or vertex_index as in three.js and VTK, triangulated like OBJ polygons.
  • Per-corner texture coordinates, a face texcoord list of u v per 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 OBJ vt.
  • Colors: integer channels span their type's range, 0–255 for uchar as 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 with texnumber, 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, TextureFile comments in a file without texture coordinates, the UVs of a face whose texcoord list doesn't match its corners, and the texture of a face whose texnumber names 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

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

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.

VRML

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.

Conversion · Documentation home

Clone this wiki locally