Axis Conversion and Normals help

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
Twistedsnail
Posts: 0
Joined: Wed Jul 31, 2013 10:02 am

Axis Conversion and Normals help

Post by Twistedsnail »

Hey Everyone

I have a problem of currently unknown magnitude.
I have written an exporter for a custom file type for a project in C++ and OpenGL and as you may know, the internal system axis uses -Z for depth and Y for up as opposed to Blender's Y depth and Z up.

I thought I had it solved when I stumbled across axis_conversion() which I am using as follows:

Code: Select all

mat = Matrix()
msh.transform(obj.matrix_world * (mat * axis_conversion('Y', 'Z', '-Z', 'Y').to_4x4()))
This works perfectly for transforming the mesh.

However I have a problem with the way that transformation seems incorrectly deforming vertex normals.
It happened when I was writing shaders and my lighting algorithms seemed weird, just weird.
So I did some debugging and after rendering the normals the problem becomes apparent:


Image
This is the exported model with axis_conversion removed, the normals are perfect and produce good lighting.
It is however, the wrong orientation (petty, I know, but I hope it can be fixed)


Image
This is the same model, at the same rotation, same lighting, shaders etc. Except with the axis_conversion used.
It is at the right orientation but has strange normals that result in weird lighting.


Does anyone know what causes this? Should I just extract and store the normals from the unprocessed mesh then proceed with exporting?

I am grateful for any help.
Thanks.

Post Reply