How to get the absolute position of a vertex in three.js?

﹥>﹥吖頭↗ 提交于 2019-12-27 13:57:07

问题


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?


回答1:


First make sure the object's matrices have been updated.

object.updateMatrixWorld();

The render loop usually calls this for you.

Then, do this:

var vector = object.geometry.vertices[i].clone();

vector.applyMatrix4( object.matrixWorld );

The vector will now contain the position in world coordinates.

You might want to read some CG reference books.

  1. 3D math primer for graphics and game development / by Fletcher Dunn and Ian Parberry

  2. Essential Mathematics for Games and Interactive Applications: A Programmer’s Guide James M. Van Verth and Lars M. Bishop

three.js r69




回答2:


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 );


来源:https://stackoverflow.com/questions/11495089/how-to-get-the-absolute-position-of-a-vertex-in-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!