From a0334c015e66a8d860011458a749860fd11316b7 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 23 Mar 2021 13:01:36 +0100 Subject: [PATCH] Small Fixes, Add Get Gravity Node --- __init__.py | 7 +++-- basicnodes/__init__.py | 54 +++++++++++++++++++++++++++++++++++++- game/bgelogic.py | 32 +++++++++++++++++++++- nodeutils/__init__.py | 3 ++- ops/tree_code_generator.py | 7 ++--- ui/__init__.py | 6 +++-- 6 files changed, 99 insertions(+), 10 deletions(-) diff --git a/__init__.py b/__init__.py index cb67a00..021d43e 100644 --- a/__init__.py +++ b/__init__.py @@ -452,8 +452,6 @@ def draw(self, context): link_row.operator("bge_netlogic.donate", icon="FUND") contrib_row = col.row() contrib_row.label(text='Contributors: L_P, Mike King') - testers_row = col.row() - testers_row.label(text='Testers: Firespury') basicnodes = _abs_import("basicnodes", _abs_path("basicnodes", "__init__.py")) @@ -599,6 +597,11 @@ def register(): print("Registering... {}".format(cls.__name__)) bpy.utils.register_class(cls) menu_nodes = _list_menu_nodes() + layout_items = [ + nodeitems_utils.NodeItem('NodeReroute'), + nodeitems_utils.NodeItem('NodeFrame') + ] + menu_nodes.append(NodeCategory('LayoutNodes', 'Layout', items=layout_items)) nodeitems_utils.register_node_categories("NETLOGIC_NODES", menu_nodes) bpy.types.Object.sound_occluder = bpy.props.BoolProperty( diff --git a/basicnodes/__init__.py b/basicnodes/__init__.py index 66d3f7a..72ca31c 100644 --- a/basicnodes/__init__.py +++ b/basicnodes/__init__.py @@ -4389,6 +4389,22 @@ def get_netlogic_class_name(self): _nodes.append(NLActiveCameraParameterNode) +class NLGetGravityNode(bpy.types.Node, NLParameterNode): + bl_idname = "NLGetGravityNode" + bl_label = "Get Gravity" + nl_category = "Scene" + + def init(self, context): + NLParameterNode.init(self, context) + self.outputs.new(NLVec3FieldSocket.bl_idname, "Gravity") + + def get_netlogic_class_name(self): + return "bgelogic.GetGravity" + + +_nodes.append(NLGetGravityNode) + + class NLGetCollectionNode(bpy.types.Node, NLParameterNode): bl_idname = "NLGetCollectionNode" bl_label = "Get Collection" @@ -5209,6 +5225,30 @@ def get_input_sockets_field_names(self): _nodes.append(NLParameterMatrixToEulerNode) +class NLParameterMatrixToVectorNode(bpy.types.Node, NLParameterNode): + bl_idname = "NLParameterMatrixToVectorNode" + bl_label = "Matrix To Vector" + nl_category = "Math" + nl_subcat = 'Vector Math' + + def init(self, context): + NLParameterNode.init(self, context) + self.inputs.new(NLParameterSocket.bl_idname, 'Matrix') + self.outputs.new(NLVec3FieldSocket.bl_idname, "Vector") + + def get_netlogic_class_name(self): + return "bgelogic.ParameterMatrixToVector" + + def get_output_socket_varnames(self): + return ["OUT"] + + def get_input_sockets_field_names(self): + return ["input_m"] + + +_nodes.append(NLParameterMatrixToVectorNode) + + class NLOnInitConditionNode(bpy.types.Node, NLConditionNode): bl_idname = "NLOnInitConditionNode" bl_label = "On Init" @@ -7937,7 +7977,7 @@ def draw_buttons(self, context, layout): self, "local", toggle=True, - text="Apply Local" if self.local else "Apply Global" + text="Local" if self.local else "Global" ) def get_netlogic_class_name(self): @@ -9383,6 +9423,7 @@ class NLActionAlignAxisToVector(bpy.types.Node, NLActionNode): bl_label = "Align Axis to Vector" nl_category = "Objects" nl_subcat = 'Transformation' + local: bpy.props.BoolProperty(default=True, update=update_tree_code) def init(self, context): NLActionNode.init(self, context) @@ -9393,6 +9434,14 @@ def init(self, context): self.inputs.new(NLSocketAlphaFloat.bl_idname, "Factor") self.inputs[-1].value = 1.0 self.outputs.new(NLConditionSocket.bl_idname, 'Done') + + def draw_buttons(self, context, layout): + layout.prop( + self, + "local", + toggle=True, + text="Apply Local" if self.local else "Apply Global" + ) def get_output_socket_varnames(self): return ["OUT"] @@ -9402,6 +9451,9 @@ def get_netlogic_class_name(self): def get_input_sockets_field_names(self): return ["condition", "game_object", "vector", "axis", 'factor'] + + def get_nonsocket_fields(self): + return [("local", lambda: "True" if self.local else "False")] _nodes.append(NLActionAlignAxisToVector) diff --git a/game/bgelogic.py b/game/bgelogic.py index bc67ba5..da077d3 100644 --- a/game/bgelogic.py +++ b/game/bgelogic.py @@ -2919,6 +2919,16 @@ def evaluate(self): self._set_value(scene.active_camera) +class GetGravity(ParameterCell): + def __init__(self): + ParameterCell.__init__(self) + self.collection = None + + def evaluate(self): + self._set_ready() + self._set_value(bge.logic.getCurrentScene().gravity) + + class GetCollection(ParameterCell): def __init__(self): ParameterCell.__init__(self) @@ -3761,6 +3771,23 @@ def evaluate(self): self.euler = matrix.to_euler() +class ParameterMatrixToVector(ParameterCell): + def __init__(self): + ParameterCell.__init__(self) + self.input_m = None + self.vec = mathutils.Vector() + self.OUT = LogicNetworkSubCell(self, self.get_vec) + + def get_vec(self): + return self.vec + + def evaluate(self): + self._set_ready() + matrix = self.get_parameter_value(self.input_m) + e = matrix.to_euler() + self.vec = mathutils.Vector((e.x, e.y, e.z)) + + class ParameterVector3Simple(ParameterCell): def __init__(self): ParameterCell.__init__(self) @@ -9828,7 +9855,7 @@ def evaluate(self): self.done = False condition = self.get_parameter_value(self.condition) self._set_ready() - if not condition: + if not_met(condition): return game_object = self.get_parameter_value(self.game_object) v = self.get_parameter_value(self.vector) @@ -9840,6 +9867,9 @@ def evaluate(self): return if factor is None: return + v = getattr(v, 'worldPosition', v).copy() + if not self.local: + v -= game_object.worldPosition if axis > 2: matvec = v.copy() matvec.negate() diff --git a/nodeutils/__init__.py b/nodeutils/__init__.py index 27147a2..3009f1a 100644 --- a/nodeutils/__init__.py +++ b/nodeutils/__init__.py @@ -82,7 +82,8 @@ 'Time', 'Variables', 'Render', - 'Utilities' + 'Utilities', + 'Layout' ] _cat_separators = [ diff --git a/ops/tree_code_generator.py b/ops/tree_code_generator.py index 04f6a95..2872bff 100644 --- a/ops/tree_code_generator.py +++ b/ops/tree_code_generator.py @@ -53,7 +53,7 @@ def write_code_for_tree(self, tree): for varname in self._sort_cellvarnames(cell_var_names, uid_map): if not uid_map.is_removed(varname): line_writer.write_line("network.add_cell({})", varname) - line_writer.write_line('owner["{}"] = network', tree.name) + line_writer.write_line('owner["IGNLTree_{}"] = network', tree.name) line_writer.write_line("network._owner = owner") line_writer.write_line("network.setup()") line_writer.write_line("network.stopped = not owner.get('{}')", utils.get_key_network_initial_status_for_tree(tree)) @@ -63,7 +63,7 @@ def write_code_for_tree(self, tree): line_writer.write_line("def pulse_network(controller):") line_writer.set_indent_level(1) line_writer.write_line("owner = controller.owner") - line_writer.write_line('network = owner.get("{}")', tree.name) + line_writer.write_line('network = owner.get("IGNLTree_{}")', tree.name) line_writer.write_line("if network is None:") line_writer.set_indent_level(2) line_writer.write_line("network = _initialize(owner)") @@ -74,7 +74,7 @@ def write_code_for_tree(self, tree): line_writer.set_indent_level(2) line_writer.write_line("controller.sensors[0].repeat = False") line_writer.close() - #write the bgelogic.py module source in the directory of the current blender file + # write the bgelogic.py module source in the directory of the current blender file this_module_dir = os.path.dirname(__file__) bge_netlogic_dir = os.path.dirname(this_module_dir) @@ -153,6 +153,7 @@ def _sort_cellvarnames(self, node_cellvar_list, uid_map): def _test_node_links(self, node, added_cell_names, uid_map): for input in node.inputs: if input.is_linked: + # XXX: MAYBE THIS IS THE CAUSE OF ACCESS VIOLATION linked_node = input.links[0].from_socket.node while isinstance(linked_node, bpy.types.NodeReroute): if not linked_node.inputs[0].links: diff --git a/ui/__init__.py b/ui/__init__.py index ae7cd9d..a2bb506 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -212,7 +212,8 @@ class BGE_PT_GamePropertyPanel(bpy.types.Panel): @classmethod def poll(cls, context): ob = context.active_object - return ob and ob.name + enabled = (context.space_data.tree_type == BGELogicTree.bl_idname) + return ob and ob.name and enabled def draw_tree_prop(self, prop, index, box, show_movers): col = box.column() @@ -716,7 +717,8 @@ class BGE_PT_LogicTreeInfoPanel(bpy.types.Panel): @classmethod def poll(cls, context): ob = context.active_object - return ob and ob.name + enabled = (context.space_data.tree_type == BGELogicTree.bl_idname) + return ob and ob.name and enabled def get_combined_status_of_tree_items(self, tree_item_list): last = None