-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
204 lines (151 loc) · 6.24 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import bpy
from bpy.types import Menu, Operator
from bpy_extras.io_utils import ImportHelper
def find_missing_files(filepath):
bpy.ops.file.find_missing_files(directory=filepath)
return {'FINISHED'}
bl_info = {
"name": "Sollumz Pie Menus",
"author": "ooknumber13",
"version": (0, 0, 3),
"description": "Pie menus for Sollumz",
"blender": (2, 93, 0),
"categeory": "3D view"
}
class OokSollumzPie(Menu):
bl_idname = "OOK_MT_sollumz_pie"
bl_label = "Sollumz Pie"
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
pie.operator("ook.autoconvertmats",
text="Convert Material", icon='NODE_MATERIAL')
pie.operator("ook.addobjasmloentity",
text="Add Objects To Room", icon='OBJECT_DATA')
pie.operator("ook.applyselectedflagpreset",
text="Apply Flag Preset", icon='ALIGN_TOP')
pie.operator("ook.drawable", text="Create Drawable", icon='CUBE')
pie.operator("ook.findmissingtextures",
text="Find Missing Textures", icon='MATERIAL')
pie.operator("ook.importxml", text="Import XML", icon='DUPLICATE')
class PieConvertToDrawable(Operator):
"""Convert selected object(s) to drawable(s)"""
bl_idname = "ook.drawable"
bl_label = "create drawable"
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
for obj in context.selected_objects:
if obj.type == "MESH":
bpy.ops.sollumz.createdrawable()
self.report({'INFO'}, 'Created Sollumz Drawable(s)')
else:
self.report({'WARNING'}, 'Object type is not a mesh')
return {"FINISHED"}
class PieAutoConvertMaterial(Operator):
"""Autoconvert materials from selected object(s)"""
bl_idname = "ook.autoconvertmats"
bl_label = "convert material"
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
for obj in context.selected_objects:
if len(obj.data.materials) > 0:
bpy.ops.sollumz.autoconvertmaterial()
self.report({'INFO'}, 'Converted to sollumz Material')
else:
self.report({'WARNING'}, 'Object has no materials')
return {"FINISHED"}
class PieAddObjAsMloentity(Operator):
"""Add selected object(s) as MLO Entity to selected room"""
bl_idname = "ook.addobjasmloentity"
bl_label = "add objects to room"
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
# Check if there are any YTYP's in scene
if len(context.scene.ytyps) > 0:
selectedYtyp = context.scene.ytyp_index
# Add object(s) as Sollumz MLO Entity
for obj in context.selected_objects:
if obj.sollum_type == 'sollumz_drawable' or obj.type == "MESH":
if len(context.scene.ytyps[selectedYtyp].archetypes) > 0:
selectedArchetype = context.scene.ytyps[selectedYtyp].archetype_index
if context.scene.ytyps[selectedYtyp].archetypes[selectedArchetype].type == 'sollumz_archetype_mlo':
if len(context.scene.ytyps[selectedYtyp].archetypes[selectedArchetype].rooms) > 0:
bpy.ops.sollumz.addobjasmloentity()
self.report(
{'INFO'}, 'Added selected object(s) to selected room')
else:
self.report({'WARNING'}, 'MLO has no Rooms')
else:
self.report(
{'WARNING'}, 'Selected Archetype type is incorrect, must be: MLO')
else:
self.report(
{'WARNING'}, 'Selected YTYP has no Archetypes')
else:
self.report({'WARNING'}, 'Selected object isnt a mesh')
else:
self.report(
{'WARNING'}, 'No YTYPs found, create and select a YTYP first.')
return {"FINISHED"}
class PieApplySelectedFlagPreset(Operator):
"""Apply selected collision flag preset to selected object(s)"""
bl_idname = "ook.applyselectedflagpreset"
bl_label = "apply flag preset"
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
for obj in context.selected_objects:
if obj.sollum_type == 'sollumz_bound_geometrybvh':
bpy.ops.sollumz.load_flag_preset()
self.report({'INFO'}, 'Applied selected flag preset')
else:
self.report({'WARNING'}, 'Bound GeometryBVH is not selected')
return {"FINISHED"}
class PieFindMissingTextures(Operator, ImportHelper):
"""Opens find missing textures dialog"""
bl_idname = "ook.findmissingtextures"
bl_label = "Find Missing Textures"
# ImportHelper mixin class uses this
filename_ext = ".dds"
@classmethod
def poll(cls, context):
return context.object is not None
def execute(self, context):
return find_missing_files(self.filepath)
addon_keymaps = []
OokClasses = [
OokSollumzPie,
PieConvertToDrawable,
PieAutoConvertMaterial,
PieAddObjAsMloentity,
PieApplySelectedFlagPreset,
PieFindMissingTextures]
def register():
for cls in OokClasses:
bpy.utils.register_class(cls)
# Assigns default keybinding
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
kmi = km.keymap_items.new(
"wm.call_menu_pie", type='V', value='PRESS', shift=False)
kmi.properties.name = "OOK_MT_sollumz_pie"
addon_keymaps.append((km, kmi))
def unregister():
# default keybinding
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
for cls in reversed(OokClasses):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
bpy.ops.wm.call_menu_pie(name="OOK_MT_sollumz_pie")