Horde3D
http://horde3d.org/forums/

Blender exporter crashes
http://horde3d.org/forums/viewtopic.php?f=11&t=937
Page 1 of 2

Author:  Funto [ 04.09.2009, 00:19 ]
Post subject:  Blender exporter crashes

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 ?

Author:  DarkAngel [ 04.09.2009, 02:16 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Volker [ 04.09.2009, 07:14 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Funto [ 04.09.2009, 10:07 ]
Post subject:  Re: Blender exporter crashes

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...

Author:  SpOOky [ 04.09.2009, 10:20 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Funto [ 04.09.2009, 10:49 ]
Post subject:  Re: Blender exporter crashes

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...

Author:  Funto [ 04.09.2009, 10:57 ]
Post subject:  Re: Blender exporter crashes

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()...

Author:  Volker [ 04.09.2009, 10:59 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Funto [ 04.09.2009, 12:38 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Funto [ 04.09.2009, 14:01 ]
Post subject:  Re: Blender exporter crashes

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 ?

Author:  Funto [ 04.09.2009, 18:12 ]
Post subject:  Re: Blender exporter crashes

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...

Author:  marciano [ 04.09.2009, 19:43 ]
Post subject:  Re: Blender exporter crashes

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.

Author:  Funto [ 04.09.2009, 21:30 ]
Post subject:  Re: Blender exporter crashes

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...

Author:  SpOOky [ 04.09.2009, 22:04 ]
Post subject:  Re: Blender exporter crashes

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

Author:  Funto [ 04.09.2009, 23:28 ]
Post subject:  Re: Blender exporter crashes

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 1635 times

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/