[SOLVED] What is the Best/Correct way to implement Spring Bone in Flax?

I wanted to implement “Spring Bone” in Flax.
Basically is a script to move specific bones (usually hair) to bounce/swing like a joint constraint.
For example this asset in Unity :

I am not looking for assets, because I used to write my own code to move the bone manually.
That way I can have specific parameters that will feed my needs in my game.
In Unity, the bones are represented by an object (Actor in Flax) and can be seen in the Hierarchy
So moving these bones is straightforward, you just select the Object and move its Transform.

My question is, how can you “edit/move/influence” bones in Flax?
The closest thing I can find is in this IK tutorial , where you move the bone inside AnimGraph

But that only works because

  • most of the computation is done by script (outside of AnimGraph) and we only pass parameter value to AnimGraph parameters to move the bone. (we only do “write/set” process towards AnimGraph)
  • IK bones tend to have small amount (e,g : left foot, right foot, left hand, right hand)

Meanwhile, in Spring bone, there are some problems that is a bit different than IK :

  • I need to cache and check the current position/rotation of specific bone ( “get/read” process)
    so this is the solution I came up with
    I call “AnimatedModel.GetNodeTransformation()” and then process it in custom Script,
    then set the result into “AnimGraphParameter” to affect that specific bone.
    Is this the correct way? or are there more direct approach?

  • The AnimGraph will be very occupied with many nodes. Because in spring bone you need to move/edit all joints of the constraints (hair_root → hair1 → hair2 → hair_end)

And this will increase, if you have more bones to simulate (like tails, accessories, etc)

Can someone or the dev, point me in the right direction to how to edit/affect bones for AnimatedModel properly in Flax?
Thank you.

Unfortunately this method does not work.
“AnimatedModel.GetNodeTransformation()” will return the last pose in the AnimGraph

So with this setup, I thought I can get the original Node transformation before processing
by calling “AnimatedModel.GetNodeTransformation()”
then return the “post-processed” Quaternion rotation into AnimGraphParameters
But “AnimatedModel.GetNodeTransformation()” returns the value of the Parameter in AnimGraph
so it will return (0,0,0,0) the default value of the Parameter.

I need a method API to change the transformation of bone node,
something like “AnimatedModel.SetNodeTransformation()”.
This way there is no need to create the nodes in AnimGraph like my setup in the picture above.
Just a simple Animation Output like this

Then do
“AnimatedModel.GetNodeTransformation()” → Process by Script → “AnimatedModel.SetNodeTransformation()”
to output the result back to the Bone Nodes.

Posted Git Issue here :

Thanks to @mafiesto4 who directed me to the correct SourceCode API,
I finally managed to implement SpringBone/Cloth bone in Flax.
The two belts hanging behind the character are computed and processed by Script in runtime.

For people who needs to affect Model’s bones in runtime, this is how you do it :

  1. Read/Get current bone transformation with AnimatedModel.GetCurrentPose()
  2. You will get an array of Matrices from 1 above.
    To identify which bone ID with a specific boneName, you need to manage that manually
    (e.g : create your own Dictionary of boneName & BoneID)
    The bone list can be obtained from AnimatedModel.SkinnedModel.Nodes
  3. Process the matrices of the bones you want to edit
  4. Return/Write the processed matrices back to the Model by calling AnimatedModel.SetCurrentPose()
1 Like