Bake Action inaccurate for Spline IK
Open, NormalPublic

Description

System Information
Windows 8.1 64 bit; EVGA GTX 970

Blender Version
Broken: (2.78c e92f235283)
Worked: Unknown

Short description of error

Hi Blender developer team,

I just wanted to report an issue I've discovered regarding baking actions on a rig that uses a Spline IK chain. Firstly, the rig is setup correctly: I have a Control Rig that uses 2 bones as Hooks to control a Bezier Curve; then I have a separate Deform Rig that contains the Spline IK chain which has the Bezier Curve set as its target. All other bones in the Deform Rig have copy transform constraints which point back to their duplicate bones in the Control Rig. This avoids cyclic dependency issues.

However, the deform rig is the one that needs to be exported with all the animation applied for use in another program. This requires baking each action into the deform rig, since the deform rig actually has no animation data of its own. So, for each action in the Control Rig, I would duplicate the Deform Rig, and name it Export Rig. I would then Bake the Action using the following settings:

After the bake, I began to notice a discrepancy in the bone positions of those which had been Spline IK bones. Interestingly, sometimes I could get it to work perfectly, usually by adding a visual keying LocRotScale keyframe first. But sometimes, that didn't work, and Blender had to be closed and re-opened. And sometimes THAT didn't work either, resulting in the final workaround which was manually adding a Visual LocRotScale keyframe for all bones in the Export Rig for EACH frame, and then baking the action (except with the "Overwrite" checkbox selected in the Bake Actions options). Essentially, that last step of baking was probably unneeded, but I did it as a quick way to remove all constraints. You can see the difference below, the selected (blue) rig is the baked one, and in the 2nd picture, you can see the baked and unbaked rigs line up perfectly:

Thanks so much for looking into this.

Sincerely,
Adam Janz

Details

Type
Bug

I can confirm there is still a very slight discrepancy (basically negligible) at times even when manually setting visual LocRotScale keyframes and then clearing all constraints manually using Ctrl Alt C. This is likely the nature of Blender not being able to truly pinpoint the position of bones affected by the Spline IK constraint after visually keying. However, there is no doubt something wrong with the way Bake Action does the visual keying on Spline IK affected bones, as 9/10 times there is a fairly large discrepancy.

-Adam

Here's a first guess at what may be happening (without having checked the file or the Bake Action operator):
It's likely that because the pose gets evaluated again for each bone (in order to compute what effect the visual keying should have), the results of the previous bone in the chain (that got keyed first) will end up influencing the results for latter bones, causing drift in the results. IIRC, there are similar problems with certain operations for the IK constraint.

Thanks Joshua and Brendon for your input. I did notice that manually setting visual LocRotScale keyframes and then hitting Bake Action produced much more accurate (but not perfect) results than just hitting Ctrl Alt C to clear the contraints. Maybe because the visual keying gets applied twice?

Joshua Leung (aligorith) triaged this task as Normal priority.Jul 17 2017, 5:11 PM

Indeed, I'd be very surprised if this was related to T51971.

I'm having the same problem when trying to export a complex rig to FBX. From what I can see, the problem could be related to the scaling of the bones. In other words, the scale of the parent bone affects the transforms of the child bone, thus, rotations end up looking totally sheared. I really don't know what kind of math could solve this, but it seems a pretty nasty issue if you are exporting things to a game engine.

So far, the only way I could manage to get an undistorted result, was to make all the bones children of the root bone, therefore making each bone independent from each other. Of course, this would not be what you wanted if you were planning on setting up an IK chain inside of the target Game Engine...

Hi Juan, you might be encountering this issue? If so, I posted a workaround; and there is also a solution inside UE4 if you are using that game engine. I hope this helps!

Hi Adam! Thanks for the link!

And yes, I found a similar solution, I also had a couple of bones moving like crazy in the export, so in my case I added some new parent bones that wouldn't scale along wit the rig, but would only copy rotation and location. From what I see, the main issue is with scaling.

You're welcome! Glad you got it working. :-)

Hi!

For those reading later:

I had a similar problem with baking spline IK and found a really easy fix that worked perfectly at least in my situation:

Take the armature to edit mode and remove the "inherit scale" checkbox from each bone. After this the baking works perfectly (bake action-->"visual keying", "clear constraints" and "replace action" checked.)

Thanks Andy for sharing that tip! :)

-Adam

If disabling Inherit Scale fixes this, it may be related to T54159. Basically, inherited non-uniform scale plus local rotation fundamentally creates shear, and it's impossible to avoid except by only using uniform scale, or not inheriting scale.

We should probably disable Inherit Scale by default for new bones? It doesn't really solve the bug, but might avoid the problem in most cases. I except that usually you don't even want to inherit scale from parent bones anyway.

We should probably disable Inherit Scale by default for new bones? It doesn't really solve the bug, but might avoid the problem in most cases. I except that usually you don't even want to inherit scale from parent bones anyway.

Reasons not to do it:

  • Inheriting uniform scale is perfectly fine.
  • Usually you'd expect resizing your character root bone to work.
  • When not all checkboxes are enabled the code uses more advanced math to do it, instead of just simply multiplying matrices.
  • I wonder if export file formats for bone animations actually support these checkboxes - if they only can support full parenting, this would be pointless.

The real cause of user confusion in this case is that constraints, by working directly on matrices, can produce transformations that cannot be replicated using LocRotScale channels. I.e. inheriting scale induces shear into the local coordinate space, but constraints like Stretch To remove it from the world matrix, and this ends up impossible to bake.

I agree with Alexander, the inherit scale option shouldn't be turned off by default. You want it to be on in 99% of the cases.

Unfortunately, I just tested this and though baking within Blender is in fact fixed by turning off the inherit scale option, FBX export seems to ignore this option and bones get exported with shearing nevertheless.

The only way to avoid shearing is to actually unparent all bones, but though that would export things correctly, visually speaking, you lose hierarchies, and that results in an armature that can't get used in the game engine to add an IK constraints and stuff.