How Meshopt Optimizes glTF Vertex Compression

The meshoptimizer library optimizes glTF vertex buffers for compression by rearranging geometry data to maximize spatial coherence and predictive patterns. By sorting vertices into the strict sequence in which they are first accessed by the index buffer, the library minimizes differences between adjacent values. This structural reorganization allows delta filters and entropy encoders—such as those defined in the EXT_meshopt_compression glTF extension—to store attributes as tightly clustered, small integers, yielding substantially higher compression ratios.

Cache-Aware Index Optimization

Before reordering vertex data directly, meshopt first optimizes the triangle index buffer using a vertex cache optimization algorithm. This step reorders the indices so that triangles sharing vertices are grouped closely together in memory. By prioritizing cache locality, the algorithm generates an index stream that accesses the mesh's surface topology smoothly and continuously, eliminating erratic jumping across different regions of the model.

First-Referenced Vertex Reordering

Once the index sequence is stabilized, meshopt applies vertex fetch optimization via functions like meshopt_optimizeVertexFetch. In this phase, the library scans the index buffer from start to finish and reorders the entire vertex buffer into a "first-seen" layout:

  1. The first unique index encountered in the index stream becomes vertex index 0 in the newly ordered vertex buffer.
  2. Each subsequent unique index is placed into the next contiguous slot (1, 2, 3...).
  3. The index buffer is then updated to point to these newly assigned vertex locations.

Duplicate or unreferenced vertices are removed during this process. Because triangles on a 3D surface usually connect adjacent points, ordering vertices chronologically by when they are drawn guarantees that adjacent elements in the vertex array are almost always geometrically adjacent in 3D space.

Maximizing Delta Encoding Efficiency

Raw vertex buffers typically store interleaved attributes—such as positions, normals, tangents, and texture coordinates—that can vary drastically if adjacent array indices represent opposite sides of an object. After meshopt's reordering:

  • Positional Continuity: The position coordinates of vertex i and vertex i+1 are physically close to one another, making the difference vector (\(V_{i} - V_{i-1}\)) very small.
  • Attribute Continuity: Normals, tangents, and UV coordinates also change smoothly across adjacent indices rather than exhibiting abrupt discontinuities.

This smooth progression is the foundation of meshopt's compression pipeline. Instead of storing absolute values, attributes are split into separate contiguous streams (de-interleaved) and processed with predictive delta filters. Because consecutive values are closely correlated, their differences concentrate tightly around zero.

Enhancing Downstream Entropy Coding

The ultimate compression gains come from how entropy coders handle the post-delta data:

  • Bitwise Redundancy: Small numerical differences contain redundant leading zeros or identical sign bits. Meshopt's byte-grouping and variable-length integer encoding schemes pack these near-zero values into fewer bytes.
  • Zip and Zstandard Friendliness: General-purpose byte compressors, such as Zstandard or Deflate, rely on finding repeated byte sequences and low-entropy probability distributions. By transforming noisy floating-point or quantized coordinates into recurring, small-magnitude deltas, meshopt gives these codecs predictable symbol frequencies that compress far more efficiently than unordered raw buffers.