Monday, 26 December 2011

Quran Project - Loading 3D Obj Models

Reading e-books is like eating marmite. You either love it or hate it. Myself personally, I read lots of articles, but never have the attention span to get through a book. Currently we're working together with the Quran Project charity (http://quranproject.org) in trying to re-create your typical reading experience into something more as an interactive 3d novel. The basic idea being that you get to browse the different chapters of the book, by swiping through different scenery and animations that hopefully entice you to read on more than perhaps you normally would.



Working along with a 3d artist has it's challenges, ranging from getting your naming conventions right to importing the assets created.

The models I'm working with have been exported from Maya as obj files. In the past I'd write my own exporter into my own personal favoured file format. However, I took this opportunity, to go with the flow for compatibility reasons and work on getting obj files imported into the application engine I'm working with.

I found a great ObjLoader tutorial series online here (http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www), I tested out the provided tutorials with the model exported and found that tutorial3 was everything I needed to get to the obj description.



Integrating the objloader header and cpp file into an iOS project can be done with minimal changes to get it compiling. Those being to comment out win32 specific includes and switch from the OpenGL method of drawing polygons using glBegin and glEnd, into an OpenGL ES compatible vertex array using GL_TRIANGLES.

So the first step would be to take the loaded in vertices and draw them using OpenGL ES's GL_TRIANGLE construct, but of course this would lead to an incomplete scene.


What we need to do is switch from OpenGL's GL_POLYGONS to OpenGL ES' GL_TRIANGLES. To do so we can create a triangles from the first vertex and remaining vertices of the polygon.

As in if we have a 5 sided polygon.
We'll make a triangle from the first three vertices (v1, v2, v3).
Then, the first vertex and the next two (v1, v3, v4).
Then finally, the first vertex and the last two (v1, v4, v5).



You can grab the source code from the Open Source cross platform application framework (here) with the file to watch out for being CCModelObj.cpp.

4 comments:

  1. The first paragraph is such a win.

    I actually need to concentrate really hard to read the rest so I'll be back with more comments.

    Fan. Tas. Tic.

    ReplyDelete
  2. It was wondering if I could use this write-up on my other website, I will link it back to your website though.Great Thanks. cnc clipart

    ReplyDelete
  3. Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck. Markforged 3D Printers

    ReplyDelete
  4. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. 3D models STL

    ReplyDelete