Team Fortress 2 Source Code as on 22/4/2020
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.

140 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing a mesh
  4. //
  5. //=============================================================================
  6. #ifndef DMETESTMESH_H
  7. #define DMETESTMESH_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "movieobjects/dmeshape.h"
  12. #include "datacache/imdlcache.h"
  13. #include "mathlib/vector.h"
  14. #include <string>
  15. #include <vector>
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class CDmeTransform;
  20. class IMorph;
  21. class IMaterial;
  22. struct SubdivMesh_t;
  23. class IMesh;
  24. class CDmeDrawSettings;
  25. //-----------------------------------------------------------------------------
  26. // First attempt at making a hacky SMD loader - clean this up later
  27. //-----------------------------------------------------------------------------
  28. struct skinning_info_t
  29. {
  30. skinning_info_t() : index( -1 ), weight( 0.0f )
  31. {
  32. }
  33. skinning_info_t( int i, float w ) : index( i ), weight( w )
  34. {
  35. }
  36. int index;
  37. float weight;
  38. bool operator<( const skinning_info_t &info )
  39. {
  40. return weight < info.weight;
  41. }
  42. };
  43. struct vertex_t
  44. {
  45. Vector coord;
  46. Vector normal;
  47. Vector2D texcoord;
  48. std::vector< skinning_info_t > skinning;
  49. static float normal_tolerance;
  50. bool operator==( const vertex_t &vert )
  51. {
  52. return
  53. // skinning == vert.skinning && // TODO - the original studiomdl doesn't do this, but...
  54. coord == vert.coord &&
  55. texcoord == vert.texcoord &&
  56. DotProduct( normal, vert.normal ) > normal_tolerance;
  57. }
  58. };
  59. struct submesh_t
  60. {
  61. submesh_t( const std::string &texture_name ) : texname( texture_name )
  62. {
  63. }
  64. std::string texname;
  65. std::vector< int > indices;
  66. std::vector< vertex_t > vertices;
  67. std::vector< CDmeTransform* > bones;
  68. };
  69. //-----------------------------------------------------------------------------
  70. // A class representing a mesh
  71. //-----------------------------------------------------------------------------
  72. class CDmeTestMesh : public CDmeShape
  73. {
  74. DEFINE_ELEMENT( CDmeTestMesh, CDmeShape );
  75. public:
  76. virtual void Draw( const matrix3x4_t& shapeToWorld, CDmeDrawSettings *pDrawSettings = NULL );
  77. static CDmeTestMesh *ReadMeshFromSMD( char *pFilename, DmFileId_t fileid );
  78. virtual void Resolve();
  79. private:
  80. // Addref/Release the MDL handle
  81. void ReferenceMDL( const char *pMDLName );
  82. void UnreferenceMDL();
  83. // Returns a mask indicating which bones to set up
  84. int BoneMask( );
  85. // Sets up the bones
  86. void SetUpBones( CDmeTransform *pTransform, int nMaxBoneCount, matrix3x4_t *pBoneToWorld );
  87. // For testing vertex textures
  88. void LoadMorphData( const char *pMorphFile, int nVertexCount );
  89. void UnloadMorphData();
  90. void LoadModelMatrix( CDmeTransform *pTransform );
  91. void DrawBox( CDmeTransform *pTransform );
  92. // Draws a subdivided box
  93. void DrawSubdivMesh( const SubdivMesh_t &mesh );
  94. void DrawSubdividedBox();
  95. // Creates/destroys the subdiv control cage
  96. void CreateControlCage( );
  97. void DestroyControlCage( );
  98. // Creates/destroys the morphed mesh
  99. void CreateMesh( );
  100. void DestroyMesh( );
  101. MDLHandle_t m_MDLHandle;
  102. IMaterial *m_pMaterial;
  103. IMesh *m_pMesh;
  104. IMorph *m_pMorph;
  105. SubdivMesh_t *m_pControlCage;
  106. //-----------------------------------------------------------------------------
  107. // First attempt at making a hacky SMD loader - clean this up later
  108. //-----------------------------------------------------------------------------
  109. std::vector< submesh_t* > m_submeshes;
  110. std::vector< CDmeTransform* > m_bones;
  111. };
  112. #endif // DMETESTMESH_H