Sidebar.Animation.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { UIPanel, UIBreak, UISelect, UIButton, UIText, UINumber, UIRow } 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. if ( object !== null && object.animations.length > 0 ) {
  9. var animations = object.animations;
  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. mixerTimeScaleNumber.setValue( mixer.timeScale );
  21. } else {
  22. container.setDisplay( 'none' );
  23. }
  24. } );
  25. signals.objectRemoved.add( function ( object ) {
  26. if ( object !== null && object.animations.length > 0 ) {
  27. mixer.uncacheRoot( object );
  28. }
  29. } );
  30. function playAction() {
  31. actions[ animationsSelect.getValue() ].play();
  32. }
  33. function stopAction() {
  34. actions[ animationsSelect.getValue() ].stop();
  35. signals.animationStopped.dispatch();
  36. }
  37. function changeTimeScale() {
  38. mixer.timeScale = mixerTimeScaleNumber.getValue();
  39. }
  40. var container = new UIPanel();
  41. container.setDisplay( 'none' );
  42. container.add( new UIText( strings.getKey( 'sidebar/animations' ) ).setTextTransform( 'uppercase' ) );
  43. container.add( new UIBreak() );
  44. container.add( new UIBreak() );
  45. //
  46. var animationsRow = new UIRow();
  47. var animationsSelect = new UISelect().setFontSize( '12px' );
  48. animationsRow.add( animationsSelect );
  49. animationsRow.add( new UIButton( strings.getKey( 'sidebar/animations/play' ) ).setMarginLeft( '4px' ).onClick( playAction ) );
  50. animationsRow.add( new UIButton( strings.getKey( 'sidebar/animations/stop' ) ).setMarginLeft( '4px' ).onClick( stopAction ) );
  51. container.add( animationsRow );
  52. //
  53. var mixerTimeScaleRow = new UIRow();
  54. var mixerTimeScaleNumber = new UINumber( 0.5 ).setWidth( '60px' ).setRange( - 10, 10 ).onChange( changeTimeScale );
  55. mixerTimeScaleRow.add( new UIText( strings.getKey( 'sidebar/animations/timescale' ) ).setWidth( '90px' ) );
  56. mixerTimeScaleRow.add( mixerTimeScaleNumber );
  57. container.add( mixerTimeScaleRow );
  58. return container;
  59. }
  60. export { SidebarAnimation };