gpt4 book ai didi

javascript - 识别 BufferGeometry 上光线转换相交的面

转载 作者:行者123 更新时间:2023-11-29 14:54:17 24 4
gpt4 key购买 nike

交集对象(由 raycaster.intersectObject() 返回)具有 facefaceIndex 属性。但是,如果相交对象是 BufferGeometry,则这些属性为 null。另一方面,point 属性按预期工作。

有什么方法可以确定 BufferGeometry 的哪个面被击中了吗? BufferGeometry 中显然没有 faces 数组,但知道(例如)定义命中面的 position 属性中的点索引会有很大帮助.

(我当然可以使用一些数学,因为我知道所有点的坐标,但这会降低我在大型几何体上的表现)

最佳答案

其实相关代码可以在THREE.Mesh中找到;如果你看Raycaster.js ,你会看到 THREE.Raycaster主要代表(未记录,摘要)raycast THREE.Object3D的方法| . Various subclasses of Object3D implement this method , 包括 Mesh .

relevant lines from THREE.Mesh#raycast 显示交集对象如下所示:

{
distance: distance,
point: intersectionPoint,
indices: [ a, b, c ],
face: null,
faceIndex: null,
object: this
}

哪里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
}

three.js r68

关于javascript - 识别 BufferGeometry 上光线转换相交的面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20553230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com