Jelajahi Sumber

Addressing PR feedback from https://github.com/mrdoob/three.js/pull/18822#discussion_r395966066

- Added AnimationBlendMode constants: OverrideBlendMode and AdditiveBlendMode
- Updated AnimationAction and AnimationMixer to use blendMode rather than isAdditive boolean
- Updated example to use AnimationBlendMode constants rather than isAdditive boolean
Christine Morten 5 tahun lalu
induk
melakukan
9715a3ffcc

TEMPAT SAMPAH
examples/screenshots/webgl_animation_skinning_additive_blending.png


+ 2 - 2
examples/webgl_animation_skinning_additive_blending.html

@@ -117,7 +117,7 @@
 
 						if ( baseActions[ name ] ) {
 
-							const action = mixer.clipAction( clip, undefined, false );
+							const action = mixer.clipAction( clip, undefined, THREE.OverrideBlendMode );
 							activateAction( action );
 							baseActions[ name ].action = action;
 							allActions.push( action );
@@ -134,7 +134,7 @@
 
 							}
 
-							const action = mixer.clipAction( clip, undefined, true );
+							const action = mixer.clipAction( clip, undefined, THREE.AdditiveBlendMode );
 							activateAction( action );
 							additiveActions[ name ].action = action;
 							allActions.push( action );

+ 3 - 3
src/animation/AnimationAction.d.ts

@@ -1,14 +1,14 @@
 import { AnimationMixer } from './AnimationMixer';
 import { AnimationClip } from './AnimationClip';
-import { AnimationActionLoopStyles } from '../constants';
+import { AnimationActionLoopStyles, AnimationBlendMode } from '../constants';
 import { Object3D } from '../core/Object3D';
 // Animation ////////////////////////////////////////////////////////////////////////////////////////
 
 export class AnimationAction {
 
-	constructor( mixer: AnimationMixer, clip: AnimationClip, localRoot?: Object3D, isAdditive?: boolean );
+	constructor( mixer: AnimationMixer, clip: AnimationClip, localRoot?: Object3D, blendMode?: AnimationBlendMode );
 
-	isAdditive: boolean;
+	blendMode: AnimationBlendMode;
 	loop: AnimationActionLoopStyles;
 	time: number;
 	timeScale: number;

+ 18 - 13
src/animation/AnimationAction.js

@@ -1,4 +1,4 @@
-import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, LoopOnce, LoopRepeat } from '../constants.js';
+import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, LoopOnce, LoopRepeat, OverrideBlendMode, AdditiveBlendMode } from '../constants.js';
 
 /**
  *
@@ -11,12 +11,12 @@ import { WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, LoopPingPong, L
  *
  */
 
