armory/Sources/armory/logicnode/BoneFKNode.hx

54 lines
1 KiB
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.Mat4;
class BoneFKNode extends LogicNode {
var notified = false;
2019-12-19 23:54:08 +01:00
var m: Mat4 = null;
var w: Mat4 = null;
2018-08-03 15:17:08 +02:00
var iw = Mat4.identity();
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();
var transform: Mat4 = inputs[3].get();
2018-08-03 15:17:08 +02:00
if (object == null) return;
var anim = object.animation != null ? cast(object.animation, BoneAnimation) : null;
if (anim == null) anim = object.getParentArmature(object.name);
// Manipulating bone in world space
var bone = anim.getBone(boneName);
m = anim.getBoneMat(bone);
w = anim.getAbsMat(bone);
2019-12-19 23:54:08 +01:00
2018-08-03 15:17:08 +02:00
function moveBone() {
m.setFrom(w);
2018-08-28 13:50:52 +02:00
m.multmat(transform);
2018-08-03 15:17:08 +02:00
iw.getInverse(w);
2018-08-28 13:50:52 +02:00
m.multmat(iw);
2018-08-03 15:17:08 +02:00
// anim.removeUpdate(moveBone);
// notified = false;
}
if (!notified) {
anim.notifyOnUpdate(moveBone);
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
}
}