我正在尝试使用THREE.raycaster在单击时触发.obj文件的下载。出于某种原因,我一直得到一个THREE.Raycaster:不支持的相机类型错误。我正在使用THREEPerspectiveCamera。我正在使用画布网格并为每个画布渲染不同的对象 - 这可能是我收到错误的原因吗?救命!
var projector = new THREE.Projector();
var directionVector = new THREE.Vector3();
var SCREEN_HEIGHT = window.innerHeight;
var SCREEN_WIDTH = window.innerWidth;
var mouse;
var objects = [];
raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
init();
animate();
//camera
function View( canvas, fullWidth, fullHeight, viewX, viewY, viewWidth, viewHeight ) {
canvas.width = viewWidth * window.devicePixelRatio;
canvas.height = viewHeight * window.devicePixelRatio;
var context = canvas.getContext( '2d' );
var camera = new THREE.PerspectiveCamera( 20, viewWidth / viewHeight, 1, 10000 );
camera.setViewOffset( fullWidth, fullHeight, viewX, viewY, viewWidth, viewHeight );
camera.position.z = 75;
this.render = function () {
camera.lookAt( scene.position );
renderer.render( scene, camera );
context.drawImage( renderer.domElement, 0, 0 );
};
}
也
function onDocumentMouseDown( event ) {
event.preventDefault();
var mouseX = (event.clientX / window.innerWidth)*2-1;
var mouseY = -(event.clientY /window.innerHeight)*2+1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( objects );
if ( intersects.length > 0 ) {
console.log( 'click');
}
}