Sidebar.Animation.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. console.log( child.geometry );
  24. animations[ child.id ] = new THREE.Animation( child );
  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. }