如何在three.js中获得立方体所有角的确切x,y,z位置

问题描述 投票:0回答:1

another answer to this question,但是在实现它之后,我看到这些位置不是顶点的绝对x,y,z位置的真实表示。我检查了网格,并查看了geometry:BoxGeometry属性中的_corners数组。在这里我也可以找到值。如果立方体在两个不同的轴上旋转,并在x和z轴上移动,则角位置的y值不会更改,因此,它们不是角的x,y和z位置的准确值。我可以清楚地看到拐角位置在x,y和z轴上移动。

我还能如何得出这些角的准确的绝对位置?到目前为止,我找不到确定该属性的属性。我需要使用带有这些角位置的旋转值来应用某种数学吗?

three.js rotation position vertices
1个回答
1
投票

您只需要获取多维数据集的WorldMatrix(其中包含所有转换),并将其应用于具有原始顶点位置的Vector3:

var w = 10;
var h = 15;
var d = 7;

const geom = new THREE.BoxBufferGeometry(w, h, d);
const mat = new THREE.MeshBasicMaterial();
const box = new THREE.Mesh(geom, mat);

// Get world matrix transformation of the box
var boxMatrix = box.matrixWorld;

// Set the initial position of the desired vertex into a Vector3
var vertex = new THREE.Vector3(w / 2, h / 2, d / 2);

// Apply the matrix transformation to the vector
vertex.applyMatrix4(boxMatrix);

// Read the result
console.log(vertex);
© www.soinside.com 2019 - 2024. All rights reserved.