Sidebar.Animation.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. Sidebar.Animation = function ( editor ) {
  2. var signals = editor.signals;
  3. var options = {};
  4. var possibleAnimations = {};
  5. var container = new UI.CollapsiblePanel();
  6. container.setCollapsed( true );
  7. container.setDisplay( 'none' );
  8. container.addStatic( new UI.Text( 'Animation' ).setTextTransform( 'uppercase' ) );
  9. container.add( new UI.Break() );
  10. var animationsRow = new UI.Panel();
  11. container.add( animationsRow );
  12. var animations = {};
  13. signals.objectAdded.add( function ( object ) {
  14. object.traverse( function ( child ) {
  15. if ( child instanceof THREE.SkinnedMesh ) {
  16. var material = child.material;
  17. if ( material instanceof THREE.MeshFaceMaterial ) {
  18. for ( var i = 0; i < material.materials.length; i ++ ) {
  19. material.materials[ i ].skinning = true;
  20. }
  21. } else {
  22. child.material.skinning = true;
  23. }
  24. animations[ child.id ] = new THREE.Animation( child, child.geometry.animation );
  25. }
  26. } );
  27. } );
  28. signals.objectSelected.add( function ( object ) {
  29. container.setDisplay( 'none' );
  30. if ( object instanceof THREE.SkinnedMesh ) {
  31. animationsRow.clear();
  32. var animation = animations[ object.id ];
  33. var playButton = new UI.Button().setLabel( 'Play' ).onClick( function () {
  34. animation.play();
  35. signals.playAnimation.dispatch( animation );
  36. } );
  37. animationsRow.add( playButton );
  38. var pauseButton = new UI.Button().setLabel( 'Stop' ).onClick( function () {
  39. animation.stop();
  40. signals.stopAnimation.dispatch( animation );
  41. } );
  42. animationsRow.add( pauseButton );
  43. container.setDisplay( 'block' );
  44. }
  45. } );
  46. return container;
  47. }