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.

222 lines
13 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Declaration of CDmAnimUtils a set of animation related utilities
  4. // which work on DmeDag and other DmElement derived objects.
  5. //
  6. //=============================================================================
  7. #ifndef DMANIMUTILS_H
  8. #define DMANIMUTILS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "movieobjects/dmerigconstraintoperators.h"
  13. #include "movieobjects/dmechannel.h"
  14. class CDmeGameModel;
  15. enum TransformSpace_t
  16. {
  17. TS_WORLD_SPACE,
  18. TS_LOCAL_SPACE,
  19. TS_OBJECT_SPACE,
  20. TS_REFERENCE_SPACE,
  21. };
  22. enum ReParentLogMode_t
  23. {
  24. REPARENT_LOGS_NONE, // Do not touch logs
  25. REPARENT_LOGS_OVERWRITE, // Overwrite the logs with new local transform of the dag
  26. REPARENT_LOGS_OFFSET_LOCAL, // Apply the transform required to maintain the world space transform of the dag to all log samples
  27. REPARENT_LOGS_MAINTAIN_WORLD, // Modify the logs so that the world space position and orientation animation is maintained
  28. };
  29. //-----------------------------------------------------------------------------
  30. // CDmeDagPtr - For swig generation this is an actual class with a single
  31. // member which is a pointer to dag, for normal c++ code it is just a typedef
  32. // of a pointer to a CDmeDag* , this is required because swig has issues
  33. // generating code for CUtlVector< CDmeDag * > as there are functions within
  34. // CUtlVector which use the paremter of T & wich with T = CDmeDag * results in
  35. // CDmeDag *&, and when swig generates code to parse this type coming from python
  36. // it considers a pointer to a pointer, when infact it is still just a pointer.
  37. // So we tell swig that CDmeDagPtr is a class to avoid this issue, but treat it
  38. // as typedef in code. This works since both are exactly 4 bytes containing the
  39. // address of the CDmeDag instance.
  40. //-----------------------------------------------------------------------------
  41. #ifdef SWIG
  42. class CDmeDagPtr
  43. {
  44. public:
  45. CDmeDagPtr() { m_pDag = NULL; }
  46. CDmeDagPtr( CDmeDag *pDag ) { m_pDag = pDag; }
  47. private:
  48. CDmeDag *m_pDag;
  49. };
  50. #else
  51. typedef CDmeDag* CDmeDagPtr;
  52. #endif
  53. //-----------------------------------------------------------------------------
  54. // CDmeAnimUtils - A collection of utility functions which perform animation
  55. // related operations on data model elements. This class is wrapped by swig so
  56. // that the functions are accessible from python, but the functions are
  57. // designed to be used directly as well.
  58. //-----------------------------------------------------------------------------
  59. class CDmAnimUtils
  60. {
  61. public:
  62. // Create an infinite time selection
  63. static CDmeTimeSelection *CreateInfiniteTimeSelection();
  64. // Create an absolute time selection with the specified key times
  65. static CDmeTimeSelection *CreateTimeSelection( DmeTime_t leftFalloff, DmeTime_t leftHold, DmeTime_t rightHold, DmeTime_t rightFalloff );
  66. // Create a dag with the specified name, position and orientation
  67. static CDmeDag *CreateDag( const char *pchName, const Vector &position, const Quaternion &orientation, CDmeDag *pParent = NULL );
  68. // Get the average position of the provided dag nodes in the specified space
  69. static Vector GetDagPosition( const CUtlVector< CDmeDagPtr > &dagList, TransformSpace_t space, const CDmeDag *pReference = NULL );
  70. // Get the average Euler rotation of the provided dag nodes in the specified space
  71. static Vector GetDagRotation( const CUtlVector< CDmeDagPtr > &dagList, TransformSpace_t space, const CDmeDag *pReference = NULL );
  72. // Get the average orientation (quaternion) of the provided dag nodes in the specified space
  73. static Quaternion GetDagOrientation( const CUtlVector< CDmeDagPtr > &dagList, TransformSpace_t space, const CDmeDag *pReference = NULL );
  74. // Get the average position and orientation of the provided dag nodes in the specified space
  75. static void GetDagPositionOrienation( Vector &position, Quaternion &orienation, const CUtlVector< CDmeDagPtr > &dagList, TransformSpace_t space, const CDmeDag *pReferenceDag = NULL );
  76. // Move the provided dag nodes in the specified space
  77. static void MoveDagNodes( const Vector &offset, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, TransformSpace_t space, CDmeDag *pReference = NULL );
  78. // Move the provided dag nodes in the specified space and apply the operation to the logs associated with the dag
  79. static void MoveDagNodes( const Vector &offset, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, const CDmeTimeSelection *pTimeSelection, bool bOffsetOverTime, TransformSpace_t space, CDmeDag *pReference = NULL );
  80. // Rotate the provided dag nodes in the specified space
  81. static void RotateDagNodes( const Vector &rotation, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, TransformSpace_t space, CDmeDag *pReference = NULL );
  82. // Rotate the provided dag nodes in the specified space and apply the operation to the logs associated with the dag
  83. static void RotateDagNodes( const Vector &rotation, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, const CDmeTimeSelection *pTimeSelection, bool bOffsetOverTime, TransformSpace_t space, CDmeDag* pReference = NULL );
  84. // Perform both a translation and a rotation of the specified dag nodes
  85. static void TransformDagNodes( const Vector &offset, const Quaternion &rotation, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, TransformSpace_t space, CDmeDag* pReferenceDag = NULL, bool bPosition = true, bool bRotation = true );
  86. // Perform both a translation and a rotation of the specified dag nodes and apply the operation to the logs associated with the dag
  87. static void TransformDagNodes( const Vector &offset, const Quaternion &rotation, const CUtlVector< CDmeDagPtr > &dagList, bool bRelative, const CDmeTimeSelection *pTimeSelection, bool bOffsetOverTime, TransformSpace_t space, CDmeDag* pReferenceDag = NULL, bool bPosition = true, bool bRotation = true );
  88. // Set the current position and orientation as the defaults for the specified dag nodes.
  89. static void SetDagTransformDefaults( const CUtlVector< CDmeDagPtr > &dagList, bool bPosition, bool bOrientation );
  90. // Set the controls associated with the specified dag nodes to the reference pose position and orientation
  91. static void SetReferencePose( CDmeGameModel *pGameModel, const CUtlVector< CDmeDag* > &dagList );
  92. // Re-parent the specified dag node from its current parent to the specified dag node.
  93. static void ReParentDagNode( CDmeDag *pDagNode, CDmeDag *pNewParent, bool bMaintainWorldPos, ReParentLogMode_t logMode );
  94. // Set the temporary override parent of a dag, maintaining its world space position and orientation animation
  95. static void SetOverrideParent( CDmeDag *pDagNode, const CDmeDag *pOverrideParent, bool bPosition, bool bRotation );
  96. // Enable or disable the override parent functionality on a dag, if different than the current state the logs will be udpdated such the dag world space position and orientation are maintained.
  97. static void ToggleOverrideParent( CDmeDag *pDagNode, bool bEnable );
  98. // Determine if the specified dag node has any constraints
  99. static bool DagHasConstraints( CDmeDag *pDag );
  100. // Remove all of the constraints from the specified dag
  101. static void RemoveConstraints( CDmeDag *pDag );
  102. // Update the logs of the dag so the the current local transform is the only value in the log
  103. static void SetLogsToCurrentTransform( CDmeDag *pDag );
  104. // Generate log samples for the specified dag node, if a parent is provided, generate the samples in the space of that parent, otherwise generate the samples in world space.
  105. static void GenerateLogSamples( CDmeDag* pDag, CDmeDag *pParent, bool bPosition, bool bOrientation, const DmeLog_TimeSelection_t *pTimeSelection = NULL );
  106. // Find and operate all of the channels driving the specified dag nodes
  107. static void OperateDagChannels( const CUtlVector< CDmeDag* > &dagList, ChannelMode_t mode, const DmeLog_TimeSelection_t &timeSelection, CDmeClip *pShot = NULL, CDmeClip *pMovie = NULL );
  108. // Create a constraint of the specified type
  109. static CDmeRigBaseConstraintOperator *CreateConstraint( const char *pchName, EConstraintType constraintType, CDmeDag *pConstrainedDag, const CUtlVector< CDmeDagPtr > &targetDagList, bool bPreserveOffset, float flWeight, bool bOperate );
  110. // Create a Point constraint which will control the position of the specified dag such that it matches the weighted target position
  111. static CDmeRigPointConstraintOperator* CreatePointConstraint( char const *pchName, CDmeDag *pConstrainedDag, const CUtlVector< CDmeDagPtr > &targetDagList, bool bPreserveOffset, float flWeight );
  112. // Create a Orient constraint which will control the orientation of the specified dag such that it matches the weighted target orientation
  113. static CDmeRigOrientConstraintOperator* CreateOrientConstraint( char const *pchName, CDmeDag *pConstrainedDag, const CUtlVector< CDmeDagPtr > &targetDagList, bool bPreserveOffset, float flWeight );
  114. // Create a Parent constraint which will control the position and orientation of the specified dag such the dag behaves as if it is a child of the transform defined by the weighted target list
  115. static CDmeRigParentConstraintOperator* CreateParentConstraint( char const *pchName, CDmeDag *pConstrainedDag, const CUtlVector< CDmeDagPtr > &targetDagList, bool bPreserveOffset, float flWeight );
  116. // Create an Aim constraint which will control the orientation of the specified dag such that it points toward the weighted target position
  117. static CDmeRigAimConstraintOperator* CreateAimConstraint( char const *pchName, CDmeDag *pConstrainedDag, const CUtlVector< CDmeDagPtr > &targetDagList, bool bPreserveOffset, float flWeight, const Vector &upVector, TransformSpace_t upSpace, const CDmeDag* pReferenceDag = NULL );
  118. // Create an IK constraint controlling the 2 bone chain from the specified root dag to the specified end dag
  119. static CDmeRigIKConstraintOperator* CreateIKConstraint( const char *pchName, CDmeDag *pChainRootDag, CDmeDag *pChainEndDag, CDmeDag *pTargetDag, bool bPreserveOffset, const Vector &poleVector, CDmeDag *pPoleVectorTarget = NULL );
  120. // Print the position and orientation of the dag over time for debugging purposes
  121. static void PrintDagTransformOverTime( CDmeDag* pDag, CDmeClip *pShot = NULL, CDmeClip *pMovie = NULL );
  122. private:
  123. // Find the constraint of the specified type controlling the specified dag node
  124. static CDmeRigBaseConstraintOperator *FindConstraintOnDag( CDmeDag* pDag, EConstraintType constraintType );
  125. // Allocate an constraint of the specified type.
  126. static CDmeRigBaseConstraintOperator *InstanceConstraint( char const *pchName, EConstraintType eType, const DmFileId_t &fileId );
  127. // Find the position or orientation channel for the specified dag node
  128. static CDmeChannel *FindDagTransformChannel( CDmeDag *pDag, const char *pchAttributeName );
  129. // Create the position and orientation channels for the specified dag node if they do not already exist.
  130. static void CreateTransformChannelsForDag( CDmeDag *pDag, CDmeChannelsClip *pChannelsClip, bool bPosition, bool bOrientation, CDmeChannel *&pPositionChannel, CDmeChannel *&pOrientationChannel );
  131. // Generate a list of all of the world space transform of the specified dag node at each time in the provided list
  132. static void GenerateDagWorldTransformList( CDmeDag *pDag, const CUtlVector< DmeTime_t > &times, CUtlVector< matrix3x4_t > &transformList, CDmeClip *pShot, CDmeClip *pMovie );
  133. // Update the position and orientation logs of the specified dag node so that the dag node's world space transform matches the provided list
  134. static void SetDagWorldSpaceTransforms( CDmeDag* pDag, CUtlVector< DmeTime_t > &times, const CUtlVector< matrix3x4_t > &transformList, CDmeClip *pShot, CDmeClip *pMovie );
  135. // Create a list of all of the key times in the provided list of channels
  136. static void CompileKeyTimeList( const CUtlVector< CDmeOperator* > &channelList, CUtlVector< DmeTime_t > &times, const DmeLog_TimeSelection_t *pTimeSelection, CDmeClip *pShot, CDmeClip *pMovie );
  137. // Find the position and orientation controls for the specified dag node
  138. static CDmeTransformControl *GetTransformControl( const CDmeDag *pDag );
  139. // Get the local space default transform for the specified dag node
  140. static void GetDefaultTransform( CDmeDag *pDagNode, matrix3x4_t &defaultTransform );
  141. // Get the world space default transform for the specified dag node
  142. static void GetDefaultAbsTransform( CDmeDag *pDagNode, matrix3x4_t &absDefaultTransform );
  143. // Update the default values for the position and orientation controls of the specified dag so they maintain their world space position
  144. static void UpdateDefaultsForNewParent( CDmeDag *pDagNode, CDmeDag *pParentDag );
  145. // Get all of the channels directly driving the specified dag nodes
  146. static void GetChannelsForDags( const CUtlVector< CDmeDag* > &dagList, CUtlVector< CDmeChannel* > &channelList );
  147. // Operate all of the provided channels.
  148. static void OperateChannels( const CUtlVector< CDmeChannel* > &channelList, const DmeLog_TimeSelection_t &timeSelection, CDmeClip *pShot, CDmeClip *pMovie );
  149. // Operate all of the provided channels in the specified mode.
  150. static void RecordChannels( const CUtlVector< CDmeChannel* > &channelList, const DmeLog_TimeSelection_t &timeSelection, CDmeClip *pShot, CDmeClip *pMovie );
  151. // Find the shot and the movie to which the specified dag node belongs
  152. static void FindShotAndMovieForDag( const CDmeDag *pDag, CDmeClip *&pShot, CDmeClip *&pMovie );
  153. };
  154. #endif // DMANIMUTILS_H