MorphAnimMesh.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.mixer.removeAction( this.activeAction );
  21. this.activeAction = null;
  22. }
  23. var clip = THREE.AnimationClip.findByName( this.geometry.animations, label );
  24. if ( clip ) {
  25. var action = new THREE.AnimationAction( clip );
  26. action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
  27. this.mixer.addAction( action );
  28. this.activeAction = action;
  29. } else {
  30. throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );
  31. }
  32. };
  33. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  34. this.mixer.update( delta );
  35. };
  36. THREE.MorphAnimMesh.prototype.copy = function ( source ) {
  37. THREE.Mesh.prototype.copy.call( this, source );
  38. this.mixer = new THREE.AnimationMixer( this );
  39. return this;
  40. };