I'm writing a model exporter in Blender 2.77 and except from triangles and vertex positions, I also want their normals and tangents.
As an example, I'm using a simple cube centered at the Origin (0,0,0).
I found out that Blender can calculate normals and tangents using the following commands:
data=C.object.data
data.calc_normals();
data.calc_tangents("UVMap");
So after that for testing purposes I'm executing the following code
data.calc_tessface();
for f in data.tessfaces: # indices
polygon = data.polygons[f.index] #Load Polygon
for vert in range(len(f.vertices)):
norm = data.vertices[f.vertices[vert]].normal
norm1 = data.loops[polygon.vertices[vert]].normal
print(norm, norm1)
I know that the order of the output vertices won't be correct when iterating in the tessfaces and the polygon structs. My problem is that the output looks like this:
<Vector (-0.5773, 0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, -0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, -0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, 0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, 0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (0.5773, 0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, 0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (-0.5773, 0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (0.5773, 0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, -0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, -0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, 0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (-0.5773, -0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, -0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (0.5773, -0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, -0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (-0.5773, -0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, 0.5773, -0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (0.5773, 0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, -0.5773, -0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, -0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (0.5773, 0.5773, 0.5773)> <Vector (0.0000, 1.0000, 0.0000)>
<Vector (-0.5773, 0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
<Vector (-0.5773, -0.5773, 0.5773)> <Vector (-1.0000, 0.0000, 0.0000)>
Am I missing some other data operator that will update the normals? Why are the loop normals not equal to the vertices normals?