2016-08-01 131 views
-1

我有一個用BoxGeometry(w:20,h:20,d)構造的子網格(本地位置0,0,0)的Object3D(位置10,0,30) :20)。爲three.js檢測子網格的碰撞

現在,如果射線與原點(-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

回答

0

爲了Raycaster正確地確定子對象遞歸,我不得不打電話在檢查intersectionObject之前,在父對象上使用updateMatrixWorld()。