Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Preface
 3D File Formats
 The Framework
 X File Class

 Down to the Code

 Source code
 Printable version

 


  The Series

 The Basics
 First Steps to
 Animation

 Multitexturing
 Building Worlds
 With X Files


 

The Framework X File Class

The Direct3D 7 IM Framework provides you the following interface class:

class CD3DFile { CD3DFileObject* m_pRoot; public: HRESULT GetMeshVertices( TCHAR* strName, D3DVERTEX** ppVertices, DWORD* pdwNumVertices ); HRESULT GetMeshIndices( TCHAR* strName, WORD** ppIndices, DWORD* pdwNumIndices ); CD3DFileObject* FindObject( TCHAR* strName ); VOID EnumObjects( BOOL (*fnCallback) (CD3DFileObject*, D3DMATRIX*, VOID*), D3DMATRIX* pmat, VOID* pContext ); VOID Scale( FLOAT fScale ); HRESULT Load( TCHAR* strFilename ); HRESULT Render( LPDIRECT3DDEVICE7 ); CD3DFile(); ~CD3DFile(); };

These methods are exported by the Framework. The GetMeshVertices() method retrieves the vertices for a specified mesh by traversing its hierarchy of frames and meshes, whereas GetMeshIndices() retrieves the vertices for the specified mesh. Both methods are useful, when, for example, you would like to use your own render method and not the one provided with the framework. To use your own RenderMethod, you might use these in two function calls in InitDeviceObjects() and call DrawIndexedPrimitive() with the array of vertices and indices in the Render() method.

Check out the second tutorial First Steps to Animations to learn more about indexed primitives.

FindObject() returns the named meshes by searching through all meshes a in file object, whereas EnumObjects() enumerates all objects in the file. It's also used by FindObjects(). Scale() scales a mesh with the help of ScaleMeshCB(). Load() creates a hierarchy of frames and meshes and loads the X file with ParseFrame() and ParseMesh(), which enumerate all the child objects. There are two Render() methods in d3dfile.cpp in the Framework source. One is in the class CD3DFileObject and the other one in the class CD3DFile. That brings us to the second class used only internally by the Framework for objects in a .X file. You'll find it in the d3dfile.h:

class CD3DFileObject { ... // lot of stuff ... // Common functions VOID Render( LPDIRECT3DDEVICE7 pd3dDevice, BOOL bAlpha ); BOOL EnumObjects( BOOL (*fnCallback)(CD3DFileObject*,D3DMATRIX*,VOID*), D3DMATRIX* pmat, VOID* pContext ); // Constuctor / destructor CD3DFileObject( TCHAR* strName ); ~CD3DFileObject(); };

The class CD3DFile uses this class to solve a lot of its tasks. The CD3DFile::Render() method will call CD3DFileObject::Render() to render the object. We don't worry about it here, because it's used internally by CD3DFile.

These render methods aren't optimal. They support alpha blending, but not other features of Direct3D, especially Multi-Texturing. You might be programming your own X file routines to wring out the last possible byte and cycle of the X file format and Direct3D. So d3dfile.cpp should only serve as an example for your own X file class, which will be optimized based on the needs your game will have. See the tutorial from Mr. Gamemaker at Loading X files for an optimized X file class.

Well, now that you know the Framework interface, we can dive deeper into the code of the sample app.


Next : Down to the Code