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.

231 lines
9.8 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // NOTE: This is a cut-and-paste hack job to get animation set construction
  4. // working from a commandline tool. It came from tools/ifm/createsfmanimation.cpp
  5. // This file needs to die almost immediately + be replaced with a better solution
  6. // that can be used both by the sfm + sfmgen.
  7. //
  8. //=============================================================================
  9. #ifndef SFMANIMATIONSETUTILS_H
  10. #define SFMANIMATIONSETUTILS_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier1/UtlVector.h"
  15. #include "tier1/UtlDict.h"
  16. #include "tier1/UtlString.h"
  17. #include "datamodel/dmattributevar.h"
  18. #include "dme_controls/BaseAnimationSetEditorController.h"
  19. //-----------------------------------------------------------------------------
  20. // movieobjects
  21. //-----------------------------------------------------------------------------
  22. class CDmeCamera;
  23. class CDmeFilmClip;
  24. class CDmeGameModel;
  25. class CDmeAnimationSet;
  26. class CDmeGameModel;
  27. class CDmeProjectedLight;
  28. class CDmePresetGroup;
  29. class CDmeChannelsClip;
  30. class CDmeTransform;
  31. class CDmeChannel;
  32. class CDmeLog;
  33. class CStudioHdr;
  34. extern const char *g_pSuffix[];
  35. extern DmAttributeType_t g_ChannelTypes[];
  36. enum ControlType_t
  37. {
  38. CONTROL_TYPE_POSITION = 0,
  39. CONTROL_TYPE_ORIENTATION = 1,
  40. };
  41. enum LogPreviewChannelType_t
  42. {
  43. LOG_PREVIEW_VALUE = 0,
  44. LOG_PREVIEW_VALUE_RIGHT,
  45. LOG_PREVIEW_VALUE_LEFT,
  46. LOG_PREVIEW_FLEX_CHANNEL_COUNT,
  47. LOG_PREVIEW_POSITION = 0,
  48. LOG_PREVIEW_ORIENTATION,
  49. LOG_PREVIEW_TRANSFORM_CHANNEL_COUNT,
  50. LOG_PREVIEW_MAX_CHANNEL_COUNT = LOG_PREVIEW_FLEX_CHANNEL_COUNT,
  51. };
  52. struct LogPreview_t;
  53. struct Context_t
  54. {
  55. DECLARE_FIXEDSIZE_ALLOCATOR( Context_t );
  56. public:
  57. Context_t() :
  58. m_bHighlight( false ),
  59. m_bValid( false ),
  60. m_bHasAncestorsBeingManipulated( false )
  61. {
  62. SetIdentityMatrix( m_InitialBoneToWorld );
  63. SetIdentityMatrix( m_InitialWorldToBone );
  64. SetIdentityMatrix( m_InitialBoneMatrix );
  65. m_CurrentWorldPosition.Init();
  66. SetIdentityMatrix( m_InitialTranslationWorldToParent );
  67. }
  68. void InitContext( const LogPreview_t *lp );
  69. void UpdatePosition( bool bInitialAndCurrent );
  70. // from TxForm_t
  71. CUtlString m_basename;
  72. bool m_bHighlight : 1;
  73. bool m_bValid : 1;
  74. bool m_bHasAncestorsBeingManipulated : 1;
  75. CDmeHandle< CDmeDag > m_hDrag;
  76. // those originally used by DragContextList
  77. matrix3x4_t m_InitialBoneToWorld;
  78. matrix3x4_t m_InitialWorldToBone;
  79. matrix3x4_t m_InitialBoneMatrix;
  80. // those originally used by FullTransformList
  81. Vector m_CurrentWorldPosition;
  82. matrix3x4_t m_InitialTranslationWorldToParent;
  83. };
  84. struct LogPreview_t : public SelectionInfo_t
  85. {
  86. DECLARE_FIXEDSIZE_ALLOCATOR( LogPreview_t );
  87. public:
  88. LogPreview_t() : SelectionInfo_t(), m_pTransformContext( NULL ) {}
  89. LogPreview_t( CDmeAnimationSet *pAnimSet, CDmElement *pControl, TransformComponent_t nComponentFlags );
  90. bool IsEqual( const LogPreview_t& other ) const
  91. {
  92. if ( m_hControl != other.m_hControl )
  93. return false;
  94. for ( int i = 0; i < LOG_PREVIEW_MAX_CHANNEL_COUNT; ++i )
  95. {
  96. if ( m_hChannels[ i ] != other.m_hChannels[ i ] )
  97. return false;
  98. }
  99. if ( m_hOwner != other.m_hOwner )
  100. return false;
  101. if ( m_nComponentFlags != other.m_nComponentFlags )
  102. return false;
  103. return true;
  104. }
  105. bool operator==( const LogPreview_t& other ) const
  106. {
  107. return IsEqual( other );
  108. }
  109. LogComponents_t GetLogComponentFlagsForChannel( int nChannel )
  110. {
  111. // If the control is a transform control convert the flags from transform component flags to log component flags
  112. if ( m_pTransformContext )
  113. {
  114. return ConvertTransformFlagsToLogFlags( m_nComponentFlags, ( nChannel == LOG_PREVIEW_ORIENTATION ) );
  115. }
  116. // For all other controls consider all components selected
  117. return LOG_COMPONENTS_ALL;
  118. }
  119. CDmeChannel *GetSelectedChannel( int nChannel )
  120. {
  121. if ( nChannel >= LOG_PREVIEW_MAX_CHANNEL_COUNT )
  122. return NULL;
  123. // If the control is a transform control check the flags to determine if the specific channel is selected
  124. if ( m_pTransformContext )
  125. {
  126. if ( ( nChannel == LOG_PREVIEW_POSITION ) && ( ( m_nComponentFlags & TRANSFORM_COMPONENT_POSITION ) == 0 ) )
  127. return NULL;
  128. if ( ( nChannel == LOG_PREVIEW_ORIENTATION ) && ( ( m_nComponentFlags & TRANSFORM_COMPONENT_ROTATION ) == 0 ) )
  129. return NULL;
  130. }
  131. return m_hChannels[ nChannel ];
  132. }
  133. CDmeHandle< CDmeChannel > m_hChannels[ LOG_PREVIEW_MAX_CHANNEL_COUNT ];
  134. CDmeHandle< CDmeChannelsClip > m_hOwner;
  135. Context_t *m_pTransformContext;
  136. };
  137. struct MDLSquenceLayer_t;
  138. //-----------------------------------------------------------------------------
  139. // Creates an animation set
  140. //-----------------------------------------------------------------------------
  141. CDmeAnimationSet *CreateEmptyAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeChannelsClip **ppChannelsClip = NULL, CDmeControlGroup**ppControlGroup = NULL );
  142. CDmeAnimationSet *CreateAnimationSetForDag( CDmeFilmClip *pClip, const char *pSetName, CDmeDag *pDag );
  143. CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeCamera *pCamera );
  144. CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pClip, const char *pSetName, CDmeProjectedLight *pLight );
  145. CDmeAnimationSet *CreateAnimationSet( CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CDmeGameModel *pGameModel, const char *pAnimationSetName, bool bAttachToGameRecording, CDmElement *pSharedPresetGroupSettings );
  146. CDmeGameModel *CreateGameModel( CDmeFilmClip *pShot, const char *pRelativeName );
  147. // building blocks for creating animationsets (don't contain undo scopes)
  148. void AddFloatControlToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmAttribute *pSrcAttr, float flMin = 0.0f, float flMax = 1.0f, float flDefault = -FLT_MAX );
  149. void AddColorControlToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmAttribute *pSrcAttr );
  150. void AddTransformControlsToAnimationSet( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeChannelsClip *pDstChannelsClip, CDmeControlGroup *pControlGroup, CDmeTransform *pTransform, const char *pControlName );
  151. void AddLocalViewTargetControl( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
  152. void AddEyeConvergenceControl( CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
  153. void AddViewTargetControl( CDmeFilmClip *pFilmClip, CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, CDmeChannelsClip *pChannelsClip );
  154. void AddIllumPositionAttribute( CDmeGameModel *pGameModel );
  155. void BuildGroupMappings( CDmeAnimationSet *pAnimationSet );
  156. CDmeTrack *GetAnimationSetTrack( CDmeFilmClip *pFilmClip, bool bCreateIfMissing );
  157. CDmeChannelsClip* CreateChannelsClip( CDmeAnimationSet *pAnimationSet, CDmeFilmClip *pOwnerClip );
  158. CDmeChannelsClip *FindChannelsClip( CDmeDag *pDag );
  159. CDmeChannelsClip *FindChannelsClip( CDmeAnimationSet *pAnimSet );
  160. CDmeDag *GetAnimSetTargetDag( CDmeAnimationSet *pAnimSet );
  161. CDmeChannel *FindChannelTargetingTransform( CDmeChannelsClip *pChannelsClip, CDmeTransform *pTransform, ControlType_t controlType );
  162. void CreateTransformChannels( CDmeTransform *pTransform, const char *pBaseName, CDmeChannelsClip *pChannelsClip );
  163. void CreateAnimationLogs( CDmeChannelsClip *channelsClip, CDmeGameModel *pModel, const CStudioHdr &hdr, int sequence, float flStartTime, float flDuration, float flTimeStep );
  164. void ImportAnimationLogs( CUtlVector< KeyValues* > &importData, DmeTime_t &duration, DmeTime_t startTime, DmeFramerate_t framerate, CDmeFilmClip *pMovie, CDmeFilmClip *pShot, CUtlLinkedList< LogPreview_t* > &controls, CDmeGameModel *pModel, int sequence, const CUtlVector< float > *pPoseParameters = NULL, const CUtlVector< MDLSquenceLayer_t > *pLayers = NULL, bool bRootMotion = true );
  165. void DestroyLayerData( CUtlVector< KeyValues* > &layerData );
  166. void RetimeLogData( CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeLog *pLog );
  167. void TransferRemainingChannels( CDmeFilmClip *shot, CDmeChannelsClip *destClip, CDmeChannelsClip *srcClip );
  168. template < class T >
  169. CDmeChannel *CreateConstantValuedLog( CDmeChannelsClip *channelsClip, const char *pName, CDmElement *pToElement, const char *pToAttr, const T &value );
  170. CDmeTransformControl *CreateTransformControlAndChannels( const char *pName, CDmeTransform *pTransform, CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeAnimationSet *pAnimationSet, bool bUseExistingLogData );
  171. void SetupBoneTransform( CDmeChannelsClip *pSrcChannelsClip, CDmeChannelsClip *pDstChannelsClip, CDmeAnimationSet *pAnimationSet, CDmeGameModel *pGameModel, const CStudioHdr &hdr, int bonenum, bool bUseExistingLogData );
  172. // Finds a channel in the animation set to overwrite with import data
  173. CDmeChannel* FindImportChannel( CDmeChannel *pChannel, CDmeChannelsClip *pChannelsClip );
  174. // Transforms an imported channel, if necessary
  175. void TransformBoneChannel( CDmeChannel *pChannel, bool bImport );
  176. bool ImportChannel( CDmeChannel *pChannel, CDmeChannelsClip *pChannelsClip );
  177. void GetChannelsForControl( const CDmElement *control, CDmeChannel *channels[LOG_PREVIEW_MAX_CHANNEL_COUNT] );
  178. void GetChannelsForControl( const CDmElement *pControl, CUtlVector< CDmeChannel* > &channels );
  179. void GetControlChannelsForAnimSet( CDmeAnimationSet *pAnimSet, CUtlVector< CDmeChannel* > &channels );
  180. void ImportAnimation( CDmeChannelsClip *pImportedChannelsClip, CDmeAnimationSet *pAnimSet, int *pNumMatchingChannels, int *pNumMissingChannels, int *pNumSkippedChannels );
  181. #endif // SFMANIMATIONSETUTILS_H