Better Collada and OBJ support...

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
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Better Collada and OBJ support...

Post by RyanClark »

Hi all,

Here's an update to the OBJ loader, to preserve smoothing groups. This is necessary for proper normal-mapping. Also an update to the Collada loader, which preserves smoothing groups AND adds support for meshes in the Collada 1.4 format.

http://www.ryanclark.net/irrlicht/S3DVertex.h

http://www.ryanclark.net/irrlicht/CColl ... Loader.cpp

http://www.ryanclark.net/irrlicht/COBJM ... Loader.cpp

Please feel free to republish these under any license.

cheers,

-Ryan Clark
Last edited by RyanClark on Tue Sep 04, 2007 10:58 pm, edited 2 times in total.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Cool, thanks. I'll add it for the next release. We are currently integrating the animation system, so it might take some days until I can cope with this.
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

Cool.

I'm actually seeing some terrible loadtimes with this code because it's doing dumb things. I need to fix the performance and re-post...
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, then I'll wait for the next version. I guess there are enough things with the animation system to work on until then :wink:
BTW: Remember to ignore smoothing groups in .obj meshes when finding vertex normals. These override the smoothing group marker.
Also could you develop the code against the latest SVN revision? There are some conflicts between my latest changes and your code.
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

I've updated the code now. I'm developing against v1.31. I hope I'm not duplicating work that's already been done!

I'm not actually looking at smoothing group flags; all I'm doing is sharing identical vertices between faces. For some reason, the old code was breaking faces apart, duplicating vertices that should be shared. This was causing bad seams in the tangent space.

Also, the Collada 1.4 support is only for basic meshes. I haven't updated lights or scenes or other Collada stuff to 1.4.


Here is an image to illustrate the change.

Image
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh, I see. I'll have to check this then. Is the code updated now?
lester
Posts: 86
Joined: Mon Jan 29, 2007 3:33 pm

Post by lester »

oh great! I was allways wondering what's wrong with my meshes as I export them from blender and they look flat shaded. That was just irrlicht's bug
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Could you please also upload the .obj file?
I don't understand the operator> for S3DVertex - that's operator== :!:
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

Oops! Thanks for pointing that out!

I started writing an > operator, realized it wasn't needed, and left it unfinished.

I've removed it now. My apologies :)
RyanClark
Posts: 15
Joined: Sun Jul 22, 2007 7:34 am
Location: Chicago / Austin
Contact:

Post by RyanClark »

Here is the teapot model used in the above images.

http://cggmwww.csie.nctu.edu.tw/courses ... teapot.obj


Seams will appear when you use the mesh manipulator to calculate "smooth" normals. or to generate a smooth tangent space using the code I posted previously. http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=23046

Since faces were not connected to each other by the old loader, smooth operations on the mesh were impossible.

The new code does preserve non-smooth faces. In fact, it makes no change to the appearance of the mesh; It simply preserves the relationship between smooth faces, so that the mesh manipulator can use it in the future, to calculate smooth normals or tangents.

The new code also makes the mesh a lot smaller. So even if you aren't normal mapping, you should see improved performance.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, I understand the intention now. It's indeed a known problem that, due to the vertex normals used, we often duplicate vertices. It's not strictly necessary, and as we now see it is often evil, but this was done in favor of speed. So did you already measure larger meshes? Just curious before I'm going to commit this to the core :wink: Which will last some more time anyway as I'll have to port your code to the latest SVN revisions.
Post Reply