tags:

views:

340

answers:

1

I'm trying to load and display (EXTREMELY SIMPLY) a wavefront OBJ file.

I have the parser working 100%... it loads the data from the files and stores them in structures in the program.

Now is the part where I am utterly failing to find any information on, the target data structure.

I have no clue how to use Vertex Buffers and Index Buffers, I've only ever used Display Lists and Immediate Mode in OpenGL.

Now I'm trying to work with Managed Direct X and I am having serious problems wrapping my brain around this.


There's several things I'm confused about...

1) Are there any good tutorials on how to store and render simple VB & IB objects in MDX?

2) What Vertex Format should I use? The OBJ spec allows you to miss the texture or normal indexes if the Vertex doesn't have one defined (so certain faces could have the normal, texture, and position indexes while others may have JUST location). So do I just store it in a CustomVertex.PositionNormalTexture and then leave the normal and texture blank if they aren't defined in the OBJ?

3) This is the hardest one for me to understand (possibly stemming from my ignorance of the concepts of VB and IB). The OBJ spec allows (and my sample file has) faces that have an arbitrary number of vertex indexes. Basically, the face can be defined as

f 1/1 2/2 3/3 4/4 5/5 6/6 7/7 8/8 9/9 10/10

The problem is, how do I render that? Is that a triangle strip, a polygon, etc?


As an alternative, if someone knows of any PRE-EXISTING solutions to do this (a very lightweight and well documented 3D system on C# that can load OBJs itself or through an already made plugin) that would be good as well.

Mogre is out, such poor documentation it's laughable (incorrect Wiki info, inconsistencies in docs, etc.)

I've tried Irrlicht, and this is the closest I've come. It has a built in OBJ loader, which is nice (and doesn't throw any exceptions like 90% of the other prebuilt OBJ viewers out there (I think it's due to the arbitrary # of vert faces, most parsers seem to fix on a max of 3 or 4). The only problem with Irrlicht is A.) I can't figure out how to apply the textures to the OBJ files, and B.) I can't figure out how to render it INTO a control rather than the whole form (want the windows form UI with a 3D viewport embedded in a control).

If you can solve either of Irrlicht's problems, that would be an accepted answer as well.

Edit: Also, if you know of a C# Library or a REALLY small command line .exe that I can use to convert from OBJ to another 3D format that would be much easier to use, I would also like to know.

A: 

There are a bunch of loaders for OpenGL (OpenTK specifically, a .NET wrapper around OpenGL) at this page:

http://www.opentk.com/node/642

The best of which appears to be Meshomatic.


Here's another in CSat, but the code doesn't look too great:

http://code.google.com/p/csat/source/browse/trunk/csat_src/ObjModel.cs

And here's another:

http://www.google.com/codesearch/p?hl=en#m0z-eXZOCSQ/trunk/mmokit/3dspeeders/tools/SkinEdit/OBJFile.cs&q=OBJFile.cs%20package:http://mmokit%5C.googlecode%5C.com&sa=N&cd=1&ct=rc


An observation, as I approach this myself, is that the loader is dependant upon the represenation you use for transferring data to OpenGL, such as the arrangement within a VBO. Furthermore there are some features of .obj files that some people choose to omit, such as smoothing groups and support for quads/polys as well as triangles.

Drew Noakes