【发布时间】:2015-10-14 01:52:45
【问题描述】:
我是 3D 和 Threejs 的新手。
我设置了一个有地面的场景,地面上有很多立方体。
http://jsfiddle.net/whurp02s/1/
我正在尝试选择穿过黄色矩形的立方体。
所以我在网上查看了示例,发现了 Raycaster 对象和它的 intersectObject 函数
//**************** colision detection
var caster = new THREE.Raycaster();
var collisions = [];
var rays = [
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(1, 0, 1),
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(1, 0, -1),
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(-1, 0, -1),
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(-1, 0, 1)
];
for ( var i = 0; i < rays.length; i += 1 ) {
caster.set( squareTL.position, rays[i] );
for( var boxId in boxGroup ) {
var boxObj = boxGroup[boxId];
collisions = caster.intersectObject( boxObj );
if ( collisions.length ) {
console.log(collisions);
} else console.log("no colision");
}
}
但是发现了 0 个碰撞。
有一些明显的东西我错过了......
【问题讨论】:
标签: javascript three.js collision-detection