Loading .babylon scene as a child of a specific scene graph node

There is some confusion in these posts, so I will try to clear some things up. SceneLoader has multiple ways for loading an asset (Load, Append, ImportMesh, and LoadAssetContainer), all of which have an async counterpart that returns a promise instead of using callbacks. Load will load into a new scene. Append will append to an existing scene. The only methods that will give you the meshes that come from the asset are ImportMesh and LoadAssetContainer.

Here is a PG using ImportMeshAsync that will do what you want that should work with either glTF or babylon files: https://playground.babylonjs.com/#8FHM4P#2. I’ve modified some code to make them more correct based on your PG.

If you are strictly working with glTF, the loader guarantees that a __root__ node will be created and it will be meshes[0] of the resulting meshes for ImportMesh and thus you can just parent this mesh instead of looping.

There should be a way to do this with asset containers also.

(copy the code, hit TS , then paste the code back in, because he editor starts it as JavaScript even though I selected TypeScript)

The way the playground determines whether it’s TS or JS is by checking for the string class Playground. If you don’t have that string, it will default to JS.

I personally would like to improve the way we load assets to make it more obvious and easier to pass in options, but we keep backwards compatibility around here, so it will take some effort to make this happen.

1 Like