Skip to content

Commit

Permalink
Small Fixes, Add Get Gravity Node
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Mar 23, 2021
1 parent c097eb3 commit a0334c0
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
7 changes: 5 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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(
Expand Down
54 changes: 53 additions & 1 deletion basicnodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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"]
Expand All @@ -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)
Expand Down
32 changes: 31 additions & 1 deletion game/bgelogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion nodeutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
'Time',
'Variables',
'Render',
'Utilities'
'Utilities',
'Layout'
]

_cat_separators = [
Expand Down
7 changes: 4 additions & 3 deletions ops/tree_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)")
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0334c0

Please sign in to comment.