Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  86] [ 3]  / answers: 1 / hits: 74378  / 11 Years ago, thu, october 17, 2013, 12:00:00

I'm generating objects from an array which I've defined like this (It's not limited to these three):



var links = [['Linkedin','img/linkedin.png','-300','-230', '600'],
['Google+', 'img/google.png', '0', '-230', '600'],
['Twitter', 'img/twitter.png', '300', '-230', '600']];


Now it goes through the each loop to create and add the objects to the scene by Three.JS like this:



$.each(links, function(i, item) {
var thisItemTexture = THREE.ImageUtils.loadTexture(item[1]);
thisItemGeo = new THREE.CubeGeometry(60, 60, 60,1 ,1 , 1);
thisItemMat = new THREE.MeshBasicMaterial({map: thisItemTexture });
thisItem = new THREE.Mesh(thisItemGeo, thisItemMat);
scene.add(thisItem);
thisItem.position.x = item[2];
thisItem.position.y = item[3];
thisItem.position.z = item[4];
thisItem.castShadow = true;
thisItem.receiveShadow = true;
});


The question is:
How can I access the objects that I've made in the each loop above?


More From » three.js

 Answers
9

You can do this:



myObject.name = objectName;
...
var object = scene.getObjectByName( objectName );


or to recursively search the scene graph



var object = scene.getObjectByName( objectName, true );


Alternatively, you can search by ID.



var object = scene.getObjectById( 4, true );


three.js r.61


[#74925] Wednesday, October 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynnb

Total Points: 402
Total Questions: 96
Total Answers: 109

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
kaitlynnb questions
;