Skip to content

Commit decfc4c

Browse files
committed
Refactoring for networking.
1 parent fbc3b47 commit decfc4c

File tree

2 files changed

+85
-67
lines changed

2 files changed

+85
-67
lines changed

BEngine-Py/BERunNodes.py

Lines changed: 80 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,12 @@
2626
import BEUtils
2727

2828

29-
# def IsInstanceFromSelected(object_instance):
30-
# # For instanced objects we check selection of their instancer (more accurately: check
31-
# # selection status of the original object corresponding to the instancer).
32-
# if object_instance.parent:
33-
# return object_instance.parent.original.select_get()
34-
# # For non-instanced objects we check selection state of the original object.
35-
# return object_instance.object.original.select_get()
36-
37-
38-
def MainWork():
29+
def Run():
3930
context = bpy.context
4031

41-
BEUtils.ClearScene()
32+
# BEUtils.ClearScene()
33+
bpy.ops.wm.read_homefile(use_empty=True)
34+
# bpy.ops.wm.read_factory_settings(use_empty=True)
4235

4336
be_proj_paths = BEUtils.BEProjectPaths()
4437

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

5346
if node_tree:
5447

55-
# GET BLENDER INPUTS
56-
beInputs_path = be_proj_paths.be_tmp_folder + "BEngineInputs.json"
57-
js_input_data = BEUtils.LoadJSON(beInputs_path)
58-
59-
if js_input_data:
60-
# If GN
61-
if node_tree.bl_idname == BEUtils.TYPE_GN and process_gn_obj:
62-
# Set Transform
63-
process_gn_obj.location = js_input_data["Pos"]
64-
BEUtils.SetRotationFromJSON(process_gn_obj, js_input_data["Rot"], be_base_stuff.be_type)
65-
process_gn_obj.scale = js_input_data["Scale"]
66-
67-
# Setup inputs
68-
BEUtils.SetupInputsFromJSON(context, node_tree, geom_mod,
69-
js_input_data, be_proj_paths, be_base_stuff.be_type)
70-
# geom_mod.show_viewport = True
71-
72-
# Set the GN Object Active and Selected
73-
bpy.ops.object.select_all(action='DESELECT')
74-
process_gn_obj.select_set(True)
75-
context.view_layer.objects.active = process_gn_obj
76-
77-
process_gn_obj.data.update()
78-
79-
# Save Node Outputs
80-
BEUtils.SaveBlenderOutputs(context, [process_gn_obj], be_proj_paths, be_base_stuff.be_type, True)
81-
82-
# If SV
83-
elif node_tree.bl_idname == BEUtils.TYPE_SV:
84-
# node_tree = node_tree.evaluated_get(context.evaluated_depsgraph_get())
85-
86-
# Setup inputs
87-
BEUtils.SetupInputsFromJSON(context, node_tree, None,
88-
js_input_data, be_proj_paths, be_base_stuff.be_type)
89-
90-
# Update All Nodes
91-
# node_tree.update()
92-
context.view_layer.update()
93-
node_tree.process_ani(True, False)
94-
95-
# Save Node Outputs
96-
BEUtils.SaveBlenderOutputs(context, BEUtils.GetSVOutputObjects(node_tree),
97-
be_proj_paths, be_base_stuff.be_type, False)
98-
99-
else:
100-
print("Nodes were not Loaded! Please check Paths and NodeTree Name!")
101-
return False
48+
if be_base_stuff.run_type == "UpdateNodes":
49+
GetBlenderInputs(be_base_stuff, node_tree)
10250
else:
103-
print("JSON Object is Empty: " + beInputs_path)
104-
return False
51+
RunNodes(context, be_proj_paths, node_tree, process_gn_obj, geom_mod, be_base_stuff)
10552

10653
return True
10754

@@ -110,9 +57,81 @@ def MainWork():
11057
return False
11158

11259

