检测 three.js 子网格的碰撞
detect collision for child mesh for three.js
我有一个 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);
相交数组的长度为 2,而它的长度应为 0。
为了让 Raycaster 正确地递归确定子对象,我必须在检查 intersectionObject 之前调用父对象的 updateMatrixWorld()。
我有一个 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);
相交数组的长度为 2,而它的长度应为 0。
为了让 Raycaster 正确地递归确定子对象,我必须在检查 intersectionObject 之前调用父对象的 updateMatrixWorld()。