如何得到一个顶点在三个点的绝对位置?

时间:2022-04-03 04:20:55

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.

就我所知,var point = object.geometry. nodes [I];将返回物体几何中的点的x、y和z的相对位置。

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

如果物体被移动、旋转或缩放,如何获得绝对位置?

2 个解决方案

#1


34  

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数学入门》

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

    游戏和交互式应用的基本数学:程序员指南詹姆斯·m·范·弗思和拉尔斯·m·贝肖普。

three.js r69

三。js r69

#2


22  

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:

最新版本的三人。js (v50+)提供了这三种功能。Object3D类。特别是要得到世界坐标的一个局部3。Vector3实例命名为vector,使用localToWorld方法:

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:

同样,有一种worldToLocal方法可以将世界坐标转换成局部坐标,从数学上讲,这有点复杂。将一个世界向量转换为对象局部坐标空间:

object.worldToLocal( vector );

#1


34  

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数学入门》

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

    游戏和交互式应用的基本数学:程序员指南詹姆斯·m·范·弗思和拉尔斯·m·贝肖普。

three.js r69

三。js r69

#2


22  

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:

最新版本的三人。js (v50+)提供了这三种功能。Object3D类。特别是要得到世界坐标的一个局部3。Vector3实例命名为vector,使用localToWorld方法:

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:

同样,有一种worldToLocal方法可以将世界坐标转换成局部坐标,从数学上讲,这有点复杂。将一个世界向量转换为对象局部坐标空间:

object.worldToLocal( vector );