فهرست منبع

SkeletonUtils: added `trim` (#29424)

sunag 1 سال پیش
والد
کامیت
3415f33763
2فایلهای تغییر یافته به همراه34 افزوده شده و 13 حذف شده
  1. 31 13
      examples/jsm/utils/SkeletonUtils.js
  2. 3 0
      examples/webgpu_animation_retargeting.html

+ 31 - 13
examples/jsm/utils/SkeletonUtils.js

@@ -222,13 +222,31 @@ function retargetClip( target, source, clip, options = {} ) {
 		name;
 		name;
 
 
 	mixer.clipAction( clip ).play();
 	mixer.clipAction( clip ).play();
-	mixer.update( 0 );
+
+	// trim
+
+	let start = 0, end = numFrames;
+
+	if ( options.trim !== undefined ) {
+
+		start = Math.round( options.trim[ 0 ] * options.fps );
+		end = Math.min( Math.round( options.trim[ 1 ] * options.fps ), numFrames ) - start;
+
+		mixer.update( options.trim[ 0 ] );
+
+	} else {
+
+		mixer.update( 0 );
+
+	}
 
 
 	source.updateMatrixWorld();
 	source.updateMatrixWorld();
 
 
-	for ( let i = 0; i < numFrames; ++ i ) {
+	//
+
+	for ( let frame = 0; frame < end; ++ frame ) {
 
 
-		const time = i * delta;
+		const time = frame * delta;
 
 
 		retarget( target, source, options );
 		retarget( target, source, options );
 
 
@@ -247,15 +265,15 @@ function retargetClip( target, source, clip, options = {} ) {
 					if ( ! boneData.pos ) {
 					if ( ! boneData.pos ) {
 
 
 						boneData.pos = {
 						boneData.pos = {
-							times: new Float32Array( numFrames ),
-							values: new Float32Array( numFrames * 3 )
+							times: new Float32Array( end ),
+							values: new Float32Array( end * 3 )
 						};
 						};
 
 
 					}
 					}
 
 
 					if ( options.useFirstFramePosition ) {
 					if ( options.useFirstFramePosition ) {
 
 
-						if ( i === 0 ) {
+						if ( frame === 0 ) {
 
 
 							positionOffset = bone.position.clone();
 							positionOffset = bone.position.clone();
 
 
@@ -265,30 +283,30 @@ function retargetClip( target, source, clip, options = {} ) {
 
 
 					}
 					}
 
 
-					boneData.pos.times[ i ] = time;
+					boneData.pos.times[ frame ] = time;
 
 
-					bone.position.toArray( boneData.pos.values, i * 3 );
+					bone.position.toArray( boneData.pos.values, frame * 3 );
 
 
 				}
 				}
 
 
 				if ( ! boneData.quat ) {
 				if ( ! boneData.quat ) {
 
 
 					boneData.quat = {
 					boneData.quat = {
-						times: new Float32Array( numFrames ),
-						values: new Float32Array( numFrames * 4 )
+						times: new Float32Array( end ),
+						values: new Float32Array( end * 4 )
 					};
 					};
 
 
 				}
 				}
 
 
-				boneData.quat.times[ i ] = time;
+				boneData.quat.times[ frame ] = time;
 
 
-				bone.quaternion.toArray( boneData.quat.values, i * 4 );
+				bone.quaternion.toArray( boneData.quat.values, frame * 4 );
 
 
 			}
 			}
 
 
 		}
 		}
 
 
-		if ( i === numFrames - 2 ) {
+		if ( frame === end - 2 ) {
 
 
 			// last mixer update before final loop iteration
 			// last mixer update before final loop iteration
 			// make sure we do not go over or equal to clip duration
 			// make sure we do not go over or equal to clip duration

+ 3 - 0
examples/webgpu_animation_retargeting.html

@@ -199,6 +199,9 @@
 					// use ( 0, 1, 0 ) to ignore xz hip movement.
 					// use ( 0, 1, 0 ) to ignore xz hip movement.
 					//hipInfluence: new THREE.Vector3( 0, 1, 0 ),
 					//hipInfluence: new THREE.Vector3( 0, 1, 0 ),
 
 
+					// specify an animation range in seconds.
+					//trim: [ 3.0, 4.0 ],
+
 					// preserve the scale of the target model
 					// preserve the scale of the target model
 					scale: 1 / targetModel.scene.scale.y,
 					scale: 1 / targetModel.scene.scale.y,
 
 

粤ICP备19079148号