OBJ files, in Direct3D

Started by
6 comments, last by Reegan 15 years, 1 month ago
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]
Advertisement
Quote:Original post by Reegan
the faces in each file are completely out of whack with eachother!!


How do they differ?
The Trouble With Robots - www.digitalchestnut.com/trouble
Hi,

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

Peace
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}).
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?

*.obj
Quote:#
# 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


*.x
Quote:Mesh Box01 {
8;
-1.000000;-1.000000;-1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000;1.000000;-1.000000;,
1.000000;1.000000;-1.000000;,
-1.000000;-1.000000;1.000000;,
1.000000;-1.000000;1.000000;,
-1.000000;1.000000;1.000000;,
1.000000;1.000000;1.000000;;
12;
3;0,2,3;,
3;3,1,0;,
3;4,5,7;,
3;7,6,4;,
3;0,1,5;,
3;5,4,0;,
3;1,3,7;,
3;7,5,1;,
3;3,2,6;,
3;6,7,3;,
3;2,0,4;,
3;4,6,2;;


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?

The indices in your OBJ file start at 1. The indices in your .X file start at 0. Just subtract one from each index as you load it in.
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!
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.

This topic is closed to new replies.

Advertisement