Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkeletonUtils: Fix retargetClip() final keyframe #25589

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions examples/jsm/utils/SkeletonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ function retargetClip( target, source, clip, options = {} ) {
if ( ! boneData.pos ) {

boneData.pos = {
times: new Float32Array( numFrames ),
values: new Float32Array( numFrames * 3 )
times: new Float32Array( numFrames + 1 ),
values: new Float32Array( ( numFrames + 1 ) * 3 )
};

}
Expand All @@ -274,9 +274,10 @@ function retargetClip( target, source, clip, options = {} ) {

if ( ! boneData.quat ) {

// `numFrames + 1` accomodate final keyframe
boneData.quat = {
times: new Float32Array( numFrames ),
values: new Float32Array( numFrames * 4 )
times: new Float32Array( numFrames + 1 ),
values: new Float32Array( ( numFrames + 1 ) * 4 )
};

}
Expand All @@ -289,12 +290,51 @@ function retargetClip( target, source, clip, options = {} ) {

}

mixer.update( delta );
// check for final keyframe
if ( i === numFrames - 1 ) {

mixer.update( Math.max( clip.duration - mixer.time, 0 ) );

} else {

mixer.update( delta );

}

source.updateMatrixWorld();

}

retarget( target, source, options );

// add boneData at final keyframe
for ( let j = 0; j < boneDatas.length; ++ j ) {

boneData = boneDatas[ j ];

if ( boneData ) {

if ( boneData.pos ) {

boneData.pos.times[ numFrames ] = clip.duration;

bone.position.toArray( boneData.pos.values, numFrames * 3 );

}

if ( boneData.quat ) {

boneData.quat.times[ numFrames ] = clip.duration;

bone.position.toArray( boneData.quat.values, numFrames * 4 );

}

}

}


for ( let i = 0; i < boneDatas.length; ++ i ) {

boneData = boneDatas[ i ];
Expand Down