Find target object for animation clip loaded via GLB/GLTF file

Hello,

I’m loading a gltf file using the GLTFLoader. The loaded file contains my array of animation but I can’t find any information about the target object that animation was originally assigned to.

Loading the gltf in babylon or modelviewer works and I can switch between the animation clips and it animates the correct objects so it looks like there is a way to resolve those connections.

Would appreciate any help!

The animation isn’t necessarily assigned to a single object – it could animate many objects, and you don’t need to manually resolve them to play the animation. See the webgl / animation / keyframes demo for an example of this.

If you do need to identify the objects affected, that’s part of the name of each keyframe track. The example below would target the object with the name ‘LeftArm’. The first part could also be a UUID.

for (const track of clip.tracks) {
  console.log(track.name); // Example: 'LeftArm.rotation'
}
1 Like

Yes but what if multiple objects share the same name? For example in case of multiple characters sharing one rig but should be assigned different animations.
In my case the name is the name and not the UUID unfortunately

THREE.GLTFLoader makes names unique within each model for this reason. When loading multiple glTF models into the same scene you could have name collisions though.

THREE.AnimationMixer finds objects underneath whatever root object you give it. So for multiple characters whose armatures have the same bone names, you could use a separate mixer for each character — each with a different root object — and that’d be fine.

1 Like

Thanks for your reply. It helped solve the problem (or find a better solution to it)

1 Like

Hello, I currently have this issue where a node is being renamed although it should actually be unique as far as I know.

Consider the following scene. “MyUniqueObject” is actually unique on export and I dont understand why it is being renamed on load. Maybe you can help me figure out what I’m missing?

image

myScene.glb (237.2 KB)

the hierarchy I’m exporting looks like this:
image

If I move “MyUniqueObject” out one level it is not being renamed BUT then the “Bla” object’s index inside MyUniqueObject increase by one.
image

GLTFLoader doesn’t guarantee it won’t rename unique objects – sometimes there could be a nested hierarchy of things (e.g. “Node > Mesh > Primitive”) in the file each having the same name, which are then collapsed into a single Mesh during the loading process, and the names are assigned before they’re collapsed.

1 Like