How to Simplify Meshes by Default with Auto-Lod?

I hope to actively reduce the surface of the imported model, not according to the distance of the camera, in order to adapt to low-performance equipment.

Is this way right now?

   const simplifer = new QuadraticErrorSimplification(m);
  
            const newMesh = simplifer.simplify(
              {
                quality: 0.01,
                distance: 2,
              },
              (mesh) => {
                mesh.rotation = m.rotation;
                mesh.rotationQuaternion = m.rotationQuaternion;
                mesh.position = m.position;
                mesh.scaling = m.scaling;
                mesh.isVisible = true;
                m.setEnabled(false);
              }
            );

It seems ok to me, except simplify does not return the new mesh.

You also have additional properties to tweak the result, see QuadraticErrorSimplification | Babylon.js Documentation and Simplifying Meshes With Auto-LOD | Babylon.js Documentation.

1 Like

When the mesh is copied, will the auto_lod data not be copied together? Does it need to be set for each mesh?

When you use QuadraticErrorSimplification directly, no LODs are set on the mesh: you must do it yourself if you need it.

Note that you can avoid the auto LOD assignment when using mesh.simplify(...) by not setting a distance (leave it undefined). When using QuadraticErrorSimplification directly, the distance parameter is not used (only quality).

1 Like

Is it possible to cache the result when I use mesh.simplify(...)?

The result of the process is a mesh, so you can serialize it to a json object or save it in a file (.babylon / .gltf/glb for eg).

1 Like

Thanks for your answer!