Ver Fonte

SkeletonUtils: added `getBoneName()` (#29416)

* SkeletonUtils: added `getBoneName()`

* Update SkeletonUtils.js
sunag há 1 ano atrás
pai
commit
dcb30fd112
1 ficheiros alterados com 16 adições e 5 exclusões
  1. 16 5
      examples/jsm/utils/SkeletonUtils.js

+ 16 - 5
examples/jsm/utils/SkeletonUtils.js

@@ -9,6 +9,17 @@ import {
 	VectorKeyframeTrack
 } from 'three';
 
+function getBoneName( bone, options ) {
+
+	if ( options.getBoneName !== undefined ) {
+
+		return options.getBoneName( bone );
+
+	}
+
+	return options.names[ bone.name ];
+
+}
 
 function retarget( target, source, options = {} ) {
 
@@ -77,7 +88,7 @@ function retarget( target, source, options = {} ) {
 	for ( let i = 0; i < bones.length; ++ i ) {
 
 		bone = bones[ i ];
-		name = options.names[ bone.name ];
+		name = getBoneName( bone, options );
 
 		boneTo = getBoneByName( name, sourceBones );
 
@@ -161,7 +172,7 @@ function retarget( target, source, options = {} ) {
 		for ( let i = 0; i < bones.length; ++ i ) {
 
 			bone = bones[ i ];
-			name = options.names[ bone.name ] || bone.name;
+			name = getBoneName( bone, options ) || bone.name;
 
 			if ( name !== options.hip ) {
 
@@ -203,6 +214,7 @@ function retargetClip( target, source, clip, options = {} ) {
 		mixer = new AnimationMixer( source ),
 		bones = getBones( target.skeleton ),
 		boneDatas = [];
+
 	let positionOffset,
 		bone, boneTo, boneData,
 		name;
@@ -220,13 +232,12 @@ function retargetClip( target, source, clip, options = {} ) {
 
 		for ( let j = 0; j < bones.length; ++ j ) {
 
-			name = options.names[ bones[ j ].name ] || bones[ j ].name;
-
+			bone = bones[ j ];
+			name = getBoneName( bone, options ) || bone.name;
 			boneTo = getBoneByName( name, source.skeleton );
 
 			if ( boneTo ) {
 
-				bone = bones[ j ];
 				boneData = boneDatas[ j ] = boneDatas[ j ] || { bone: bone };
 
 				if ( options.hip === name ) {

粤ICP备19079148号