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

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

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

Post 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 ?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

Post 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.
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

Post 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
xirtamatrix
Posts: 219
Joined: Fri Feb 19, 2010 4:03 pm
Location: Estonia

Post 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.
to live, is natural; to die, is not!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

Post 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))
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

Post 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.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
griffin2000
Posts: 22
Joined: Mon Nov 15, 2010 9:18 pm

Post 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)
fmx

Post 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
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply