17

As far as I know var point = object.geometry.vertices[i]; will return with the relative position for the x, y and z of the point inside the geometry of the object.

How to get the absolute position, if the object was moved, rotated or scaled?

Wilt
  • 41,477
  • 12
  • 152
  • 203
Danny Fox
  • 38,659
  • 28
  • 68
  • 94

2 Answers2

46

You can get the world position of a vertex like so:

const vertex = new THREE.Vector3(); // create once and reuse

const attribute = object.geometry.getAttribute( 'position' );

vertex.fromBufferAttribute( attribute, index );

object.localToWorld( vertex );

three.js r151

WestLangley
  • 102,557
  • 10
  • 276
  • 276
26

Recent versions of Three.js (v50+) provide this functionality built into the THREE.Object3D class. In particular, to get the world coordinates of a local THREE.Vector3 instance named vector, use the localToWorld method:

object.localToWorld( vector );

Similarly, there is a worldToLocal method for converting world coordinates into local coordinates, which is slightly more complicated, mathematically speaking. To translate a world vector into the objects local coordinate space:

object.worldToLocal( vector );
Stemkoski
  • 8,936
  • 3
  • 47
  • 61
  • ...and don't forget to run object.updateMatrixWorld(); I was scratching my head for a while before I tried that. – arpo Apr 22 '17 at 14:11
  • 1
    Tried doing that... Still get 0, 0, 0 :( – James Heald May 03 '17 at 18:32
  • I’m also totally stuck with this as well!! Spent 5 hrs trying everything here in different ways...nothing, errors, undefined...seriously frustrating!!! – Josh Bowman Jul 24 '18 at 12:57