MorphAnimMesh.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. import {
  5. AnimationClip,
  6. AnimationMixer,
  7. Mesh
  8. } from "../../../build/three.module.js";
  9. var MorphAnimMesh = function ( geometry, material ) {
  10. Mesh.call( this, geometry, material );
  11. this.type = 'MorphAnimMesh';
  12. this.mixer = new AnimationMixer( this );
  13. this.activeAction = null;
  14. };
  15. MorphAnimMesh.prototype = Object.create( Mesh.prototype );
  16. MorphAnimMesh.prototype.constructor = MorphAnimMesh;
  17. MorphAnimMesh.prototype.setDirectionForward = function () {
  18. this.mixer.timeScale = 1.0;
  19. };
  20. MorphAnimMesh.prototype.setDirectionBackward = function () {
  21. this.mixer.timeScale = - 1.0;
  22. };
  23. MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  24. if ( this.activeAction ) {
  25. this.activeAction.stop();
  26. this.activeAction = null;
  27. }
  28. var clip = AnimationClip.findByName( this, label );
  29. if ( clip ) {
  30. var action = this.mixer.clipAction( clip );
  31. action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
  32. this.activeAction = action.play();
  33. } else {
  34. throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );
  35. }
  36. };
  37. MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  38. this.mixer.update( delta );
  39. };
  40. MorphAnimMesh.prototype.copy = function ( source ) {
  41. Mesh.prototype.copy.call( this, source );
  42. this.mixer = new AnimationMixer( this );
  43. return this;
  44. };
  45. export { MorphAnimMesh };