Animating a GLB file using the animation from a separate GLB file

My application has some animated GLTF body models and I have been asked to see if it’s possible to update the animation by loading a secondary GLTF file that only contains an animation and apply that to the body models. I came up with this pattern:

gltfLoader.load('body.glb', function (body_gltf) {
        let body_model = SkeletonUtils.clone(body_gltf.scene);
        scene.add(body_model);

        gltfLoader.load('animation.glb', function (animation_gltf) {
            let animation_model = SkeletonUtils.clone(animation_gltf.scene);

            let animation_object_group = new THREE.AnimationObjectGroup(animation_model);
            animationMixer = new THREE.AnimationMixer(animation_object_group);
            animationMixer.clipAction(animation_gltf.animations[0]).play();
            animation_object_group.add(body_model);
        });
    });

I.E. add the animation GLTF and body GLTF to an animation group and play both using the animation from the animation GLTF clip. My test appears to work as expected but before I declare victory and ask the content folk to make some real animations, can anyone confirm that this is correct approach? I’ve been bitten in the past where a test works but then fails when real-world content is introduced.

Hello Callum
Your method is indeed what I am interested in myself (nicely procedural). When trying to implement your pattern the browser console returns an error:

Uncaught (in promise) ReferenceError: SkeletonUtils is not defined
script.js:61
load GLTFLoader.js:226
parse GLTFLoader.js:2550

Might I be missing something?
Cheers
Michiel

import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';

https://threejs.org/examples/?q=multip#webgl_animation_multiple

That looks legit to me. The main pain point in having external animations is getting them to export without including a copy of the whole animated character for each set, but you seem to have that handled.

Thanks! Indeed makes sense

Hi Callum, i guess I have got your pattern working myself. I am very new at this, how would you add a second animation-file (or third/…) in this setup?