Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


OBJ files, in Direct3D


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 Reegan   Members   -  Reputation: 100

Like
0Likes
Like

Posted 22 March 2009 - 08:08 PM

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]

Sponsor:

#2 Geoffrey   Members   -  Reputation: 554

Like
0Likes
Like

Posted 23 March 2009 - 01:41 AM

Quote:
Original post by Reegan
the faces in each file are completely out of whack with eachother!!


How do they differ?

#3 c00ler   Members   -  Reputation: 122

Like
0Likes
Like

Posted 23 March 2009 - 02:01 AM

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

#4 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

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
Systems Programmer

Rockstar North


#5 Reegan   Members   -  Reputation: 100

Like
0Likes
Like

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
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?



#6 Dancin_Fool   Members   -  Reputation: 621

Like
0Likes
Like

Posted 23 March 2009 - 09:03 AM

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.

#7 wodan   Members   -  Reputation: 122

Like
0Likes
Like

Posted 23 March 2009 - 09:11 AM

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!

#8 Reegan   Members   -  Reputation: 100

Like
0Likes
Like

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.




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