[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Faster OBJ loader



On Mon, Sep 27, 2010 at 7:52 PM, Ian Mallett <geometrian@xxxxxxxxx> wrote:

On Mon, Sep 27, 2010 at 4:49 PM, Christopher Night <cosmologicon@xxxxxxxxx> wrote:
Hi, I'm looking into modifying the well-known objloader.py on the pygame wiki:


I would modify it to use vertex arrays. I think this could improve efficiency of loading and rendering the models, based on some tests I did a few months ago on the pyweek message board:
Vertex arrays would only be marginally faster than fixed functionality for rendering.  This version loads into display lists, which are about as fast as possible for that.  You won't be able to get better rendering performance. 

Thanks for the response! Assuming that rendering means what I think it means (actually drawing the thing on the screen, right?), I was able to improve the rendering performance significantly using vertex arrays in the test I did a few months ago. I was still using a display list as well, but I greatly reduced the number of GL commands within the display list. The trick was to triangulate all the faces, and render all the faces for a given material using a single call to glDrawArrays(GL_TRIANGLES...). I realize this is hardware-dependent, but the speedup was dramatic on 2 out of 2 systems that I've tried. Maybe it's not the vertex arrays that matter, and triangulating all the faces and using a single call to glBegin(GL_TRIANGLES) would yield the same speedup. Either way, it's worth looking into I think....

Improved loading performance comes from the fact that these arrays can be pickled, so you don't have to read them directly from the OBJ file after the first time. You only need to distribute the pickled OBJ/MTL files with your actual game. Psyco or C might be just as good, but this solution was pretty simple, and reduces the (subsequent) load times to almost nothing.

I'm very interested in any more feedback you have on this! I'm a real beginner when it comes to OpenGL stuff!

I started with this particular loader and extensively modified it and improved it to support vertex arrays, vertex buffer objects, display lists, and fixed functionality.  It also has better support for .mtl files and handles file loading and texturing more elegantly.  It also calculates the tangent vectors for use in normalmapping and related techniques.

It's presently integrated into glLib Reloaded, my project, which I humbly present.  The actual loader, (glLib/glLibLoadOBJ.py), is heavily tied into the rest of the library, and as such I can't support using it in other ways--but, you may find it useful.

Great, thank you so much! I'll definitely have a look!

-Christopher