Previous Thread  Next Thread

chat icon Expose tangent space for export script in Python

drakfluga

Posted: Sun Nov 04, 2012 7:18 pm
Joined: 03 Nov 2012
Posts: 3
Hi,

This is my first post. I'm sure this has been asked before, I've searched on the forums but the threads I've found have been either short and non-specific or in other ways useless and/or long dead.

I'm with a small indie game development company. I'm currently working on an export script, getting our 3D assets from Python into our proprietary game engine. We're rolling our own binary format.

My question: Is it possible, somehow, to export tangent space coordinates from a Blender mesh via Python? I know the values are there because Blender correctly renders normal mapped surfaces, but as far as I can see they are not available through the Python API.

The problem is that normal mapping is implementation-dependant, so any attempt to recreate tangents/bitangents outside of Blender is futile. We need to access the values within Blender directly.

I've seen patches around which hack this functionality into Blender but being dependent on a patch which breaks with every update is not acceptable, nor is having to provide our external talent with hacked builds. And that's providing it even works, I haven't looked that closely at it yet.

Since the values are available to Blender internally, it should be a trivial matter to expose them to the Python API, no?

I'd be extremely grateful for any response on this issue. Normal mapping is an integral part of game graphics these days and not having the ability to extract this information is a serious impediment to Blender being a viable 3D graphics package for game development.

Cheers!

-- Andy
Reply with quote


jkoops

Posted: Mon Nov 05, 2012 9:57 am
Joined: 02 Nov 2012
Posts: 3
Hi Andy,

Just wanted to say that this is something I would very much appreciate too.

On the other hand, are you sure that tangent space definition is implementation dependent? It seems to me that two of the axis can be calculated from the UV mapping, and the third axis is a simple cross-product. From what I understand, this is what Blender does, and since you have access to the UV-mapping, you can do this yourself too.

But as you say: apparently the functionality does exist within Blender, and it would be very nice to have Python access to it.
Reply with quote


drakfluga

Posted: Mon Nov 05, 2012 3:47 pm
Joined: 03 Nov 2012
Posts: 3
jkoops wrote:
Hi Andy,

Just wanted to say that this is something I would very much appreciate too.

On the other hand, are you sure that tangent space definition is implementation dependent? It seems to me that two of the axis can be calculated from the UV mapping, and the third axis is a simple cross-product. From what I understand, this is what Blender does, and since you have access to the UV-mapping, you can do this yourself too.

But as you say: apparently the functionality does exist within Blender, and it would be very nice to have Python access to it.


There's a fairly detailed writeup on the Wiki:
http://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps

What stumps me is that I've been looking at old (2.4 and before) scripts, and it seems that tangents have been possible to extract before, but that this feature somehow disappeared in 2.5+. And nobody has bothered to put it back in, in several years.
Reply with quote


synkarius

Posted: Wed Nov 07, 2012 9:50 pm
Joined: 07 Nov 2012
Posts: 1
Drakfluga:

Apply this patch to build 46548:
https://projects.blender.org/tracker/index.php?func=detail&aid=29335&group_id=9&atid=127

I am in your exact situation. Tangents are calculated differently in Blender and the engine I am using, Away3D. I can confirm that this patch works. Yes, it is a hack, but it will get the job done. Plus, 46584 is build 2.63a, so you're not missing that much. (Current build at time of writing this is 2.64a.)

There is also this patch to the Collada exporter, which I have not tried yet:
https://projects.blender.org/tracker/index.php?func=detail&aid=31523&group_id=9&atid=127
Reply with quote


drakfluga

Posted: Thu Nov 08, 2012 2:37 pm
Joined: 03 Nov 2012
Posts: 3
synkarius wrote:
Drakfluga:

Apply this patch to build 46548:
https://projects.blender.org/tracker/index.php?func=detail&aid=29335&group_id=9&atid=127

I am in your exact situation. Tangents are calculated differently in Blender and the engine I am using, Away3D. I can confirm that this patch works. Yes, it is a hack, but it will get the job done. Plus, 46584 is build 2.63a, so you're not missing that much. (Current build at time of writing this is 2.64a.)

There is also this patch to the Collada exporter, which I have not tried yet:
https://projects.blender.org/tracker/index.php?func=detail&aid=31523&group_id=9&atid=127


Hi!

I actually managed to get a hold of the original patch author just yesterday, and he's updated it to the current build! As of right now, the verts and faces members of tangent_space are empty in my meshes and I'm trying to track down the problem. But he built it on his end and has verified that it does indeed work.

I would be extremely grateful to see this patch merged into the Blender trunk, as that would mean we could start relying on it more permanently. If there is anyone with dev status who would like to take it upon them to look at this, I and a big part of the gamedev community will be in your debt. Wink
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group