检测three.js的子网格的碰撞
我有一个Object3D(位置10,0,30),它有一个子网格(局部位置0,0,0),由BoxGeometry(w:20,h:20,d:20)构造 现在,如果使用原点(-10,0,0)和方向(1,0,0)投射光线并检查相交,则会检测到相交(由于对象不在路径中,因此检测不正确) 考虑以下代码:检测three.js的子网格的碰撞,three.js,collision-detection,Three.js,Collision Detection,我有一个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,
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。为了使Raycaster能够递归地正确确定子对象,我必须在检查intersectionObject之前调用父对象上的UpdateMatrix World()