我有一个Object3D(位置10,0,30),其子网格(本地位置0,0,0)由BoxGeometry(w:20,h:20,d:20)构成。
现在,如果光线与原点(-10,0,0)和方向(1,0,0)一起投射并检查交叉点,则检测到交叉点(错误,因为对象不在路径中)。
考虑以下代码:
const THREE = require('three');
let obj = new THREE.Object3D();
let boxGeo = new THREE.BoxGeometry(20, 20, 20);
let mat = new THREE.MeshPhongMaterial();
let mesh = new THREE.Mesh(boxGeo, mat);
obj.add(mesh);
obj.position.set(10, 0, 30);
let raycaster = new THREE.Raycaster(new THREE.Vector3(-10, 0, 0), new THREE.Vector3(1, 0, 0));
let intersects = raycaster.intersectObject(obj, true);
intersects数组的长度为2,而它的长度应为0。
答案 0 :(得分:0)
为了让Raycaster以递归方式正确地确定子对象,我必须在检查intersectionObject之前在父对象上调用updateMatrixWorld()。