Wrong coordinate system? How to rotate model?

I made and exported a 3DS model in Blender, and am able to import and view it in jME. (Yippee.) But it is horribly tilted – or rather, my model seems to use a wrong coordinate system.



I don't mind whether I rotate my model, or change something in jME to solve this, whatever is best, what do you recommend? If anybody knows how I can set Blender to rotate the object to be jME-compatible, please tell me. I also tried rotating the model in the game world after loading it: I applied Quaternions by trial and error, but there are too many variations. The question remains, which way?



By the way, "out of desperation," I wrote and donated three pages to the wiki about rotation and stuff

http://www.jmonkeyengine.com/wiki/doku.php?id=transforming_the_scene

Please check whether they are correct!

Well, I found a work-around:

public static final Quaternion UPRIGHT  = new Quaternion().fromAngleAxis(- FastMath.PI/2,   new Vector3f(1,0,0));


Trial and error rules.

Any more elegant solutions out there?

i suppose the best thing is to export the model from blender in such a way so you don't have to rotate it in jme every time.

i didn't used models from blender yet, so i can't give you anything more specific, but i suppose you can experiment a bit. just export a cube with different colored faces and see if it's tilted too. then you can decide how to export your actual model.

hth

Other opinion:



I prefer to let the modellers work with the coordinate system of their choice.



In example, I use this:



   /**
    * Loads a model.
    */
   public static Node loadModel(String name, String path) {

      Node model = null;
      path = Globals.DATA_DIR + "/" + path;
      
      // This is a plain model loader
      model = MeshUtil.convertModel(path);

      // And here I rotate the model
      model.getLocalRotation().fromAngles((float) -Math.PI / 2.0f, 0.0f, 0.0f);
      model.updateRenderState();

      // I use a intermediate node to encapsulate the transformation,
      // so the final node has local rotation set to Vector3f.ZERO (I've found this useful)
      Node nodeTransformed = new Node(name + "-transformed");
      nodeTransformed.attachChild(model);

      return nodeTransformed;
   }



Geometry transformation is not as expensive after all, I think.

Edit: Bad suggestion, see below.
jjmontes said:

Geometry transformation is not as expensive after all, I think.


yes, but you have to do it every time. for me it's just unnecessary overhead.
sure you just let the artists work with whatever coordinate system they want, but when you get the model it should be in the coordinate system you need. that's why most programmers write tools for their artists ;)

Also won't compounding rotations result in floating point errors? 



If so having to rotate the model just to get it facing the right way at the start sounds like a very bad idea to me.

Gentleman Hal said:

Also won't compounding rotations result in floating point errors? 
If so having to rotate the model just to get it facing the right way at the start sounds like a very bad idea to me.


I belive you are right. Each sucesive rotation will surely add some amount of error to the transformation matrix coeficients.

And even if the performance impact is very small, it still is a performance impact.

Really I've suggested a bad idea here.

At least, I'm still considering to rotate models by code during development, and precalculate rotation for release. It is easier/faster/less-error-prone than forcing artists to rotate models each time they export one.

Edit: typo

Thank you for your insights. I didn't know that rounding errors will stack up, but it makes sense to assume they would! I'll go fiddle about with a model of a cube in Blender then.  :slight_smile:

we had the same problem using Blender-3D-models in our game…



we managed to solve it by simply making a 90-degree rotation on the model in Blender

which worked due to the fact that Blender uses z-axis as height and in jME z-axis should be equal to depth…



but you should be careful because Blender uses switched normals for the model's faces

means you have to invert the normals of your model before exporting…



