From 7e842a0c96f733e35367f16a6c6c0eb97e474623 Mon Sep 17 00:00:00 2001 From: Simonrazer Date: Thu, 15 Feb 2018 09:04:52 +0100 Subject: [PATCH] quat nodes 2 new quat nodes --- Sources/armory/logicnode/QuatToEulerNode.hx | 34 ++++++++++++++++++++ Sources/armory/logicnode/SeparateQuatNode.hx | 28 ++++++++++++++++ blender.py | 29 +++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 Sources/armory/logicnode/QuatToEulerNode.hx create mode 100644 Sources/armory/logicnode/SeparateQuatNode.hx diff --git a/Sources/armory/logicnode/QuatToEulerNode.hx b/Sources/armory/logicnode/QuatToEulerNode.hx new file mode 100644 index 0000000..edc761a --- /dev/null +++ b/Sources/armory/logicnode/QuatToEulerNode.hx @@ -0,0 +1,34 @@ +package armory.logicnode; + +import iron.math.Mat4; +import iron.math.Vec4; +import iron.math.Quat; + +class QuatToEulerNode extends LogicNode { + + + public function new(tree:LogicTree) { + super(tree); + + } + + + override function get(from:Int):Dynamic { + var x:Float = inputs[0].get(); + var y:Float = inputs[1].get(); + var z:Float = inputs[2].get(); + var w:Float = inputs[3].get(); + var q = new Quat(); + + q.x=x; + q.y=y; + q.z=z; + q.w=w; + + var v = new Vec4(); + v.setFrom(q.getEuler()); + return v; + } + } + + diff --git a/Sources/armory/logicnode/SeparateQuatNode.hx b/Sources/armory/logicnode/SeparateQuatNode.hx new file mode 100644 index 0000000..d1f0d5d --- /dev/null +++ b/Sources/armory/logicnode/SeparateQuatNode.hx @@ -0,0 +1,28 @@ +package armory.logicnode; + +import iron.math.Mat4; +import iron.math.Vec4; +import iron.math.Quat; + +class SeparateQuatNode extends LogicNode { + + + public function new(tree:LogicTree) { + super(tree); + + } + + + override function get(from:Int):Dynamic { + var m:Mat4 = inputs[0].get(); + + if (from == 0) return m.getQuat().x; + else if (from == 1) return m.getQuat().y; + else if (from == 2) return m.getQuat().z; + else if (from == 3) return m.getQuat().w; + else return m.getQuat().getEuler(); + + } + } + + diff --git a/blender.py b/blender.py index a36fc90..c11d4ed 100644 --- a/blender.py +++ b/blender.py @@ -4,6 +4,33 @@ from arm.logicnode.arm_nodes import * import arm.nodes_logic +class QuatToEulerNode(Node, ArmLogicTreeNode): + '''QuatToEulerNode''' + bl_idname = 'LNQuatToEulerNode' + bl_label = 'Quat To Euler' + bl_icon = 'GAME' + + def init(self, context): + self.inputs.new('NodeSocketFloat', 'X') + self.inputs.new('NodeSocketFloat', 'Y') + self.inputs.new('NodeSocketFloat', 'Z') + self.inputs.new('NodeSocketFloat', 'W') + self.outputs.new('NodeSocketVector', 'Euler') + +class SeparateQuatNode(Node, ArmLogicTreeNode): + '''SeparateQuatNode''' + bl_idname = 'LNSeparateQuatNode' + bl_label = 'Separate Quat' + bl_icon = 'GAME' + + def init(self, context): + self.inputs.new('NodeSocketShader', 'Transform') + self.outputs.new('NodeSocketFloat', 'X') + self.outputs.new('NodeSocketFloat', 'Y') + self.outputs.new('NodeSocketFloat', 'Z') + self.outputs.new('NodeSocketFloat', 'W') + self.outputs.new('NodeSocketVector', 'Euler') + class TranslateOnLocalAxisNode(Node, ArmLogicTreeNode): '''TranslateOnLocalAxisNode''' bl_idname = 'LNTranslateOnLocalAxisNode' @@ -85,6 +112,8 @@ def init(self, context): def register(): # Add custom nodes + add_node(QuatToEulerNode, category= 'Value') + add_node(SeparateQuatNode, category='Value') add_node(TranslateOnLocalAxisNode, category='Action') add_node(ArrayLoopIndiceNode, category='Logic') add_node(ToBoolNode, category='Logic')