Horde3D

Next-Generation Graphics Engine
It is currently 21.11.2024, 19:39

All times are UTC + 1 hour




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Blender exporter crashes
PostPosted: 04.09.2009, 00:19 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Hi all,

I recently tried to export simple meshes done with Blender (default cube, Suzanne the monkey...), and the exporter crashed.

I started to take a look at it, putting "print" statements everywhere, and the problem is that there is a normalization [0, 0, 0] vectors, which produces NaN values.

I contacted Felix, the creator of the script, who doesn't have the problem, when using his script. I wonder if that comes from a problem with versions : I tried Blender 2.48a (works with him), but I use Python 2.6 / Ubuntu, while he uses Python 2.5 / Windows.

The problem is with exporting tangent and bitangent vectors. What do they exactly represent ? In the case of a simple cube, should what should they be equal to ?


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 02:16 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Funto wrote:
The problem is with exporting tangent and bitangent vectors. What do they exactly represent ? In the case of a simple cube, should what should they be equal to ?
The Normal, Tangent and Bitangent (AKA Normal, Binormal, Tangent) define the local coordinate system for a vertex. i.e. the direction that the X, Y and Z axis point in relative to the surface.

Each one of these vectors should be perpendicular (i.e. at 90º) to the other two vectors.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 07:14 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
As already mentioned, in another thread, it seems, like something has changed in Blender 2.49 that results in wrong tangent data. For export you currently have to use blender 2.48. I don't think that it depends on the OS or Python version, although I haven't tested that.

We hope that for blender 2.5 a new collada exporter will be released so we don't have to further devlope the direct blender exporter.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 10:07 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
DarkAngel >> Thank you :) One question : should these vectors be represented in local coordinates or world coordinates ? I suppose local, as they must be independent of the position of the object, but I just would like a confirmation ^^

In the case of the cube, for example, the upper face's vectors could be : t=[1, 0, 0], n=[0, 1, 0], b=[0, 0, 1], am I right ?

Volker >> I do not have very much hope for improvements in the COLLADA exporter for Blender, as it is an independent project from Blender that last released more than 2 years ago...

You say we should use Blender 2.48, but as I said, I tried the exporter with both Blender 2.48a and Blender 2.49.
I do not see how Blender could have broken the tangent vectors calculation, as this one is done in the script (and not read from the model...).

In the "changes since 2.5" log (here : http://wiki.blender.org/index.php/Templ ... Python/API ), they mention a "Mesh.getTangents()" method ; perhaps using it could fix the problem ?

I will try with older versions of Blender and different versions of Python and see what happens...


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 10:20 
Offline

Joined: 05.03.2007, 19:38
Posts: 167
Location: Romania
any luck/development Funto? I'll try to help.

i looked in the change-log too and didn't find any breaking changes in the api.
how about having an older/working setup, and just print the tangent data and compare it to the current version?

le: from what i've found on google this is a python 2.6 problem, not a blender or exporter one.
although i might need confirmation on this, i found discussions about this ranging from numpy to yafaray.

_________________
Paul


Last edited by SpOOky on 04.09.2009, 10:49, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 10:49 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
SpOOky >> That's what I will do next ^^ I will also take a look at the Mesh.getTangents() function I was talking about...

I tried with different versions :
Blender 2.48 / Python 2.5 : works
Blender 2.48a / Python 2.5 : works
Blender 2.48a / Python 2.6 : crashes
Blender 2.49 / Python 2.6 : crashes

=> The problem seems to come from the Python version...


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 10:57 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Ok. The difference really comes from the interpreters :

Python 2.5 :
Quote:
>>> a = 1e10000
>>> a
inf
>>> b = a/a
>>> b
nan
>>> c = int(b)
>>> c
0L


Python 2.6 :
Quote:
>>> a = 1e10000
>>> a
inf
>>> b = a / a
>>> b
nan
>>> c = int(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot convert float NaN to integer


When used with Python 2.5, the script must give [0, 0, 0] vectors for normals, bitangent and tangent vectors, while this doesn't work with Python 2.6...

I suppose the tangent calculations is erroneous ; I will try to see what I could do with Mesh.getTangents()...


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 10:59 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
I only had a quick look at the crash and found the NaN tangent data too, I thought it was wrong data from blender 2.49 but if that data is also present with blender 2.48, I guess the problem is in the exporter not in blender or python. Because the tangent/normal/bitangent never should be 0 0 0 I guess.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 12:38 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Yes : I printed the values when used with Python 2.5, and it is NaN. The difference is that the conversion to integers when writing to the file produces zeros instead of crashing.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 14:01 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Hmm, I played a bit with Blender's Python API :

Code:
import Blender

from Blender import *



print '----------------------------'

scn = Scene.GetCurrent()

ob = scn.objects.active

mesh = ob.getData(False, True)

nmesh = ob.getData(False, False)

print mesh.name

methods = dir(mesh)

print 'getTangents' in methods

print mesh.getTangents()



nmesh.printDebug()



Executing this with the default scene (cube), (not being in edit mode), mesh.getTangents() gives me [0, 0, 0] vectors...

I don't understand :? Should tangent vectors be equal to [0, 0, 0] ?? How is that possible ?


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 18:12 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Still investigating :p

After some talk on #blendercoders, it appeared that the NaN values disappear after doing a "UV unwrap" to the mesh.

This is true for the tangent calculations in the script, as well as for the Mesh.getTangents() method in Blender...


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 19:43 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Funto wrote:
After some talk on #blendercoders, it appeared that the NaN values disappear after doing a "UV unwrap" to the mesh.

That makes sense. The tangent is commonly defined as the direction of the increasing u component across the face.

See this gamasutra article for a nice introduction to tangent space.


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 21:30 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Yes, that's what I finally realized by reading this article, which is used as the basis for the calculation made in the script...

I think I will slightly modify the script for it to write [0, 0, 0] vectors if there are no UV coordinates. The other solution would be to make an assumption on the UV coordinates values for the triangle, but this does not really have a sense...


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 22:04 
Offline

Joined: 05.03.2007, 19:38
Posts: 167
Location: Romania
so it turns out that you can export from 2.49 if you add uvs (tested/works).

your patch to add [0, 0, 0] if the uvs are not there will help if for some reason geometry with no uvs is needed

_________________
Paul


Top
 Profile  
Reply with quote  
PostPosted: 04.09.2009, 23:28 
Offline

Joined: 10.07.2009, 21:16
Posts: 42
Here it is : very small difference from the original, but at least it does not crash with a non-UV mapped model :)


Attachments:
Horde3DExport.py.zip [10.55 KiB]
Downloaded 1630 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group