Sidebar.Animation.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. container.add( animationsRow );
  11. var animations = {};
  12. signals.objectAdded.add( function ( object ) {
  13. object.traverse( function ( child ) {
  14. if ( child instanceof THREE.SkinnedMesh ) {
  15. var material = child.material;
  16. if ( material instanceof THREE.MeshFaceMaterial ) {
  17. for ( var i = 0; i < material.materials.length; i ++ ) {
  18. material.materials[ i ].skinning = true;
  19. }
  20. } else {
  21. child.material.skinning = true;
  22. }
  23. animations[ child.id ] = new THREE.Animation( child, child.geometry.animation );
  24. }
  25. } );
  26. } );
  27. signals.objectSelected.add( function ( object ) {
  28. container.setDisplay( 'none' );
  29. if ( object instanceof THREE.SkinnedMesh ) {
  30. animationsRow.clear();
  31. var animation = animations[ object.id ];
  32. var playButton = new UI.Button().setLabel( 'Play' ).onClick( function () {
  33. animation.play();
  34. signals.playAnimation.dispatch( animation );
  35. } );
  36. animationsRow.add( playButton );
  37. var pauseButton = new UI.Button().setLabel( 'Stop' ).onClick( function () {
  38. animation.stop();
  39. signals.stopAnimation.dispatch( animation );
  40. } );
  41. animationsRow.add( pauseButton );
  42. container.setDisplay( 'block' );
  43. }
  44. } );
  45. return container;
  46. }