armory/Sources/armory/logicnode/BoneFKNode.hx

65 lines
1.4 KiB
Haxe
Raw Permalink Normal View History

2018-08-03 15:17:08 +02:00
package armory.logicnode;
import iron.math.Quat;
import iron.math.Vec4;
2018-08-03 15:17:08 +02:00
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);
// Get bone in armature
2018-08-03 15:17:08 +02:00
var bone = anim.getBone(boneName);
2019-12-19 23:54:08 +01:00
2018-08-03 15:17:08 +02:00
function moveBone() {
var t2 = Mat4.identity();
var loc= new Vec4();
var rot = new Quat();
var scl = new Vec4();
2018-08-03 15:17:08 +02:00
//Set scale to Armature scale. Bone scaling not yet implemented
t2.setFrom(transform);
t2.decompose(loc, rot, scl);
scl = object.transform.world.getScale();
t2.compose(loc, rot, scl);
//Set the bone local transform from world transform
anim.setBoneMatFromWorldMat(t2, bone);
//Remove this method from animation loop after FK
anim.removeUpdate(moveBone);
notified = false;
2018-08-03 15:17:08 +02:00
}
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
}
}