-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (35 loc) · 1.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import sys
from os import path
from mesh_union.logger import logger
from mesh_union.tree import Node
from mesh_union.utils import union
def get_metadata(json_file_or_encoded):
try:
if json_file_or_encoded.endswith('.json'): # uses json file
with open(json_file_or_encoded) as f:
return json.load(f)
else:
return json.loads(json_file_or_encoded)
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
logger.error("Error loading json - {}".format(e))
sys.exit(1)
if __name__ == '__main__':
args = sys.argv[1:]
if len(args) != 2:
print(
'First argument should be a json encoded string or a path to a json file.',
'Second argument should be the output path.',
sep = '\n', end = '\n'
)
sys.exit(1)
# first arg is json file or encoded as string
# second arg is the path to the output file
[json_file_or_encoded, output_path] = args
metadata = get_metadata(json_file_or_encoded)
tree = Node.from_json(metadata)
meshes = tree.flatten()
final_mesh = union(meshes)
# final_mesh.show() # used only for visual debugging
final_mesh.export(output_path)
sys.exit(0)