THREE.js raycaster intersectObject 方法returns 检查点是否在网格内部时没有相交

THREE.js raycaster intersectObject method returns no intersection when checking if point is inside mesh

我想检查一个点是否在网格内。为此,我使用了光线投射器,将其设置为点的原点,如果光线仅与网格相交一次,则它一定在内部。不幸的是,intersectObject 始终 return 没有交集,即使在我知道该点位于网格内部的情况下也是如此。 点的原点在世界坐标中给出,网格的 matrixWorld 也是最新的。此外,我将 mesh.material.side 设置为 THREE.DoubleSide,以便检测到内部的交叉点。我也尝试将递归属性设置为 true,但正如预期的那样,这没有任何效果(因为网格是一个长方体几何体)。网格来自 Autodesk Forge 查看器界面。 这是我的代码:

mesh.material.side = THREE.DoubleSide;
const raycaster = new THREE.Raycaster();
let vertex = new THREE.Vector3();
vertex.fromArray(positions, positionIndex);
vertex.applyMatrix4(matrixWorld);
const rayDirection = new THREE.Vector3(1, 1, 1).normalize();
raycaster.set(vertex, rayDirection);
const intersects = raycaster.intersectObject(mesh);
if (intersects.length % 2 === 1) {
   isPointInside = true;
}

顶点看起来像这样(它显然位于边界框内):

网格是一个具有以下边界框的盒形房间:

网格看起来像这样:

网格的几何形状包含 vb 中的顶点。应用世界矩阵后,网格顶点在世界 space 中是正确的。这是 vb 列表的一部分:

为什么 raycaster 没有 return 任何交点?计算交点时是否考虑了网格的矩阵世界?

感谢您的帮助!

请注意,Forge Viewer 基于 three.js 版本 R71,它必须 modify/reimplement 库的某些部分来处理大型和复杂的模型(尤其是架构和基础设施设计),因此 THREE.Mesh 对象的结构可能略有不同。在那种情况下,我建议使用 Forge Viewer 自己的机制进行光线投射,例如,使用 viewer.impl.rayIntersect(ray, ignoreTransparent, dbIds, modelIds, intersections);.