Sign in to follow this  
CyberGhost

Milkshape3D to Direct3D9c X-file conversion

Recommended Posts

Hi, Sorry if this has already been posted else where on the site. I have had a quick look but cannot find anything about. I am currently creating 3D models using MilkShape3D 1.74 and trying to export to Microsoft's Direct3D9c X-File format. (SDK April 2005) The problem is between sometime between December 2004 and the current version (April 2005) of the DirectX SDK. Microsoft has changed the format of the X-file and as a result old X-file's do not load (great backwards compatibly). Luckly I still have my MilkShape model projects, but have tried using the various DirectX export settings but cant get one that Direct3D will load. Has anyone else had this problem and have found a way round this either via setting certain settings or using some other conversion software. Thanx, CyberGhost

Share this post


Link to post
Share on other sites
You could use other formats that MilkShape supports (which means you have to
load it yourself), I think there's an ASCII format which is quite easy to read.

Anyway, did you try to ask the MilkShape developers, maybe they know
where to download new versions of the X-File Exporter?!

Share this post


Link to post
Share on other sites
Thank you for your response,
Well I could using one of the other formats although this is not ideal. Ideally it would be nice to make use of the X-File format as its quite simple to use and do not have to write loads of loading code.

Regards asking developers of MilkShape, that was going to be my next move but thought I would just check on here first incase other people have had the same problem..which they must have.
Thanx,

CyberGhost

Share this post


Link to post
Share on other sites
I ran into the same problem and was able to get around it by exporting the models to .x differently. Unfortunately, I'm not at the pc with milkshape on it right now, so this is all going from memory--but I'm pretty sure exporting as a 'managed directx (.jt)' file works. During the export process, select the save name as a .x, and export as binary.

I'll verify the process once I get back to that computer.

Share this post


Link to post
Share on other sites
Thanks Toraque,
Thats helped loads. To confirm for yours and others reference. When exporting select DirectX (JT) select your output file name with the extension .x
Next select DirectX Retained Mode as the format and you can either export as Binary (select binary check) or text by deselecting all checks.

However as these things are never simple. There appears to be some bugs in the exporter. If you have a model that has more then one texture material only the first is used and textures will always be looked for in the current directory.
Which means you either have to manually edit the x file and add relative paths or modify your texture loading.
So I'll probably submit a bug report to chUmbaLum sOft regarding the textures see what they say.
Thanks for you help.

Now to get my Collision Detection work :(

Share this post


Link to post
Share on other sites
The problem has to do with an extra "}" being put into the .X file at the end of the materials list when exported by Milkshape. You simply need to open the file in notepad and remove it. It will work fine after that.

Share this post


Link to post
Share on other sites
I think I am miss understanding,
I have just tried editing the file and there appears to be no extra "}" character. I have tried hacking about removing the "}" after the materials listed in the materiallist group however that breaks the file.
Where exactly should the edit be made.

Thanx,

CyberGhost

Share this post


Link to post
Share on other sites
Here is a .x export of a single box from Milkshape with a single texture.


xof 0303txt 0032
template XSkinMeshHeader {
<3cf169ce-ff7c-44ab-93c0-f78f62d172e2>
WORD nMaxSkinWeightsPerVertex;
WORD nMaxSkinWeightsPerFace;
WORD nBones;
}

template VertexDuplicationIndices {
<b8d65549-d7c9-4995-89cf-53a9a8b031e3>
DWORD nIndices;
DWORD nOriginalVertices;
array DWORD indices[nIndices];
}

template SkinWeights {
<6f0d123b-bad2-4167-a0d0-80224f25fabb>
STRING transformNodeName;
DWORD nWeights;
array DWORD vertexIndices[nWeights];
array FLOAT weights[nWeights];
Matrix4x4 matrixOffset;
}


Frame Scene_Root {


FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}

Frame Box01 {

FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}

Mesh {
24;
-0.300000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
1.525000;0.975000;-0.950000;,
1.525000;-0.925000;-0.950000;,
1.525000;0.975000;-0.950000;,
1.525000;-0.925000;-0.950000;,
1.525000;0.975000;0.950000;,
1.525000;-0.925000;0.950000;,
1.525000;0.975000;0.950000;,
1.525000;-0.925000;0.950000;,
-0.300000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
-0.300000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
-0.300000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
-0.300000;0.975000;-0.950000;,
1.525000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
1.525000;-0.925000;-0.950000;,
-0.300000;0.975000;0.950000;,
1.525000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
1.525000;-0.925000;0.950000;;
12;
3;0,2,1;,
3;1,2,3;,
3;4,6,5;,
3;5,6,7;,
3;8,10,9;,
3;9,10,11;,
3;12,14,13;,
3;13,14,15;,
3;20,21,16;,
3;16,21,17;,
3;18,19,22;,
3;22,19,23;;

MeshNormals {
24;
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;;
12;
3;0,2,1;,
3;1,2,3;,
3;4,6,5;,
3;5,6,7;,
3;8,10,9;,
3;9,10,11;,
3;12,14,13;,
3;13,14,15;,
3;20,21,16;,
3;16,21,17;,
3;18,19,22;,
3;22,19,23;;
}

MeshTextureCoords {
24;
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;1.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
1.000000;0.000000;,
0.000000;0.000000;,
1.000000;0.000000;,
0.000000;1.000000;,
1.000000;1.000000;;
}

VertexDuplicationIndices {
24;
20;
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
12,
6,
13,
7;
}

MeshMaterialList {
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;

Material Material01 {
0.800000;0.800000;0.800000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFilename {
"ed2.jpg";
}
}
}

XSkinMeshHeader {
1;
3;
0;
}

}
}
}
}

