Sign in to follow this  

OBJ files, in Direct3D

Recommended Posts

ok, so i managed to write some code that would read OBJ files ( to an extent ) so i tried to see if the values i was loading in from .obj file would indeed form the mesh created in my 3d package, i created a simple cube and exported only the vitals ( vertex positions and faces ) then loaded it into my small application ( faces being the indicies loaded into the IndexBuffer ) only to find out that the cube looks nothing like it did in the 3d package * shock horror * So i thought, "ok, must be some setting somewhere i messed up.." - hour later - i decided to take a look inside a .x file and compare it with the .obj files data, vertex positions are roughly the same the except the Z components in the obj file are the inverse of the Z component in the .x file ( easily fixed when loading the data ). But the faces in each file are completely out of whack with eachother!! whats going on here? i tried googling around and to find some tutorials on loading obj files in directx but didnt find anything of use. perhaps someone here can explain what i have to do to get the correct faces, and ultimatly a good looking cube [smile] i tried: - changing options in the exporter - changing the primitive topology - swapping the Y/Z - googling.. - and some other stuff... Thanks in advance ~Reegan [Edited by - Reegan on March 23, 2009 2:33:01 AM]

Share this post

Link to post
Share on other sites

There's a sample integrated in the DXSDK wich show you how to load .OBJ in your DX scene :

C:\Program Files\Microsoft DirectX SDK (November 2008)\Samples\C++\Direct3D10\MeshFromOBJ10

Good Luck


Share this post

Link to post
Share on other sites
Have you tried disabling culling (pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE))? It may be that OBJ files store their vertices in counter-clockwise order; especially if Z if flipped. If that fixes it, then try changing the order of your indices (From {1, 2, 3} to {1, 3, 2}).

Share this post

Link to post
Share on other sites
Hi, thanks for the replies ive tried what you have all said already, no luck [sad]

Here are the two exact same cube mesh files ( in *.x and *.obj ) with there differences. I dont know alot about indicies so i cant really figure what should go where.. maybe you guys can figure this out?

# object Box01

v -1.00 -1.00 1.00
v 1.00 -1.00 1.00
v -1.00 -1.00 -1.00
v 1.00 -1.00 -1.00
v -1.00 1.00 1.00
v 1.00 1.00 1.00
v -1.00 1.00 -1.00
v 1.00 1.00 -1.00
# 8 vertices

g Box01
f 1 3 4
f 4 2 1
f 5 6 8
f 8 7 5
f 1 2 6
f 6 5 1
f 2 4 8
f 8 6 2
f 4 3 7
f 7 8 4
f 3 1 5
f 5 7 3
# 12 faces

Mesh Box01 {

the .x file one works all i have to do is plug in the values into the vertex and index buffers and voila! but the .obj is seriously messed up.

Any help here?

Share this post

Link to post
Share on other sites
Looks like the only difference is, that the indices in your .obj file aren't zero based. The order is the same though.
Try to subtract 1 from each index when you load it.

EDIT: man, am I typing slowly!

Share this post

Link to post
Share on other sites
Holy **** it worked! thanks alot guys! how strange that .obj files start at index 1 :S, im going to check the mesh from obj tutorial and see if they subtracted 1 from each index or not.

wooooo *is happy now*

EDIT: They do aswell [smile] good stuff.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this