Sidebar.Animation.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { UIPanel, UIBreak, UIButton, UIDiv, UIText, UINumber, UIRow } from './libs/ui.js';
  2. function SidebarAnimation( 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. console.log( action );
  19. action.isRunning() ? action.stop() : action.play();
  20. button.setTextContent( getButtonText( action ) );
  21. } );
  22. container.add( button );
  23. return container;
  24. }
  25. signals.objectSelected.add( function ( object ) {
  26. if ( object !== null && object.animations.length > 0 ) {
  27. animationsList.clear();
  28. const animations = object.animations;
  29. for ( const animation of animations ) {
  30. animationsList.add( new Animation( animation, object ) );
  31. }
  32. container.setDisplay( '' );
  33. } else {
  34. container.setDisplay( 'none' );
  35. }
  36. } );
  37. signals.objectRemoved.add( function ( object ) {
  38. if ( object !== null && object.animations.length > 0 ) {
  39. mixer.uncacheRoot( object );
  40. }
  41. } );
  42. const container = new UIPanel();
  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( 0.5 ).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' ) ).setWidth( '90px' ) );
  55. mixerTimeScaleRow.add( mixerTimeScaleNumber );
  56. container.add( mixerTimeScaleRow );
  57. return container;
  58. }
  59. export { SidebarAnimation };