Hi there!
I load in a model, traverse through it and can see mesh names perfectly in console.log. Outside this function i try to get acces to these meshes by their names but when i console.log the output it’s “undefined”. I tried a million things (or at leat it feels like it) but i’m getting nowhere. I even tried making the geometry name the same as the mesh name but no difference. Apparently my approach is wrong…
This is my model loading function
function loadModel(){
colorValue = document.getElementById("chaircolor").value;
colorValue = new THREE.Color(colorValue);
let loader = new GLTFLoader().setPath('./models/');
loader.load('chair3207.gltf', function(gltf){
gltf.scene.traverse(function(child){
if (child.isMesh){
if (child.name) {
child.material = new THREE.MeshPhongMaterial({color: colorValue, flatShading: false});
}
console.log(child.name);
}
});
scene.add(gltf.scene);
render();
});
}
And my little test to try access the meshes and manipulate their attributes (this is outside any functions:
let theResult = scene.getObjectByName("cloth", true);
console.log(theResult);
I’m a beginner with javascript and moving forward but this has just caught me up. Hope you can help me out here.
Many thanks,
Henrik