1
在我的原型系统中有一个功能,用于在您单击Collada文件时检测相交。相交功能如下:Three.JS-在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);
的交叉矩阵是空的,无法检测到十字路口!
但是当我使用:
controls = new THREE.TrackballControls(camera);
我能得到的交叉矩阵,它工作得很好,但另一个问题是发现(在这里看看:Three.JS -- conflict Camera controls with a textbox in a scene)
是否有任何的代码在以上功能?为了您的信息,我使用了一个简单的相机:
camera = new THREE.PerspectiveCamera(40, window.innerWidth/window.innerHeight, 1, 10000);
谢谢。