Clone mesh without appending to Scene automaticlly?

when using LoadAssetContainerAsync, before calling addAllToScene , i want to clone a mesh, and do some work , then mannually append it to scene.But babylon just append the copy to Scene right after const cloned = myMesh.clone(). Even when passing null to the second param doesn’t work.I’ve done a lot of search but still havn’t a idea.please help :sob:

modelClone | Babylon.js Playground (
Unfortunately, clone doesn’t seem to have the option not to add to the scene, but it is possible to remove it from the scene by calling scene.removeMesh(rootMesh, true) as soon as it is cloned, and to add it again to the scene with scene.addMesh(rootMesh, true) if needed.


Thanks! besides, to make the loaded assets be like an ‘asset library’, then reuse it on demand(clone and transform, thin instancing…etc) without reloading, and keep the original one clean.The only approach would be makeGeometryUnique() after clone the mesh?

The reason I want to copy without appending is, I want to do some common transformations from A, and apply some different and independent transforms then append to scene(A->B->C,A->B->D). So, the common transforms should be a temporary state(B), and should not be appended to scene directly.

If you look at the playground, you’ll see that the modelClone function has a mesh traversal after the clone is called. This is because mesh.clone only clones mesh, and the cloned copy shares geometry material skeletons animationGroups morphTargetManager with the source mesh.
My program doesn’t do edits to geometry, so clone geometry in modelClone.
Replicas sharing these references have the advantage of reducing memory footprint, and the disadvantage of editing them will affect all meshes that reference the same resource, such as geometry material.
Therefore, it is necessary to make flexible choices and manage them according to the actual situation.

1 Like

There is also a heavier method, which is to store the requested binary file to indexDB, and each time you need to take it directly from indexDB to create a temporary address, and then use the loader to load a new assetContainer, this method is different from cloning, you can create two completely unrelated asset objects, and of course, the memory usage is also directly doubled.

Thanks,this is handy :heart:. When I used three.js before, I implemented this feature manually. I never thought that it would be available out of the box in babylon.