Animate multiple Ready Player Me avatars in the same scene

You also have a problem with the animation structure.

In animations.glb you have 3 targeted animations (the last 3) which target a root node named “BreathingIdle”, “Running” and “Walking” for the 3 animations “BreathingIdle”, “Running” and “Walking”, respectively. But the avatar meshes have a “Armature” root node instead, leading to target === null in these cases.

So, you should retarget those 3 targeted animations to the right node instead:

const avatar1 = importedRPM.meshes[0];
const avatar1Armature = avatar1.getChildren((node) => node.name === "Armature", false)[0];

for (const ag of scene.animationGroups) {
    for (const ta of ag.targetedAnimations) {
        if (!ta.target) {
            ta.target = avatar1Armature;
        }
    }
}

This will retarget to the “Armature” node of the first avatar.

Then you should clone the animation groups and retarget them to the 2nd avatar, as @carolhmj said:

const ags = scene.animationGroups.slice(0);
for (const ag of ags) {
    ag.clone(ag.name + "2", (oldTarget) => {
        return avatar2.getChildren((node) => node.name === oldTarget.name, false)[0];
    }, true);
}                

Here’s the full PG:

4 Likes