In my project, I’m using BABYLON.SceneLoader.ImportMeshAsync in order to load several assets (in GLTF format) to build my scene.
This said, I wonder the way to dispose all the assets (mainly meshes, materials, textures and animations) coming with a specific file (GLTF) from the scene, but leaving untouched the rest. It would be a kind of anti-import ( ), you know.
I believe the easiest way which gives the full control is to create an array with the list of imported meshes. When you need to dispose the loaded GLTF just dispose meshes from this list until it will be clear. Mesh.dispose() has the flag disposeMaterialAndTextures to dispose associated materials and textures when true - Mesh | Babylon.js Documentation
To dispose animations associated with the mesh one needs to go through the array of mesh.animations - Mesh | Babylon.js Documentation
Wow, I didn’t know about the disposeMaterialAndTextures flag, great stuff! And of course, It would be nice to have another one named “disposeAnimations”.