meshfx // LOD // THREEJS
How to use LOD in three.js
In three.js you build LOD with a THREE.LOD object: add the detailed mesh at distance 0 and simpler meshes at larger distances with addLevel(mesh, distance), then add the LOD to your scene. The renderer shows the right level for each camera distance, and the simpler meshes come from your 3D editor as separate GLB files.
pyrofx effects work today, and new accounts start with $5 of usage.
meshfx measures faults, checks repairs and makes LODs for a triangle budget. meshfx runs on the hosted API: try it in the Playground.
- Object: THREE.LOD
- addLevel(mesh, distance, hysteresis)
- Distances in scene units
01 // CODE
Load three levels and switch by distance
- Export three versions of the model from your 3D editor, for example 20,000, 5,000 and 1,000 triangles, as
rock_lod0.glb,rock_lod1.glbandrock_lod2.glb. - Load all three with
GLTFLoader. - Add each one to a
THREE.LODat the distance where it takes over, in scene units (meters for glTF). - Add the LOD to the scene and fly the camera out to check each switch.
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
const loader = new GLTFLoader();
const files = ['rock_lod0.glb', 'rock_lod1.glb', 'rock_lod2.glb'];
const distances = [0, 15, 40];
const gltfs = await Promise.all(files.map((f) => loader.loadAsync(f)));
const lod = new THREE.LOD();
gltfs.forEach((gltf, i) => lod.addLevel(gltf.scene, distances[i]));
lod.position.set(0, 0, -10);
scene.add(lod);
02 // FLICKER
Stop levels flickering at the switch distance
When the camera sits right at a switch distance, small movements can flip the level back and forth. Pass a hysteresis value as the third argument, as in lod.addLevel(mesh, 15, 0.1), so the switch back happens about 10 percent closer than the switch out.
lod.autoUpdate is true by default, so the renderer updates the level for you. If you render one scene with several cameras, set it to false and call lod.update(camera) yourself.
03 // WHAT LOD SAVES
What LOD saves in a browser
LOD cuts the triangles drawn per frame, but the browser still downloads every level. Keep the far levels very light, share one material and texture across levels, and load the detailed level last if the model starts far from the camera.
For hundreds of copies of the same object, InstancedMesh saves more than LOD, because it draws every copy in one call.
04 // meshfx
meshfx for lod in three.js
meshfx reduces toward a triangle budget and makes LODs by count, ratio, explicit budgets or error. Each level reports measured distance, outline and faults. Godot 4 is the supported output target. Hosted meshfx runs are available in the Playground.
What is LOD in three.js?
THREE.LOD is an object that holds multiple mesh versions and displays the appropriate one based on distance from the camera.
How do I set up a three.js LOD object?
Create a THREE.LOD instance, call addLevel with each mesh and switch distance in meters, then add it to your scene.
How do I prevent LOD popping in three.js?
Switch at distances where changes cover few pixels and pass a hysteresis value as the third argument to addLevel.
How much should I reduce polycount between three.js LOD levels?
Cut each level to a quarter or third of the previous mesh, using two lower levels so web downloads stay small.
Explore meshfx outputs
Inspect compiled meshfx outputs and their reports. Hosted meshfx runs are available in the Playground.