xfile loading/parsing tutorials

Started by
22 comments, last by GameDev.net 19 years, 4 months ago
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.
Advertisement
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 facespData->Lock( &size, &pDword );DWORD numFaces = *pDword;pData->Unlock();// Create vertex buffer bug enough for numFaces * 3 vertices.// get vertex datafor( 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 indicespData->Lock( &size, &pDword );DWORD numIdxFaces = *pDword;pData->Unlock();// Create index buffer big enough for 3 * numIdxFaces// get index datafor( 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.


[size=2]aliak.net
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.
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

This topic is closed to new replies.

Advertisement