Sidebar.Object.Animation.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { UIBreak, UIButton, UIDiv, UIText, UINumber, UIRow } from './libs/ui.js';
  2. function SidebarObjectAnimation( editor ) {
  3. const strings = editor.strings;
  4. const signals = editor.signals;
  5. const mixer = editor.mixer;
  6. function getButtonText( action ) {
  7. return action.isRunning()
  8. ? strings.getKey( 'sidebar/animations/stop' )
  9. : strings.getKey( 'sidebar/animations/play' );
  10. }
  11. function Animation( animation, object ) {
  12. const action = mixer.clipAction( animation, object );
  13. const container = new UIRow();
  14. const name = new UIText( animation.name ).setWidth( '200px' );
  15. container.add( name );
  16. const button = new UIButton( getButtonText( action ) );
  17. button.onClick( function () {
  18. action.isRunning() ? action.stop() : action.play();
  19. button.setTextContent( getButtonText( action ) );
  20. } );
  21. container.add( button );
  22. return container;
  23. }
  24. signals.objectSelected.add( function ( object ) {
  25. if ( object !== null && object.animations.length > 0 ) {
  26. animationsList.clear();
  27. const animations = object.animations;
  28. for ( const animation of animations ) {
  29. animationsList.add( new Animation( animation, object ) );
  30. }
  31. container.setDisplay( '' );
  32. } else {
  33. container.setDisplay( 'none' );
  34. }
  35. } );
  36. signals.objectRemoved.add( function ( object ) {
  37. if ( object !== null && object.animations.length > 0 ) {
  38. mixer.uncacheRoot( object );
  39. }
  40. } );
  41. const container = new UIDiv();
  42. container.setMarginTop( '20px' );
  43. container.setDisplay( 'none' );
  44. container.add( new UIText( strings.getKey( 'sidebar/animations' ) ).setTextTransform( 'uppercase' ) );
  45. container.add( new UIBreak() );
  46. container.add( new UIBreak() );
  47. const animationsList = new UIDiv();
  48. container.add( animationsList );
  49. const mixerTimeScaleRow = new UIRow();
  50. const mixerTimeScaleNumber = new UINumber( 1 ).setWidth( '60px' ).setRange( - 10, 10 );
  51. mixerTimeScaleNumber.onChange( function () {
  52. mixer.timeScale = mixerTimeScaleNumber.getValue();
  53. } );
  54. mixerTimeScaleRow.add( new UIText( strings.getKey( 'sidebar/animations/timescale' ) ).setClass( 'Label' ) );
  55. mixerTimeScaleRow.add( mixerTimeScaleNumber );
  56. container.add( mixerTimeScaleRow );
  57. return container;
  58. }
  59. export { SidebarObjectAnimation };