MorphAnimMesh.js 1.3 KB

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