Questions about normals, tangents, bitangents, normal maps... a lot of things really

Greetings!

I’m putting the finishing touches on an exporter I’ve written that will allow Blender’s .blend files to be converted to Natural Selection 2’s (http://www.naturalselection2.com/) model format (including animations! :D). I also recently discovered the “normal edit” modifier, and a thought occurred to me: what if I could, via a python script, manually edit the normals, tangents, and bitangents of a mesh INSIDE of blender, and then, would that mean I could also bake normal maps with blender, to an extreme degree of accuracy?

See… I’m attempting to solve the same problem that handplane was designed to solve (http://www.handplane3d.com/) – that is, that the normals/tangents/bitangents generated by the 3d application to bake the normal map texture don’t exactly match the techniques used by the game engine to calculate the normals/tangents/bitangents, leading to odd artifacts near poles and seams – areas where the small discrepancies are magnified. In this case, I’m only interested in getting the normals/tangents/bitangents in blender to match what is output by the export script for the NS2 model format.

Anyways, here’s my questions:

  1. How do I go about modifying the actual tangent/bitangent/normal values of each vertex via python? I’ve tried simply writing, for example:
bpy.data.objects['Suzanne'].data.loops[0].bitangent = Vector((1.0,0.0,0.0))

However, blender tells me this data is read-only, implying there is a “proper” way to handle this. To be clear, I’ve already got the exporter working, however what I’m trying to do here is generate the proper normals/tangents/bitangents inside of blender, so that the normal map baking process can be using the proper tangents, rather than those generated by blender. I know the methodology for matching them up, I just don’t know how to go about actually modifying this particular mesh data within blender – assuming this is possible.

  1. Does blender’s texture baking even take into account the custom split normals, or does it re-do the calculations – and therefore defeat the purpose of customizing the normals in the first place?

Cheers!
Trevor

Blender has limited support for custom normals:
http://wiki.blender.org/index.php/User:Mont29/Foundation/Split_Vertex_Normals
http://wiki.blender.org/index.php/User:Mont29/Foundation/Split_Vertex_Normals/Custom_Split_Normals_Manual

Hmm, wiki must be down for me, can’t get any of those pages to load. I did a bit more digging after the original post, and it’s looking like there’s no way to manually edit the tangents and bitangents of a loop, only the normals can be edited.

Well, I guess I’ll just have to go with plan “B” here: bake normal maps in world-space and write a python utility to convert THOSE to the proper tangent space.

Thanks for your help Codeman! You’re a beast in this area of the forums! :smiley: