three.js r116.1, GLTFLoader, AnimationMixer
After loading a GLTF-Scene I want to set actions for different AnimationClips.
Accessing them through their corresponding
gltf.animations index value works, e.g:
let mixer = new AnimationMixer( gltf.scene );
let action = mixer.clipAction( gltf.animations[ 0 ] );
According to AnimationMixer.clipAction documentation they should also be accessible by passing an action name, I guess like this:
let action = mixer.clipAction( 'my_action' );
but this doesn’t work, I get following Error:
Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
at Function.findByName (AnimationClip.js:211)
at AnimationMixer.clipAction (AnimationMixer.js:526)
Thanks & Cheers!
Ah, that should probably be changed in the documentation. It’s only going to work if the animations are attached to specific objects in the scene, and animations coming from GLTFLoader are not. You’ll need to do something like:
const clip = gltf.animations.find((clip) => clip.name === 'my_action');
const action = mixer.clipAction(clip);
ok cool, that did the trick, thanks!
The information concerning GLTFLoader is also interesting
I stumbled over an issue as I tried to duplicate a rigged and animated (Actions) mesh in Blender and export it to GTLF2.0. Blender does duplicate the Actions and Bones (incl. hierarchy), but doesn’t alter their names to e.g.
.XXX as usual with duplicated objects. So inside exported glTF-File all Actions and Bones names are doubled with no hierarchy, all references are tied to names, means if you try to play any of the available Actions (also the doubled ones), they will all animate the one same (I guess the first found) Armature / Bones / Mesh.
My current workaround for this would be renaming all Actions & Bones inside Blender manually, so the names don’t interfere + reassigning referenced Bones inside Actions. My current scene / meshes / armatures are not that complex, so this wouldn’t be a very tedious task, but it would get worse with more duplicates.
I’m still thinking / searching for other solutions…
https://github.com/mrdoob/three.js/pull/16639 would fix the references to bones. Otherwise, yeah, I think it’s necessary to make sure things have unique names. I’m surprised Blender didn’t export the
.XXX suffixes, do you know if that’s coming from Blender itself or the glTF Addon? E.g. do you see unique names in the Blender scene hierarchy?
No, for Actions and Bones I don’t see unique names in the Blender scene hierarchy, they keep names in the duplicated Collection. Duplicated Collections themselves, as well as Objects, Armatures etc. do get the suffix (when duplicating a collection) and also get exported correctly named. Hm… All of my Animations (Actions inside NLATracks) are attached to Armatures, the animated mesh is parented to the Armature… I really don’t have a clue what’s wrong, if at all, at the moment.
I see that NLATracks get duplicated: are not suffixed, but I can uniquely rename them.
Actions don’t get duplicated just inserted into the duplicated NLATracks, I can’t uniquely rename them.
I see that Bones get duplicated: are not suffixed, but I can uniquely rename them.
This is somehow related to Bones not being suffixed “issue”: ⚓ T61484 shift-D to duplicate armature does only shallow copy
Inspecting Outliner shows that a new armature was created, but no new bones.
Same as above. These are just named the same (which is allowed)