javascript - With three.js, can I attach information to an object, such as a URL? -


i have webgl question related three.js. attach information object. instance, when click on object, retrieve information that's tied object, url, , run function using information.

the code i'm using finding object is:

    var vector = new three.vector3((event.clientx / window.innerwidth) * 2 - 1, -(event.clienty / window.innerheight) * 2 + 1, 0.5);     projector.unprojectvector(vector, camera);      var raycaster = new three.raycaster(camera.position, vector.sub(camera.position).normalize());      var intersects = raycaster.intersectobjects(objects);      intersects[0].object.material.color.sethex(math.random() * 0xffffff); 

the last line being how i'm manipulating object. array objects array of of objects. issue don't know enough how raycaster or intersectobjects works, or enough how tie information object can recalled later.

indeed can set custom user data object in three.js. key here object3d basis scene graph objects. docs have property called

object3d.userdata;  

this can loaded object of choice , when raycaster class retrieves intersect can access directly @ point.

setter during init or runtime

object3d.userdata = { url: "http://myurl.com" }; 

getter on collision

window.location = intersects[0].object.userdata.url; 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -