Skip to content

Commit

Permalink
SkeletonUtils: added getBoneName() (mrdoob#29416)
Browse files Browse the repository at this point in the history
* SkeletonUtils: added `getBoneName()`

* Update SkeletonUtils.js
  • Loading branch information
sunag authored Sep 16, 2024
1 parent 9b76dc8 commit dcb30fd
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions examples/jsm/utils/SkeletonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {} ) {

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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;
Expand All @@ -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 ) {
Expand Down

0 comments on commit dcb30fd

Please sign in to comment.