-function AnimationAction( mixer, clip, localRoot, isAdditive = false ) {
+function AnimationAction( mixer, clip, localRoot, blendMode = OverrideBlendMode ) {
 
 	this._mixer = mixer;
 	this._clip = clip;
 	this._localRoot = localRoot || null;
-	this.isAdditive = isAdditive;
+	this.blendMode = blendMode;
 
 	var tracks = clip.tracks,
 		nTracks = tracks.length,
@@ -375,23 +375,28 @@ Object.assign( AnimationAction.prototype, {
 			var interpolants = this._interpolants;
 			var propertyMixers = this._propertyBindings;
 
-			if ( this.isAdditive ) {
+			switch ( this.blendMode ) {
 
-				for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
+				case AdditiveBlendMode:
 
-					interpolants[ j ].evaluate( clipTime );
-					propertyMixers[ j ].accumulateAdditive( weight );
+					for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
 
-				}
+						interpolants[ j ].evaluate( clipTime );
+						propertyMixers[ j ].accumulateAdditive( weight );
 
-			} else {
+					}
 
-				for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
+					break;
 
-					interpolants[ j ].evaluate( clipTime );
-					propertyMixers[ j ].accumulate( accuIndex, weight );
+				case OverrideBlendMode:
+				default:
 
-				}
+					for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
+
+						interpolants[ j ].evaluate( clipTime );
+						propertyMixers[ j ].accumulate( accuIndex, weight );
+
+					}
 
 			}
 

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

@@ -1,5 +1,6 @@
 import { AnimationClip } from './AnimationClip';
 import { AnimationAction } from './AnimationAction';
+import { AnimationBlendMode } from '../constants';
 import { EventDispatcher } from './../core/EventDispatcher';
 import { Object3D } from '../core/Object3D';
 import { AnimationObjectGroup } from './AnimationObjectGroup';
@@ -11,7 +12,7 @@ export class AnimationMixer extends EventDispatcher {
 	time: number;
 	timeScale: number;
 
-	clipAction( clip: AnimationClip, root?: Object3D | AnimationObjectGroup, isAdditive?: boolean ): AnimationAction;
+	clipAction( clip: AnimationClip, root?: Object3D | AnimationObjectGroup, blendMode?: AnimationBlendMode ): AnimationAction;
 	existingAction( clip: AnimationClip, root?: Object3D | AnimationObjectGroup ): AnimationAction | null;
 	stopAllAction(): AnimationMixer;
 	update( deltaTime: number ): AnimationMixer;

+ 4 - 3
src/animation/AnimationMixer.js

@@ -4,6 +4,7 @@ import { LinearInterpolant } from '../math/interpolants/LinearInterpolant.js';
 import { PropertyBinding } from './PropertyBinding.js';
 import { PropertyMixer } from './PropertyMixer.js';
 import { AnimationClip } from './AnimationClip.js';
+import { OverrideBlendMode } from '../constants.js';
 
 /**
  *
@@ -516,7 +517,7 @@ AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototy
 	// return an action for a clip optionally using a custom root target
 	// object (this method allocates a lot of dynamic memory in case a
 	// previously unknown clip/root combination is specified)
-	clipAction: function ( clip, optionalRoot, isAdditive = false ) {
+	clipAction: function ( clip, optionalRoot, blendMode = OverrideBlendMode ) {
 
 		var root = optionalRoot || this._root,
 			rootUuid = root.uuid,
@@ -534,7 +535,7 @@ AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototy
 			var existingAction =
 					actionsForClip.actionByRoot[ rootUuid ];
 
-			if ( existingAction !== undefined && existingAction.isAdditive === isAdditive ) {
+			if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
 
 				return existingAction;
 
@@ -554,7 +555,7 @@ AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototy
 		if ( clipObject === null ) return null;
 
 		// allocate all resources required to run it
-		var newAction = new AnimationAction( this, clipObject, optionalRoot, isAdditive );
+		var newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
 
 		this._bindAction( newAction, prototypeAction );
 

+ 5 - 0
src/constants.d.ts

@@ -303,6 +303,11 @@ export const ZeroCurvatureEnding: InterpolationEndingModes;
 export const ZeroSlopeEnding: InterpolationEndingModes;
 export const WrapAroundEnding: InterpolationEndingModes;
 
+// Animation blending modes
+export enum AnimationBlendMode { }
+export const OverrideBlendMode: AnimationBlendMode;
+export const AdditiveBlendMode: AnimationBlendMode;
+
 // Triangle Draw modes
 export enum TrianglesDrawModes {}
 export const TrianglesDrawMode: TrianglesDrawModes;

+ 2 - 0
src/constants.js

@@ -152,6 +152,8 @@ export var InterpolateSmooth = 2302;
 export var ZeroCurvatureEnding = 2400;
 export var ZeroSlopeEnding = 2401;
 export var WrapAroundEnding = 2402;
+export var OverrideBlendMode = 2500;
+export var AdditiveBlendMode = 2501;
 export var TrianglesDrawMode = 0;
 export var TriangleStripDrawMode = 1;
 export var TriangleFanDrawMode = 2;