Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.9 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: D3DFile.h
  3. //
  4. // Desc: Support code for loading DirectX .X files.
  5. //
  6. // Copyright (c) 1997-1999 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DFILE_H
  9. #define D3DFILE_H
  10. //-----------------------------------------------------------------------------
  11. // Name: struct MeshMaterialData
  12. // Desc: Internal structure for holding material data for within a mesh. This
  13. // is used because multiple materials can be used in the same mesh.
  14. //-----------------------------------------------------------------------------
  15. #define MAX_MATERIAL 16
  16. #define MAX_TEXTURE_NAME 80
  17. struct MeshMaterialData
  18. {
  19. D3DMATERIAL7 m_mtrl;
  20. TCHAR m_strTexture[MAX_TEXTURE_NAME];
  21. DWORD m_dwNumIndices;
  22. };
  23. //-----------------------------------------------------------------------------
  24. // Name: class CD3DFileObject
  25. // Desc: Internal class for objects in a .X file
  26. //-----------------------------------------------------------------------------
  27. class CD3DFileObject
  28. {
  29. // Common data
  30. TCHAR m_strName[80];
  31. CD3DFileObject* m_pNext;
  32. CD3DFileObject* m_pChild;
  33. // For file frames
  34. D3DMATRIX m_mat;
  35. // For file meshes
  36. BOOL m_bHasMeshData;
  37. DWORD m_dwNumVertices;
  38. D3DVERTEX* m_pVertices;
  39. DWORD m_dwNumIndices;
  40. WORD* m_pIndices;
  41. DWORD m_dwNumMaterials;
  42. MeshMaterialData m_Material[MAX_MATERIAL];
  43. BOOL m_bHasAlpha;
  44. public:
  45. // Initializing functions
  46. VOID AddNext(CD3DFileObject*);
  47. VOID AddChild(CD3DFileObject*);
  48. VOID SetName(TCHAR* strName) { StrCpy(m_strName, strName); }
  49. VOID SetMatrix(D3DMATRIX* pmat) { m_mat = *pmat; }
  50. VOID SetNormals(D3DVECTOR* pNormals);
  51. VOID SetTextureCoords(FLOAT* pTexCoords);
  52. VOID SetMaterialData(DWORD dwMaterial, D3DMATERIAL7* pmtrl, TCHAR*strName);
  53. VOID AddFace(DWORD dwMaterial, DWORD* pFaceData, DWORD dwNumFaces);
  54. HRESULT ComputeNormals();
  55. HRESULT SetMeshGeometry(D3DVECTOR* pvVertices, DWORD dwNumVertices,
  56. DWORD* pFaces, DWORD dwNumFaces);
  57. // Access functions
  58. TCHAR* GetName() { return m_strName; }
  59. CD3DFileObject* GetNext() { return m_pNext; }
  60. CD3DFileObject* GetChild() { return m_pChild; }
  61. D3DMATRIX* GetMatrix() { return &m_mat; }
  62. HRESULT GetMeshGeometry(D3DVERTEX** ppVertices,
  63. DWORD* pdwNumVertices, WORD** ppIndices,
  64. DWORD* pdwNumIndices);
  65. // Common functions
  66. VOID Render(LPDIRECT3DDEVICE7 pd3dDevice , BOOL bAlpha);
  67. BOOL EnumObjects(BOOL (*fnCallback)(CD3DFileObject*,D3DMATRIX*,VOID*),
  68. D3DMATRIX* pmat, VOID* pContext);
  69. // Constuctor / destructor
  70. CD3DFileObject(TCHAR* strName);
  71. ~CD3DFileObject();
  72. };
  73. //-----------------------------------------------------------------------------
  74. // Name: class CD3DFile
  75. // Desc:
  76. //-----------------------------------------------------------------------------
  77. class CD3DFile
  78. {
  79. CD3DFileObject* m_pRoot;
  80. public:
  81. HRESULT GetMeshVertices(TCHAR* strName, D3DVERTEX** ppVertices,
  82. DWORD* pdwNumVertices);
  83. HRESULT GetMeshIndices(TCHAR* strName, WORD** ppIndices,
  84. DWORD* pdwNumIndices);
  85. CD3DFileObject* FindObject(TCHAR* strName);
  86. VOID EnumObjects(BOOL (*fnCallback)(CD3DFileObject*,D3DMATRIX*,VOID*),
  87. D3DMATRIX* pmat, VOID* pContext);
  88. VOID Scale(FLOAT fScale);
  89. HRESULT Load(LPCTSTR strFilename);
  90. HRESULT Render(LPDIRECT3DDEVICE7);
  91. CD3DFile();
  92. ~CD3DFile();
  93. };
  94. #endif