From dcb30fd11276a14255155f3cb6eb3345622c9aef Mon Sep 17 00:00:00 2001 From: sunag Date: Sun, 15 Sep 2024 22:59:50 -0300 Subject: [PATCH] SkeletonUtils: added `getBoneName()` (#29416) * SkeletonUtils: added `getBoneName()` * Update SkeletonUtils.js --- examples/jsm/utils/SkeletonUtils.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/jsm/utils/SkeletonUtils.js b/examples/jsm/utils/SkeletonUtils.js index 3c86b064d05143..e959b73953793a 100644 --- a/examples/jsm/utils/SkeletonUtils.js +++ b/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 ) {