0

我正在尝试确定光线是否与 three.js 中的对象相交

我的场景设置和显示很好。

我点击我创建的球体,如下所示:

var intersect_objects = [];

//Initialize scene and object and events

scene = new THREE.Scene();
group = new THREE.Object3D();
sphere = new THREE.SphereGeometry(23.8, 60, 60);

//Add meshes and textures etc..

intersect_objects.push(group);

function onDocumentMouseUp(event) {

    event.preventDefault();

    var mouseX = (event.clientX / window.innerWidth)*2-1;
    var mouseY = -(event.clientY /window.innerHeight)*2+1;

    var vector = new THREE.Vector3(mouseX, mouseY, 0.5);
    projector.unprojectVector(vector, camera);

    var ray = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());

    var intersects = ray.intersectObjects(intersect_objects);

    console.log(intersects.length); //Aways 0

}

但 intersects.length 始终为 0。它肯定与球体相交吗?

4

1 回答 1

0

交叉口代码看起来不错;您确定“组”已添加到“场景”并且“球体”已正确添加到“组”吗?如果不查看其余代码,就不可能确定错误可能是什么。请考虑创建一个包含完整代码的 jsfiddle。

此外,也许尝试使用 ray.intersectObjects(scene.children) 进行测试,看看是否有任何东西会记录碰撞。

于 2013-03-23T01:22:48.360 回答