How to access each mech names including ".babylon" file?

Hi BJS developers.

I made some toy slider parts in Blender 2.8.1 and export them by BabylonJS-BlenderExporter6.3.

Ref : Blender2Babylon-6.3.zip

Exported slider.babylon file seems to work like below. (Lighting setting is not complete)

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.

Thanks very a lot.

Limes

Hey! You may try the

scene.getMeshByName()

method for this ! I think “ID” is used different in BJs! You may use the babylon inspector to check these values up! :relaxed:

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 :slight_smile:

Yeah didn’t see that you also need to move the code :sweat_smile:

Could you point out the difference between “ID” and “Name” in this example plz?

https://playground.babylonjs.com/#Z44DT5#1

here also getMeshByID() returns null, that’s why I thought you may have to use getMeshByName()

getMeshByID looks for meshes by using the id property and getMeshByName uses the name property instead.

@wulf11, @RaananW, @Evgeni_Popov.

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.

Thanks again!

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.