Assigning the same animation to different objects

animation

#1

Hello,
let’s say I have a GLTF scene with multiple objects including a dummy one. Every object is animated.

in my three.js environment I import this scene, but I also have some other meshes.

One of the meshes, a 3D pointer, can be controlled in real time by the mouse.
When it reaches the position of the imported dummy object, I’d like to start the animation stored in GLTF file and move the hand as the dummy object does, so basically I’d like to know if is it possible to assign and unassign animation clip / tracks from dummy object to new object


#2

Yes, that is possible. The rootObject of the animation mixer determines which object is affected by the animation.


#3

I have to dig a bit more into it.

Right now I imported a GLTF scene, and the rootObject of the mixer is a Scene.
I suppose that the reference between animation clips and meshes (children of the root scene) is in the mesh names, correct?

In that case, I could change that name in the animation clip / animation action to a new one, so that the animation will affect the new “named” mesh.


#4

No, it’s the name of the keyframe track. It’s kind of a selector relative to the root object. I suggest you read the documentation about the animation system and check out basic examples like the following:

https://threejs.org/examples/misc_animation_keys.html


#5

thanks @Mugen87,
yes, I intended the ‘name’ property of the tracks objects of animation clips, that have the same names as the Meshes
eg animationClip.tracks[x].name = ‘Cube.position’, affects the position of the Mesh named Cube
and this name should be a children of the mixer’s rootObject.

So I could add a new mesh to the mixer rootObject, then change the name of the clip track to the new mesh one.

I’ll dig more into it.


#6

^Yeah this sounds right.

Also a quick note for completeness that if your glTF file does not contain object names, animation will use UUIDs to target them instead (in which case reusing animation clips will be harder).


#7

thanks for the clarification @donmccurdy
Luckily exporting from blender, using either khronos group or kupoman exporters, assigns the right names to objects and animations.

The main difference at the moment (as you know, but I feel right to write for post clarity), is that kupoman’s supports multiple animation clips while khronos’ just one animation clip for the entire scene, so the workflow would be a bit different: on khronos’ is a iterative search in the tracks array of the one and only animation clip, while on kupoman generated gltf we’ll need to search by traversing all the different animation clips and respective tracks.
But being this a very specific task, the entire workflow will be tailored to the specific need.


#8

Support for multiple animation clips was merged to the Khronos exporter yesterday: https://github.com/KhronosGroup/glTF-Blender-Exporter/pull/166 :+1:


#9

ahah perfect, thanks