-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathd3dfile.h
127 lines (95 loc) · 4.03 KB
/
d3dfile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//-----------------------------------------------------------------------------
// File: D3DFile.h
//
// Desc: Support code for loading DirectX .X files.
//-----------------------------------------------------------------------------
#ifndef D3DFILE_H
#define D3DFILE_H
#include <tchar.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dxfile.h>
//-----------------------------------------------------------------------------
// Name: class CD3DMesh
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CD3DMesh
{
public:
TCHAR m_strName[512];
LPD3DXMESH m_pSysMemMesh; // SysMem mesh, lives through resize
LPD3DXMESH m_pLocalMesh; // Local mesh, rebuilt on resize
DWORD m_dwNumMaterials; // Materials for the mesh
D3DMATERIAL9* m_pMaterials;
LPDIRECT3DTEXTURE9* m_pTextures;
bool m_bUseMaterials;
public:
// Rendering
HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
bool bDrawOpaqueSubsets = true,
bool bDrawAlphaSubsets = true );
// Mesh access
LPD3DXMESH GetSysMemMesh() { return m_pSysMemMesh; }
LPD3DXMESH GetLocalMesh() { return m_pLocalMesh; }
// Rendering options
void UseMeshMaterials( bool bFlag ) { m_bUseMaterials = bFlag; }
HRESULT SetFVF( LPDIRECT3DDEVICE9 pd3dDevice, DWORD dwFVF );
// Initializing
HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT InvalidateDeviceObjects();
// Creation/destruction
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, TCHAR* strFilename );
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPDIRECTXFILEDATA pFileData );
HRESULT Destroy();
CD3DMesh( TCHAR* strName = _T("CD3DFile_Mesh") );
virtual ~CD3DMesh();
};
//-----------------------------------------------------------------------------
// Name: class CD3DFrame
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CD3DFrame
{
public:
TCHAR m_strName[512];
D3DXMATRIX m_mat;
CD3DMesh* m_pMesh;
CD3DFrame* m_pNext;
CD3DFrame* m_pChild;
public:
// Matrix access
void SetMatrix( D3DXMATRIX* pmat ) { m_mat = *pmat; }
D3DXMATRIX* GetMatrix() { return &m_mat; }
CD3DMesh* FindMesh( TCHAR* strMeshName );
CD3DFrame* FindFrame( TCHAR* strFrameName );
bool EnumMeshes( bool (*EnumMeshCB)(CD3DMesh*,void*),
void* pContext );
HRESULT Destroy();
HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT InvalidateDeviceObjects();
HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
bool bDrawOpaqueSubsets = true,
bool bDrawAlphaSubsets = true,
D3DXMATRIX* pmatWorldMartix = NULL);
CD3DFrame( TCHAR* strName = _T("CD3DFile_Frame") );
virtual ~CD3DFrame();
};
//-----------------------------------------------------------------------------
// Name: class CD3DFile
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CD3DFile : public CD3DFrame
{
HRESULT LoadMesh( LPDIRECT3DDEVICE9 pd3dDevice, LPDIRECTXFILEDATA pFileData,
CD3DFrame* pParentFrame );
HRESULT LoadFrame( LPDIRECT3DDEVICE9 pd3dDevice, LPDIRECTXFILEDATA pFileData,
CD3DFrame* pParentFrame );
public:
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, TCHAR* strFilename );
HRESULT CreateFromResource( LPDIRECT3DDEVICE9 pd3dDevice, TCHAR* strResource, TCHAR* strType );
// For pure devices, specify the world transform. If the world transform is not
// specified on pure devices, this function will fail.
HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice, D3DXMATRIX* pmatWorldMatrix = NULL );
CD3DFile() : CD3DFrame( _T("CD3DFile_Root") ) {}
};
#endif