我的原型系统中有一个功能可以在您单击 Collada 文件时检测交叉点。相交函数如下:
function Intersectfun ( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
var toIntersect = [];
THREE.SceneUtils.traverseHierarchy(scene, function (child) {
if (child instanceof THREE.Mesh) {
toIntersect.push(child);
}
});
// Unproject the vector
projector.unprojectVector(vector, camera);
var ray = new THREE.Ray( camera.position, vector.subSelf(camera.position).normalize());
var intersects = ray.intersectObjects( toIntersect );
if(intersects.length){
target = intersects[0].object;
}
}
但是当我使用:
controls = new THREE.TrackballControls( camera, renderer.domElement );
intersects 矩阵为空,无法检测到交叉点!!!
但是当我使用:
controls = new THREE.TrackballControls( camera );
我可以得到 intersects 矩阵,它工作得很好,但是发现了另一个问题(看这里:Three.JS -- conflict Camera controls with a textbox in a scene)
上面的函数中有代码吗?为了您的信息,我使用了一个简单的相机:
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
谢谢。