.X files

    How do i make a .X file and a .FX file what program


Answer this question

.X files

  • Peter Gummer

    If you are looking to create .X files by hand, you can read the documentation in the DirectX docs.


  • PierreDSavard

    For x file I'm doing it now... :-) it took me a while to be able to...
    It's absolutely not that hard once you know the way...

    I'm giving you the way but not all the correct detail, my memory is too bad ;-)
    So all this code here is approx....but you can look how it's done
    in the Sample, the one that use vsh is good to tell how to createmesh and
    put Vertex and Index inside, don't forget to set at least one material in

    You must adapt the following code...it's not acurate at all...
    I don't define normal...

    MYVERTEX {

    D3DXVECTOR3 p; //vertex
    D3DXVECTOR2 t; //texture it's a vector 2 not 3...

    const double FVF;
    };

    MYINDEX{
    word Index; //if your mesh use the flag 32 bit this should be a double not a word
    };

    //weirdly TEXCOORD1 give you 1 set of U,V...go figure...

    FVF=FVF_POSITION | FVF_TEXCOORD1;

    //See the example Vertex Shader in the SDK to get the good flag...
    // Numberoffaces is NOT NumberOfVertex/3 because some time you have
    // 6 vertex and 4 faces...contrary to many exemple in the SDK...
    //Where they assume each triangle as 3 vertex...

    //In my example of a simple square I use 4 vertex and 2 triangle (faces)
    //So NumberOfFace=2 and NumberOfVertex=4
    You call :
    D3DXCreateMesh(NumberOfFace,NumberOfVertex,FLag 32 bit mesh or not and Discard,MYVERTEX,...., pMesh);

    //Again if you define a 32 bit mesh the Index should be a double NOT a word...

    //You create your vertex and fill it with your data (here a simple square with 2 faces)
    //Texture coordinate allways roll over from 0 to 1, if you put 2 you will have the
    //texture repeat twice...
    MYVERTEX Vertex[400];

    Vertex[0].p=D3DXVECTOR(0,0,0);
    Vertex[0].t=D3DXVECTOR(0,0);

    Vertex[1].p=D3DXVECTOR(0,1,0);
    Vertex[1].t=D3DXVECTOR(0,1);

    Vertex[2].p=D3DXVECTOR(1,1,0);
    Vertex[2].t=D3DXVECTOR(1,1);

    Vertex[3].p=D3DXVECTOR(1,0,0);
    Vertex[3].t=D3DXVECTOR(1,0);

    NumberOfVertex=4;

    MYINDEX Index[400]; //of course it's way too big now but it's for big futur mesh

    //See the Index Buffer to point the vertex you want to define the triangle...
    //Make sure they rotate the way you want because MVIEW will cull...

    //First triangle use vertex 0,1,3
    Index[0]=0;
    Index[1]=1;
    Index[2]=3;

    //Second triangle use vertex 1,2,3
    Index[0]=1;
    Index[1]=2;
    Index[2]=3;

    //So 6 index who point to the position of the Vertex in the Vertex Buffer
    //for 3 faces, the 1 means that the Vertex who is in Vertex[1]..who as x,y,z value
    NumberOfIndex=6; //It's NOT number of Face/triangle who is 2 in our case...

    MYVERTEX *pVB;
    MYINDEX *pIB;

    You lock the Vertex Mesh data...
    pMesh->LockVB( ...,(void **)pVB);

    //Copy to the pointer you got the Buffer of Vertex you have define earlier
    memcpy(pVB,Vertex,NumberOfVertex * sizeof(MYVERTEX));

    pMesh->UnlockVB();

    //You lock the Index Mesh data...
    pMesh->LockIB( ...,(void **)pIB);

    //Copy to the pointer you got the Buffer of Index you have define earlier
    memcpy(pIB,Index,NumberOfIndex * sizeof(MYINDEX));

    Size of MYINDEX is really sizeof(word) or sizeof(double) in 32 bit mesh

    pMesh->UnlockIB();

    //Here is the tricky part...you need to set the material...
    //You can go see the help for the correct structure
    //It's a series of vector for the light, a value for power...I don't know the use of it
    //And the name of a texture file that can tell the directory ex: c:\\texture.bmp

    D3DXMATERIAL pMat;
    pMat.LightDiffuse=D3DXVECTOR4(0.0,0.0,0.0,0.0);
    pMat.LightAmbiant=D3DXVECTOR4(0.0,0.0,0.0,0.0);
    pMat.LightSpecular=D3DXVECTOR4(0.0,0.0,0.0,0.0);
    pMat.LightEmissive=D3DXVECTOR4(0.0,0.0,0.0,0.0);
    pMat.TextureName="c:\\texture.bmp"; //probably not that easy here...

    //You should put real value here in those light...not all 0...

    //Set the material of your mesh
    pMesh->SetMaterial(pMat);


    //You now are the happy owner of a mesh that has 4 vertex and 2 faces (triangle)
    //So a buffer of 6 index value, each 3 set of index value defining a triangle
    //You simply write that mesh to a x file
    D3DXSaveMeshToFile("c:\\MyMesh.x",...,Format Text not Binary so you can read the x file with notepad...);

    //And now you are ready to see how far off you are using Notepad
    //to read the x file... :-P
    //If the mesh look ok you could see it with dxviewer.exe or mview.exe

    //You can read the correct light value in an existing x file to see what work

    As for the fx file you have RenderMonkey (ati.com) and FX Composer (nvidia.com)
    Both are free...and produce fx file BUT they are not readily compatible
    to DX...or dxviewer.exe...basicaly they are NOT usable as there are produce
    NOT easily at least

    You have to fix the resulting Fx file to add all the SAS.MatrixView value
    And it's a real pain...But FX Composer 2.0 should fix all this...once it is released...
    Now we are stuck with 1.6....










  • deepak sv

    For a free program have a look at Blender, this will allow you to create your models and the export them to the x format.

    For .fx files you can also look at the NVidia tools on their Developers page.

  • andizzle

     werwin wrote:
        How do i make a .X file and a .FX file what program


    You can also use a program like DelEd, Gamespace, Milkshape, Lightwave, etc...

  • KUCL

    Well there is lots of programs able to do so, but one or two is AC3D, 3D Studio Max and Maya.

    An X-file is actually just a bunch of text defining boxes, spheres and so on along with their textures if set. Pretty hard to write yourself, I'd say. You could try AC3D, it's very easy to start on Smile

    FX-files are effects and you would write them in HLSL (High Level Shader Language), which is a whole other topic.

    Regards,
    SirErugor

  • msolgi

    Thanks every one

  • .X files