Browse Source

Merge pull request #17504 from Bug-Reaper/animation-mixer-set-time-method

AnimationMixer: Add .setTime() method.
Mr.doob 5 years ago
parent
commit
c5323d1a31

+ 7 - 0
docs/api/en/animation/AnimationMixer.html

@@ -85,6 +85,13 @@
 			This is usually done in the render loop, passing [page:Clock.getDelta clock.getDelta] scaled by the mixer's [page:.timeScale timeScale]).
 		</p>
 
+		<h3>[method:AnimationMixer setTime]([param:Number timeInSeconds]) </h3>
+		<p>
+			Sets the global mixer to a specific time and updates the animation accordingly.<br /><br />
+
+			This is useful when you need to jump to an exact time in an animation. The input parameter will be scaled by the mixer's [page:.timeScale timeScale].
+		</p>
+
 		<h3>[method:null uncacheClip]([param:AnimationClip clip])</h3>
 
 		<p>

+ 1 - 0
src/animation/AnimationMixer.d.ts

@@ -13,6 +13,7 @@ export class AnimationMixer extends EventDispatcher {
 	existingAction( clip: AnimationClip, root?: any ): AnimationAction;
 	stopAllAction(): AnimationMixer;
 	update( deltaTime: number ): AnimationMixer;
+	setTime( timeInSeconds: number ): AnimationMixer;
 	getRoot(): any;
 	uncacheClip( clip: AnimationClip ): void;
 	uncacheRoot( root: any ): void;

+ 14 - 0
src/animation/AnimationMixer.js

@@ -653,6 +653,20 @@ AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 	},
 
+	// Allows you to seek to a specific time in an animation.
+	setTime: function ( timeInSeconds ) {
+
+		this.time = 0; // Zero out time attribute for AnimationMixer object;
+		for ( var i = 0; i < this._actions.length; i ++ ) {
+
+			this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
+
+		}
+
+		return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
+
+	},
+
 	// return this mixer's root target object
 	getRoot: function () {