Normal transform question

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
EladarGL
Posts: 0
Joined: Sun May 15, 2005 4:58 pm

Normal transform question

Post by EladarGL »

Im exporting normals very well.. but when i transform (rotate) the 3d figure, normals isnt transformed. I tried transform them whit getMatrix() of the figure. However, it is not correct way, because normals are transformed in the wrong way. How can i transform normals in the correct way when i rotate the figure? Thx for reply

Brandano
Posts: 0
Joined: Mon Apr 19, 2004 6:03 pm

Post by Brandano »

Vertex normals are defined as vectors with an origin set at 0,0,0 and a length of 1, so when you apply a transform matrix to them you must remember that:
1-they mustn't be translated
2-they mustn't be scaled
So if you want to apply transforms to them you must obtain the rotation part of the transform matrix (easy) and remove from it the scaling info (a bit harder). If the scaling is uniform you can just apply the rotation and normalize the vector back to alength of one, otherwise you will need quite a bit of mathematics that at the moment I am unable to help you with. My suggestion would be to apply your transformations within Blender before exporting, as he does all these calculations for you and recalculates the normals internally. You can copy the mesh to a new object, export that one and delete it, so that the original scene will be left unchanged.

Post Reply