How CAD Tools Convert B-Rep Geometry to glTF

This article provides an overview of the conversion pipeline used by modern CAD software to translate mathematically continuous Boundary Representation (B-Rep) models into discrete, real-time glTF polygonal meshes. Converting CAD models to glTF requires bridging the gap between exact mathematical definitions (NURBS and analytic surfaces) and lightweight, GPU-ready triangle arrays. The process involves adaptive tessellation, edge-stitching to ensure watertightness, analytical normal generation, and mapping complex CAD assemblies to the glTF scene graph hierarchy.

Understanding the Structural Difference

CAD systems store 3D models as Boundary Representations (B-Rep). A B-Rep model consists of two parts:

  1. Geometry: Mathematical definitions of shapes, such as Non-Uniform Rational B-Splines (NURBS), planes, cylinders, and tori.
  2. Topology: The relational data structure defining how surfaces meet, comprising faces, edges, and vertices.

In contrast, glTF (GL Transmission Format) is designed for efficient transmission and direct rendering by graphics APIs like WebGL, Vulkan, and DirectX. It does not support parametric curves or equations; it only accepts discrete geometric primitives—primarily indexed triangle lists, point clouds, and line segments.

Step 1: Surface Tessellation and Discretization

The core phase of the conversion is tessellation, where CAD kernels (such as Parasolid, ACIS, or Open CASCADE) evaluate parametric mathematical surfaces to generate planar triangles.

To produce a usable mesh, CAD tools rely on user-defined or automated tolerance criteria:

  • Chordal Deviation (Sagitta): The maximum allowable linear distance between the true curved surface and the flat triangle plane.
  • Angular Tolerance: The maximum angle between the surface normals at adjacent vertices, preventing visible faceting on tightly curved fillets or rounds.
  • Maximum Edge Length: A constraint ensuring triangles do not stretch disproportionately, preventing rendering and lighting artifacts.

The mesher evaluates the surface across its parametric \((u, v)\) domain, inserting vertices and connecting them into a Delaunay triangulation or similar planar triangulation structure.

Step 2: Boundary Trimming and Crack Prevention

Parametric surfaces in CAD are rarely untrimmed rectangles; they are bounded by trimming curves (such as intersections with other surfaces). During export, the CAD tool must discretize these trimming curves into 1D polyline segments before filling the interior with triangles.

A critical engineering challenge is preventing "cracking" (T-junctions or gaps) between adjacent faces. If two neighboring surfaces with different curvatures are meshed independently, their shared boundary might receive differing numbers of vertices. CAD exporters prevent this by meshing shared topological edges first. Once the edge vertices are locked, the adjacent faces are tessellated using those shared boundary points, ensuring a watertight mesh.

Step 3: Generating GPU Attributes from CAD Geometry

Because the tessellator has direct access to the original mathematical surfaces, it generates vertex attributes with higher fidelity than traditional mesh decimation tools:

  • Normals: Instead of calculating face normals or averaging adjacent polygon planes, the exporter evaluates the true surface derivative at each vertex coordinate. This produces smooth, accurate lighting on curved surfaces without requiring dense geometry.
  • UV Coordinates: The \((u, v)\) parameters of the underlying surface are normalized and mapped to texture coordinates for PBR (Physically Based Rendering) materials.
  • Color and Materials: CAD face colors and material properties are mapped to glTF’s standard metallic-roughness PBR model.

Step 4: Structuring the glTF Scene Graph

CAD data is inherently hierarchical, structured as parts, sub-assemblies, and top-level assemblies. The exporter translates this directly into the glTF JSON structure:

  • Assemblies and Components: Exported as nested nodes with their respective local transform matrices (translation, rotation, scale).
  • B-Rep Solids: Mapped to glTF meshes.
  • Individual Faces: Can either be grouped into a single mesh composed of multiple primitives (if different faces have unique materials) or merged into a single contiguous vertex buffer to minimize GPU draw calls.

Step 5: Binary Packing and Optimization

Once geometry and topology are resolved into arrays of indices and vertex attributes, the exporter packages the data for minimal file size and fast GPU ingestion:

  • Array Buffering: Vertex positions, normals, and UVs are packed into contiguous binary blobs (.bin files or embedded Base64 data) aligned to 4-byte boundaries.
  • Indexing: Vertices are deduplicated, and an index buffer is created to allow vertex reuse across adjacent triangles.
  • Compression (Optional): Many CAD exporters apply extensions such as KHR_draco_mesh_compression or KHR_mesh_quantization to convert floating-point attributes into 8-bit or 16-bit integers, significantly reducing network transfer times without visible loss of fidelity.