Sidebar.Animation.js 1.8 KB

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