سؤال

I have created a an OBJ loader that can import .OBJ files that were exported from 3DS Max into my simple OpenGL viewer / app. At the heart of this was a Vector3.h written with the help of some tutorials.

It worked great on a couple models I used, but the one I want to work with has something different that wasn't accounted for. It has 4 points in its vertices instead of 3. Here is a sample of a line I am working with:

g Box02
usemtl Wood_Bark
s 4
f 1/1/1 2/2/1 3/3/1 4/4/2
f 4/1/3 3/2/3 5/3/3 

The first 'f' line has 4 vertices I am interested in. My Vertex3.h takes X, Y, Z. In the other models I had, all lines were like the second 'f' line, with only 3 elements. I am getting a vertex out of range, so when I went to check where it was happening, I saw it was on this line, so I assumed because there is more data on the line that can be handled. Here is the entire Vertex3.h

http://pastebin.com/dgGSBSFe

And this is the line of code that fails. vertices is a Vector3.

tempVertices.push_back ( vertices[--vertex] );

My question is, what is the 4th point? How would you account for that in something like my Vector3.h file? Seems like I need to create a Vector4.h, and ignore the 4th var if there is only 3 on the line. But I would like to know more about what I am dealing with, and any tips on how to do it. Is the 4th element an alpha or something? How should it be used, or should it be used at all in my calculations in Vector3.h?

هل كانت مفيدة؟

المحلول

A face with four points is called a quad. Usually if you want to render it you should break it up into two triangles.

So for example, you have this:

 ___
|   |
|   |
|___|

You need to turn it into this:

 ___
|\  |
| \ |
|__\|

Assuming the vertices go counter-clockwise (the default in OpenGL), starting from the upper left, you could make two triangles. The first triangle's vertices would be the quad's first, second, and third vertices. The second triangle's vertices would be the quad's third, fourth, and first vertices.

نصائح أخرى

Why don't you export as triangles only? Convert to EMesh in 3ds max, make all edges visible, export. Or simply use the appropriate OBJ export option.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top