Sidebar.Animation.js 1.8 KB

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