1
我爲mouseMove和mouseDown寫了兩個非常類似的函數。雖然前者工作正常,後者繼續從var intersects = ray.intersectScene(scene)獲取空對象。three.js intersectScene獲取空對象
您可以在這裏找到完整的代碼 http://converteveryunit.com/pot/biluochun/temp/ 謝謝。
function onDocumentMouseMove(event) {
mouseX = event.clientX - homeWidth/2;
mouseY = event.clientY - homeHeight/2;
var vector = new THREE.Vector3((event.clientX/homeWidth) * 2 - 1, - (event.clientY/homeHeight) * 2 + 1, 0.5);
projector.unprojectVector(vector, camera);
var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize());
var intersects = ray.intersectScene(scene);
}
function onDocumentMouseDown(event) {
event.preventDefault();
var vector = new THREE.Vector3((event.clientX/homeWidth) * 2 - 1, - (event.clientY/homeHeight) * 2 + 1, 100);
projector.unprojectVector(vector, camera);
var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize());
var intersects = ray.intersectScene(scene);
console.log(intersects);
}