Wavefront files with Blender [SOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Wavefront files with Blender [SOLVED]

Post by Benjamin100 »

When I export a wavefront obj file with blender, I get the vertices, but it doesn't seem to be in triangles. When I use "GL_TRIANGLES" the cube looks all out of order. I check the box for "triangulate" also. What else should I do?
Last edited by Benjamin100 on Mon Mar 03, 2014 4:51 pm, edited 1 time in total.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Wavefront files with Blender

Post by dandymcgee »

Are you sure you have the clockwise / counter-clockwise orientation correct?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

Well, I'm not really sure how to control the orientation. Is there something other than the z and "y is up" options that I should be paying attention too? I don't see very many options in Blender. Or do you mean that I need to program it a certain way?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Wavefront files with Blender

Post by dandymcgee »

Benjamin100 wrote:Well, I'm not really sure how to control the orientation. Is there something other than the z and "y is up" options that I should be paying attention too? I don't see very many options in Blender. Or do you mean that I need to program it a certain way?
Well that depends what "looks all out of order" means exactly. Perhaps an image would be useful.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

Well, when I do "GL_POINTS" I see the 8 vertices as I would expect, but when I use triangles or triangle strip, it is as if it connects in the wrong order, it looks all twisted and missing sides and a face going diagonally across the middle.
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

Re: Wavefront files with Blender

Post by bbguimaraes »

If the points are correct, my guess is the edges are being loaded incorrectly. Create a simple model and take a look at the data produced by the code that loads this information from the file.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Wavefront files with Blender

Post by qpHalcy0n »

Are you backface culling?

Not familiar with wavefront's format but if you have a poly list you should have a good solid object model. If your poly winding order is off, then if you have backface culling for either CW/CCW then you'll get exactly the anomalies you're seeing.

Either way, this should not happen with a good design because you should be able to cull back faces for solid object models.
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

Thanks for the advice.

I don't understand why I would need to load edges if I have the vertices.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Wavefront files with Blender

Post by qpHalcy0n »

You wouldn't need to at all unless that information was useful to you.

If there is no poly list, however, then you will require the edge list. You may have to build it yourself with correct winding order.
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

Well, I took a break from this for a while, and now I'm back to trying to understand my old code.
I'm mostly confused about the Obj file format.
What are the numbers associated with the faces for? What do they tell me?
I see three pairs of numbers for each face, each pair separated by two slashes.
What does this tell me and how does it help me draw the object?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Wavefront files with Blender

Post by dandymcgee »

Have you read the Wiki article? http://en.wikipedia.org/wiki/Wavefront_.obj_file

If you want more details about a particular section, just click the citation link and browse to the site where the information was sourced from.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

Ok. I transitioned to using 3ds because the lib3ds library looked helpful, and I didn't want to deal with parsing the files myself anymore.

But I still have problems drawing. I don't understand why I need any more information than the vertices to draw the triangles. What is the purpose of the list of faces? What other information do I need? Are the vertices simply written out of order?
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender

Post by Benjamin100 »

So I leave this for months out of frustration over this one problem.
No matter what I do I cannot load the file information correctly to draw to the screen.
I have it all, and yet many of the vertices look out of place, and almost random.
Then, it occurs to me, that such a thing would happen if it was taking the color array as the vertex array. So I change a number in the color array, and one of the polygons drastically changes size.
Well, that much should be easy to fix.
Benjamin100
ES Beta Backer
ES Beta Backer
Posts: 250
Joined: Tue Jul 19, 2011 9:37 pm

Re: Wavefront files with Blender [SOLVED]

Post by Benjamin100 »

Finally got an OBJ file model on the screen. No lighting yet, but I finally got the info. Found a tutorial that gave a good explanation of how to get the face information and use it to order the vertices. What a relief!
Post Reply