Hello folks,
I'm making an exporter from Blender to Irrlicht, only to play with new things. I made it simple, a loop iterating over blender vertices and polygons and the "same" loop building an Irrlicht mesh.
I had to flip the Y UV Coordinate to fix the image upside down. But I still have one problem:
There are some axis flipped:
My Irrlicht camera is positioned at the same coordinate as Blender, (0, -10, 0) and I stated that the Y axis and the face normal is flipped, so I'm seeing the object backwards
How is the best way to solve this?
Blender X Irrlicht axis problem
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Blender X Irrlicht axis problem
Professional Software Developer and Amateur Game Designer
Re: Blender X Irrlicht axis problem
Blender has a right handed coordinate system and Irrlicht is left handed.
So you have to flip one axis. Either multiply any axis by -1 or switch 2 axes. Usually switching y and z is nice as it keeps the same way "up" in Blender and Irrlicht.
And as you noticed - after doing so you have the problem that front/backside of polygons got flipped.
In Irrlicht the front-back sides are defined by the sorting of the vertices. I think if you see vertices sorted clockwise you see them from the front. In Blender I think face-normals and polygon vertex sorting may be independent and hte face normal defines what the front is? (edit: I could be wrong there, maybe Blender doesn't use face-normals to define direction, it's something some 3d tools do and others don't).
So if it's always wrong, then you can switch the first and third index for each triangle on loading to fix it. Maybe check if Blender already has functions to deliver your model in triangles as then it probably also does ensure front-back is defined via the index-order.
If that doesn't work and the result is kinda random - then figure out what is meant to be front in Blender. Usually the direction the face-normal points at. Then base your index sorting on that direction. So the cross-product of any 2 edges in your polygon has to go either toward or away from that normal (just try - I'm not sure right now which one). So if your vertices are v1 to v3 it's something like: (v2-v1).crossProduct(v3-v1).dotProduct(normal) > 0. And depending on that result do switch the order of indices for that polygon or don't.
The uv swap is maybe needed because it prefers textures having 0,0 at bottom-left instead of top-left.
So you have to flip one axis. Either multiply any axis by -1 or switch 2 axes. Usually switching y and z is nice as it keeps the same way "up" in Blender and Irrlicht.
And as you noticed - after doing so you have the problem that front/backside of polygons got flipped.
In Irrlicht the front-back sides are defined by the sorting of the vertices. I think if you see vertices sorted clockwise you see them from the front. In Blender I think face-normals and polygon vertex sorting may be independent and hte face normal defines what the front is? (edit: I could be wrong there, maybe Blender doesn't use face-normals to define direction, it's something some 3d tools do and others don't).
So if it's always wrong, then you can switch the first and third index for each triangle on loading to fix it. Maybe check if Blender already has functions to deliver your model in triangles as then it probably also does ensure front-back is defined via the index-order.
If that doesn't work and the result is kinda random - then figure out what is meant to be front in Blender. Usually the direction the face-normal points at. Then base your index sorting on that direction. So the cross-product of any 2 edges in your polygon has to go either toward or away from that normal (just try - I'm not sure right now which one). So if your vertices are v1 to v3 it's something like: (v2-v1).crossProduct(v3-v1).dotProduct(normal) > 0. And depending on that result do switch the order of indices for that polygon or don't.
The uv swap is maybe needed because it prefers textures having 0,0 at bottom-left instead of top-left.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 260
- Joined: Thu Apr 17, 2008 1:38 pm
- Location: Brasopolis - Brazil
Re: Blender X Irrlicht axis problem
Aha! Thanks man! Flipping the v1 and v3 indexes does the trick. The mesh seems to be loading right way now!
Professional Software Developer and Amateur Game Designer