60+
def GetBlenderInputs(be_base_stuff: BEUtils.BEBaseStuff, node_tree):
61+
# ORIGINAL STUFF
62+
# Get GN Data
63+
js_output_data = {}
64+
65+
if node_tree.bl_idname == BEUtils.TYPE_SV:
66+
gn_inputs_data = BEUtils.GetSVInputsData(node_tree)
67+
else:
68+
gn_inputs_data = BEUtils.GetGNInputsData(node_tree)
69+
70+
js_output_data['Inputs'] = gn_inputs_data
71+
72+
# If No JSON File
73+
gn_js_path = be_base_stuff.blendfolder + be_base_stuff.blendfile_name + '_' + be_base_stuff.node_sys_name + '.json'
74+
BEUtils.SaveJSON(gn_js_path, js_output_data)
75+
76+
77+
def RunNodes(context, be_proj_paths, node_tree, process_gn_obj, geom_mod, be_base_stuff):
78+
# GET BLENDER INPUTS
79+
beInputs_path = be_proj_paths.be_tmp_folder + "BEngineInputs.json"
80+
js_input_data = BEUtils.LoadJSON(beInputs_path)
81+
82+
if js_input_data:
83+
# If GN
84+
if node_tree.bl_idname == BEUtils.TYPE_GN and process_gn_obj:
85+
# Set Transform
86+
process_gn_obj.location = js_input_data["Pos"]
87+
BEUtils.SetRotationFromJSON(process_gn_obj, js_input_data["Rot"], be_base_stuff.be_type)
88+
process_gn_obj.scale = js_input_data["Scale"]
89+
90+
# Setup inputs
91+
BEUtils.SetupInputsFromJSON(context, node_tree, geom_mod,
92+
js_input_data, be_proj_paths, be_base_stuff.be_type)
93+
# geom_mod.show_viewport = True
94+
95+
# Set the GN Object Active and Selected
96+
bpy.ops.object.select_all(action='DESELECT')
97+
process_gn_obj.select_set(True)
98+
context.view_layer.objects.active = process_gn_obj
99+
100+
process_gn_obj.data.update()
101+
102+
# Save Node Outputs
103+
BEUtils.SaveBlenderOutputs(context, [process_gn_obj], be_proj_paths, be_base_stuff.be_type, True)
104+
105+
# If SV
106+
elif node_tree.bl_idname == BEUtils.TYPE_SV:
107+
# node_tree = node_tree.evaluated_get(context.evaluated_depsgraph_get())
108+
109+
# Setup inputs
110+
BEUtils.SetupInputsFromJSON(context, node_tree, None,
111+
js_input_data, be_proj_paths, be_base_stuff.be_type)
112+
113+
# Update All Nodes
114+
# node_tree.update()
115+
context.view_layer.update()
116+
node_tree.process_ani(True, False)
117+
118+
# Save Node Outputs
119+
BEUtils.SaveBlenderOutputs(context, BEUtils.GetSVOutputObjects(node_tree),
120+
be_proj_paths, be_base_stuff.be_type, False)
121+
122+
else:
123+
print("Nodes were not Loaded! Please check Paths and NodeTree Name!")
124+
return False
125+
else:
126+
print("JSON Object is Empty: " + beInputs_path)
127+
return False
128+
129+
return True
130+
131+
113132
# start = time.time()
114133

115-
is_done = MainWork()
134+
is_done = Run()
116135

117136
# end = time.time()
118137
# print(end - start)

BEngine-Py/Utils/BEUtils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,13 @@ def __init__(self, be_paths: dict):
8888
self.blendfolder = ""
8989
self.node_sys_name = ""
9090

91-
# if arg.startswith('BLENDFILE='):
92-
self.blendfile = be_paths["BLENDFILE"]
91+
self.blendfile = be_paths["BlendFile"]
9392

94-
# elif arg.startswith('BLENDFOLDER='):
95-
self.blendfolder = be_paths["BLENDFOLDER"]
93+
self.blendfolder = be_paths["BlendFolder"]
9694
if not self.blendfolder.endswith('/'):
9795
self.blendfolder = self.blendfolder + "/"
9896

99-
# elif arg.startswith('NODESYSNAME='):
100-
self.node_sys_name = be_paths["NODESYSNAME"]
97+
self.node_sys_name = be_paths["NodeSysName"]
10198

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

111108
self.be_type = be_paths["BEngineType"]
112109

110+
self.run_type = be_paths["RunNodesType"]
111+
113112
# # Networking
114113
# self.RunBlenderType = be_paths["RunBlenderType"]
115114
# self.Host = be_paths["Host"]

0 commit comments

Comments
 (0)