Incorrect camera loading while using ColladaImporter

I'm trying to figure out how to get the cameras stored within my collada file to render properly. On loading the scene using ColladaImporter, i can see that the model correctly stores the two objects as well as the light and camera as children of the rootNode, and upon further investigation, the camera child of the rootnode even reveals the correct position when getLocalTranslation is called on it.

However, when i try to call ColladaImporter.getCameraNode(…) to get the information about the camera that should be used to render the scene, the camera information says that the camera is located at the origin and is looking up the z axis (this is wrong), and when rendering, the camera is either initially looking in the wrong direction, or is not looking into the scene at all (rotation fails to bring the objects into view either due to bad looking around on my part, or (more likely) that the camera can't see the scene.

Is there something special that i'm missing in order to properly store the camera information in the cameranodes, or is this a bug with the latest release? I haven't had any luck finding anything like this on the forums or in the documentation.

Your Z come from 3dstudio right?

I have do some test too and i solve some problem in that way:



        camNode = ColladaImporter.getCameraNode("Camera-camera");
        camNode.lookAt( new Vector3f( 10, 10, 10 ), Vector3f.UNIT_Y );
        camNode.updateGeometricState(0, true);
        rootNode.attachChild(camNode);
        input = new NodeHandler( camNode, 30, 2 );



my unique problem still remain to controll the CameraNode... Try it and let me know..

Err, that's actually not what talyn and me are looking for.

You are just grabbing the camera node and giving it the information where to look at (which should be in the collada file).

But we are getting collada files from a designer and we would like to use the cameras exactly the way they are positioned inside the collada file.

Any other hints?

I've finally managed to figure out what's involved in creating a camera from those found while parsing a collada scene file (*.dae).

It turns out that the cameras specified by the library_cameras field in a collada file are simply the information about how the camera views the scene, and that the information regarding positioning and orientation of the camera is stored within the visual scene itself, and the cameras (with locations and positions) then reference the library_cameras to specify the view type of the camera.



As a result of this, it is not possible to create a camera by calling getCameraNode( nodeID ).getCamera because the camera stored within the node doesn't actually hold any information about the camera itself. The real information is stored in the node's parent, and must then be converted into the proper format for applying to a camera.

Also, since the camera information provided in library_cameras may be used by any of the scenes in the collada file, it is possible that the scene you wish to render is not using all the cameras in the library of cameras, or that a single camera is reference by multiple visual_scenes.

This second possiblity is a bit of an issue since the camera may only have one parent when it is inserted into the scenegraph; thus, if the collada file being loaded references a camera from the library in more than one scene, only the last scene will have the light attached, because it is removed from the previous scenes as it is attached to the later scenes.



Thus, if you can assume that the scene you are trying to render is either the last one, or there are otherwise no conflicts with cameras between scenes, it is possible to keep track of the cameras which are pertinent to your scene by checking to see if they have a parent:


      // store cameras
      cameras = new ArrayList<CameraNode>();
      ArrayList<String> cameranames = ColladaImporter.getCameraNodeNames();
      itr = cameranames.iterator();
      while (itr.hasNext()) {
         String name = (String) itr.next();
         CameraNode cn = ColladaImporter.getCameraNode(name);

         // only keep track of cameras in the scenegraph
         if (cn.getParent() != null) {
            cameras.add(cn);
            if (curcam == -1)
               curcam = 0;
         }
      }



Once the cameras have been filtered down, a camera can then be created from any of the camera nodes in the scene by performing the following:


      // create the camera
      CameraNode cn = cameras.get(curcam);
      Camera c = display.getRenderer().createCamera(display.getWidth(),
            display.getHeight());
      System.out.println("creating viewport for camera #" + curcam + " ("
            + cn.getParent().getName() + ")");

      // set up a perspective camera
      transferFrustrumInfo(cameras.get(curcam).getCamera(), c);
      c.setParallelProjection(false);

      // get camera information from cameranode
      Vector3f loc = cn.getParent().getLocalTranslation();
      Quaternion rot = cn.getParent().getLocalRotation().opposite();
      c.setFrame(loc, rot);

      // slight compatibility for camera orientation adjustment
      // if ( c.getUp().y < 0 )
      // c.setLeft(c.getLeft().negate());
      // c.setUp(new Vector3f(0,1,0));

      // print some camera information
      System.out.println("location: " + loc);
      System.out.println("rotation: " + rot);
      System.out.println("up_vec:   " + c.getUp());

      // update camera
      c.update();



As you can see, there is a commented section that provides the ability to turn the camera right side up, as this algorithm tends to result in cameras that are upside down in some instances.
If anyone manages to figure out why the orientation of the cameras are not being interpreted correctly when the rotation quaternion is being passed to the setFrame function, please let me know.