Browse Source

useFirstFramePosition, best settings, rename offset to offsets

sunag 7 years ago
parent
commit
7ce8a196fb
2 changed files with 20 additions and 5 deletions
  1. 17 3
      examples/js/utils/SkeletonUtils.js
  2. 3 2
      examples/webgl_loader_sea3d_bvh.html

+ 17 - 3
examples/js/utils/SkeletonUtils.js

@@ -72,7 +72,7 @@ THREE.SkeletonUtils = {
 
 			}
 
-			if ( options.offset ) {
+			if ( options.offsets ) {
 
 				bindBones = [];
 
@@ -81,9 +81,9 @@ THREE.SkeletonUtils = {
 					bone = bones[ i ];
 					name = options.names[ bone.name ] || bone.name;
 
-					if ( options.offset[ name ] ) {
+					if ( options.offsets[ name ] ) {
 
-						bone.matrix.multiply( options.offset[ name ] );
+						bone.matrix.multiply( options.offsets[ name ] );
 
 						bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
 
@@ -192,6 +192,7 @@ THREE.SkeletonUtils = {
 	retargetClip: function ( target, source, clip, options ) {
 
 		options = options || {};
+		options.useFirstFramePosition = options.useFirstFramePosition !== undefined ? options.useFirstFramePosition : false;
 		options.fps = options.fps !== undefined ? options.fps : 30;
 		options.names = options.names || [];
 
@@ -210,6 +211,7 @@ THREE.SkeletonUtils = {
 			mixer = new THREE.AnimationMixer( source ),
 			bones = this.getBones( target.skeleton ),
 			boneDatas = [],
+			positionOffset,
 			bone, boneTo, boneData, i, j;
 
 		mixer.clipAction( clip ).play();
@@ -243,6 +245,18 @@ THREE.SkeletonUtils = {
 
 						}
 
+						if ( options.useFirstFramePosition ) {
+
+							if ( i === 0 ) {
+
+								positionOffset = bone.position.clone();
+
+							}
+
+							bone.position.sub( positionOffset );
+
+						}
+
 						boneData.pos.times[ i ] = time;
 
 						bone.position.toArray( boneData.pos.values, i * 3 );

+ 3 - 2
examples/webgl_loader_sea3d_bvh.html

@@ -115,7 +115,8 @@
 			function bvhToSEA3D( result ) {
 
 				var clip = THREE.SkeletonUtils.retargetClip( player, result.skeleton, result.clip, {
-					preservePosition: true,
+					preservePosition: false,
+					useFirstFramePosition: true,
 					hip: "Base HumanPelvis",
 					names: {
 						"Base HumanPelvis": "hip",
@@ -139,7 +140,7 @@
 						"Base HumanLCalf1": "lShin",
 						"Base HumanLFoot": "lFoot"
 					},
-					offset: {
+					offsets: {
 						"lShldr": new THREE.Matrix4().makeRotationFromEuler(
 							new THREE.Euler(
 								0,