Normals not being read correctly?

I’m attempting to diagnose a problem with a game engine model exporter I’ve written for Natural Selection 2. The exporter uses the normals, tangents and bitangents generated in Blender via the mesh.calc_tangents() function – it does not calculate its own tangent vectors. It works flawlessly for dozens of other models I have exported with it, yet for some reason, this newest model is exhibiting some tangent/normal mapping mismatches.


Wireframe:

I tried importing the exported file and to my surprise, the problem remained!


I wrote a python script that mimics the effects of what exporting and re-importing the mesh is doing. Super un-optimized, it’s just something I threw together in 5 minutes to see if the issue could be replicated wholly inside blender – it can!

http://pastebin.com/QMTPSqqE

I would appreciate any insight into this problem, it’s very frustrating for me.

Anyone? Wild theories are welcome. :slight_smile:

It seems the problem is either with how Blender is making the normal/tangent/bitangent data available to python (ie it doesn’t match up with the viewport renderer data), or there’s some other element I’m neglecting…

Is there a way to visualize the tangents/bitangents in blender? I have compared the split-vertex normals of the good and the bad, and they appear identical, so I’m led to believe the tangents and/or bitangents are incorrect… somehow…

Well, after some investigation, it definitely looks like it’s the tangents/bitangents that are mismatched… not sure how that’s happening.
(Wrote a script to match up the vertices, and spit out the pertinent information)


The argument could be made that the tangents/bitangents aren’t matching up between the meshes because in the original, most of the geometry is joined together, so (I assume) tangents/bitangents are also getting smoothed at each vertex. When the script creates the new version, the tangents are misaligned because they don’t have the adjacent faces to smooth them over with in the same way… but that doesn’t explain why the exact same artifacts would show up in the game engine… The exporter I wrote doesn’t split the mesh into triangles, all it does is spits out the tangents/bitangents it’s given by the mesh, calculated with the calc_tangents() command… which should result in the same tangents/bitangents as being displayed in blender… after all, if they weren’t, where has the difference I’ve just discovered come from?

Whoa, HELLO. Something is definitely wrong here with Blender…

I created a script, and all it does is copy the mesh’s normals into the custom split normals of that same mesh, and… it’s incorrect. It’s exhibiting the same problems as the copied mesh from my previous posts.

The script I ran.
http://pastebin.com/giJtZgST

Results:


I got some issue too, most of the time I care only about what I see in the engine. S
omething weird here. U__U

Submitted a bug report to the blender guys… so fingers crossed!

Apparently this is fixed now! :smiley: Hopefully this also fixes the exported normals/tangents/bitangents problem too.

Hmm darn… It fixes the bug of stuff being drawn incorrectly in the blender viewport, but doesn’t fix that l’m still getting incorrect tangents/bitangents from the loops when exporting… Oh well… time to write my own damn mikkt space functions for the exporter. :frowning: