Sign in to follow this  
IFooBar

xfile loading/parsing tutorials

Recommended Posts

I've noticed a lot of questions regarding xfiles and how to manually load them in. So I took the liberty of writing 2 tutorials about it. One loads xfiles and displays it, the other manually parses the xfile and loads the mesh information in. Tutorials can be found in my sig, and look forward to more mesh related topics...

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Alf, I haven't seen you in ages on MSN, but you should submit these tutorials to GDNet aswell, and have them end up on the frontpage. People will see them quicker than.


That's becuase I don't sign in too much. But anyway, it's easier and quicker to just stick the tutorials up on my site. And besides I have a whole collection now, so one tutorial outside wouldn't really make sense.

Share this post


Link to post
Share on other sites
great tutorial!
the document in the sdk help is just not enough to explain how this works!
are you going to update the tutorial with the new ID3DXFile interface in dx9?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Great tutorial -:)
Just a small request,would you be able to update this tut to also load the textures and to demo the use of the anim controller please?

keep up the good work.
One more thing(before i forget)...the bumpmapping tut on your website is missing some files,or it needs or uses your GameSDK?

would it be possible to seperate this tutorial from your SDK if that is the case.

Thanks -:)

Share this post


Link to post
Share on other sites
Quote:

Great tutorial -:)
Just a small request,would you be able to update this tut to also load the textures and to demo the use of the anim controller please?

Thanks,

Animation is on the todo list. It'll get there eventually.

Quote:

One more thing(before i forget)...the bumpmapping tut on your website is missing some files,or it needs or uses your GameSDK?

would it be possible to seperate this tutorial from your SDK if that is the case.


It needs the mini sdk, yes. Which can be downloaded from the main tutorials page (before you enter the graphics section). It would be possible to seperate the tutorial from the SDK, but that SDK is just a bunch of really stripped down initialization routines (and input routines IIRC). So that would really be unnecessary.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks -:)
The reason i asked was becuase i'm still using VC++ 6,not .NET,
and i remember a while ago i tried to compile it under 6 and couldn't.I remember seeing on your forums someone posted a VS6 workspace,but the link is broken now.

I don't suppose you have a backup copy of that download i could get from you?

Thanks.

Share this post


Link to post
Share on other sites
To compile dx9 with vc6 you're going to have to download the vc6 libs. it's in the sdk extras download. If you've already done that, then you can post specific errors on the sites forums and we'll see what we can do.

Share this post


Link to post
Share on other sites
can you tell me how to load animated X file.
I am using Panda Exporter to load my X file and there's an option for the animation too but i dont know how can i pick up the frames of animation in DirectX. pretty hard though, I know but if anyone can help me it'll be very nice.
Thanx in advance.

Share this post


Link to post
Share on other sites
You can either parse the xfile your self and build the animation data by getting the TID_D3DRMAnimationSet, TID_D3DRMAnimation and TID_D3DRMAnimationKey. But you'll need to build a hierarchy by parsing TID_D3DRMFrame objects. OR you can can set up a few classes and use another way to do all this which is described here in a few docs and samples. Specifically the mesh hierarchy and skinned mesh docs is what you're looking for. If you're having specific problems however then you should probably create a topic for that so everyone can see and help you. Everyone is not going to be checking this thread since it's just an announcement.

Share this post


Link to post
Share on other sites
If we don't want to use the ID3DXMesh, how to interpret the X file data manually?

Specifically regarding the Mesh template, it contains:

NumVertices
Array of vertices
NumFaces
Array of MeshFace

Optionals are MeshFaceWraps, MeshTextureCoords, MeshNormals, MeshVertexColors, MeshMaterialList.

For simple meshes I could get by with loading the vertices in the array to a vertex buffer. As for the MeshFace array, I ignore the first item, which is the Number of FaceVertexIndices (seems to be always 3, I could be wrong since I don't really understand); then I just load the rest into an index buffer.

I could anyone provide a better explaination to the inter-working of this? What about the MeshNormals, seems to have the same dilema. Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hey IFooBar,thanks for your tutorials...very good :)
I have a couple of questions about the .x file format in general for you,as you seem to know your stuff about the format.

Someone recently told me that i would not be able to use the .x file format for characters or maps,if i wanted to use bump-mapping and light-mapping in my project.

Is this true? if so why is this,and what does he mean about the format being crap?

Can you(or anyone one) shed some light on this for me please?
I'm really starting to get into shaders now,and want to use this format for both my characters and map data.

So far,most of the books on directX iv'e read have said how flexible .xfiles are,so what this person said to me doesn't really make sense as he is a pro coder.

thanks.

Share this post


Link to post
Share on other sites
Quote:
If we don't want to use the ID3DXMesh, how to interpret the X file data manually?

