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.

144 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef STUDIOMODEL_H
  8. #define STUDIOMODEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #ifndef byte
  13. typedef unsigned char byte;
  14. #endif // byte
  15. #include "hammer_mathlib.h"
  16. #include "studio.h"
  17. #include "utlvector.h"
  18. #include "datacache/imdlcache.h"
  19. #include "FileChangeWatcher.h"
  20. class StudioModel;
  21. class CMaterial;
  22. class CRender3D;
  23. class CRender2D;
  24. struct ModelCache_t
  25. {
  26. StudioModel *pModel;
  27. char *pszPath;
  28. int nRefCount;
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Defines an interface to a cache of studio models.
  32. //-----------------------------------------------------------------------------
  33. class CStudioModelCache
  34. {
  35. public:
  36. static StudioModel *FindModel(const char *pszModelPath);
  37. static StudioModel *CreateModel(const char *pszModelPath);
  38. static void AddRef(StudioModel *pModel);
  39. static void Release(StudioModel *pModel);
  40. static void AdvanceAnimation(float flInterval);
  41. protected:
  42. static BOOL AddModel(StudioModel *pModel, const char *pszModelPath);
  43. static void RemoveModel(StudioModel *pModel);
  44. static ModelCache_t m_Cache[1024];
  45. static int m_nItems;
  46. };
  47. // Calling these will monitor the filesystem for changes to model files and automatically
  48. // incorporate changes to the models.
  49. void InitStudioFileChangeWatcher();
  50. void UpdateStudioFileChangeWatcher();
  51. class StudioModel
  52. {
  53. public:
  54. static bool Initialize( void );
  55. static void Shutdown( void ); // garymcthack - need to call this.
  56. StudioModel(void);
  57. ~StudioModel(void);
  58. void FreeModel ();
  59. bool LoadModel( const char *modelname );
  60. bool PostLoadModel ( const char *modelname );
  61. void DrawModel3D( CRender3D *pRender, float flAlpha, bool bWireframe);
  62. void DrawModel2D( CRender2D *pRender, float flAlpha, bool bWireFrame);
  63. void AdvanceFrame( float dt );
  64. void ExtractBbox( Vector &mins, Vector &maxs );
  65. void ExtractClippingBbox( Vector &mins, Vector &maxs );
  66. void ExtractMovementBbox( Vector &mins, Vector &maxs );
  67. void RotateBbox( Vector &Mins, Vector &Maxs, const QAngle &Angles );
  68. int SetSequence( int iSequence );
  69. int GetSequence( void );
  70. int GetSequenceCount( void );
  71. void GetSequenceName( int nIndex, char *szName );
  72. void GetSequenceInfo( float *pflFrameRate, float *pflGroundSpeed );
  73. int SetBodygroup( int iGroup, int iValue );
  74. int SetSkin( int iValue );
  75. void SetOrigin( float x, float y, float z );
  76. void GetOrigin( float &x, float &y, float &z );
  77. void SetOrigin( const Vector &v );
  78. void GetOrigin( Vector &v );
  79. void SetAngles( QAngle& pfAngles );
  80. bool IsTranslucent();
  81. private:
  82. CStudioHdr *m_pStudioHdr;
  83. CStudioHdr *GetStudioHdr() const;
  84. studiohdr_t* GetStudioRenderHdr() const;
  85. studiohwdata_t* GetHardwareData();
  86. // entity settings
  87. Vector m_origin;
  88. QAngle m_angles;
  89. int m_sequence; // sequence index
  90. float m_cycle; // pos in animation cycle
  91. int m_bodynum; // bodypart selection
  92. int m_skinnum; // skin group selection
  93. byte m_controller[MAXSTUDIOBONECTRLS]; // bone controllers
  94. float m_poseParameter[MAXSTUDIOPOSEPARAM]; // animation blending
  95. byte m_mouth; // mouth position
  96. char* m_pModelName; // model file name
  97. Vector *m_pPosePos;
  98. Quaternion *m_pPoseAng;
  99. // internal data
  100. MDLHandle_t m_MDLHandle;
  101. mstudiomodel_t *m_pModel;
  102. void SetUpBones ( bool bUpdatePose, matrix3x4_t* pBoneToWorld );
  103. void SetupModel ( int bodypart );
  104. void LoadStudioRender( void );
  105. bool LoadVVDFile( const char *modelname );
  106. bool LoadVTXFile( const char *modelname );
  107. };
  108. extern Vector g_vright; // needs to be set to viewer's right in order for chrome to work
  109. extern float g_lambert; // modifier for pseudo-hemispherical lighting
  110. #endif // STUDIOMODEL_H