Counter Strike : Global Offensive Source Code
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.

151 lines
4.2 KiB

  1. //========= Copyright � 1996-2005, 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. #define MAX_STUDIOMODELCACHE 2048
  31. //-----------------------------------------------------------------------------
  32. // Purpose: Defines an interface to a cache of studio models.
  33. //-----------------------------------------------------------------------------
  34. class CStudioModelCache
  35. {
  36. public:
  37. static StudioModel *FindModel(const char *pszModelPath);
  38. static StudioModel *CreateModel(const char *pszModelPath);
  39. static void ReloadModel( const char *pszModelPath );
  40. static void AddRef(StudioModel *pModel);
  41. static void Release(StudioModel *pModel);
  42. static void AdvanceAnimation(float flInterval);
  43. protected:
  44. static BOOL AddModel(StudioModel *pModel, const char *pszModelPath);
  45. static void RemoveModel(StudioModel *pModel);
  46. static ModelCache_t m_Cache[MAX_STUDIOMODELCACHE];
  47. static int m_nItems;
  48. };
  49. // Calling these will monitor the filesystem for changes to model files and automatically
  50. // incorporate changes to the models.
  51. void InitStudioFileChangeWatcher();
  52. void UpdateStudioFileChangeWatcher();
  53. class StudioModel
  54. {
  55. public:
  56. static bool Initialize( void );
  57. static void Shutdown( void ); // garymcthack - need to call this.
  58. StudioModel(void);
  59. ~StudioModel(void);
  60. void FreeModel ();
  61. bool LoadModel( const char *modelname );
  62. bool PostLoadModel ( const char *modelname );
  63. void DrawModel3D( CRender3D *pRender, const Color &color, float flAlpha, bool bWireframe);
  64. void DrawModel2D( CRender2D *pRender, float flAlpha, bool bWireFrame);
  65. void AdvanceFrame( float dt );
  66. void ExtractBbox( Vector &mins, Vector &maxs );
  67. void ExtractClippingBbox( Vector &mins, Vector &maxs );
  68. void ExtractMovementBbox( Vector &mins, Vector &maxs );
  69. void RotateBbox( Vector &Mins, Vector &Maxs, const QAngle &Angles );
  70. void SetFrame( int nFrame );
  71. int GetMaxFrame( void );
  72. int SetSequence( int iSequence );
  73. int GetSequence( void );
  74. int GetSequenceCount( void );
  75. void GetSequenceName( int nIndex, char *szName );
  76. void GetSequenceInfo( float *pflFrameRate, float *pflGroundSpeed );
  77. const char *GetModelName( void );
  78. int SetBodygroup( int iGroup, int iValue );
  79. int SetBodygroups( int iValue );
  80. int SetSkin( int iValue );
  81. void SetOrigin( float x, float y, float z );
  82. void GetOrigin( float &x, float &y, float &z );
  83. void SetOrigin( const Vector &v );
  84. void GetOrigin( Vector &v );
  85. void SetAngles( QAngle& pfAngles );
  86. bool IsTranslucent();
  87. private:
  88. CStudioHdr *m_pStudioHdr;
  89. CStudioHdr *GetStudioHdr() const;
  90. studiohdr_t* GetStudioRenderHdr() const;
  91. studiohwdata_t* GetHardwareData();
  92. // entity settings
  93. Vector m_origin;
  94. QAngle m_angles;
  95. int m_sequence; // sequence index
  96. float m_cycle; // pos in animation cycle
  97. int m_bodynum; // bodypart selection
  98. int m_skinnum; // skin group selection
  99. byte m_controller[MAXSTUDIOBONECTRLS]; // bone controllers
  100. float m_poseParameter[MAXSTUDIOPOSEPARAM]; // animation blending
  101. byte m_mouth; // mouth position
  102. char* m_pModelName; // model file name
  103. Vector *m_pPosePos;
  104. QuaternionAligned *m_pPoseAng;
  105. // internal data
  106. MDLHandle_t m_MDLHandle;
  107. mstudiomodel_t *m_pModel;
  108. void SetUpBones ( bool bUpdatePose, matrix3x4a_t* pBoneToWorld );
  109. void SetupModel ( int bodypart );
  110. void LoadStudioRender( void );
  111. bool LoadVVDFile( const char *modelname );
  112. bool LoadVTXFile( const char *modelname );
  113. };
  114. extern Vector g_vright; // needs to be set to viewer's right in order for chrome to work
  115. extern float g_lambert; // modifier for pseudo-hemispherical lighting
  116. #endif // STUDIOMODEL_H