Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coordinates of clicked object relative to the same clicked object

Tags:

three.js

I have rotating object (sphere). When I click on an object, I get coordinates relative to camera by:

var raycaster = new THREE.Raycaster();
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( cameradestinations, true );

How can I get this coordinates relative to clicked object position, not to scene center?

(yes I can make clicked.point - clicked.position, but is here something smarter? )

like image 651
Martin Avatar asked Oct 19 '22 12:10

Martin


1 Answers

If you have a vector with World coordinates and want them in an objects Local space, you can use the .worldToLocal() method in Object3D class.

intersectedObject.worldToLocal(point);
like image 162
micnil Avatar answered Jan 04 '23 06:01

micnil