(btw: which exporter is it you're using? Collada?)



let me know if it worked out :slight_smile:

greetings

neebie

neebie said:

we had the same problem using Blender-3D-models in our game..
we managed to solve it by simply making a 90-degree rotation on the model in Blender
which worked due to the fact that Blender uses z-axis as height and in jME z-axis should be equal to depth..


Thanks for the confirmation, I was suspecting something like that! Everytime I rotate something like I am used to, it comes out all wrong in Blender, I thought I was losing it or something...  :D

neebie said:

but you should be careful because Blender uses switched normals for the model's faces
means you have to invert the normals of your model before exporting..


Inverted normals -- that's what makes all surfaces look wrongly lit, right? Everything has just one plain color on one, and white on the other side, is that it? :| So how did you invert them in Blender? I already tried "No V Normal Flip" in Edit > Mesh, but that didn't help.

neebie said:

(btw: which exporter is it you're using? Collada?)


I used 3DS up to now. Couldn't get the others to work with jME -- except OBJ, which kind of worked but broke all transparencies. But transparency does not work either in 3DS, so I am not sure whether it is not supported by that format, or whether the import breaks it...?

I will give Collada a try, can you recommend it?

PS: I still get "Unable to load Collada file. Invalid byte 1 of 1-byte UTF-8 sequence." ? :| but I'll keep trying. Tipps are appreciated. :)
zathras said:

Inverted normals -- that's what makes all surfaces look wrongly lit, right? Everything has just one plain color on one, and white on the other side, is that it? :| So how did you invert them in Blender? I already tried "No V Normal Flip" in Edit > Mesh, but that didn't help.


In Edit Mode you simply (after selecting all faces of the object) use Mesh -> Normals -> Flip..
after that the normals should face inwards.. (works at least in Blender versions: 2.41 and 2.42)

zathras said:

I used 3DS up to now. Couldn't get the others to work with jME -- except OBJ, which kind of worked but broke all transparencies. But transparency does not work either in 3DS, so I am not sure whether it is not supported by that format, or whether the import breaks it...?

I will give Collada a try, can you recommend it?

PS: I still get "Unable to load Collada file. Invalid byte 1 of 1-byte UTF-8 sequence." ? :| but I'll keep trying. Tipps are appreciated. :)


If you use the Collada Exporter from illusoft http://colladablender.illusoft.com/ (and not the one that comes with Blender)
then exporting should work fine.. BUT some things are not working at the moment, though..
for example exporting animations or materials (the developer is currently on it)

hope that helps.. ?
neebie said:

In Edit Mode you simply (after selecting all faces of the object) use Mesh -> Normals -> Flip..
after that the normals should face inwards.. (works at least in Blender versions: 2.41 and 2.42)


Oh they should be INWARDS? Oops I thought outwards, nevermind. :) So when I switch to "normals" mode in jME, it shows all those red rods sticking out of my stuff like an angry hedgehog -- what should they look like?

neebie said:

If you use the Collada Exporter from illusoft http://colladablender.illusoft.com/ (and not the one that comes with Blender)
then exporting should work fine.. BUT some things are not working at the moment, though..
for example exporting animations or materials (the developer is currently on it)


What a pity, but well, I'll wait. :) Thanks for the tip anyway!

One quick tip to see if your normals are on the "right" side is to cull the backside of your model.

If you now do not see your model your normals are facing the wrong direction.


CullState cs = display.getRenderer().createCullState();
      cs.setCullMode(CullState.CS_BACK);
      cs.setEnabled(true);

      rootNode.setRenderState(cs);



And do you really need animations right now?
You can do the animation stuff in jME as well as the materials.
Ata later point you can easily export the models again from blender when the collada plug-in runs with all features.
You can also use the blender to jME exporter but I recommend the collada thingy ;)

greetin's Sue
Sue said:

One quick tip to see if your normals are on the "right" side is to cull the backside of your model.
If you now do not see your model your normals are facing the wrong direction.

CullState cs = display.getRenderer().createCullState();
      cs.setCullMode(CullState.CS_BACK);
      cs.setEnabled(true);
      rootNode.setRenderState(cs);



Strange, that didn't do anything at all. (And there is no other line unsetting the renderstate later, either.) When I do CS_FRONT instead, everything turns gray and funny though. Does that mean the normals are correct?

My main problem is: Half of all sides of my model are shown as completely white. (And no textures.) 3DS does support textures, right? I even tried adding a light to the camera node, but either I did it wrong or it didn't make any difference. (And the light worked, as a test, I changed it to red and everything turned reddish.)

If you cull the backsides then they are not shown and if you cull the frontside … ya know what now comes :wink:

It seems your problem is a texture problem you should search in the forum I think you will find an answer :wink:



I wish ya a nice weekend

Sue

zathras said:
I still get "Unable to load Collada file. Invalid byte 1 of 1-byte UTF-8 sequence." ? :| but I'll keep trying. Tipps are appreciated. :)


PS: The UTF-8 error was because I had used UTF-8 characters when naming scene nodes in my model. Naming nodes with plain ascii text helped.