MorphAnimMesh.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ( function () {
  2. class MorphAnimMesh extends THREE.Mesh {
  3. constructor( geometry, material ) {
  4. super( geometry, material );
  5. this.type = 'MorphAnimMesh';
  6. this.mixer = new THREE.AnimationMixer( this );
  7. this.activeAction = null;
  8. }
  9. setDirectionForward() {
  10. this.mixer.timeScale = 1.0;
  11. }
  12. setDirectionBackward() {
  13. this.mixer.timeScale = - 1.0;
  14. }
  15. playAnimation( label, fps ) {
  16. if ( this.activeAction ) {
  17. this.activeAction.stop();
  18. this.activeAction = null;
  19. }
  20. const clip = THREE.AnimationClip.findByName( this, label );
  21. if ( clip ) {
  22. const action = this.mixer.clipAction( clip );
  23. action.timeScale = clip.tracks.length * fps / clip.duration;
  24. this.activeAction = action.play();
  25. } else {
  26. throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );
  27. }
  28. }
  29. updateAnimation( delta ) {
  30. this.mixer.update( delta );
  31. }
  32. copy( source ) {
  33. super.copy( source );
  34. this.mixer = new THREE.AnimationMixer( this );
  35. return this;
  36. }
  37. }
  38. THREE.MorphAnimMesh = MorphAnimMesh;
  39. } )();