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.

453 lines
16 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Operators that generate combinations
  4. //
  5. //=============================================================================
  6. #ifndef DMECOMBINATIONOPERATOR_H
  7. #define DMECOMBINATIONOPERATOR_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/dmeoperator.h"
  15. #include "movieobjects/dmeexpressionoperator.h"
  16. #include "datamodel/dmehandle.h"
  17. //-----------------------------------------------------------------------------
  18. // Expression operator
  19. //-----------------------------------------------------------------------------
  20. class CDmeChannel;
  21. class CDmeDag;
  22. class CDmElement;
  23. class CDmeChannelsClip;
  24. class CDmeShape;
  25. //-----------------------------------------------------------------------------
  26. // Control handles
  27. //-----------------------------------------------------------------------------
  28. typedef int ControlIndex_t;
  29. //-----------------------------------------------------------------------------
  30. // Basic version..
  31. //-----------------------------------------------------------------------------
  32. class CDmeCombinationInputControl : public CDmElement
  33. {
  34. DEFINE_ELEMENT( CDmeCombinationInputControl, CDmElement );
  35. public:
  36. virtual void OnElementUnserialized();
  37. // Adds a control, returns the control index,
  38. // returns true if remapped control lists need updating
  39. bool AddRawControl( const char *pRawControlName );
  40. // Removes controls
  41. // returns true if remapped control lists need updating
  42. bool RemoveRawControl( const char *pRawControlName );
  43. void RemoveAllRawControls();
  44. // Iterates remapped controls
  45. int RawControlCount() const;
  46. const char *RawControlName( int nIndex ) const;
  47. // Reordering controls
  48. void MoveRawControlUp( const char *pRawControlName );
  49. void MoveRawControlDown( const char *pRawControlName );
  50. // Is this control a stereo control?
  51. bool IsStereo() const;
  52. void SetStereo( bool bStereo );
  53. // Is this control an eyelid control?
  54. bool IsEyelid() const;
  55. void SetEyelid( bool bEyelid );
  56. // Returns the name of the eyeball
  57. const char *GetEyesUpDownFlexName() const;
  58. // Returns the wrinkle scale for a particular control
  59. float WrinkleScale( const char *pRawControlName );
  60. float WrinkleScale( int nIndex );
  61. void SetWrinkleScale( const char *pRawControlName, float flWrinkleScale );
  62. float GetDefaultValue() const;
  63. float GetBaseValue() const;
  64. private:
  65. int FindRawControl( const char *pRawControlName );
  66. CDmaStringArray m_RawControlNames;
  67. CDmaVar<bool> m_bIsStereo;
  68. CDmaVar< bool > m_bIsEyelid;
  69. // FIXME! Remove soon! Used to autogenerate wrinkle deltas
  70. CDmaArray< float > m_WrinkleScales;
  71. };
  72. //-----------------------------------------------------------------------------
  73. // Basic version..
  74. //-----------------------------------------------------------------------------
  75. class CDmeCombinationDominationRule : public CDmElement
  76. {
  77. DEFINE_ELEMENT( CDmeCombinationDominationRule, CDmElement );
  78. public:
  79. // Methods of IDmElement
  80. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  81. // Adds a dominating control
  82. void AddDominator( const char *pDominatorControl );
  83. // Add a suppressed control
  84. void AddSuppressed( const char *pSuppressedControl );
  85. // Remove all dominatior + suppressed controls
  86. void RemoveAllDominators();
  87. void RemoveAllSuppressed();
  88. // Iteration
  89. int DominatorCount() const;
  90. const char *GetDominator( int i ) const;
  91. int SuppressedCount() const;
  92. const char *GetSuppressed( int i ) const;
  93. // Search
  94. bool HasDominatorControl( const char *pDominatorControl ) const;
  95. bool HasSuppressedControl( const char *pSuppressedControl ) const;
  96. private:
  97. bool HasString( const char *pString, const CDmaStringArray& attr );
  98. CDmaStringArray m_Dominators;
  99. CDmaStringArray m_Suppressed;
  100. };
  101. //-----------------------------------------------------------------------------
  102. // Basic version.. needs channels to copy the data out of its output attributes
  103. //-----------------------------------------------------------------------------
  104. enum CombinationControlType_t
  105. {
  106. COMBO_CONTROL_FIRST = 0,
  107. COMBO_CONTROL_NORMAL = 0,
  108. COMBO_CONTROL_LAGGED,
  109. COMBO_CONTROL_TYPE_COUNT,
  110. };
  111. class CDmeCombinationOperator : public CDmeOperator
  112. {
  113. DEFINE_ELEMENT( CDmeCombinationOperator, CDmeOperator );
  114. public:
  115. // Methods of IDmElement
  116. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  117. virtual void OnElementUnserialized();
  118. // Adds a control, returns the control index. Also adds a raw control with the same name to this control
  119. ControlIndex_t FindOrCreateControl( const char *pControlName, bool bStereo, bool bAutoAddRawControl = false );
  120. // Finds the index of the control with the specified name
  121. ControlIndex_t FindControlIndex( const char *pControlName );
  122. // Changes a control's name
  123. void SetControlName( ControlIndex_t nControl, const char *pControlName );
  124. // Removes a control
  125. void RemoveControl( const char *pControlName );
  126. void RemoveAllControls();
  127. // Adds a remapped control to a input control
  128. void AddRawControl( ControlIndex_t nControl, const char *pRawControlName );
  129. // Removes an remapped control from a control
  130. void RemoveRawControl( ControlIndex_t nControl, const char *pRawControlName );
  131. void RemoveAllRawControls( ControlIndex_t nControl );
  132. // Iterates output controls associated with an input control
  133. int GetRawControlCount( ControlIndex_t nControl ) const;
  134. const char *GetRawControlName( ControlIndex_t nControl, int nIndex ) const;
  135. float GetRawControlWrinkleScale( ControlIndex_t nControl, int nIndex ) const;
  136. float GetRawControlWrinkleScale( ControlIndex_t nControl, const char *pRawControlName ) const;
  137. // Iterates a global list of output controls
  138. int GetRawControlCount( ) const;
  139. const char *GetRawControlName( int nIndex ) const;
  140. float GetRawControlWrinkleScale( int nIndex ) const;
  141. bool IsStereoRawControl( int nIndex ) const;
  142. bool IsEyelidRawControl( int nIndex ) const;
  143. // Gets Input Control Default & Base Values
  144. float GetControlDefaultValue( ControlIndex_t nControl ) const;
  145. float GetControlBaseValue( ControlIndex_t nControl ) const;
  146. // Do we have a raw control?
  147. bool HasRawControl( const char *pRawControlName ) const;
  148. // Sets the wrinkle scale for a particular raw control
  149. void SetWrinkleScale( ControlIndex_t nControlIndex, const char *pRawControlName, float flWrinkleScale );
  150. // Sets the value of a control
  151. void SetControlValue( ControlIndex_t nControlIndex, float flValue, CombinationControlType_t type = COMBO_CONTROL_NORMAL );
  152. // Sets the value of a stereo control
  153. void SetControlValue( ControlIndex_t nControlIndex, float flLeftValue, float flRightValue, CombinationControlType_t type = COMBO_CONTROL_NORMAL );
  154. void SetControlValue( ControlIndex_t nControlIndex, const Vector2D& vec, CombinationControlType_t type = COMBO_CONTROL_NORMAL );
  155. // Returns true if a control is a stereo control
  156. void SetStereoControl( ControlIndex_t nControlIndex, bool bIsStereo );
  157. bool IsStereoControl( ControlIndex_t nControlIndex ) const;
  158. // Sets the level of a control (only used by controls w/ 3 or more remappings)
  159. void SetMultiControlLevel( ControlIndex_t nControlIndex, float flLevel, CombinationControlType_t type = COMBO_CONTROL_NORMAL );
  160. float GetMultiControlLevel( ControlIndex_t nControlIndex, CombinationControlType_t type = COMBO_CONTROL_NORMAL ) const;
  161. // Reordering controls
  162. void MoveControlUp( const char *pControlName );
  163. void MoveControlDown( const char *pControlName );
  164. void MoveControlBefore( const char *pDragControlName, const char *pDropControlName );
  165. void MoveControlAfter( const char *pDragControlName, const char *pDropControlName );
  166. void MoveRawControlUp( ControlIndex_t nControlIndex, const char *pRawControlName );
  167. void MoveRawControlDown( ControlIndex_t nControlIndex, const char *pRawControlName );
  168. // Returns true if a control is a multi control (a control w/ 3 or more remappings)
  169. bool IsMultiControl( ControlIndex_t nControlIndex ) const;
  170. // Returns true if a control is a multi-control which controls eyelids
  171. void SetEyelidControl( ControlIndex_t nControlIndex, bool bIsEyelid );
  172. bool IsEyelidControl( ControlIndex_t nControlIndex ) const;
  173. const char *GetEyesUpDownFlexName( ControlIndex_t nControlIndex ) const;
  174. // Sets the value of a control
  175. float GetControlValue( ControlIndex_t nControlIndex, CombinationControlType_t type = COMBO_CONTROL_NORMAL ) const;
  176. const Vector2D& GetStereoControlValue( ControlIndex_t nControlIndex, CombinationControlType_t type = COMBO_CONTROL_NORMAL ) const;
  177. // Iterates controls
  178. int GetControlCount() const;
  179. const char *GetControlName( ControlIndex_t i ) const;
  180. // Attaches a channel to an input
  181. void AttachChannelToControlValue( ControlIndex_t nControlIndex, CombinationControlType_t type, CDmeChannel *pChannel );
  182. // Adds a domination rule. Domination rules are specified using raw control names
  183. CDmeCombinationDominationRule *AddDominationRule( );
  184. CDmeCombinationDominationRule *AddDominationRule( int nDominatorCount, const char **ppDominatorOutputControlNames, int nSuppressedCount, const char **ppSuppressedOutputControlNames );
  185. CDmeCombinationDominationRule *AddDominationRule( const CUtlVector< const char * > dominators, const CUtlVector< const char * > suppressed );
  186. CDmeCombinationDominationRule *AddDominationRule( CDmeCombinationDominationRule *pSrcRule );
  187. // Removes a domination rule
  188. void RemoveDominationRule( int nIndex );
  189. void RemoveDominationRule( CDmeCombinationDominationRule *pRule );
  190. void RemoveAllDominationRules();
  191. // Iteration
  192. int DominationRuleCount() const;
  193. CDmeCombinationDominationRule *GetDominationRule( int i );
  194. // Rule reordering
  195. void MoveDominationRuleUp( CDmeCombinationDominationRule* pRule );
  196. void MoveDominationRuleDown( CDmeCombinationDominationRule* pRule );
  197. // Indicates we're using lagged control values
  198. void UsingLaggedData( bool bEnable );
  199. bool IsUsingLaggedData() const;
  200. // Adds a target model/arbitrary element to perform the combinations on
  201. // The arbitrary element must have two attributes
  202. // "deltaStates", which is an array of elements
  203. // "deltaStateWeights", which is an array of floats
  204. // In the case of the model, it will look for all shapes in the dag hierarchy
  205. // and attempt to add that shape as a target
  206. // NOTE: Targets are not saved
  207. void AddTarget( CDmeDag *pDag );
  208. void AddTarget( CDmElement *pElement );
  209. void RemoveAllTargets();
  210. // Used by studiomdl to discover the various combination rules
  211. int GetOperationTargetCount() const;
  212. CDmElement *GetOperationTarget( int nTargetIndex );
  213. int GetOperationCount( int nTargetIndex ) const;
  214. CDmElement *GetOperationDeltaState( int nTargetIndex, int nOpIndex );
  215. const CUtlVector< int > &GetOperationControls( int nTargetIndex, int nOpIndex ) const;
  216. int GetOperationDominatorCount( int nTargetIndex, int nOpIndex ) const;
  217. const CUtlVector< int > &GetOperationDominator( int nTargetIndex, int nOpIndex, int nDominatorIndex ) const;
  218. // Does one of the targets we refer to contain a particular delta state?
  219. bool DoesTargetContainDeltaState( const char *pDeltaStateName );
  220. virtual void Operate();
  221. virtual void Resolve();
  222. virtual void GetInputAttributes ( CUtlVector< CDmAttribute * > &attrs );
  223. virtual void GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs );
  224. // Would a particular delta state attached to this combination operator end up stero?
  225. bool IsDeltaStateStereo( const char *pDeltaStateName );
  226. void CopyControls( CDmeCombinationOperator *pSrc );
  227. void GenerateWrinkleDeltas( bool bOverwrite, bool bUseNormalForSign = false, float flScale = 1.0f );
  228. void SetToDefault();
  229. // The base values are different from the default values see CDmeCombinationInputControl
  230. void SetToBase();
  231. // Remove all controls and domination rules which are not referring to anything
  232. void Purge();
  233. protected:
  234. void ComputeCombinationInfo( int nIndex );
  235. private:
  236. typedef int RawControlIndex_t;
  237. struct DominatorInfo_t
  238. {
  239. CUtlVector< RawControlIndex_t > m_DominantIndices;
  240. CUtlVector< RawControlIndex_t > m_SuppressedIndices;
  241. };
  242. struct CombinationOperation_t
  243. {
  244. int m_nDeltaStateIndex;
  245. CUtlVector< RawControlIndex_t > m_ControlIndices;
  246. CUtlVector< RawControlIndex_t > m_DominatorIndices;
  247. };
  248. struct CombinationInfo_t
  249. {
  250. DmAttributeHandle_t m_hDestAttribute[COMBO_CONTROL_TYPE_COUNT];
  251. CUtlVector< CombinationOperation_t > m_Outputs;
  252. };
  253. struct RawControlInfo_t
  254. {
  255. CUtlString m_Name;
  256. bool m_bIsDefaultControl;
  257. ControlIndex_t m_InputControl;
  258. float m_flWrinkleScale;
  259. bool m_bLowerEyelid;
  260. Vector4D m_FilterRamp; // [0] = point at which ramp starts going up
  261. // [1] = point at which ramp hits 1.0
  262. // [2] = point at which ramp stops holding at 1.0
  263. // [3] = point at which ramp starts going down
  264. };
  265. void ComputeCombinationInfo();
  266. void CleanUpCombinationInfo( int nIndex );
  267. void CleanUpCombinationInfo();
  268. // Is a particular remapped control stereo?
  269. bool IsRawControlStereo( const char *pRawControlName );
  270. // Determines the weighting of input controls based on the deltaState name
  271. int FindDeltaStateIndex( CDmAttribute *pDeltaArray, const char *pDeltaStateName );
  272. // Determines which combination to use based on the deltaState name
  273. int ParseDeltaName( const char *pDeltaStateName, int *pControlIndices );
  274. // Finds dominators
  275. void FindDominators( CombinationOperation_t& op );
  276. // Computes lists of dominators and suppressors
  277. void RebuildDominatorInfo();
  278. // Computes list of all remapped controls
  279. void RebuildRawControlList();
  280. // Remaps non-stereo -> stereo, stereo ->left/right
  281. void ComputeInternalControlValue( RawControlIndex_t nRawControlIndex, CombinationControlType_t type, Vector2D &value );
  282. // Computes lagged input values from non-lagged input
  283. void ComputeLaggedInputValues();
  284. // Finds the index of the remapped control with the specified name
  285. RawControlIndex_t FindRawControlIndex( const char *pControlName, bool bIgnoreDefaultControls = false ) const;
  286. // Updates the default value associated with a control
  287. void UpdateDefaultValue( ControlIndex_t nControlIndex );
  288. // Finds a domination rule
  289. int FindDominationRule( CDmeCombinationDominationRule *pRule );
  290. // Generates wrinkle deltas for a dag hierarchy
  291. void GenerateWrinkleDeltas( CDmeShape *pShape, bool bOverwrite, bool bUseNormalForSign, float flScale = 1.0f );
  292. CDmaElementArray< CDmeCombinationInputControl > m_InputControls;
  293. CDmaArray< Vector > m_ControlValues[COMBO_CONTROL_TYPE_COUNT];
  294. CDmaVar< bool > m_bSpecifyingLaggedData;
  295. CDmaElementArray< CDmeCombinationDominationRule > m_Dominators;
  296. CDmaElementArray< CDmElement > m_Targets;
  297. CUtlVector< bool > m_IsDefaultValue; // one per control value
  298. CUtlVector< RawControlInfo_t > m_RawControlInfo;
  299. CUtlVector< CombinationInfo_t > m_CombinationInfo;
  300. CUtlVector< DominatorInfo_t > m_DominatorInfo;
  301. float m_flLastLaggedComputationTime;
  302. };
  303. //-----------------------------------------------------------------------------
  304. // Indicates we're using lagged control values
  305. //-----------------------------------------------------------------------------
  306. inline void CDmeCombinationOperator::UsingLaggedData( bool bEnable )
  307. {
  308. m_bSpecifyingLaggedData = bEnable;
  309. }
  310. inline bool CDmeCombinationOperator::IsUsingLaggedData() const
  311. {
  312. return m_bSpecifyingLaggedData;
  313. }
  314. //-----------------------------------------------------------------------------
  315. // Helper method to create a lagged version of channel data from source data
  316. //-----------------------------------------------------------------------------
  317. void CreateLaggedVertexAnimation( CDmeChannelsClip *pClip, int nSamplesPerSec );
  318. //-----------------------------------------------------------------------------
  319. //
  320. // A class used to edit combination operators in Maya.. doesn't connect to targets
  321. //
  322. //-----------------------------------------------------------------------------
  323. class CDmeMayaCombinationOperator : public CDmeCombinationOperator
  324. {
  325. DEFINE_ELEMENT( CDmeMayaCombinationOperator, CDmeCombinationOperator );
  326. public:
  327. void AddDeltaState( const char *pDeltaStateName );
  328. void RemoveDeltaState( const char *pDeltaStateName );
  329. void RemoveAllDeltaStates();
  330. int FindDeltaState( const char *pDeltaStateName );
  331. int DeltaStateCount() const;
  332. const char *GetDeltaState( int nIndex ) const;
  333. const Vector2D& GetDeltaStateWeight( int nIndex, CombinationControlType_t type ) const;
  334. private:
  335. CDmaElementArray< CDmElement > m_DeltaStates;
  336. CDmaArray< Vector2D > m_DeltaStateWeights[COMBO_CONTROL_TYPE_COUNT];
  337. };
  338. #endif // DMECOMBINATIONOPERATOR_H