Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检测three.js的子网格的碰撞_Three.js_Collision Detection - Fatal编程技术网

检测three.js的子网格的碰撞

检测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,

我有一个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。

为了使Raycaster能够递归地正确确定子对象,我必须在检查intersectionObject之前调用父对象上的UpdateMatrix World()