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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
// This code contains NVIDIA Confidential Information and is disclosed
// under the Mutual Non-Disclosure Agreement.
//
// Notice
// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
//
// NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
// expressly authorized by NVIDIA. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright � 2008- 2013 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software and related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is
// strictly prohibited.
//
//-----------------------------------------------------------------------------
// File: DXUTMesh.h
//
// Desc: Support code for loading DirectX .X files.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#pragma once
#ifndef DXUTMESH_H
#define DXUTMESH_H
//-----------------------------------------------------------------------------
// Name: class CDXUTMesh
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CDXUTMesh
{
public:
WCHAR m_strName[512];
LPD3DXMESH m_pMesh; // Managed mesh
// Cache of data in m_pMesh for easy access
IDirect3DVertexBuffer9* m_pVB;
IDirect3DIndexBuffer9* m_pIB;
IDirect3DVertexDeclaration9* m_pDecl;
DWORD m_dwNumVertices;
DWORD m_dwNumFaces;
DWORD m_dwBytesPerVertex;
DWORD m_dwNumMaterials; // Materials for the mesh
D3DMATERIAL9* m_pMaterials;
CHAR (*m_strMaterials)[MAX_PATH];
IDirect3DBaseTexture9** m_pTextures;
bool m_bUseMaterials;
public:
// Rendering
HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
bool bDrawOpaqueSubsets = true,
bool bDrawAlphaSubsets = true );
HRESULT Render( ID3DXEffect *pEffect,
D3DXHANDLE hTexture = NULL,
D3DXHANDLE hDiffuse = NULL,
D3DXHANDLE hAmbient = NULL,
D3DXHANDLE hSpecular = NULL,
D3DXHANDLE hEmissive = NULL,
D3DXHANDLE hPower = NULL,
bool bDrawOpaqueSubsets = true,
bool bDrawAlphaSubsets = true );
// Mesh access
LPD3DXMESH GetMesh() { return m_pMesh; }
// Rendering options
void UseMeshMaterials( bool bFlag ) { m_bUseMaterials = bFlag; }
HRESULT SetFVF( LPDIRECT3DDEVICE9 pd3dDevice, DWORD dwFVF );
HRESULT SetVertexDecl( LPDIRECT3DDEVICE9 pd3dDevice, const D3DVERTEXELEMENT9 *pDecl,
bool bAutoComputeNormals = true, bool bAutoComputeTangents = true,
bool bSplitVertexForOptimalTangents = false );
// Initializing
HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT InvalidateDeviceObjects();
// Creation/destruction
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename );
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData );
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, ID3DXMesh* pInMesh, D3DXMATERIAL* pd3dxMaterials, DWORD dwMaterials );
HRESULT CreateMaterials( LPCWSTR strPath, IDirect3DDevice9 *pd3dDevice, D3DXMATERIAL* d3dxMtrls, DWORD dwNumMaterials );
HRESULT Destroy();
CDXUTMesh( LPCWSTR strName = L"CDXUTMeshFile_Mesh" );
virtual ~CDXUTMesh();
};
//-----------------------------------------------------------------------------
// Name: class CDXUTMeshFrame
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CDXUTMeshFrame
{
public:
WCHAR m_strName[512];
D3DXMATRIX m_mat;
CDXUTMesh* m_pMesh;
CDXUTMeshFrame* m_pNext;
CDXUTMeshFrame* m_pChild;
public:
// Matrix access
void SetMatrix( D3DXMATRIX* pmat ) { m_mat = *pmat; }
D3DXMATRIX* GetMatrix() { return &m_mat; }
CDXUTMesh* FindMesh( LPCWSTR strMeshName );
CDXUTMeshFrame* FindFrame( LPCWSTR strFrameName );
bool EnumMeshes( bool (*EnumMeshCB)(CDXUTMesh*,void*),
void* pContext );
HRESULT Destroy();
HRESULT RestoreDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT InvalidateDeviceObjects();
HRESULT Render( LPDIRECT3DDEVICE9 pd3dDevice,
bool bDrawOpaqueSubsets = true,
bool bDrawAlphaSubsets = true,
D3DXMATRIX* pmatWorldMatrix = NULL);
CDXUTMeshFrame( LPCWSTR strName = L"CDXUTMeshFile_Frame" );
virtual ~CDXUTMeshFrame();
};
//-----------------------------------------------------------------------------
// Name: class CDXUTMeshFile
// Desc: Class for loading and rendering file-based meshes
//-----------------------------------------------------------------------------
class CDXUTMeshFile : public CDXUTMeshFrame
{
HRESULT LoadMesh( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData,
CDXUTMeshFrame* pParentFrame );
HRESULT LoadFrame( LPDIRECT3DDEVICE9 pd3dDevice, LPD3DXFILEDATA pFileData,
CDXUTMeshFrame* pParentFrame );
public:
HRESULT Create( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strFilename );
HRESULT CreateFromResource( LPDIRECT3DDEVICE9 pd3dDevice, LPCWSTR strResource, LPCWSTR 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 );
CDXUTMeshFile() : CDXUTMeshFrame( L"CDXUTMeshFile_Root" ) {}
};
#endif
|