I've hijacked the obj exporter according to the Mesh Loop documentation in order to do a simplified vertex-attribute export:
# loop faces per object
for face in me.polygons:
# loop over face loop
for vert in [me.loops[i] for i in face.loop_indices]:
fw('v %.6f %.6f %.6f' % me.vertices[vert.vertex_index].co[:])
fw(' %.6f %.6f' % uv_layer[vert.index].uv[:])
fw(' %.6f %.6f %.6f' % vert.normal[:])
tangent = vert.tangent
bitangent = vert.bitangent_sign * vert.normal.cross(tangent)
fw(' %.6f %.6f %.6f' % tangent[:])
fw(' %.6f %.6f %.6f' % bitangent[:])
fw('\n')
As can be seen above I'm trying to extract the following vertex attributes: position, UV coord, normal, tangent, bitangent. The tangent and bitangent vectors are in object space and my goal is to get them in tangent space. I've also seen this Blender SE post about converting object space to tangent space.
Would anyone who is more familiar with the math be able to help me implement these tangent space vectors in my Blender Script?
For context I am implementing PBR in a WebGL application and would rather not have to compute the tangent space vectors from the normal map on the fragment shader.
Edit: the above code shows my modification of scripts\addons\io_scene_obj\export_obj.py
Edit edit: Am I being stupid? Is "local space" in the documentation referring to tangent space?
1 0 0and0 1 0. I don't think that's actually what you want. – scurest Jan 01 '22 at 00:591 0 0and0 1 0. So I think it does calculate them local to the face – michael b Jan 01 '22 at 02:05