Sidebar.Animation.js 1.7 KB

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