forked from konmast3r/Up3date
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path__init__.py
163 lines (133 loc) · 4.93 KB
/
__init__.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""Main module of the CityJSON Blender addon"""
import json
import time
import bpy
from bpy.props import BoolProperty, EnumProperty, StringProperty, IntProperty
from bpy.types import Operator
from bpy_extras.io_utils import ExportHelper, ImportHelper
from .core.objects import CityJSONParser, CityJSONExporter
from .core import ui, prop, operator
bl_info = {
"name": "Up3date",
"author": "Konstantinos Mastorakis",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "File > Import > CityJSON (.json) || File > Export > CityJSON (.json)",
"description": "Visualize, edit and export 3D City Models encoded in CityJSON format",
"warning": "",
"wiki_url": "",
"category": "Import-Export",
}
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):
"""Executes the import process"""
parser = CityJSONParser(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):
exporter = CityJSONExporter(self.filepath,
check_for_duplicates=self.check_for_duplicates,
precision=self.precision)
return exporter.execute()
classes = (
ImportCityJSON,
ExportCityJSON,
prop.UP3DATE_CityjsonfyProperties,
operator.UP3DATECityjsonfy,
ui.UP3DATE_PT_gui
)
def menu_func_export(self, context):
"""Defines the menu item for CityJSON import"""
self.layout.operator(ExportCityJSON.bl_idname, text="CityJSON (.json)")
def menu_func_import(self, context):
"""Defines the menu item for CityJSON export"""
self.layout.operator(ImportCityJSON.bl_idname, text="CityJSON (.json)")
def register():
"""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=prop.UP3DATE_CityjsonfyProperties)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
"""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()