Skip to content

Commit

Permalink
Refactoring for networking.
Browse files Browse the repository at this point in the history
  • Loading branch information
mifth committed Feb 2, 2023
1 parent fbc3b47 commit decfc4c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 67 deletions.
141 changes: 80 additions & 61 deletions BEngine-Py/BERunNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@
import BEUtils


# def IsInstanceFromSelected(object_instance):
# # For instanced objects we check selection of their instancer (more accurately: check
# # selection status of the original object corresponding to the instancer).
# if object_instance.parent:
# return object_instance.parent.original.select_get()
# # For non-instanced objects we check selection state of the original object.
# return object_instance.object.original.select_get()


def MainWork():
def Run():
context = bpy.context

BEUtils.ClearScene()
# BEUtils.ClearScene()
bpy.ops.wm.read_homefile(use_empty=True)
# bpy.ops.wm.read_factory_settings(use_empty=True)

be_proj_paths = BEUtils.BEProjectPaths()

Expand All @@ -52,56 +45,10 @@ def MainWork():

if node_tree:

# GET BLENDER INPUTS
beInputs_path = be_proj_paths.be_tmp_folder + "BEngineInputs.json"
js_input_data = BEUtils.LoadJSON(beInputs_path)

if js_input_data:
# If GN
if node_tree.bl_idname == BEUtils.TYPE_GN and process_gn_obj:
# Set Transform
process_gn_obj.location = js_input_data["Pos"]
BEUtils.SetRotationFromJSON(process_gn_obj, js_input_data["Rot"], be_base_stuff.be_type)
process_gn_obj.scale = js_input_data["Scale"]

# Setup inputs
BEUtils.SetupInputsFromJSON(context, node_tree, geom_mod,
js_input_data, be_proj_paths, be_base_stuff.be_type)
# geom_mod.show_viewport = True

# Set the GN Object Active and Selected
bpy.ops.object.select_all(action='DESELECT')
process_gn_obj.select_set(True)
context.view_layer.objects.active = process_gn_obj

process_gn_obj.data.update()

# Save Node Outputs
BEUtils.SaveBlenderOutputs(context, [process_gn_obj], be_proj_paths, be_base_stuff.be_type, True)

# If SV
elif node_tree.bl_idname == BEUtils.TYPE_SV:
# node_tree = node_tree.evaluated_get(context.evaluated_depsgraph_get())

# Setup inputs
BEUtils.SetupInputsFromJSON(context, node_tree, None,
js_input_data, be_proj_paths, be_base_stuff.be_type)

# Update All Nodes
# node_tree.update()
context.view_layer.update()
node_tree.process_ani(True, False)

# Save Node Outputs
BEUtils.SaveBlenderOutputs(context, BEUtils.GetSVOutputObjects(node_tree),
be_proj_paths, be_base_stuff.be_type, False)

else:
print("Nodes were not Loaded! Please check Paths and NodeTree Name!")
return False
if be_base_stuff.run_type == "UpdateNodes":
GetBlenderInputs(be_base_stuff, node_tree)
else:
print("JSON Object is Empty: " + beInputs_path)
return False
RunNodes(context, be_proj_paths, node_tree, process_gn_obj, geom_mod, be_base_stuff)

return True

Expand All @@ -110,9 +57,81 @@ def MainWork():
return False


def GetBlenderInputs(be_base_stuff: BEUtils.BEBaseStuff, node_tree):
# ORIGINAL STUFF
# Get GN Data
js_output_data = {}

if node_tree.bl_idname == BEUtils.TYPE_SV:
gn_inputs_data = BEUtils.GetSVInputsData(node_tree)
else:
gn_inputs_data = BEUtils.GetGNInputsData(node_tree)

js_output_data['Inputs'] = gn_inputs_data

# If No JSON File
gn_js_path = be_base_stuff.blendfolder + be_base_stuff.blendfile_name + '_' + be_base_stuff.node_sys_name + '.json'
BEUtils.SaveJSON(gn_js_path, js_output_data)


def RunNodes(context, be_proj_paths, node_tree, process_gn_obj, geom_mod, be_base_stuff):
# GET BLENDER INPUTS
beInputs_path = be_proj_paths.be_tmp_folder + "BEngineInputs.json"
js_input_data = BEUtils.LoadJSON(beInputs_path)

if js_input_data:
# If GN
if node_tree.bl_idname == BEUtils.TYPE_GN and process_gn_obj:
# Set Transform
process_gn_obj.location = js_input_data["Pos"]
BEUtils.SetRotationFromJSON(process_gn_obj, js_input_data["Rot"], be_base_stuff.be_type)
process_gn_obj.scale = js_input_data["Scale"]

# Setup inputs
BEUtils.SetupInputsFromJSON(context, node_tree, geom_mod,
js_input_data, be_proj_paths, be_base_stuff.be_type)
# geom_mod.show_viewport = True

# Set the GN Object Active and Selected
bpy.ops.object.select_all(action='DESELECT')
process_gn_obj.select_set(True)
context.view_layer.objects.active = process_gn_obj

process_gn_obj.data.update()

# Save Node Outputs
BEUtils.SaveBlenderOutputs(context, [process_gn_obj], be_proj_paths, be_base_stuff.be_type, True)

# If SV
elif node_tree.bl_idname == BEUtils.TYPE_SV:
# node_tree = node_tree.evaluated_get(context.evaluated_depsgraph_get())

# Setup inputs
BEUtils.SetupInputsFromJSON(context, node_tree, None,
js_input_data, be_proj_paths, be_base_stuff.be_type)

# Update All Nodes
# node_tree.update()
context.view_layer.update()
node_tree.process_ani(True, False)

# Save Node Outputs
BEUtils.SaveBlenderOutputs(context, BEUtils.GetSVOutputObjects(node_tree),
be_proj_paths, be_base_stuff.be_type, False)

else:
print("Nodes were not Loaded! Please check Paths and NodeTree Name!")
return False
else:
print("JSON Object is Empty: " + beInputs_path)
return False

return True


# start = time.time()

is_done = MainWork()
is_done = Run()

# end = time.time()
# print(end - start)
Expand Down
11 changes: 5 additions & 6 deletions BEngine-Py/Utils/BEUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,13 @@ def __init__(self, be_paths: dict):
self.blendfolder = ""
self.node_sys_name = ""

# if arg.startswith('BLENDFILE='):
self.blendfile = be_paths["BLENDFILE"]
self.blendfile = be_paths["BlendFile"]

# elif arg.startswith('BLENDFOLDER='):
self.blendfolder = be_paths["BLENDFOLDER"]
self.blendfolder = be_paths["BlendFolder"]
if not self.blendfolder.endswith('/'):
self.blendfolder = self.blendfolder + "/"

# elif arg.startswith('NODESYSNAME='):
self.node_sys_name = be_paths["NODESYSNAME"]
self.node_sys_name = be_paths["NodeSysName"]

# blend file name
self.blendfile_basename = os.path.basename(self.blendfile)
Expand All @@ -110,6 +107,8 @@ def __init__(self, be_paths: dict):

self.be_type = be_paths["BEngineType"]

self.run_type = be_paths["RunNodesType"]

# # Networking
# self.RunBlenderType = be_paths["RunBlenderType"]
# self.Host = be_paths["Host"]
Expand Down

0 comments on commit decfc4c

Please sign in to comment.