我使用Three.js来显示飞机,但我似乎找不到改变它的法线的方法。这是一个具有普通属性的Plane类,那么有没有办法使用它而不是PlaneGeometry呢?
答案 0 :(得分:1)
PlaneGeometry无法改变其法线,实际上总是(0,0,1)。 要使平面几何体面向不同的方向,您需要转换其顶点。这个 通过将Plane对象转换为变换矩阵并应用它来完成 矩阵到PlaneGeometry。以下是生成转换矩阵的代码:
// Assumes that "plane" is the source THREE.Plane object.
// Normalize the plane
var normPlane=new THREE.Plane().copy(plane).normalize();
// Rotate from (0,0,1) to the plane's normal
var quaternion=new THREE.Quaternion()
.setFromUnitVectors(new THREE.Vector3(0,0,1),normPlane.normal);
// Calculate the translation
var position=new THREE.Vector3(
-normPlane.constant*normPlane.normal.x,
-normPlane.constant*normPlane.normal.y,
-normPlane.constant*normPlane.normal.z);
// Create the matrix
var matrix=new THREE.Matrix4()
.compose(position,quaternion,new THREE.Vector3(1,1,1));
// Transform the geometry (assumes that "geometry"
// is a THREE.PlaneGeometry or indeed any
// THREE.Geometry)
geometry.applyMatrix(matrix);
答案 1 :(得分:0)
还有另一种选择可能适合你。您可以使用Mesh类中的 lookAt 方法。此方法继承自Object3D类。您只需指定平面的外观点即可。这样,您可以将PlaneGeometry重用于其他Mesh实例。
var geometry = new THREE.PlaneGeometry( 12, 12 );
var material = new THREE.MeshBasicMaterial( { color: 0x005E99 } );
var plane = new THREE.Mesh( geometry, material );
plane.lookAt(new THREE.Vector3(0.7, 0.7, 0.7));