MorphAnimMesh.js 1.4 KB

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