I'm new in THREE.js.
I'm trying to get 3D coordinates of point on mouse click on the object (not simple objects: Box, Sphere,..) in Canvas.
In detail, I'm working with 3D objects viewer - I have camera (THREE.PerspectiveCamera), mouse controls (rotate, zoom, move), add/remove objects (my own object, loaded using loaders for THREE.js) in scene,.. And I want to add a function, which gets 3D coordinates for clicked point in 3D.
Exactly, I want coordinates of the end point of a ray - begining from mouse click on the camera_near_window and ending to the object's point, I've clicked on..
I tried a lot of ways to do it:
Getting coordinates of point on z=0 plane -- It works fine, but it is on z=0 plane and it is not that I need, cause I have OrbitControls..
THREE.js example - clickable objects -- It uses CanvasRenderer (not WebGLRenderer) and works for a little objects (but works for my project): browser crashes when I load many objects (CanvasRenderer needs 5x more memory then WebGLRenderer).
"How to get object in WebGL 3d space from a mouse click coordinate" - I tried this one too, but
raycaster.intersectObjects
found nothing,intersects
was an empty array (maybe it works for only simple objects like box, sphere,..).
Can anyone show me the demo code which gets 3D point coords for clicked point of clicking object in 3D, please..?
Raycaster
. In your case, you likely want to set therecursiveFlag
to true:raycaster.intersectObjects( objects, true );
– WestLangleyraycaster.intersectObjects(objects, true)
got me an array and the first record had a point parameter, which I needed, thanks.. – GuRAmvar rayCaster = new THREE.Raycaster();
) next to camera declaration, and then I use set (rayCaster.set(camera.position, vector.sub(camera.position).normalize());
) every mouse click; is it right? – GuRAm