-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathui.py
365 lines (295 loc) · 12.1 KB
/
ui.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import os
import bpy
from bpy.types import Context, Panel, UILayout, NodeTree
from .preferences import GRABDOC_PT_presets
from .utils.baker import get_baker_collections
from .utils.generic import get_version, get_user_preferences
from .utils.scene import camera_in_3d_view, is_scene_valid
class GDPanel(Panel):
bl_category = 'GrabDoc'
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = ""
class GRABDOC_PT_grabdoc(GDPanel):
bl_label = "GrabDoc " + get_version()
documentation = "https://github.com/oRazeD/GrabDoc/wiki"
def draw_header_preset(self, _context: Context):
row = self.layout.row()
if is_scene_valid():
GRABDOC_PT_presets.draw_menu(row, text="Presets")
row.operator(
"wm.url_open", text="", icon='HELP'
).url = self.documentation
row.separator(factor=.2)
def draw(self, _context: Context):
if is_scene_valid():
return
row = self.layout.row(align=True)
row.scale_y = 1.5
row.operator("grab_doc.scene_setup",
text="Setup Scene", icon='TOOL_SETTINGS')
class GRABDOC_PT_scene(GDPanel):
bl_label = 'Scene'
bl_parent_id = "GRABDOC_PT_grabdoc"
@classmethod
def poll(cls, _context: Context) -> bool:
return is_scene_valid()
def draw_header(self, _context: Context):
self.layout.label(icon='SCENE_DATA')
def draw_header_preset(self, _context: Context):
row2 = self.layout.row(align=True)
row2.operator("grab_doc.toggle_camera_view",
text="Leave" if camera_in_3d_view() else "View",
icon="OUTLINER_OB_CAMERA")
def draw(self, context: Context):
gd = context.scene.gd
layout = self.layout
row = self.layout.row(align=True)
row.scale_x = row.scale_y = 1.25
row.operator("grab_doc.scene_setup",
text="Rebuild Scene", icon='FILE_REFRESH')
row.operator("grab_doc.scene_cleanup", text="", icon="CANCEL")
box = layout.box()
row = box.row(align=True)
row.scale_y = .9
row.label(text="Camera Restrictions")
row.prop(gd, "coll_selectable", text="", emboss=False,
icon='RESTRICT_SELECT_OFF' if gd.coll_selectable else 'RESTRICT_SELECT_ON')
row.prop(gd, "coll_visible", text="", emboss=False,
icon='RESTRICT_VIEW_OFF' if gd.coll_visible else 'RESTRICT_VIEW_ON')
row.prop(gd, "coll_rendered", text="", emboss=False,
icon='RESTRICT_RENDER_OFF' if gd.coll_rendered else 'RESTRICT_RENDER_ON')
col = layout.column(align=True)
col.use_property_split = True
col.use_property_decorate = False
col.prop(gd, "scale", text='Scaling', expand=True)
row = col.row()
row.prop(gd, "grid_subdivs", text="Grid")
row.separator()
row.prop(gd, "use_grid", text="")
row = col.row()
row.enabled = not gd.preview_state
row.prop(gd, "reference", text='Reference')
row.operator("grab_doc.load_reference", text="", icon='FILE_FOLDER')
class GRABDOC_PT_output(GDPanel):
bl_label = 'Output'
bl_parent_id = "GRABDOC_PT_grabdoc"
@classmethod
def poll(cls, _context: Context) -> bool:
return is_scene_valid()
def draw_header(self, _context: Context):
self.layout.label(icon='OUTPUT')
def draw_header_preset(self, context: Context):
mt_executable = get_user_preferences().mt_executable
if context.scene.gd.engine == 'marmoset' \
and not os.path.exists(mt_executable):
self.layout.enabled = False
self.layout.scale_x = 1
self.layout.operator("grab_doc.baker_export",
text="Export", icon="EXPORT")
def mt_header_layout(self, layout: UILayout):
preferences = get_user_preferences()
mt_executable = preferences.mt_executable
col = layout.column(align=True)
row = col.row()
if not os.path.exists(mt_executable):
row.alignment = 'CENTER'
row.label(text="Marmoset Toolbag Executable Required", icon='INFO')
row = col.row()
row.prop(preferences, 'mt_executable', text="Executable Path")
return
row.prop(preferences, 'mt_executable', text="Executable Path")
row = col.row(align=True)
row.scale_y = 1.25
row.operator("grab_doc.bake_marmoset", text="Bake in Marmoset",
icon="EXPORT").send_type = 'open'
row.operator("grab_doc.bake_marmoset",
text="", icon='FILE_REFRESH').send_type = 'refresh'
def draw(self, context: Context):
gd = context.scene.gd
layout = self.layout
layout.activate_init = True
layout.use_property_split = True
layout.use_property_decorate = False
if gd.engine == 'marmoset':
self.mt_header_layout(layout)
col2 = layout.column()
row = col2.row()
row.prop(gd, 'engine')
row = col2.row()
row.prop(gd, 'filepath', text="Path")
row.operator("grab_doc.open_folder",
text="", icon="FOLDER_REDIRECT")
col2.prop(gd, "filename", text="Name")
row = col2.row()
row.prop(gd, "resolution_x", text='Resolution')
row.prop(gd, "resolution_y", text='')
row.prop(gd, 'resolution_lock', icon_only=True,
icon="LOCKED" if gd.resolution_lock else "UNLOCKED")
row = col2.row()
if gd.engine == "marmoset":
image_format = "mt_format"
else:
image_format = "format"
row.prop(gd, image_format)
row2 = row.row()
if gd.format == "OPEN_EXR":
row2.prop(gd, "exr_depth", expand=True)
elif gd.format != "TARGA" or gd.engine == 'marmoset':
row2.prop(gd, "depth", expand=True)
else:
row2.enabled = False
row2.prop(gd, "tga_depth", expand=True)
if gd.format != "TARGA":
image_settings = bpy.context.scene.render.image_settings
row = col2.row(align=True)
if gd.format == "PNG":
row.prop(gd, "png_compression", text="Compression")
elif gd.format == "OPEN_EXR":
row.prop(image_settings, "exr_codec", text="Codec")
else: # TIFF
row.prop(image_settings, "tiff_codec", text="Codec")
row = col2.row()
row.prop(gd, "filter_width", text="Filtering")
row.separator() # NOTE: Odd spacing without these
row.prop(gd, "use_filtering", text="")
if gd.engine == "marmoset":
row = col2.row(align=True)
row.prop(gd, "mt_samples", text="Samples", expand=True)
col = layout.column(align=True)
col.prop(gd, "use_bake_collection", text="Bake Groups")
col.prop(gd, 'use_pack_maps')
if gd.use_pack_maps:
col.prop(gd, 'remove_original_maps')
if gd.engine == "marmoset":
col.prop(gd, 'mt_auto_bake', text='Bake on Import')
row = col.row()
row.enabled = gd.mt_auto_bake
row.prop(gd, 'mt_auto_close', text='Close after Baking')
class GRABDOC_PT_bake_maps(GDPanel):
bl_label = 'Bake Maps'
bl_parent_id = "GRABDOC_PT_grabdoc"
@classmethod
def poll(cls, _context: Context) -> bool:
return is_scene_valid()
def draw_header(self, _context: Context):
self.layout.label(icon='SHADING_RENDERED')
def draw_header_preset(self, _context: Context):
self.layout.operator("grab_doc.baker_visibility",
emboss=False, text="", icon="SETTINGS")
def draw(self, context: Context):
if not context.scene.gd.preview_state:
return
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
row.alert = True
row.scale_y = 1.5
row.operator("grab_doc.baker_preview_exit", icon="CANCEL")
row = col.row(align=True)
row.scale_y = 1.1
gd = context.scene.gd
baker = getattr(gd, gd.preview_map_type)[gd.preview_index]
row.operator("grab_doc.baker_export_preview",
text=f"Export {baker.NAME}", icon="EXPORT")
baker.draw(context, layout)
class GRABDOC_PT_pack_maps(GDPanel):
bl_label = 'Pack Maps'
bl_parent_id = "GRABDOC_PT_grabdoc"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context: Context) -> bool:
if context.scene.gd.preview_state:
return False
return is_scene_valid()
def draw_header(self, _context: Context):
self.layout.label(icon='RENDERLAYERS')
def draw_header_preset(self, _context: Context):
self.layout.scale_x = .9
self.layout.operator("grab_doc.baker_pack")
def draw(self, context: Context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
gd = context.scene.gd
col = layout.column(align=True)
col.prop(gd, 'channel_r')
col.prop(gd, 'channel_g')
col.prop(gd, 'channel_b')
col.prop(gd, 'channel_a')
col.prop(gd, 'pack_name', text="Suffix")
class BakerPanel(GDPanel):
bl_parent_id = "GRABDOC_PT_bake_maps"
bl_options = {'DEFAULT_CLOSED', 'HEADER_LAYOUT_EXPAND'}
baker = None
@classmethod
def poll(cls, context: Context) -> bool:
if cls.baker is None:
return False
return not context.scene.gd.preview_state and cls.baker.visibility
def draw_header(self, context: Context):
row = self.layout.row(align=True)
baker_name = self.baker.NAME
if self.baker.ID == 'custom':
baker_name = self.baker.suffix.capitalize()
index = self.baker.index
if index > 0 and not self.baker.ID == 'custom':
baker_name = f"{self.baker.NAME} {index+1}"
text = f"{baker_name} Preview".replace("_", " ")
row2 = row.row(align=True)
if self.baker.ID == 'custom' \
and not isinstance(self.baker.node_tree, NodeTree):
row2.enabled = False
row2.separator(factor=.5)
row2.prop(self.baker, 'enabled', text="")
preview = row2.operator("grab_doc.baker_preview", text=text)
preview.map_type = self.baker.ID
preview.baker_index = self.baker.index
row2.operator("grab_doc.baker_export_single",
text="", icon='RENDER_STILL').map_type = self.baker.ID
if self.baker == getattr(context.scene.gd, self.baker.ID)[0]:
row.operator("grab_doc.baker_add",
text="", icon='ADD').map_type = self.baker.ID
return
remove = row.operator("grab_doc.baker_remove", text="", icon='TRASH')
remove.map_type = self.baker.ID
remove.baker_index = self.baker.index
def draw(self, context: Context):
self.baker.draw(context, self.layout)
################################################
# REGISTRATION
################################################
def create_baker_panels():
"""Creates panels for every item in the baker
`CollectionProperty`s utilizing dynamic subclassing."""
baker_classes = []
for baker_prop in get_baker_collections():
for baker in baker_prop:
if baker.index == -1:
baker.__init__() # pylint: disable=C2801
class_name = f"GRABDOC_PT_{baker.ID}_{baker.index}"
panel_cls = type(class_name, (BakerPanel,), {})
panel_cls.baker = baker
baker_classes.append(panel_cls)
return baker_classes
def register_baker_panels():
for cls in BakerPanel.__subclasses__():
try:
bpy.utils.unregister_class(cls)
except RuntimeError:
continue
for cls in create_baker_panels():
bpy.utils.register_class(cls)
classes = [
GRABDOC_PT_grabdoc,
GRABDOC_PT_scene,
GRABDOC_PT_output,
GRABDOC_PT_bake_maps,
GRABDOC_PT_pack_maps
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)