Merge pull request #2363 from t3du/master

add get object uid nodes / agg args to call haxe static function / add Between to gate node
master
Lubos Lenco 2021-10-22 09:18:51 +02:00 committed by GitHub
commit 297f7cdfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 125 additions and 6 deletions

View File

@ -12,11 +12,17 @@ class CallHaxeStaticNode extends LogicNode {
var path: String = inputs[1].get();
if (path != "") {
var args: Array<Dynamic> = [];
for (i in 2...inputs.length) {
args.push(inputs[i].get());
}
var dotIndex = path.lastIndexOf(".");
var classPath = path.substr(0, dotIndex);
var classType = Type.resolveClass(classPath);
var funName = path.substr(dotIndex + 1);
result = Reflect.callMethod(classType, Reflect.field(classType, funName), [tree]);
result = Reflect.callMethod(classType, Reflect.field(classType, funName), args);
}
runOutput(0);

View File

@ -29,6 +29,9 @@ class GateNode extends LogicNode {
cond = v1 < v2;
case "Less Equal":
cond = v1 <= v2;
case "Between":
var v3: Dynamic = inputs[3].get();
cond = v2 <= v1 && v1 <= v3;
case "Or":
for (i in 1...inputs.length) {
if (inputs[i].get()) {

View File

@ -0,0 +1,22 @@
package armory.logicnode;
import iron.data.SceneFormat;
import iron.object.Object;
class GetObjectByUidNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var objectUid: Int = inputs[0].get();
var obj = iron.Scene.active.getChildren(true);
for (obji in obj) if (obji.uid == objectUid) return obji;
return null;
}
}

View File

@ -0,0 +1,18 @@
package armory.logicnode;
import iron.object.Object;
class GetUidNode extends LogicNode {
public function new(tree: LogicTree) {
super(tree);
}
override function get(from: Int): Dynamic {
var object: Object = inputs[0].get();
if (object == null) return null;
return object.uid;
}
}

View File

@ -1,6 +1,8 @@
package armory.logicnode;
import iron.math.Vec4;
import iron.math.Vec2;
import iron.App;
class WorldToScreenSpaceNode extends LogicNode {
@ -19,7 +21,10 @@ class WorldToScreenSpaceNode extends LogicNode {
v.setFrom(v1);
v.applyproj(cam.V);
v.applyproj(cam.P);
var w = App.w();
var h = App.h();
return v;
return new Vec2((v.x + 1) * 0.5 * w, (-v.y + 1) * 0.5 * h);
}
}

View File

@ -5,11 +5,13 @@ def remove_extra_inputs(self, context):
if not any(p == self.property0 for p in ['Or', 'And']):
while len(self.inputs) > self.min_inputs:
self.inputs.remove(self.inputs[-1])
if self.property0 == 'Between':
self.add_input('ArmDynamicSocket', 'Input 3')
class GateNode(ArmLogicTreeNode):
"""Logic nodes way to do "if" statements. When activated, it
compares if its two inputs are being Equal, Greater Equal,
Less Equal, or Not Equal, regardless of variable type, and passes
Less Equal, Not Equal or Between regardless of variable type, and passes
through its active input to the output that matches the result of
the comparison.
@ -17,7 +19,7 @@ class GateNode(ArmLogicTreeNode):
the input when both booleans are true (And) or at least one (Or)."""
bl_idname = 'LNGateNode'
bl_label = 'Gate'
arm_version = 1
arm_version = 2
min_inputs = 3
property0: HaxeEnumProperty(
@ -28,6 +30,7 @@ class GateNode(ArmLogicTreeNode):
('Greater Equal', 'Greater Equal', 'Greater Equal'),
('Less', 'Less', 'Less'),
('Less Equal', 'Less Equal', 'Less Equal'),
('Between', 'Between', 'Input 1 Between Input 2 and Input 3 inclusive'),
('Or', 'Or', 'Or'),
('And', 'And', 'And')],
name='', default='Equal',
@ -59,3 +62,12 @@ class GateNode(ArmLogicTreeNode):
op.socket_type = 'ArmDynamicSocket'
op2 = row.operator('arm.node_remove_input', text='', icon='X', emboss=True)
op2.node_index = str(id(self))
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.arm_version not in (0, 1):
raise LookupError()
return NodeReplacement(
'LNGateNode', self.arm_version, 'LNGateNode', 2,
in_socket_mapping={0:0, 1:1, 2:2}, out_socket_mapping={0:0, 1:1}
)

View File

@ -1,18 +1,42 @@
from arm.logicnode.arm_nodes import *
class CallHaxeStaticNode(ArmLogicTreeNode):
"""Calls the given static Haxe function.
"""Calls the given static Haxe function and optionally passes arguments to it.
**Compatibility info**: prior versions of this node didn't accept arguments and instead implicitly passed the current logic tree object as the first argument. In newer versions you need to pass that argument explicitly if the called function expects it.
@input Function: the full module path to the function.
@output Result: the result of the function."""
bl_idname = 'LNCallHaxeStaticNode'
bl_label = 'Call Haxe Static'
arm_section = 'haxe'
arm_version = 1
arm_version = 2
def __init__(self):
array_nodes[str(id(self))] = self
def arm_init(self, context):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmStringSocket', 'Function')
self.add_output('ArmNodeSocketAction', 'Out')
self.add_output('ArmDynamicSocket', 'Result')
def draw_buttons(self, context, layout):
row = layout.row(align=True)
op = row.operator('arm.node_add_input', text='Add Arg', icon='PLUS', emboss=True)
op.node_index = str(id(self))
op.socket_type = 'ArmDynamicSocket'
op.name_format = "Arg {0}"
op.index_name_offset = -2
op2 = row.operator('arm.node_remove_input', text='', icon='X', emboss=True)
op2.node_index = str(id(self))
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.arm_version not in (0, 1):
raise LookupError()
return NodeReplacement(
'LNCallHaxeStaticNode', self.arm_version, 'LNCallHaxeStaticNode', 2,
in_socket_mapping={0:0, 1:1}, out_socket_mapping={0:0, 1:1}
)

View File

@ -0,0 +1,16 @@
import bpy
from arm.logicnode.arm_nodes import *
class GetObjectByUidNode(ArmLogicTreeNode):
"""Searches for a object with this uid in the current active scene and returns it."""
bl_idname = 'LNGetObjectByUidNode'
bl_label = 'Get Object By Uid'
arm_version = 1
def arm_init(self, context):
self.add_input('ArmIntSocket', 'Uid')
self.add_output('ArmNodeSocketObject', 'Object')

View File

@ -0,0 +1,13 @@
from arm.logicnode.arm_nodes import *
class GetUidNode(ArmLogicTreeNode):
"""Returns the uid of the given object."""
bl_idname = 'LNGetUidNode'
bl_label = 'Get Object Uid'
arm_section = 'props'
arm_version = 1
def arm_init(self, context):
self.add_input('ArmNodeSocketObject', 'Object')
self.add_output('ArmIntSocket', 'Uid')