I expected the scene from callback function is the loaded scene model. But nope, it’s actually the scene in which the modal is loaded. Is there no way to get the loaded object?
My current solution is scene.getMeshByName('__root__'). But this is just a workaround. It’s because the glb has that root node. What if you load multiple models? The funciton must return the loaded model, not the same scene you have already access to. It makes no sense.
const model = await SceneLoader.ImportMeshAsync('', './assets/cube.glb');
// Now you can work with that.
const modelRoot = model.meshes[0];
if (modelRoot && this.transformNode) {
modelRoot.parent = this.transformNode;
}
It’s still a bit weird in babylon.js. For example, why is my model added to the scene when no scene is passed to the function? Can I load models without directly adding it to scene (add it later)?
Btw. it would be better when babylon.js just let gives me a root object (transformNode). Instead of accessing the meshes array (which has 5 entries for my simple cube). Not sure but there is also a transformNode array with only one entry which also works well to e.g. move the model. I would only have one transformNode which is the root object. Not sure, but this seems to be the better solution. The transformNode also has the name of my root object I had in Blender. You can inspect it in chrome (console.log(model)).
Interessting. Babylon is a bit weird. You still need to pass the scene. And if not, babylon uses a global variable to acces the last created scene. I expected something like (pseudo code, similar to three.js):
const model = await Loader.load('path/to/model.glb');
scene.add(model.scene);
Babylon has a bit different logic, but I hope you’ll be quite comfortable with it quite soon. Besides the documentation there is a lot of examples as well.