我试图使用Raycaster找到来自'child'和网格(child2)的光线之间的交叉点:
var raycaster = new THREE.Raycaster();
var meshList = [];
meshList.push(child2);
for (var i = 0; i < child.geometry.vertices.length; i++) {
var diff = new THREE.Vector3();
diff.subVectors (child.geometry.vertices[i],child2.position);
raycaster.set(child.geometry.vertices[i],diff.normalize());
var intersects = raycaster.intersectObjects( meshList );
console.log(intersects[0].point);
}
但是上面的代码在最后一行给出了错误(console.log(intersects [0] .distance)):“TypeError:undefined不是一个对象(评估'intersects [0] .point')”。
如何提取光线和'child2'网格之间的交叉点?
答案 0 :(得分:0)
测试以确保确实有结果!
var intersects = raycaster.intersectObjects( meshList );
if (intersects.length) {
console.log(intersects[0].point);
} else {
console.log('ha, you missed me');
}