Raycaster doesnot work when CombinedCamera is used

Description of the problem

I am building an application like threeJs editor. I have four cameras and each one named differently and positioned diffrently and one of the camera is
cameras['home'] = new THREE.CombinedCamera(window.innerWidth / 2, window.innerHeight / 2, 70, 1, 1000, -500, 1000); cameras['home'].lookAt(centerPoint);

When I use raycaster to work with the selected Camera
raycaster.setFromCamera(mouse, selectedCamera); var intersects = raycaster.intersectObjects([sceneObjects], true);

it throws me this error

‘THREE.Raycaster: Unsupported camera type.’

I edited Three.js from
Raycaster.prototype = { ... setFromCamera: function ( coords, camera ) { if ( (camera && camera.isPerspectiveCamera) ) {

to below
if ( (camera ) ) {
even though the Raycaster is working fine. I just wanted to know Why the camera is not working for CombinedCamera

Three.js version
  • [x ] Dev
  • r81
Browser
  • All of them
  • [x ] Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “Raycaster doesnot work when CombinedCamera is used

  1. I had a similar issue when I made a combined camera (didn’t realise there already was one). I ended up overwriting the raycaster code to handle my camera separately but it looks like there is an easy solution here now.

    The Raycaster code looks like this:

    if ( (camera && camera.isPerspectiveCamera) ) {
        // do perspective things
    } else if ( (camera && camera.isOrthographicCamera) ) {
        // do orthographic things
    }
    

    Perspective camera has these set

    this.type = 'PerspectiveCamera';
    isPerspectiveCamera: true,
    

    Orthographic has these set

    this.type = 'OrthographicCamera';
    isOrthographicCamera: true,
    

    The combined camera however uses these flags

    this.inPerspectiveMode = true;
    this.inOrthographicMode = false;
    

    Maybe the combined camera should instead use the flags isPerspectiveCamera and isOrthographicCamera to be consistent with the standard cameras? This way the combined camera should work as intended and not break the functionality of raycaster with the other cameras.

Comments are closed.