SkeletonModification3DFABRIK

Inherits: SkeletonModification3D < Resource < RefCounted < Object

A modification that uses FABRIK to manipulate a series of bones to reach a target.

Description

This SkeletonModification3D uses an algorithm called Forward And Backward Reaching Inverse Kinematics, or FABRIK, to rotate a bone chain so that it reaches a target.

FABRIK works by knowing the positions and lengths of a series of bones, typically called a "bone chain". It first starts by running a forward pass, which places the final bone at the target's position. Then all other bones are moved towards the tip bone, so they stay at the defined bone length away. Then a backwards pass is performed, where the root/first bone in the FABRIK chain is placed back at the origin. then all other bones are moved so they stay at the defined bone length away. This positions the bone chain so that it reaches the target when possible, but all of the bones stay the correct length away from each other.

Because of how FABRIK works, it often gives more natural results than those seen in SkeletonModification3DCCDIK, though FABRIK currently does not support joint constraints.

Note: The FABRIK modifier has fabrik_joints, which are the data objects that hold the data for each joint in the FABRIK chain. This is different from a bone! FABRIK joints hold the data needed for each bone in the bone chain used by FABRIK.

To help control how the FABRIK joints move, a magnet vector can be passed, which can nudge the bones in a certain direction prior to solving, giving a level of control over the final result.

Methods

void

fabrik_joint_auto_calculate_length ( int joint_idx )

bool

get_fabrik_joint_auto_calculate_length ( int joint_idx ) const

int

get_fabrik_joint_bone_index ( int joint_idx ) const

String

get_fabrik_joint_bone_name ( int joint_idx ) const

float

get_fabrik_joint_length ( int joint_idx ) const

Vector3

get_fabrik_joint_magnet ( int joint_idx ) const

NodePath

get_fabrik_joint_tip_node ( int joint_idx ) const

bool

get_fabrik_joint_use_target_basis ( int joint_idx ) const

bool

get_fabrik_joint_use_tip_node ( int joint_idx ) const

void

set_fabrik_joint_auto_calculate_length ( int joint_idx, bool auto_calculate_length )

void

set_fabrik_joint_bone_index ( int joint_idx, int bone_index )

void

set_fabrik_joint_bone_name ( int joint_idx, String bone_name )

void

set_fabrik_joint_length ( int joint_idx, float length )

void

set_fabrik_joint_magnet ( int joint_idx, Vector3 magnet_position )

void

set_fabrik_joint_tip_node ( int joint_idx, NodePath tip_node )

void

set_fabrik_joint_use_target_basis ( int joint_idx, bool use_target_basis )

void

set_fabrik_joint_use_tip_node ( int joint_idx, bool use_tip_node )

Property Descriptions

  • int chain_max_iterations

Default

10

Setter

set_chain_max_iterations(value)

Getter

get_chain_max_iterations()

The number of times FABRIK will try to solve each time the execute function is called. Setting this value to a lower number will be result in better performance, but this can also result in harsher movements and slower solves.


Default

0.01

Setter

set_chain_tolerance(value)

Getter

get_chain_tolerance()

The minimum distance the target has to be from the tip of the final bone in the bone chain. Setting this value to a higher number allows for greater performance, but less accurate solves.


  • int fabrik_data_chain_length

Default

0

Setter

set_fabrik_data_chain_length(value)

Getter

get_fabrik_data_chain_length()

The amount of FABRIK joints in the FABRIK modification.


Default

NodePath("")

Setter

set_target_node(value)

Getter

get_target_node()

The NodePath to the node that is the target for the FABRIK modification. This node is what the FABRIK chain will attempt to rotate the bone chain to.

Method Descriptions

  • void fabrik_joint_auto_calculate_length ( int joint_idx )

Will attempt to automatically calculate the length of the bone assigned to the FABRIK joint at joint_idx.


  • bool get_fabrik_joint_auto_calculate_length ( int joint_idx ) const

Returns a boolean that indiciates whether this modification will attempt to autocalculate the length of the bone assigned to the FABRIK joint at joint_idx.


  • int get_fabrik_joint_bone_index ( int joint_idx ) const

Returns the bone index of the bone assigned to the FABRIK joint at joint_idx.


  • String get_fabrik_joint_bone_name ( int joint_idx ) const

Returns the name of the bone that is assigned to the FABRIK joint at joint_idx.


  • float get_fabrik_joint_length ( int joint_idx ) const

Returns the length of the FABRIK joint at joint_idx.


  • Vector3 get_fabrik_joint_magnet ( int joint_idx ) const

Returns the magnet vector of the FABRIK joint at joint_idx.


  • NodePath get_fabrik_joint_tip_node ( int joint_idx ) const

Returns the Node3D-based node placed at the tip of the FABRIK joint at joint_idx, if one has been set.


  • bool get_fabrik_joint_use_target_basis ( int joint_idx ) const

Returns a boolean indiciating whether the FABRIK joint uses the target's Basis for its rotation.

Note: This option is only available for the final bone in the FABRIK chain, with this setting being ignored for all other bones.


  • bool get_fabrik_joint_use_tip_node ( int joint_idx ) const

Sets the Node3D-based node that will be used as the tip of the FABRIK joint at joint_idx.


  • void set_fabrik_joint_auto_calculate_length ( int joint_idx, bool auto_calculate_length )

When true, this modification will attempt to automatically calculate the length of the bone for the FABRIK joint at joint_idx. It does this by either using the tip node assigned, if there is one assigned, or the distance the of the bone's children, if the bone has any. If the bone has no children and no tip node is assigned, then the modification cannot autocalculate the joint's length. In this case, the joint length should be entered manually or a tip node assigned.


  • void set_fabrik_joint_bone_index ( int joint_idx, int bone_index )

Sets the bone index, bone_index, of the FABRIK joint at joint_idx. When possible, this will also update the bone_name of the FABRIK joint based on data provided by the Skeleton3D.


  • void set_fabrik_joint_bone_name ( int joint_idx, String bone_name )

Sets the bone name, bone_name, of the FABRIK joint at joint_idx. When possible, this will also update the bone_index of the FABRIK joint based on data provided by the Skeleton3D.


  • void set_fabrik_joint_length ( int joint_idx, float length )

Sets the joint length, length, of the FABRIK joint at joint_idx.


  • void set_fabrik_joint_magnet ( int joint_idx, Vector3 magnet_position )

Sets the magenet position to magnet_position for the joint at joint_idx. The magnet position is used to nudge the joint in that direction when solving, which gives some control over how that joint will bend when being solved.


  • void set_fabrik_joint_tip_node ( int joint_idx, NodePath tip_node )

Sets the nodepath of the FARIK joint at joint_idx to tip_node. The tip node is used to calculate the length of the FABRIK joint when set to automatically calculate joint length.

Note: The tip node should generally be a child node of a BoneAttachment3D node attached to the bone that this FABRIK joint operates on, with the child node being offset so it is at the end of the bone.


  • void set_fabrik_joint_use_target_basis ( int joint_idx, bool use_target_basis )

Sets whether the FABRIK joint at joint_idx uses the target's Basis for its rotation.

Note: This option is only available for the final bone in the FABRIK chain, with this setting being ignored for all other bones.


  • void set_fabrik_joint_use_tip_node ( int joint_idx, bool use_tip_node )

Sets whether the tip node should be used when autocalculating the joint length for the FABRIK joint at joint_idx. This will only work if there is a node assigned to the tip nodepath for this joint.