Sidebar.Animation.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Sidebar.Animation = function ( editor ) {
  2. var signals = editor.signals;
  3. var options = {};
  4. var possibleAnimations = {};
  5. var container = new UI.CollapsiblePanel();
  6. container.setDisplay( 'none' );
  7. container.addStatic( new UI.Text( 'ANIMATION' ) );
  8. container.add( new UI.Break() );
  9. var AnimationsRow = new UI.Panel();
  10. var Animations = new UI.Select().setOptions( options ).setWidth( '130px' ).setColor( '#444' ).setFontSize( '12px' );
  11. AnimationsRow.add( new UI.Text( 'animations' ).setWidth( '90px' ) );
  12. AnimationsRow.add( Animations );
  13. container.add( AnimationsRow );
  14. container.add( new UI.Break() );
  15. var PlayRow = new UI.Panel();
  16. var playButton = new UI.Button().setLabel( 'Play' ).onClick( play );
  17. PlayRow.add( playButton );
  18. container.add( PlayRow );
  19. container.add( new UI.Break() );
  20. function play() {
  21. var value = Animations.getValue();
  22. if ( possibleAnimations[ value ] ) {
  23. var anims = possibleAnimations[value]
  24. for ( var i = 0; i < anims.length; i ++ ) {
  25. anims[ i ].play();
  26. }
  27. signals.playAnimations.dispatch( anims );
  28. };
  29. }
  30. signals.objectAdded.add( function ( object ) {
  31. if ( object instanceof THREE.SkinnedMesh ) {
  32. var geometry = object.geometry;
  33. var material = object.material;
  34. material.skinning = true;
  35. var name = geometry.animation.name;
  36. options[ name ] = name
  37. Animations.setOptions( options );
  38. THREE.AnimationHandler.add( geometry.animation );
  39. var animation = new THREE.Animation( object, name );
  40. if ( possibleAnimations[ name ] ){
  41. possibleAnimations[ name ].push( animation );
  42. } else {
  43. possibleAnimations[ name ] = [ animation ];
  44. }
  45. }
  46. } );
  47. signals.objectSelected.add( function ( object ) {
  48. if ( object && object.geometry && object.geometry.animation ) {
  49. container.setDisplay( 'block' );
  50. } else {
  51. container.setDisplay( 'none' );
  52. }
  53. } );
  54. return container;
  55. }