Get new, simplified mesh from Mesh.simplify()

Is it possible to get the new, simplified mesh from Mesh.simplify() as a returned variable? My goal is to simplify a mesh, get the simplified mesh as a variable, and reuse it (cloning or instancing)

Documentation: Simplifying Meshes With Auto-LOD

According to babylon.d.ts, the signature of Mesh.simplify() is:

simplify(
	settings: Array<ISimplificationSettings>,
	parallelProcessing?: boolean,
	simplificationType?: SimplificationType,
	successCallback?: (mesh?: Mesh, submeshIndex?: number) => void
): Mesh;

I thought that mesh from successCallback() would be the new, simplified mesh, but it’s always undefined for me despite the mesh being successfully simplified (visually verified) in the rendered scene…

In the Babylon.js source, I think I see where the newMesh is, but it’s not returned for us to use externally: Source for runSimplification()

Thank you for your help!

I believe this PG has all answers :slight_smile: https://playground.babylonjs.com/#1ED15P#38

        const decimatedMesh = sphere2.getLODLevelAtDistance(100);
        const clonedDecimated = decimatedMesh.clone("SimplifiedMesh");
3 Likes

Thank you so much, @labris :smile:

1 Like

And if you want to vary the parameters of the QuadraticErrorSimplification, you’ll need to call it directly. Note that the simplification occurs asynchronously and takes a few seconds to appear. Set up the sphere in the callback since sphere3 won’t be valid until the callback happens (asynchronously).

Something like this:

2 Likes

Whoa, this is really cool! Thank you for sharing, @HiGreg

You’re welcome. I worked this out a while ago, but your post spurred me to clean it up and (it turns out) generalize to the point where you probably could substitute any function that implements ISimplifier, though I’m not aware of any others.

1 Like