Fix Up Axis in blender loader - lets discuss it once again ;)

Hi,



I’ve notices that Remy had made a change in MeshHelper to load models with Y axis set as up axis.

He changes the positions of the vertices.

Even if the change is right it is not complete.



Try using more complex model with a node having many children and a texture with user defined UV’s.

Let the children have other children. Scale/translate/rotate all of the nodes in any way you like.



This change causes many many problems.

The models are not properly transformed.

The meshes are displaced and do not look properly.

The transformations of the children are not correct.

The textures are not displayed the right way because the UV’s do not fit the proper vertices.



My approach was to rotate/translate only the root nodes. This way the scene looked ok (at least in most cases).

I know that sometimes this method did not work well, but I belive this to be a problem of quaternion transformations in jme.

I’ve made a post about it some time ago:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/strange-behaviour-of-quaternions/





The code that caused problems is in MeshHelper in the method

[java]public Vector3f[] getVertices(Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException;[/java]



The following lines of code:

[java]

vertices = new Vector3f(coordinates.get(0).floatValue(),

coordinates.get(1).floatValue(), coordinates.get(2)

.floatValue());

[/java]



were changed into



[java]

if (blenderContext.getBlenderKey().isFixUpAxis()) {

vertices = new Vector3f(coordinates.get(0).floatValue(),

coordinates.get(2).floatValue(), -coordinates.get(1)

.floatValue());

} else {

vertices = new Vector3f(coordinates.get(0).floatValue(),

coordinates.get(1).floatValue(), coordinates.get(2)

.floatValue());

}

[/java]



I reverted the changes locally and it worked fine with complex models.



I do not say that this method is wrong. Perhaps it is better than mine. But for the moment I think it is incomplete.

But if I’m wrong - tell me :wink:

Its definitely incomplete. This is transforms and not just locations. Basically it has to mimic the whole “world location / updategeometricstate” stuff. Remember for example that a child that has an offset automatically changes its location when its rotation is changed… Another example where this is handled is with the CollisionShapeFactory.

One of my stupid questions but where is that MeshHelper? I tried to find it with windows explorer (filename) but didnt found, so maybe it’s internal class or so?

Second question, is there jmp/nb project file that contains all jme engine files, so if I want to try some modifying, I can compile it in IDE? (and using svn version of jme, so this file structure used)

See the manual under “using you own jme3 build”

It is in src/blender folder in the jme sources.



com.jme3.scene.plugins.blender.meshes.MeshHelper

@normen thanks, heh readed so much wiki so forgot that one

@Kaelthas oh there that file is…I dont understand why windows 7 search doesnt show files that are there :confused: (not the first time that it does not find anyhing)

@larda: Its basically the same content, the manual for the SDK is pulled from the wiki, but the manual is easier and faster to search through :slight_smile:

I must learn to use F1 :smiley:

@Kaelthas

why not use the ide integrted search? Also extend your index to the src folder to trade speed for accuracy of results.(Well on a SSd it is speed and accuracy so win win, but else a larger index might slow down searches.)

@EmpirePhoenix: maybe you meant me :wink: I have disabled index system (on win7) on every partition, but it is weird that it cant find files…

in dos box “dir mesh /s” was enough, I will use some other search program because search integrated in explorer just suck (even in XP that search was better). But no more on that :smiley: (and if that reply of yours wasnt to me, sorry :smiley: )

“why not use the ide integrted search?”

How?

F1? xD

Just right-click any folder or project to search for a file.

@Kaelthas I’m sorry,my bad, i shouldn’t have committed it. Also you don’t have to ask permission to revert something i did if you feel it’s incorrect, especially on the blender loader which is you area of expertise.



I did that change because I though it wasn’t implemented at all. None of the models i tested were correct, always facing the ground.

For example it’s not working for Sinbad blend file. and all my models btw…

With the change it was fine, but the model i tested were without textures. Didn’t think I would mess anything since I believed it was not implemented at all.



Maybe you should investigate why your way of doing it is not working on sinbad’s file. I can help if you think it’s a quaternion issue.

But ogre exporter handle’s it the way I did, by just inverting y and -z axis. It should work if you apply this each time you read a coordinate in the blend file. (position, vertices position, transforms, etc…)

UV must not be changed, only 3D coordinates.



Rotating the whole scene seems fine, but it should work in every cases.



On a side note for the quaternion issue, my understanding is that a rotation can be represented by one and only one quaternion, but a rotation can be represented by several euler angles rotations (i think it’s even an infinite number of euler angles representation).

ie euler angles rotation (0, 0, 0) can be (2PI, 2PI, 2PI), same result, different values.

So when you convert a rotation from euler angles to quaternion and to euler angles again, you are not certain of getting the same euler angles.

Also i’m not a math genius so i can be wrong.

My approach was to rotate/translate only the root nodes. This way the scene looked ok (at least in most cases).
I know that sometimes this method did not work well, but I belive this to be a problem of quaternion transformations in jme.
I’ve made a post about it some time ago:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/strange-behaviour-of-quaternions/


Of course, that thread was a bit unclear I think and the conversation died relatively quickly. You were essentially asking the same thing as "when I rotate 1080 degrees why does the quaternion only show a rotation of 0?" You probably don't realize it is the same question but it's pretty much the same. A 180 degree yaw then a 90 degree pitch, and a 90 degree roll works out to be two 90 degree rotations.... yaw and pitch I believe.

What I don't understand and so someone will have to educate me...

Why is the blender to JME transformation not just a 90 degree rotation around the x axis? Is there also a handedness difference? (in which case no rotation will help, I think.)

And if loading a model produces ultimately a single root node... why can't the transformation just be applied to that node?
Why is the blender to JME transformation not just a 90 degree rotation around the x axis? Is there also a handedness difference? (in which case no rotation will help, I think.)

And if loading a model produces ultimately a single root node… why can’t the transformation just be applied to that node?


Well that was his approach.
But it seems it does not work in some cases.

Ok, but then…


My approach was to rotate/translate only the root nodes. This way the scene looked ok (at least in most cases).
I know that sometimes this method did not work well, but I belive this to be a problem of quaternion transformations in jme.
I’ve made a post about it some time ago:

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/strange-behaviour-of-quaternions/


Needs some further refinement... because a simple new Quaternion().fromAngles( FastMath.HALF_PI, 0, 0 ) should work just fine and has nothing to do with that other thread. (+ or - HALF_PI, I'm not sure in this case.)

Also there is a draw back with this method, the model always have to be “re rotated” each time you use the spatial.lookAt method for example. Not that bad…but it feels kind of hacky to have to rotate again the model afterward.



Maybe we should implement something like the “apply transforms” function that exist in blender.

Or the caller can stick it under another node. I admit that it’s not pretty but it should work. :slight_smile: When it’s a choice, working trumps pretty.

yeah but the user won’t be necessarily aware of that when loading a blend file…

I can already see posts like “spatial.lookAt bugged my model look at the ground!!!” :stuck_out_tongue:

Based on forum posts, I don’t believe anyone is ever able to successfully use lookAt() anyway. :slight_smile: :slight_smile: :slight_smile: