Page 1 of 1

Animated tangents+binormals (and added to X Mesh Loader)

Posted: Sat Nov 20, 2010 8:02 am
by griffin2000
So locally I have made some changes to the Irrlicht engine so Tangents and Binormals can be loaded from X Mesh files, and can be animated by skinned animations. I've tested this with an animated model (exported via Kw exporter and it works fine).

Here is the patch if anyone wants it:
http://dl.dropbox.com/u/2809326/Tangents.patch

As I mentioned in another thread, I also added support for floating point textures on OpenGL, though this somewhat more hacked, and should prob be tidied up a little before checking in:
http://dl.dropbox.com/u/2809326/Floatin ... ures.patch

Would it be possible to write access to the SVN repository so I can check-in directly ?

Posted: Sat Nov 20, 2010 1:03 pm
by CuteAlien
Thanks for the patches. Tangents.patch seems to be 3 patches in one.

The SViewFrustum changes have been requested recently by more people, so I guess everyone is happy when they are applied.

The tangents fix for dx looks also look good to me on first view. If you have any test-model for me to check if it works I can apply it.

Don't know about the fast_atof change, I don't think that is correct (as the value can't be larger than UINT_MAX), what was your reason for changing this?

Posted: Sat Nov 20, 2010 4:49 pm
by griffin2000
CuteAlien wrote: Don't know about the fast_atof change, I don't think that is correct (as the value can't be larger than UINT_MAX), what was your reason for changing this?
Ah yeah, the X loader was hitting that error case in findNextNoneWhiteSpaceNumber. If the number to be read was larger than INT_MAX (but less than UINT_MAX) then it would get truncated incorrectly. Looking at it again it seems the correct solution is to add strtou10 that returns u32.

Posted: Sat Nov 20, 2010 5:57 pm
by griffin2000
griffin2000 wrote:
CuteAlien wrote: Don't know about the fast_atof change, I don't think that is correct (as the value can't be larger than UINT_MAX), what was your reason for changing this?
Ah yeah, the X loader was hitting that error case in findNextNoneWhiteSpaceNumber. If the number to be read was larger than INT_MAX (but less than UINT_MAX) then it would get truncated incorrectly. Looking at it again it seems the correct solution is to add strtou10 that returns u32.
Here is the corrected code. With the new function:
http://dl.dropbox.com/u/2809326/Correct ... ents.patch

Posted: Sat Nov 20, 2010 9:20 pm
by xirtamatrix
Splendid! Going to test it asap.

The collada format also contains binormal and tangent information (and there are excellent Collada exporters for most major design apps). Could you possibly also do the same for Collada (.dae) loader? That would be a great and *very* needed addition.

Thanks for the effort and for sharing.

Posted: Sat Nov 20, 2010 9:35 pm
by CuteAlien
The following line looks suspicious:

Code: Select all

if ((tangentpos != -1 && tangentpos == 1) || (binormalpos != -1 && binormaltype == 1))
Did you want to check for tangenttype instead of 2 times for tangentpos?

Posted: Sat Nov 20, 2010 10:46 pm
by griffin2000
CuteAlien wrote:The following line looks suspicious:

Code: Select all

if ((tangentpos != -1 && tangentpos == 1) || (binormalpos != -1 && binormaltype == 1))
Did you want to check for tangenttype instead of 2 times for tangentpos?
Indeed, well caught, should have read:

Code: Select all

if ((tangentpos != -1 && tangenttype == 2) || (binormalpos != -1 && binormaltype == 2))

Posted: Sat Nov 20, 2010 10:50 pm
by griffin2000
xirtamatrix wrote:Splendid! Going to test it asap.

The collada format also contains binormal and tangent information (and there are excellent Collada exporters for most major design apps). Could you possibly also do the same for Collada (.dae) loader? That would be a great and *very* needed addition.

Thanks for the effort and for sharing.
Indeed unfortunately the Collada loader does not support skinning, so is no good for my needs. I make take a stab at adding both features at some point as its generally a much more widely supported format.

Posted: Sun Nov 21, 2010 10:00 pm
by CuteAlien
I start to run into problems because I don't really know enough about mesh-loaders. I suppose this solution might have trouble when more than one texture is set because the vertex format would no longer correspond to the materialtype.

As far as I can see right now the only choice for material is setting it to video::EMT_LIGHTMAP after a check that probably looks if a second texture is available. Otherwise it should be set to EMT_SOLID. Solid would probably be fine as S3DVertexTangents is derived from S3DVertex, but S3DVertexTangents and S3DVertex2TCoords are incompatible.

Maybe I'm missing something, but I think we must also figure out which Materialtype to use for the tangent formats or the results should be unpredictable.

Posted: Mon Nov 22, 2010 7:21 pm
by griffin2000
My reading of the code is that its an either-or thing. You can't have 2 UVs and tangents, only one or the other. That is a bit of a pain (it means you can't have lightmaps and normal-maps)

Posted: Mon Nov 22, 2010 7:30 pm
by fmx
griffin2000 wrote:My reading of the code is that its an either-or thing. You can't have 2 UVs and tangents, only one or the other. That is a bit of a pain (it means you can't have lightmaps and normal-maps)
Exactly :x

Messing about with loaders right now is pointless because irrlicht is still heavily restrictive about vertex formats.
Its possible to hack in two UV sets into Tangent vertex format (the most flexible of the three which irrlicht supports) but it isn't logical or convenient to modify all the loaders to do it that way

Irrlicht needs flexible vertex formats ASAP

Posted: Mon Nov 22, 2010 8:43 pm
by CuteAlien
In this case we would use one of the normal-map materials. Which won't hurt and might be useful for some people. And yeah -having both is currently not possible.