Sidebar.Animation.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. } else if ( child instanceof THREE.MorphAnimMesh ) {
  32. var animation = new THREE.MorphAnimation( child );
  33. animation.duration = 30;
  34. // temporal hack for THREE.AnimationHandler
  35. animation._play = animation.play;
  36. animation.play = function () {
  37. this._play();
  38. THREE.AnimationHandler.play( this );
  39. };
  40. animation.resetBlendWeights = function () {};
  41. animation.stop = function () {
  42. this.pause();
  43. THREE.AnimationHandler.stop( this );
  44. };
  45. animations[ child.id ] = animation;
  46. }
  47. } );
  48. } );
  49. signals.objectSelected.add( function ( object ) {
  50. container.setDisplay( 'none' );
  51. if ( object instanceof THREE.SkinnedMesh || object instanceof THREE.MorphAnimMesh ) {
  52. animationsRow.clear();
  53. var animation = animations[ object.id ];
  54. var playButton = new UI.Button( 'Play' ).onClick( function () {
  55. animation.play();
  56. } );
  57. animationsRow.add( playButton );
  58. var pauseButton = new UI.Button( 'Stop' ).onClick( function () {
  59. animation.stop();
  60. } );
  61. animationsRow.add( pauseButton );
  62. container.setDisplay( 'block' );
  63. }
  64. } );
  65. return container;
  66. }