im searching now for a quite long time to find something working to import
Blender 3D .obj files into xcode to use it on an iphone application.
i cant find a description how to implement something like that anywhere!
i dont want to use any engine. i just want to know the steps i have to
fullfill and the basic things to do.
there is really nothing on the www. you can find articles from 2005 - 2008
but thats all not up to date and nothing working.
So, does anybody knows how to do that?
take a look at the source in libgdx, and take a look at the objloader. He built the lib to be able to load obj files, and is supposed to work across multiple platforms (including ios). From reading the source you will see that creating an object loader for just the vertices is really simple, but becomes more complicated when you start caring about the normals and texture coords. Here is a simple algorithm for scraping an obj file (I will leave parsing the associated tpl file for the reader's own research):
- Read in the lines of the file, throwing out all lines that start with
#
(comments)
- Vertices look like:
v 1.000 1.000 1.000
, so, if line starts with 'v '
split the line on the spaces and store (and convert to float) the 3 floats as a vertice.
- Normals look like:
vn 1.000 1.000 1.000
, so, if the line starts with 'vn '
do the same as number 2, but store as a normal.
- Texture coords look like
vt 1.000 1.000
with a possible 3rd [w]
value, split and store the line in the same way.
- Now it gets tricky, there is the face descriptions that look like
f 1/1/1 2/2/2 3/3/3
these are describing 3 vertices/textcoords/normals (in that order) for each of the vertices of a shape (normally they are triangles) by index. The hardest part about this is that the obj file type uses three indexes instead of one like opengl or direct3d. So you will have to shuffle around the order of your vertexes/coords/normals so that you can utilize indexed drawing on the sources.
E.g. Basically you have to get the f 1/300/30 40/22/400 20/30/10
to become more like f 1/1/1 2/2/2 40/40/40
through reshuffling the order.
This site gives you an idea of this same algorithm and shows you an example of how to go about this in a high level algorithm (go about midway down on the page), and the source code he references for you to check out can be found here.
Anyways, let me know if you need anymore assistance. :)
Edit:
By the way if you see something like this: f 1//4 2//5 3//7
don't be alarmed, this is a valid file as intended and just means (in this instance) that there are no texture coords
I used the GLEssentials sample app as a starting point. It is really bare bones, but its kind of what you want to start with so you can really understand the format for when you decide to add to it later.
https://developer.apple.com/library/mac/#samplecode/GLEssentials/Introduction/Intro.html