AnimationSet AnimationSet0 {

Animation {

AnimationKey {
4;
2;
0; 16; 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000;;,
-1; 16; 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000;;;
}
{ Scene_Root }
}

}





Here is the edited version

xof 0303txt 0032
template XSkinMeshHeader {
<3cf169ce-ff7c-44ab-93c0-f78f62d172e2>
WORD nMaxSkinWeightsPerVertex;
WORD nMaxSkinWeightsPerFace;
WORD nBones;
}

template VertexDuplicationIndices {
<b8d65549-d7c9-4995-89cf-53a9a8b031e3>
DWORD nIndices;
DWORD nOriginalVertices;
array DWORD indices[nIndices];
}

template SkinWeights {
<6f0d123b-bad2-4167-a0d0-80224f25fabb>
STRING transformNodeName;
DWORD nWeights;
array DWORD vertexIndices[nWeights];
array FLOAT weights[nWeights];
Matrix4x4 matrixOffset;
}


Frame Scene_Root {


FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}

Frame Box01 {

FrameTransformMatrix {
1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 0.000000, 1.000000, 0.000000,
0.000000, 0.000000, 0.000000, 1.000000;;
}

Mesh {
24;
-0.300000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
1.525000;0.975000;-0.950000;,
1.525000;-0.925000;-0.950000;,
1.525000;0.975000;-0.950000;,
1.525000;-0.925000;-0.950000;,
1.525000;0.975000;0.950000;,
1.525000;-0.925000;0.950000;,
1.525000;0.975000;0.950000;,
1.525000;-0.925000;0.950000;,
-0.300000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
-0.300000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
-0.300000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
-0.300000;0.975000;-0.950000;,
1.525000;0.975000;-0.950000;,
-0.300000;-0.925000;-0.950000;,
1.525000;-0.925000;-0.950000;,
-0.300000;0.975000;0.950000;,
1.525000;0.975000;0.950000;,
-0.300000;-0.925000;0.950000;,
1.525000;-0.925000;0.950000;;
12;
3;0,2,1;,
3;1,2,3;,
3;4,6,5;,
3;5,6,7;,
3;8,10,9;,
3;9,10,11;,
3;12,14,13;,
3;13,14,15;,
3;20,21,16;,
3;16,21,17;,
3;18,19,22;,
3;22,19,23;;

MeshNormals {
24;
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
0.000000;0.000000;-1.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
1.000000;0.000000;0.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
0.000000;0.000000;1.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
-1.000000;0.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;-1.000000;0.000000;,
0.000000;-1.000000;0.000000;;
12;
3;0,2,1;,
3;1,2,3;,
3;4,6,5;,
3;5,6,7;,
3;8,10,9;,
3;9,10,11;,
3;12,14,13;,
3;13,14,15;,
3;20,21,16;,
3;16,21,17;,
3;18,19,22;,
3;22,19,23;;
}

MeshTextureCoords {
24;
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
0.000000;1.000000;,
1.000000;0.000000;,
1.000000;1.000000;,
0.000000;1.000000;,
1.000000;1.000000;,
0.000000;0.000000;,
1.000000;0.000000;,
0.000000;0.000000;,
1.000000;0.000000;,
0.000000;1.000000;,
1.000000;1.000000;;
}

VertexDuplicationIndices {
24;
20;
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
12,
6,
13,
7;
}

MeshMaterialList {
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;

Material Material01 {
0.800000;0.800000;0.800000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFilename {
"ed2.jpg";
}
}
}

XSkinMeshHeader {
1;
3;
0;
}

}
}
}

AnimationSet AnimationSet0 {

Animation {

AnimationKey {
4;
2;
0; 16; 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000;;,
-1; 16; 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000;;;
}
{ Scene_Root }
}

}




The place that was edited was the part containing this:

Material Material01 {
0.800000;0.800000;0.800000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFilename {
"ed2.jpg";
}
}
}

XSkinMeshHeader {
1;
3;
0;
}

}
}
}
}


It was changed to:

Material Material01 {
0.800000;0.800000;0.800000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFilename {
"ed2.jpg";
}
}
}

XSkinMeshHeader {
1;
3;
0;
}

}
}
}

One of the braces right after XSkinMeshHeader was removed.

Share this post


Link to post
Share on other sites
I think theres a confusion,
That code sample is from an exported X-File that is using template format not binary or text. Which doing so does not seem to load with the new Direct3D.
The text version of the output appears to be correct (all braces are in matched pairs).

Anyone else got any bright ideas?

Thanx

CyberGhost

Share this post


Link to post
Share on other sites
As mentioned previously in the thread I'm using the April 2005 version of the SDK.
Basically I have taken just the code Microsoft uses to load the Mesh (x-file) in their Direct3D tutorials.
If I try to load an X-file that has been exported using any other method then Text or Binary in the DirectX (JT) DirectX Retained Mode format. The D3DXLoadMeshFromX() method will fail.
Are you doing anything else special to get them to load?

Thanx

CyberGhost

Share this post


Link to post
Share on other sites
I don't think I'm doing anything special. Here's the code I'm using



// load the mesh
LPD3DXBUFFER materialBuffer;
DWORD numMaterials;
LPD3DXMESH mesh;
// Load the mesh from the specified file
if(FAILED(D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&materialBuffer,NULL, &numMaterials,
&mesh )))
{
ShowMessage("DirectX9 does not recognize this .X format");
return false;
}

Share this post


Link to post
Share on other sites
hmmmmm very odd.
Thats exactly what I am doing.
We must be either using different SDK versions, MilkShape3D versions or using different settings when exporting.
Well the first two are easy.
As said previously I'm using April 2005 DirectX SDK and version 1.74 MilkShape.

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