I have an issue regarding the Raycaster model. I understand the idea and the fact that it intersects meshes, which I can transform, but for example, if I create JS objects that have an inner THREE.Object3D that groups meshes (for their UI), how can I know when the corresponding instance of an object is clicked?
Imagine a button. This button has several characteristics and an inner _model that holds it's THREE.js graphical form (let's say a boxGeometry and a textGeometry that build this button). When the button is added to the scene it adds its buttonInstance.getModel() to the scene, and adds itself to a repository of objects to keep a reference to it.
If I wanted to click this button, I create a raycaster and get the intersecting objects from an array of "buttons" (Objects 3D or Meshes that represent this object).
But how do I fire an event or interact with the button instance itself? I have the mesh but can't get the idea on how to link it with the instance itself.
Any clues? I've searched a lot about raycasting in THREE, but all the examples relate to changing colors or positions of meshes.
_raycaster.setFromCamera(new THREE.Vector2(0,0), _camera);
_activeBtns = _raycaster.intersectObjects(_buttons, true);
_activeBtns[0].object.parent.position.set(curPos.x, curPos.y, curPos.z-.2); // alter position of the Object3D that holds textMesh and BoxMesh
But how do I even know which button is this one that has been 'clicked' if all buttons have two meshes and I dont see a way of idetifying them once they are in the scene?
Thanks
d
mesh.name = 'button' or mesh.type = 'text'
and later checkif(_activeBtns[0].name === 'button'
) – uhuratype
property of a three.js object. UseuserData
, instead:mesh.userData.type = 'text'
. – WestLangley