AssetContainer Support for Instanced Models

I’m posting this in Feature Requests because I don’t think it can quite be called a “bug,” more a holdover from how things used to work.

Mesh.createInstance() seems to assume that there’s a single scene and that the instance must be created there. This has some unexpected effects. If one loads assets to an assetContainer, any instanced models in the container will display immediately, rather than waiting for assetContainer.addAllToScene(). Calling assetContainer.removeAllFromScene() will not remove them. Calling assetContainer.meshes[n].createInstance() will create the instance in the current active scene, rather than adding it to the assetContainer. I haven’t experimented with multiple scenes, but I assume the same would happen.

I think the best solution is to add an optional second parameter, in the manner of MeshBuilder and the other object creation functions: createInstance( name: string, scene?: [Nullable]<Scene>)

I’m afraid AssetContainer would need some updates too, in order to handle instances properly. Perhaps an AssetContainer.instances array. It isn’t safe to assume that an instance will always be tied to the active status of its original, especially when AssetContainer.instantiateModelsToScene() is used.

I would call that a bug :slight_smile:
Can you provide a repro in the PG?

I can do so for parts of the issue. Not sure how to import a custom .babylon file into the Playground–linking to my site throws an origin policy error.

here we are :slight_smile: