Bone rotation with animation

Hello again, I am trying to apply rotation to a bone channel already animated with channel.rotation_euler, but the rotation that I apply does not appear, only the animation, but when I disable the animation, it appears, but not as I wanted. Is there any way to merge the animation with custom rotation channel.rotation_euler?

animation layer blending is what you want.

layer 0 will have the main anim
layer 1 will animate select bones set to add, and use blend ratio as a factor of mix.

animations have the final say when setting position.

you could also move the bone channels to a different animation, and run that animation with the selected bones to override your manual eulers

1 Like

I haven’t tested it, but something like this might output the correct rotation.

from math import radians
from mathutils import Euler

newrot = Euler(channel.rotation_euler).rotate( Euler([radians(90),0,0]) )
channel.rotation_euler = newrot

If you want to drive the animation entirely through python, likely you want to write keyframes to json and pick those values up ingame to get an animation dict. Interpolate between keyframes to get the initial value for the current frame, then rotate that. It’s probably quicker to use quaternions and just multiply the initial value by the secondary rotation.

Also, I wouldn’t do it in pure python unless it’s just a bare handful of bones per frame.

1 Like

u can tell me how to make this? :expressionless:

I already did.

  1. write keyframes to a nested dict and dump it to json; d[bone][action][frame]
  2. ingame, load the json file as a dictionary
  3. use this dictionary to get your initial rotation
  4. interpolate between keyframes
  5. apply your manual rotation

If you’re stuck at one step/don’t know how to go about it ask about that specifically – this is a moderately complex system and I don’t know the inner workings of your project, so I can’t just code out a quick script to solve the problem.

1 Like