Sidebar.Animation.js 1.9 KB

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