There is a function in my code that loads objects from .obj files in a specific way:
function loadObject(obj, mtl, clr, opc, px, py, pz, rx, ry, rz, cs, rs, name) {
switch(mtl) {
case 'transparent':
var material = new THREE.MeshLambertMaterial({
color: clr,
transparent: true,
opacity: opc,
});
break;
case 'web':
var material = createElementMaterial('img/web.png');
break;
case 'basic':
var material = new THREE.MeshBasicMaterial({ color: clr });
break;
default:
var material = new THREE.MeshLambertMaterial({color: clr, transparent: true, opacity: opc});
break;
}
var objLoader = new THREE.OBJLoader();
objLoader.load(obj, function(mesh) {
globalobject = mesh;
globalobject.name = name;
mesh.traverse(function(node) {
if(node instanceof THREE.Mesh) {
node.castShadow = cs;
node.receiveShadow = rs;
node.material = material;
node.position.x = px;
node.position.y = py;
node.position.z = pz;
node.rotation.x = rx;
node.rotation.y = ry;
node.rotation.z = rz; }
});
scene.add(mesh);
});
}
Now, I want to assign a unique name to each loaded object and be able to control its properties like opacity using getObjectByName(). When I load an object and try to access it by name, the console returns undefined. However, when I directly query the console, I can print the object successfully. Therefore, I am looking for a solution to individually access each object loaded from .obj files.