MorphAnimMesh.js 1.4 KB

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