Specifically regarding the Mesh template, it contains:


The Mesh templates contains the following data:

- number of faces
- face vertices
- number of indexed faces
- index data as arrays

That's the basics. You multiply the number of faces by three and you'll get how many vertices you have. You then loop through for that many vertices and get the vertex info. Then you get the indices by looping thorugh and reading arrays of 3. so, you'd go about it something like this:


SIZE_T size;
DWORD* pDword;

// Get num faces
pData->Lock( &size, &pDword );
DWORD numFaces = *pDword;
pData->Unlock();

// Create vertex buffer bug enough for numFaces * 3 vertices.

// get vertex data
for( int i = 0; i < numFaces; ++i )
{
float* c1, *c2, *c3;
pData->Lock( &size, &c1 );
pData->Lock( &size, &c2 );
pData->Lock( &size, &c3 );
D3DXVECTOR pos( *c1, *c2, *c3 );
// store pos directly in vertex buffer or put away in a std::vector
// or something to store later.
pData->Unlock();
pData->Unlock();
pData->Unlock();
}

// Get num indices
pData->Lock( &size, &pDword );
DWORD numIdxFaces = *pDword;
pData->Unlock();

// Create index buffer big enough for 3 * numIdxFaces

// get index data
for( int i = 0; i < numIdxFaces; ++i )
{
float* i1, *i2, *i3;
pData->Lock( &size, &pDword ); // array size comes first.
pData->Lock( &size, &i1 );
pData->Lock( &size, &i2 );
pData->Lock( &size, &i3 );
D3DXVECTOR idx( *i1, *i2, *i3 );
pData->Unlock();
pData->Unlock();
pData->Unlock();
pData->Unlock();
}



The MeshFace array (the last loaded thing in the for loop in the above code) is just an array of indices. Now I've never manually laoded in data using the new SDK yet, so Im not sure if the data retrieval is done correctly. Going by the documentation, teh above should work. The problem you seem to be having is with MeshFace. Its not just a group of 3 values. It's an array. It can have an arbitrary number of values in it. Almost all the time, it's 3 though. For every MeshFace, you fist have to read in the number of value sit contains, then you can read in the actual values.

Quote:
Someone recently told me that i would not be able to use the .x file format for characters or maps,if i wanted to use bump-mapping and light-mapping in my project.


you definetly can. lightmapping just requires texture coordinates which is available with standard xfiles. Although you cant store tangent and binormal data for bumpmapping in xfiles, you can compute it at run time which is what is usually done as far as I know. Cloning comes in handy over here. So it is very possible to use.

Quote:
if so why is this,and what does he mean about the format being crap?


I dunno, ask him. Maybe because it's very annoying to work with - which it is, but its like anything else once you get the hang of it. Best thing for you to do is experiment and decide for yourself whether you want to use it or not.

Quote:
So far,most of the books on directX iv'e read have said how flexible .xfiles are,so what this person said to me doesn't really make sense as he is a pro coder.


The person never implied it wasnt flexible by saying the format was crap. It is very flexible as Im sure this person will agree with you on that. But with flexibility comes complexity - unfortuanetly, and the complexity part is probably what he dosen't like.


Share this post


Link to post
Share on other sites
Is the number of indices for the face there for flexibility's sake, in which it's is almost always 3? For the MeshNormals, for the time being is it pretty much safe to ignore the index part? For example a simple geometry with 2 faces, 3 indices each. There may be syntax errors, but hopefully you'll get the idea:

Mesh Rect{
4;
0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 0.0, 0.0,
1.0, 1.0, 0.0;

2;
3;0, 1, 2;
3;2, 1, 3;

MeshNormals
{
4;
0.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 0.0, 0.0,
1.0, 1.0, 0.0;

2;
3;0, 1, 2;
3;2, 1, 3;
}
}

The only case I sometimes see is that one vertex may have many normals. Is there any examples out there where it loads meshes correctly and still providing the flexibility?

What about the idea of a "subset". I have a feeling that a subset is something( a group of faces) that uses the same material. How to correctly divide subsets while loading meshes?

Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
We are writing a Java loader for the DirectX "X" format. I am trying to find info on exactly what information is output from the animatian arrays in file specificly in the rotation end.
Here's my example
AnimationKey {
0; //rotation
41; //41 frames
0;4;-0.696364,-0.696364,-0.122788,-0.122788;;,
1;4;-0.696768,-0.696768,-0.120478,-0.120478;;,
2;4;-0.697852,-0.697852,-0.114028,-0.114028;;,
3;4; ? , ? , ? , ? ;;,
ect....
The question marks inicate the section we are having trouble finding info on.
The output type is keyframes. We have managed to get just about everything else loaded but this area eludes us. The X file template in the msdn is pretty vague.

Thanks in advance

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