Take use_inherit_scale and use_inherit_rotation into account
QbieShay opened this issue · 8 comments
Is your feature request related to a problem? Please describe.
I have a character that's animated with some stretch and squash. In order to do so, we used the property use_inherit_scale and use_inherit_rotation. For example, for the idle animation, the character breathes and the torso is scaled on the y and x axis. When exporting to gltf, the entire subtree of bones after this bone scales as well, even if the child bone of the torso bone has a inherit scale disabled.
Describe the solution you'd like
I'd appreciate if the exporter took into account these properties and reversed location/rotation upon exporting
Describe alternatives you've considered
We have tried to implement the fix but it goes beyond our abilities. Another alternative would be to redo parts of the animations, but that's a long work.
Additional context
We tried a fix and we figured out that the place to look at is in exp/gltf2_blender_gather_animation_samplers.py. When a keyframe is calculated, it should be checked for inherit location/rotation and the keyframe shall be saved accordingly.
I attach here a blend file as a sample reproduction case for this issue:
I ran into this issue as well and I found that if you have a bone with a Child Of constraint down the chain, it's transform gets baked correctly in the export. Then I thought I could use the constraint as a work around, but it seems that when you disable rotation/scale in the constraint it will stop adjusting to the parent's tail, only head, so it doesn't work.
Ran into this as well. It's absurd this isn't implemented already as it's commonly used and pretty much crucial for a lot of animations. In fact I would consider this issue a bug. Not an enhancement.
I'll defer to other maintainers, but I'm going to guess this is extremely difficult to implement. While disabling inherited tranforms may be a common feature in Blender, runtimes (and runtime formats like glTF) have no such feature. Which means that animation on a parent node would need to be baked — by the exporter — into inverted animations on every child, and viewers will do extra animation work accordingly.
Suggestions or PRs welcome, of course. If Blender's FBX exporter handles this correctly, I'd be curious to know how.
I looked at how the Godot Engine's .escn exporter handles this and it seems this is the correct formula:
(pbone = pose bone)
` rest_mat = (pbone.parent.bone.matrix_local.inverted_safe() @ pbone.bone.matrix_local)
matrix = (rest_mat.inverted_safe() @ pbone.parent.matrix.inverted_safe() @ pbone.matrix)
I added it to blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py/get_bone_matrix
and from initial testing it seems to work. Should also handle inherit_scaling.
Not sure if I should make a pull request though. Am not a good coder (and have even worse math skills) and don't know the in-and-outs of the exporter very well. I am pretty sure my implementation is kinda hacky and ugly.
Made a fork though so people willing to check it out can go right ahead.
Don't hesitate to create a PR, so people can see / test / complete what you already did
Can this be merged, this is really important it gets merged (for me personally and for godot), right now the default path from blender to godot is blocked by this not being in the stable release of blender. #880
By default path I mean, without having to apply fixes to the asset in blender to workaround this, it should not be required for a good export, if you think about it people lose track of changing these setting over time and we should support the defaults set by blender for bones / armatures. (invalid comment as this is not the defaults I checked in a new file)
We are using GLTF2 specifically, we're in the process of rewriting FBX too.
Is there any way of fast tracking this change to blender in a hotfix release?
Blender 2.83 will be release next week, and we can't merge into this particular version one week before the release. Only crutial bugfixes are allowed.
I planned to test heavily and merge for 2.90 (release planned in august).
and we should support the defaults set by blender for bones / armatures.
Changing inherit rotation and inherit scale values is not the default values for rigging in blender
Ah thanks for the clarification, okay, I can just write a patch to fix the meshes on our FBX importer in the meantime then, this should get that files which use this working.