| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /**
- * @author mrdoob / http://mrdoob.com
- */
- THREE.MorphAnimation = function ( mesh ) {
- this.mesh = mesh;
- this.frames = mesh.morphTargetInfluences.length;
- this.currentTime = 0;
- this.duration = 1000;
- this.loop = true;
- this.isPlaying = false;
- };
- THREE.MorphAnimation.prototype = {
- play: function () {
- this.isPlaying = true;
- },
- pause: function () {
- this.isPlaying = false;
- },
- update: ( function () {
- var lastFrame = 0;
- var currentFrame = 0;
- return function ( delta ) {
- if ( this.isPlaying === false ) return;
- this.currentTime += delta;
- if ( this.loop === true && this.currentTime > this.duration ) {
- this.currentTime %= this.duration;
- }
- this.currentTime = Math.min( this.currentTime, this.duration );
- var interpolation = this.duration / this.frames;
- var frame = Math.floor( this.currentTime / interpolation );
- if ( frame != currentFrame ) {
- this.mesh.morphTargetInfluences[ lastFrame ] = 0;
- this.mesh.morphTargetInfluences[ currentFrame ] = 1;
- this.mesh.morphTargetInfluences[ frame ] = 0;
- lastFrame = currentFrame;
- currentFrame = frame;
- }
- this.mesh.morphTargetInfluences[ frame ] = ( this.currentTime % interpolation ) / interpolation;
- this.mesh.morphTargetInfluences[ lastFrame ] = 1 - this.mesh.morphTargetInfluences[ frame ];
- }
- } )()
- };
|