raSystem  1.0 bata
raSDKmesh.h
Go to the documentation of this file.
1 //--------------------------------------------------------------------------------------
2 //
3 //
4 // Disclaimer:
5 // The SDK Mesh format (.sdkmesh) is not a recommended file format for shipping titles.
6 // It was designed to meet the specific needs of the SDK samples. Any real-world
7 // applications should avoid this file format in favor of a destination format that
8 // meets the specific needs of the application.
9 //
10 // Copyright (c) Microsoft Corporation. All rights reserved.
11 //--------------------------------------------------------------------------------------
12 #define SDKMESH_FILE_VERSION 101
13 #define MAX_VERTEX_ELEMENTS 32
14 #define MAX_VERTEX_STREAMS 16
15 #define MAX_FRAME_NAME 100
16 #define MAX_MESH_NAME 100
17 #define MAX_SUBSET_NAME 100
18 #define MAX_MATERIAL_NAME 100
19 #define MAX_TEXTURE_NAME MAX_PATH
20 #define MAX_MATERIAL_PATH MAX_PATH
21 #define INVALID_FRAME ((UINT)-1)
22 #define INVALID_MESH ((UINT)-1)
23 #define INVALID_MATERIAL ((UINT)-1)
24 #define INVALID_SUBSET ((UINT)-1)
25 #define INVALID_ANIMATION_DATA ((UINT)-1)
26 #define INVALID_SAMPLER_SLOT ((UINT)-1)
27 #define ERROR_RESOURCE_VALUE 1
28 
29  template<typename TYPE> BOOL IsErrorResource( TYPE data )
30  {
31  if( ( TYPE )ERROR_RESOURCE_VALUE == data )
32  return TRUE;
33  return FALSE;
34  }
36  {
48  };
49 
51  {
52  IT_16BIT = 0,
54  };
55 
57  {
60  };
61 
63  {
64  //Basic Info and sizes
65  UINT Version;
67  UINT64 HeaderSize;
70 
71  //Stats
74  UINT NumMeshes;
76  UINT NumFrames;
78 
79  //Offsets to Data
86  };
87 
89  {
90  UINT64 NumVertices;
91  UINT64 SizeBytes;
92  UINT64 StrideBytes;
93  union
94  {
95  UINT64 DataOffset; //(This also forces the union to 64bits)
96  ID3D11Buffer* pVB11;
97  };
98  };
99 
101  {
102  UINT64 NumIndices;
103  UINT64 SizeBytes;
104  UINT IndexType;
105  union
106  {
107  UINT64 DataOffset; //(This also forces the union to 64bits)
108  ID3D11Buffer* pIB11;
109  };
110  };
111 
113  {
114  char Name[MAX_MESH_NAME];
116  UINT VertexBuffers[MAX_VERTEX_STREAMS];
119  UINT NumFrameInfluences; //aka bones
120 
121  D3DXVECTOR3 BoundingBoxCenter;
122  D3DXVECTOR3 BoundingBoxExtents;
123 
124  union
125  {
126  UINT64 SubsetOffset; //Offset to list of subsets (This also forces the union to 64bits)
127  UINT* pSubsets; //Pointer to list of subsets
128  };
129  union
130  {
131  UINT64 FrameInfluenceOffset; //Offset to list of frame influences (This also forces the union to 64bits)
132  UINT* pFrameInfluences; //Pointer to list of frame influences
133  };
134  };
135 
137  {
138  char Name[MAX_SUBSET_NAME];
141  UINT64 IndexStart;
142  UINT64 IndexCount;
143  UINT64 VertexStart;
144  UINT64 VertexCount;
145  };
146 
148  {
149  char Name[MAX_FRAME_NAME];
150  UINT Mesh;
154  D3DXMATRIX Matrix;
155  UINT AnimationDataIndex; //Used to index which set of keyframes transforms this frame
156  };
157 
159  {
160  char Name[MAX_MATERIAL_NAME];
161 
162  char MaterialInstancePath[MAX_MATERIAL_PATH];
163 
164  char DiffuseTexture[MAX_TEXTURE_NAME];
165  char NormalTexture[MAX_TEXTURE_NAME];
166  char SpecularTexture[MAX_TEXTURE_NAME];
167 
168  D3DXVECTOR4 Diffuse;
169  D3DXVECTOR4 Ambient;
170  D3DXVECTOR4 Specular;
171  D3DXVECTOR4 Emissive;
172  FLOAT Power;
173 
174  union
175  {
176  UINT64 Force64_1; //Force the union to 64bits
177  ID3D11Texture2D* pDiffuseTexture11;
178  };
179  union
180  {
181  UINT64 Force64_2; //Force the union to 64bits
182  ID3D11Texture2D* pNormalTexture11;
183  };
184  union
185  {
186  UINT64 Force64_3; //Force the union to 64bits
187  ID3D11Texture2D* pSpecularTexture11;
188  };
189 
190  union
191  {
192  UINT64 Force64_4; //Force the union to 64bits
193  ID3D11ShaderResourceView* pDiffuseRV11;
194  };
195  union
196  {
197  UINT64 Force64_5; //Force the union to 64bits
198  ID3D11ShaderResourceView* pNormalRV11;
199  };
200  union
201  {
202  UINT64 Force64_6; //Force the union to 64bits
203  ID3D11ShaderResourceView* pSpecularRV11;
204  };
205  };
206 
208  {
209  UINT Version;
212  UINT NumFrames;
217  };
218 
220  {
221  D3DXVECTOR3 Translation;
222  D3DXVECTOR4 Orientation;
223  D3DXVECTOR3 Scaling;
224  };
225 
227  {
228  char FrameName[MAX_FRAME_NAME];
229  union
230  {
231  UINT64 DataOffset;
233  };
234  };
235 
236  typedef void ( CALLBACK*LPCREATETEXTUREFROMFILE11 )( raDirectX* pDev, raString szFileName,
237  ID3D11ShaderResourceView** ppRV, void* pContext );
238  typedef void ( CALLBACK*LPCREATEVERTEXBUFFER11 )( raDirectX* pDev, ID3D11Buffer** ppBuffer,
239  D3D11_BUFFER_DESC BufferDesc, void* pData, void* pContext );
240  typedef void ( CALLBACK*LPCREATEINDEXBUFFER11 )( raDirectX* pDev, ID3D11Buffer** ppBuffer,
241  D3D11_BUFFER_DESC BufferDesc, void* pData, void* pContext );
243  {
244  LPCREATETEXTUREFROMFILE11 pCreateTextureFromFile;
245  LPCREATEVERTEXBUFFER11 pCreateVertexBuffer;
246  LPCREATEINDEXBUFFER11 pCreateIndexBuffer;
247  void* pContext;
248  };
250  {
251  private:
252  UINT m_NumOutstandingResources;
253  bool m_bLoading;
254  HANDLE m_hFile;
255  HANDLE m_hFileMappingObject;
256  raArray <BYTE*> m_MappedPointers;
257  raDirectX* m_pDev11;
258 
259  protected:
260  //These are the pointers to the two chunks of data loaded in from the mesh file
262  BYTE* m_pHeapData;
264  BYTE** m_ppVertices;
265  BYTE** m_ppIndices;
266 
267  //Keep track of the path
268  char m_strPathW[MAX_PATH];
269  char m_strPath[MAX_PATH];
270 
271  //General mesh info
279 
280  // Adjacency information (not part of the m_pStaticMeshData, so it must be created and destroyed separately )
282 
283  //Animation (TODO: Add ability to load/track multiple animation sets)
289 
290  protected:
291  void LoadMaterials( raDirectX* pd3dDevice, SDKMESH_MATERIAL* pMaterials,
292  UINT NumMaterials, SDKMESH_CALLBACKS11* pLoaderCallbacks=NULL );
293 
294  HRESULT CreateVertexBuffer( raDirectX* pd3dDevice,
295  SDKMESH_VERTEX_BUFFER_HEADER* pHeader, void* pVertices,
296  SDKMESH_CALLBACKS11* pLoaderCallbacks=NULL );
297 
298  HRESULT CreateIndexBuffer( raDirectX* pd3dDevice, SDKMESH_INDEX_BUFFER_HEADER* pHeader,
299  void* pIndices, SDKMESH_CALLBACKS11* pLoaderCallbacks=NULL );
300 
301  virtual HRESULT CreateFromFile( raDirectX* pDev11,
302  LPCTSTR szFileName,
303  bool bCreateAdjacencyIndices,
304  SDKMESH_CALLBACKS11* pLoaderCallbacks11 = NULL );
305 
306  virtual HRESULT CreateFromMemory( raDirectX* pDev11,
307  BYTE* pData,
308  UINT DataBytes,
309  bool bCreateAdjacencyIndices,
310  bool bCopyStatic,
311  SDKMESH_CALLBACKS11* pLoaderCallbacks11 = NULL);
312 
313  //frame manipulation
314  void TransformBindPoseFrame( UINT iFrame, D3DXMATRIX* pParentWorld );
315  void TransformFrame( UINT iFrame, D3DXMATRIX* pParentWorld, double fTime );
316  void TransformFrameAbsolute( UINT iFrame, double fTime );
317 
318  //Direct3D 11 rendering helpers
319  //SW
320  public:
321  void RenderMesh( UINT iMesh,
322  bool bAdjacent,
323  UINT iDiffuseSlot,
324  UINT iNormalSlot,
325  UINT iSpecularSlot );
326  //SW
327  protected:
328  void RenderFrame( UINT iFrame,
329  bool bAdjacent,
330  UINT iDiffuseSlot,
331  UINT iNormalSlot,
332  UINT iSpecularSlot );
333 
334  public:
335  CDXUTSDKMesh();
336  virtual ~CDXUTSDKMesh();
337 
338  virtual HRESULT Create( raDirectX* pDev11, LPCTSTR szFileName, bool bCreateAdjacencyIndices=
339  false, SDKMESH_CALLBACKS11* pLoaderCallbacks=NULL );
340  virtual HRESULT Create( raDirectX* pDev11, BYTE* pData, UINT DataBytes,
341  bool bCreateAdjacencyIndices=false, bool bCopyStatic=false,
342  SDKMESH_CALLBACKS11* pLoaderCallbacks=NULL );
343 
344  virtual HRESULT LoadAnimation( raString szFileName );
345  virtual void Destroy();
346 
347  //Frame manipulation
348  void TransformBindPose( D3DXMATRIX* pWorld );
349  void TransformMesh( D3DXMATRIX* pWorld, double fTime );
350 
351  //Direct3D 11 Rendering
352  virtual void Render( UINT iDiffuseSlot = INVALID_SAMPLER_SLOT,
353  UINT iNormalSlot = INVALID_SAMPLER_SLOT,
354  UINT iSpecularSlot = INVALID_SAMPLER_SLOT );
355  virtual void RenderAdjacent( UINT iDiffuseSlot = INVALID_SAMPLER_SLOT,
356  UINT iNormalSlot = INVALID_SAMPLER_SLOT,
357  UINT iSpecularSlot = INVALID_SAMPLER_SLOT );
358 
359  //Helpers (D3D11 specific)
360  static D3D11_PRIMITIVE_TOPOLOGY GetPrimitiveType11( SDKMESH_PRIMITIVE_TYPE PrimType );
361  DXGI_FORMAT GetIBFormat11( UINT iMesh );
362  ID3D11Buffer* GetVB11( UINT iMesh, UINT iVB );
363  ID3D11Buffer* GetIB11( UINT iMesh );
364  SDKMESH_INDEX_TYPE GetIndexType( UINT iMesh );
365 
366  ID3D11Buffer* GetAdjIB11( UINT iMesh );
367 
368  //Helpers (general)
369  raString GetMeshPathA();
370  UINT GetNumMeshes();
371  UINT GetNumMaterials();
372  UINT GetNumVBs();
373  UINT GetNumIBs();
374 
375  ID3D11Buffer* GetVB11At( UINT iVB );
376  ID3D11Buffer* GetIB11At( UINT iIB );
377 
378  BYTE* GetRawVerticesAt( UINT iVB );
379  BYTE* GetRawIndicesAt( UINT iIB );
380  SDKMESH_MATERIAL* GetMaterial( UINT iMaterial );
381  SDKMESH_MESH* GetMesh( UINT iMesh );
382  UINT GetNumSubsets( UINT iMesh );
383  SDKMESH_SUBSET* GetSubset( UINT iMesh, UINT iSubset );
384  UINT GetVertexStride( UINT iMesh, UINT iVB );
385  UINT GetNumFrames();
386  SDKMESH_FRAME* GetFrame( UINT iFrame );
387  SDKMESH_FRAME* FindFrame( raString pszName );
388  UINT64 GetNumVertices( UINT iMesh, UINT iVB );
389  UINT64 GetNumIndices( UINT iMesh );
390  D3DXVECTOR3 GetMeshBBoxCenter( UINT iMesh );
391  D3DXVECTOR3 GetMeshBBoxExtents( UINT iMesh );
392  UINT GetOutstandingResources();
393  UINT GetOutstandingBufferResources();
394  bool CheckLoadDone();
395  bool IsLoaded();
396  bool IsLoading();
397  void SetLoading( bool bLoading );
398  BOOL HadLoadingError();
399 
400  //Animation
401  UINT GetNumInfluences( UINT iMesh );
402  const D3DXMATRIX* GetMeshInfluenceMatrix( UINT iMesh, UINT iInfluence );
403  UINT GetAnimationKeyFromTime( double fTime );
404  const D3DXMATRIX* GetWorldMatrix( UINT iFrameIndex );
405  const D3DXMATRIX* GetInfluenceMatrix( UINT iFrameIndex );
406  bool GetAnimationProperties( UINT* pNumKeys, FLOAT* pFrameTime );
407  };
SDKMESH_VERTEX_BUFFER_HEADER * m_pVertexBufferArray
Definition: raSDKmesh.h:273
ID3D11ShaderResourceView * pSpecularRV11
Definition: raSDKmesh.h:203
UINT64 VertexStart
Definition: raSDKmesh.h:143
#define MAX_TEXTURE_NAME
Definition: raSDKmesh.h:19
SDKMESH_SUBSET * m_pSubsetArray
Definition: raSDKmesh.h:276
SDKANIMATION_DATA * pAnimationData
Definition: raSDKmesh.h:232
UINT64 MeshDataOffset
Definition: raSDKmesh.h:82
ID3D11Texture2D * pDiffuseTexture11
Definition: raSDKmesh.h:177
raString ID3D11ShaderResourceView void * pContext
Definition: raSDKmesh.h:236
SDKMESH_FRAME * m_pFrameArray
Definition: raSDKmesh.h:277
BOOL IsErrorResource(TYPE data)
Definition: raSDKmesh.h:29
ID3D11Texture2D * pNormalTexture11
Definition: raSDKmesh.h:182
LPCREATEINDEXBUFFER11 pCreateIndexBuffer
Definition: raSDKmesh.h:246
UINT64 MaterialDataOffset
Definition: raSDKmesh.h:85
UINT64 IndexStreamHeadersOffset
Definition: raSDKmesh.h:81
UINT AnimationDataIndex
Definition: raSDKmesh.h:155
#define MAX_MATERIAL_NAME
Definition: raSDKmesh.h:18
UINT64 NonBufferDataSize
Definition: raSDKmesh.h:68
UINT * pFrameInfluences
Definition: raSDKmesh.h:132
BYTE ** m_ppIndices
Definition: raSDKmesh.h:265
SDKMESH_INDEX_BUFFER_HEADER * m_pIndexBufferArray
Definition: raSDKmesh.h:274
#define RAPI
Definition: raMain.h:11
#define MAX_MESH_NAME
Definition: raSDKmesh.h:16
LPCREATEVERTEXBUFFER11 pCreateVertexBuffer
Definition: raSDKmesh.h:245
#define MAX_MATERIAL_PATH
Definition: raSDKmesh.h:20
SDKANIMATION_FRAME_DATA * m_pAnimationFrameData
Definition: raSDKmesh.h:285
#define MAX_FRAME_NAME
Definition: raSDKmesh.h:15
UINT * pSubsets
Definition: raSDKmesh.h:127
UINT SiblingFrame
Definition: raSDKmesh.h:153
UINT64 SubsetOffset
Definition: raSDKmesh.h:126
UINT64 IndexCount
Definition: raSDKmesh.h:142
D3DXVECTOR4 Emissive
Definition: raSDKmesh.h:171
UINT NumTotalSubsets
Definition: raSDKmesh.h:75
LPCREATETEXTUREFROMFILE11 pCreateTextureFromFile
Definition: raSDKmesh.h:244
UINT64 Force64_2
Definition: raSDKmesh.h:181
#define MAX_SUBSET_NAME
Definition: raSDKmesh.h:17
UINT ParentFrame
Definition: raSDKmesh.h:151
UINT64 SubsetDataOffset
Definition: raSDKmesh.h:83
UINT NumMaterials
Definition: raSDKmesh.h:77
UINT NumIndexBuffers
Definition: raSDKmesh.h:73
UINT64 FrameDataOffset
Definition: raSDKmesh.h:84
SDKMESH_HEADER * m_pMeshHeader
Definition: raSDKmesh.h:272
UINT64 VertexCount
Definition: raSDKmesh.h:144
BYTE * m_pStaticMeshData
Definition: raSDKmesh.h:261
BYTE ** m_ppVertices
Definition: raSDKmesh.h:264
raString ID3D11ShaderResourceView ** ppRV
Definition: raSDKmesh.h:236
UINT64 FrameInfluenceOffset
Definition: raSDKmesh.h:131
UINT NumFrameInfluences
Definition: raSDKmesh.h:119
#define MAX_VERTEX_STREAMS
Definition: raSDKmesh.h:14
UINT64 VertexStreamHeadersOffset
Definition: raSDKmesh.h:80
D3DXMATRIX * m_pBindPoseFrameMatrices
Definition: raSDKmesh.h:286
UINT NumFrames
Definition: raSDKmesh.h:76
SDKMESH_MATERIAL * m_pMaterialArray
Definition: raSDKmesh.h:278
SDKMESH_PRIMITIVE_TYPE
Definition: raSDKmesh.h:35
#define ERROR_RESOURCE_VALUE
Definition: raSDKmesh.h:27
FRAME_TRANSFORM_TYPE
Definition: raSDKmesh.h:56
UINT64 Force64_3
Definition: raSDKmesh.h:186
ID3D11Buffer D3D11_BUFFER_DESC BufferDesc
Definition: raSDKmesh.h:238
UINT ChildFrame
Definition: raSDKmesh.h:152
UINT NumSubsets
Definition: raSDKmesh.h:118
BYTE IsBigEndian
Definition: raSDKmesh.h:66
D3DXVECTOR4 Ambient
Definition: raSDKmesh.h:169
ID3D11ShaderResourceView * pDiffuseRV11
Definition: raSDKmesh.h:193
SDKMESH_INDEX_BUFFER_HEADER * m_pAdjacencyIndexBufferArray
Definition: raSDKmesh.h:281
UINT64 Force64_6
Definition: raSDKmesh.h:202
UINT64 IndexStart
Definition: raSDKmesh.h:141
ID3D11Buffer ** ppBuffer
Definition: raSDKmesh.h:238
BYTE * m_pAnimationData
Definition: raSDKmesh.h:263
D3DXVECTOR3 BoundingBoxCenter
Definition: raSDKmesh.h:121
std::string raString
Definition: raMain.h:107
UINT NumMeshes
Definition: raSDKmesh.h:74
SDKMESH_MESH * m_pMeshArray
Definition: raSDKmesh.h:275
UINT64 BufferDataSize
Definition: raSDKmesh.h:69
D3DXVECTOR3 BoundingBoxExtents
Definition: raSDKmesh.h:122
raString szFileName
Definition: raSDKmesh.h:236
BYTE NumVertexBuffers
Definition: raSDKmesh.h:115
ID3D11Buffer D3D11_BUFFER_DESC void * pData
Definition: raSDKmesh.h:238
UINT64 HeaderSize
Definition: raSDKmesh.h:67
UINT64 Force64_4
Definition: raSDKmesh.h:192
D3DXVECTOR4 Orientation
Definition: raSDKmesh.h:222
BYTE * m_pHeapData
Definition: raSDKmesh.h:262
D3DXMATRIX * m_pTransformedFrameMatrices
Definition: raSDKmesh.h:287
UINT64 Force64_1
Definition: raSDKmesh.h:176
UINT PrimitiveType
Definition: raSDKmesh.h:140
ID3D11Texture2D * pSpecularTexture11
Definition: raSDKmesh.h:187
D3DXMATRIX Matrix
Definition: raSDKmesh.h:154
SDKANIMATION_FILE_HEADER * m_pAnimationHeader
Definition: raSDKmesh.h:284
D3DXVECTOR4 Diffuse
Definition: raSDKmesh.h:168
UINT64 Force64_5
Definition: raSDKmesh.h:197
UINT NumVertexBuffers
Definition: raSDKmesh.h:72
UINT IndexBuffer
Definition: raSDKmesh.h:117
Definition: raArray.h:3
D3DXVECTOR3 Scaling
Definition: raSDKmesh.h:223
ID3D11ShaderResourceView * pNormalRV11
Definition: raSDKmesh.h:198
#define INVALID_SAMPLER_SLOT
Definition: raSDKmesh.h:26
typedef void(CALLBACK *LPCREATETEXTUREFROMFILE11)(raDirectX *pDev
SDKMESH_INDEX_TYPE
Definition: raSDKmesh.h:50
D3DXMATRIX * m_pWorldPoseFrameMatrices
Definition: raSDKmesh.h:288
D3DXVECTOR3 Translation
Definition: raSDKmesh.h:221
D3DXVECTOR4 Specular
Definition: raSDKmesh.h:170