The movie below was developed by Unity. I’d like to make similar one in Babylon.js.
I try to get each mesh from imported mesh data but failed. In the following code, I expected “ShortRail_2” mesh (It’s showed in the above debug layer) The result of the console log is “the name is null”.
BABYLON.SceneLoader.ImportMesh("","","./model/slider_rail_forBabylonjs_join2.babylon",
scene,function(newMeshes,particleSystems,skeltons) {
// importedMeshes = newMeshes.meshes;
});
var mesh= scene.getMeshByID("ShortRail_2");
console.log("the name is :"+mesh);
My code is pushed on github.
Sorry for my basic question. I could not find good answers from official doc or forums.
If some guys know about appropriate pages or hints, It’s be helpful for me.
The problem here is that you are running this code before the mesh was loaded. Move the getMeshBy (name of ID) call into the onSuccess loop:
BABYLON.SceneLoader.ImportMesh("","","./model/slider_rail_forBabylonjs_join2.babylon",
scene,function(newMeshes,particleSystems,skeltons) {
// importedMeshes = newMeshes.meshes;
var mesh= scene.getMeshByID("ShortRail_2");
console.log("the name is :"+mesh);
});
or use the newMeshes array to find your new mesh and do whatever you want with it
Thanks for your kind and quick reply. The following code works.
BABYLON.SceneLoader.ImportMesh("","","./model/slider_rail_forBabylonjs_join2.babylon",
scene,function(newMeshes,particleSystems,skeltons) {
mesh= scene.getMeshByName("ShortRail_2");
console.log("the name is :"+mesh.name);
});
I’m new to Blender 2.8. I don’t know which cause the problem my 3D modeling or BJS code.
In the blender exporter, they are set to the same value. ID is really used by the Max exporter, I think. It puts some code string in the ID, and the user puts in the name.