2

I am trying to use a THREE.raycaster to trigger the download of a .obj file when it is clicked on. For some reason I keep getting a THREE.Raycaster: Unsupported camera type error. I am using a a THREEPerspectiveCamera. I am using a grid of canvases and rendering a different object to each- could this be why I am getting the error? Help!

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 );
    };
}

also

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');
    }

}
HariV
  • 687
  • 1
  • 10
  • 17
  • 1
    the error is generated from the `Raycaster` class `setFromCamera` function and can be seen [HERE](https://github.com/mrdoob/three.js/blob/master/src/core/Raycaster.js#L76). It just checks `camera.isPerspectiveCamera`. I suspect you may be having variables scoping issue as you set the `camera` variable inside your `View` function, maybe. – 2pha Dec 31 '17 at 03:36

0 Answers0