Skip to content

Commit d83342d

Browse files
committed
add webgpu_animation_retargeting
1 parent 0bf5f09 commit d83342d

File tree

7 files changed

+25574
-33
lines changed

7 files changed

+25574
-33
lines changed

examples/files.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@
301301
"webgl_performance"
302302
],
303303
"webgpu (wip)": [
304+
"webgpu_animation_retargeting",
304305
"webgpu_backdrop",
305306
"webgpu_backdrop_area",
306307
"webgpu_backdrop_water",

examples/jsm/utils/SkeletonUtils.js

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function retarget( target, source, options = {} ) {
1515
const pos = new Vector3(),
1616
quat = new Quaternion(),
1717
scale = new Vector3(),
18-
bindBoneMatrix = new Matrix4(),
1918
relativeMatrix = new Matrix4(),
2019
globalMatrix = new Matrix4();
2120

@@ -29,8 +28,7 @@ function retarget( target, source, options = {} ) {
2928
const sourceBones = source.isObject3D ? source.skeleton.bones : getBones( source ),
3029
bones = target.isObject3D ? target.skeleton.bones : getBones( target );
3130

32-
let bindBones,
33-
bone, name, boneTo,
31+
let bone, name, boneTo,
3432
bonesPosition;
3533

3634
// reset bones
@@ -76,35 +74,10 @@ function retarget( target, source, options = {} ) {
7674

7775
}
7876

79-
if ( options.offsets ) {
80-
81-
bindBones = [];
82-
83-
for ( let i = 0; i < bones.length; ++ i ) {
84-
85-
bone = bones[ i ];
86-
name = options.names[ bone.name ] || bone.name;
87-
88-
if ( options.offsets[ name ] ) {
89-
90-
bone.matrix.multiply( options.offsets[ name ] );
91-
92-
bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
93-
94-
bone.updateMatrixWorld();
95-
96-
}
97-
98-
bindBones.push( bone.matrixWorld.clone() );
99-
100-
}
101-
102-
}
103-
10477
for ( let i = 0; i < bones.length; ++ i ) {
10578

10679
bone = bones[ i ];
107-
name = options.names[ bone.name ] || bone.name;
80+
name = options.names[ bone.name ];
10881

10982
boneTo = getBoneByName( name, sourceBones );
11083

@@ -136,18 +109,23 @@ function retarget( target, source, options = {} ) {
136109

137110
if ( target.isObject3D ) {
138111

139-
const boneIndex = bones.indexOf( bone ),
140-
wBindMatrix = bindBones ? bindBones[ boneIndex ] : bindBoneMatrix.copy( target.skeleton.boneInverses[ boneIndex ] ).invert();
112+
if ( options.offsets && boneTo ) {
141113

142-
globalMatrix.multiply( wBindMatrix );
114+
if ( options.offsets[ bone.name ] ) {
115+
116+
globalMatrix.multiply( options.offsets[ bone.name ] );
117+
118+
}
119+
120+
}
143121

144122
}
145123

146124
globalMatrix.copyPosition( relativeMatrix );
147125

148126
}
149127

150-
if ( bone.parent && bone.parent.isBone ) {
128+
if ( bone.parent ) {
151129

152130
bone.matrix.copy( bone.parent.matrixWorld ).invert();
153131
bone.matrix.multiply( globalMatrix );
@@ -200,6 +178,7 @@ function retarget( target, source, options = {} ) {
200178
function retargetClip( target, source, clip, options = {} ) {
201179

202180
options.useFirstFramePosition = options.useFirstFramePosition !== undefined ? options.useFirstFramePosition : false;
181+
203182
// Calculate the fps from the source clip based on the track with the most frames, unless fps is already provided.
204183
options.fps = options.fps !== undefined ? options.fps : ( Math.max( ...clip.tracks.map( track => track.times.length ) ) / clip.duration );
205184
options.names = options.names || [];

examples/models/gltf/Pete/pete.bin

549 KB
Binary file not shown.

0 commit comments

Comments
 (0)