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.

3107 lines
111 KiB

  1. //=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Converts from any one DMX file format to another
  12. //
  13. //=============================================================================
  14. #include "dmserializers.h"
  15. #include "dmserializers/idmserializers.h"
  16. #include "appframework/iappsystem.h"
  17. #include "filesystem.h"
  18. #include "datamodel/idatamodel.h"
  19. #include "datamodel/dmattributevar.h"
  20. #include "datamodel/dmelementfactoryhelper.h"
  21. #include "tier2/tier2.h"
  22. #include "tier1/timeutils.h"
  23. #include "tier1/fmtstr.h"
  24. #include "tier1/utldict.h"
  25. //-----------------------------------------------------------------------------
  26. // format updater macros
  27. //-----------------------------------------------------------------------------
  28. typedef bool (*FnUpdater)( CDmElement *pElement );
  29. #define IMPLEMENT_UPDATER( n ) \
  30. bool Update##n##_R( CDmElement **ppElement, bool bParity ) \
  31. { \
  32. return UpdateElement_R( &Update##n, ppElement, bParity ); \
  33. }
  34. #define DECLARE_FORMAT_UPDATER( _name, _description, _extension, _encoding, _updaters ) \
  35. class CDmFormatUpdater_ ## _name : public IDmFormatUpdater \
  36. { \
  37. public: \
  38. CDmFormatUpdater_ ## _name() {} \
  39. virtual const char *GetName() const { return #_name; } \
  40. virtual const char *GetDescription() const { return _description; } \
  41. virtual const char *GetExtension() const { return _extension; } \
  42. virtual const char *GetDefaultEncoding() const { return _encoding; } \
  43. virtual int GetCurrentVersion() const { return ARRAYSIZE( _updaters ); } \
  44. virtual bool Update( CDmElement **ppRoot, int nSourceVersion ) \
  45. { \
  46. if ( !ppRoot || !*ppRoot ) \
  47. return false; \
  48. if ( nSourceVersion > GetCurrentVersion() ) \
  49. return false; \
  50. int nUpdater = MAX( 0, nSourceVersion - 1 ); \
  51. bool bParity = true; \
  52. while ( _updaters[ nUpdater ] ) \
  53. { \
  54. if ( !_updaters[ nUpdater ]( ppRoot, bParity ) ) \
  55. return false; \
  56. bParity = !bParity; \
  57. ++nUpdater; \
  58. } \
  59. return true; \
  60. } \
  61. }; \
  62. static CDmFormatUpdater_ ## _name s_FormatUpdater ## _name;
  63. #define INSTALL_FORMAT_UPDATER( _name ) g_pDataModel->AddFormatUpdater( &s_FormatUpdater ## _name )
  64. //-----------------------------------------------------------------------------
  65. // updater helper functions
  66. //-----------------------------------------------------------------------------
  67. void ChangeAttributeType( CDmElement *pElement, const char *pAttrName, DmAttributeType_t type )
  68. {
  69. CDmAttribute *pAttr = pElement->GetAttribute( pAttrName );
  70. Assert( pAttr );
  71. if ( !pAttr )
  72. return;
  73. pAttr->ChangeType_UNSAFE( type );
  74. }
  75. CDmElement *FindElementNamed( CDmrElementArray<> elements, const char *pTargetName )
  76. {
  77. int nElements = elements.Count();
  78. for ( int i = 0; i < nElements; ++i )
  79. {
  80. CDmElement *pElement = elements[ i ];
  81. if ( pElement && !V_strcmp( pTargetName, pElement->GetName() ) )
  82. return pElement;
  83. }
  84. return NULL;
  85. }
  86. CDmElement *FindChannelsClipForChannel( CDmElement *pFilmClip, CDmElement *pChannel )
  87. {
  88. const static CUtlSymbolLarge channelsClipSym = g_pDataModel->GetSymbol( "DmeChannelsClip" );
  89. const static CUtlSymbolLarge channelsSym = g_pDataModel->GetSymbol( "channels" );
  90. DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( pChannel->GetHandle() );
  91. while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
  92. {
  93. CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
  94. CDmElement *pParent = pAttribute->GetOwner();
  95. if ( pParent && pParent->GetType() == channelsClipSym && pAttribute->GetNameSymbol() == channelsSym )
  96. {
  97. CUtlVector< ElementPathItem_t > path;
  98. if ( pParent->FindReferer( pFilmClip->GetHandle(), path, TD_ALL ) ) // NOTE - with non-typed elements, TD_SHALLOW == TD_NONE and TD_DEEP == TD_ALL
  99. return pParent;
  100. }
  101. i = g_pDataModel->NextAttributeReferencingElement( i );
  102. }
  103. return NULL;
  104. }
  105. CDmElement *FindChannelTargettingElement( CDmElement *pTarget, const char *pTargetAttr, bool bFromTarget )
  106. {
  107. const static CUtlSymbolLarge channelSym = g_pDataModel->GetSymbol( "DmeChannel" );
  108. const static CUtlSymbolLarge fromElementSym = g_pDataModel->GetSymbol( bFromTarget ? "fromElement" : "toElement" );
  109. DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( pTarget->GetHandle() );
  110. for( ; i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID; i = g_pDataModel->NextAttributeReferencingElement( i ) )
  111. {
  112. CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
  113. if ( pAttribute->GetNameSymbol() != fromElementSym )
  114. continue;
  115. CDmElement *pParent = pAttribute->GetOwner();
  116. if ( !pParent || pParent->GetType() != channelSym )
  117. continue;
  118. if ( !V_strcmp( pParent->GetValueString( bFromTarget ? "fromAttribute" : "toAttribute" ), pTargetAttr ) )
  119. return pParent;
  120. }
  121. return NULL;
  122. }
  123. CDmElement *GetLogLayerFromChannel( CDmElement *pChannel )
  124. {
  125. CDmElement *pLog = pChannel->GetValueElement< CDmElement >( "log" );
  126. if ( !pLog )
  127. return NULL;
  128. const CUtlVector< DmElementHandle_t > &layers = pLog->GetValue< CUtlVector< DmElementHandle_t > >( "layers" );
  129. if ( layers.Count() != 1 )
  130. return NULL;
  131. return g_pDataModel->GetElement( layers[ 0 ] );
  132. }
  133. void ConcatTransforms( Quaternion qParent, Vector vParent, Quaternion qLocal, Vector vLocal, Quaternion &qFinal, Vector &vFinal )
  134. {
  135. matrix3x4_t mLocal, mParent, mFinal;
  136. QuaternionMatrix( qLocal, vLocal, mLocal );
  137. QuaternionMatrix( qParent, vParent, mParent );
  138. ConcatTransforms( mParent, mLocal, mFinal );
  139. MatrixQuaternion( mFinal, qFinal );
  140. MatrixPosition( mFinal, vFinal );
  141. }
  142. //-----------------------------------------------------------------------------
  143. // format updater functions
  144. //-----------------------------------------------------------------------------
  145. // IMPORTANT: all elements created during update MUST have their parity set to the parity of the current updater
  146. // otherwise, they (and their children) won't be traversed during the next updater
  147. //-----------------------------------------------------------------------------
  148. // Update19 -- Removal of Control display sets. Removes all control display
  149. // sets from animation sets and removes references to display sets from all
  150. // controls. Also updates rigs to have hidden control groups instead of
  151. // display sets.
  152. //-----------------------------------------------------------------------------
  153. void FixupRigGroups( CDmElement *pRig );
  154. bool Update19( CDmElement *pElement )
  155. {
  156. const static CUtlSymbolLarge symDmeControlDisplaySet = g_pDataModel->GetSymbol( "DmeControlDisplaySet" );
  157. const static CUtlSymbolLarge symDmeAnimationSet = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  158. const static CUtlSymbolLarge symDmeRig = g_pDataModel->GetSymbol( "DmeRig" );
  159. const static CUtlSymbolLarge symDisplaySetAttr = g_pDataModel->GetSymbol( "displaySet" );
  160. if ( pElement->GetType() == symDmeControlDisplaySet )
  161. {
  162. // This case shouldn't actually happen all paths which refer to display
  163. // sets should be removed before the display set can actually be reached.
  164. DestroyElement( pElement );
  165. }
  166. else if ( pElement->GetType() == symDmeAnimationSet )
  167. {
  168. pElement->RemoveAttribute( "displaySets" );
  169. }
  170. else if ( pElement->GetType() == symDmeRig )
  171. {
  172. if ( pElement->HasAttribute( "displaySetElements" ) )
  173. {
  174. FixupRigGroups( pElement );
  175. pElement->RemoveAttribute( "displaySetElements" );
  176. }
  177. }
  178. else
  179. {
  180. pElement->RemoveAttribute( "displaySet" );
  181. }
  182. return true;
  183. }
  184. CDmElement *FindChildControlGroup( CDmElement *pGroup, const char *pName, bool bRecursive )
  185. {
  186. CDmAttribute *pChildrenAttr = pGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  187. if ( pChildrenAttr == NULL )
  188. return NULL;
  189. CDmrElementArray< CDmElement > children( pChildrenAttr );
  190. int nNumChildren = children.Count();
  191. for ( int iChild = 0; iChild < nNumChildren; ++iChild )
  192. {
  193. CDmElement *pChild = children[ iChild ];
  194. if ( pChild )
  195. {
  196. if ( V_stricmp( pChild->GetName(), pName ) == 0 )
  197. return pChild;
  198. if ( bRecursive )
  199. {
  200. FindChildControlGroup( pChild, pName, true );
  201. }
  202. }
  203. }
  204. return NULL;
  205. }
  206. CDmElement *FindOrCreateControlGroup( CDmElement *pRig, CDmElement *pParentGroup, const char *pGroupName )
  207. {
  208. CDmElement *pGroup = FindChildControlGroup( pParentGroup, pGroupName, true );
  209. if ( pGroup == NULL )
  210. {
  211. pGroup = CreateElement< CDmElement >( "DmeControlGroup", pGroupName, pParentGroup->GetFileId() );
  212. pGroup->SetParity( pRig->GetParity() );
  213. // Add the new group to the parent
  214. CDmAttribute *pChildrenAttr = pParentGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  215. if ( pChildrenAttr )
  216. {
  217. CDmrElementArray< CDmElement > children( pChildrenAttr );
  218. children.AddToTail( pGroup );
  219. }
  220. }
  221. return pGroup;
  222. }
  223. void ReParentCongrolGroup( CDmElement *pControlGroup, CDmElement *pNewParent )
  224. {
  225. const static CUtlSymbolLarge symChildren = g_pDataModel->GetSymbol( "children" );
  226. if ( ( pControlGroup == NULL ) || ( pNewParent == NULL ) )
  227. return;
  228. // Find the current parent of the control group
  229. CDmElement *pCurrentParent = FindReferringElement< CDmElement >( pControlGroup, symChildren );
  230. if ( pCurrentParent == pNewParent )
  231. return;
  232. // Add the group to the children of the new parent
  233. CDmAttribute *pNewChildrenAttr = pNewParent->GetAttribute( "children", AT_ELEMENT_ARRAY );
  234. if ( pNewChildrenAttr == NULL )
  235. {
  236. pNewChildrenAttr = pNewParent->AddAttributeElementArray< CDmElement >( "children" );
  237. }
  238. CDmrElementArray< CDmElement > newChildren( pNewChildrenAttr );
  239. newChildren.AddToTail( pControlGroup );
  240. // Remove the group from the children of the old parent
  241. if ( pCurrentParent )
  242. {
  243. CDmAttribute *pOldChildrenAttr = pCurrentParent->GetAttribute( "children", AT_ELEMENT_ARRAY );
  244. if ( pOldChildrenAttr )
  245. {
  246. CDmrElementArray< CDmElement > oldChildren( pOldChildrenAttr );
  247. int nIndex = oldChildren.Find( pControlGroup );
  248. oldChildren.Remove( nIndex );
  249. }
  250. }
  251. }
  252. bool IsControlGroupEmpty( CDmElement *pControlGroup )
  253. {
  254. CDmAttribute *pControlsAttr = pControlGroup->GetAttribute( "controls" );
  255. if ( pControlsAttr )
  256. {
  257. CDmrElementArray< CDmElement > controls( pControlsAttr );
  258. if ( controls.Count() > 0 )
  259. return false;
  260. }
  261. CDmAttribute *pChildrenAttr = pControlGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  262. if ( pChildrenAttr )
  263. {
  264. CDmrElementArray< CDmElement > children( pChildrenAttr );
  265. int nNumChildren = children.Count();
  266. for ( int iChild = 0; iChild < nNumChildren; ++iChild )
  267. {
  268. CDmElement *pChild = children[ iChild ];
  269. if ( pChild )
  270. {
  271. if ( IsControlGroupEmpty( pChild ) == false )
  272. return false;
  273. }
  274. }
  275. }
  276. return true;
  277. }
  278. void SetControlGroupState( CDmElement *pRootControlGroup, const char *pGroupName, bool bVisible, bool bSnappable )
  279. {
  280. CDmElement *pControlGroup = FindChildControlGroup( pRootControlGroup, pGroupName, true );
  281. if ( pControlGroup == NULL )
  282. return;
  283. pControlGroup->SetValue< bool >( "visible", bVisible, true );
  284. pControlGroup->SetValue< bool >( "snappable", bSnappable, true );
  285. }
  286. void MoveRigControlsToGroup( CDmElement *pRig, CDmElement *pAnimSetElements, CDmElement *pRootGroup, const char *pSrcGroupName, const char *pDstGroupName, bool bTransformOnly )
  287. {
  288. const static CUtlSymbolLarge symDmeTransformControl = g_pDataModel->GetSymbol( "DmeTransformControl" );
  289. const static CUtlSymbolLarge symElementList = g_pDataModel->GetSymbol( "elementList" );
  290. // First find the specified source control group
  291. CDmElement *pSrcGroup = pRootGroup;
  292. if ( pSrcGroupName )
  293. {
  294. pSrcGroup = FindChildControlGroup( pRootGroup, pSrcGroupName, true );
  295. }
  296. if ( pSrcGroup == NULL )
  297. return;
  298. // Iterate through the controls in the source control group,
  299. // if they are rig elements add them to the destination group.
  300. CDmAttribute *pControlsAttr = pSrcGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  301. if ( pControlsAttr == NULL )
  302. return;
  303. CDmrElementArray< CDmElement > controls( pControlsAttr );
  304. int nNumControls = controls.Count();
  305. CDmElement *pDstGroup = NULL;
  306. CDmAttribute *pDstControlsAttr = NULL;
  307. for ( int iControl = 0; iControl < nNumControls; ++iControl )
  308. {
  309. CDmElement *pControl = controls[ iControl ];
  310. if ( pControl == NULL )
  311. continue;
  312. if ( bTransformOnly && ( pControl->GetType() != symDmeTransformControl ) )
  313. continue;
  314. CUtlVector< CDmElement* > referringElements( 0, 4 );
  315. FindReferringElements( referringElements, pControl, symElementList );
  316. if ( referringElements.Find( pAnimSetElements ) != referringElements.InvalidIndex() )
  317. {
  318. if ( pDstGroup == NULL )
  319. {
  320. pDstGroup = FindOrCreateControlGroup( pRig, pRootGroup, pDstGroupName );
  321. }
  322. if ( pDstControlsAttr == NULL )
  323. {
  324. pDstControlsAttr = pDstGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  325. if ( pDstControlsAttr == NULL )
  326. {
  327. pDstControlsAttr = pDstGroup->AddAttributeElementArray< CDmElement >( "controls" );
  328. }
  329. }
  330. CDmrElementArray< CDmElement > dstControls( pDstControlsAttr );
  331. dstControls.AddToTail( pControl );
  332. }
  333. }
  334. // Now remove the rig controls from the source group
  335. if ( pDstControlsAttr != NULL )
  336. {
  337. CDmrElementArray< CDmElement > rigControls( pDstControlsAttr );
  338. int nNumRigControls = rigControls.Count();
  339. for ( int iControl = 0; iControl < nNumRigControls; ++iControl )
  340. {
  341. CDmElement *pControl = rigControls[ iControl ];
  342. int nIndex = controls.Find( pControl );
  343. if ( nIndex != controls.InvalidIndex() )
  344. {
  345. controls.Remove( nIndex );
  346. }
  347. }
  348. }
  349. }
  350. void RemoveInvalidTransformControls( CDmElement *pAnimSet )
  351. {
  352. const static CUtlSymbolLarge symDmeTransformControl = g_pDataModel->GetSymbol( "DmeTransformControl" );
  353. const static CUtlSymbolLarge symControls = g_pDataModel->GetSymbol( "controls" );
  354. CDmAttribute *pControlsAttr = pAnimSet->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  355. if ( pControlsAttr == NULL )
  356. return;
  357. CDmrElementArray< CDmElement > controls( pControlsAttr );
  358. int nNumControls = controls.Count();
  359. CUtlVector< CDmElement* > invalidControls( 0, nNumControls / 2 );
  360. for ( int iControl = 0; iControl < nNumControls; ++iControl )
  361. {
  362. CDmElement *pControl = controls[ iControl ];
  363. if ( pControl == NULL )
  364. continue;
  365. if ( pControl->GetType() == symDmeTransformControl )
  366. {
  367. CDmElement *pPosChannel = pControl->GetValueElement< CDmElement >( "positionChannel" );
  368. CDmElement *pRotChannel = pControl->GetValueElement< CDmElement >( "orientationChannel" );
  369. if ( ( pPosChannel == NULL ) && ( pRotChannel == NULL ) )
  370. {
  371. invalidControls.AddToTail( pControl );
  372. }
  373. }
  374. }
  375. int nNumInvalid = invalidControls.Count();
  376. for ( int iInvalid = 0; iInvalid < nNumInvalid; ++iInvalid )
  377. {
  378. CDmElement *pInvalidControl = invalidControls[ iInvalid ];
  379. if ( pInvalidControl == NULL )
  380. return;
  381. // Remove the control from the animation set
  382. int nIndex = controls.Find( pInvalidControl );
  383. if ( nIndex != controls.InvalidIndex() )
  384. {
  385. controls.Remove( nIndex );
  386. }
  387. // Remove the control from the control groups
  388. CUtlVector < CDmElement* > referringElements( 0, 4 );
  389. FindReferringElements( referringElements, pInvalidControl, symControls );
  390. int nNumReferringElements = referringElements.Count();
  391. for ( int iElement = 0; iElement < nNumReferringElements; ++iElement )
  392. {
  393. CDmElement *pElement = referringElements[ iElement ];
  394. if ( pElement == NULL )
  395. continue;
  396. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  397. if ( pControlsAttr == NULL )
  398. continue;
  399. CDmrElementArray< CDmElement > controls( pControlsAttr );
  400. nIndex = controls.Find( pInvalidControl );
  401. if ( nIndex != controls.InvalidIndex() )
  402. {
  403. controls.Remove( nIndex );
  404. }
  405. }
  406. }
  407. }
  408. void FixupRigGroupsForAnimationSet( CDmElement *pRig, CDmElement *pAnimSetElements )
  409. {
  410. const static CUtlSymbolLarge symDmeAnimationSet = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  411. // Get the animation set
  412. CDmElement *pAnimSet = pAnimSetElements->GetValueElement< CDmElement >( "animationSet" );
  413. if ( ( pAnimSet == NULL ) || ( pAnimSet->GetType() != symDmeAnimationSet ) )
  414. return;
  415. // First clean out any invalid controls from the animations set
  416. RemoveInvalidTransformControls( pAnimSet );
  417. // Get the root control group of the animation set
  418. CDmElement *pRootControlGroup = pAnimSet->GetValueElement< CDmElement >( "rootControlGroup" );
  419. if ( pRootControlGroup == NULL )
  420. return;
  421. // Move the rig controls into their own groups
  422. MoveRigControlsToGroup( pRig, pAnimSetElements, pRootControlGroup, NULL, "RigHelpers", false );
  423. MoveRigControlsToGroup( pRig, pAnimSetElements, pRootControlGroup, "Body", "RigBody", true );
  424. MoveRigControlsToGroup( pRig, pAnimSetElements, pRootControlGroup, "Arms", "RigArms", true );
  425. MoveRigControlsToGroup( pRig, pAnimSetElements, pRootControlGroup, "Legs", "RigLegs", true );
  426. MoveRigControlsToGroup( pRig, pAnimSetElements, pRootControlGroup, "Root", "RigRoot", true );
  427. // Move the fingers into their own groups
  428. CDmElement *pArmsGroup = FindChildControlGroup( pRootControlGroup, "Arms", true );
  429. if ( pArmsGroup )
  430. {
  431. // Find the fingers group and make sure it is a child of the root and then
  432. // make sure the left and right fingers groups children of the fingers group.
  433. CDmElement *pFingers = FindOrCreateControlGroup( pRig, pRootControlGroup, "Fingers" );
  434. if ( pFingers )
  435. {
  436. ReParentCongrolGroup( pFingers, pRootControlGroup );
  437. CDmElement *pFingersR = FindChildControlGroup( pArmsGroup, "Fingers_R", false );
  438. if ( pFingersR )
  439. {
  440. pFingersR->SetName( "RightFingers" );
  441. ReParentCongrolGroup( pFingersR, pFingers );
  442. }
  443. CDmElement *pFingersL = FindChildControlGroup( pArmsGroup, "Fingers_L", false );
  444. if ( pFingersL )
  445. {
  446. pFingersL->SetName( "LeftFingers" );
  447. ReParentCongrolGroup( pFingersL, pFingers );
  448. }
  449. }
  450. }
  451. // Hide the original body groups and rig utility groups
  452. SetControlGroupState( pRootControlGroup, "Arms", false, true );
  453. SetControlGroupState( pRootControlGroup, "Legs", false, true );
  454. SetControlGroupState( pRootControlGroup, "Body", false, true );
  455. SetControlGroupState( pRootControlGroup, "Root", false, true );
  456. SetControlGroupState( pRootControlGroup, "Other", false, true );
  457. SetControlGroupState( pRootControlGroup, "Unknown", false, true );
  458. SetControlGroupState( pRootControlGroup, "Attachments", false, true );
  459. SetControlGroupState( pRootControlGroup, "RigHelpers", false, false );
  460. SetControlGroupState( pRootControlGroup, "RigConstraints", false, false );
  461. // Add the body groups to the list of groups hidden by the rig
  462. CDmAttribute *pHiddenGroupsAttr = pAnimSetElements->GetAttribute( "hiddenGroups", AT_STRING_ARRAY );
  463. if ( pHiddenGroupsAttr == NULL )
  464. {
  465. pHiddenGroupsAttr = pAnimSetElements->AddAttribute( "hiddenGroups", AT_STRING_ARRAY );
  466. }
  467. CDmrStringArray hiddenGroups( pHiddenGroupsAttr );
  468. hiddenGroups.AddToTail( "Body" );
  469. hiddenGroups.AddToTail( "Arms" );
  470. hiddenGroups.AddToTail( "Legs" );
  471. hiddenGroups.AddToTail( "Root" );
  472. hiddenGroups.AddToTail( "Other" );
  473. hiddenGroups.AddToTail( "Unknown" );
  474. // Set the color of all of the top level groups and remove any control groups which are empty
  475. CDmAttribute *pChildrenAttr = pRootControlGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  476. if ( pChildrenAttr )
  477. {
  478. Color topLevelColor( 0, 128, 255, 255 );
  479. Color controlColor( 200, 200, 200, 255 );
  480. CDmrElementArray< CDmElement > children( pChildrenAttr );
  481. int nChildren = children.Count();
  482. CUtlVector< CDmElement* > emptyGroups( 0, nChildren );
  483. for ( int iChild = 0; iChild < nChildren; ++iChild )
  484. {
  485. CDmElement *pChildGroup = children[ iChild ];
  486. pChildGroup->SetValue< Color >( "groupColor", topLevelColor );
  487. pChildGroup->SetValue< Color >( "controlColor", controlColor );
  488. // If the child group is empty add it to the list of children to remove
  489. if ( IsControlGroupEmpty( pChildGroup ) )
  490. {
  491. emptyGroups.AddToTail( pChildGroup );
  492. }
  493. }
  494. // Remove the empty groups
  495. int nNumEmptyGroups = emptyGroups.Count();
  496. for ( int iEmptyGroup = 0; iEmptyGroup < nNumEmptyGroups; ++iEmptyGroup )
  497. {
  498. CDmElement *pEmptyGroup = emptyGroups[ iEmptyGroup ];
  499. int nIndex = children.Find( pEmptyGroup );
  500. if ( nIndex != children.InvalidIndex() )
  501. {
  502. children.Remove( nIndex );
  503. }
  504. }
  505. }
  506. }
  507. void FixupRigGroups( CDmElement *pRig )
  508. {
  509. CDmAttribute *pAnimSetListAttr = pRig->GetAttribute( "animSetList", AT_ELEMENT_ARRAY );
  510. if ( pAnimSetListAttr == NULL )
  511. return;
  512. CDmrElementArray<> animSetList( pAnimSetListAttr );
  513. int nNumAnimSets = animSetList.Count();
  514. for ( int iAnimSet = 0; iAnimSet < nNumAnimSets; ++iAnimSet )
  515. {
  516. CDmElement *pAnimSetElements = animSetList[ iAnimSet ];
  517. if ( pAnimSetElements )
  518. {
  519. FixupRigGroupsForAnimationSet( pRig, pAnimSetElements );
  520. }
  521. }
  522. }
  523. //-----------------------------------------------------------------------------
  524. // Update18 -- removing procedural presetgroup and presets (now exist only in code, and not as elements)
  525. //-----------------------------------------------------------------------------
  526. bool Update18( CDmElement *pElement )
  527. {
  528. const static CUtlSymbolLarge symDmeAnimationSet = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  529. const static CUtlSymbolLarge symDmePreset = g_pDataModel->GetSymbol( "DmePreset" );
  530. if ( pElement->GetType() == symDmeAnimationSet )
  531. {
  532. CDmAttribute *pPresetGroupsAttr = pElement->GetAttribute( "presetGroups", AT_ELEMENT_ARRAY );
  533. if ( pPresetGroupsAttr )
  534. {
  535. CDmrElementArray<> presetGroups( pPresetGroupsAttr );
  536. int nNumPresetGroups = presetGroups.Count();
  537. for ( int i = nNumPresetGroups - 1; i >= 0; --i )
  538. {
  539. if ( CDmElement *pPresetGroup = presetGroups[ i ] )
  540. {
  541. if ( V_strcmp( pPresetGroup->GetName(), "procedural" ) != 0 && V_strcmp( pPresetGroup->GetName(), "Procedural" ) != 0 )
  542. continue;
  543. }
  544. presetGroups.Remove( i );
  545. }
  546. }
  547. }
  548. else if ( pElement->GetType() == symDmePreset )
  549. {
  550. pElement->RemoveAttribute( "procedural" );
  551. }
  552. return true;
  553. }
  554. //-----------------------------------------------------------------------------
  555. // Update17 -- Transform control unification. Separate transform controls for
  556. // position and orientation are combine in to a single transform control and
  557. // the control group which previously contained the separate position and
  558. // orientation controls is removed.
  559. //-----------------------------------------------------------------------------
  560. void UnifyTransformControl( CDmElement *pControl, CDmElement *pAnimSet );
  561. void DestroyControl( CDmElement *pControl );
  562. CDmElement *CollapseControlGroup( CDmElement *pControlGroup, CDmElement *pRootGroup );
  563. bool Update17( CDmElement *pElement )
  564. {
  565. const static CUtlSymbolLarge symDmeAnimationSet = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  566. const static CUtlSymbolLarge symDmePreset = g_pDataModel->GetSymbol( "DmePreset" );
  567. // If the element is an animation set iterate through its controls and unify the transform controls.
  568. // Note that while the transform controls themselves would be visited they may be visited from the
  569. // animation set or control group containing them, making removing the controls from the animation set
  570. // or control group problematic since the calling function is in the middle of walking the array that
  571. // will be modified.
  572. if ( pElement->GetType() == symDmeAnimationSet )
  573. {
  574. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  575. if ( pControlsAttr )
  576. {
  577. // Make a copy of the controls list. A copy is must be made
  578. // since the actual list may be modified during iteration.
  579. CDmrElementArray<> controls( pControlsAttr );
  580. int nNumControls = controls.Count();
  581. CUtlVector< DmElementHandle_t > controlHandles;
  582. controlHandles.SetSize( nNumControls );
  583. for ( int iControl = 0; iControl < nNumControls; ++iControl )
  584. {
  585. controlHandles[ iControl ] = controls[ iControl ]->GetHandle();
  586. }
  587. // Iterate through the controls, unifying and of the transform controls which contain only a
  588. // position or rotation with the corresponding control containing the other component.
  589. for ( int iControl = 0; iControl < nNumControls; ++iControl )
  590. {
  591. CDmElement *pControl = g_pDataModel->GetElement( controlHandles[ iControl ] );
  592. if ( pControl )
  593. {
  594. UnifyTransformControl( pControl, pElement );
  595. }
  596. }
  597. }
  598. }
  599. else if ( pElement->GetType() == symDmePreset )
  600. {
  601. // For presets merge all control value elements that share the same base name
  602. CDmAttribute *pControlValuesAttr = pElement->GetAttribute( "controlValues", AT_ELEMENT_ARRAY );
  603. if ( pControlValuesAttr )
  604. {
  605. CDmrElementArray<> controlValueElements( pControlValuesAttr );
  606. int nControlValues = controlValueElements.Count();
  607. if ( nControlValues > 0 )
  608. {
  609. CUtlDict< CDmElement*, int > mergedControls;
  610. CUtlVector< DmElementHandle_t > validControlValues( 0, nControlValues );
  611. for ( int iValue = 0; iValue < nControlValues; ++iValue )
  612. {
  613. CDmElement *pControlValue = controlValueElements[ iValue ];
  614. if ( pControlValue == NULL )
  615. continue;
  616. bool bPos = pControlValue->HasAttribute( "valuePosition" );
  617. bool bRot = pControlValue->HasAttribute( "valueOrientation" );
  618. const char *pComponentStart = NULL;
  619. const char *pName = pControlValue->GetName();
  620. // Must have a position or rotation value, but not both
  621. if ( bPos && !bRot )
  622. {
  623. pComponentStart = V_strstr( pName, " - pos" );
  624. }
  625. else if ( bRot && !bPos )
  626. {
  627. pComponentStart = V_strstr( pName, " - rot" );
  628. }
  629. // If the control value will not be merged,
  630. // add it to the list of valid control values.
  631. if ( pComponentStart == NULL )
  632. {
  633. validControlValues.AddToTail( pControlValue->GetHandle() );
  634. continue;
  635. }
  636. // Construct the base name by removing the component extension
  637. char baseName[ 256 ];
  638. V_strncpy( baseName, pName, 256 );
  639. baseName[ pComponentStart - pName ] = 0;
  640. // Find or create the new control value
  641. CDmElement *pNewControlValue = NULL;
  642. int nIndex = mergedControls.Find( baseName );
  643. if ( nIndex == mergedControls.InvalidIndex() )
  644. {
  645. pNewControlValue = CreateElement< CDmElement >( "DmElement", baseName, pElement->GetFileId() );
  646. pNewControlValue->SetParity( pElement->GetParity() );
  647. nIndex = mergedControls.Insert( baseName, pNewControlValue );
  648. validControlValues.AddToTail( pNewControlValue->GetHandle() );
  649. }
  650. else
  651. {
  652. pNewControlValue = mergedControls.Element( nIndex );
  653. }
  654. // Copy the value from the old control value element
  655. if ( pNewControlValue )
  656. {
  657. if ( bPos )
  658. {
  659. Vector position = pControlValue->GetValue< Vector >( "valuePosition" );
  660. pNewControlValue->SetValue< Vector >( "valuePosition", position );
  661. }
  662. else
  663. {
  664. Quaternion orentation = pControlValue->GetValue< Quaternion >( "valueOrientation" );
  665. pNewControlValue->SetValue< Quaternion >( "valueOrientation", orentation );
  666. }
  667. }
  668. }
  669. // Replace the original list of control elements with
  670. // the list of currently valid control elements.
  671. controlValueElements = validControlValues;
  672. }
  673. }
  674. }
  675. return true;
  676. }
  677. void UnifyTransformControl( CDmElement *pTransformControl, CDmElement *pAnimSet )
  678. {
  679. const static CUtlSymbolLarge symDmeTransformControl = g_pDataModel->GetSymbol( "DmeTransformControl" );
  680. const static CUtlSymbolLarge symDmeControlGroup = g_pDataModel->GetSymbol( "DmeControlGroup" );
  681. const static CUtlSymbolLarge symDmeAnimationSet = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  682. const static CUtlSymbolLarge symDmeRigAnimSetElements = g_pDataModel->GetSymbol( "DmeRigAnimSetElements" );
  683. const static CUtlSymbolLarge symDmeRig = g_pDataModel->GetSymbol( "DmeRig" );
  684. const static CUtlSymbolLarge symControls = g_pDataModel->GetSymbol( "controls" );
  685. const static CUtlSymbolLarge symElementList = g_pDataModel->GetSymbol( "elementList" );
  686. const static CUtlSymbolLarge symDisplaySetElements = g_pDataModel->GetSymbol( "displaySetElements" );
  687. if ( pTransformControl->GetType() == symDmeTransformControl )
  688. {
  689. const char *baseName = pTransformControl->GetValueString( "baseName" );
  690. // Find the control group containing the specified control
  691. CDmElement *pTransformControlGroup = NULL;
  692. CUtlVector< CDmElement* > controlGroups;
  693. FindReferringElements( controlGroups, pTransformControl, symControls );
  694. int nNumGroups = controlGroups.Count();
  695. for ( int iGroup = 0; iGroup < nNumGroups; ++iGroup )
  696. {
  697. CDmElement *pGroup = controlGroups[ iGroup ];
  698. if ( pGroup->GetType() == symDmeControlGroup )
  699. {
  700. pTransformControlGroup = pGroup;
  701. break;
  702. }
  703. }
  704. Assert( pTransformControlGroup );
  705. if ( pTransformControlGroup == NULL )
  706. return;
  707. // Find the position or orientation control that corresponds to the given control
  708. CDmElement *pPositionControl = NULL;
  709. CDmElement *pOrientationControl = NULL;
  710. CDmElement *pPositionChannel = NULL;
  711. CDmElement *pOrientationChannel = NULL;
  712. CDmAttribute *pControlsAttr = pTransformControlGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  713. if ( pControlsAttr )
  714. {
  715. CDmrElementArray<> controlList( pControlsAttr );
  716. for ( int iControl = 0; iControl < controlList.Count(); ++iControl )
  717. {
  718. CDmElement *pControl = controlList[ iControl ];
  719. if ( pControl->HasAttribute( "position", AT_ELEMENT ) )
  720. {
  721. pPositionControl = pControl;
  722. pPositionChannel = pPositionControl->GetValueElement< CDmElement >( "position" );
  723. }
  724. else if ( pControl->HasAttribute( "orientation", AT_ELEMENT ) )
  725. {
  726. pOrientationControl = pControl;
  727. pOrientationChannel = pOrientationControl->GetValueElement< CDmElement >( "orientation" );
  728. }
  729. if ( pPositionControl && pOrientationControl )
  730. break;
  731. }
  732. }
  733. // Make sure we got the correct element
  734. if ( ( pPositionControl != pTransformControl ) && ( pOrientationControl != pTransformControl ) )
  735. return;
  736. // Get the position and value controls from the old element
  737. Vector position = pPositionControl ? pPositionControl->GetValue< Vector >( "valuePosition", vec3_origin ) : vec3_origin;
  738. Quaternion orientation = pOrientationControl ? pOrientationControl->GetValue< Quaternion >( "valueOrientation", quat_identity ) : quat_identity;
  739. // Create the new transform control
  740. CDmElement *pNewTransformControl = CreateElement< CDmElement >( "DmeTransformControl", baseName, pTransformControl->GetFileId() );
  741. pNewTransformControl->SetParity( pTransformControl->GetParity() );
  742. pNewTransformControl->SetValue( "positionChannel", pPositionChannel );
  743. pNewTransformControl->SetValue( "orientationChannel", pOrientationChannel );
  744. pNewTransformControl->SetValue( "valuePosition", position );
  745. pNewTransformControl->SetValue( "valueOrientation", orientation );
  746. if ( pPositionChannel )
  747. {
  748. pPositionChannel->SetValue( "fromElement", pNewTransformControl );
  749. }
  750. if ( pOrientationChannel )
  751. {
  752. pOrientationChannel->SetValue( "fromElement", pNewTransformControl );
  753. }
  754. // If the old transform control was in a display set, add the new one to the display set as well
  755. CDmElement *pDisplaySet = pTransformControl->GetValueElement< CDmElement >( "displaySet" );
  756. if ( pDisplaySet )
  757. {
  758. pNewTransformControl->SetValue( "displaySet", pDisplaySet );
  759. }
  760. // Add the new control to the animation set
  761. CDmAttribute *pAnimSetControlsAttr = pAnimSet->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  762. if ( pAnimSetControlsAttr )
  763. {
  764. CDmrElementArray<> animSetControls( pAnimSetControlsAttr );
  765. animSetControls.AddToTail( pNewTransformControl );
  766. }
  767. // If the old transform control was part of a rig, add the new transform control to the rig as well
  768. CUtlVector< CDmElement * > animSetRigList;
  769. FindReferringElements( animSetRigList, pTransformControl, symElementList );
  770. int nNumAnimSetRigs = animSetRigList.Count();
  771. for ( int iAnimSetRig = 0; iAnimSetRig < nNumAnimSetRigs; ++iAnimSetRig )
  772. {
  773. CDmElement *pAnimElements = animSetRigList[ iAnimSetRig ];
  774. if ( ( pAnimElements != NULL ) && ( pAnimElements->GetType() == symDmeRigAnimSetElements ) &&
  775. ( pAnimElements->GetValueElement< CDmElement >( "animationSet" ) == pAnimSet ) )
  776. {
  777. CDmAttribute *pElementsAttr = pAnimElements->GetAttribute( "elementList", AT_ELEMENT_ARRAY );
  778. if ( pElementsAttr )
  779. {
  780. CDmrElementArray<> elementsList( pElementsAttr );
  781. elementsList.AddToTail( pNewTransformControl );
  782. }
  783. }
  784. }
  785. CUtlVector< CDmElement * > rigList;
  786. FindReferringElements( rigList, pTransformControl, symDisplaySetElements );
  787. int nNumRigs = rigList.Count();
  788. for ( int iRig = 0; iRig < nNumRigs; ++iRig )
  789. {
  790. CDmElement *pRig = rigList[ iRig ];
  791. if ( ( pRig != NULL ) && ( pRig->GetType() == symDmeRig ) )
  792. {
  793. CDmAttribute *pDisplaySetElementsAttr = pRig->GetAttribute( "displaySetElements", AT_ELEMENT_ARRAY );
  794. if ( pDisplaySetElementsAttr )
  795. {
  796. CDmrElementArray<> displaySetElements( pDisplaySetElementsAttr );
  797. displaySetElements.AddToTail( pNewTransformControl );
  798. }
  799. }
  800. }
  801. // Move all the controls and children from the transform control group up to
  802. // its parent and remove the the transform control group from its parent.
  803. CDmElement *pParentControlGroup = pAnimSet->GetValueElement< CDmElement >( "rootControlGroup" );
  804. if ( pTransformControlGroup )
  805. {
  806. pParentControlGroup = CollapseControlGroup( pTransformControlGroup, pParentControlGroup );
  807. }
  808. // Add the new control to parent control group
  809. if ( pParentControlGroup )
  810. {
  811. CDmAttribute *pParentControlsAttr = pParentControlGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  812. if ( pParentControlsAttr )
  813. {
  814. CDmrElementArray<> parentControls( pParentControlsAttr );
  815. parentControls.AddToTail( pNewTransformControl );
  816. }
  817. }
  818. // Remove the old controls from all animation sets and
  819. // control groups they belong to, and then destroy them.
  820. DestroyControl( pPositionControl );
  821. DestroyControl( pOrientationControl );
  822. }
  823. }
  824. void DestroyControl( CDmElement *pControl )
  825. {
  826. const static CUtlSymbolLarge symControls = g_pDataModel->GetSymbol( "controls" );
  827. const static CUtlSymbolLarge symElementList = g_pDataModel->GetSymbol( "elementList" );
  828. const static CUtlSymbolLarge symDisplaySetElements = g_pDataModel->GetSymbol( "displaySetElements" );
  829. if ( pControl == NULL )
  830. return;
  831. // Remove the control from any animation sets and control groups it belongs to
  832. CUtlVector< CDmElement* > ownerList;
  833. FindReferringElements( ownerList, pControl, symControls );
  834. Assert( ownerList.Count() == 2 );
  835. for ( int iElement = 0; iElement < ownerList.Count(); ++iElement )
  836. {
  837. CDmElement *pElement = ownerList[ iElement ];
  838. if ( pElement == NULL )
  839. continue;
  840. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  841. if ( pControlsAttr == NULL )
  842. continue;
  843. CDmrElementArray<> controlList( pControlsAttr );
  844. int nIndex = controlList.Find( pControl );
  845. if ( nIndex != controlList.InvalidIndex() )
  846. {
  847. controlList.Remove( nIndex );
  848. }
  849. }
  850. // Remove the control from any rigs it is a part of
  851. CUtlVector< CDmElement * > animSetRigList;
  852. FindReferringElements( animSetRigList, pControl, symElementList );
  853. int nAimSetRigs = animSetRigList.Count();
  854. for ( int iAnimSetRig = 0; iAnimSetRig < nAimSetRigs; ++iAnimSetRig )
  855. {
  856. CDmElement *pElement = animSetRigList[ iAnimSetRig ];
  857. if ( pElement == NULL )
  858. continue;
  859. CDmAttribute *pElementsAttr = pElement->GetAttribute( "elementList", AT_ELEMENT_ARRAY );
  860. if ( pElementsAttr == NULL )
  861. continue;
  862. CDmrElementArray<> elementsList( pElementsAttr );
  863. int nIndex = elementsList.Find( pControl );
  864. if ( nIndex != elementsList.InvalidIndex() )
  865. {
  866. elementsList.Remove( nIndex );
  867. }
  868. }
  869. CUtlVector< CDmElement * > rigList;
  870. FindReferringElements( rigList, pControl, symDisplaySetElements );
  871. int nNumRigs = rigList.Count();
  872. for ( int iRig = 0; iRig < nNumRigs; ++iRig )
  873. {
  874. CDmElement *pRig = rigList[ iRig ];
  875. if ( pRig == NULL )
  876. continue;
  877. CDmAttribute *pDisplaySetElementsAttr = pRig->GetAttribute( "displaySetElements", AT_ELEMENT_ARRAY );
  878. if ( pDisplaySetElementsAttr == NULL )
  879. continue;
  880. CDmrElementArray<> displaySetElements( pDisplaySetElementsAttr );
  881. int nIndex = displaySetElements.Find( pControl );
  882. if ( nIndex != displaySetElements.InvalidIndex() )
  883. {
  884. displaySetElements.Remove( nIndex );
  885. }
  886. }
  887. // Destroy the control even if something is holding on to it
  888. DestroyElement( pControl );
  889. }
  890. CDmElement *CollapseControlGroup( CDmElement *pControlGroup, CDmElement *pRootGroup )
  891. {
  892. const static CUtlSymbolLarge symDmeControlGroup = g_pDataModel->GetSymbol( "DmeControlGroup" );
  893. const static CUtlSymbolLarge symChildren = g_pDataModel->GetSymbol( "children" );
  894. if ( pControlGroup->GetType() != symDmeControlGroup )
  895. return NULL;
  896. if ( pRootGroup && ( pRootGroup->GetType() != symDmeControlGroup ) )
  897. return NULL;
  898. // Find the parent control group of the specified control group
  899. CDmElement *pParentControlGroup = NULL;
  900. CUtlVector< CDmElement* > parentList;
  901. FindReferringElements( parentList, pControlGroup, symChildren );
  902. for ( int i = 0; i < parentList.Count(); ++i )
  903. {
  904. CDmElement *pElement = parentList[ i ];
  905. if ( pElement->GetType() == symDmeControlGroup )
  906. {
  907. pParentControlGroup = pElement;
  908. break;
  909. }
  910. }
  911. Assert( pParentControlGroup );
  912. // If no parent was found, use the supplied root group
  913. if ( pParentControlGroup == NULL )
  914. {
  915. pParentControlGroup = pRootGroup;
  916. }
  917. if ( ( pParentControlGroup != NULL ) && ( pParentControlGroup != pControlGroup ) )
  918. {
  919. // Move add the controls of the child to its parent
  920. CDmAttribute *pChildControlsAttr = pControlGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  921. CDmAttribute *pParentControlsAttr = pParentControlGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  922. if ( pChildControlsAttr && pParentControlsAttr )
  923. {
  924. CDmrElementArray<> childControls( pChildControlsAttr );
  925. CDmrElementArray<> parentControls( pParentControlsAttr );
  926. for ( int iControl = 0; iControl < childControls.Count(); ++iControl )
  927. {
  928. parentControls.AddToTail( childControls[ iControl ] );
  929. }
  930. childControls.RemoveAll();
  931. }
  932. // Move the children of the child to its parent
  933. CDmAttribute *pChildChildrenAttr = pControlGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  934. CDmAttribute *pParentChildrenAttr = pParentControlGroup->GetAttribute( "children", AT_ELEMENT_ARRAY );
  935. if ( pParentChildrenAttr )
  936. {
  937. CDmrElementArray<> parentChildren( pParentChildrenAttr );
  938. // Move the children from the control group to its parent
  939. if ( pChildChildrenAttr )
  940. {
  941. CDmrElementArray<> childChildren( pChildChildrenAttr );
  942. for ( int iChild = 0; iChild < childChildren.Count(); ++iChild )
  943. {
  944. parentChildren.AddToTail( childChildren[ iChild ] );
  945. }
  946. childChildren.RemoveAll();
  947. }
  948. // Remove the control group from its parent
  949. int nGroupIndex = parentChildren.Find( pControlGroup );
  950. parentChildren.Remove( nGroupIndex );
  951. }
  952. }
  953. return pParentControlGroup;
  954. }
  955. //-----------------------------------------------------------------------------
  956. // Update16 -- remove settings from sfm sessions
  957. //-----------------------------------------------------------------------------
  958. bool Update16( CDmElement *pElement )
  959. {
  960. // remove manipulatorsettings from sfm sessions
  961. if ( !V_strcmp( pElement->GetName(), "sessionSettings" ) )
  962. {
  963. pElement->RemoveAttribute( "manipulatorSettings" );
  964. CDmElement *pRenderSettings = pElement->GetValueElement< CDmElement >( "renderSettings" );
  965. if ( pRenderSettings )
  966. {
  967. CDmElement *pMovieSettings = pRenderSettings->GetValueElement< CDmElement >( "MovieSettings" );
  968. pElement->SetValue( "movieSettings", pMovieSettings ); // lower-casing first letter to match other settings
  969. pRenderSettings->RemoveAttribute( "MovieSettings" );
  970. if ( pMovieSettings )
  971. {
  972. pMovieSettings->RemoveAttribute( "shutterSpeed" );
  973. pMovieSettings->RemoveAttribute( "framerate" );
  974. pMovieSettings->RemoveAttribute( "nLayoffState" );
  975. pMovieSettings->RemoveAttribute( "startTime" );
  976. pMovieSettings->RemoveAttribute( "endTime" );
  977. pMovieSettings->RemoveAttribute( "renderOnlySelectedClips" );
  978. pMovieSettings->InitValue( "videoTarget", 2 ); // TGA
  979. pMovieSettings->InitValue( "audioTarget", 2 ); // WAV
  980. pMovieSettings->InitValue( "stereoscopic", false );
  981. pMovieSettings->InitValue( "stereoSingleFile", false );
  982. pMovieSettings->InitValue( "clearDecals", false );
  983. pMovieSettings->InitValue( "width", 1280 );
  984. pMovieSettings->InitValue( "height", 720 );
  985. pMovieSettings->InitValue( "filename", "" );
  986. }
  987. CDmElement *pPosterSettings = pRenderSettings->GetValueElement< CDmElement >( "PosterSettings" );
  988. pElement->SetValue( "posterSettings", pPosterSettings ); // lower-casing first letter to match other settings
  989. pRenderSettings->RemoveAttribute( "PosterSettings" );
  990. pRenderSettings->RemoveAttribute( "syncEngineFramerate" );
  991. pRenderSettings->RemoveAttribute( "showFocalPlane" );
  992. pRenderSettings->RemoveAttribute( "showCameraFrustum" );
  993. pRenderSettings->RemoveAttribute( "showViewTargets" );
  994. pRenderSettings->RemoveAttribute( "StereoFlip" );
  995. pRenderSettings->InitValue( "ambientOcclusionMode", 0 ); // Perform ambient occlusion and/or outlining
  996. pRenderSettings->InitValue( "showAmbientOcclusion", 0 ); // Show just AO/outlining (vs combined with normal scene rendering)
  997. pRenderSettings->InitValue( "drawGameRenderablesMask", 0xd8 ); // RENDER_GAME_ROPES | RENDER_GAME_BEAMS | RENDER_GAME_WORLD_BRUSHES | RENDER_GAME_WORLD_PROPS
  998. pRenderSettings->InitValue( "drawToolRenderablesMask", 0x0f ); // RENDER_TOOL_PUPPETS | RENDER_TOOL_EFFECTS | RENDER_TOOL_PARTICLE_SYSTEMS | RENDER_TOOL_LIGHTS
  999. pRenderSettings->InitValue( "toneMapScale", 1.0f );
  1000. }
  1001. }
  1002. return true;
  1003. }
  1004. //-----------------------------------------------------------------------------
  1005. // Remove the "parentConstraint" attribute from all dmeDag elements and the
  1006. // "embeddedTarget" attribute from all operators.
  1007. //-----------------------------------------------------------------------------
  1008. bool IsRigConstraint( CDmElement *pElement )
  1009. {
  1010. const static CUtlSymbolLarge rigSym[] =
  1011. {
  1012. g_pDataModel->GetSymbol( "DmeRigPointConstraintOperator" ),
  1013. g_pDataModel->GetSymbol( "DmeRigOrientConstraintOperator" ),
  1014. g_pDataModel->GetSymbol( "DmeRigAimConstraintOperator" ),
  1015. g_pDataModel->GetSymbol( "DmeRigRotationConstraintOperator" ),
  1016. g_pDataModel->GetSymbol( "DmeRigParentConstraintOperator" ),
  1017. g_pDataModel->GetSymbol( "DmeRigIKConstraintOperator" ),
  1018. };
  1019. static const int nNumConstraintOperators = sizeof( rigSym ) / sizeof( CUtlSymbolLarge );
  1020. CUtlSymbolLarge elementSym = pElement->GetType();
  1021. for ( int i = 0; i < nNumConstraintOperators; ++i )
  1022. {
  1023. if ( elementSym == rigSym[ i ] )
  1024. return true;
  1025. }
  1026. return false;
  1027. }
  1028. bool Update15( CDmElement *pElement )
  1029. {
  1030. const static CUtlSymbolLarge dmeDagSym = g_pDataModel->GetSymbol( "DmeDag" );
  1031. if ( pElement->GetType() == dmeDagSym )
  1032. {
  1033. pElement->RemoveAttribute( "parentConstraint" );
  1034. }
  1035. else if ( IsRigConstraint( pElement ) )
  1036. {
  1037. pElement->RemoveAttribute( "embeddedTarget" );
  1038. }
  1039. return true;
  1040. }
  1041. void CollectAnimSetsAndDestroyAnimSetGroups( CDmrElementArray< CDmElement > animationSets, CDmElement *pSrcAnimSetGroup )
  1042. {
  1043. if ( !pSrcAnimSetGroup || !animationSets.IsValid() )
  1044. return;
  1045. CDmrElementArray< CDmElement > srcAnimationSets( pSrcAnimSetGroup, "animationSets" );
  1046. int nAnimationSets = srcAnimationSets.IsValid() ? srcAnimationSets.Count() : 0;
  1047. for ( int i = 0; i < nAnimationSets; ++i )
  1048. {
  1049. if ( CDmElement *pAnimSet = srcAnimationSets[ i ] )
  1050. {
  1051. animationSets.AddToTail( pAnimSet );
  1052. }
  1053. }
  1054. CDmrElementArray< CDmElement > children( pSrcAnimSetGroup, "children" );
  1055. int nChildren = children.IsValid() ? children.Count() : 0;
  1056. for ( int i = 0; i < nChildren; ++i )
  1057. {
  1058. CollectAnimSetsAndDestroyAnimSetGroups( animationSets, children[ i ] );
  1059. }
  1060. DestroyElement( pSrcAnimSetGroup );
  1061. }
  1062. //-----------------------------------------------------------------------------
  1063. // eliminating animationsetsgroups and moving their animationsets to a single filmclip attribute
  1064. //-----------------------------------------------------------------------------
  1065. bool Update14( CDmElement *pElement )
  1066. {
  1067. const static CUtlSymbolLarge filmClipSym = g_pDataModel->GetSymbol( "DmeFilmClip" );
  1068. if ( pElement->GetType() == filmClipSym )
  1069. {
  1070. CDmrElementArray< CDmElement > animationSets( pElement, "animationSets", true );
  1071. CDmrElementArray< CDmElement > animSetGroups( pElement, "animationSetGroups" );
  1072. int nAnimSetGroups = animSetGroups.IsValid() ? animSetGroups.Count() : 0;
  1073. for ( int i = 0; i < nAnimSetGroups; ++i )
  1074. {
  1075. CollectAnimSetsAndDestroyAnimSetGroups( animationSets, animSetGroups[ i ] );
  1076. }
  1077. pElement->RemoveAttribute( "animationSetGroups" );
  1078. }
  1079. return true;
  1080. }
  1081. // this works because both CDmeFilmClip and CDmeAnimationSetGroup have an element array called "bookmarks" that is being replaced
  1082. void CreateBookmarkSetAndMoveBookmarks( CDmrElementArray< CDmElement > bookmarkSets, CDmElement *pSrcElement, const char *pSetName, bool bForce )
  1083. {
  1084. CDmAttribute *pSrcBookmarks = pSrcElement->GetAttribute( "bookmarks" );
  1085. CDmrElementArray< CDmElement > srcBookmarks( pSrcBookmarks );
  1086. if ( bForce || ( srcBookmarks.IsValid() && srcBookmarks.Count() > 0 ) )
  1087. {
  1088. CDmElement *pOwner = bookmarkSets.GetAttribute()->GetOwner();
  1089. CDmElement *pBookmarkSet = CreateElement< CDmElement >( "DmeBookmarkSet", pSetName, pOwner->GetFileId() );
  1090. pBookmarkSet->SetParity( pOwner->GetParity() );
  1091. bookmarkSets.AddToTail( pBookmarkSet );
  1092. CDmAttribute *pSetBookmarks = pBookmarkSet->AddAttribute( "bookmarks", AT_ELEMENT_ARRAY );
  1093. if ( pSrcBookmarks && pSetBookmarks )
  1094. {
  1095. pSetBookmarks->SetValue( pSrcBookmarks );
  1096. }
  1097. }
  1098. pSrcElement->RemoveAttributeByPtr( pSrcBookmarks );
  1099. }
  1100. void MoveBookmarksFromAnimSetGroups( CDmrElementArray< CDmElement > bookmarkSets, CDmElement *pSrcAnimSetGroup )
  1101. {
  1102. if ( !pSrcAnimSetGroup || !bookmarkSets.IsValid() )
  1103. return;
  1104. CreateBookmarkSetAndMoveBookmarks( bookmarkSets, pSrcAnimSetGroup, pSrcAnimSetGroup->GetName(), false );
  1105. CDmrElementArray< CDmElement > children( pSrcAnimSetGroup, "children" );
  1106. int nChildren = children.IsValid() ? children.Count() : 0;
  1107. for ( int i = 0; i < nChildren; ++i )
  1108. {
  1109. MoveBookmarksFromAnimSetGroups( bookmarkSets, children[ i ] );
  1110. }
  1111. }
  1112. //-----------------------------------------------------------------------------
  1113. // moving bookmarks from filmclip and animsetionsetgroup to bookmarkset
  1114. // and adding bookmarksets to filmclip to allow named sets of bookmarks,
  1115. // and in preparation for removing animationsetgroups
  1116. //-----------------------------------------------------------------------------
  1117. bool Update13( CDmElement *pElement )
  1118. {
  1119. const static CUtlSymbolLarge filmClipSym = g_pDataModel->GetSymbol( "DmeFilmClip" );
  1120. if ( pElement->GetType() == filmClipSym )
  1121. {
  1122. pElement->SetValue( "activeBookmarkSet", 0 );
  1123. CDmrElementArray< CDmElement > bookmarkSets( pElement, "bookmarkSets", true );
  1124. CreateBookmarkSetAndMoveBookmarks( bookmarkSets, pElement, "default set", true );
  1125. CDmrElementArray< CDmElement > animSetGroups( pElement, "animationSetGroups" );
  1126. int nAnimSetGroups = animSetGroups.IsValid() ? animSetGroups.Count() : 0;
  1127. for ( int i = 0; i < nAnimSetGroups; ++i )
  1128. {
  1129. MoveBookmarksFromAnimSetGroups( bookmarkSets, animSetGroups[ i ] );
  1130. }
  1131. }
  1132. return true;
  1133. }
  1134. //-----------------------------------------------------------------------------
  1135. // moving displaySets from animsetionsetgroup to animationset in preparation for removing animationsetgroups
  1136. //-----------------------------------------------------------------------------
  1137. bool Update12( CDmElement *pElement )
  1138. {
  1139. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1140. const static CUtlSymbolLarge animSetGroupSym = g_pDataModel->GetSymbol( "DmeAnimationSetGroup" );
  1141. const static CUtlSymbolLarge controlDisplaySetSym = g_pDataModel->GetSymbol( "DmeControlDisplaySet" );
  1142. const static CUtlSymbolLarge displaySetSym = g_pDataModel->GetSymbol( "displaySet" );
  1143. const static CUtlSymbolLarge controlsSym = g_pDataModel->GetSymbol( "controls" );
  1144. if ( pElement->GetType() == animSetGroupSym )
  1145. {
  1146. CDmrElementArray<> displaySets( pElement, "displaySets" );
  1147. int nDisplaySets = displaySets.IsValid() ? displaySets.Count() : 0;
  1148. for ( int di = 0; di < nDisplaySets; ++di )
  1149. {
  1150. CDmElement *pDisplaySet = displaySets[ di ];
  1151. if ( !pDisplaySet )
  1152. continue;
  1153. // gather controls referencing the displayset
  1154. CUtlVector< CDmElement* > controls;
  1155. FindReferringElements( controls, pDisplaySet, displaySetSym );
  1156. // gather animationsets referencing those controls
  1157. CUtlVector< CDmElement* > animsets;
  1158. int nControls = controls.Count();
  1159. for ( int ci = 0; ci < nControls; ++ci )
  1160. {
  1161. CDmElement *pControl = controls[ ci ];
  1162. if ( !pControl )
  1163. continue;
  1164. CUtlVector< CDmElement* > controlGroupsAndAnimationSets;
  1165. FindReferringElements( controlGroupsAndAnimationSets, pControl, controlsSym );
  1166. int nControlGroupsAndAnimationSets = controlGroupsAndAnimationSets.Count();
  1167. for ( int gi = 0; gi < nControlGroupsAndAnimationSets; ++gi )
  1168. {
  1169. CDmElement *pGroupOrAnimSet = controlGroupsAndAnimationSets[ gi ];
  1170. if ( !pGroupOrAnimSet || pGroupOrAnimSet->GetType() != animSetSym )
  1171. continue;
  1172. if ( animsets.Find( pGroupOrAnimSet ) < 0 )
  1173. {
  1174. animsets.AddToTail( pGroupOrAnimSet );
  1175. }
  1176. }
  1177. }
  1178. // add displayset to gathered animationsets (and replace controls' displaysets with new copy if needed)
  1179. int nAnimSets = animsets.Count();
  1180. for ( int ai = 0; ai < nAnimSets; ++ai )
  1181. {
  1182. CDmElement *pAnimSet = animsets[ ai ];
  1183. CDmElement *pNewDisplaySet = pDisplaySet;
  1184. if ( ai > 0 )
  1185. {
  1186. // copy displayset
  1187. pNewDisplaySet = pDisplaySet->Copy( TD_SHALLOW );
  1188. pNewDisplaySet->SetParity( pElement->GetParity(), TD_SHALLOW );
  1189. // replace displayset with copy on each control in this animationset
  1190. CDmrElementArray<> controls( pAnimSet, "controls" );
  1191. int nControls = controls.Count();
  1192. for ( int ci = 0; ci < nControls; ++ci )
  1193. {
  1194. CDmElement *pControl = controls[ ci ];
  1195. if ( !pControl )
  1196. continue;
  1197. if ( pControl->GetValueElement< CDmElement >( "displaySet" ) == pDisplaySet )
  1198. {
  1199. pControl->SetValue( "displaySet", pNewDisplaySet );
  1200. }
  1201. }
  1202. }
  1203. // add displayset (or copy) to animationset
  1204. CDmrElementArray<> newDisplaySets( pAnimSet, "displaySets", true );
  1205. newDisplaySets.AddToTail( pNewDisplaySet );
  1206. }
  1207. }
  1208. // remove displaysets attribute from animationsetgroup
  1209. pElement->RemoveAttribute( "displaySets" );
  1210. }
  1211. return true;
  1212. }
  1213. //-----------------------------------------------------------------------------
  1214. // Purpose: Remove redundant attributes in animationset controls to save memory
  1215. //-----------------------------------------------------------------------------
  1216. bool Update11( CDmElement *pElement )
  1217. {
  1218. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1219. if ( pElement->GetType() == animSetSym )
  1220. {
  1221. CDmrElementArray<> controls( pElement, "controls" );
  1222. Assert( controls.IsValid() );
  1223. if ( !controls.IsValid() )
  1224. return false;
  1225. int nControls = controls.Count();
  1226. for ( int i = 0; i < nControls; ++i )
  1227. {
  1228. CDmElement *pControl = controls[ i ];
  1229. if ( !pControl )
  1230. continue;
  1231. if ( pControl->HasAttribute( "combo" ) )
  1232. {
  1233. if ( pControl->GetValue< bool >( "combo" ) )
  1234. {
  1235. float flDefaultLeftValue = pControl->GetValue< float >( "defaultLeftValue" );
  1236. float flDefaultRightValue = pControl->GetValue< float >( "defaultRightValue" );
  1237. pControl->SetValue( "defaultValue", 0.5f * ( flDefaultLeftValue + flDefaultRightValue ) );
  1238. pControl->RemoveAttribute( "value" );
  1239. pControl->RemoveAttribute( "channel" );
  1240. }
  1241. else
  1242. {
  1243. pControl->RemoveAttribute( "rightValue" );
  1244. pControl->RemoveAttribute( "leftValue" );
  1245. pControl->RemoveAttribute( "rightvaluechannel" );
  1246. pControl->RemoveAttribute( "leftvaluechannel" );
  1247. }
  1248. pControl->RemoveAttribute( "combo" );
  1249. pControl->RemoveAttribute( "defaultLeftValue" );
  1250. pControl->RemoveAttribute( "defaultRightValue" );
  1251. }
  1252. else
  1253. {
  1254. if ( !pControl->GetValue< bool >( "isPosition" ) )
  1255. {
  1256. pControl->RemoveAttribute( "position" );
  1257. pControl->RemoveAttribute( "valuePosition" );
  1258. }
  1259. if ( !pControl->GetValue< bool >( "isOrientation" ) )
  1260. {
  1261. pControl->RemoveAttribute( "orientation" );
  1262. pControl->RemoveAttribute( "valueOrientation" );
  1263. }
  1264. pControl->RemoveAttribute( "transform" );
  1265. pControl->RemoveAttribute( "isPosition" );
  1266. pControl->RemoveAttribute( "isOrientation" );
  1267. }
  1268. }
  1269. }
  1270. return true;
  1271. }
  1272. //-----------------------------------------------------------------------------
  1273. // Purpose: Create a control group with the specified name and add it to the
  1274. // provided parent if the parent is a DmeControlGroup.
  1275. //-----------------------------------------------------------------------------
  1276. CDmElement *CreateControlGroup( const char *pchName, CDmElement *pParent )
  1277. {
  1278. const static CUtlSymbolLarge controlGroupSym = g_pDataModel->GetSymbol( "DmeControlGroup" );
  1279. CDmElement *pGroup = CreateElement< CDmElement >( "DmeControlGroup", pchName, pParent->GetFileId() );
  1280. pGroup->SetParity( pParent->GetParity() );
  1281. pGroup->AddAttribute( "children", AT_ELEMENT_ARRAY );
  1282. pGroup->AddAttribute( "controls", AT_ELEMENT_ARRAY );
  1283. pGroup->SetValue< Color >( "groupColor", Color( 200, 200, 200, 255 ) );
  1284. pGroup->SetValue< Color >( "controlColor", Color( 200, 200, 200, 255 ) );
  1285. if ( pParent->GetType() == controlGroupSym )
  1286. {
  1287. CDmAttribute *pChildrenAttr = pParent->GetAttribute( "children", AT_ELEMENT_ARRAY );
  1288. CDmrElementArray<> childList( pChildrenAttr );
  1289. childList.AddToTail( pGroup );
  1290. }
  1291. return pGroup;
  1292. }
  1293. #define MULTI_CONTROL_FORMAT_STRING "multi_%s"
  1294. bool ConvertControlGroup_R( CDmrElementArray<> &animSetControls, CDmElement *pControlGroup )
  1295. {
  1296. if ( !pControlGroup )
  1297. return true;
  1298. CDmrElementArray<> children( pControlGroup, "children" );
  1299. int nChildren = children.Count();
  1300. for ( int i = 0; i < nChildren; ++i )
  1301. {
  1302. ConvertControlGroup_R( animSetControls, children[ i ] );
  1303. }
  1304. CDmrElementArray<> controls( pControlGroup, "controls" );
  1305. Assert( controls.IsValid() );
  1306. if ( !controls.IsValid() )
  1307. return true;
  1308. int nControls = controls.Count();
  1309. for ( int i = 0; i < nControls; ++i )
  1310. {
  1311. CDmElement *pControl = controls[ i ];
  1312. if ( !pControl )
  1313. continue;
  1314. if ( pControl->GetValue< bool >( "multi" ) )
  1315. {
  1316. CDmElement *pMultiChannel = pControl->GetValueElement< CDmElement >( "multilevelchannel" );
  1317. Assert( pMultiChannel );
  1318. if ( pMultiChannel )
  1319. {
  1320. // create new multi control
  1321. char multiName[ 256 ];
  1322. V_snprintf( multiName, sizeof( multiName ), MULTI_CONTROL_FORMAT_STRING, pControl->GetName() );
  1323. CDmElement *pMultiControl = CreateElement< CDmElement >( "DmElement", multiName, pControl->GetFileId() );
  1324. pMultiControl->SetParity( pControlGroup->GetParity() );
  1325. pMultiControl->SetValue( "value", pControl->GetValue< float >( "multilevel" ) );
  1326. pMultiControl->SetValue( "defaultValue", pControl->GetValue< float >( "defaultMultilevel" ) );
  1327. pMultiControl->SetValue( "channel", pMultiChannel );
  1328. // add multi control to animset's flat control list
  1329. int j = animSetControls.Find( pControl );
  1330. if ( j < 0 )
  1331. return false;
  1332. // WARNING: this isn't a great practice, since it's technically possible that we're iterating controls,
  1333. // but some control's channel would have to reference a control group (with multi controls) for that to be true
  1334. animSetControls.Remove( j );
  1335. animSetControls.InsertBefore( 0, pControl );
  1336. animSetControls.InsertBefore( 1, pMultiControl );
  1337. // update channel to point to new element
  1338. pMultiChannel->SetValue( "fromElement", pMultiControl );
  1339. pMultiChannel->SetValue( "fromAttribute", "value" );
  1340. // create control group to contain both controls and add it to the parent group
  1341. CDmElement *pNewControlGroup = CreateControlGroup( pControl->GetName(), pControlGroup );
  1342. // add original and multi control to new control group
  1343. CDmrElementArray<> newControls( pNewControlGroup, "controls" );
  1344. if ( !newControls.IsValid() )
  1345. return false;
  1346. newControls.AddToTail( pControl );
  1347. newControls.AddToTail( pMultiControl );
  1348. // remove original control from its old parent group
  1349. controls.Remove( i );
  1350. --i; --nControls;
  1351. }
  1352. }
  1353. // remove multi-related attributes from original control
  1354. pControl->RemoveAttribute( "multi" );
  1355. pControl->RemoveAttribute( "multilevel" );
  1356. pControl->RemoveAttribute( "defaultMultilevel" );
  1357. pControl->RemoveAttribute( "multilevelchannel" );
  1358. }
  1359. return true;
  1360. }
  1361. //-----------------------------------------------------------------------------
  1362. // Purpose: Convert multi controls into a control group and two controls
  1363. //-----------------------------------------------------------------------------
  1364. bool Update10( CDmElement *pElement )
  1365. {
  1366. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1367. const static CUtlSymbolLarge presetSym = g_pDataModel->GetSymbol( "DmePreset" );
  1368. if ( pElement->GetType() == animSetSym )
  1369. {
  1370. CDmrElementArray<> controls( pElement, "controls" );
  1371. Assert( controls.IsValid() );
  1372. if ( !controls.IsValid() )
  1373. return false;
  1374. ConvertControlGroup_R( controls, pElement->GetValueElement< CDmElement >( "rootControlGroup" ) );
  1375. }
  1376. else if ( pElement->GetType() == presetSym )
  1377. {
  1378. CDmrElementArray<> controlValues( pElement, "controlValues" );
  1379. Assert( controlValues.IsValid() );
  1380. if ( !controlValues.IsValid() )
  1381. return true;
  1382. int nControls = controlValues.Count();
  1383. for ( int ci = 0; ci < nControls; ++ci )
  1384. {
  1385. CDmElement *pControlValue = controlValues[ ci ];
  1386. if ( !pControlValue )
  1387. continue;
  1388. CDmAttribute *pAttr = pControlValue->GetAttribute( "multilevel", AT_FLOAT );
  1389. if ( !pAttr )
  1390. continue;
  1391. // create new multi control value
  1392. char multiName[ 256 ];
  1393. V_snprintf( multiName, sizeof( multiName ), MULTI_CONTROL_FORMAT_STRING, pControlValue->GetName() );
  1394. CDmElement *pMultiControlValue = CreateElement< CDmElement >( "DmElement", multiName, pControlValue->GetFileId() );
  1395. pMultiControlValue->SetParity( pElement->GetParity() );
  1396. pMultiControlValue->SetValue( "value", pAttr->GetValue< float >() );
  1397. controlValues.InsertBefore( ci + 1, pMultiControlValue );
  1398. ++ci; ++nControls;
  1399. // remove multilevel attribute from original control
  1400. pControlValue->RemoveAttributeByPtr( pAttr );
  1401. }
  1402. }
  1403. return true;
  1404. }
  1405. //-------------------------------------------------------------------------------------------------
  1406. // Update9 -- AnimationSet DmElement to DmeControlGroup conversion
  1407. //-------------------------------------------------------------------------------------------------
  1408. //-----------------------------------------------------------------------------
  1409. // Purpose: Find the control in the animation set with the specified name
  1410. //-----------------------------------------------------------------------------
  1411. CDmElement *FindAnimSetControl( CDmElement* pAnimSet, const char *pchControlName )
  1412. {
  1413. CDmAttribute *pControlsAttr = pAnimSet->GetAttribute( "controls" );
  1414. if ( pControlsAttr == NULL )
  1415. return NULL;
  1416. CDmrElementArray<> controls( pControlsAttr );
  1417. int nControls = controls.Count();
  1418. for ( int iControl = 0; iControl < nControls; ++iControl )
  1419. {
  1420. CDmElement *pElement = controls[ iControl ];
  1421. if ( pElement )
  1422. {
  1423. if ( V_stricmp( pchControlName, pElement->GetName() ) == 0 )
  1424. {
  1425. return pElement;
  1426. }
  1427. }
  1428. }
  1429. return NULL;
  1430. }
  1431. //-----------------------------------------------------------------------------
  1432. // Purpose: Recursively convert the generic DmElement selection group and its
  1433. // children into a DmeControlGroup
  1434. //-----------------------------------------------------------------------------
  1435. void ConvertSelectionGroup_R( CDmElement* pAnimSet, CDmElement *pParentControlGroup, CDmElement *pSelectionElement )
  1436. {
  1437. if ( ( pAnimSet == NULL ) || ( pParentControlGroup == NULL ) || ( pSelectionElement == NULL ) )
  1438. return;
  1439. bool isGroup = pSelectionElement->GetValue< bool >( "isGroup" );
  1440. if ( isGroup )
  1441. {
  1442. // Create a control group and add it to the parent group.
  1443. CDmElement *pControlGroup = CreateControlGroup( pSelectionElement->GetName(), pParentControlGroup );
  1444. if ( pControlGroup )
  1445. {
  1446. // Copy the tree color of the element to the group color of the control group
  1447. if ( pSelectionElement->HasAttribute( "treeColor", AT_COLOR ) )
  1448. {
  1449. pControlGroup->SetValue< Color >( "groupColor", pSelectionElement->GetValue< Color >( "treeColor" ) );
  1450. }
  1451. // Process the children of the selection element group
  1452. CDmAttribute *pSelectionControlsAttr = pSelectionElement->GetAttribute( "controls" );
  1453. if ( pSelectionControlsAttr )
  1454. {
  1455. CDmrElementArray<> children( pSelectionControlsAttr );
  1456. int nChildren = children.Count();
  1457. for ( int iChild = 0; iChild < nChildren; ++iChild )
  1458. {
  1459. CDmElement *pChild = children[ iChild ];
  1460. ConvertSelectionGroup_R( pAnimSet, pControlGroup, pChild );
  1461. }
  1462. }
  1463. }
  1464. }
  1465. else
  1466. {
  1467. // If the selection element is not a group, it is a control selection element which shares
  1468. // its name with the control it targets. Find that control and add it to the parent group.
  1469. CDmElement *pControl = FindAnimSetControl( pAnimSet, pSelectionElement->GetName() );
  1470. if ( pControl )
  1471. {
  1472. CDmAttribute *pControlsAttr = pParentControlGroup->GetAttribute( "controls" );
  1473. if ( pControlsAttr )
  1474. {
  1475. CDmrElementArray<> controls( pControlsAttr );
  1476. controls.AddToTail( pControl );
  1477. }
  1478. }
  1479. }
  1480. }
  1481. //-----------------------------------------------------------------------------
  1482. // Purpose: Convert the animation set selection group DmElements into
  1483. // DmeControlGroups. Removes "selectionGroups" and creates "rootControlGroup"
  1484. //-----------------------------------------------------------------------------
  1485. bool Update9( CDmElement *pElement )
  1486. {
  1487. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1488. if ( pElement->GetType() == animSetSym )
  1489. {
  1490. CDmElement* pAnimSet = pElement;
  1491. // Create the root selection group
  1492. CDmElement *pRootGroup = CreateControlGroup( "rootGroup", pAnimSet );
  1493. pAnimSet->SetValue( "rootControlGroup", pRootGroup );
  1494. // Iterate through the selection DmElement groups and recursively
  1495. // convert them to them to the DmeControlGroup format.
  1496. CDmAttribute *pSelectionGroupsAttr = pAnimSet->GetAttribute( "selectionGroups", AT_ELEMENT_ARRAY );
  1497. if ( pSelectionGroupsAttr )
  1498. {
  1499. CDmrElementArray<> controls( pSelectionGroupsAttr );
  1500. int nControls = controls.Count();
  1501. for ( int ci = 0; ci < nControls; ++ci )
  1502. {
  1503. CDmElement *pSelectionElement = controls[ ci ];
  1504. if ( !pSelectionElement )
  1505. continue;
  1506. // Convert the generic DmElement group into a DmeControlGroup
  1507. ConvertSelectionGroup_R( pAnimSet, pRootGroup, pSelectionElement );
  1508. // Destroy the generic DmElement group
  1509. DestroyElement( pSelectionElement );
  1510. }
  1511. }
  1512. // Remove the selection groups list
  1513. pAnimSet->RemoveAttributeByPtr( pSelectionGroupsAttr );
  1514. }
  1515. return true;
  1516. }
  1517. //-------------------------------------------------------------------------------------------------
  1518. //-------------------------------------------------------------------------------------------------
  1519. //-----------------------------------------------------------------------------
  1520. // Purpose: Change DmeModel.jointTransforms to DmeModel.jointList
  1521. //-----------------------------------------------------------------------------
  1522. bool Update8( CDmElement *pElement )
  1523. {
  1524. const static CUtlSymbolLarge modelSetSym = g_pDataModel->GetSymbol( "DmeModel" );
  1525. CUtlSymbolLarge typeSym = pElement->GetType();
  1526. if ( typeSym == modelSetSym )
  1527. {
  1528. CDmAttribute *pJointTransformsAttr = pElement->GetAttribute( "jointTransforms", AT_ELEMENT_ARRAY );
  1529. if ( pJointTransformsAttr )
  1530. {
  1531. CDmAttribute *pJointListAttr = pElement->GetAttribute( "jointList", AT_ELEMENT_ARRAY );
  1532. if ( !pJointListAttr )
  1533. {
  1534. pJointListAttr = pElement->AddAttribute( "jointList", AT_ELEMENT_ARRAY );
  1535. }
  1536. if ( pJointListAttr )
  1537. {
  1538. const static CUtlSymbolLarge transformSym = g_pDataModel->GetSymbol( "transform" );
  1539. const static CUtlSymbolLarge dmeJointSym = g_pDataModel->GetSymbol( "DmeJoint" );
  1540. const static CUtlSymbolLarge dmeDagSym = g_pDataModel->GetSymbol( "DmeDag" );
  1541. CUtlVector< CDmElement * > refList;
  1542. CDmrElementArray<> jt( pJointTransformsAttr );
  1543. CDmrElementArray<> jl( pJointListAttr );
  1544. jl.RemoveAll();
  1545. const int nJointCount = jt.Count();
  1546. for ( int ji = 0; ji < nJointCount; ++ji )
  1547. {
  1548. refList.RemoveAll();
  1549. if ( FindReferringElements( refList, jt[ ji ], transformSym ) )
  1550. {
  1551. const int nRefCount = refList.Count();
  1552. for ( int ri = 0; ri < nRefCount; ++ri )
  1553. {
  1554. typeSym = refList[ ri ]->GetType();
  1555. if ( typeSym == dmeJointSym || typeSym == dmeDagSym )
  1556. {
  1557. jl.AddToTail( refList[ ri ] );
  1558. break;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. pElement->RemoveAttribute( "jointTransforms" );
  1564. }
  1565. }
  1566. }
  1567. return true;
  1568. }
  1569. //-----------------------------------------------------------------------------
  1570. // Purpose: Convert base control elements with the "transform" flag set into
  1571. // CDmeTransformControl elements and remove the obsolete attributes from the
  1572. // element which are now part of the CDmeTransfrom control class.
  1573. //-----------------------------------------------------------------------------
  1574. bool Update7( CDmElement *pElement )
  1575. {
  1576. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1577. CUtlSymbolLarge typeSym = pElement->GetType();
  1578. if ( typeSym == animSetSym )
  1579. {
  1580. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  1581. if ( pControlsAttr )
  1582. {
  1583. CDmrElementArray<> controls( pControlsAttr );
  1584. int nControls = controls.Count();
  1585. for ( int ci = 0; ci < nControls; ++ci )
  1586. {
  1587. CDmElement *pControl = controls[ ci ];
  1588. if ( !pControl )
  1589. continue;
  1590. if ( pControl->GetValue<bool>( "transform", false ) )
  1591. {
  1592. // Remove the obsolete attributes that are now part of the transform control class
  1593. pControl->RemoveAttribute( "valueTransform" );
  1594. pControl->RemoveAttribute( "valueDeltaRotation" );
  1595. pControl->RemoveAttribute( "valuePivot" );
  1596. pControl->RemoveAttribute( "pivotOffset" );
  1597. pControl->RemoveAttribute( "refOrientation" );
  1598. // Change the element type to specify a CDmeTransformControl
  1599. pControl->SetType( "DmeTransformControl" );
  1600. }
  1601. }
  1602. }
  1603. }
  1604. return true;
  1605. }
  1606. bool Update6( CDmElement *pElement )
  1607. {
  1608. CUtlSymbolLarge typeSym = pElement->GetType();
  1609. const static CUtlSymbolLarge grainFXClipSym = g_pDataModel->GetSymbol( "DmeHSLGrainFXClip" );
  1610. if ( typeSym == grainFXClipSym )
  1611. {
  1612. pElement->RemoveAttribute( "scale" );
  1613. pElement->RemoveAttribute( "left" );
  1614. pElement->RemoveAttribute( "top" );
  1615. pElement->RemoveAttribute( "width" );
  1616. pElement->RemoveAttribute( "height" );
  1617. return true;
  1618. }
  1619. const static CUtlSymbolLarge dirLightSym = g_pDataModel->GetSymbol( "DmeDirectionalLight" );
  1620. const static CUtlSymbolLarge pointLightSym = g_pDataModel->GetSymbol( "DmePointLight" );
  1621. const static CUtlSymbolLarge spotLightSym = g_pDataModel->GetSymbol( "DmeSpotLight" );
  1622. const static CUtlSymbolLarge projLightSym = g_pDataModel->GetSymbol( "DmeProjectedLight" );
  1623. if ( typeSym == dirLightSym || typeSym == pointLightSym || typeSym == spotLightSym || typeSym == projLightSym )
  1624. {
  1625. Vector pos = pElement->GetValue< Vector >( "position" );
  1626. Vector dir = pElement->GetValue< Vector >( "direction" );
  1627. Quaternion quat = pElement->GetValue< Quaternion >( "orientation" );
  1628. if ( dir != vec3_origin )
  1629. {
  1630. // HACK - there's some question here as to whether to use VectorAngles, which assumes forward is 1,0,0,
  1631. // or to compute the 0,0,1->dir quaternion manually, but since dirlights aren't used anyways, I'm not worrying about it
  1632. QAngle angles;
  1633. VectorAngles( dir, angles );
  1634. AngleQuaternion( angles, quat );
  1635. }
  1636. CDmElement *pTransform = pElement->GetValueElement< CDmElement >( "transform" );
  1637. if ( !pTransform )
  1638. {
  1639. pTransform = CreateElement< CDmElement >( "DmeTransform", "transform", pElement->GetFileId() );
  1640. pTransform->SetParity( pElement->GetParity() );
  1641. pElement->SetValue( "transform", pTransform );
  1642. }
  1643. Vector parentPos = pTransform->GetValue< Vector >( "position" );
  1644. Quaternion parentQuat = pTransform->GetValue< Quaternion >( "orientation" );
  1645. Vector finalPos;
  1646. Quaternion finalQuat;
  1647. ConcatTransforms( parentQuat, parentPos, quat, pos, finalQuat, finalPos );
  1648. pTransform->SetValue( "position", finalPos );
  1649. pTransform->SetValue( "orientation", finalQuat );
  1650. // NOTE - not bothering to convert logs on transform, since up until this change, updating the light's transform didn't do anything
  1651. CDmElement *pPosChannel = FindChannelTargettingElement( pElement, "position", false );
  1652. CDmElement *pPosLog = pPosChannel ? GetLogLayerFromChannel( pPosChannel ) : NULL;
  1653. if ( pPosLog )
  1654. {
  1655. Quaternion qDummy;
  1656. Vector temp;
  1657. CDmAttribute *pAttr = pPosLog->GetAttribute( "values", AT_VECTOR3_ARRAY );
  1658. CDmrArray< Vector > values( pAttr );
  1659. int nValues = values.Count();
  1660. for ( int i = 0; i < nValues; ++i )
  1661. {
  1662. ConcatTransforms( parentQuat, parentPos, quat_identity, values[ i ], qDummy, temp );
  1663. values.Set( i, temp );
  1664. }
  1665. pPosChannel->SetValue( "toElement", pTransform );
  1666. }
  1667. CDmElement *pRotChannel = FindChannelTargettingElement( pElement, "orientation", false );
  1668. CDmElement *pRotLog = pRotChannel ? GetLogLayerFromChannel( pRotChannel ) : NULL;
  1669. if ( pRotLog )
  1670. {
  1671. Quaternion temp;
  1672. Vector vDummy;
  1673. CDmAttribute *pAttr = pRotLog->GetAttribute( "values", AT_QUATERNION_ARRAY );
  1674. CDmrArray< Quaternion > values( pAttr );
  1675. int nValues = values.Count();
  1676. for ( int i = 0; i < nValues; ++i )
  1677. {
  1678. ConcatTransforms( parentQuat, parentPos, values[ i ], vec3_origin, temp, vDummy );
  1679. values.Set( i, temp );
  1680. }
  1681. pRotChannel->SetValue( "toElement", pTransform );
  1682. }
  1683. pElement->RemoveAttribute( "position" );
  1684. pElement->RemoveAttribute( "direction" );
  1685. pElement->RemoveAttribute( "orientation" );
  1686. return true;
  1687. }
  1688. return true;
  1689. }
  1690. bool Update4( CDmElement *pElement )
  1691. {
  1692. const static CUtlSymbolLarge filmClipSym = g_pDataModel->GetSymbol( "DmeFilmClip" );
  1693. const static CUtlSymbolLarge presetGroupSym = g_pDataModel->GetSymbol( "DmePresetGroup" );
  1694. CUtlSymbolLarge typeSym = pElement->GetType();
  1695. if ( typeSym == presetGroupSym )
  1696. {
  1697. CDmElement *pPresetRemap = pElement->GetValueElement< CDmElement >( "presetRemap" );
  1698. if ( pPresetRemap )
  1699. {
  1700. DestroyElement( pPresetRemap, TD_NONE );
  1701. }
  1702. pElement->RemoveAttribute( "presetRemap" );
  1703. }
  1704. if ( typeSym != filmClipSym )
  1705. return true;
  1706. CDmAttribute *pClipAnimSetsAttr = pElement->GetAttribute( "animationSets", AT_ELEMENT_ARRAY );
  1707. Assert( pClipAnimSetsAttr );
  1708. if ( !pClipAnimSetsAttr )
  1709. return true;
  1710. CDmrElementArray<> clipAnimSets( pClipAnimSetsAttr );
  1711. CDmAttribute *pAnimSetGroupsAttr = pElement->AddAttribute( "animationSetGroups", AT_ELEMENT_ARRAY );
  1712. Assert( pAnimSetGroupsAttr );
  1713. if ( !pAnimSetGroupsAttr )
  1714. return true;
  1715. CDmrElementArray<> animSetGroups( pAnimSetGroupsAttr );
  1716. int nClipAnimSets = clipAnimSets.Count();
  1717. for ( int i = 0; i < nClipAnimSets; ++i )
  1718. {
  1719. CDmElement *pAnimSet = clipAnimSets[ i ];
  1720. if ( !pAnimSet )
  1721. {
  1722. animSetGroups.AddToTail( NULL );
  1723. continue;
  1724. }
  1725. CDmElement *pAnimSetGroup = CreateElement< CDmElement >( "DmeAnimationSetGroup", pAnimSet->GetName(), pAnimSet->GetFileId() );
  1726. pAnimSetGroup->SetParity( pElement->GetParity() );
  1727. animSetGroups.AddToTail( pAnimSetGroup );
  1728. CDmAttribute *pBookmarksAttr = pAnimSetGroup->AddAttribute( "bookmarks", AT_ELEMENT_ARRAY );
  1729. CDmAttribute *pAnimSetsAttr = pAnimSetGroup->AddAttribute( "animationSets", AT_ELEMENT_ARRAY );
  1730. /*CDmAttribute *pChildrenAttr*/pAnimSetGroup->AddAttribute( "children", AT_ELEMENT_ARRAY );
  1731. CDmrElementArray<> animSets( pAnimSetsAttr );
  1732. animSets.AddToTail( pAnimSet );
  1733. CDmAttribute *pClipBookmarksAttr = pElement->GetAttribute( "bookmarks", AT_ELEMENT_ARRAY );
  1734. Assert( pClipBookmarksAttr );
  1735. if ( pClipBookmarksAttr )
  1736. {
  1737. CDmrElementArray<> clipBookmarks( pClipBookmarksAttr );
  1738. CDmrElementArray<> bookmarks( pBookmarksAttr );
  1739. int nBookmarks = clipBookmarks.Count();
  1740. for ( int bi = 0; bi < nBookmarks; ++bi )
  1741. {
  1742. bookmarks.AddToTail( clipBookmarks[ bi ] );
  1743. }
  1744. }
  1745. pAnimSet->RemoveAttribute( "bookmarks" );
  1746. }
  1747. pElement->RemoveAttribute( "animationSets" );
  1748. return true;
  1749. }
  1750. inline void ValueBalanceToLeftRight( float *pLeft, float *pRight, float flValue, float flBalance, float flDefaultValue )
  1751. {
  1752. *pLeft = ( flBalance <= 0.5f ) ? flValue : ( ( 1.0f - flBalance ) / 0.5f ) * ( flValue - flDefaultValue ) + flDefaultValue;
  1753. *pRight = ( flBalance >= 0.5f ) ? flValue : ( flBalance / 0.5f ) * ( flValue - flDefaultValue ) + flDefaultValue;
  1754. }
  1755. bool ConvertIntArrayToTimeArray( CDmAttribute *pAttribute )
  1756. {
  1757. if ( !pAttribute )
  1758. return false;
  1759. DmAttributeType_t type = pAttribute->GetType();
  1760. if ( type == AT_TIME_ARRAY )
  1761. return true;
  1762. Assert( type == AT_INT_ARRAY );
  1763. if ( type != AT_INT_ARRAY )
  1764. return false;
  1765. pAttribute->ChangeType_UNSAFE( AT_TIME_ARRAY );
  1766. Assert( pAttribute->GetType() == AT_TIME_ARRAY );
  1767. if ( pAttribute->GetType() != AT_TIME_ARRAY )
  1768. return false;
  1769. return true;
  1770. }
  1771. float GetDefaultControlValue( const char *pControlName )
  1772. {
  1773. // HACK - this is nasty, (and not 100% correct - the engineer's BrowInV is 1-way control) but it's either that or manually fix every preset file
  1774. // fortunately, even if this isn't perfect, it's almost undetectable
  1775. // we had to search the movies to find a spot where 0.0f wasn't a good enough default for every control, and the difference wasn't a big deal
  1776. const static char *s_2WayControls[] =
  1777. {
  1778. "TongueWidth",
  1779. "TongueV",
  1780. "TongueH",
  1781. "TongueD",
  1782. "TongueCurl",
  1783. "ScalpD",
  1784. "NostrilFlare",
  1785. "NoseV",
  1786. "LipUpV",
  1787. "LipsV",
  1788. "LipLoV",
  1789. "JawV",
  1790. "JawH",
  1791. "JawD",
  1792. "FoldLipUp",
  1793. "FoldLipLo",
  1794. "CheekH",
  1795. "BrowInV",
  1796. "CloseLid", // this is actually a multi (3-way) control, so it's defaultValue *should* be 0, but due to dmxedit's trickery it's (intentionally???) 0.5
  1797. };
  1798. for ( int i = 0; i < ARRAYSIZE( s_2WayControls ); ++i )
  1799. {
  1800. if ( !V_strcmp( pControlName, s_2WayControls[i] ) )
  1801. return 0.5f;
  1802. }
  1803. return 0.0f;
  1804. }
  1805. bool UpdatePreset( CDmElement *pPreset )
  1806. {
  1807. if ( !pPreset )
  1808. return true;
  1809. CDmAttribute *pControlValuesAttr = pPreset->GetAttribute( "controlValues", AT_ELEMENT_ARRAY );
  1810. if ( !pControlValuesAttr )
  1811. return true;
  1812. const char *pPresetName = pPreset->GetName();
  1813. bool bFixupBalance = !V_stricmp( pPresetName, "zero" ) || !V_stricmp( pPresetName, "one" );
  1814. CDmrElementArray<> controlValues( pControlValuesAttr );
  1815. int nControlValues = controlValues.Count();
  1816. for ( int vi = 0; vi < nControlValues; ++vi )
  1817. {
  1818. CDmElement *pControlValue = controlValues[ vi ];
  1819. if ( !pControlValue )
  1820. return true;
  1821. if ( pControlValue->HasAttribute( "balance" ) )
  1822. {
  1823. float flDefaultValue = GetDefaultControlValue( pControlValue->GetName() );
  1824. float flValue = pControlValue->GetValue< float >( "value" );
  1825. float flBalance = pControlValue->GetValue< float >( "balance" );
  1826. pControlValue->RemoveAttribute( "value" );
  1827. pControlValue->RemoveAttribute( "balance" );
  1828. if ( bFixupBalance )
  1829. {
  1830. flBalance = 0.5f;
  1831. }
  1832. float flLeft, flRight;
  1833. ValueBalanceToLeftRight( &flLeft, &flRight, flValue, flBalance, flDefaultValue );
  1834. pControlValue->SetValue( "leftValue", flLeft );
  1835. pControlValue->SetValue( "rightValue", flRight );
  1836. }
  1837. }
  1838. return true;
  1839. }
  1840. bool Update3( CDmElement *pElement )
  1841. {
  1842. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  1843. const static CUtlSymbolLarge presetSym = g_pDataModel->GetSymbol( "DmePreset" );
  1844. const static CUtlSymbolLarge comboOpSym = g_pDataModel->GetSymbol( "DmeCombinationOperator" );
  1845. const static CUtlSymbolLarge logLayerSym = g_pDataModel->GetSymbol( "DmeLogLayer" );
  1846. const static CUtlSymbolLarge intLogLayerSym = g_pDataModel->GetSymbol( "DmeIntLogLayer" );
  1847. const static CUtlSymbolLarge floatLogLayerSym = g_pDataModel->GetSymbol( "DmeFloatLogLayer" );
  1848. const static CUtlSymbolLarge boolLogLayerSym = g_pDataModel->GetSymbol( "DmeBoolLogLayer" );
  1849. const static CUtlSymbolLarge colorLogLayerSym = g_pDataModel->GetSymbol( "DmeColorLogLayer" );
  1850. const static CUtlSymbolLarge vec2LogLayerSym = g_pDataModel->GetSymbol( "DmeVector2LogLayer" );
  1851. const static CUtlSymbolLarge vec3LogLayerSym = g_pDataModel->GetSymbol( "DmeVector3LogLayer" );
  1852. const static CUtlSymbolLarge vec4LogLayerSym = g_pDataModel->GetSymbol( "DmeVector4LogLayer" );
  1853. const static CUtlSymbolLarge qangleLogLayerSym = g_pDataModel->GetSymbol( "DmeQAngleLogLayer" );
  1854. const static CUtlSymbolLarge quatLogLayerSym = g_pDataModel->GetSymbol( "DmeQuaternionLogLayer" );
  1855. const static CUtlSymbolLarge vmatrixLogLayerSym = g_pDataModel->GetSymbol( "DmeVMatrixLogLayer" );
  1856. const static CUtlSymbolLarge stringLogLayerSym = g_pDataModel->GetSymbol( "DmeStringLogLayer" );
  1857. const static CUtlSymbolLarge timeLogLayerSym = g_pDataModel->GetSymbol( "DmeTimeLogLayer" );
  1858. CUtlSymbolLarge typeSym = pElement->GetType();
  1859. if ( typeSym == logLayerSym
  1860. || typeSym == intLogLayerSym
  1861. || typeSym == floatLogLayerSym
  1862. || typeSym == boolLogLayerSym
  1863. || typeSym == colorLogLayerSym
  1864. || typeSym == vec2LogLayerSym
  1865. || typeSym == vec3LogLayerSym
  1866. || typeSym == vec4LogLayerSym
  1867. || typeSym == qangleLogLayerSym
  1868. || typeSym == quatLogLayerSym
  1869. || typeSym == vmatrixLogLayerSym
  1870. || typeSym == stringLogLayerSym
  1871. || typeSym == timeLogLayerSym )
  1872. {
  1873. return ConvertIntArrayToTimeArray( pElement->GetAttribute( "times" ) );
  1874. }
  1875. if ( typeSym == comboOpSym )
  1876. {
  1877. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  1878. CDmAttribute *pControlValuesAttr = pElement->GetAttribute( "controlValues", AT_VECTOR3_ARRAY );
  1879. CDmAttribute *pControlValuesLaggedAttr = pElement->GetAttribute( "controlValuesLagged", AT_VECTOR3_ARRAY );
  1880. if ( !pControlsAttr || !pControlValuesAttr || !pControlValuesLaggedAttr )
  1881. return false;
  1882. CDmrElementArray<> controls( pControlsAttr );
  1883. CDmrArray< Vector > controlValues( pControlValuesAttr );
  1884. CDmrArray< Vector > controlValuesLagged( pControlValuesLaggedAttr );
  1885. int nControls = controls.Count();
  1886. for ( int i = 0; i < nControls; ++i )
  1887. {
  1888. CDmElement *pControl = controls[ i ];
  1889. if ( !pControl || !pControl->GetValue<bool>( "stereo" ) )
  1890. continue;
  1891. CDmAttribute *pRawControlNames = pControl->GetAttribute( "rawControlNames", AT_STRING_ARRAY );
  1892. if ( !pRawControlNames )
  1893. continue;
  1894. CDmrStringArray rawControlNames( pRawControlNames );
  1895. float flDefaultValue = rawControlNames.Count() == 2 ? 0.5f : 0.0f;
  1896. float flLeftValue, flRightValue;
  1897. Vector cv = controlValues[ i ];
  1898. ValueBalanceToLeftRight( &flLeftValue, &flRightValue, cv.x, cv.y, flDefaultValue );
  1899. controlValues.Set( i, Vector( flLeftValue, flRightValue, cv.z ) );
  1900. Vector cvl = controlValuesLagged[ i ];
  1901. ValueBalanceToLeftRight( &flLeftValue, &flRightValue, cvl.x, cvl.y, flDefaultValue );
  1902. controlValuesLagged.Set( i, Vector( flLeftValue, flRightValue, cvl.z ) );
  1903. }
  1904. return true;
  1905. }
  1906. if ( typeSym == presetSym )
  1907. {
  1908. return UpdatePreset( pElement );
  1909. }
  1910. if ( typeSym == animSetSym )
  1911. {
  1912. CDmElement *pFilmClip = FindReferringElement< CDmElement >( pElement, "animationSets" );
  1913. if ( !pFilmClip )
  1914. return true;
  1915. // remove multi from controls, and move multilevel, defaultMultilevel and multilevelChannel to new _alt control
  1916. // split preset multilevel controlValues into new controlValue
  1917. // put new _alt control into same selection group as original
  1918. // convert stereo controls from value/balance to left/right
  1919. // - convert old VB into new LR, remove VB attributes
  1920. // - convert and copy old VB log data into LR log data, and delete VB channels and logs
  1921. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  1922. if ( pControlsAttr )
  1923. {
  1924. CDmrElementArray<> controls( pControlsAttr );
  1925. int nControls = controls.Count();
  1926. for ( int ci = 0; ci < nControls; ++ci )
  1927. {
  1928. CDmElement *pControl = controls[ ci ];
  1929. if ( !pControl )
  1930. continue;
  1931. if ( !pControl->GetValue<bool>( "multi", false ) )
  1932. {
  1933. // these shouldn't be here anyways, but sometimes they are so...
  1934. pControl->RemoveAttribute( "multilevel" );
  1935. pControl->RemoveAttribute( "defaultMultilevel" );
  1936. pControl->RemoveAttribute( "multilevelchannel" );
  1937. }
  1938. if ( !pControl->GetValue<bool>( "combo", false ) )
  1939. {
  1940. // these shouldn't be here anyways, but sometimes they are so...
  1941. pControl->RemoveAttribute( "balance" );
  1942. pControl->RemoveAttribute( "defaultBalance" );
  1943. pControl->RemoveAttribute( "balancechannel" );
  1944. continue;
  1945. }
  1946. float flValue = pControl->GetValue<float>( "value" );
  1947. float flBalance = pControl->GetValue<float>( "balance" );
  1948. float flDefaultValue = pControl->GetValue<float>( "defaultValue" );
  1949. float flDefaultBalance = pControl->GetValue<float>( "defaultBalance" );
  1950. CDmElement *pValueChannel = pControl->GetValueElement< CDmElement >( "valuechannel" );
  1951. CDmElement *pBalanceChannel = pControl->GetValueElement< CDmElement >( "balancechannel" );
  1952. pControl->RemoveAttribute( "value" );
  1953. pControl->RemoveAttribute( "balance" );
  1954. pControl->RemoveAttribute( "defaultValue" );
  1955. pControl->RemoveAttribute( "defaultBalance" );
  1956. pControl->RemoveAttribute( "valuechannel" );
  1957. pControl->RemoveAttribute( "balancechannel" );
  1958. float flLeftValue, flRightValue;
  1959. ValueBalanceToLeftRight( &flLeftValue, &flRightValue, flValue, flBalance, flDefaultValue );
  1960. pControl->SetValue( "leftValue", flLeftValue );
  1961. pControl->SetValue( "rightValue", flRightValue );
  1962. float flLeftDefaultValue, flRightDefaultValue;
  1963. ValueBalanceToLeftRight( &flLeftDefaultValue, &flRightDefaultValue, flDefaultValue, flDefaultBalance, 0.0f ); // this is kind of silly, since we expect flDefaultBalance to always be 0.5
  1964. pControl->SetValue( "defaultLeftValue", flLeftDefaultValue );
  1965. pControl->SetValue( "defaultRightValue", flRightDefaultValue );
  1966. if ( !pValueChannel || !pBalanceChannel )
  1967. continue;
  1968. CDmElement *pChannelsClip = FindChannelsClipForChannel( pFilmClip, pValueChannel );
  1969. Assert( pChannelsClip == FindChannelsClipForChannel( pFilmClip, pBalanceChannel ) );
  1970. if ( !pChannelsClip )
  1971. continue;
  1972. CDmAttribute *pChannelsAttr = pChannelsClip->GetAttribute( "channels" );
  1973. if ( !pChannelsAttr )
  1974. continue;
  1975. CDmrElementArray<> channels( pChannelsAttr );
  1976. channels.Remove( channels.Find( pValueChannel ) );
  1977. channels.Remove( channels.Find( pBalanceChannel ) );
  1978. CDmElement *pVB2LRCalcOp = pValueChannel->GetValueElement< CDmElement >( "toElement" );
  1979. Assert( pVB2LRCalcOp == pBalanceChannel->GetValueElement< CDmElement >( "toElement" ) );
  1980. CDmElement *pLeftChannel = FindChannelTargettingElement( pVB2LRCalcOp, "result_left", true );
  1981. CDmElement *pRightChannel = FindChannelTargettingElement( pVB2LRCalcOp, "result_right", true );
  1982. if ( !pLeftChannel || !pRightChannel )
  1983. return false;
  1984. pControl->SetValue( "leftvaluechannel", pLeftChannel );
  1985. pControl->SetValue( "rightvaluechannel", pRightChannel );
  1986. int nChannelMode = pValueChannel->GetValue< int >( "mode" );
  1987. pLeftChannel ->SetValue( "fromElement", pControl );
  1988. pLeftChannel ->SetValue( "fromAttribute", "leftValue" );
  1989. pLeftChannel ->SetValue( "mode", nChannelMode );
  1990. pRightChannel->SetValue( "fromElement", pControl );
  1991. pRightChannel->SetValue( "fromAttribute", "rightValue" );
  1992. pRightChannel->SetValue( "mode", nChannelMode );
  1993. CDmElement *pValueLog = GetLogLayerFromChannel( pValueChannel );
  1994. CDmElement *pBalanceLog = GetLogLayerFromChannel( pBalanceChannel );
  1995. CDmElement *pLeftLog = GetLogLayerFromChannel( pLeftChannel );
  1996. CDmElement *pRightLog = GetLogLayerFromChannel( pRightChannel );
  1997. if ( !pValueLog || !pBalanceLog || !pLeftLog || !pRightLog )
  1998. continue;
  1999. // doing this on-demand, in case the loglayer wasn't reached directly yet
  2000. if ( !ConvertIntArrayToTimeArray( pValueLog->GetAttribute( "times" ) ) ||
  2001. !ConvertIntArrayToTimeArray( pBalanceLog->GetAttribute( "times" ) ) )
  2002. return false;
  2003. const CUtlVector< DmeTime_t > &valueTimes = pValueLog ->GetValue< CUtlVector< DmeTime_t > >( "times" );
  2004. const CUtlVector< float > &valueValues = pValueLog ->GetValue< CUtlVector< float > >( "values" );
  2005. const CUtlVector< DmeTime_t > &balanceTimes = pBalanceLog->GetValue< CUtlVector< DmeTime_t > >( "times" );
  2006. const CUtlVector< float > &balanceValues = pBalanceLog->GetValue< CUtlVector< float > >( "values" );
  2007. CDmAttribute *pLeftTimesAttr = pLeftLog ->GetAttribute( "times" );
  2008. CDmAttribute *pLeftValuesAttr = pLeftLog ->GetAttribute( "values", AT_FLOAT_ARRAY );
  2009. CDmAttribute *pRightTimesAttr = pRightLog->GetAttribute( "times" );
  2010. CDmAttribute *pRightValuesAttr = pRightLog->GetAttribute( "values", AT_FLOAT_ARRAY );
  2011. if ( !pLeftTimesAttr || !pLeftValuesAttr || !pRightTimesAttr || !pRightValuesAttr )
  2012. return false;
  2013. // doing this on-demand, in case the loglayer wasn't reached directly yet
  2014. if ( !ConvertIntArrayToTimeArray( pLeftTimesAttr ) ||
  2015. !ConvertIntArrayToTimeArray( pRightTimesAttr ) )
  2016. return false;
  2017. CDmrArray< DmeTime_t > leftTimes ( pLeftTimesAttr );
  2018. CDmrArray< float > leftValues ( pLeftValuesAttr );
  2019. CDmrArray< DmeTime_t > rightTimes ( pRightTimesAttr );
  2020. CDmrArray< float > rightValues( pRightValuesAttr );
  2021. // convert and copy log data
  2022. int vi = 0, bi = 0;
  2023. int vn = valueTimes.Count(), bn = balanceTimes.Count();
  2024. leftTimes .EnsureCapacity( MAX( vn, bn ) );
  2025. leftValues .EnsureCapacity( MAX( vn, bn ) );
  2026. rightTimes .EnsureCapacity( MAX( vn, bn ) );
  2027. rightValues.EnsureCapacity( MAX( vn, bn ) );
  2028. while ( vi < vn || bi < bn )
  2029. {
  2030. float value, balance;
  2031. DmeTime_t t;
  2032. if ( vi >= vn )
  2033. {
  2034. t = balanceTimes[ bi ];
  2035. value = vn > 0 ? valueValues[ vn - 1 ] : flDefaultValue;
  2036. balance = balanceValues[ bi ];
  2037. ++bi;
  2038. }
  2039. else if ( bi >= bn )
  2040. {
  2041. t = valueTimes[ vi ];
  2042. value = valueValues[ vi ];
  2043. balance = bn > 0 ? balanceValues[ bn - 1 ] : flDefaultBalance;
  2044. ++vi;
  2045. }
  2046. else
  2047. {
  2048. DmeTime_t vt = valueTimes [ vi ];
  2049. DmeTime_t bt = balanceTimes[ bi ];
  2050. value = valueValues [ vi ];
  2051. balance = balanceValues[ bi ];
  2052. if ( vt < bt )
  2053. {
  2054. t = vt;
  2055. if ( bi > 0 )
  2056. {
  2057. float f = ( t - balanceTimes[ bi - 1 ] ) / ( bt - balanceTimes[ bi - 1 ] );
  2058. balance = Lerp( f, balanceValues[ bi - 1 ], balance );
  2059. }
  2060. ++vi;
  2061. }
  2062. else if ( bt < vt )
  2063. {
  2064. t = bt;
  2065. if ( vi > 0 )
  2066. {
  2067. float f = ( t - valueTimes[ vi - 1 ] ) / ( vt - valueTimes[ vi - 1 ] );
  2068. value = Lerp( f, valueValues[ vi - 1 ], value );
  2069. }
  2070. ++bi;
  2071. }
  2072. else
  2073. {
  2074. t = vt;
  2075. ++vi;
  2076. ++bi;
  2077. }
  2078. }
  2079. float left, right;
  2080. ValueBalanceToLeftRight( &left, &right, value, balance, flDefaultValue );
  2081. leftTimes .AddToTail( t );
  2082. rightTimes.AddToTail( t );
  2083. leftValues .AddToTail( left );
  2084. rightValues.AddToTail( right );
  2085. }
  2086. // NOTE - with non-typed elements, TD_SHALLOW == TD_NONE and TD_DEEP == TD_ALL
  2087. DestroyElement( pValueChannel, TD_NONE );
  2088. DestroyElement( pValueLog, TD_ALL );
  2089. DestroyElement( pBalanceChannel, TD_NONE );
  2090. DestroyElement( pBalanceLog, TD_ALL );
  2091. }
  2092. }
  2093. // remove and delete BalanceToStereoCalculatorOperators
  2094. CDmAttribute *pOperatorsAttr = pElement->GetAttribute( "operators" );
  2095. if ( pOperatorsAttr )
  2096. {
  2097. const static CUtlSymbolLarge balanceToStereoSym = g_pDataModel->GetSymbol( "DmeBalanceToStereoCalculatorOperator" );
  2098. CDmrElementArray<> operators( pOperatorsAttr );
  2099. int nOperators = operators.Count();
  2100. for ( int i = nOperators-1; i >= 0; --i )
  2101. {
  2102. CDmElement *pOperator = operators[ i ];
  2103. if ( pOperator && pOperator->GetType() != balanceToStereoSym )
  2104. continue;
  2105. DestroyElement( pOperator, TD_NONE ); // NOTE - with non-typed elements, TD_SHALLOW == TD_NONE and TD_DEEP == TD_ALL
  2106. operators.Remove( i );
  2107. }
  2108. }
  2109. // convert preset control values from VB to LR
  2110. CDmAttribute *pPresetGroupsAttr = pElement->GetAttribute( "presetGroups", AT_ELEMENT_ARRAY );
  2111. if ( pPresetGroupsAttr )
  2112. {
  2113. CDmrElementArray<> presetGroups( pPresetGroupsAttr );
  2114. int nPresetGroups = presetGroups.Count();
  2115. for ( int gi = 0; gi < nPresetGroups; ++gi )
  2116. {
  2117. CDmElement *pPresetGroup = presetGroups[ gi ];
  2118. if ( !pPresetGroup )
  2119. continue;
  2120. CDmAttribute *pPresetsAttr = pPresetGroup->GetAttribute( "presets", AT_ELEMENT_ARRAY );
  2121. if ( !pPresetsAttr )
  2122. continue;
  2123. CDmrElementArray<> presets( pPresetsAttr );
  2124. int nPresets = presets.Count();
  2125. for ( int pi = 0; pi < nPresets; ++pi )
  2126. {
  2127. if ( !UpdatePreset( presets[ pi ] ) )
  2128. return false;
  2129. }
  2130. }
  2131. }
  2132. }
  2133. return true;
  2134. }
  2135. static CDmElement *FindAnimSetControlByName( CDmrElementArray<> &array, char const *pchControlName, int *pIndex )
  2136. {
  2137. Assert( pIndex );
  2138. *pIndex = array.InvalidIndex();
  2139. for ( int i = 0; i < array.Count(); ++i )
  2140. {
  2141. CDmElement *e = array[ i ];
  2142. if ( !Q_stricmp( e->GetName(), pchControlName ) )
  2143. {
  2144. *pIndex = i;
  2145. return e;
  2146. }
  2147. }
  2148. return NULL;
  2149. }
  2150. bool Update2( CDmElement *pElement )
  2151. {
  2152. const char *g_pControlType[] = { "isPosition", "isOrientation" };
  2153. const char *g_pSuffix[] = { "pos", "rot" };
  2154. const static CUtlSymbolLarge animSetSym = g_pDataModel->GetSymbol( "DmeAnimationSet" );
  2155. CUtlSymbolLarge typeSym = pElement->GetType();
  2156. if ( typeSym == animSetSym )
  2157. {
  2158. // Split transform controls out from the groups
  2159. // Add the isPosition/isOrientation and baseName bools/string
  2160. // Split the actual controls for transforms
  2161. // First find the selectionGroups attribute and the controls attribute
  2162. CDmAttribute *pGroupsAttr = pElement->GetAttribute( "selectionGroups", AT_ELEMENT_ARRAY );
  2163. CDmAttribute *pControlsAttr = pElement->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  2164. if ( pGroupsAttr && pControlsAttr )
  2165. {
  2166. CDmrElementArray<> groups( pGroupsAttr );
  2167. CDmrElementArray<> controls( pControlsAttr );
  2168. // Walk through groups and for the controls which point to transforms, build the subgroups
  2169. int c = groups.Count();
  2170. for ( int i = 0; i < c; ++i )
  2171. {
  2172. CDmElement *pGroup = groups[ i ];
  2173. CDmAttribute *temp = pGroup->GetAttribute( "selectedControls", AT_STRING_ARRAY );
  2174. CDmrStringArray temp2( temp );
  2175. pGroup->RenameAttribute( "selectedControls", "selectedControls2" );
  2176. CDmAttribute *pControlsAttr = pGroup->GetAttribute( "selectedControls2", AT_STRING_ARRAY );
  2177. // First convert all of the string array stuff into an element array
  2178. if ( pControlsAttr )
  2179. {
  2180. CDmrStringArray controlsInGroup( pControlsAttr );
  2181. CDmAttribute *pNewControlsAttr = pGroup->AddAttribute( "controls", AT_ELEMENT_ARRAY );
  2182. CDmrElementArray< CDmElement > newControls( pNewControlsAttr );
  2183. for ( int j = 0 ; j < controlsInGroup.Count(); ++j )
  2184. {
  2185. char const *pchControlName = controlsInGroup[ j ];
  2186. CDmElement *pNewControl = CreateElement< CDmElement >( pchControlName, pElement->GetFileId() );
  2187. pNewControl->SetParity( pElement->GetParity() );
  2188. // Assume the new ones are not groups
  2189. pNewControl->SetValue< bool >( "isGroup", false );
  2190. newControls.AddToTail( pNewControl );
  2191. }
  2192. // Discard the old one
  2193. pGroup->RemoveAttribute( "selectedControls2" );
  2194. }
  2195. pGroup->SetValue< bool >( "isGroup", true );
  2196. }
  2197. // In the 2nd pass, create the subgroups for the transforms and update the "controls" array accordingly
  2198. for ( int i = 0; i < c; ++i )
  2199. {
  2200. CDmElement *pGroup = groups[ i ];
  2201. CDmAttribute *pControlsAttr = pGroup->GetAttribute( "controls", AT_ELEMENT_ARRAY );
  2202. if ( pControlsAttr )
  2203. {
  2204. CDmrElementArray< CDmElement > controlsInGroup( pControlsAttr );
  2205. for ( int j = 0 ; j < controlsInGroup.Count(); ++j )
  2206. {
  2207. char const *pchControlName = controlsInGroup[ j ]->GetName();
  2208. // Now that we have a control, we'll see if it corresponds to a transform
  2209. int nIndex = controls.InvalidIndex();
  2210. CDmElement *pControl = FindAnimSetControlByName( controls, pchControlName, &nIndex );
  2211. if ( pControl && pControl->GetValue< bool >( "transform" ) )
  2212. {
  2213. controlsInGroup[ j ]->SetValue< bool >( "isGroup", true );
  2214. CDmAttribute *pNewControlsAttr = controlsInGroup[ j ]->AddAttribute( "controls", AT_ELEMENT_ARRAY );
  2215. CDmrElementArray< CDmElement > newControls( pNewControlsAttr );
  2216. CUtlVector< CDmElement * > added;
  2217. // Build the pos and rot versions
  2218. for ( int k = 0; k < 2; ++k )
  2219. {
  2220. CDmElement *control = CreateElement< CDmElement >( CFmtStr( "%s - %s", pchControlName, g_pSuffix[ k ] ), pElement->GetFileId() );
  2221. control->SetParity( pElement->GetParity() );
  2222. control->SetValue< bool >( "transform", true );
  2223. control->SetValue< bool >( g_pControlType[ k ], true );
  2224. control->SetValue< bool >( g_pControlType[ 1 - k ], false );
  2225. control->SetValue( "baseName", pchControlName );
  2226. if ( k == 0 )
  2227. {
  2228. control->SetValue< Vector >( "valuePosition", pControl->GetValue< Vector >( "valuePosition" ) );
  2229. CDmElement *p = pControl->GetValueElement< CDmElement >( "position" );
  2230. if ( p )
  2231. {
  2232. control->SetValue< CDmElement >( "position", p );
  2233. // Now find the position channel's "from" and set it to the new control
  2234. p->SetValue< CDmElement >( "fromElement", control );
  2235. }
  2236. }
  2237. else
  2238. {
  2239. control->SetValue< Quaternion >( "valueOrientation", pControl->GetValue< Quaternion >( "valueOrientation" ) );
  2240. CDmElement *p = pControl->GetValueElement< CDmElement >( "orientation" );
  2241. if ( p )
  2242. {
  2243. control->SetValue< CDmElement >( "orientation", p );
  2244. // Now find the orientation channel's "from" and set it to the new control
  2245. p->SetValue< CDmElement >( "fromElement", control );
  2246. }
  2247. }
  2248. added.AddToTail( control );
  2249. CDmElement *groupControl = CreateElement< CDmElement >( CFmtStr( "%s - %s", pchControlName, g_pSuffix[ k ] ), pElement->GetFileId() );
  2250. groupControl->SetParity( pElement->GetParity() );
  2251. groupControl->SetValue< bool >( "isGroup", false );
  2252. newControls.AddToTail( groupControl );
  2253. }
  2254. // Remove the singular one and replace with paired ones
  2255. controls.Remove( nIndex );
  2256. for ( int k = 0; k < 2; ++k )
  2257. {
  2258. controls.AddToTail( added[ k ] );
  2259. }
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. return true;
  2267. }
  2268. bool Update1( CDmElement *pElement )
  2269. {
  2270. // remove lights attribute from filmclips
  2271. const static CUtlSymbolLarge projectedLightSym = g_pDataModel->GetSymbol( "DmeProjectedLight" );
  2272. const static CUtlSymbolLarge filmClipSym = g_pDataModel->GetSymbol( "DmeFilmClip" );
  2273. const static CUtlSymbolLarge bookmarkSym = g_pDataModel->GetSymbol( "DmeBookmark" );
  2274. const static CUtlSymbolLarge timeframeSym = g_pDataModel->GetSymbol( "DmeTimeFrame" );
  2275. const static CUtlSymbolLarge timeSelectionSym = g_pDataModel->GetSymbol( "DmeTimeSelection" );
  2276. const static CUtlSymbolLarge proceduralPresetSym = g_pDataModel->GetSymbol( "DmeProceduralPresetSettings" );
  2277. const static CUtlSymbolLarge gameParticleSysSym = g_pDataModel->GetSymbol( "DmeGameParticleSystem" );
  2278. const static CUtlSymbolLarge cameraSym = g_pDataModel->GetSymbol( "DmeCamera" );
  2279. const static CUtlSymbolLarge intCurveInfoSym = g_pDataModel->GetSymbol( "DmeIntCurveInfo" );
  2280. const static CUtlSymbolLarge floatCurveInfoSym = g_pDataModel->GetSymbol( "DmeFloatCurveInfo" );
  2281. const static CUtlSymbolLarge boolCurveInfoSym = g_pDataModel->GetSymbol( "DmeBoolCurveInfo" );
  2282. const static CUtlSymbolLarge colorCurveInfoSym = g_pDataModel->GetSymbol( "DmeColorCurveInfo" );
  2283. const static CUtlSymbolLarge vec2CurveInfoSym = g_pDataModel->GetSymbol( "DmeVector2CurveInfo" );
  2284. const static CUtlSymbolLarge vec3CurveInfoSym = g_pDataModel->GetSymbol( "DmeVector3CurveInfo" );
  2285. const static CUtlSymbolLarge vec4CurveInfoSym = g_pDataModel->GetSymbol( "DmeVector4CurveInfo" );
  2286. const static CUtlSymbolLarge qangleCurveInfoSym = g_pDataModel->GetSymbol( "DmeQAngleCurveInfo" );
  2287. const static CUtlSymbolLarge quatCurveInfoSym = g_pDataModel->GetSymbol( "DmeQuaternionCurveInfo" );
  2288. const static CUtlSymbolLarge vmatrixCurveInfoSym = g_pDataModel->GetSymbol( "DmeVMatrixCurveInfo" );
  2289. const static CUtlSymbolLarge stringCurveInfoSym = g_pDataModel->GetSymbol( "DmeStringCurveInfo" );
  2290. const static CUtlSymbolLarge timeCurveInfoSym = g_pDataModel->GetSymbol( "DmeTimeCurveInfo" );
  2291. CUtlSymbolLarge typeSym = pElement->GetType();
  2292. if ( typeSym == projectedLightSym )
  2293. {
  2294. pElement->RemoveAttribute( "textureFrame" );
  2295. ChangeAttributeType( pElement, "animationTime", AT_TIME );
  2296. }
  2297. else if ( typeSym == filmClipSym )
  2298. {
  2299. pElement->RemoveAttribute( "lights" );
  2300. ChangeAttributeType( pElement, "fadeIn", AT_TIME );
  2301. ChangeAttributeType( pElement, "fadeOut", AT_TIME );
  2302. }
  2303. else if ( typeSym == bookmarkSym )
  2304. {
  2305. ChangeAttributeType( pElement, "time", AT_TIME );
  2306. ChangeAttributeType( pElement, "duration", AT_TIME );
  2307. }
  2308. else if ( typeSym == timeframeSym )
  2309. {
  2310. pElement->RenameAttribute( "startTime", "start" );
  2311. pElement->RenameAttribute( "durationTime", "duration" );
  2312. pElement->RenameAttribute( "offsetTime", "offset" );
  2313. ChangeAttributeType( pElement, "start", AT_TIME );
  2314. ChangeAttributeType( pElement, "duration", AT_TIME );
  2315. ChangeAttributeType( pElement, "offset", AT_TIME );
  2316. }
  2317. else if ( typeSym == timeSelectionSym )
  2318. {
  2319. ChangeAttributeType( pElement, "falloff_left", AT_TIME );
  2320. ChangeAttributeType( pElement, "falloff_right", AT_TIME );
  2321. ChangeAttributeType( pElement, "hold_left", AT_TIME );
  2322. ChangeAttributeType( pElement, "hold_right", AT_TIME );
  2323. ChangeAttributeType( pElement, "resampleinterval", AT_TIME );
  2324. }
  2325. else if ( typeSym == proceduralPresetSym )
  2326. {
  2327. ChangeAttributeType( pElement, "staggerinterval", AT_TIME );
  2328. }
  2329. else if ( typeSym == gameParticleSysSym )
  2330. {
  2331. ChangeAttributeType( pElement, "simulationTime", AT_TIME );
  2332. ChangeAttributeType( pElement, "startTime", AT_TIME );
  2333. ChangeAttributeType( pElement, "emissionStopTime", AT_TIME );
  2334. ChangeAttributeType( pElement, "endTime", AT_TIME );
  2335. }
  2336. else if ( typeSym == cameraSym )
  2337. {
  2338. ChangeAttributeType( pElement, "shutterSpeed", AT_TIME );
  2339. }
  2340. else if ( typeSym == intCurveInfoSym
  2341. || typeSym == floatCurveInfoSym
  2342. || typeSym == boolCurveInfoSym
  2343. || typeSym == colorCurveInfoSym
  2344. || typeSym == vec2CurveInfoSym
  2345. || typeSym == vec3CurveInfoSym
  2346. || typeSym == vec4CurveInfoSym
  2347. || typeSym == qangleCurveInfoSym
  2348. || typeSym == quatCurveInfoSym
  2349. || typeSym == vmatrixCurveInfoSym
  2350. || typeSym == stringCurveInfoSym
  2351. || typeSym == timeCurveInfoSym )
  2352. {
  2353. ChangeAttributeType( pElement, "rightEdgeTime", AT_TIME );
  2354. }
  2355. return true;
  2356. }
  2357. static char *s_RemapOperatorNameTable[]={
  2358. "alpha_fade", "Alpha Fade and Decay",
  2359. "alpha_fade_in_random", "Alpha Fade In Random",
  2360. "alpha_fade_out_random", "Alpha Fade Out Random",
  2361. "basic_movement", "Movement Basic",
  2362. "color_fade", "Color Fade",
  2363. "controlpoint_light", "Color Light From Control Point",
  2364. "Dampen Movement Relative to Control Point", "Movement Dampen Relative to Control Point",
  2365. "Distance Between Control Points Scale", "Remap Distance Between Two Control Points to Scalar",
  2366. "Distance to Control Points Scale", "Remap Distance to Control Point to Scalar",
  2367. "lifespan_decay", "Lifespan Decay",
  2368. "lock to bone", "Movement Lock to Bone",
  2369. "postion_lock_to_controlpoint", "Movement Lock to Control Point",
  2370. "maintain position along path", "Movement Maintain Position Along Path",
  2371. "Match Particle Velocities", "Movement Match Particle Velocities",
  2372. "Max Velocity", "Movement Max Velocity",
  2373. "noise", "Noise Scalar",
  2374. "vector noise", "Noise Vector",
  2375. "oscillate_scalar", "Oscillate Scalar",
  2376. "oscillate_vector", "Oscillate Vector",
  2377. "Orient Rotation to 2D Direction", "Rotation Orient to 2D Direction",
  2378. "radius_scale", "Radius Scale",
  2379. "Random Cull", "Cull Random",
  2380. "remap_scalar", "Remap Scalar",
  2381. "rotation_movement", "Rotation Basic",
  2382. "rotation_spin", "Rotation Spin Roll",
  2383. "rotation_spin yaw", "Rotation Spin Yaw",
  2384. "alpha_random", "Alpha Random",
  2385. "color_random", "Color Random",
  2386. "create from parent particles", "Position From Parent Particles",
  2387. "Create In Hierarchy", "Position In CP Hierarchy",
  2388. "random position along path", "Position Along Path Random",
  2389. "random position on model", "Position on Model Random",
  2390. "sequential position along path", "Position Along Path Sequential",
  2391. "position_offset_random", "Position Modify Offset Random",
  2392. "position_warp_random", "Position Modify Warp Random",
  2393. "position_within_box", "Position Within Box Random",
  2394. "position_within_sphere", "Position Within Sphere Random",
  2395. "Inherit Velocity", "Velocity Inherit from Control Point",
  2396. "Initial Repulsion Velocity", "Velocity Repulse from World",
  2397. "Initial Velocity Noise", "Velocity Noise",
  2398. "Initial Scalar Noise", "Remap Noise to Scalar",
  2399. "Lifespan from distance to world", "Lifetime from Time to Impact",
  2400. "Pre-Age Noise", "Lifetime Pre-Age Noise",
  2401. "lifetime_random", "Lifetime Random",
  2402. "radius_random", "Radius Random",
  2403. "random yaw", "Rotation Yaw Random",
  2404. "Randomly Flip Yaw", "Rotation Yaw Flip Random",
  2405. "rotation_random", "Rotation Random",
  2406. "rotation_speed_random", "Rotation Speed Random",
  2407. "sequence_random", "Sequence Random",
  2408. "second_sequence_random", "Sequence Two Random",
  2409. "trail_length_random", "Trail Length Random",
  2410. "velocity_random", "Velocity Random",
  2411. };
  2412. bool Update5( CDmElement *pElement )
  2413. {
  2414. const static CUtlSymbolLarge ParticleOperatorSym = g_pDataModel->GetSymbol( "DmeParticleOperator" );
  2415. CUtlSymbolLarge typeSym = pElement->GetType();
  2416. if ( typeSym == ParticleOperatorSym )
  2417. {
  2418. const char *pOpName = pElement->GetValueString( "functionName" );
  2419. for( int i = 0 ; i < ARRAYSIZE( s_RemapOperatorNameTable ) ; i += 2 )
  2420. {
  2421. if ( Q_stricmp( pOpName, s_RemapOperatorNameTable[i] ) == 0 )
  2422. {
  2423. pElement->SetValueFromString( "functionName", s_RemapOperatorNameTable[i + 1 ] );
  2424. // pElement->SetValueFromString( "name", s_RemapOperatorNameTable[i + 1 ] );
  2425. pElement->SetName( s_RemapOperatorNameTable[i + 1 ] );
  2426. break;
  2427. }
  2428. }
  2429. }
  2430. return true;
  2431. }
  2432. bool UpdateElement_R( FnUpdater pfnUpdate, CDmElement **ppElement, bool bParity )
  2433. {
  2434. CDmElement *pElement = *ppElement;
  2435. if ( pElement->GetParity() == bParity )
  2436. return true; // already visited
  2437. pElement->SetParity( bParity );
  2438. if ( !pfnUpdate( pElement ) )
  2439. return false;
  2440. for ( CDmAttribute *pAttribute = pElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
  2441. {
  2442. if ( pAttribute->GetType() == AT_ELEMENT )
  2443. {
  2444. CDmElement *pElement = pAttribute->GetValueElement< CDmElement >();
  2445. if ( pElement )
  2446. {
  2447. if ( !UpdateElement_R( pfnUpdate, &pElement, bParity ) )
  2448. return false;
  2449. pAttribute->SetValue< CDmElement >( pElement );
  2450. }
  2451. continue;
  2452. }
  2453. if ( pAttribute->GetType() == AT_ELEMENT_ARRAY )
  2454. {
  2455. CDmrElementArray<> array( pAttribute );
  2456. int nCount = array.Count();
  2457. for ( int i = 0; i < nCount; ++i )
  2458. {
  2459. CDmElement *pChild = array[ i ];
  2460. if ( pChild )
  2461. {
  2462. if ( !UpdateElement_R( pfnUpdate, &pChild, bParity ) )
  2463. return false;
  2464. array.Set( i, pChild );
  2465. }
  2466. }
  2467. continue;
  2468. }
  2469. }
  2470. return true;
  2471. }
  2472. IMPLEMENT_UPDATER( 1 ); // Creates Update1_R, which requires an Update1 func
  2473. IMPLEMENT_UPDATER( 2 );
  2474. IMPLEMENT_UPDATER( 3 );
  2475. IMPLEMENT_UPDATER( 4 );
  2476. IMPLEMENT_UPDATER( 5 );
  2477. IMPLEMENT_UPDATER( 6 );
  2478. IMPLEMENT_UPDATER( 7 );
  2479. IMPLEMENT_UPDATER( 8 );
  2480. IMPLEMENT_UPDATER( 9 );
  2481. IMPLEMENT_UPDATER( 10 );
  2482. IMPLEMENT_UPDATER( 11 );
  2483. IMPLEMENT_UPDATER( 12 );
  2484. IMPLEMENT_UPDATER( 13 );
  2485. IMPLEMENT_UPDATER( 14 );
  2486. IMPLEMENT_UPDATER( 15 );
  2487. IMPLEMENT_UPDATER( 16 );
  2488. IMPLEMENT_UPDATER( 17 );
  2489. IMPLEMENT_UPDATER( 18 );
  2490. IMPLEMENT_UPDATER( 19 );
  2491. typedef bool (*ElementUpdateFunction)( CDmElement **pRoot, bool bParity );
  2492. ElementUpdateFunction EmptyUpdateFunctionList[] = { NULL };
  2493. ElementUpdateFunction PresetUpdateFunctionList[] = { Update3_R, Update4_R, Update10_R, NULL };
  2494. ElementUpdateFunction MovieObjectsUpdateFunctionList[] =
  2495. {
  2496. Update1_R, Update2_R, Update3_R, Update4_R, Update6_R, Update7_R, Update8_R, Update9_R,
  2497. Update10_R, Update11_R, Update12_R, Update13_R, Update14_R, Update15_R, Update17_R, Update18_R, Update19_R, NULL
  2498. };
  2499. ElementUpdateFunction SFMSessionObjectsUpdateFunctionList[] =
  2500. {
  2501. Update1_R, Update2_R, Update3_R, Update4_R, Update6_R, Update7_R, Update8_R, Update9_R,
  2502. Update10_R, Update11_R, Update12_R, Update13_R, Update14_R, Update15_R, Update16_R, Update17_R, Update18_R, Update19_R, NULL
  2503. };
  2504. ElementUpdateFunction ParticleUpdateFunctionList[] = { Update5_R, NULL };
  2505. //-----------------------------------------------------------------------------
  2506. // declare format updaters
  2507. //-----------------------------------------------------------------------------
  2508. DECLARE_FORMAT_UPDATER( dmx, "Generic DMX", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2509. DECLARE_FORMAT_UPDATER( movieobjects, "Generic MovieObjects", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2510. DECLARE_FORMAT_UPDATER( sfm, "Generic SFM", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2511. DECLARE_FORMAT_UPDATER( sfm_settings, "SFM Settings", "dmx", "keyvalues2",MovieObjectsUpdateFunctionList )
  2512. DECLARE_FORMAT_UPDATER( sfm_session, "SFM Session", "dmx", "binary", SFMSessionObjectsUpdateFunctionList )
  2513. DECLARE_FORMAT_UPDATER( sfm_trackgroup, "SFM TrackGroup", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2514. DECLARE_FORMAT_UPDATER( pcf, "Particle Configuration File", "pcf", "binary", ParticleUpdateFunctionList )
  2515. DECLARE_FORMAT_UPDATER( preset, "Preset File", "dmx", "keyvalues2",PresetUpdateFunctionList )
  2516. DECLARE_FORMAT_UPDATER( facial_animation, "Facial Animation File", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2517. DECLARE_FORMAT_UPDATER( model, "DMX Model", "dmx", "binary", MovieObjectsUpdateFunctionList )
  2518. DECLARE_FORMAT_UPDATER( ved, "Vgui editor file", "ved", "keyvalues2", EmptyUpdateFunctionList )
  2519. DECLARE_FORMAT_UPDATER( mks, "Make sheet file", "mks", "keyvalues2", EmptyUpdateFunctionList )
  2520. DECLARE_FORMAT_UPDATER( mp_preprocess, "DMX Model Pipeline Preprocess File", "mpp", "keyvalues2", EmptyUpdateFunctionList )
  2521. DECLARE_FORMAT_UPDATER( mp_root, "DMX Model Pipeline Root Script File", "root", "keyvalues2", EmptyUpdateFunctionList )
  2522. DECLARE_FORMAT_UPDATER( mp_model, "DMX Model Pipeline Model Script File", "model", "keyvalues2", EmptyUpdateFunctionList )
  2523. DECLARE_FORMAT_UPDATER( mp_anim, "DMX Model Pipeline Animation Script File", "anim", "keyvalues2", EmptyUpdateFunctionList )
  2524. DECLARE_FORMAT_UPDATER( mp_physics, "DMX Model Pipeline Physics Script File", "physics", "keyvalues2", EmptyUpdateFunctionList )
  2525. DECLARE_FORMAT_UPDATER( mp_hitbox, "DMX Model Pipeline Hitbox Script File", "hitbox", "keyvalues2", EmptyUpdateFunctionList )
  2526. DECLARE_FORMAT_UPDATER( mp_materialgroup, "DMX Model Pipeline Material Group Script File", "materialgroup", "keyvalues2", EmptyUpdateFunctionList )
  2527. DECLARE_FORMAT_UPDATER( mp_keyvalues, "DMX Model Pipeline KeyValues Script File", "keyvalues", "keyvalues2", EmptyUpdateFunctionList )
  2528. DECLARE_FORMAT_UPDATER( mp_eyes, "DMX Model Pipeline Eyes Script File", "eyes", "keyvalues2", EmptyUpdateFunctionList )
  2529. DECLARE_FORMAT_UPDATER( mp_bonemask, "DMX Model Pipeline Bone Mask Script File", "bonemask", "keyvalues2", EmptyUpdateFunctionList )
  2530. DECLARE_FORMAT_UPDATER( gui, "Compiled GUI file", "gui", "keyvalues2",EmptyUpdateFunctionList )
  2531. DECLARE_FORMAT_UPDATER( schema, "Schema description file", "sch", "keyvalues2",EmptyUpdateFunctionList )
  2532. DECLARE_FORMAT_UPDATER( tex, "Texture Configuration File", "tex", "keyvalues2",EmptyUpdateFunctionList )
  2533. DECLARE_FORMAT_UPDATER( world, "World Files", "wld", "binary", EmptyUpdateFunctionList )
  2534. DECLARE_FORMAT_UPDATER( worldnode, "World Node Files", "wnd", "binary", EmptyUpdateFunctionList )
  2535. //-----------------------------------------------------------------------------
  2536. // The application object
  2537. //-----------------------------------------------------------------------------
  2538. class CDmSerializers : public CBaseAppSystem< IDmSerializers >
  2539. {
  2540. typedef CBaseAppSystem< IDmSerializers > BaseClass;
  2541. public:
  2542. // Inherited from IAppSystem
  2543. virtual bool Connect( CreateInterfaceFn factory );
  2544. virtual void *QueryInterface( const char *pInterfaceName );
  2545. virtual InitReturnVal_t Init();
  2546. };
  2547. //-----------------------------------------------------------------------------
  2548. // Singleton interface
  2549. //-----------------------------------------------------------------------------
  2550. static CDmSerializers g_DmSerializers;
  2551. IDmSerializers *g_pDmSerializers = &g_DmSerializers;
  2552. //-----------------------------------------------------------------------------
  2553. // Here's where the app systems get to learn about each other
  2554. //-----------------------------------------------------------------------------
  2555. bool CDmSerializers::Connect( CreateInterfaceFn factory )
  2556. {
  2557. if ( !BaseClass::Connect( factory ) )
  2558. return false;
  2559. if ( !factory( FILESYSTEM_INTERFACE_VERSION, NULL ) )
  2560. {
  2561. Warning( "DmSerializers needs the file system to function" );
  2562. return false;
  2563. }
  2564. // Here's the main point where all DM element classes get installed
  2565. // Necessary to do it here so all type symbols for all DME classes are set
  2566. // up prior to install
  2567. InstallDmElementFactories( );
  2568. return true;
  2569. }
  2570. //-----------------------------------------------------------------------------
  2571. // Here's where systems can access other interfaces implemented by this object
  2572. //-----------------------------------------------------------------------------
  2573. void *CDmSerializers::QueryInterface( const char *pInterfaceName )
  2574. {
  2575. if ( !V_strcmp( pInterfaceName, DMSERIALIZERS_INTERFACE_VERSION ) )
  2576. return (IDmSerializers*)this;
  2577. return NULL;
  2578. }
  2579. //-----------------------------------------------------------------------------
  2580. // Init, shutdown
  2581. //-----------------------------------------------------------------------------
  2582. InitReturnVal_t CDmSerializers::Init()
  2583. {
  2584. InitReturnVal_t nRetVal = BaseClass::Init();
  2585. if ( nRetVal != INIT_OK )
  2586. return nRetVal;
  2587. // Install non-dmx importers
  2588. InstallActBusyImporter( g_pDataModel );
  2589. InstallCommentaryImporter( g_pDataModel );
  2590. InstallVMTImporter( g_pDataModel );
  2591. InstallVMFImporter( g_pDataModel );
  2592. InstallMKSImporter( g_pDataModel );
  2593. InstallTEXImporter( g_pDataModel );
  2594. // Install legacy dmx importers
  2595. InstallSFMV1Importer( g_pDataModel );
  2596. InstallSFMV2Importer( g_pDataModel );
  2597. InstallSFMV3Importer( g_pDataModel );
  2598. InstallSFMV4Importer( g_pDataModel );
  2599. InstallSFMV5Importer( g_pDataModel );
  2600. InstallSFMV6Importer( g_pDataModel );
  2601. InstallSFMV7Importer( g_pDataModel );
  2602. InstallSFMV8Importer( g_pDataModel );
  2603. InstallSFMV9Importer( g_pDataModel );
  2604. // install dmx format updaters
  2605. INSTALL_FORMAT_UPDATER( dmx );
  2606. INSTALL_FORMAT_UPDATER( movieobjects );
  2607. INSTALL_FORMAT_UPDATER( sfm );
  2608. INSTALL_FORMAT_UPDATER( sfm_settings );
  2609. INSTALL_FORMAT_UPDATER( sfm_session );
  2610. INSTALL_FORMAT_UPDATER( sfm_trackgroup );
  2611. INSTALL_FORMAT_UPDATER( pcf );
  2612. INSTALL_FORMAT_UPDATER( gui );
  2613. INSTALL_FORMAT_UPDATER( schema );
  2614. INSTALL_FORMAT_UPDATER( preset );
  2615. INSTALL_FORMAT_UPDATER( facial_animation );
  2616. INSTALL_FORMAT_UPDATER( model );
  2617. INSTALL_FORMAT_UPDATER( ved );
  2618. INSTALL_FORMAT_UPDATER( mks );
  2619. INSTALL_FORMAT_UPDATER( mp_preprocess );
  2620. INSTALL_FORMAT_UPDATER( mp_root );
  2621. INSTALL_FORMAT_UPDATER( mp_model );
  2622. INSTALL_FORMAT_UPDATER( mp_anim );
  2623. INSTALL_FORMAT_UPDATER( mp_physics );
  2624. INSTALL_FORMAT_UPDATER( mp_hitbox );
  2625. INSTALL_FORMAT_UPDATER( mp_materialgroup );
  2626. INSTALL_FORMAT_UPDATER( mp_keyvalues );
  2627. INSTALL_FORMAT_UPDATER( mp_eyes );
  2628. INSTALL_FORMAT_UPDATER( mp_bonemask );
  2629. INSTALL_FORMAT_UPDATER( tex );
  2630. INSTALL_FORMAT_UPDATER( world );
  2631. INSTALL_FORMAT_UPDATER( worldnode );
  2632. return INIT_OK;
  2633. }