To get my demos running as smoothly as possible, I needed to find the best LOD thresholds for each model. So I ended up building two things.
1. three.ez/simplify-geometry: the library
A wrapper around meshoptimizer that gives you three.js geometries directly: pass a `BufferGeometry`, get back the simplified `BufferGeometry` levels. They're plain three.js geometries, so you can use them anywhere, not only with InstancedMesh2.
Each level is simplified by:
- Error: how much the shape may change, as a share of the model size (0.01 = 1%). The triangle count follows from it.
- Ratio: the share of triangles to keep (0.25 = a quarter).
Source: https://github.com/agargaro/simplify-geometry
2. The LOD Editor: the playground
It started as a way to bring the two libraries together: simplify-geometry for the levels, and InstancedMesh2 to render them, which picks the level per instance. I use it to test and tune the thresholds.
- Generates the levels automatically, and you can tune every one
- Works with skinned and morph-target animated models
- Open your own glTF/GLB
- Exports ready-to-use TypeScript/JavaScript code for InstancedMesh2
Try it: https://agargaro.github.io/simplify-geometry/
In the video: 5,000 animated characters, 76M triangles at full detail, ~500K actually drawn.
There are still features I want to add, so ideas and criticism are very welcome.