2

我正在尝试使用 THREE.raycaster 在单击时触发 .obj 文件的下载。出于某种原因,我不断收到 THREE.Raycaster: Unsupported camera type 错误。我正在使用一个 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');
    }

}
4

0 回答 0