-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcleanup_lod_3d_data.py
146 lines (113 loc) · 4.62 KB
/
cleanup_lod_3d_data.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
#
# <pep8 compliant>
# 21615171614242537
import argparse
import os
import site
import sys
import bpy
CONSTANTS_FOLDER = "constants"
UTILS_FOLDER = "utils"
SCRIPT_FOLDER = "scripts"
# Check if script is executed in Blender and get absolute path of current folder
if bpy.context.space_data is not None:
sources_path = os.path.dirname(bpy.context.space_data.text.filepath)
else:
sources_path = os.path.dirname(os.path.abspath(__file__))
# Get scripts folder and add it to the search path for modules
os.chdir(sources_path)
sys.path.append(site.USER_SITE)
if sources_path not in sys.path:
sys.path.append(sources_path)
# Get scripts folder and add it to the search path for modules
cwd = os.path.join(sources_path, CONSTANTS_FOLDER)
if cwd not in sys.path:
sys.path.append(cwd)
# Get scripts folder and add it to the search path for modules
cwd = os.path.join(sources_path, UTILS_FOLDER)
if cwd not in sys.path:
sys.path.append(cwd)
# Get scripts folder and add it to the search path for modules
cwd = os.path.join(sources_path, SCRIPT_FOLDER)
if cwd not in sys.path:
sys.path.append(cwd)
from utils import *
from blender import clean_scene
from msfs_project import MsfsLod, PROCESS_TYPE
# clear and open the system console
# open_console()
try:
# get the args passed to blender after "--", all of which are ignored by
# blender so scripts may receive their own arguments
argv = sys.argv
if "--" not in argv:
argv = [] # as if no args are passed
else:
argv = argv[argv.index("--") + 1:] # get all args after "--"
# When --help or no args are given, print this help
usage_text = (
"Run blender in background mode with this script:"
" blender --background --python " + __file__ + " -- [options]"
)
parser = argparse.ArgumentParser(description=usage_text)
parser.add_argument(
"-f", "--folder", dest="folder", type=str, required=True,
help="folder of the original MsfsLod model file",
)
parser.add_argument(
"-of", "--output_folder", dest="output_folder", type=str, required=True,
help="folder of the modified MsfsLod model file",
)
parser.add_argument(
"-m", "--model_file", dest="model_file", type=str, required=True,
help="name of the gltf model file",
)
parser.add_argument(
"-p", "--positioning_file_path", dest="positioning_file_path", type=str, required=True,
help="path of the positioning mask file",
)
parser.add_argument(
"-msk", "--mask_file_path", dest="mask_file_path", type=str, required=True,
help="path of the exclusion mask file",
)
parser.add_argument(
"-dbg", "--debug", dest="debug", type=str, required=False,
help="Debug the height data in blender",
)
args = parser.parse_args(argv)
if not argv:
raise ScriptError("Error: arguments not given, aborting.")
if not args.folder:
raise ScriptError("Error: --folder=\"some string\" argument not given, aborting.")
if not args.output_folder:
raise ScriptError("Error: --output_folder=\"some string\" argument not given, aborting.")
if not args.model_file:
raise ScriptError("Error: --model_file=\"some string\" argument not given, aborting.")
if not args.positioning_file_path:
raise ScriptError("Error: --positioning_file_path=\"some string\" argument not given, aborting.")
if not args.mask_file_path:
raise ScriptError("Error: --mask_file_path=\"some string\" argument not given, aborting.")
clean_scene()
if args.debug:
debug = json.loads(args.debug.lower())
else:
debug = False
lod = MsfsLod(os.path.splitext(args.model_file)[0][-2:], 0, args.folder, args.model_file)
lod.process_3d_data(args.positioning_file_path, args.mask_file_path, args.output_folder, process_type=PROCESS_TYPE.cleanup_3d_data, debug=debug)
except:
pass