From c1e104e23211e3631dc55a90954c6143a66184fc Mon Sep 17 00:00:00 2001 From: Simonrazer Date: Wed, 15 Aug 2018 08:51:45 +0200 Subject: [PATCH] Lerp Vectors node --- Sources/armory/logicnode/LerpVectorsNode.hx | 41 +++++++++++++++++++++ blender.py | 14 +++++++ 2 files changed, 55 insertions(+) create mode 100644 Sources/armory/logicnode/LerpVectorsNode.hx diff --git a/Sources/armory/logicnode/LerpVectorsNode.hx b/Sources/armory/logicnode/LerpVectorsNode.hx new file mode 100644 index 0000000..32312cd --- /dev/null +++ b/Sources/armory/logicnode/LerpVectorsNode.hx @@ -0,0 +1,41 @@ +package armory.logicnode; + +import iron.math.Vec4; + +class LerpVectorsNode extends LogicNode { + + var v = new Vec4(); + var v1:Vec4; + var v2:Vec4; + var t=0.0; + var c:Float; + var f=0.0; + + public function new(tree:LogicTree) { + super(tree); + } + + override function run() { + v1 = inputs[1].get(); + v2 = inputs[2].get(); + t = inputs[3].get(); + f = (t / iron.system.Time.delta); + } + + override function get(from:Int):Dynamic { + if (v1==null) { + return null; + c=1; + } + if (t>=0) { + trace(t); + v.x=v1.x+((v2.x-v1.x)/f)*c; + v.y=v1.y+((v2.y-v1.y)/f)*c; + v.z=v1.z+((v2.z-v1.z)/f)*c; + t -= iron.system.Time.delta; + c++; + return v; + } + else {c=1; return null;} + } +} diff --git a/blender.py b/blender.py index 765286b..42827cc 100644 --- a/blender.py +++ b/blender.py @@ -223,6 +223,19 @@ def init(self, context): self.inputs.new('NodeSocketFloat', 'Seconds') self.inputs.new('NodeSocketInt', 'Repetitions (0 for oneshot, negative for unlimited)') +class LerpVectorsNode(Node, ArmLogicTreeNode): + '''Lerp Vectors node''' + bl_idname = 'LNLerpVectorsNode' + bl_label = 'Lerp Vectors' + bl_icon = 'GAME' + + def init(self, context): + self.inputs.new('ArmNodeSocketAction', 'In') + self.inputs.new('NodeSocketVector', 'Starting Vector') + self.inputs.new('NodeSocketVector', 'End Vector') + self.inputs.new('NodeSocketFloat', 'Time For Change') + self.outputs.new('NodeSocketVector', 'Vector') + def register(): # Add custom nodes # TODO: separate into single .py file per logic node, similar to the main Armory repository @@ -235,6 +248,7 @@ def register(): add_node(CameraController, category='Action') add_node(AnimationControllerNode, category='Animation') add_node(TimerNode, category='Logic') + add_node(LerpVectorsNode, category='Value') # Register newly added nodes arm.nodes_logic.register_nodes()