Blender CameraNode rotation

@Kaelthas I’m having some trouble with the rotation the blender importer is applying to the CameraNode and am hoping you can help me figure this out. It seems like the Blender camera looks out the back of the camera, so the JME camera ends up looking directly behind itself.



I was able to fix this in the case where the blend is imported with fixUpAxis=false by rotating the camera 180 degrees around Y - then the view matches blender.



But I’m confused what rotation I need in the fixUpAxis=true case.



Here is the blend I’ve been using to test with - camera inside a cube with each face a different color.



This is the patch that works for fixUpAxis=false



[patch]diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

index c0058eb…9d1ef34 100644

— a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

+++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

@@ -208,6 +208,14 @@ public class ObjectHelper extends AbstractBlenderHelper {

List<Structure> camerasArray = pCamera.fetchData(blenderContext.getInputStream());

CameraNode camera = cameraHelper.toCamera(camerasArray.get(0));

camera.setName(name);

  •   				Quaternion rot = t.getRotation();<br />
    
  •   				if (fixUpAxis) {<br />
    
  •   					// ???<br />
    
  •   				} else {<br />
    
  •   					// Rotate 180 degrees around Y (multiply by quaternion (0, 1, 0, 0))<br />
    
  •   					// Blender camera faces opposite direction<br />
    
  •   					rot.set(-rot.getZ(), rot.getW(), rot.getX(), -rot.getY());<br />
    
  •   				}<br />
    

camera.setLocalTransform(t);

result = camera;

}

[/patch]



This is the test app I’ve been using - give it cambox.blend on the command line.



[java]import com.jme3.app.DebugKeysAppState;

import com.jme3.app.SimpleApplication;

import com.jme3.asset.BlenderKey;

import com.jme3.asset.plugins.FileLocator;

import com.jme3.renderer.Camera;

import com.jme3.scene.CameraNode;

import com.jme3.system.AppSettings;



public class CamBox extends SimpleApplication {

private String modelPath;

private CameraNode cameraNode;



public static void main(String[] args){

CamBox app = new CamBox(args[0]);

app.start();

}



public CamBox(String modelPath) {

super(new DebugKeysAppState());

this.showSettings = false;

AppSettings settings = new AppSettings(true);

settings.setResolution(640, 480);

settings.setHeight(480);

setSettings(settings);

this.modelPath = modelPath;

}



@Override

public void simpleInitApp() {

assetManager.registerLocator("/", FileLocator.class);

BlenderKey key = new BlenderKey(modelPath);

//key.setFixUpAxis(false);

rootNode.attachChild(assetManager.loadModel(key));

cameraNode = (CameraNode)rootNode.getChild(“Camera”);

}



@Override

public void simpleUpdate(float tpf) {

Camera camera = getCamera();

camera.setLocation(cameraNode.getWorldTranslation());

camera.setRotation(cameraNode.getWorldRotation());

}

}

[/java]

Hey,



it is really hard to debug this because every time I do some change, either to the code or the blend file, I get totally black screen in jme.

Even if I revert my changes I still get the same black screen.

I totally have no idea why this happens :frowning:



But I think the problem might be not with the camera node rotation but with camera itself.

The node transform is computed properly taking fixUpAxis into account if needed. This can be seen when you load lights or other objects.



I’ll check it out, because there were changes in amera object in blender since version 2.60+.

My last test for it was for version 2.53 as I remember.

@Kaelthas said:
But I think the problem might be not with the camera node rotation but with camera itself.
The node transform is computed properly taking fixUpAxis into account if needed. This can be seen when you load lights or other objects.


I'm using blender 2.63. If I uncomment key.setFixUpAxis(false) in the sample, this is what I see.

With the jme patch to flip the camera 180 degrees around Y. This matches the view through the camera that blender renders:
http://i.imgur.com/Kt8MO.png

Without the patch:
http://i.imgur.com/gj0GX.png

Is this what you see?

If I leave setFixUpAxis at the default (true), this is what I see:
http://i.imgur.com/dzp2I.png