# kW X-port: new X file exporter for 3dsMax 8

## Recommended Posts

The SDK exporter for X files out of 3dsMax version 8 has been busted for years now. The Panda exporter works pretty well for some things, but I ran into a few bugs with exporting skinned geometry using off-origin object offset, and it also doesn't support scales other than system units. Last, its management of settings wasn't what I needed -- I'd like settings for each file to be stored in that file, because I use many different kinds of settings for different files. Last time I tried fixing this, IGame (an API within 3dsMax) was too buggy to be used well. However, this time, version 2.0 of IGame is actually usable (if not bug free), so I spent a few vaccation days writing an exporter. Feel free to try it out and let me know how it works for you. Make sure you use the pre-requisites installer if you don't have the VS 2005 runtime libraries already installed. Screen shot:

##### Share on other sites
Very cool :)

I'd try it out, but I don't have 3ds.

##### Share on other sites
Yeah, this post is kind-of only interesting for the intersection of people who use 3dsmax, and those who use .X files...

##### Share on other sites
Quote:
 Original post by hplus0603Yeah, this post is kind-of only interesting for the intersection of people who use 3dsmax, and those who use .X files...
Admittedly I don't use 3dsmax myself (would have to sell my body for medical research to pay for a licence [lol]), but I see enough threads in this forum asking about it. Stickied for a bit so that it (hopefully) gets seen by those that keep asking about it [smile]

Cheers,
Jack

##### Share on other sites
I'd actually prefer a little more third party testing before getting too much wide-spread usage, but thanks. I'll sticky a new thread once it's shored up a bit.

##### Share on other sites
hehe, okay then - hopefully I'll spot it, but if you could keep me in the loop for any changes it'd be appreciated. I'm trying to put the finishing touches on the .X file part of the updated forum FAQ... I've got a few links to the different exporters/importers/tools, but adding another cant be a bad thing.

Cheers,
Jack

##### Share on other sites
Did you try exporting tangents and binromals and then loading the .x file? I cannot see how this would work given:

template DeclData
{
< BF22E553-292C-4781-9FEA-62BD554BDD93 >
DWORD nElements;
array VertexElement Elements[nElements];
DWORD nDWords;
array DWORD data[nDWords];
}

What would the DX functions do with DWORDs, being that they are really noramlized D3DXVECTOR3s (floats)? The actual values would be lost in the DWORD conversion.

##### Share on other sites
Quote:
 Original post by DXnutWhat would the DX functions do with DWORDs, being that they are really noramlized D3DXVECTOR3s (floats)? The actual values would be lost in the DWORD conversion.
It doesn't convert the floating point value to an integer equivalent and then store it. A DWORD is a 32bit quantity as is a float - so it'd just do a reinterpret_cast<DWORD*>(&fVariable) operation (the F2DW() macro does similar). If you were to load it without performing the opposite then you'd probably get a very large integer number [smile]

hth
Jack

##### Share on other sites
The numbers are stored in the .x file (that was saved with the TEXT option) without any decimal point. So, DX would have to know to not just use the normal text array to float conversion routine (like _tstof()). They would need to treat the numbers as having an implied decimal point.

And if it were saved in binary format, you would have an 8 byte binary number in the .x file. How would you convert it to a float and insert the decimal point where it belongs?

I just assumed, after I saved a mesh with tangents and binormals to a .x file and looked at it in WordPad, that the decldata would be useless and could never be read back in.

##### Share on other sites
Looks pretty sweet to me - nice work. It's good to see that somebody is breathing life into X-file animation [smile]

##### Share on other sites

The DWORD part is just raw memory data (similar to how memcpy() just treats blocks of data). After unpacking, the mesh will use the vertex data declaration to

Anyway, I've exported tangents and binormals, and loaded them into the DirectX Viewer, and they came out OK (without the viewer having to re-calculate them) so there is an existence proof, if you don't believe me.

Oh, another thing my exporter does which Panda doesn't: it rotates the geometry to put Y up, out of the Max Z up coordinate space. Most people prefer this; some possibly don't, so at some point I might make that optional, too...

When it comes to .X file support, it's always been a stepchild within Microsoft AFAICT -- the exporters have been going on and off for a long time. Given that they're working on XNA as an actual platform now, I'm assuming they have to address geometry export and animation; it'll be interesting to see what they do with that.

