Sidebar.Animation.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { UIPanel, UIDiv, UIBreak, UISelect, UIButton, UIText } from './libs/ui.js';
  2. function SidebarAnimation( editor ) {
  3. var signals = editor.signals;
  4. var mixer = editor.mixer;
  5. var actions = {};
  6. signals.objectSelected.add( function ( object ) {
  7. var animations = editor.animations[ object !== null ? object.uuid : '' ];
  8. if ( animations !== undefined ) {
  9. container.setDisplay( '' );
  10. var options = {};
  11. var firstAnimation;
  12. for ( var animation of animations ) {
  13. if ( firstAnimation === undefined ) firstAnimation = animation.name;
  14. actions[ animation.name ] = mixer.clipAction( animation, object );
  15. options[ animation.name ] = animation.name;
  16. }
  17. animationsSelect.setOptions( options );
  18. animationsSelect.setValue( firstAnimation );
  19. } else {
  20. container.setDisplay( 'none' );
  21. }
  22. } );
  23. signals.objectRemoved.add( function ( object ) {
  24. var animations = editor.animations[ object !== null ? object.uuid : '' ];
  25. if ( animations !== undefined ) {
  26. mixer.uncacheRoot( object );
  27. }
  28. } );
  29. function playAction() {
  30. actions[ animationsSelect.getValue() ].play();
  31. }
  32. function stopAction() {
  33. actions[ animationsSelect.getValue() ].stop();
  34. }
  35. var container = new UIPanel();
  36. container.setDisplay( 'none' );
  37. container.add( new UIText( 'Animations' ).setTextTransform( 'uppercase' ) );
  38. container.add( new UIBreak() );
  39. container.add( new UIBreak() );
  40. var div = new UIDiv();
  41. container.add( div );
  42. var animationsSelect = new UISelect().setFontSize( '12px' );
  43. div.add( animationsSelect );
  44. div.add( new UIButton( 'Play' ).setMarginLeft( '4px' ).onClick( playAction ) );
  45. div.add( new UIButton( 'Stop' ).setMarginLeft( '4px' ).onClick( stopAction ) );
  46. return container;
  47. }
  48. export { SidebarAnimation };