Mesh LOD
This section covers how to apply LOD to general Mesh objects. LOD for a Mesh works by calculating the distance from the camera on the CPU every frame and swapping to the Geometry that meets the condition.
1. How it Works
The LODManager inside the Mesh iterates through the registered LOD levels and finds the level with the largest distance value that is less than or equal to the current camera distance. When a suitable level is found, the rendering target is swapped to the geometry registered in that level.
2. Usage
Use mesh.LODManager.addLOD(distance, geometry) to register geometry by distance.
javascript
import * as RedGPU from "https://redcamel.github.io/RedGPU/dist/index.js";
// 1. Create Base Mesh (Distance 0~10)
const mesh = new RedGPU.Display.Mesh(
redGPUContext,
new RedGPU.Primitive.Sphere(redGPUContext, 1, 32, 32),
material
);
// 2. Add LOD Levels
// Distance 10 or more: Sphere (16x16)
mesh.LODManager.addLOD(10, new RedGPU.Primitive.Sphere(redGPUContext, 1, 16, 16));
// Distance 20 or more: Box
mesh.LODManager.addLOD(20, new RedGPU.Primitive.Box(redGPUContext));
scene.addChild(mesh);3. Live Example
Observe how the sphere shape becomes simpler and eventually turns into a box as the distance increases.