Of course, in the latest SDK, they now have a proprietary, undocumented, binary "SDKMesh" format -- why they couldn't stick with .X, I have no idea. If you think the mesh/meshnormals/texcoords are too verbose (which they are), you can just export everything to DeclData, and be happy that way. In fact, that's another option I'd love to add at some point (although you'd need custom .X file loading to recognize it).

##### Share on other sites
This is really great Jon, thanks for making this exporter. We've been using the panda one in our art pipeline for a while now, and having occasional problems with it. I'll be sure to try this one out.

##### Share on other sites
Quote:
 Original post by hplus0603When it comes to .X file support, it's always been a stepchild within Microsoft AFAICT -- the exporters have been going on and off for a long time. Given that they're working on XNA as an actual platform now, I'm assuming they have to address geometry export and animation; it'll be interesting to see what they do with that.

A few years ago, there was talk of scrapping .X and creating a new format that would have solid animation (ie both changing the file format itself and the D3DX interfaces). The idea was to get something out there that developers could actually use. I think it died pretty quickly though, since devs already have their own in-house format or some licensed SDK. However, it seems they didn't forget about the 'scrapping .X' part [wink]

##### Share on other sites
Sorry, but I just don't get it. I looked at the DXViewer code, and it will call the D3DX functions to create normals, tangents, and binormals if needed. So, it may not use what is in the .x file.

Here is the decldata I get when I create and save a mesh with them:

DeclData {
2;
2;0;6;0;,
2;0;7;0;;
762;
1044957488, <---- Take this "float"
3211805320,
3197205575,
1064742840,
1047777084,
3187194272,
1055321086,
3210300676,
3196925422,

I saved it in text format. So, you are saying that there is a standard way to convert 1044957488 to a DWORD or directly to a float from a char string? How would it know where the decimal goes? I cannot see this, given the various functions available in the C++ standard libraries.

All of the other data in the .x file saved as a float looks like a floating point number. This doesn't look at all like one. For one thing it has 10 digits in each number, so you couldn't even try to fill the nibbles of a 4 byte float with them: 0x1044957488 is 5 bytes.

Thanks.

##### Share on other sites
doesn't seem to like any of my models, module crashes every time...

##### Share on other sites
Quote:
 Original post by DXnutSorry, but I just don't get it. I looked at the DXViewer code, and it will call the D3DX functions to create normals, tangents, and binormals if needed. So, it may not use what is in the .x file.Here is the decldata I get when I create and save a mesh with them:DeclData { 2; 2;0;6;0;, 2;0;7;0;; 762; 1044957488, <---- Take this "float" 3211805320, 3197205575, 1064742840, 1047777084, 3187194272, 1055321086, 3210300676, 3196925422,I saved it in text format. So, you are saying that there is a standard way to convert 1044957488 to a DWORD or directly to a float from a char string? How would it know where the decimal goes? I cannot see this, given the various functions available in the C++ standard libraries.All of the other data in the .x file saved as a float looks like a floating point number. This doesn't look at all like one. For one thing it has 10 digits in each number, so you couldn't even try to fill the nibbles of a 4 byte float with them: 0x1044957488 is 5 bytes.Thanks.

Sorry to revive this thread, but I was figuring this out as I was writing my Maya exporter. You can convert between the original floats we need to and from the DWORDs stored in this template as follows:

DWORD d = 1044957488;float * fd = (float*)(&d);float f = *fd;DWORD * df = (DWORD*)(&f);cout << "DWORD d = " << d << endl;cout << "float d = " << *fd << endl;cout << "float f = " << f << endl;cout << "DWORD f = " << *df << endl;

This will output:
DWORD d = 1044957488
float d = 0.19608
float f = 0.19608
DWORD f = 1044957488

##### Share on other sites
Thanks! I think I get it now.

1044957488 is 3E48C930 in hex. So it is saved as a decimal value (when the text format is used), you can use one of the string functions to convert it to a DWORD and then treat it like a float.

Your post made me realize that the xfile loader does the same thing the compiler would do when converting a literal in a program.

##### Share on other sites
I can't wait to try it tonight. I've been using Panda, but have had issues from time to time.

How does the exporter deal with texture types, does it know a base texture from an alpha from a bump, etc, so they can be dealt with correclty once loaded?

An alpha for example you'll want to render last, and maybe even after not just the model is rendered but all other opaque models. I'm just thinking of a building with windows, and you're looking in the front window, through the room and out the back window. Most model exporters I've seen don't provide anything to handle this well.

Thanks