1 | //-----------------------------------------------------------------------------
|
---|
2 | // File: DXUTMesh.h
|
---|
3 | //
|
---|
4 | // Desc: Support code for loading DirectX .X files.
|
---|
5 | //
|
---|
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
---|
7 | //-----------------------------------------------------------------------------
|
---|
8 | #pragma once
|
---|
9 | #ifndef DXUTMESH_H
|
---|
10 | #define DXUTMESH_H
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | //-----------------------------------------------------------------------------
|
---|
17 | // Name: class CDXUTMesh
|
---|
18 | // Desc: Class for loading and rendering file-based meshes
|
---|
19 | //-----------------------------------------------------------------------------
|
---|
20 | class CDXUTMesh
|
---|
21 | {
|
---|
22 | public:
|
---|
23 | WCHAR m_strName[512];
|
---|
24 | LPD3DXMESH m_pMesh; // Managed mesh
|
---|
25 |
|
---|
26 | // Cache of data in m_pMesh for easy access
|
---|
27 | IDirect3DVertexBuffer9* m_pVB;
|
---|
28 | IDirect3DIndexBuffer9* m_pIB;
|
---|
29 | IDirect3DVertexDeclaration9* m_pDecl;
|
---|
30 | DWORD m_dwNumVertices;
|
---|
31 | DWORD m_dwNumFaces;
|
---|
32 | DWORD m_dwBytesPerVertex;
|
---|
33 |
|
---|
34 | DWORD m_dwNumMaterials; // Materials for the mesh
|
---|
35 | D3DMATERIAL9* m_pMaterials;
|
---|
36 | CHAR (*m_strMaterials)[MAX_PATH];
|
---|
37 | IDirect3DBaseTexture9** m_pTextures;
|
---|
38 | bool m_bUseMaterials;
|
---|
39 |
|
---|
40 | public:
|
---|
41 | // Rendering
|
---|
42 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
|
---|
43 | bool bDrawOpaqueSubsets = true,
|
---|
44 | bool bDrawAlphaSubsets = true );
|
---|
45 | HRESULT Render( ID3DXEffect *pEffect,
|
---|
46 | D3DXHANDLE hTexture = NULL,
|
---|
47 | D3DXHANDLE hDiffuse = NULL,
|
---|
48 | D3DXHANDLE hAmbient = NULL,
|
---|
49 | D3DXHANDLE hSpecular = NULL,
|
---|
50 | D3DXHANDLE hEmissive = NULL,
|
---|
51 | D3DXHANDLE hPower = NULL,
|
---|
52 | bool bDrawOpaqueSubsets = true,
|
---|
53 | bool bDrawAlphaSubsets = true );
|
---|
54 |
|
---|
55 | // Mesh access
|
---|
56 | LPD3DXMESH GetMesh() { return m_pMesh; }
|
---|
57 |
|
---|
58 | // Rendering options
|
---|
59 | void UseMeshMaterials( bool bFlag ) { m_bUseMaterials = bFlag; }
|
---|
60 | HRESULT SetFVF( LPDIRECT3DDEVICE9 pd3dDevice, DWORD dwFVF );
|
---|
61 | HRESULT SetVertexDecl( LPDIRECT3DDEVICE9 pd3dDevice, const D3DVERTEXELEMENT9 *pDecl,
|
---|
62 | bool bAutoComputeNormals = true, bool bAutoComputeTangents = true,
|
---|
63 | bool bSplitVertexForOptimalTangents = false );
|
---|
64 |
|
---|
65 | // Initializing
|
---|
66 | HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
|
---|
67 | HRESULT InvalidateDeviceObjects();
|
---|
68 |
|
---|
69 | // Creation/destruction
|
---|
70 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename );
|
---|
71 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData );
|
---|
72 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, ID3DXMesh* pInMesh, D3DXMATERIAL* pd3dxMaterials, DWORD dwMaterials );
|
---|
73 | HRESULT CreateMaterials( LPCWSTR strPath, IDirect3DDevice9 *pd3dDevice, D3DXMATERIAL* d3dxMtrls, DWORD dwNumMaterials );
|
---|
74 | HRESULT Destroy();
|
---|
75 |
|
---|
76 | CDXUTMesh( LPCWSTR strName = L"CDXUTMeshFile_Mesh" );
|
---|
77 | virtual ~CDXUTMesh();
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 | //-----------------------------------------------------------------------------
|
---|
84 | // Name: class CDXUTMeshFrame
|
---|
85 | // Desc: Class for loading and rendering file-based meshes
|
---|
86 | //-----------------------------------------------------------------------------
|
---|
87 | class CDXUTMeshFrame
|
---|
88 | {
|
---|
89 | public:
|
---|
90 | WCHAR m_strName[512];
|
---|
91 | D3DXMATRIX m_mat;
|
---|
92 | CDXUTMesh* m_pMesh;
|
---|
93 |
|
---|
94 | CDXUTMeshFrame* m_pNext;
|
---|
95 | CDXUTMeshFrame* m_pChild;
|
---|
96 |
|
---|
97 | public:
|
---|
98 | // Matrix access
|
---|
99 | void SetMatrix( D3DXMATRIX* pmat ) { m_mat = *pmat; }
|
---|
100 | D3DXMATRIX* GetMatrix() { return &m_mat; }
|
---|
101 |
|
---|
102 | CDXUTMesh* FindMesh( LPCWSTR strMeshName );
|
---|
103 | CDXUTMeshFrame* FindFrame( LPCWSTR strFrameName );
|
---|
104 | bool EnumMeshes( bool (*EnumMeshCB)(CDXUTMesh*,void*),
|
---|
105 | void* pContext );
|
---|
106 |
|
---|
107 | HRESULT Destroy();
|
---|
108 | HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
|
---|
109 | HRESULT InvalidateDeviceObjects();
|
---|
110 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
|
---|
111 | bool bDrawOpaqueSubsets = true,
|
---|
112 | bool bDrawAlphaSubsets = true,
|
---|
113 | D3DXMATRIX* pmatWorldMatrix = NULL);
|
---|
114 |
|
---|
115 | CDXUTMeshFrame( LPCWSTR strName = L"CDXUTMeshFile_Frame" );
|
---|
116 | virtual ~CDXUTMeshFrame();
|
---|
117 | };
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | //-----------------------------------------------------------------------------
|
---|
123 | // Name: class CDXUTMeshFile
|
---|
124 | // Desc: Class for loading and rendering file-based meshes
|
---|
125 | //-----------------------------------------------------------------------------
|
---|
126 | class CDXUTMeshFile : public CDXUTMeshFrame
|
---|
127 | {
|
---|
128 | HRESULT LoadMesh( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData,
|
---|
129 | CDXUTMeshFrame* pParentFrame );
|
---|
130 | HRESULT LoadFrame( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData,
|
---|
131 | CDXUTMeshFrame* pParentFrame );
|
---|
132 | public:
|
---|
133 | HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename );
|
---|
134 | HRESULT CreateFromResource( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strResource, LPCWSTR strType );
|
---|
135 | // For pure devices, specify the world transform. If the world transform is not
|
---|
136 | // specified on pure devices, this function will fail.
|
---|
137 | HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice, D3DXMATRIX* pmatWorldMatrix = NULL );
|
---|
138 |
|
---|
139 | CDXUTMeshFile() : CDXUTMeshFrame( L"CDXUTMeshFile_Root" ) {}
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 | #endif
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|