I am pretty new to babylon and web graphics but I think it is the right tool for what I want to do. I have managed to import obj file into babylon but I can’t manage to access/modify the meshes from this file individually?
I have tried to access them by scene.getMeshByName and byID and UniqueID (got from sandbox)
I have also tried to convert the obj into a .babylon file but the Blender plugin fails with an error hence why I am dealing with obj files.
Traceback (most recent call last):
File "...\Blender Foundation\Blender\2.83\scripts\addons\babylon_js\__init__.py",
line 65, in execute
exporter.execute(context, self.filepath)
File "...\Blender Foundation\Blender\2.83\scripts\addons\babylon_js\json_exporter.py", line 115, in execute
mesh = Mesh(object, scene, self)
File "...\Blender\2.83\scripts\addons\babylon_js\mesh.py", line 158, in __init__
mat.processImageTextures(bpyMesh)
File "...\Blender Foundation\Blender\2.83\scripts\addons\babylon_js\materials\material.py", line 79, in processImageTextures
tex.process(self.exporter, True, bpyMesh)
File "...\Blender Foundation\Blender\2.83\scripts\addons\babylon_js\materials\texture.py", line 84, in process
self.uvMapName = bpyMesh.data.uv_layers.active.name
AttributeError: 'NoneType' object has no attribute 'name'
location: <unknown location>:-1
It seems that the “StanfordBunny.obj” in your example does not contain multiple meshes!
So you won’t be able to move the “ears” mesh, because there is no separation in it.
You can check the scene via the inspector. Just click on the options-icon in the playground (top right) and click on “inspector”. You can then check the nodes of the scene.
I may suggest you to replicate your example with the “candle.babylon” file. This one has multiple meshes in it.
My .obj (linked first post) has multiple nodes in it, so how do I access them individually via getMeshBy_? I will try with candle like you suggested when I get back to my desk
Well I took some time and tested a PlayGround with the file you provided.
Btw you can easily use external assets via DropBox (if you have an account there).
I used the BABYLON.SceneLoader.ImportMesh-Method. like this:
BABYLON.SceneLoader.ImportMesh(
"",
"https://dl.dropbox.com/s/s8qybdnnsk5w36r/",
"website.obj",
scene,
function (meshes) {
scene.createDefaultCameraOrLight(true, true, true);
scene.createDefaultEnvironment();
//log the name of the meshes we just imported
for(var i = 0; i < meshes.length; i++){
console.log(meshes[i].name);
}
var wallsMesh = scene.getMeshByID("walls");
wallsMesh.isVisible = false;
}
);
Note!
I deleted the website.obj, so the example won’t work with my link anymore…so feel free to host it yourself or try it in your local dev-environment!
I think your problem was not the scene.getMeshByID()-method. I guess you placed the call in the wrong place?! You have to make sure that everything is loaded before accessing the mesh (e.g. via the onSucess?-callback function in the ImportMesh()-method).
You are welcome
If you want to use the variable from anywhere, then declare it outside of the onSucess-function!
Otherwise the scope will be only in the function!