Three JS - How to access the object loaded from .obj by name?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Three JS - How to access the object loaded from .obj by name?



I got a function which loads objects from .obj files this 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 need to name each loaded object and control its properties such as opacity etc. by using getObjectByName(). The objects get loaded and follow the function rules but when I load an object and try to access it by name, I get an undefined output from console and it's when I can print the object when I send query to console by typing in it directly.
So, in another hand, I'm looking for a way which allows me to access each loaded object from .obj files.



Thank you









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS