JME3 -> Blender rotation

I know there are a tonne of topics about importing various things from blender, in particular the camera (I’ve been trawling through them).

I am going the opposite way though, trying to take the cameras position and rotation in JME and set the camera in blender the same. Rotation ofc is the only thing I can’t get, no matter what combination of values I try.

I get the cameras rotation, print with toString() and am trying to put it into blender, so essentially

I’m aware of the different axis stuff and have tried putting in so many combinations… I feel bad asking this because there is so much about it on the forum but alas I cannot do it

Blender is Z-up so JME’s quaternion values won’t mean anything. If Blender has another way of entering rotation then I suggest you use that.

Else, you might be able to tease out proper values by taking your JME Quaternion, grabbing it’s x,y,z angles (toAngles()) then feeding those into another quaternion flipping the y and z angles (fromAngles(), then using those quaternion values.

1 Like

Thanks pspeed.

The axis-angle system looks simple enough and is in both blender and available in jme so i tried…

Vector3f p = new Vector3f();
float theAngle = cam.getRotation().toAngleAxis(p);
System.out.println("the angle: "+theAngle);
System.out.println("in degrees: "+(FastMath.RAD_TO_DEG*theAngle));

System.out.println(new DecimalFormat("#.########").format(p.x));
System.out.println(new DecimalFormat("#.########").format(p.y));
System.out.println(new DecimalFormat("#.########").format(p.z));

And put that into…

And still no matter how I try putting them in, it is not the same as in JME. Do I need to do something further with the vector because of blenders different axis? (beyond just switching them and changing the positive/negative)

EDIT: Also tried your other solution,

float[] floats = new float[3];
v.cameraAngle.toAngles(floats);
Quaternion b = new Quaternion();
b.fromAngles(floats[0], -floats[2], floats[1]);

But still no luck

:facepalm:

Again… y is up in JME. z is up in blender. Unless you translate that you will always have problems.

Repeat that until you understand what I’m saying.

The reason my suggestion should work is because I was swapping the rotation about z with the rotation about y.

If blender has a way to enter three angles then use that… but make sure you swap rotation about z with rotation about y.

Because in JME y is up and in blender z is up. In blender z is up and in JME y is up. So any solution will require translating y up rotation with z up rotation. So rotation about y becomes rotation about z and rotation about z becomes rotation around y.

Not sure how many other ways to say it.

Edit: ninja edit made my post less relevant.

Well, I can only see one snippet of code and not what you are writing out, what was written, what the effect was. It’s entirely possible that math works different in your immediate vicinity. :wink:

I’m aware of that, also I think the Z in JME needs to be negative for blender’s Y. As far as I can tell I have been swapping them but still not getting it to work.

I appreciate the help none the less, I will post some more detailed code/screenshots to see if you can help me :stuck_out_tongue: Safe bets are still on me doing some idiotic though

If that’s the case then you may also have to flip the sign of one of the axes of rotation.

Sorry for the long post of images, here is what I am doing

This is the area involved

When I click the “eye-camera” button on the right, it moves the camera to the saved position (Which is done)

main.getCamera().setLocation(view.cameraPosition);
main.getCamera().setRotation(view.cameraAngle);


So the desired rotation for view is (the door at the end is hidden by the spec)

Once the camera is there, I press a key and in my Main class the following code attempts to get the rotation and position

System.out.println("----------");
System.out.println("Position: ");
Vector3f pos = new Vector3f(cam.getLocation());
pos.z*=-1f;//for blender
System.out.println("X :"+pos.x);
System.out.println("Y :"+pos.z);
System.out.println("Z :"+pos.y);

The position works as expected

Now I try 3 methods to get the rotation right in blender

Using a new quaternion (I sincerely hope I have altered it correctly for the axis change with the fromAngles line!)

System.out.println("New Quaternion");
float[] floats = new float[3];
cam.getRotation().toAngles(floats);

Quaternion b = new Quaternion();
b.fromAngles(floats[0], -floats[2], floats[1]);//-z for blenders y, clockwise = negative in blender

System.out.println("W: "+new DecimalFormat("#.########").format(b.getW())); 
System.out.println("X: "+new DecimalFormat("#.########").format(b.getX())); 
System.out.println("Y: "+new DecimalFormat("#.########").format(b.getY())); 
System.out.println("Z: "+new DecimalFormat("#.########").format(b.getZ()));

But it looks into the sky

So I have tried using toAngles

System.out.println("----------");
System.out.println("To angles");
cam.getRotation().toAngles(floats);
//convert to degrees for blender input
//for easier copy paste print..
System.out.println("copy/paste");
System.out.println("X: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[0])));
System.out.println("Y: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[2]*-1f)));
System.out.println("Z: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[1])));

This time I get the floor

Finally I have tried using angle axis

System.out.println("----------");
System.out.println("Angle Axis");
Vector3f p = new Vector3f();
float theAngle = cam.getRotation().toAngleAxis(p);
System.out.println("angle: "+(FastMath.RAD_TO_DEG*theAngle));//degrees for blender
//now the vector
System.out.println("X: "+new DecimalFormat("#.###############").format(p.x));
System.out.println("Y: "+new DecimalFormat("#.###############").format(-1f*p.z));
System.out.println("Z: "+new DecimalFormat("#.###############").format(p.y));

I get a similar result to the previous attempt

I have also tried swapping every value negative/positive and different combinations of using them but nothing makes the blender camera rotate how I have it in JME. Also whilst 2 seem the same the quaternion method is different so I feel like I’ve done something wrong at least. Help much appreciated ^^

This is the way that might bear the most fruit, though it occurs to me that toAngles()/fromAngles() has a specific order that it applies the angles that may differ from Bender’s ordering.

So that I can make better sense of your results, can you show me what was actually printed for that version?

Was the same camera angle used in all cases?

If someone can save me some time and tell me what different ways blender lets you enter rotation that would be helpful also. If they let you do a rotation matrix 3x3 then that’s going to be the surest approach of all.

1 Like

I don’t want you to waste too much time on this, so I’m going to try and put together a script that uses the rotation matrix in blender. I’ll update this as soon as I fail/succeed

Quick edit, I’ll be honest I know nothing about matrices, what would I change to match blender - Do I just swap the Y and Z columns and and then multiple all 3 values by -1 for the other change? Or is it more complex than that?

The columns of a rotation matrix represent the x, y, and z axes (normal vectors) in whatever space you are using. In JME, Y is up so the second column is up.

If you can imagine how you’d rearrange the vectors to define a different space then that’s how you should rearrange them. For certain, JME’s columns 2 and 3 need to be swapped. It’s also possible that the new column 2 (the old column 3) also needs to be negated.

One other thing you can try in any case, position things like you think they should be in your JME scene and take various snapshots of the rotation as you’ve already done.

Then manually position things similarly in Blender and copy the values down. If you post all of that then we should be able to help more. Unfortunately, I don’t have time to fire up Blender myself tonight though I am curious about the ultimate outcome.

fs… Managed to stumble my way through making a python script for the Matrix - camera is looking at floor again. I get what you are saying about the from angles order, here are the available rotation inputs:

Here are the toAngles WITHOUT the necessary changes

float[] floats = new float[3];
cam.getRotation().toAngles(floats);

System.out.println("X: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[0])));
System.out.println("Y: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[1])));
System.out.println("Z: "+new DecimalFormat("#.###############").format((FastMath.RAD_TO_DEG*floats[2])));

And the resulted print out:

X: 3.832273483276367
Y: -177.4264678955078
Z: 0.000090273220849

With Y and Z swapped, the result is the floor facing camera as before - both with *-1 and without.
Furthermore, I tried every single one of the Euler angle inputs, both with and without the *-1 and only got some minor changes which I guess figures with those angles - but none worked.

As you suggested I lined the blender camera up as best I could and got the angles:

Regardless of what XYZ input order I chose the view barely changed at all so I have just posted this 1 set of angles.

: /

6am here… time to sleep on it

By “view” do you mean your camera view of the values in those fields? I’d have expected the field values to change quite a bit with different ZYX, XYZ, etc…

Depending on how they define the order, I think the JME equivalent would be YXZ for quake style rotation. (or reverse if its premult, ZXY). In other words, yaw then pitch then roll… with roll almost never being used.

XYZ Euler is almost certainly not the right one, though.

If you position the camera in blender as close as you can to what’s in JME, I’d be curious to see with the rotation says in Blender’s YXZ mode.

1 Like

Yeah I ment that when I changed between XYZ, XYZ and so on, the values in the boxes remain the same and the view changes - but the change is tiny and it was still roughly lined up with that I was going for.

REGARDLESS… I had a play around with some rotations in JME like straight down, straight up etc, and using YXZ as you suggested it seems I’ve managed to find an answer:

Blender(X,Y,Z), JME3(A,B,C)

X: -270-A
Y: C
Z: B - 180

Rotation input: YXZ Euler

I think this is correct as it works for every test case I can come up with (and so good for my purposes) but I cannot guarantee it since I didn’t calculate it logically. The proper test will be when I line up a rendered image from blender in JME, I’ll follow up with a screenshot if it either way.

Thanks for your help pspeed