-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
153 lines (111 loc) · 3.98 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
bl_info = {
"name" : "Avorion XML Format",
"author" : "Janick Gerstenberger",
"description": "Import Avorion XML",
"blender" : (2, 90, 0),
"version" : (0, 0, 1),
"location" : "File > Import-Export",
"warning" : "",
"category" : "Import-Export"
}
if "bpy" in locals():
import importlib
if "import_avorion_xml" in locals():
importlib.reload(import_avorion_xml)
if "avorion_utils" in locals():
importlib.reload(avorion_utils)
import bpy
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
from bpy.types import Operator, Panel
from bpy_extras.io_utils import orientation_helper, path_reference_mode, axis_conversion
@orientation_helper(axis_forward='-Z', axis_up='Y')
class ImportAvorionXML(Operator):
bl_idname = "avorion.import_xml"
bl_label = "Import Avorion XML"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".xml"
filter_glob: StringProperty(
default="*.xml",
options={'HIDDEN'}
)
filepath: StringProperty(
name="File Path",
description="Filepath used for importing the file."
"(WARNING! disables turret rigging.)",
maxlen=1024,
subtype='FILE_PATH'
)
seperate_blocks: BoolProperty(
name="Seperate Blocks",
description="Seperate Blocks into indiviual Meshes",
default=False
)
def draw(self, context):
pass
def execute(self, context):
from . import import_avorion_xml
keywords = self.as_keywords(ignore=("axis_forward", "axis_up", "filter_glob"))
global_matrix = axis_conversion(from_forward=self.axis_forward, from_up=self.axis_up)
keywords["global_matrix"] = global_matrix.to_4x4()
return import_avorion_xml.load(context, **keywords)
def invoke(self, context, _event):
from pathlib import Path
from . appdirs import user_data_dir
path = Path(user_data_dir('Avorion', appauthor=False, roaming= True))
path /= "ships"
if path.exists() and path.is_dir():
self.filepath = str(path) + "//"
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
class AVORION_PT_import_transform(Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Transform"
bl_parent_id = "FILE_PT_operator"
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "AVORION_OT_import_xml"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator, "axis_forward")
layout.prop(operator, "axis_up")
class AVORION_PT_import_geometry(Panel):
bl_space_type = 'FILE_BROWSER'
bl_region_type = 'TOOL_PROPS'
bl_label = "Geometry"
bl_parent_id = "FILE_PT_operator"
@classmethod
def poll(cls, context):
sfile = context.space_data
operator = sfile.active_operator
return operator.bl_idname == "AVORION_OT_import_xml"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sfile = context.space_data
operator = sfile.active_operator
layout.prop(operator, "seperate_blocks")
def menu_func_import(self, context):
self.layout.operator(ImportAvorionXML.bl_idname, text="Avorion (.xml)")
classes = (
ImportAvorionXML,
AVORION_PT_import_transform,
AVORION_PT_import_geometry
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()