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]
OBJ files, in Direct3D
Started by Reegan, Mar 22 2009 08:08 PM
7 replies to this topic
Sponsor:
#4 Moderators - Reputation: 1918
Posted 23 March 2009 - 02:11 AM
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}).
Steve Macpherson
Senior programmer, Firebrand Games
#5 Members - Reputation: 100
Posted 23 March 2009 - 08:50 AM
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
*.x
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?
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?
#8 Members - Reputation: 100
Posted 23 March 2009 - 09:16 AM
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.
wooooo *is happy now*
EDIT: They do aswell [smile] good stuff.







