|
4 | 4 | import os |
5 | 5 |
|
6 | 6 | import json |
7 | | -# from json.decoder import JSONDecodeError |
| 7 | +from json.decoder import JSONDecodeError |
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 |
|
@@ -47,50 +47,86 @@ class SVConstants: |
47 | 47 | SV_OUTPUT_OBJ = "BEObjectsOutput.py" |
48 | 48 |
|
49 | 49 |
|
50 | | -class BEPaths: |
| 50 | +class BEProjectPaths: |
51 | 51 |
|
52 | 52 | def __init__(self): |
53 | | - self.blendfile = "" |
54 | | - self.blendfolder = "" |
55 | | - self.section = "/NodeTree/" |
56 | | - self.node_sys_name = "" |
57 | | - self.be_tmp_folder = "" |
58 | | - self.project_path = "" |
59 | | - self.project_path_2 = "" |
| 53 | + self.be_tmp_folder = None |
| 54 | + self.project_path = None |
| 55 | + self.project_path_2 = None |
| 56 | + |
| 57 | + self.run_blender_Type = None |
| 58 | + self.host = None |
| 59 | + self.port = None |
| 60 | + self.max_package_bytes = None |
60 | 61 |
|
61 | 62 | args = sys.argv |
62 | 63 |
|
63 | 64 | for arg in args: |
64 | | - if arg.startswith('BLENDFILE='): |
65 | | - self.blendfile = arg.replace('BLENDFILE=', '') |
66 | | - |
67 | | - elif arg.startswith('BLENDFOLDER='): |
68 | | - self.blendfolder = arg.replace('BLENDFOLDER=', '') |
69 | | - |
70 | | - if not self.blendfolder.endswith('/'): |
71 | | - self.blendfolder = self.blendfolder + "/" |
72 | | - |
73 | | - elif arg.startswith('NODESYSNAME='): |
74 | | - self.node_sys_name = arg.replace('NODESYSNAME=', '') |
75 | | - |
76 | | - elif arg.startswith('BE_TMP_FOLDER='): |
| 65 | + if arg.startswith('BE_TMP_FOLDER='): |
77 | 66 | self.be_tmp_folder = arg.replace('BE_TMP_FOLDER=', '') |
78 | | - |
79 | 67 | elif arg.startswith('PROJECT_PATH='): |
80 | 68 | self.project_path = arg.replace('PROJECT_PATH=', '') |
81 | | - |
82 | 69 | elif arg.startswith('PROJECT_PATH_2='): |
83 | 70 | self.project_path_2 = arg.replace('PROJECT_PATH_2=', '') |
84 | 71 |
|
| 72 | + # # Networking |
| 73 | + elif arg.startswith('RunBlenderType='): |
| 74 | + self.run_blender_Type = arg.replace('RunBlenderType=', '') |
| 75 | + elif arg.startswith('Host='): |
| 76 | + self.host = arg.replace('Host=', '') |
| 77 | + elif arg.startswith('Port='): |
| 78 | + self.port = int(arg.replace('Port=', '')) |
| 79 | + elif arg.startswith('MaxPackageBytes='): |
| 80 | + self.max_package_bytes = int(arg.replace('MaxPackageBytes=', '')) |
| 81 | + |
| 82 | + |
| 83 | +class BEBaseStuff: |
| 84 | + |
| 85 | + def __init__(self, be_paths: dict): |
| 86 | + self.section = "/NodeTree/" |
| 87 | + self.blendfile = "" |
| 88 | + self.blendfolder = "" |
| 89 | + self.node_sys_name = "" |
| 90 | + |
| 91 | + # if arg.startswith('BLENDFILE='): |
| 92 | + self.blendfile = be_paths["BLENDFILE"] |
| 93 | + |
| 94 | + # elif arg.startswith('BLENDFOLDER='): |
| 95 | + self.blendfolder = be_paths["BLENDFOLDER"] |
| 96 | + if not self.blendfolder.endswith('/'): |
| 97 | + self.blendfolder = self.blendfolder + "/" |
| 98 | + |
| 99 | + # elif arg.startswith('NODESYSNAME='): |
| 100 | + self.node_sys_name = be_paths["NODESYSNAME"] |
| 101 | + |
85 | 102 | # blend file name |
86 | 103 | self.blendfile_basename = os.path.basename(self.blendfile) |
87 | 104 | self.blendfile_name = os.path.splitext(self.blendfile_basename)[0] |
88 | 105 |
|
89 | | - # Load GN |
| 106 | + # Load GN Paths |
90 | 107 | self.filepath = self.blendfile + self.section + self.node_sys_name |
91 | 108 | self.directory = self.blendfile + self.section |
92 | 109 | self.filename = self.node_sys_name |
93 | 110 |
|
| 111 | + self.be_type = be_paths["BEngineType"] |
| 112 | + |
| 113 | + # # Networking |
| 114 | + # self.RunBlenderType = be_paths["RunBlenderType"] |
| 115 | + # self.Host = be_paths["Host"] |
| 116 | + # self.Port = be_paths["Port"] |
| 117 | + # self.MaxPackageBytes = be_paths["MaxPackageBytes"] |
| 118 | + |
| 119 | + |
| 120 | +def LoadJSON(bengineInputs_path: str): |
| 121 | + with open(bengineInputs_path) as js_file: |
| 122 | + try: |
| 123 | + js_input_data = json.load(js_file) |
| 124 | + except JSONDecodeError: |
| 125 | + print("Problem to Open File: " + bengineInputs_path) |
| 126 | + js_input_data = None |
| 127 | + |
| 128 | + return js_input_data |
| 129 | + |
94 | 130 |
|
95 | 131 | def SaveJSON(gn_js_path, js_data): |
96 | 132 | with open(gn_js_path, 'w') as json_file: |
@@ -275,13 +311,13 @@ def GetGNInputsData(node_group): |
275 | 311 | return gn_inputs_data |
276 | 312 |
|
277 | 313 |
|
278 | | -def LoadNodesTreeFromJSON(context, be_paths: BEPaths): |
| 314 | +def LoadNodesTreeFromJSON(context, be_paths: BEProjectPaths, be_base_stuff: BEBaseStuff): |
279 | 315 |
|
280 | | - bpy.ops.wm.link(filepath=be_paths.filepath, filename=be_paths.filename, directory=be_paths.directory, link=False) |
281 | | - # bpy.ops.wm.append(filepath=be_paths.filepath, filename=be_paths.filename, directory=be_paths.directory) |
| 316 | + bpy.ops.wm.link(filepath=be_base_stuff.filepath, filename=be_base_stuff.filename, |
| 317 | + directory=be_base_stuff.directory, link=False) |
282 | 318 |
|
283 | 319 | if (bpy.data.node_groups): |
284 | | - node_tree = bpy.data.node_groups[be_paths.node_sys_name] |
| 320 | + node_tree = bpy.data.node_groups[be_base_stuff.node_sys_name] |
285 | 321 |
|
286 | 322 | process_gn_obj = None |
287 | 323 | geom_mod = None |
@@ -312,7 +348,7 @@ def LoadNodesTreeFromJSON(context, be_paths: BEPaths): |
312 | 348 |
|
313 | 349 |
|
314 | 350 | def SetupInputsFromJSON(context, node_tree, GN_mod, js_input_data, |
315 | | - be_paths: BEPaths, engine_type: str): |
| 351 | + be_paths: BEProjectPaths, engine_type: str): |
316 | 352 |
|
317 | 353 | js_inputs = js_input_data["BEngineInputs"] |
318 | 354 |
|
@@ -795,7 +831,7 @@ def RecordObjectOutputToJSON(inst_dict, the_object, is_instance: bool): |
795 | 831 | cur_inst_data["Mesh"] = MeshToJSONData(true_obj) |
796 | 832 |
|
797 | 833 |
|
798 | | -def SaveBlenderOutputs(context, process_objs: list, be_paths: BEPaths, engine_type: str, is_GN: bool): |
| 834 | +def SaveBlenderOutputs(context, process_objs: list, be_paths: BEProjectPaths, engine_type: str, is_GN: bool): |
799 | 835 |
|
800 | 836 | depsgraph = context.evaluated_depsgraph_get() |
801 | 837 |
|
|
0 commit comments