Team Fortress 2 Source Code as on 22/4/2020
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.

739 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "dme_controls/dmedagrenderpanel.h"
  8. #include "movieobjects/dmedag.h"
  9. #include "movieobjects/dmemodel.h"
  10. #include "movieobjects/timeutils.h"
  11. #include "movieobjects/dmeanimationlist.h"
  12. #include "movieobjects/dmeclip.h"
  13. #include "movieobjects/dmechannel.h"
  14. #include "movieobjects/dmemdlmakefile.h"
  15. #include "movieobjects/dmedccmakefile.h"
  16. #include "movieobjects/dmemesh.h"
  17. #include "movieobjects/dmedrawsettings.h"
  18. #include "dme_controls/dmepanel.h"
  19. #include "tier1/KeyValues.h"
  20. #include "VGuiMatSurface/IMatSystemSurface.h"
  21. #include "tier3/tier3.h"
  22. #include "materialsystem/imaterialsystemhardwareconfig.h"
  23. #include "materialsystem/imesh.h"
  24. #include "vgui_controls/Menu.h"
  25. #include "vgui_controls/MenuBar.h"
  26. #include "vgui_controls/MenuButton.h"
  27. #include "vgui/IVGui.h"
  28. //-----------------------------------------------------------------------------
  29. //
  30. // Hook into the dme panel editor system
  31. //
  32. //-----------------------------------------------------------------------------
  33. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDag, "DmeDagRenderer", "DmeDag Preview Renderer", false );
  34. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceSkin, "DmeSourceSkinPreview", "MDL Skin Previewer", false );
  35. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeSourceAnimation, "DmeSourceAnimationPreview", "MDL Animation Previewer", false );
  36. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagRenderPanel, DmeDCCMakefile, "DmeMakeFileOutputPreview", "DCC MakeFile Output Preview", false );
  37. //-----------------------------------------------------------------------------
  38. // Constructor, destructor
  39. //-----------------------------------------------------------------------------
  40. CDmeDagRenderPanel::CDmeDagRenderPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
  41. {
  42. // Used to poll input
  43. vgui::ivgui()->AddTickSignal( GetVPanel() );
  44. m_bDrawJointNames = false;
  45. m_bDrawJoints = false;
  46. m_bDrawGrid = true;
  47. // Deal with the default cubemap
  48. ITexture *pCubemapTexture = g_pMaterialSystem->FindTexture( "editor/cubemap", NULL, true );
  49. m_DefaultEnvCubemap.Init( pCubemapTexture );
  50. pCubemapTexture = g_pMaterialSystem->FindTexture( "editor/cubemap.hdr", NULL, true );
  51. m_DefaultHDREnvCubemap.Init( pCubemapTexture );
  52. m_pDrawSettings = CreateElement< CDmeDrawSettings >( "drawSettings", g_pDataModel->FindOrCreateFileId( "DagRenderPanelDrawSettings" ) );
  53. m_hDrawSettings = m_pDrawSettings;
  54. m_pMenuBar = new vgui::MenuBar( this, "Dag Render Panel Menu Bar" );
  55. m_pShadingMenu = new vgui::Menu( NULL, "Shading Menu" );
  56. m_nMenuSmoothShade = m_pShadingMenu->AddCheckableMenuItem( "&Smooth Shade", new KeyValues( "SmoothShade" ), this );
  57. m_nMenuFlatShade = m_pShadingMenu->AddCheckableMenuItem( "&Flat Shade", new KeyValues( "FlatShade" ), this );
  58. m_nMenuWireframe = m_pShadingMenu->AddCheckableMenuItem( "&Wireframe", new KeyValues( "Wireframe" ), this );
  59. m_pShadingMenu->AddSeparator();
  60. m_nMenuBoundingBox = m_pShadingMenu->AddCheckableMenuItem( "&Bounding Box", new KeyValues( "BoundingBox" ), this );
  61. m_pShadingMenu->AddSeparator(); // Bug is visibility
  62. m_nMenuNormals = m_pShadingMenu->AddCheckableMenuItem( "&Normals", new KeyValues( "Normals" ), this );
  63. m_nMenuWireframeOnShaded = m_pShadingMenu->AddCheckableMenuItem( "WireFrame &On Shaded", new KeyValues( "WireframeOnShaded" ), this );
  64. m_nMenuBackfaceCulling = m_pShadingMenu->AddCheckableMenuItem( "&Backface Culling", new KeyValues( "BackfaceCulling" ), this );
  65. m_nMenuXRay = m_pShadingMenu->AddCheckableMenuItem( "&X-Ray", new KeyValues( "XRay" ), this );
  66. m_nMenuGrayShade = m_pShadingMenu->AddCheckableMenuItem( "&Gray Shade", new KeyValues( "GrayShade" ), this );
  67. // For now...
  68. m_pShadingMenu->SetItemVisible( m_nMenuFlatShade, false );
  69. m_pShadingMenu->SetItemEnabled( m_nMenuFlatShade, false );
  70. m_pShadingMenu->SetItemVisible( m_nMenuBoundingBox, false );
  71. m_pShadingMenu->SetItemEnabled( m_nMenuBoundingBox, false );
  72. m_pShadingMenu->SetItemVisible( m_nMenuBackfaceCulling, false );
  73. m_pShadingMenu->SetItemEnabled( m_nMenuBackfaceCulling, false );
  74. m_pShadingMenu->SetItemVisible( m_nMenuXRay, false );
  75. m_pShadingMenu->SetItemEnabled( m_nMenuXRay, false );
  76. m_pMenuBar->AddMenu( "&Shading", m_pShadingMenu );
  77. UpdateMenu();
  78. }
  79. //-----------------------------------------------------------------------------
  80. //
  81. //-----------------------------------------------------------------------------
  82. CDmeDagRenderPanel::~CDmeDagRenderPanel()
  83. {
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Scheme settings
  87. //-----------------------------------------------------------------------------
  88. void CDmeDagRenderPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  89. {
  90. BaseClass::ApplySchemeSettings( pScheme );
  91. SetBorder( pScheme->GetBorder( "MenuBorder") );
  92. m_hFont = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Set the scene
  96. //-----------------------------------------------------------------------------
  97. void CDmeDagRenderPanel::SetDmeElement( CDmeDag *pScene )
  98. {
  99. m_hDag = pScene;
  100. ComputeDefaultTangentData( m_hDag, false );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Other methods which hook into DmePanel
  104. //-----------------------------------------------------------------------------
  105. void CDmeDagRenderPanel::SetDmeElement( CDmeSourceSkin *pSkin )
  106. {
  107. // First, try to grab the dependent makefile
  108. CDmeMakefile *pSourceMakefile = pSkin->GetDependentMakefile();
  109. if ( !pSourceMakefile )
  110. {
  111. m_hDag = NULL;
  112. return;
  113. }
  114. // Next, try to grab the output of that makefile
  115. CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
  116. if ( !pOutput )
  117. {
  118. m_hDag = NULL;
  119. return;
  120. }
  121. // Finally, grab the 'skin' attribute of that makefile
  122. m_hDag = pOutput->GetValueElement< CDmeDag >( "model" );
  123. ComputeDefaultTangentData( m_hDag, false );
  124. DrawJoints( false );
  125. DrawJointNames( false );
  126. }
  127. void CDmeDagRenderPanel::SetDmeElement( CDmeSourceAnimation *pAnimation )
  128. {
  129. // First, try to grab the dependent makefile
  130. CDmeMakefile *pSourceMakefile = pAnimation->GetDependentMakefile();
  131. if ( !pSourceMakefile )
  132. {
  133. m_hDag = NULL;
  134. return;
  135. }
  136. // Next, try to grab the output of that makefile
  137. CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
  138. if ( !pOutput )
  139. {
  140. m_hDag = NULL;
  141. return;
  142. }
  143. // Finally, grab the 'model' or 'skeleton' attribute of that makefile
  144. CDmeDag *pDag = pOutput->GetValueElement< CDmeDag >( "model" );
  145. if ( !pDag )
  146. {
  147. pDag = pOutput->GetValueElement< CDmeDag >( "skeleton" );
  148. }
  149. if ( !pDag )
  150. return;
  151. CDmeAnimationList *pAnimationList = pOutput->GetValueElement< CDmeAnimationList >( "animationList" );
  152. if ( !pAnimationList )
  153. return;
  154. if ( pAnimationList->FindAnimation( pAnimation->m_SourceAnimationName ) < 0 )
  155. return;
  156. m_hDag = pDag;
  157. ComputeDefaultTangentData( m_hDag, false );
  158. m_hAnimationList = pAnimationList;
  159. SelectAnimation( pAnimation->m_SourceAnimationName );
  160. DrawJoints( true );
  161. DrawJointNames( true );
  162. }
  163. void CDmeDagRenderPanel::SetDmeElement( CDmeDCCMakefile *pDCCMakefile )
  164. {
  165. // First, try to grab the dependent makefile
  166. CDmElement *pOutputElement = pDCCMakefile->GetOutputElement( true );
  167. if ( !pOutputElement )
  168. {
  169. m_hDag = NULL;
  170. return;
  171. }
  172. // Finally, grab the 'model' or 'skeleton' attribute of that makefile
  173. CDmeDag *pDag = pOutputElement->GetValueElement< CDmeDag >( "model" );
  174. if ( !pDag )
  175. {
  176. pDag = pOutputElement->GetValueElement< CDmeDag >( "skeleton" );
  177. }
  178. if ( !pDag )
  179. return;
  180. CDmeAnimationList *pAnimationList = pOutputElement->GetValueElement< CDmeAnimationList >( "animationList" );
  181. m_hDag = pDag;
  182. ComputeDefaultTangentData( m_hDag, false );
  183. m_hAnimationList = pAnimationList;
  184. SelectAnimation( 0 );
  185. DrawJoints( pAnimationList != NULL );
  186. DrawJointNames( pAnimationList != NULL );
  187. }
  188. CDmeDag *CDmeDagRenderPanel::GetDmeElement()
  189. {
  190. return m_hDag;
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Draw joint names
  194. //-----------------------------------------------------------------------------
  195. void CDmeDagRenderPanel::DrawJointNames( CDmeDag *pRoot, CDmeDag *pDag, const matrix3x4_t& parentToWorld )
  196. {
  197. CDmeTransform *pJointTransform = pDag->GetTransform();
  198. int nJointIndex = -1;
  199. CDmeModel *pRootModel = CastElement<CDmeModel>( pRoot );
  200. if ( pRootModel )
  201. {
  202. nJointIndex = pRootModel->GetJointTransformIndex( pJointTransform );
  203. if ( nJointIndex < 0 && pRootModel != pDag )
  204. return;
  205. }
  206. matrix3x4_t jointToParent, jointToWorld;
  207. pJointTransform->GetTransform( jointToParent );
  208. ConcatTransforms( parentToWorld, jointToParent, jointToWorld );
  209. CDmeJoint *pJoint = CastElement< CDmeJoint >( pDag );
  210. if ( pJoint )
  211. {
  212. Vector vecJointOrigin;
  213. MatrixGetColumn( jointToWorld, 3, &vecJointOrigin );
  214. Vector2D vecPanelPos;
  215. ComputePanelPosition( vecJointOrigin, &vecPanelPos );
  216. char pJointName[512];
  217. if ( nJointIndex >= 0 )
  218. {
  219. Q_snprintf( pJointName, sizeof(pJointName), "%d : %s", nJointIndex, pJoint->GetName() );
  220. }
  221. else
  222. {
  223. Q_snprintf( pJointName, sizeof(pJointName), "%s", pJoint->GetName() );
  224. }
  225. g_pMatSystemSurface->DrawColoredText( m_hFont, vecPanelPos.x + 5, vecPanelPos.y, 255, 255, 255, 255, pJointName );
  226. }
  227. int nCount = pDag->GetChildCount();
  228. for ( int i = 0; i < nCount; ++i )
  229. {
  230. CDmeDag *pChild = pDag->GetChild(i);
  231. if ( !pChild )
  232. continue;
  233. DrawJointNames( pRoot, pChild, jointToWorld );
  234. }
  235. }
  236. //-----------------------------------------------------------------------------
  237. //
  238. //-----------------------------------------------------------------------------
  239. void CDmeDagRenderPanel::OnSmoothShade()
  240. {
  241. if ( m_pShadingMenu->IsChecked( m_nMenuSmoothShade ) )
  242. {
  243. m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_SMOOTH );
  244. }
  245. UpdateMenu();
  246. }
  247. //-----------------------------------------------------------------------------
  248. //
  249. //-----------------------------------------------------------------------------
  250. void CDmeDagRenderPanel::OnFlatShade()
  251. {
  252. if ( m_pShadingMenu->IsChecked( m_nMenuFlatShade ) )
  253. {
  254. m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_FLAT );
  255. }
  256. UpdateMenu();
  257. }
  258. //-----------------------------------------------------------------------------
  259. //
  260. //-----------------------------------------------------------------------------
  261. void CDmeDagRenderPanel::OnWireframe()
  262. {
  263. if ( m_pShadingMenu->IsChecked( m_nMenuWireframe ) )
  264. {
  265. m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_WIREFRAME );
  266. }
  267. UpdateMenu();
  268. }
  269. //-----------------------------------------------------------------------------
  270. //
  271. //-----------------------------------------------------------------------------
  272. void CDmeDagRenderPanel::OnBoundingBox()
  273. {
  274. if ( m_pShadingMenu->IsChecked( m_nMenuBoundingBox ) )
  275. {
  276. m_pDrawSettings->SetDrawType( CDmeDrawSettings::DRAW_BOUNDINGBOX );
  277. }
  278. UpdateMenu();
  279. }
  280. //-----------------------------------------------------------------------------
  281. //
  282. //-----------------------------------------------------------------------------
  283. void CDmeDagRenderPanel::OnNormals()
  284. {
  285. m_pDrawSettings->SetNormals( m_pShadingMenu->IsChecked( m_nMenuNormals ) );
  286. UpdateMenu();
  287. }
  288. //-----------------------------------------------------------------------------
  289. //
  290. //-----------------------------------------------------------------------------
  291. void CDmeDagRenderPanel::OnWireframeOnShaded()
  292. {
  293. m_pDrawSettings->SetWireframeOnShaded( m_pShadingMenu->IsChecked( m_nMenuWireframeOnShaded ) );
  294. UpdateMenu();
  295. }
  296. //-----------------------------------------------------------------------------
  297. //
  298. //-----------------------------------------------------------------------------
  299. void CDmeDagRenderPanel::OnBackfaceCulling()
  300. {
  301. m_pDrawSettings->SetBackfaceCulling( m_pShadingMenu->IsChecked( m_nMenuBackfaceCulling ) );
  302. UpdateMenu();
  303. }
  304. //-----------------------------------------------------------------------------
  305. //
  306. //-----------------------------------------------------------------------------
  307. void CDmeDagRenderPanel::OnXRay()
  308. {
  309. m_pDrawSettings->SetXRay( m_pShadingMenu->IsChecked( m_nMenuXRay ) );
  310. UpdateMenu();
  311. }
  312. //-----------------------------------------------------------------------------
  313. //
  314. //-----------------------------------------------------------------------------
  315. void CDmeDagRenderPanel::OnGrayShade()
  316. {
  317. m_pDrawSettings->SetGrayShade( m_pShadingMenu->IsChecked( m_nMenuGrayShade ) );
  318. UpdateMenu();
  319. }
  320. //-----------------------------------------------------------------------------
  321. //
  322. //-----------------------------------------------------------------------------
  323. void CDmeDagRenderPanel::OnFrame()
  324. {
  325. if ( !m_hDag )
  326. return;
  327. float flRadius;
  328. Vector vecCenter, vecWorldCenter;
  329. m_hDag->GetBoundingSphere( vecCenter, flRadius );
  330. matrix3x4_t dmeToEngine;
  331. CDmeDag::DmeToEngineMatrix( dmeToEngine );
  332. VectorTransform( vecCenter, dmeToEngine, vecWorldCenter );
  333. LookAt( vecWorldCenter, flRadius );
  334. }
  335. //-----------------------------------------------------------------------------
  336. //
  337. //-----------------------------------------------------------------------------
  338. void CDmeDagRenderPanel::PerformLayout()
  339. {
  340. BaseClass::PerformLayout();
  341. if ( m_pMenuBar->IsVisible() )
  342. {
  343. int iWidth;
  344. int iHeight;
  345. GetSize( iWidth, iHeight );
  346. int iMenuWidth; // Unused
  347. int iMenuHeight;
  348. m_pMenuBar->GetSize( iMenuWidth, iMenuHeight );
  349. m_pMenuBar->SetSize( iWidth, iMenuHeight );
  350. }
  351. }
  352. //-----------------------------------------------------------------------------
  353. // paint it!
  354. //-----------------------------------------------------------------------------
  355. void CDmeDagRenderPanel::Paint()
  356. {
  357. if ( m_hCurrentAnimation.Get() )
  358. {
  359. DmeTime_t currentTime( Plat_FloatTime() - m_flStartTime );
  360. if ( m_hCurrentAnimation->GetDuration() != DMETIME_ZERO )
  361. {
  362. currentTime = currentTime % m_hCurrentAnimation->GetDuration();
  363. }
  364. else
  365. {
  366. currentTime = DMETIME_ZERO;
  367. }
  368. currentTime += m_hCurrentAnimation->GetStartTime();
  369. DmeTime_t mediaTime = m_hCurrentAnimation->ToChildMediaTime( currentTime, true );
  370. int nChannelCount = m_hCurrentAnimation->m_Channels.Count();
  371. for ( int i = 0; i < nChannelCount; ++i )
  372. {
  373. m_hCurrentAnimation->m_Channels[i]->SetCurrentTime( mediaTime );
  374. }
  375. }
  376. if ( m_hCurrentVertexAnimation.Get() )
  377. {
  378. DmeTime_t currentTime( Plat_FloatTime() - m_flStartTime );
  379. currentTime = currentTime % m_hCurrentVertexAnimation->GetDuration();
  380. currentTime += m_hCurrentVertexAnimation->GetStartTime();
  381. DmeTime_t mediaTime = m_hCurrentVertexAnimation->ToChildMediaTime( currentTime, true );
  382. int nChannelCount = m_hCurrentVertexAnimation->m_Channels.Count();
  383. for ( int i = 0; i < nChannelCount; ++i )
  384. {
  385. m_hCurrentVertexAnimation->m_Channels[i]->SetCurrentTime( mediaTime );
  386. }
  387. }
  388. // FIXME: Shouldn't this happen at the application level?
  389. // run the machinery - apply, resolve, dependencies, operate, resolve
  390. {
  391. CDisableUndoScopeGuard guard;
  392. g_pDmElementFramework->SetOperators( m_operators );
  393. g_pDmElementFramework->Operate( true );
  394. }
  395. // allow elements and attributes to be edited again
  396. g_pDmElementFramework->BeginEdit();
  397. BaseClass::Paint();
  398. // Overlay the joint names
  399. if ( m_bDrawJointNames && m_hDag )
  400. {
  401. matrix3x4_t modelToWorld;
  402. CDmeDag::DmeToEngineMatrix( modelToWorld );
  403. DrawJointNames( m_hDag, m_hDag, modelToWorld );
  404. }
  405. }
  406. //-----------------------------------------------------------------------------
  407. // Indicate we should draw joint names
  408. //-----------------------------------------------------------------------------
  409. void CDmeDagRenderPanel::DrawJointNames( bool bDrawJointNames )
  410. {
  411. m_bDrawJointNames = bDrawJointNames;
  412. }
  413. //-----------------------------------------------------------------------------
  414. // Indicate we should draw joints
  415. //-----------------------------------------------------------------------------
  416. void CDmeDagRenderPanel::DrawJoints( bool bDrawJoint )
  417. {
  418. m_bDrawJoints = bDrawJoint;
  419. }
  420. //-----------------------------------------------------------------------------
  421. // Indicate we should draw the grid
  422. //-----------------------------------------------------------------------------
  423. void CDmeDagRenderPanel::DrawGrid( bool bDrawGrid )
  424. {
  425. m_bDrawGrid = bDrawGrid;
  426. }
  427. //-----------------------------------------------------------------------------
  428. // paint it!
  429. //-----------------------------------------------------------------------------
  430. void CDmeDagRenderPanel::OnPaint3D()
  431. {
  432. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  433. ITexture *pLocalCube = pRenderContext->GetLocalCubemap();
  434. if ( g_pMaterialSystemHardwareConfig->GetHDRType() == HDR_TYPE_NONE )
  435. {
  436. pRenderContext->BindLocalCubemap( m_DefaultEnvCubemap );
  437. }
  438. else
  439. {
  440. pRenderContext->BindLocalCubemap( m_DefaultHDREnvCubemap );
  441. }
  442. if ( m_bDrawGrid )
  443. {
  444. BaseClass::DrawGrid();
  445. }
  446. if ( m_bDrawJoints )
  447. {
  448. CDmeJoint::DrawJointHierarchy( true );
  449. }
  450. pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
  451. CDmeDag::DrawUsingEngineCoordinates( true );
  452. m_pDrawSettings->DrawDag( m_hDag );
  453. CDmeDag::DrawUsingEngineCoordinates( false );
  454. pRenderContext->Flush();
  455. pRenderContext->BindLocalCubemap( pLocalCube );
  456. }
  457. //-----------------------------------------------------------------------------
  458. // input
  459. //-----------------------------------------------------------------------------
  460. void CDmeDagRenderPanel::OnMouseDoublePressed( vgui::MouseCode code )
  461. {
  462. OnFrame();
  463. BaseClass::OnMouseDoublePressed( code );
  464. }
  465. //-----------------------------------------------------------------------------
  466. // TODO: Have a whole groovy keybinding thingy like SFM
  467. //-----------------------------------------------------------------------------
  468. void CDmeDagRenderPanel::OnKeyCodePressed( vgui::KeyCode code )
  469. {
  470. BaseClass::OnKeyCodePressed( code );
  471. if ( code == KEY_F )
  472. {
  473. OnFrame();
  474. }
  475. }
  476. //-----------------------------------------------------------------------------
  477. // Rebuilds the list of operators
  478. //-----------------------------------------------------------------------------
  479. void CDmeDagRenderPanel::RebuildOperatorList( )
  480. {
  481. m_operators.RemoveAll();
  482. if ( m_hCurrentAnimation.Get() )
  483. {
  484. int nChannelCount = m_hCurrentAnimation->m_Channels.Count();
  485. for ( int i = 0; i < nChannelCount; ++i )
  486. {
  487. m_hCurrentAnimation->m_Channels[i]->SetMode( CM_PLAY );
  488. m_operators.AddToTail( m_hCurrentAnimation->m_Channels[i] );
  489. }
  490. }
  491. if ( m_hCurrentVertexAnimation.Get() )
  492. {
  493. int nChannelCount = m_hCurrentVertexAnimation->m_Channels.Count();
  494. for ( int i = 0; i < nChannelCount; ++i )
  495. {
  496. m_hCurrentVertexAnimation->m_Channels[i]->SetMode( CM_PLAY );
  497. m_operators.AddToTail( m_hCurrentVertexAnimation->m_Channels[i] );
  498. }
  499. }
  500. m_flStartTime = Plat_FloatTime();
  501. }
  502. //-----------------------------------------------------------------------------
  503. // Select animation by index
  504. //-----------------------------------------------------------------------------
  505. void CDmeDagRenderPanel::SelectAnimation( int nIndex )
  506. {
  507. m_hCurrentAnimation = NULL;
  508. if ( m_hAnimationList.Get() && ( nIndex >= 0 ) )
  509. {
  510. // FIXME: How is this actually going to work?
  511. m_hCurrentAnimation = m_hAnimationList->GetAnimation( nIndex );
  512. }
  513. RebuildOperatorList();
  514. }
  515. void CDmeDagRenderPanel::SelectVertexAnimation( int nIndex )
  516. {
  517. m_hCurrentVertexAnimation = NULL;
  518. if ( m_hVertexAnimationList.Get() && ( nIndex >= 0 ) )
  519. {
  520. // FIXME: How is this actually going to work?
  521. m_hCurrentVertexAnimation = m_hVertexAnimationList->GetAnimation( nIndex );
  522. }
  523. RebuildOperatorList();
  524. }
  525. //-----------------------------------------------------------------------------
  526. // Select animation by name
  527. //-----------------------------------------------------------------------------
  528. void CDmeDagRenderPanel::SelectAnimation( const char *pAnimName )
  529. {
  530. if ( !pAnimName[0] )
  531. {
  532. SelectAnimation( -1 );
  533. return;
  534. }
  535. if ( m_hAnimationList )
  536. {
  537. int nIndex = m_hAnimationList->FindAnimation( pAnimName );
  538. if ( nIndex >= 0 )
  539. {
  540. SelectAnimation( nIndex );
  541. }
  542. }
  543. }
  544. void CDmeDagRenderPanel::SelectVertexAnimation( const char *pAnimName )
  545. {
  546. if ( !pAnimName[0] )
  547. {
  548. SelectVertexAnimation( -1 );
  549. return;
  550. }
  551. if ( m_hVertexAnimationList )
  552. {
  553. int nIndex = m_hVertexAnimationList->FindAnimation( pAnimName );
  554. if ( nIndex >= 0 )
  555. {
  556. SelectVertexAnimation( nIndex );
  557. }
  558. }
  559. }
  560. //-----------------------------------------------------------------------------
  561. // Sets animation
  562. //-----------------------------------------------------------------------------
  563. void CDmeDagRenderPanel::SetAnimationList( CDmeAnimationList *pAnimationList )
  564. {
  565. m_hAnimationList = pAnimationList;
  566. int nCount = pAnimationList ? pAnimationList->GetAnimationCount() : 0;
  567. if ( nCount == 0 )
  568. {
  569. m_hCurrentAnimation = NULL;
  570. return;
  571. }
  572. SelectAnimation( 0 );
  573. }
  574. void CDmeDagRenderPanel::SetVertexAnimationList( CDmeAnimationList *pAnimationList )
  575. {
  576. m_hVertexAnimationList = pAnimationList;
  577. int nCount = pAnimationList ? pAnimationList->GetAnimationCount() : 0;
  578. if ( nCount == 0 )
  579. {
  580. m_hCurrentVertexAnimation = NULL;
  581. return;
  582. }
  583. SelectVertexAnimation( 0 );
  584. }
  585. //-----------------------------------------------------------------------------
  586. //
  587. //-----------------------------------------------------------------------------
  588. void CDmeDagRenderPanel::UpdateMenu()
  589. {
  590. switch ( m_pDrawSettings->GetDrawType() )
  591. {
  592. case CDmeDrawSettings::DRAW_FLAT:
  593. m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
  594. m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, true );
  595. m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
  596. m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
  597. break;
  598. case CDmeDrawSettings::DRAW_WIREFRAME:
  599. m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
  600. m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
  601. m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, true );
  602. m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
  603. break;
  604. case CDmeDrawSettings::DRAW_BOUNDINGBOX:
  605. m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, false );
  606. m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
  607. m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
  608. m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, true );
  609. break;
  610. default:
  611. m_pShadingMenu->SetMenuItemChecked( m_nMenuSmoothShade, true );
  612. m_pShadingMenu->SetMenuItemChecked( m_nMenuFlatShade, false );
  613. m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframe, false );
  614. m_pShadingMenu->SetMenuItemChecked( m_nMenuBoundingBox, false );
  615. break;
  616. }
  617. m_pShadingMenu->SetMenuItemChecked( m_nMenuNormals, m_pDrawSettings->GetNormals() );
  618. m_pShadingMenu->SetMenuItemChecked( m_nMenuWireframeOnShaded, m_pDrawSettings->GetWireframeOnShaded() );
  619. m_pShadingMenu->SetMenuItemChecked( m_nMenuBackfaceCulling, m_pDrawSettings->GetBackfaceCulling() );
  620. m_pShadingMenu->SetMenuItemChecked( m_nMenuXRay, m_pDrawSettings->GetXRay() );
  621. m_pShadingMenu->SetMenuItemChecked( m_nMenuGrayShade, m_pDrawSettings->GetGrayShade() );
  622. }