Three.js: Conversion world coordinates <-> object3D coordinates

Created on 5 Jan 2012  ·  3Comments  ·  Source: mrdoob/three.js

Hello,

What I don't manage to do is to determine the world coordinates (position & rotation) of an object3D which can be the child of multiple other object3Ds.

In my application, I have assemblies and subassemblies including 3D models that can be translated and rotated. The position and rotation values of the object3Ds are relative to the parent, but I'd also like to be able to display the absolute values of those object3Ds.

When only translations of the parents are involved it is pretty easy to define the absolute values as it is just a shift for the position but it is when rotations are also included that I'm kinda lost!

Thanks for your time.

Question

All 3 comments

var worldPosition = object.matrixWorld.getPosition();

This GETS world position of an object. How do you SET world position of an object?

(Updating since this still comes up in google results)
The above technique is deprecated

var worldPosition = new THREE.Vector3().setFromMatrixPosition(object.matrixWorld);

or

var worldPosition = new THREE.Vector3();
object.localToWorld(worldPosition);
Was this page helpful?
0 / 5 - 0 ratings