MorphAnimMesh.js 1.3 KB

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