Browse Source

fix sea3d onComplete animation & AnimationAction wrong reference (#8941)

* onComplete animation fix

* wrong variable reference

* remove check action.enabled is no longer necessary

* remove animationData.completed is no longer necessary
sunag 9 years ago
parent
commit
bfec4ef203
2 changed files with 26 additions and 26 deletions
  1. 24 24
      examples/js/loaders/sea3d/SEA3DLoader.js
  2. 2 2
      src/animation/AnimationAction.js

+ 24 - 24
examples/js/loaders/sea3d/SEA3DLoader.js

@@ -474,12 +474,10 @@ THREE.SEA3D.Animator.prototype.update = function( dt ) {
 
 	this.mixer.update( dt );
 
-	if ( ! this.currentAnimationAction.enabled && ! this.currentAnimationData.completed ) {
+	if ( this.currentAnimationAction.paused ) {
 
 		this.pause();
 
-		this.currentAnimationData.completed = true;
-
 		if ( this.currentAnimationData.onComplete ) this.currentAnimationData.onComplete( this );
 
 	}
@@ -581,41 +579,43 @@ THREE.SEA3D.Animator.prototype.play = function( name, crossfade, offset, weight
 
 	if ( animation == this.currentAnimation ) {
 
-		if ( offset !== undefined ) this.currentAnimationAction.time = offset;
-		if ( weight !== undefined ) this.currentAnimationAction.setEffectiveWeight( weight );
+		if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset : 0;
+		this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
+		this.currentAnimationAction.paused = false;
 
-		return this;
+		return this.resume();
 
-	}
+	} else {
 
-	if ( ! animation ) throw new Error( 'Animation "' + name + '" not found.' );
+		if ( ! animation ) throw new Error( 'Animation "' + name + '" not found.' );
 
-	this.previousAnimation = this.currentAnimation;
-	this.currentAnimation = animation;
+		this.previousAnimation = this.currentAnimation;
+		this.currentAnimation = animation;
 
-	this.previousAnimationAction = this.currentAnimationAction;
-	this.currentAnimationAction = this.mixer.clipAction( animation ).setLoop( animation.loop ? THREE.LoopRepeat : THREE.LoopOnce, Infinity ).reset();
-	this.currentAnimationAction.clampWhenFinished = true;
+		this.previousAnimationAction = this.currentAnimationAction;
+		this.currentAnimationAction = this.mixer.clipAction( animation ).setLoop( animation.loop ? THREE.LoopRepeat : THREE.LoopOnce, Infinity ).reset();
+		this.currentAnimationAction.clampWhenFinished = true;
+		this.currentAnimationAction.paused = false;
 
-	this.previousAnimationData = this.currentAnimationData;
-	this.currentAnimationData = this.animationsData[ name ];
+		this.previousAnimationData = this.currentAnimationData;
+		this.currentAnimationData = this.animationsData[ name ];
 
-	this.currentAnimationData.completed = false;
+		this.updateTimeScale();
 
-	this.updateTimeScale();
+		if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset : 0;
+		this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
 
-	this.currentAnimationAction.play();
+		this.currentAnimationAction.play();
 
-	if ( offset !== undefined ) this.currentAnimationAction.time = offset;
-	if ( weight !== undefined ) this.currentAnimationAction.setEffectiveWeight( weight );
+		if ( ! this.playing ) this.mixer.update( 0 );
 
-	if ( ! this.playing ) this.mixer.update( 0 );
+		this.playing = true;
 
-	this.playing = true;
+		if ( this.previousAnimation ) this.previousAnimationAction.crossFadeTo( this.currentAnimationAction, crossfade || 0, true );
 
-	if ( this.previousAnimation ) this.previousAnimationAction.crossFadeTo( this.currentAnimationAction, crossfade || 0, true );
+		THREE.SEA3D.AnimationHandler.addAnimator( this );
 
-	THREE.SEA3D.AnimationHandler.addAnimator( this );
+	}
 
 	return this;
 

+ 2 - 2
src/animation/AnimationAction.js

@@ -447,7 +447,7 @@ THREE.AnimationAction._new.prototype = {
 					if ( timeScale === 0 ) {
 
 						// motion has halted, pause
-						this.pause = true;
+						this.paused = true;
 
 					} else {
 
@@ -500,7 +500,7 @@ THREE.AnimationAction._new.prototype = {
 
 				} else break handle_stop;
 
-				if ( this.clampWhenFinished ) this.pause = true;
+				if ( this.clampWhenFinished ) this.paused = true;
 				else this.enabled = false;
 
 				this._mixer.dispatchEvent( {