How glTF Encodes Line Strip Primitives for CAD
glTF (GL Transmission Format) encodes continuous vector graphics,
such as CAD schematic overlays, by defining geometry through specific
primitive topology modes stored in binary buffers and described via JSON
metadata. By setting a mesh primitive's topology mode to
LINE_STRIP (mode: 3), glTF enables compact
representation of connected linear elements like wiring traces,
dimension lines, and structural boundaries. This approach bypasses the
memory overhead of duplicate vertex definitions required by standard
disconnected line segments, optimizing performance for real-time
rendering engines.
Primitive Definition in the glTF JSON Schema
In the glTF schema, a 3D model is organized into scenes, nodes, and
meshes. A mesh contains an array of primitives, each
defining geometry and rendering parameters.
To encode a line strip, the primitive object defines the
mode property with a value of 3:
{
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0
},
"indices": 1,
"material": 0,
"mode": 3
}
]
}
]
}If the mode property is omitted, rendering engines
default to 4 (TRIANGLES). Setting
mode: 3 signals to the graphics API (such as WebGL, Vulkan,
or DirectX) to draw a continuous connected line through a series of
vertices: the first line connects vertex 0 to 1, the next connects 1 to
2, and so forth through vertex \(N-1\)
to \(N\).
Vertex Buffer and Index Representation
The spatial coordinates for the line strip reside in binary buffers
(.bin files or embedded Base64 data), referenced via
bufferViews and accessors.
Sequential (Non-Indexed) Line Strips:
When theindicesproperty is omitted, the renderer reads sequential positions directly from the accessor referenced by thePOSITIONattribute. For an overlay consisting of \(N\) points, the buffer contains exactly \(N\) coordinate sets (typicallyVEC3of typeFLOAT).Indexed Line Strips:
When theindicesproperty is included, it references an accessor of scalar integers (UNSIGNED_BYTE,UNSIGNED_SHORT, orUNSIGNED_INT). The renderer reads the vertex positions in the exact sequence specified by the indices array. This is useful when points are shared across multiple primitives or spatial features within the same CAD file.
Structuring Multi-Path CAD Overlays
A single line strip cannot naturally represent disconnected segments or branched schematic diagrams without drawing an unwanted bridging segment. In CAD overlays consisting of multiple separate lines (such as discrete electrical circuits or broken dimension lines), the data is organized using one of two strategies:
- Multiple Primitives: The mesh contains an array of several primitives, where each primitive represents a single continuous line strip with its own index or vertex slice.
- Degenerate or Segmented Alternatives: When
draw-call overhead is a concern across thousands of separate paths, CAD
converters often switch from
LINE_STRIP(mode: 3) to standardLINES(mode: 1). WhileLINESrequires two explicit indices per segment (increasing the index buffer size), it allows an entire multi-path schematic to be packaged within a single draw call.
Visual Presentation and Material Handling
Schematic overlays require consistent visibility regardless of the 3D
scene's lighting conditions. To achieve this, glTF implementations apply
the KHR_materials_unlit extension to the primitive's
material.
The unlit material ensures that line colors remain uniform and legible without calculating diffuse reflection, specular highlights, or shadow maps. Additionally, because standard glTF core specification defines line width as implementation-dependent (often restricted to 1 pixel by underlying graphics APIs), high-fidelity CAD viewers frequently interpret these line strip definitions dynamically to generate camera-facing screen-space ribbons or depth-biased overlays to prevent z-fighting with underlying 3D surfaces.