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.

667 lines
23 KiB

  1. //====== Copyright � 1996-2009, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Implementation of the CDmeRig class, a class which groups a set of
  4. // associated constraints and operators together, allowing operations to be
  5. // performed on the group of elements. Also contains the implementation of
  6. // CDmeRigAnimSetElements, a helper class used to store a list of elements which
  7. // are all associated with a single animation set.
  8. //
  9. //=============================================================================
  10. #include "movieobjects/dmerig.h"
  11. #include "movieobjects/dmeanimationset.h"
  12. #include "movieobjects/dmeoperator.h"
  13. #include "movieobjects/dmeclip.h"
  14. #include "movieobjects/dmetrackgroup.h"
  15. #include "movieobjects/dmetrack.h"
  16. #include "movieobjects/dmerigconstraintoperators.h"
  17. #include "movieobjects/dmetransformcontrol.h"
  18. #include "movieobjects/dmechannel.h"
  19. #include "datamodel/dmelementfactoryhelper.h"
  20. #include "tier1/fmtstr.h"
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include "tier0/memdbgon.h"
  23. // Expose this the classes to the scene database
  24. IMPLEMENT_ELEMENT_FACTORY( DmeRigAnimSetElements, CDmeRigAnimSetElements );
  25. IMPLEMENT_ELEMENT_FACTORY( DmeRig, CDmeRig );
  26. //-------------------------------------------------------------------------------------------------
  27. // Purpose: Provide post construction processing.
  28. //-------------------------------------------------------------------------------------------------
  29. void CDmeRigAnimSetElements::OnConstruction()
  30. {
  31. m_AnimationSet.Init( this, "animationSet" );
  32. m_ElementList.Init( this, "elementList" );
  33. m_HiddenGroups.Init( this, "hiddenGroups" );
  34. }
  35. //-------------------------------------------------------------------------------------------------
  36. // Purpose: Provide processing and cleanup before shutdown
  37. //-------------------------------------------------------------------------------------------------
  38. void CDmeRigAnimSetElements::OnDestruction()
  39. {
  40. }
  41. //-------------------------------------------------------------------------------------------------
  42. // Purpose: Set the animation set elements in the list are to be associated with, only allowed
  43. // when the element list is empty.
  44. //-------------------------------------------------------------------------------------------------
  45. void CDmeRigAnimSetElements::SetAnimationSet( CDmeAnimationSet* pAnimationSet )
  46. {
  47. // The element list must be empty when the animation set is assigned.
  48. Assert( m_ElementList.Count() == 0 );
  49. if ( m_ElementList.Count() == 0 )
  50. {
  51. m_AnimationSet = pAnimationSet;
  52. }
  53. }
  54. //-------------------------------------------------------------------------------------------------
  55. // Purpose: Add an element to the list
  56. //-------------------------------------------------------------------------------------------------
  57. void CDmeRigAnimSetElements::AddElement( CDmElement *pElement )
  58. {
  59. if ( pElement == NULL )
  60. return;
  61. m_ElementList.AddToTail( pElement );
  62. }
  63. //-------------------------------------------------------------------------------------------------
  64. // Purpose: Remove the specified element from the list. Returns true if the element is found and
  65. // removed, return false if the element could not be found.
  66. //-------------------------------------------------------------------------------------------------
  67. bool CDmeRigAnimSetElements::RemoveElement( CDmElement *pElement )
  68. {
  69. int index = m_ElementList.Find( pElement );
  70. if ( index != m_ElementList.InvalidIndex() )
  71. {
  72. m_ElementList.Remove( index );
  73. return true;
  74. }
  75. return false;
  76. }
  77. //-------------------------------------------------------------------------------------------------
  78. // Purpose: Remove all of the elements from the list
  79. //-------------------------------------------------------------------------------------------------
  80. void CDmeRigAnimSetElements::RemoveAll()
  81. {
  82. m_ElementList.RemoveAll();
  83. }
  84. //-------------------------------------------------------------------------------------------------
  85. // Purpose: Add all of the elements to the provided array
  86. //-------------------------------------------------------------------------------------------------
  87. void CDmeRigAnimSetElements::GetElements( CUtlVector< CDmElement* > &elementList ) const
  88. {
  89. int nElements = m_ElementList.Count();
  90. for ( int iElement = 0; iElement < nElements; ++iElement )
  91. {
  92. CDmElement *pElement = m_ElementList[ iElement ];
  93. if ( pElement )
  94. {
  95. elementList.AddToTail( pElement );
  96. }
  97. }
  98. }
  99. //-------------------------------------------------------------------------------------------------
  100. // Add a control group to the list of hidden control groups
  101. //-------------------------------------------------------------------------------------------------
  102. void CDmeRigAnimSetElements::AddHiddenControlGroup( CDmeControlGroup *pControlGroup )
  103. {
  104. m_HiddenGroups.AddToTail( pControlGroup->GetName() );
  105. }
  106. //-------------------------------------------------------------------------------------------------
  107. // Purpose: Provide post construction processing.
  108. //-------------------------------------------------------------------------------------------------
  109. void CDmeRig::OnConstruction()
  110. {
  111. m_AnimSetList.Init( this, "animSetList" );
  112. }
  113. //-------------------------------------------------------------------------------------------------
  114. // Purpose: Provide processing and cleanup before shutdown
  115. //-------------------------------------------------------------------------------------------------
  116. void CDmeRig::OnDestruction()
  117. {
  118. }
  119. //-------------------------------------------------------------------------------------------------
  120. // Purpose: Add an element to the rig
  121. //-------------------------------------------------------------------------------------------------
  122. void CDmeRig::AddElement( CDmElement* pElement, CDmeAnimationSet *pAnimationSet )
  123. {
  124. if ( ( pElement == NULL ) || ( pAnimationSet == NULL ) )
  125. return;
  126. // Search for an element set with the specified
  127. // animation set, if none is found, create one.
  128. CDmeRigAnimSetElements *pAnimSetElementList = FindOrCreateAnimSetElementList( pAnimationSet );
  129. if ( pAnimSetElementList )
  130. {
  131. pAnimSetElementList->AddElement( pElement );
  132. }
  133. }
  134. //-------------------------------------------------------------------------------------------------
  135. // Set the state of the specified control group and add it to list of control group modified by
  136. // the rig
  137. //-------------------------------------------------------------------------------------------------
  138. void CDmeRig::HideControlGroup( CDmeControlGroup *pGroup )
  139. {
  140. if ( pGroup == NULL )
  141. return;
  142. CDmeAnimationSet *pAnimationSet = pGroup->FindAnimationSet( true );
  143. if ( pAnimationSet == NULL )
  144. return;
  145. CDmeRigAnimSetElements *pAnimSetElementList = FindOrCreateAnimSetElementList( pAnimationSet );
  146. if ( pAnimSetElementList)
  147. {
  148. pGroup->SetVisible( false );
  149. pAnimSetElementList->AddHiddenControlGroup( pGroup );
  150. }
  151. }
  152. //-------------------------------------------------------------------------------------------------
  153. // Purpose: Remove an element from the rig
  154. //-------------------------------------------------------------------------------------------------
  155. void CDmeRig::RemoveElement( CDmElement *pElement, CDmeAnimationSet *pAnimationSet )
  156. {
  157. if ( pElement == NULL )
  158. return;
  159. // Search each of the animation set element lists for the specified element, if the element
  160. // is found and removed from an animation set element list, stop and don't search the others,
  161. // as each element should belong to only on animation set.
  162. int nAnimSets = m_AnimSetList.Count();
  163. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  164. {
  165. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  166. if ( pAnimSetElements )
  167. {
  168. if ( pAnimSetElements->AnimationSet() == pAnimationSet )
  169. {
  170. if ( pAnimSetElements->RemoveElement( pElement ) )
  171. break;
  172. }
  173. }
  174. }
  175. }
  176. //-------------------------------------------------------------------------------------------------
  177. // Purpose: Remove an animation set and all associated elements from the group
  178. //-------------------------------------------------------------------------------------------------
  179. void CDmeRig::RemoveAnimationSet( CDmeAnimationSet *pAnimationSet )
  180. {
  181. int index = FindAnimSetElementList( pAnimationSet );
  182. if ( index != m_AnimSetList.InvalidIndex() )
  183. {
  184. m_AnimSetList.Remove( index );
  185. }
  186. }
  187. //-------------------------------------------------------------------------------------------------
  188. // Determine if the rig has any animation sets associated with it
  189. //-------------------------------------------------------------------------------------------------
  190. bool CDmeRig::HasAnyAnimationSets() const
  191. {
  192. int nAnimSets = m_AnimSetList.Count();
  193. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  194. {
  195. if ( CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ] )
  196. {
  197. if ( CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet() )
  198. return true;
  199. }
  200. }
  201. return false;
  202. }
  203. //-------------------------------------------------------------------------------------------------
  204. // Purpose: Get the list of animation sets in the group
  205. //-------------------------------------------------------------------------------------------------
  206. void CDmeRig::GetAnimationSets( CUtlVector< CDmeAnimationSet* > &animationSetList ) const
  207. {
  208. int nAnimSets = m_AnimSetList.Count();
  209. animationSetList.EnsureCapacity( animationSetList.Count() + nAnimSets );
  210. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  211. {
  212. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  213. if ( pAnimSetElements != NULL )
  214. {
  215. CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
  216. if ( pAnimSet != NULL )
  217. {
  218. animationSetList.AddToTail( pAnimSet );
  219. }
  220. }
  221. }
  222. }
  223. //-------------------------------------------------------------------------------------------------
  224. // Purpose: Get the list of elements for the specified animation set
  225. //-------------------------------------------------------------------------------------------------
  226. void CDmeRig::GetAnimationSetElements( const CDmeAnimationSet* pAnimationSet, CUtlVector< CDmElement* > &elementList ) const
  227. {
  228. int nAnimSets = m_AnimSetList.Count();
  229. // Count the number of total elements in all the animation sets
  230. int nTotalElements = 0;
  231. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  232. {
  233. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  234. if ( pAnimSetElements != NULL )
  235. {
  236. nTotalElements = pAnimSetElements->NumElements();
  237. }
  238. }
  239. // Allocate enough space in the element list for all of the elements in the rig.
  240. elementList.EnsureCapacity( elementList.Count() + nTotalElements );
  241. // Add all the elements in the rig to the provided element list
  242. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  243. {
  244. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  245. if ( pAnimSetElements != NULL )
  246. {
  247. pAnimSetElements->GetElements( elementList );
  248. }
  249. }
  250. }
  251. //-------------------------------------------------------------------------------------------------
  252. // Purpose: Determine if the rig has any elements from the specified animation set
  253. //-------------------------------------------------------------------------------------------------
  254. bool CDmeRig::HasAnimationSet( const CDmeAnimationSet *pAnimationSet ) const
  255. {
  256. return ( FindAnimSetElementList( pAnimationSet ) != m_AnimSetList.InvalidIndex() );
  257. }
  258. //-------------------------------------------------------------------------------------------------
  259. // Purpose: Find the element list for the specified animation set
  260. //-------------------------------------------------------------------------------------------------
  261. int CDmeRig::FindAnimSetElementList( const CDmeAnimationSet *pAnimationSet ) const
  262. {
  263. int nAnimSets = m_AnimSetList.Count();
  264. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  265. {
  266. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  267. if ( pAnimSetElements == NULL )
  268. continue;
  269. if ( pAnimSetElements->AnimationSet() == pAnimationSet )
  270. {
  271. return iAnimSet;
  272. }
  273. }
  274. return m_AnimSetList.InvalidIndex();
  275. }
  276. //-------------------------------------------------------------------------------------------------
  277. // Find the element list for the specified animation set or create one
  278. //-------------------------------------------------------------------------------------------------
  279. CDmeRigAnimSetElements *CDmeRig::FindOrCreateAnimSetElementList( CDmeAnimationSet *pAnimationSet )
  280. {
  281. int nIndex = FindAnimSetElementList( pAnimationSet );
  282. if ( nIndex != m_AnimSetList.InvalidIndex() )
  283. return m_AnimSetList[ nIndex ];
  284. CDmeRigAnimSetElements *pAnimSetElementList = CreateElement< CDmeRigAnimSetElements >( CFmtStr( "rigElements_%s", pAnimationSet->GetName() ), GetFileId() );
  285. if ( pAnimSetElementList )
  286. {
  287. pAnimSetElementList->SetAnimationSet( pAnimationSet );
  288. m_AnimSetList.AddToTail( pAnimSetElementList );
  289. }
  290. return pAnimSetElementList;
  291. }
  292. //-------------------------------------------------------------------------------------------------
  293. // Purpose: Build a list of all of the dag nodes which are influenced by rig, does not include
  294. // dag nodes that are part of the rig.
  295. //-------------------------------------------------------------------------------------------------
  296. void CDmeRig::FindInfluencedDags( CUtlVector< CDmeDag* > &dagList ) const
  297. {
  298. // Count the total number of elements, this is done to calculate a good pre-allocation size for lists
  299. int totalElements = 0;
  300. int nAnimSets = m_AnimSetList.Count();
  301. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  302. {
  303. totalElements += m_AnimSetList[ iAnimSet ]->NumElements();
  304. }
  305. // First build a tree of all of the dag nodes that are part of the rig, we do this so that we
  306. // can quickly determine if a dag which is influenced by some element of the rig is part of the
  307. // rig and therefore should not be added to the list of influenced dag nodes.
  308. CUtlVector< CDmElement* > elementList( 0, totalElements );
  309. CUtlRBTree< const CDmeDag* > rigDags( 0, totalElements, DefLessFunc( const CDmeDag *) );
  310. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  311. {
  312. const CDmaElementArray< CDmElement > &animSetElements = m_AnimSetList[ iAnimSet ]->Elements();
  313. int nElements = animSetElements.Count();
  314. for ( int iElement = 0; iElement < nElements; ++iElement )
  315. {
  316. CDmElement *pElement = animSetElements[ iElement ];
  317. if ( pElement )
  318. {
  319. elementList.AddToTail( pElement );
  320. CDmeDag *pDag = CastElement< CDmeDag >( pElement );
  321. if ( pDag )
  322. {
  323. rigDags.Insert( pDag );
  324. }
  325. }
  326. }
  327. }
  328. // Now iterate through all of the elements that belong to the rig and find any dag nodes which
  329. // are influenced by the rig elements. This is done by looking for any operators and then
  330. // getting the output attributes of the operator and determining if any of those attributes
  331. // belong to a dag node which is not part of the rig.
  332. CUtlRBTree< CDmeDag* > influencedDags( 0, totalElements, DefLessFunc( CDmeDag *) );
  333. CUtlVector< CDmAttribute* > outputAttributes( 0, 32 );
  334. int nElements = elementList.Count();
  335. for ( int iElement = 0; iElement < nElements; ++iElement )
  336. {
  337. CDmElement *pElement = elementList[ iElement ];
  338. CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
  339. if ( pOperator )
  340. {
  341. outputAttributes.RemoveAll();
  342. pOperator->GetOutputAttributes( outputAttributes );
  343. int nAttributes = outputAttributes.Count();
  344. for ( int iAttr = 0; iAttr < nAttributes; ++iAttr )
  345. {
  346. CDmAttribute *pAttr = outputAttributes[ iAttr ];
  347. if ( pAttr == NULL )
  348. continue;
  349. CDmeDag *pDag = CastElement< CDmeDag >( pAttr->GetOwner() );
  350. if ( pDag == NULL )
  351. {
  352. CDmeTransform *pTransform = CastElement< CDmeTransform >( pAttr->GetOwner() );
  353. if ( pTransform )
  354. {
  355. pDag = pTransform->GetDag();
  356. }
  357. }
  358. if ( pDag == NULL )
  359. continue;
  360. // Make sure the dag is not part of the rig, if
  361. // not add it to the list of influenced dag nodes.
  362. if ( rigDags.Find( pDag ) == rigDags.InvalidIndex() )
  363. {
  364. influencedDags.InsertIfNotFound( pDag );
  365. }
  366. }
  367. }
  368. }
  369. // Copy the influenced dag nodes into the provided list
  370. int nDagNodes = influencedDags.Count();
  371. dagList.SetCount( nDagNodes );
  372. for ( int iDag = 0; iDag < nDagNodes; ++iDag )
  373. {
  374. dagList[ iDag ] = influencedDags[ iDag ];
  375. }
  376. }
  377. //-------------------------------------------------------------------------------------------------
  378. // Purpose: Remove all of elements in the rig from the specified shot
  379. //-------------------------------------------------------------------------------------------------
  380. void CDmeRig::RemoveElementsFromShot( CDmeFilmClip *pShot )
  381. {
  382. // Find the animation set channels track group, this will be used to find
  383. // the the channels clip for each of the animation sets referenced by the rig.
  384. CDmeTrack *pAnimSetEditorTrack = NULL;
  385. CDmeTrackGroup *pTrackGroup = pShot->FindOrAddTrackGroup( "channelTrackGroup" );
  386. if ( pTrackGroup )
  387. {
  388. pAnimSetEditorTrack = pTrackGroup->FindOrAddTrack( "animSetEditorChannels", DMECLIP_CHANNEL );
  389. }
  390. int nAnimSets = m_AnimSetList.Count();
  391. for ( int iAnimSet = 0; iAnimSet < nAnimSets; ++iAnimSet )
  392. {
  393. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ iAnimSet ];
  394. if ( pAnimSetElements == NULL )
  395. continue;
  396. CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
  397. if ( pAnimSet == NULL )
  398. continue;
  399. CDmeChannelsClip *pChannelsClip = NULL;
  400. if ( pAnimSetEditorTrack )
  401. {
  402. pChannelsClip = CastElement< CDmeChannelsClip >( pAnimSetEditorTrack->FindNamedClip( pAnimSet->GetName() ) );
  403. }
  404. // Make a copy of the array since we may remove elements from the original while iterating
  405. const CDmaElementArray< CDmElement > &elements = pAnimSetElements->Elements();
  406. int nElements = elements.Count();
  407. CUtlVector< DmElementHandle_t > elementHandles( 0, nElements );
  408. for ( int iElement = 0; iElement < nElements; ++iElement )
  409. {
  410. CDmElement *pElement = elements[ iElement ];
  411. if ( pElement )
  412. {
  413. elementHandles.AddToTail( pElement->GetHandle() );
  414. }
  415. }
  416. int nElementHandles = elementHandles.Count();
  417. for ( int iHandle = 0; iHandle < nElementHandles; ++iHandle )
  418. {
  419. // Get the element using its handle because it may have been destroyed already
  420. CDmElement *pElement = GetElement< CDmElement >( elementHandles[ iHandle ] );
  421. if ( pElement == NULL )
  422. continue;
  423. // If the element is an operator make sure it is removed from the
  424. // list of operators maintained by the shot and animation set.
  425. CDmeOperator *pOperator = CastElement< CDmeOperator >( pElement );
  426. if ( pOperator )
  427. {
  428. pAnimSet->RemoveOperator( pOperator );
  429. pShot->RemoveOperator( pOperator );
  430. // If the element is a channel remove it from the animation set's channel clip.
  431. if ( pChannelsClip )
  432. {
  433. CDmeChannel *pChannel = CastElement< CDmeChannel >( pElement );
  434. if ( pChannel )
  435. {
  436. pChannelsClip->RemoveChannel( pChannel );
  437. }
  438. }
  439. // If the element is a constraint reconnect the original
  440. // channels of the constrained dag back to the transform.
  441. CDmeRigBaseConstraintOperator *pConstraint = CastElement< CDmeRigBaseConstraintOperator >( pElement );
  442. if ( pConstraint )
  443. {
  444. pConstraint->ReconnectTransformChannels();
  445. }
  446. }
  447. else if ( pElement->IsA( CDmeDag::GetStaticTypeSymbol() ) )
  448. {
  449. CDmeDag *pDag = CastElement< CDmeDag >( pElement );
  450. CDmeDag *pParent = pDag->GetParent();
  451. if ( pParent )
  452. {
  453. // Make sure the parent hasn't already been destroyed
  454. if ( g_pDataModel->GetElement( pParent->GetHandle() ) )
  455. {
  456. pParent->RemoveChild( pDag );
  457. }
  458. }
  459. // If the dag has any constraints on it, remove them
  460. CDmeRigBaseConstraintOperator::RemoveConstraintsFromDag( pDag );
  461. }
  462. else if ( ( pElement->GetType() == CDmElement::GetStaticTypeSymbol() ) || pElement->IsA( CDmeTransformControl::GetStaticTypeSymbol() ) )
  463. {
  464. // If the element is just only element assume it may be a control or if the element is
  465. // a transform control try to remove it from the animation set's list of controls.
  466. pAnimSet->RemoveControl( pElement );
  467. }
  468. // Destroy the element, this is done because many elements refer to each other so if undo is enabled
  469. // the auto cleanup will not take place and the elements will persist until the undo history is cleared.
  470. g_pDataModel->DestroyElement( pElement->GetHandle() );
  471. } // For iElement
  472. // Reset the visibility on control groups that were hidden by the rig
  473. SetHiddenControlGroupVisibility( pAnimSetElements, true );
  474. // Clear the element list since they have all been destroyed
  475. pAnimSetElements->RemoveAll();
  476. } // For iAnimSet
  477. m_AnimSetList.RemoveAll();
  478. }
  479. //-------------------------------------------------------------------------------------------------
  480. // Set the visibility of the control groups in the hidden list
  481. //-------------------------------------------------------------------------------------------------
  482. void CDmeRig::SetHiddenControlGroupVisibility( CDmeRigAnimSetElements *pAnimSetElements, bool bVisible )
  483. {
  484. CDmeAnimationSet *pAnimSet = pAnimSetElements->AnimationSet();
  485. if ( pAnimSet == NULL )
  486. return;
  487. const CDmaStringArray &hiddenGroupList = pAnimSetElements->HiddenControlGroups();
  488. int nNumGroups = hiddenGroupList.Count();
  489. for ( int iGroup = 0; iGroup < nNumGroups; ++iGroup )
  490. {
  491. CDmeControlGroup *pGroup = pAnimSet->FindControlGroup( hiddenGroupList[ iGroup ] );
  492. if ( pGroup )
  493. {
  494. pGroup->SetVisible( bVisible );
  495. }
  496. }
  497. }
  498. //-------------------------------------------------------------------------------------------------
  499. // Hide all of the control groups in the rig's list of hidden control groups
  500. //-------------------------------------------------------------------------------------------------
  501. void CDmeRig::HideHiddenControlGroups( CDmeAnimationSet *pAnimationSet )
  502. {
  503. int nAnimSetIndex = FindAnimSetElementList( pAnimationSet );
  504. if ( nAnimSetIndex == m_AnimSetList.InvalidIndex() )
  505. return;
  506. CDmeRigAnimSetElements *pAnimSetElements = m_AnimSetList[ nAnimSetIndex ];
  507. if ( pAnimSetElements == NULL )
  508. return;
  509. SetHiddenControlGroupVisibility( pAnimSetElements, false );
  510. }
  511. //-------------------------------------------------------------------------------------------------
  512. // Purpose: Remove the specified element from any rig which it may be associated with.
  513. //-------------------------------------------------------------------------------------------------
  514. void CDmeRig::RemoveElementFromRig( CDmElement *pElement )
  515. {
  516. if ( pElement == NULL )
  517. return;
  518. CUtlVector< CDmeRigAnimSetElements* > rigElementLists;
  519. FindAncestorsReferencingElement( pElement, rigElementLists );
  520. for ( int iList = 0; iList < rigElementLists.Count(); ++iList )
  521. {
  522. CDmeRigAnimSetElements *pElementList = rigElementLists[ iList ];
  523. if ( pElementList )
  524. {
  525. pElementList->RemoveElement( pElement );
  526. }
  527. }
  528. }
  529. //-------------------------------------------------------------------------------------------------
  530. // Find all of the rigs which refer to the specified animation set
  531. //-------------------------------------------------------------------------------------------------
  532. void CollectRigsOnAnimationSet( CDmeAnimationSet *pAnimSet, CUtlVector< CDmeRig* > &rigList )
  533. {
  534. CDmeFilmClip *pFilmClip = FindReferringElement< CDmeFilmClip >( pAnimSet, "animationSets" );
  535. if ( pFilmClip == NULL )
  536. return;
  537. CDmeDag *pScene = pFilmClip->GetScene();
  538. if ( !pScene || !pAnimSet )
  539. return;
  540. pScene->FindChildrenOfType( rigList );
  541. int i = rigList.Count();
  542. while ( --i >= 0 )
  543. {
  544. CDmeRig *pRig = rigList[ i ];
  545. if ( !pRig || !pRig->HasAnimationSet( pAnimSet ) )
  546. {
  547. rigList.Remove( i );
  548. }
  549. }
  550. }