Jump to content

  • Log In with Google      Sign In   
  • Create Account

obj file format


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 codpp   Members   -  Reputation: 103

Like
0Likes
Like

Posted 13 July 2014 - 06:36 AM

I tried to load information about 3d model from a .obj file using opengl. But I noticed that some of them contain more than four vertices for a single face in f section.

Does that mean that face is a rectangle not triangle? If so, is it possible to render it out? A portion of the obj file that contain four vertices for a face is below:

 
s off
g polySurface11 polySurface12
usemtl initialShadingGroup
f 1/1/1 15/25/2 16/27/3 3/3/4
f 3/3/5 16/27/6 46/78/7 19/31/8
f 5/5/9 14/24/10 7/7/11  
f 15/26/12 1/9/13 20/33/14 21/34/15 2/10/16 
 
Thanks.


Sponsor:

#2 Sik_the_hedgehog   Crossbones+   -  Reputation: 1833

Like
1Likes
Like

Posted 13 July 2014 - 07:23 AM

OBJ files can contain polygons with an arbitrary amount of vertices (so yes, those are quadrilaterals). You need to convert them to triangles first if you want to render them using OpenGL.

 

The easiest and dumb way is to just treat them like a triangle fan, but that assumes all polygons are convex (which is likely the case for most models anyway). If that works out for your data then just do that and don't worry anymore. Otherwise, you can try loading the model in a 3D editor and reexport the model ensuring all faces are turned into triangles (Blender has a checkbox that says "triangulate" if I remember correctly, don't know about other editors).


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#3 Promit   Moderators   -  Reputation: 7621

Like
3Likes
Like

Posted 13 July 2014 - 08:50 AM

Personally I'd re-export them as triangles in a modeling tool, if possible.



#4 L. Spiro   Crossbones+   -  Reputation: 14263

Like
2Likes
Like

Posted 13 July 2014 - 04:16 PM

The normal method is to treat them as triangle fans, and it is trivial to convert them to triangles.
If you have 5 points then you have 3 triangles:
Fan: 0 1 2 3 4
Triangles:
0 1 2
0 2 3
0 3 4


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 mhagain   Crossbones+   -  Reputation: 8278

Like
2Likes
Like

Posted 14 July 2014 - 05:28 AM

I'd second Promit's advice: .obj is fine as an interchange format but for actual production use you're doing slow (and error-prone) text parsing which is just going to give you complex code and annoyed users.

 

The ideal model format is one where you can just memory-map a file and pass the resulting pointer directly to a glBufferData call.  You really shouldn't be doing anything more complex.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 Sik_the_hedgehog   Crossbones+   -  Reputation: 1833

Like
0Likes
Like

Posted 15 July 2014 - 11:57 AM

I don't think Promit ever suggested to not use OBJ, just to use a 3D editor to turn the quads into triangles.

 

In any case there's always the question of what to do with those OBJ files, because even if you don't use them directly you still need to convert them somehow. Ideally you'd have the conversion tool directly as a script for the editor itself (so you have access to all the original data). Or you could just use something like assimp in your game and avoid having to make your own parser.


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#7 Stainless   Members   -  Reputation: 1069

Like
0Likes
Like

Posted 16 July 2014 - 03:58 AM

Have a look at polytrans.

 

Not only is it an excellent tool for handling 3D meshes, it has options to triangulate meshes.

 

It can do all the hard work for you and then you can save the edited mesh in a format that is easy to parse in the game (or editor)

 

http://www.okino.com/conv/conv.htm


Edited by Stainless, 16 July 2014 - 04:01 AM.


#8 haegarr   Crossbones+   -  Reputation: 4587

Like
3Likes
Like

Posted 16 July 2014 - 05:14 AM

Using OBJ as source for GPU related APIs has at least these well-known issues:

1.) support for polygons with more than 3 vertices,

2.) usage of independent indices for positions, normals, tex-coords,

3.) is text based.

 

All of the above issues cause an essential amount of work to be done during import. Moreover, OBJ is AFAIK meaningful useable for static meshes only. With this in mind, OBJ is not a well suited format for use in game engines. It has limitations even in its use as input to tool chains. So, even if the mesh is exported with triangles only, not all problems are solved. OBJ seems to be a relatively simple format, and it actually is during the process of parsing, but it turns into headache if one wants to use the resulting mesh with  modern graphics APIs.


Edited by haegarr, 16 July 2014 - 06:12 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS