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)
0 commit comments