How to set bone transform from code

I am trying to create something like Anim Dynamics (in UE) or Wiggle Bone (in Blender), but I cannot manage to change the position of bone in runtime.
I tried:

sk = Actor.As<AnimatedModel>().SkinnedModel;
var b = skMesh.Bones[5];
b.LocalTransform.Orientation = Quaternion.Euler(20, 40, 60);
sk.Bones[5] = b;

But it doesn’t seem to take effect.
Btw, what’s the difference between SkeletonNode and SkeletonBone

Animation Graph is a place where all nodes/bones transformations should happen as it’s designed for high-performance (async) and data-logic separation. Here is an example of doing this:

If you want to edit skeleton pose from gameplay code you could link into AnimatedModel’s AnimationUpdated event and call GetCurrentPose to get current skeleton pose, modify it and the set via SetCurrentPose. - just be aware that editing pose within AnimationUpdated even might trigger it again as it updates the pose so add a safe variable to check for recursion.

1 Like

Thank you so much! I will have a try. So, editing the LocalTransform of a skeletonbone makes no sense.

By the way, how to calculate a bone’s orientation after adjusting the position of its adjacent bones? I thought it should be Quaternion.FromDirection(bone.Pos - childrenBone.Pos), but this doesn’t give the correct result :frowning:

Have you tried to duplicate Wiggle Bones with the physics system?
Gravity disabled Rigidbody, angular dampening, constrained D6 joint chain (no twist).

Sample:
Wiggle Bones FlaxForumDiscussion - YouTube

After if I wanted to apply to a SkinnedMesh, I’d probably just copy over transforms or something similar.
Although I can appreciate wanting to script this by hand.
Apologies for suggesting outside of a scripting discussion.

1 Like

Thanks for your solution, I’ll have a try.
But I wonder if it is efficient enough for large scale adoption (such as dress, which has 10 chains, each of 8 bones).

Ah…Cloth Sim in Flax.
Looks like that has been given some love recently.

Cloth on Flax Roadmap | Trello

1 Like