0
我打電話給我,只要我點擊現場。RayCaster停止檢測物體時,我打電話camera.lookAt()
function onMouseDown(event) {
controls.update();
var position = new THREE.Vector3();
position.setFromMatrixPosition(scene.group.children[0].matrixWorld);
position.normalize();
console.log(position);
var raycaster = new THREE.Raycaster(); // create once
var mouse = new THREE.Vector2(); // create once
mouse.x = (event.clientX/renderer.domElement.width) * 2 - 1;
mouse.y = - (event.clientY/renderer.domElement.height) * 2 + 1;
//console.log(mouse);
raycaster.setFromCamera(mouse, camera);
console.log(raycaster.ray.direction);
var intersects = raycaster.intersectObjects(scene.group.children , false);
if (intersects.length > 0) {
intersects[ 0 ].object.material.color.set(0xff0000);
console.log(intersects);
}
}
開始時,我有沒有施加旋轉點擊作品,但只要我打電話
scope.target.x = offset * Math.sin((scope.phi + iphi) * Math.PI/180) * Math.cos((scope.theta + itheta) * Math.PI/180);
scope.target.y = offset * Math.cos((scope.phi + iphi) * Math.PI/180);
scope.target.z = offset * Math.sin((scope.phi + iphi) * Math.PI/180) * Math.sin((scope.theta + itheta) * Math.PI/180);
scope.camera.lookAt(scope.target);
RayCaster不返回任何對象。
我也注意到,即使旋轉之後,我的raycaster也會在屏幕的相同位置給出相同的方向矢量。
然後我試圖在raycaster手動
var e = new THREE.Euler(((controls.phi-90)/180)*Math.PI, 0, (controls.theta/180)*Math.PI, 'XYZ');
raycaster.setFromCamera(mouse, camera);
raycaster.ray.direction.applyEuler(e);
應用旋轉,但現在我在附近由沒有對象的確切位置得到交集。