简体   繁体   English

如何在three.js中获取顶点的绝对位置?

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

As far as I know var point = object.geometry.vertices[i]; 据我所知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. 将返回对象几何内部的点的xyz的相对位置。

How to get the absolute position, if the object was moved, rotated or scaled? 如果物体被移动,旋转或缩放,如何获得绝对位置?

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. 您可能想阅读一些CG参考书。

  1. 3D math primer for graphics and game development / by Fletcher Dunn and Ian Parberry 用于图形和游戏开发的3D数学入门/由Fletcher Dunn和Ian Parberry完成

  2. Essential Mathematics for Games and Interactive Applications: A Programmer's Guide James M. Van Verth and Lars M. Bishop 游戏和交互式应用的基本数学:程序员指南James M. Van Verth和Lars M. Bishop

three.js r69 three.js r69

Recent versions of Three.js (v50+) provide this functionality built into the THREE.Object3D class . 最新版本的Three.js(v50 +)提供THREE.Object3D内置的这一功能。 In particular, to get the world coordinates of a local THREE.Vector3 instance named vector , use the localToWorld method : 特别是,要获取名为vector的本地THREE.Vector3实例的世界坐标,请使用localToWorld方法

object.localToWorld( vector );

Similarly, there is a worldToLocal method for converting world coordinates into local coordinates, which is slightly more complicated, mathematically speaking. 类似地,有一个worldToLocal方法可以将世界坐标转换为局部坐标,从数学上讲,这种方法稍微复杂一些。 To translate a world vector into the objects local coordinate space: 要将世界vector转换为对象局部坐标空间:

object.worldToLocal( vector );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM