DXUTMesh.h
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:5k
源码类别:

DirextX编程

开发平台:

Visual C++

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