Attaching GLTF/GLB animations-only files to GLTF/GLB 3D models

Hi, everybody:

Working with assets in GLTF/GLB format, is it possible to have a file with the 3D model on the one hand, and a file with only the animations (without any geometry in it) on the other.

Both Maya and Blender exporters allow exporting GLTF/GLB animation-only files.

The case is, when importing both files (file 1: model / file 2: animations) in the same BJS scene, although we observe from Inspector the AnimationGroups are all correctly loaded in the hierarchy, and even the channels shown the correct node names, playing the scene no produce any animation. If we export all under a unique file, all works fine with BJS.

Is our approach wrong with the concept of separated Animations from Meshes, and that fail to animate only the expected from the GLTF/GLB standard?

Thanks for your time.

If you clone the animationGroup you can retarget it to animate your model instead of the placeholder nodes. Like below is how I retargeted a flying animation for example. :slight_smile:

// After loading asset containers
const rootNode = modelEntries.rootNodes[0];
const fly = animationEntries.animationGroups[0].clone("fly", (oldTarget) =>
    rootNode.getChildren((child) => child.name === oldTarget.name, false)[0]
, true);
fly.play(true);
2 Likes

Thanks for the answer, @Blake:

I’ve just arrived to a similar implementation, but instead of cloning the Animation Group, I update (retarget) the targets of all its channels (aka Targeted Animations):

/*
  result: comes from ImportMeshAsync of the only-animation file (that despite its name also import animations)
 _targetMesh: target mesh (obviously) we're attaching the animation to
*/
for (var j = 0; j < result.animationGroups[i].targetedAnimations.length; j++) {
  result.animationGroups[i].targetedAnimations[j].target = _targetMesh.getChildren()[0];
}

This way I don’t need to dispose the old animation as an extra task, but of course maybe the AnimationsGroup.clone.is more optimized in its code.

1 Like

Great idea, I like that way better too. :slight_smile: I modified it to find the target by name like above and it’s working for my skeletal animations too. :beers:

1 Like