Nodes for IK and FK fix

Edit logic node code

fkcommit30_04

Upgrade bone IK node. Add comments
This commit is contained in:
QuantumCoderQC 2021-02-17 19:55:18 +01:00
parent 3b72fff76d
commit 5ed5b8d6a7
3 changed files with 66 additions and 13 deletions

View file

@ -28,17 +28,20 @@ class BoneFKNode extends LogicNode {
// Manipulating bone in world space
var bone = anim.getBone(boneName);
m = anim.getBoneMat(bone);
w = anim.getAbsMat(bone);
/* m = anim.getBoneMat(bone);
w = anim.getAbsMat(bone); */
function moveBone() {
m.setFrom(w);
/* m.setFrom(w);
m.multmat(transform);
iw.getInverse(w);
m.multmat(iw);
m.multmat(iw); */
//trace("Perform FK");
anim.setBoneMatFromWorldMat(transform.clone(), bone);
// anim.removeUpdate(moveBone);
// notified = false;
anim.removeUpdate(moveBone);
//trace("FK removed");
notified = false;
}
if (!notified) {

View file

@ -7,6 +7,13 @@ import iron.math.Vec4;
class BoneIKNode extends LogicNode {
var goal: Vec4;
var pole: Vec4;
var poleEnabled: Bool;
var chainLength: Int;
var maxIterartions: Int;
var precision: Float;
var rollAngle: Float;
var notified = false;
public function new(tree: LogicTree) {
@ -19,6 +26,12 @@ class BoneIKNode extends LogicNode {
var object: Object = inputs[1].get();
var boneName: String = inputs[2].get();
goal = inputs[3].get();
poleEnabled = inputs[4].get();
pole = inputs[5].get();
chainLength = inputs[6].get();
maxIterartions = inputs[7].get();
precision = inputs[8].get();
rollAngle = inputs[9].get();
if (object == null || goal == null) return;
var anim = object.animation != null ? cast(object.animation, BoneAnimation) : null;
@ -26,11 +39,13 @@ class BoneIKNode extends LogicNode {
var bone = anim.getBone(boneName);
function solveBone() {
anim.solveIK(bone, goal);
if(! poleEnabled) pole = null;
// anim.removeUpdate(solveBone);
// notified = false;
function solveBone() {
anim.solveIK(bone, goal, precision, maxIterartions, chainLength, pole, rollAngle);
anim.removeUpdate(solveBone);
notified = false;
}
if (!notified) {

View file

@ -1,10 +1,29 @@
from arm.logicnode.arm_nodes import *
class BoneIKNode(ArmLogicTreeNode):
"""Applies inverse kinematics in the given object bone."""
"""Performs inverse kinematics on the selected armature with specified bone.
@input Object: Armature on which IK should be performed.
@input Bone: Effector or tip bone for the inverse kinematics
@input Goal Position: Position in world coordinates the effector bone will track to
@input Enable Pole: Bend IK solution towards pole location
@input Pole Position: Location of the pole in world coordinates
@input Chain Length: Number of bones to include in the IK solver including the effector. If set to 0, all bones from effector to the root bone of the armature will be considered.
@input Max Iterations: Maximum allowed FABRIK iterations to solve for IK. For longer chains, more iterations are needed.
@input Precision: Presition of IK to stop at. It is described as a tolerence in length. Typically 0.01 is a good value.
@input Roll Angle: Roll the bones along their local axis with specified radians. set 0 for no extra roll.
"""
bl_idname = 'LNBoneIKNode'
bl_label = 'Bone IK'
arm_version = 1
arm_version = 2
arm_section = 'armature'
def init(self, context):
@ -12,6 +31,22 @@ class BoneIKNode(ArmLogicTreeNode):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmNodeSocketObject', 'Object')
self.add_input('NodeSocketString', 'Bone')
self.add_input('NodeSocketVector', 'Goal')
self.add_input('NodeSocketVector', 'Goal Position')
self.add_input('NodeSocketBool', 'Enable Pole')
self.add_input('NodeSocketVector', 'Pole Position')
self.add_input('NodeSocketInt', 'Chain Length')
self.add_input('NodeSocketInt', 'Max Iterations', 10)
self.add_input('NodeSocketFloat', 'Precision', 0.01)
self.add_input('NodeSocketFloat', 'Roll Angle')
self.add_output('ArmNodeSocketAction', 'Out')
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.arm_version not in (0, 1):
raise LookupError()
return NodeReplacement(
'LNBoneIKNode', self.arm_version, 'LNBoneIKNode', 2,
in_socket_mapping={0:0, 1:1, 2:2, 3:3}, out_socket_mapping={0:0}
)