---
id: "meshoptimizer"
title: "meshoptimizer mesh optimization"
aliases: [meshopt, EXT_meshopt_compression]
domain: "performance"
stage: "performance"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, cpu]
year_introduced: 2016
inputs: [mesh]
outputs: [mesh]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "zeux, 2016"
url: "https://texelatlas.vercel.app/t/meshoptimizer/"
sources_verified_at: "2026-11-29"
---
# meshoptimizer mesh optimization (zeux, 2016)

> An MIT library that reorders for vertex cache and fetch efficiency, simplifies meshes for LOD, builds meshlets, and encodes vertex and index buffers for fast decoding.

## Reach for it when

- scene has too many triangles for the gpu
- mesh loading and vertex fetch is slow
- reduce model size for web delivery
- need lod versions of meshes automatically

## How it works

Index buffers are reordered for post-transform cache hits, then vertices are reordered for fetch locality, and overdraw can be reduced further. Simplification collapses edges with a quadric error metric, returning a measured error that picks LOD by screen size. Buffer codecs byte-transposes and delta-codes streams so a general-purpose compressor works well, and the decoder runs at gigabytes per second using SIMD or WebAssembly.

The same library builds meshlets with bounds and cones for cluster pipelines.

## When to use it

Choose it as the default post-process for any mesh shipped to a GPU, and for LOD chains and meshlets. Prefer [Draco mesh compression](https://texelatlas.vercel.app/t/draco-mesh-compression.md) when size is the only goal and decode speed is irrelevant. Prefer [Nanite virtualized geometry](https://texelatlas.vercel.app/t/nanite-virtualized-geometry.md) when the engine builds cluster hierarchies itself.

## Cost

cheap — Offline processing; runtime cost is a fast decode.
Measured GPU Weight: 20.01× baseline (heavy) — 0.6582 ms median / 0.6826 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 18.17× baseline (moderate) — 0.2889 ms median (2.28× faster on L4).
Ampere A100 scaling: 13.7× baseline (moderate) — 0.3947 ms median (1.67× faster on A100).

## Failure modes

- Aggressive simplification collapses thin features and breaks UV seams
- Attribute errors are not captured unless weighted
- Decoding requires matching filter and mode settings per stream
- Lossy quantization visible at large object scales

## Engine support

- babylonjs: official — `glTF EXT_meshopt_compression loader extension (MeshoptCompression)` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Meshes/Compression/meshoptCompression.ts, checked 2026-12-01)
- blender: official — `File > Export > glTF 2.0 > Data > Compression (Meshopt)` (evidence: https://docs.blender.org/manual/en/5.2/addons/scene_gltf2.html, checked 2026-12-01) — Bundled glTF 2.0 add-on writes EXT/KHR_meshopt_compression.
- godot: builtin — `ImporterMesh.generate_lods(); scene import option Meshes > Generate LODs` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/ImporterMesh.xml, checked 2026-12-01) — Godot bundles meshoptimizer for LOD generation.
- threejs: official — `import { createMeshlets } from 'three/addons/utils/MeshletGeometryUtils.js' (uses MeshoptClusterizer, MeshoptSimplifier)` (evidence: https://github.com/mrdoob/three.js/blob/r187/examples/jsm/utils/MeshletGeometryUtils.js, checked 2026-12-01) — Official addons consume meshoptimizer; no general mesh-optimize pass.
- unity: official — `Package Manager > Meshopt Decompression (com.unity.meshopt.decompress)` (evidence: https://docs.unity3d.com/Packages/com.unity.meshopt.decompress@0.1/manual/index.html, checked 2026-12-01) — Decoder for meshopt-compressed glTF meshes (EXT_meshopt_compression).

## Dataflow

- Inputs: mesh
- Outputs: mesh
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, cpu

## Presets

### meshoptimizer meshlet limits (json-params; parameter preset)

```json
{
  "max_vertices": 64,
  "max_triangles": 126,
  "cone_weight": 0.25
}
```

Attribution: Defaults from the meshoptimizer README (MIT license).; basis: 0

### meshoptimizer — 64-triangle meshlet clusters & QEM LOD wireframe (left) vs vertex-cache-optimized smooth shading (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_MESHLET_RES": 7,
  "P_LOD_ERROR": 0.55,
  "P_WIREFRAME": 0.45,
  "P_SPLIT": 0.48
}
```

```glsl
const float P_MESHLET_RES = 7.00; // P Meshlet Density [4.0, 12.0, 1.0]
const float P_LOD_ERROR = 0.55; // P QEM LOD Step [0.0, 1.0, 0.05]
const float P_WIREFRAME = 0.45; // P Triangle Wire [0.0, 1.0, 0.05]
const float P_SPLIT = 0.48; // P Meshlets / Shaded [0.0, 1.0, 0.02]

float hash31(vec3 p) {
  p = fract(p * 0.1031);
  p += dot(p, p.yzx + 33.33);
  return fract((p.x + p.y) * p.z);
}

vec2 rot2(vec2 p, float a) {
  float c = cos(a);
  float s = sin(a);
  return vec2(c * p.x - s * p.y, s * p.x + c * p.y);
}

// Sculpted twisted torus-shell geometry ideal for showcasing spatial meshlet partitioning & LOD
float mapMesh(vec3 p, float t) {
  p.xz = rot2(p.xz, t * 0.48);
  p.xy = rot2(p.xy, 0.30);
  vec2 q = vec2(length(p.xz) - 0.38, p.y);
  float ang = atan(p.z, p.x);
  q = rot2(q, ang * 1.5);
  float dBox = length(max(abs(q) - vec2(0.11, 0.16), 0.0)) - 0.055;
  return dBox * 0.82;
}

vec3 calcNormal(vec3 p, float t) {
  vec2 e = vec2(0.0025, 0.0);
  return normalize(vec3(
    mapMesh(p + e.xyy, t) - mapMesh(p - e.xyy, t),
    mapMesh(p + e.yxy, t) - mapMesh(p - e.yxy, t),
    mapMesh(p + e.yyx, t) - mapMesh(p - e.yyx, t)
  ));
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float mRes = clamp(P_MESHLET_RES, 3.0, 14.0);
  float lodErr = clamp(P_LOD_ERROR, 0.0, 1.0);
  float wireAmt = clamp(P_WIREFRAME, 0.0, 1.0);

  vec3 ro = vec3(0.0, 0.28, 2.08);
  vec3 rd = normalize(vec3(uv.x, uv.y - 0.07, -1.50));
  vec3 lDir = normalize(vec3(0.58, 0.78, 0.52));
  vec3 col = mix(vec3(0.05, 0.07, 0.12), vec3(0.13, 0.18, 0.28), smoothstep(-0.4, 0.5, uv.y));

  float tRay = 0.05;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    float h = mapMesh(ro + rd * tRay, iTime);
    if (h < 0.002) { hit = true; break; }
    tRay += h;
    if (tRay > 6.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * tRay;
    vec3 n = calcNormal(p, iTime);
    // Transform hit to rigid object space for stable meshlet IDs
    vec3 pObj = p;
    pObj.xz = rot2(pObj.xz, iTime * 0.48);
    pObj.xy = rot2(pObj.xy, 0.30);

    float ndl = max(dot(n, lDir), 0.0);
    float spec = pow(max(dot(reflect(-lDir, n), -rd), 0.0), 42.0);
    float fres = pow(1.0 - max(dot(n, -rd), 0.0), 4.0);

    if (screenX < split) {
      // Left: Voronoi-like 3D spatial meshlet clusters (each cluster ~64 tris) + QEM triangle density grid
      vec3 scaled = pObj * mRes;
      vec3 cid = floor(scaled);
      float bestD = 9.0;
      float secondD = 9.0;
      vec3 bestId = cid;
      for (int dz = -1; dz <= 1; dz++) {
        for (int dy = -1; dy <= 1; dy++) {
          for (int dx = -1; dx <= 1; dx++) {
            vec3 nb = cid + vec3(float(dx), float(dy), float(dz));
            vec3 jit = vec3(hash31(nb), hash31(nb + 13.7), hash31(nb + 29.1));
            float dd = length((nb + jit * 0.75 + 0.125) - scaled);
            if (dd < bestD) {
              secondD = bestD;
              bestD = dd;
              bestId = nb;
            } else if (dd < secondD) {
              secondD = dd;
            }
          }
        }
      }
      float hId = hash31(bestId + 5.3);
      vec3 meshletCol = 0.50 + 0.44 * cos(vec3(0.0, 2.05, 4.10) + hId * 6.2831853);
      float clusterBorder = smoothstep(0.08, 0.015, secondD - bestD);

      // Sub-cluster QEM simplified triangle wireframe
      float triFreq = mix(28.0, 10.0, lodErr);
      vec3 tf = fract(pObj * triFreq);
      float triEdge = min(min(min(tf.x, 1.0 - tf.x), min(tf.y, 1.0 - tf.y)), abs(tf.x + tf.y - 1.0));
      float wire = smoothstep(0.08, 0.015, triEdge);

      col = meshletCol * (0.28 + 0.88 * ndl) + vec3(0.95) * spec * 0.35;
      col = mix(col, vec3(0.06, 0.08, 0.12), wire * wireAmt * 0.55);
      col = mix(col, vec3(0.98, 0.98, 1.0), clusterBorder * 0.65);
    } else {
      // Right: Vertex-cache & overdraw-optimized clean shaded metallic ceramic surface
      vec3 alb = mix(vec3(0.76, 0.79, 0.84), vec3(0.92, 0.66, 0.34), 0.5 + 0.5 * n.x);
      col = alb * (0.22 + 0.94 * ndl) + vec3(1.15, 1.08, 0.98) * spec * 0.90 + vec3(0.32, 0.66, 0.98) * fres * 0.55;
    }
  } else if (rd.y < -0.005) {
    float tf = (-0.54 - ro.y) / rd.y;
    if (tf > 0.05 && tf < 14.0) {
      vec3 fp = ro + rd * tf;
      float sh = smoothstep(0.28, 0.72, length(fp.xz));
      vec2 g = abs(fract(fp.xz * 2.5) - 0.5);
      float grid = smoothstep(0.04, 0.01, min(g.x, g.y));
      col = mix(col, mix(vec3(0.10, 0.12, 0.17), vec3(0.24, 0.30, 0.42), grid) * (0.35 + 0.65 * sh), exp(-tf * 0.16));
    }
  }

  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.98, 1.0), sep);
  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Combines with

- [Meshlets (cluster rendering)](https://texelatlas.vercel.app/t/meshlets.md): meshopt builds clusters and orders their indices for mesh shaders.

## Sources

1. [primary] zeux (2016) zeux/meshoptimizer. https://github.com/zeux/meshoptimizer License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "meshoptimizer mesh optimization." https://texelatlas.vercel.app/t/meshoptimizer/ (accessed 2026-12-01).
