forked from konmast3r/Up3date
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaddon.py
More file actions
171 lines (133 loc) · 4.82 KB
/
Copy pathaddon.py
File metadata and controls
171 lines (133 loc) · 4.82 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""Blender-dependent implementation of the Up3date add-on."""
import bpy
from bpy.props import BoolProperty, EnumProperty, IntProperty, StringProperty
from bpy.types import Operator
from bpy_extras.io_utils import ExportHelper, ImportHelper
from .blender import operators, properties, ui
from .blender.blender_types import BlenderContext, Menu
from .blender.exporter import CityJSONExporter
from .blender.importer import CityJSONImporter
class ImportCityJSON(Operator, ImportHelper):
"Load a CityJSON file"
bl_idname = "cityjson.import_file" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Import CityJSON"
# ImportHelper mixin class uses this
filename_ext = ".json"
filter_glob: StringProperty(
default="*.json",
options={"HIDDEN"},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
material_type: EnumProperty(
name="Materials' type",
items=(
(
"SURFACES",
"Surfaces",
"Creates materials based on semantic surface types",
),
(
"CITY_OBJECTS",
"City Objects",
"Creates materials based on the type of city object",
),
),
description=("Create materials based on city object or semantic surfaces"),
)
reuse_materials: BoolProperty(
name="Reuse materials",
description="Use common materials according to surface type",
default=True,
)
clean_scene: BoolProperty(
name="Clean scene",
description="Remove existing objects from the scene before importing",
default=True,
)
def execute(self, context: BlenderContext) -> set[str]:
"""Executes the import process"""
parser = CityJSONImporter(
self.filepath,
material_type=self.material_type,
reuse_materials=self.reuse_materials,
clear_scene=self.clean_scene,
)
return parser.execute()
class ExportCityJSON(Operator, ExportHelper):
"Export scene as a CityJSON file"
bl_idname = "cityjson.export_file"
bl_label = "Export CityJSON"
# ExportHelper mixin class uses this
filename_ext = ".json"
filter_glob: StringProperty(
default="*.json",
options={"HIDDEN"},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
check_for_duplicates: BoolProperty(
name="Remove vertex duplicates",
default=True,
)
precision: IntProperty(
name="Precision",
default=5,
description="Decimals to check for vertex duplicates",
min=0,
max=12,
)
# single_lod_switch: BoolProperty(
# name="Export single LoD",
# description="Enable to export only a single LoD",
# default=False,
# )
# export_single_lod: EnumProperty(
# name="Select LoD :",
# items=(('LoD0', "LoD 0",
# "Export only LoD 0"),
# ('LoD1', "LoD 1",
# "Export only LoD 1"),
# ('LoD2', "LoD 2",
# "Export only LoD 2"),
# ),
# description=(
# "Select which LoD should be exported"
# )
# )
def execute(self, context: BlenderContext) -> set[str]:
exporter = CityJSONExporter(
self.filepath,
check_for_duplicates=self.check_for_duplicates,
precision=self.precision,
)
return exporter.execute()
classes = (
ImportCityJSON,
ExportCityJSON,
properties.Up3dateCityJSONfyProperties,
operators.PrepareCityJSONObjectsOperator,
ui.Up3datePTgui,
)
def menu_func_export(self: Menu, context: BlenderContext) -> None:
"""Defines the menu item for CityJSON import"""
self.layout.operator(ExportCityJSON.bl_idname, text="CityJSON (.json)")
def menu_func_import(self: Menu, context: BlenderContext) -> None:
"""Defines the menu item for CityJSON export"""
self.layout.operator(ImportCityJSON.bl_idname, text="CityJSON (.json)")
def register() -> None:
"""Registers the classes and functions of the addon"""
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.cityjsonfy_properties = bpy.props.PointerProperty(
type=properties.Up3dateCityJSONfyProperties
)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister() -> None:
"""Unregisters the classes and functions of the addon"""
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.cityjsonfy_properties
if __name__ == "__main__":
register()