-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathui.py
More file actions
349 lines (288 loc) · 11.8 KB
/
ui.py
File metadata and controls
349 lines (288 loc) · 11.8 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
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
import os
import bpy
from bpy.types import Context, Panel, UILayout
from .preferences import GRABDOC_PT_presets
from .utils.baker import get_baker_by_index, 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()
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("grabdoc.scene_setup", 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):
GRABDOC_PT_presets.draw_menu(self.layout, text="Presets")
def draw(self, context: Context):
gd = context.scene.gd
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
row.scale_x = row.scale_y = 1.25
row.operator("grabdoc.refresh_setup", icon='FILE_REFRESH')
row.operator("grabdoc.scene_cleanup", text="", icon="CANCEL")
box = col.box()
row = box.row(align=True)
row.scale_y = .9
row.label(text="Camera")
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')
camera_in_view = camera_in_3d_view()
row.operator("grabdoc.toggle_camera_view",
text="Exit" if camera_in_view else "View",
icon="OUTLINER_OB_CAMERA" if camera_in_view else "OUTLINER_DATA_CAMERA")
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("grabdoc.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("grabdoc.baker_export",
text="Export", icon="EXPORT")
def mt_header_layout(self, layout: UILayout):
col = layout.column(align=True)
row = col.row()
preferences = get_user_preferences()
if not os.path.exists(preferences.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("grabdoc.bake_marmoset", text="Bake in Marmoset",
icon="EXPORT").send_type = 'open'
row.operator("grabdoc.bake_marmoset",
text="", icon='FILE_REFRESH').send_type = 'refresh'
def draw(self, context: Context):
layout = self.layout
layout.activate_init = True
layout.use_property_split = True
layout.use_property_decorate = False
gd = context.scene.gd
engine_is_marmoset = gd.engine == "marmoset"
if engine_is_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("grabdoc.open_folder", text="", icon="FOLDER_REDIRECT")
col2.prop(gd, 'filename', text="Name")
row = col2.row(align=True)
row.prop(gd, 'resolution_x', text="Resolution")
row.prop(gd, 'resolution_y', text="")
row = col2.row(align=True)
row.prop(gd, 'resolution_lock', icon_only=True, text=" ",
icon="LOCKED" if gd.resolution_lock else "UNLOCKED")
row.operator("grabdoc.increase_resolution", text="", icon="ADD")
row.operator("grabdoc.decrease_resolution", text="", icon="REMOVE")
row = col2.row()
row.prop(gd, 'mt_format' if engine_is_marmoset else 'format')
row2 = row.row()
if gd.format == "OPEN_EXR":
row2.prop(gd, 'exr_depth', expand=True)
elif gd.format != "TARGA" or engine_is_marmoset:
row2.prop(gd, 'depth', expand=True)
else:
row2.enabled = False
row2.prop(gd, 'tga_depth', expand=True)
if gd.format != "TARGA":
image_settings = 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:
row.prop(image_settings, 'tiff_codec', text="Codec")
row = col2.row()
row.prop(gd, 'filter_width')
row.separator()
row.prop(gd, 'use_filtering', text="")
if engine_is_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')
col.prop(gd, 'use_pack_maps')
if gd.use_pack_maps:
col.prop(gd, 'remove_original_maps')
col.prop(gd, 'use_transparent')
if engine_is_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 = '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("grabdoc.baker_visibility",
emboss=False, text="", icon="HIDE_OFF")
def draw(self, context: Context):
gd = context.scene.gd
if not 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("grabdoc.baker_preview_exit", icon="CANCEL")
row = col.row(align=True)
row.scale_y = 1.1
baker_prop = getattr(gd, gd.preview_map_type)
baker = get_baker_by_index(baker_prop, gd.preview_index)
row.operator(
"grabdoc.baker_export_preview",
text=f"Export {baker.NAME}", icon="EXPORT"
).baker_index = baker.index
baker.draw(context, layout)
class GRABDOC_PT_pack_maps(GDPanel):
bl_label = 'Pack'
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(self, context: Context):
col = self.layout.column(align=True)
col.use_property_split = True
col.use_property_decorate = False
gd = context.scene.gd
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 GRABDOC_PT_Baker(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 not cls.baker:
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)
row2 = row.row(align=True)
gd = context.scene.gd
if gd.engine == 'marmoset' \
and (len(self.baker.REQUIRED_SOCKETS) > 0 or self.baker.ID == 'custom'):
row2.active = False
row2.separator(factor=.5)
row2.prop(self.baker, 'enabled', text="")
text = f"{self.baker.get_display_name()} Preview"
preview = row2.operator("grabdoc.baker_preview", text=text)
preview.map_type = self.baker.ID
preview.baker_index = self.baker.index
row2.operator("grabdoc.baker_export_single",
text="", icon='RENDER_STILL').map_type = self.baker.ID
if self.baker == getattr(gd, self.baker.ID)[0]:
row.operator("grabdoc.baker_add",
text="", icon='ADD').map_type = self.baker.ID
return
remove = row.operator("grabdoc.baker_remove", text="", icon='TRASH')
remove.map_type = self.baker.ID
remove.baker_index = self.baker.index
def draw(self, context: Context):
baker = getattr(self, 'baker', None)
if baker is not None:
baker.draw(context, self.layout)
################################################
# REGISTRATION
################################################
def register_bakers():
"""Unregister and re-register all bakers and their respective panels."""
for cls in GRABDOC_PT_Baker.__subclasses__():
try:
bpy.utils.unregister_class(cls)
except RuntimeError:
continue
for cls in subclass_baker_panels():
bpy.utils.register_class(cls)
def subclass_baker_panels():
"""Creates panels for every item in the baker
`CollectionProperty`s via dynamic subclassing."""
baker_classes = []
for baker_prop in get_baker_collections():
for baker in baker_prop:
baker.initialize()
class_name = f"GRABDOC_PT_{baker.ID}_{baker.index}"
panel_cls = type(class_name, (GRABDOC_PT_Baker,), {})
panel_cls.baker = baker
baker_classes.append(panel_cls)
return baker_classes
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)