asd*_*sdf 4 javascript three.js
交集对象(由 返回raycaster.intersectObject())具有face和faceIndex属性。但是,如果相交对象是 ,则这些属性为 null BufferGeometry。另一方面,该point物业按预期运作。
有什么方法可以确定哪一面被BufferGeometry击中?显然没有faces数组,BufferGeometry但了解(例如)position定义击中面的属性中的点索引会有很大帮助。
(我当然可以使用一些数学,因为我知道所有点的坐标,但这会影响我在大型几何体上的表现)
其实相关代码可以在THREE.Mesh;如果您查看Raycaster.js,您会发现THREE.Raycaster大部分委托给 的(未记录的、抽象的)raycast方法THREE.Object3D。实现此方法的各个子类Object3D,包括Mesh.
相关行THREE.Mesh#raycast显示交集对象如下所示:
{
distance: distance,
point: intersectionPoint,
indices: [ a, b, c ],
face: null,
faceIndex: null,
object: this
}
Run Code Online (Sandbox Code Playgroud)
其中a、b、 和c是相交面上顶点的索引。
这意味着要获取构成相交面的顶点的索引,您可以执行以下操作:
var intersect = raycaster.intersectObject(scene);
if (intersect != null) {
var faceIndices;
if (intersect.face != null) {
faceIndices = [ face.a, face.b, face.c ];
} else if (intersect.indices != null) {
faceIndices = intersect.indices
}
// do something with the faceIndices
}
Run Code Online (Sandbox Code Playgroud)
三.js r68