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.

237 lines
8.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMEANIMATIONSET_H
  7. #define DMEANIMATIONSET_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "datamodel/dmattribute.h"
  13. #include "datamodel/dmattributevar.h"
  14. #include "movieobjects/dmephonememapping.h"
  15. #include "movieobjects/timeutils.h"
  16. #include "movieobjects/proceduralpresets.h"
  17. class CDmeBookmark;
  18. //-----------------------------------------------------------------------------
  19. // A preset is a list of values to be applied to named controls in the animation set
  20. //-----------------------------------------------------------------------------
  21. class CDmePreset : public CDmElement
  22. {
  23. DEFINE_ELEMENT( CDmePreset, CDmElement );
  24. public:
  25. CDmaElementArray< CDmElement > &GetControlValues();
  26. const CDmaElementArray< CDmElement > &GetControlValues() const;
  27. CDmElement *FindControlValue( const char *pControlName );
  28. CDmElement *FindOrAddControlValue( const char *pControlName );
  29. void RemoveControlValue( const char *pControlName );
  30. bool IsReadOnly();
  31. void CopyControlValuesFrom( CDmePreset *pSource );
  32. // See the enumeration above
  33. void SetProceduralPresetType( int nType );
  34. bool IsProcedural() const;
  35. int GetProceduralPresetType() const;
  36. private:
  37. int FindControlValueIndex( const char *pControlName );
  38. CDmaElementArray< CDmElement > m_ControlValues;
  39. CDmaVar< int > m_nProceduralType;
  40. };
  41. class CDmeProceduralPresetSettings : public CDmElement
  42. {
  43. DEFINE_ELEMENT( CDmeProceduralPresetSettings, CDmElement );
  44. public:
  45. CDmaVar< float > m_flJitterScale;
  46. CDmaVar< float > m_flSmoothScale;
  47. CDmaVar< float > m_flSharpenScale;
  48. CDmaVar< float > m_flSoftenScale;
  49. CDmaVar< int > m_nJitterIterations;
  50. CDmaVar< int > m_nSmoothIterations;
  51. CDmaVar< int > m_nSharpenIterations;
  52. CDmaVar< int > m_nSoftenIterations;
  53. CDmaVar< int > m_nStaggerInterval;
  54. };
  55. //-----------------------------------------------------------------------------
  56. // A class used to copy preset values from one preset group to another
  57. //-----------------------------------------------------------------------------
  58. class CDmePresetRemap : public CDmElement
  59. {
  60. DEFINE_ELEMENT( CDmePresetRemap, CDmElement );
  61. public:
  62. CDmaString m_SourcePresetGroup;
  63. const char *FindSourcePreset( const char *pDestPresetName );
  64. int GetRemapCount();
  65. const char *GetRemapSource( int i );
  66. const char *GetRemapDest( int i );
  67. void AddRemap( const char *pSourcePresetName, const char *pDestPresetName );
  68. void RemoveAll();
  69. private:
  70. CDmaStringArray m_SrcPresets;
  71. CDmaStringArray m_DestPresets;
  72. };
  73. class CDmeAnimationSet;
  74. class CDmeCombinationOperator;
  75. //-----------------------------------------------------------------------------
  76. // A preset group is a list of presets, with shared visibility + readonly settings
  77. //-----------------------------------------------------------------------------
  78. class CDmePresetGroup : public CDmElement
  79. {
  80. DEFINE_ELEMENT( CDmePresetGroup, CDmElement );
  81. public:
  82. CDmaElementArray< CDmePreset > &GetPresets(); // raw access to the array
  83. const CDmaElementArray< CDmePreset > &GetPresets() const;
  84. CDmePreset *FindPreset( const char *pPresetName );
  85. CDmePreset *FindOrAddPreset( const char *pPresetName, int nProceduralType = PROCEDURAL_PRESET_NOT );
  86. bool RemovePreset( CDmePreset *pPreset );
  87. void MovePresetUp( CDmePreset *pPreset );
  88. void MovePresetDown( CDmePreset *pPreset );
  89. void MovePresetInFrontOf( CDmePreset *pPreset, CDmePreset *pInFrontOf );
  90. CDmePresetRemap *GetPresetRemap();
  91. CDmePresetRemap *GetOrAddPresetRemap();
  92. CDmaVar< bool > m_bIsVisible;
  93. CDmaVar< bool > m_bIsReadOnly;
  94. // Exports this preset group to a faceposer .txt expression file
  95. bool ExportToTXT( const char *pFilename, CDmeAnimationSet *pAnimationSet = NULL, CDmeCombinationOperator *pComboOp = NULL ) const;
  96. // Exports this preset group to a faceposer .vfe expression file
  97. bool ExportToVFE( const char *pFilename, CDmeAnimationSet *pAnimationSet = NULL, CDmeCombinationOperator *pComboOp = NULL ) const;
  98. private:
  99. int FindPresetIndex( CDmePreset *pGroupName );
  100. CDmaElementArray< CDmePreset > m_Presets; // "presets"
  101. };
  102. //-----------------------------------------------------------------------------
  103. // The main controlbox for controlling animation
  104. //-----------------------------------------------------------------------------
  105. class CDmeAnimationSet : public CDmElement
  106. {
  107. DEFINE_ELEMENT( CDmeAnimationSet, CDmElement );
  108. public:
  109. CDmaElementArray< CDmElement > &GetControls(); // raw access to the array
  110. CDmaElementArray< CDmElement > &GetSelectionGroups(); // raw access to the array
  111. CDmaElementArray< CDmePresetGroup > &GetPresetGroups(); // raw access to the array
  112. CDmaElementArray< CDmePhonemeMapping > &GetPhonemeMap(); // raw access to the array
  113. CDmaElementArray< CDmeOperator > &GetOperators(); // raw access to the array
  114. void RestoreDefaultPhonemeMap();
  115. CDmePhonemeMapping *FindMapping( const char *pRawPhoneme );
  116. CDmElement *FindControl( const char *pControlName );
  117. CDmElement *FindOrAddControl( const char *pControlName );
  118. // Methods pertaining to preset groups
  119. CDmePresetGroup *FindPresetGroup( const char *pGroupName );
  120. CDmePresetGroup *FindOrAddPresetGroup( const char *pGroupName );
  121. bool RemovePresetGroup( CDmePresetGroup *pPresetGroup );
  122. void MovePresetGroupUp( CDmePresetGroup *pPresetGroup );
  123. void MovePresetGroupDown( CDmePresetGroup *pPresetGroup );
  124. void MovePresetGroupInFrontOf( CDmePresetGroup *pPresetGroup, CDmePresetGroup *pInFrontOf );
  125. CDmePreset *FindOrAddPreset( const char *pGroupName, const char *pPresetName, int nProceduralType = PROCEDURAL_PRESET_NOT );
  126. bool RemovePreset( CDmePreset *pPreset );
  127. const CDmaElementArray< CDmeBookmark > &GetBookmarks() const;
  128. CDmaElementArray< CDmeBookmark > &GetBookmarks();
  129. CDmElement *FindSelectionGroup( const char *pSelectionGroupName );
  130. CDmElement *FindOrAddSelectionGroup( const char *pSelectionGroupName );
  131. virtual void OnElementUnserialized();
  132. void CollectOperators( CUtlVector< DmElementHandle_t > &operators );
  133. void AddOperator( CDmeOperator *pOperator );
  134. void RemoveOperator( CDmeOperator *pOperator );
  135. void EnsureProceduralPresets();
  136. private:
  137. int FindPresetGroupIndex( CDmePresetGroup *pGroup );
  138. int FindPresetGroupIndex( const char *pGroupName );
  139. CDmaElementArray< CDmElement > m_Controls; // "controls"
  140. CDmaElementArray< CDmElement > m_SelectionGroups; // "selectionGroups"
  141. CDmaElementArray< CDmePresetGroup > m_PresetGroups; // "presetGroups"
  142. CDmaElementArray< CDmePhonemeMapping > m_PhonemeMap; // "phonememap"
  143. CDmaElementArray< CDmeOperator > m_Operators; // "operators"
  144. CDmaElementArray< CDmeBookmark > m_Bookmarks; // "bookmarks"
  145. friend class CModelPresetGroupManager;
  146. };
  147. //-----------------------------------------------------------------------------
  148. // Utility methods to convert between L/R and V/B
  149. //-----------------------------------------------------------------------------
  150. inline void ValueBalanceToLeftRight( float *pLeft, float *pRight, float flValue, float flBalance )
  151. {
  152. *pLeft = ( flBalance <= 0.5f ) ? 1.0f : ( ( 1.0f - flBalance ) / 0.5f );
  153. *pLeft *= flValue;
  154. *pRight = ( flBalance >= 0.5f ) ? 1.0f : ( flBalance / 0.5f );
  155. *pRight *= flValue;
  156. }
  157. inline void LeftRightToValueBalance( float *pValue, float *pBalance, float flLeft, float flRight, float flDefaultBalance = 0.5f )
  158. {
  159. *pValue = max( flRight, flLeft );
  160. if ( *pValue <= 1e-6 )
  161. {
  162. // Leave target balance at input value if target == 0 and on the dest side of blending
  163. *pBalance = flDefaultBalance;
  164. return;
  165. }
  166. if ( flRight < flLeft )
  167. {
  168. *pBalance = 0.5f * flRight / flLeft;
  169. }
  170. else
  171. {
  172. *pBalance = 1.0f - ( 0.5f * flLeft / flRight );
  173. }
  174. }
  175. //-----------------------------------------------------------------------------
  176. // A cache of preset groups to be associated with specific models
  177. //-----------------------------------------------------------------------------
  178. abstract_class IModelPresetGroupManager
  179. {
  180. public:
  181. virtual void AssociatePresetsWithFile( DmFileId_t fileId ) = 0;
  182. virtual void ApplyModelPresets( const char *pModelName, CDmeAnimationSet *pAnimationSet ) = 0;
  183. };
  184. extern IModelPresetGroupManager *g_pModelPresetGroupMgr;
  185. #endif // DMEANIMATIONSET_H