MorphAnimMesh.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. console.warn( "THREE.MorphAnimMesh: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. /**
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.MorphAnimMesh = function ( geometry, material ) {
  6. THREE.Mesh.call( this, geometry, material );
  7. this.type = 'MorphAnimMesh';
  8. this.mixer = new THREE.AnimationMixer( this );
  9. this.activeAction = null;
  10. };
  11. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  12. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  13. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  14. this.mixer.timeScale = 1.0;
  15. };
  16. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  17. this.mixer.timeScale = - 1.0;
  18. };
  19. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  20. if ( this.activeAction ) {
  21. this.activeAction.stop();
  22. this.activeAction = null;
  23. }
  24. var clip = THREE.AnimationClip.findByName( this, label );
  25. if ( clip ) {
  26. var action = this.mixer.clipAction( clip );
  27. action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
  28. this.activeAction = action.play();
  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. };