Sidebar.Animation.js 1.8 KB

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