armory/Sources/armory/logicnode/BoneIKNode.hx

46 lines
876 B
Haxe
Raw Normal View History

2018-08-03 15:17:08 +02:00
package armory.logicnode;
import iron.object.Object;
import iron.object.BoneAnimation;
import iron.math.Vec4;
class BoneIKNode extends LogicNode {
2019-12-19 23:54:08 +01:00
var goal: Vec4;
2018-08-03 15:17:08 +02:00
var notified = false;
2019-12-19 23:54:08 +01:00
public function new(tree: LogicTree) {
2018-08-03 15:17:08 +02:00
super(tree);
}
2019-12-19 23:54:08 +01:00
override function run(from: Int) {
2018-11-16 14:01:41 +01:00
#if arm_skin
2019-12-19 23:54:08 +01:00
var object: Object = inputs[1].get();
var boneName: String = inputs[2].get();
2018-08-03 15:17:08 +02:00
goal = inputs[3].get();
2019-12-19 23:54:08 +01:00
2018-08-03 15:17:08 +02:00
if (object == null || goal == null) return;
var anim = object.animation != null ? cast(object.animation, BoneAnimation) : null;
if (anim == null) anim = object.getParentArmature(object.name);
var bone = anim.getBone(boneName);
2019-12-19 23:54:08 +01:00
2018-08-03 15:17:08 +02:00
function solveBone() {
anim.solveIK(bone, goal);
// anim.removeUpdate(solveBone);
// notified = false;
}
if (!notified) {
anim.notifyOnUpdate(solveBone);
notified = true;
}
2018-10-22 10:10:33 +02:00
runOutput(0);
2018-11-16 14:01:41 +01:00
#end
2018-08-03 15:17:08 +02:00
}
}