How to animate mesh by skeleton coming from containers?

Hi all :wave:

I’ve written a preloading system that loads GLTF and GLB models using SceneLoader.LoadAssetContainerAsync.

For my player model I’m then instantiating it via:

const container = library.get('Wizard.gltf')!;
const entries = container.instantiateModelsToScene();
const mesh = entries.rootNodes[0] as WizardMesh;

In the above library is a map of all loaded containers, and WizardMesh is just a type extending Mesh with a few character-specific functions I plan on implementing.

I’m then fetching the skeleton (there were two when I logged everything, but they appeared to be the same) via the following code:

const {skeleton} = (mesh.getDescendants() as Mesh[]).find((c) => {
  if (c.skeleton && !Array.isArray(c.skeleton)) {
    return c.skeleton;
  }

  return undefined;
})!;

With these objects available (mesh, skeleton, and scene), I’ve tried animating the character via:

scene.beginWeightedAnimation(skeleton, 0, 34, 1, true);
scene.beginAnimation(skeleton, 0, 34, true);
skeleton?.beginAnimation('RunForwards', true);

All to no avail :face_with_diagonal_mouth:

My animation I’m trying to play is setup in Blender as follows (on the skeleton object):

If anyone has any hints or input I’d be very grateful! Thank you! :slight_smile:

Huzzah! Nvm I found a way to properly access the animations from:

const entries = container.instantiateModelsToScene();

// To access animation groups...
entries.animationGroups[0]; // Can lookup via name property

Running play(true) on the resulting AnimationGroup objects will loop the animation correctly :smiley:

Woohoo!

2 Likes