I am trying to have primary animations where a character is driving or sit idle and her head can turn to the side when needed. (triggered at specific moments)
This is my attempt to make it work:
The GLB and head turning animation should be set up fine, since I tested in sandbox and it plays correctly.
But I can’t get her head to turn the same way as the additive animations in this example playground from the documentation:
Here are also some questions I have about the example:
where does that long number: 0.3333 … come from?
sadPoseAnim.start(true, 1, 0.03333333507180214 * 60, 0.03333333507180214 * 60);
I also don’t fully understand why when one of the main animations like “run” is on and the “sad pose” is at max, only the head, neck and a little bit of the torso is affected. Why aren’t the legs and arms affected? As far as I can see when I opened up the xbot.glb in Blender there are keyframes on all the bones, so it doesn’t make sense to me why the leg and arm movement is not affected by the additive animation. Or is it because there is very little rotation on them in the “sad” pose so it is not noticeable?
@vx9, I spent a it of time debugging your scene. I can see that the code is working correctly. I validated that your additive animations are correctly changing weight as you change your slider, so the code seems to all be working. That lead me to looking at your rig. I am not a regular Blender user (I am guessing that you are using blender) but I found some things that I need clarification on. For example, you are driving the character’s head by a constraint to a bone named “lookAt” which is a child of the “spine” bone. The “spine.006” bone appears to be what the head mesh is skinned to, and is following the position of the “lookAt” bone. Since I only have the glTF to go from, I can’t see any constraints you put into the file, but is this assumption correct?
Since I am seeing rotational data on the “spine.006” bone, I am assuming that the rotational data is getting baked out to the bone. However, I am also seeing some strange behavior when bringing your car gltf into the sandbox. When I change the animation clip currently playing to another clip, I often see the playhead at the bottom of the page stop, even though the animation is still playing.
I am wondering if you can use your workflow to create a simpler example with only three bones. Set it up like you originally did and save out a base animation and one to add on top. I am having a hard time deciphering what may be happening based on the complexity of this rig.
@sebavan, I don’t see a reason that the additive animation would not work, unless there is some data in the gltf that we don’t expect. The file validates when looking at it in the inspector and I can confirm the additive flag is set and weights are set correctly, but it appears that the add it not happening.
@vx9, thank you for the simplified asset, this was much easier to debug. There are two basic changes I made to your PG to get this working which you can see on the updated playground. The first is that I changed the method of tagging an animation group as additive from the AnimationGroup.makeAnimationAdditive method to the simpler accessor AnimationGroup.isAdditive = true. Setting this accessor to true will set all targeted animations within the group to targetedAnimation.isAddive = true automatically. This did make the animations add correctly, but that opened up the second fix for the asset.
Since both the idle animation and the turn head animation had sampled keys from the Blender export, there is data for all keyable channels that become eligible for adding. To describe this in the most simple terms, each bone in both of your animation groups have their scale set to (1.0, 1.0, 1.0). Since the animations were sampled for each frame, they all have a key on every frame setting the scale to (1.0, 1.0, 1.0). This means when you add the turn head animation group to your idle animation group, the scale for every bone will be (2.0, 2.0, 2.0). The same applies for every parameter - position, rotation, and scale - for any animations clips that are added.
This means that what you need do to is to delete any keys that should not add to the motion. To do this, delete any curve data on any bone in the turn head animation and only key the parameters that need to change on only the needed bones. In this case, I deleted all data from everything other than the head bone and on the head bone, I deleted translation and scale data.
When you export, you need to not sample your animations, which is what is baking keys to every frame. You do this by unchecking Always Sample Animations under the Animation group of the export parameters for glTF.
I will continue looking into AnimationGroup.makeAnimationAdditive to see if there is something that is particular to Blender exports that we need to account for as the meshes from the docs samples did not come from Blender. This should hopefully unblock you, but please feel free to ping with more questions if you have them.