Can i use .x files to render spline shape models?

I have a model in 3ds max using only spline shapes. Can i export it as .x file and render in my application I also want to have control on line thickness of splines.

Answer this question

Can i use .x files to render spline shape models?

  • Internationalpaddy

    The .X file format is open-ended so you can define whatever you want. To use it for your own data types you need to define the templates and their respective GUIDs so that DirectX and you know what to look for.

    Let’s say you have a spline structure with a start point, 2 control points and an end point, like:

    struct sSpline
    {
       D3DXVECTOR3 start;
       D3DXVECTOR3 ctrl1;
       D3DXVECTOR3 ctrl2;
       D3DXVECTOR3 end;

    };

    and you want to keep a list of splines in an .X file, you need to define the spline and the spline list templates, MY_XSpline and MY_XSplineList.

    First define the GUIDs, use the second option of the "Create GUID" tool and fill in the <<name>> section, use the commented bit for the template definition

    #include "initguid.h" // For DEFINE_GUID

    // Define MY_XSpline GUID
    DEFINE_GUID(MY_XSpline, \
                0xa4a57055, 0xd3cb, 0x42c0, 0x9e, 0x1d, 0x7f, \
                0xac, 0xed, 0xe9, 0xef, 0x99);

    // Define MY_XSplineList GUID
    DEFINE_GUID(MY_XSplineList, \
                0x71755dec, 0xe1b, 0x4757, 0x8e, 0x55, 0x58, \
                0x90, 0x89, 0xf0, 0x3a, 0x3);

    The templates can be defined at the start of the .X file or in a source file. If you define them in the .X file you don’t have to register the templates with DirectX, otherwise, if you define them in a source file you’ll need to register them like:

    // User .X file templates
    char *MY_XTEMPLATES = \
       "xof 0302txt 0032 \
       template MY_XSpline { \
          <A4A57055-D3CB-42c0-9E1D-7FACEDE9EF99> \
          Vector Start; \
          Vector Ctrl1; \
          Vector CtrlPt2; \
          Vector End; \
       } \
       template MY_XSplineList { \
          <71755DEC-0E1B-4757-8E55-589089F03A03> \
          DWORD NumSplines; \
          array MY_XSpline Splines[NumSplines]; \
       }";

    // Register standard DX templates
    xFile->RegisterTemplates((LPCVOID)D3DRM_XTEMPLATES, 
                                      D3DRM_XTEMPLATE_BYTES);

    // Register user templates
    xFile->RegisterTemplates((LPCVOID)MY_XTEMPLATES, 
                                      strlen(MY_XTEMPLATES));

    The GUIDs are the important thing, I could’ve named the template MY_XSpline as Spline while keeping the GUID as MY_XSpline because when you’re enumerating the file it’s the GUID you compare, but for simplicity...

    Then in the .X file you define the data objects like:

    MY_XSplineList TestSplines {
       2; // Number of splines

       // First spline
       1.0, 1.0, 0.0;  // Start point
       2.0, 2.0, 0.0;  // First control point
       3.0, 2.0, 0.0;  // Second control point
       4.0, 1.0, 0.0;, // End point

       // Second spline
       1.0, -2.0, 0.0; // Start point
       3.0,  1.0, 0.0;  // First control point
       2.0,  3.0, 0.0;  // Second control point
       1.0,  5.0, 0.0;; // End point
    }


    If you want an example on saving .X files have a look at:

    http://www.toymaker.info/Games/html/x_file_saving.html


  • swit

    Writing my own exporter...sounds good...but as u said its lot more work that means lot more time to spent...

    Any other idea to acheive the same result

  • Antoine Sirianni

    Guilty as charged. You should also include "rmxfguid.h" for the template GUIDs.

     


  • fums64

    Thanx for the info "Bad Habit"...

    Now i have all the vertex information of spline shape in my app say in a D3DXVECTOR2 array and i can draw these lines using ID3DXLine. Its good but i want to have some container that can be used to control these line shapes like moving or scaling them etc. Any idea

    Thanx

  • Ric Fisher

    I'm pretty sure you can't store higher-order surfaces in an X file unless you convert it to a triangle-mesh first (which defeats the point really..)

    Given that you're using 3DSMax, you might want to look into their plug-in SDK and see about writing your own exporter and then reconstruct it (as appropriate) in your D3D application. It's a lot more work, but I think it's probably your best bet Smile

    hth
    Jack


  • blumash

    In the few examples I have found, RegisterTemplates() is always called with D3DRM_XTEMPLATES and D3DRM_XTEMPLATE_BYTES, yet noone tells you what file to include to get these definitions, and compiling will just give you errors.

    #include <rmxftmpl.h>

    I hope noone else becomes needlessly baffled as I was.


  • Can i use .x files to render spline shape models?