这份文件需要更具体。显然,矩阵在渲染后添加到场景中时会自动更新!!!
因此,在将网格矩阵添加到场景中后,请自行更新网格矩阵:
mesh.updateMatrix();
因此,稍后您可以确保将具有更新值的矩阵传递给applyMatrix()命令!您可以对lines.geometry执行此操作,也可以直接对其本身执行此操作:
lines.applyMatrix4(mesh.matrix);
完整代码如下:
const boxGeo = new THREE.BoxGeometry(
10,
10,
10,
);
const mesh = new THREE.Mesh(
boxGeo,
new THREE.MeshBasicMaterial({
color: "blue",
})
);
mesh.rotation.y = Math.PI / 4;
mesh.position.set(target.x, target.y, target.z);//your coordinates
mesh.updateMatrix(); //!! important!!
scene.add(mesh);
const newBox = mesh.geometry.clone();
const edges = new THREE.EdgesGeometry(newBox);
const lines = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({ color: "red" })
);
scene.add(lines);
lines.applyMatrix4(mesh.matrix);