vertex declaration data in .x file

Started by
4 comments, last by Rebuto 18 years, 8 months ago
Hi, I'm writing my own .x loader (weird, I know) and have stumbled upon the DeclData block. I´ve looked at the documentation and understand that it´s just a list of vertex elements plus the data of each vertex element. But I don´t understand the format/order that the actual data is in. Sorry if this seems very basic but I´m trying my best here. Here´s an example, I got this by exporting a cube (I simply created it and exported it) using the exporter in the August version of the sdk: DeclData { 3; //this tells us that three vertex elements are coming up as part of the vertex declaration //vertex declaration: 2;0;5;1;, //D3DDECLTYPE_FLOAT3 ; D3DDECLMETHOD_DEFAULT ; D3DDECLUSAGE_TEXCOORD ; usage index 1 2;0;7;0;, //D3DDECLTYPE_FLOAT3 ; D3DDECLMETHOD_DEFAULT ; D3DDECLUSAGE_BINORMAL ; usage index 0 2;0;6;0;; //D3DDECLTYPE_FLOAT3 ; D3DDECLMETHOD_DEFAULT ; D3DDECLUSAGE_TANGENT ; usage index 0 //now comes the data. this is the part I'm having trouble with... 297; //there´s 33 vertices in the mesh. the vertex declaration tells us to expect //3 float3 per vertex (that means 9 floats per vertex) : 33 * 9 = 297 //so far so good, but I don´t know how to interpret the actual data that comes next: 0, 0, 0, 0, 3212836864, 3045602801, 0, 898119153, 3212836864, 0, 0, 0, 0, 3212836864, 3045602801, 0, 898119153, 3212836864, 1, 0, 0, 0, 3212836864, 3045602801, 0, 898119153, 3212836864, 4294967124, 4294966825, 4294967124, ...and so on (there´s 297 numbers here in total) For starters, the vertex declaration tells us there´s an extra set of texture coordinates. What does this mean? I didn´t texture anything in 3ds max, I created a box and exported it, nothing else. What do these coordinates represent? Then, how are the numbers in the list of data grouped? I assume the first three numbers correspond to the extra texture coordinates in the first vertex, the next three numbers would be the binormal of the first vertex, the next three would be the tangent of the first vertex. Then we would proceed to the second vertex (textcoord, binormal, tangent), and so on. But these numbers don´t make any sense. Please help, I´m really lost here. Thanks in advance. [Edited by - Rebuto on August 10, 2005 8:06:07 PM]
Advertisement
Think of the DeclData as a vertex buffer.
first you pull out all of the vertex elements that you are going to represent as other templates in the system outside of the decldata...
Then the top part is the array of remaining vertex elements.
Followed by the remaining compacted vertex buffer byte* casted to a DWORD* and then serialized out to disk.
It's wierd but it works...and there is no loss of percision.
unfortunately it's also not very human-readable.

so in your example 297 just means that there are 297 DWORDs
just copy them as a chunk of memory and use the vertex declaration at the top to access your data right out of the binary chunck.
That solved it. Thank you!
Oh, one more thing.

Do you have any idea what the additional set of texture coordinates in the "vertex buffer" might be used for?

Binormal and tangent data seems to be correct when I cast the data to a float*, I just don´t know what to use the additional set of texture coordinates for :p

Thanks though.
In 3ds max different texture maps can have different texture coordinates. There are probably some cases where this is useful. I just can't remeber one for now ;-).

BTW: I'm writing my own .x loader, too. It's so frustrating ... Everywhere is written that the .x format is so well defined and clear but in reality the microsoft specs leave so many things open that have to be filled with good assumptions. :-grrrrrr
Sure, 3ds max can have lots of sets of different UVs but I didn't create any, I just created a box and exported the scene :p

Besides, the values I get back don´t look like UVs, they're super big (unlike the tangent and binormal data, which look ok).

I think that I´m getting some funny data in the form of texture uvs. It makes sense since this is essentially the same as when you´re passing your own data to a shader and there´s no specific usage available for it. Then you just give it textcoord usage and use it within your shader however you like.


On a different note, where´s this .x file format spec you mention? All I´ve found is the Microsoft DirectX File Format Specification Version 1.13 (1997). Believe it or not that´s what I´m using. It´s a little incomplete, specially regarding block references, but it´s all I got.

Thanks!

This topic is closed to new replies.

Advertisement