This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.py
278 lines (217 loc) · 10.2 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
import bpy
class LIGHTMAPBAKER_PT_main():
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Main Tab"
bl_options = {"HEADER_LAYOUT_EXPAND"}
class LIGHTMAPBAKER_PT_title(bpy.types.Panel):
bl_label = "Lightmap Baker"
bl_idname = "LIGHTMAPBAKER_PT_Panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
def draw(self, context):
layout = self.layout
class LightmapBakerMenu(bpy.types.Menu):
bl_idname = "LIGHTMAPBAKER_MT_LightmapBakerMenu"
bl_label = "Lightmap Baker Menu"
def draw(self, context):
layout = self.layout
class LIGHTMAPBAKER_PT_objects(LIGHTMAPBAKER_PT_main, bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Objects"
bl_options = {"HIDE_HEADER"}
def draw(self, context):
layout = self.layout
layout.enabled = not context.scene.lightmap_baker_properties.busy
row = layout.row(align=False)
row.operator("object.add_to_bake_list", text="Add Objects")
row.operator("object.clear_bake_list", text="Clear List")
row = layout.row(align=False)
row.enabled = not context.scene.lightmap_baker_properties.bake_in_progress
row.template_list("LIGHTMAPBAKER_UL_objects_list", "", context.scene, "lightmap_baker_objects",
context.scene.lightmap_baker_properties, "objects_index")
col = row.column(align=True)
col.operator("object.select_all_in_list", text="", icon='RESTRICT_SELECT_OFF')
col.separator()
col.operator("object.clean_all_invalid_objects", icon='BRUSH_DATA', text="")
col.separator()
col.operator("object.toggle_lightmap_preview_diffuse", icon='SHADING_TEXTURE', text="", depress=context.scene.lightmap_baker_properties.preview_diffuse_enabled)
# col.operator("object.toggle_lightmap_preview_diffuse", icon='SHADING_RENDERED', text="", depress=context.scene.lightmap_baker_properties.preview_diffuse_enabled)
col.separator()
col.menu("LIGHTMAPBAKER_MT_preview_context_menu", icon='DOWNARROW_HLT', text="")
class LIGHTMAPBAKER_PT_uv(bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Lightmap UV"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
def draw(self, context):
layout = self.layout
layout.enabled = not context.scene.lightmap_baker_properties.busy
layout.use_property_split = True
layout.use_property_decorate = False
# Add/Delete UVs
col = layout.column(align=True)
col.operator("object.add_lightmap_uv", text="Add Lightmap UVs", icon='ADD')
col.operator("object.delete_lightmap_uv", text="Delete Lightmap UVs", icon='REMOVE')
col.separator()
row = col.row(align=False)
row.prop(context.scene.lightmap_baker_properties, "lightmap_baker_uv_map_name", text="UVMap Name")
row.scale_x = 0.5
row.operator("object.set_lightmap_uv_name", text="Set")
# Switch UV Index
row = layout.row(align=True)
row.prop(context.scene.lightmap_baker_properties, "lightmap_baker_uv_map_index", text="Active UV")
row.scale_x = 0.5
row.operator("object.set_lightmap_uv_index", text="Set")
class LIGHTMAPBAKER_PT_filtering(LIGHTMAPBAKER_PT_main, bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Filtering"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
# Denoise
row = layout.row(align=False)
row.prop(context.scene.lightmap_baker_properties, "use_denoise", text="Denoise")
# Bilateral Blur
row = layout.row(align=False)
row.prop(context.scene.lightmap_baker_properties, "use_bilateral_blur", text="Bilateral Blur")
if context.scene.lightmap_baker_properties.use_bilateral_blur:
col = layout.column()
col.prop(context.scene.lightmap_baker_properties, "bilateral_blur_iterations", text="Iterations")
col.prop(context.scene.lightmap_baker_properties, "bilateral_blur_color_sigma", text="Color Sigma")
col.prop(context.scene.lightmap_baker_properties, "bilateral_blur_space_sigma", text="Space Sigma")
class LIGHTMAPBAKER_PT_settings(LIGHTMAPBAKER_PT_main, bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Settings"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
def draw(self, context):
layout = self.layout
layout.enabled = not context.scene.lightmap_baker_properties.busy
layout.use_property_split = True
layout.use_property_decorate = False
col = layout.column(align=False)
col.prop(context.scene.lightmap_baker_properties, "lightmap_resolution", text="Resolution")
col.prop(context.scene.lightmap_baker_properties, "render_device", text="Device", toggle=True)
col.separator()
col.prop(context.scene.lightmap_baker_properties, "sample_count", text="Sample Count")
col.prop(context.scene.lightmap_baker_properties, "bake_margin", text="Margin")
class LIGHTMAPBAKER_PT_export(LIGHTMAPBAKER_PT_main, bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Export Lightmaps"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
bl_options = {'DEFAULT_CLOSED'}
def draw_header(self, context):
self.layout.enabled = not context.scene.lightmap_baker_properties.busy
self.layout.prop(context.scene.lightmap_baker_properties, "export_enabled", text="")
def draw(self, context):
layout = self.layout
layout.enabled = not context.scene.lightmap_baker_properties.busy
layout.use_property_split = True
layout.use_property_decorate = False
# Export options
row = layout.row(align=True)
if context.scene.lightmap_baker_properties.export_enabled:
row = layout.row(align=True)
row.prop(context.scene.lightmap_baker_properties, "export_path", text="Export Path")
class LIGHTMAPBAKER_PT_bake(LIGHTMAPBAKER_PT_main, bpy.types.Panel):
bl_parent_id = "LIGHTMAPBAKER_PT_Panel"
bl_label = "Bake"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Lightmap Baker'
bl_options = {"HIDE_HEADER"}
def draw(self, context):
layout = self.layout
self.context = context
properties = context.scene.lightmap_baker_properties
# Baking Progress
current_index = properties.objects_index
total_objects = len(context.scene.lightmap_baker_objects)
progress_value = properties.bake_progress
# States
idle = not properties.busy and not progress_value == 1.0
baking = properties.busy and not properties.cancel_bake
aborting = properties.bake_in_progress and properties.cancel_bake
canceled = properties.cancel_bake and not properties.bake_in_progress and properties.busy
completed = progress_value == 1.0
# Bake and Cancel
row = layout.row(align=False)
row.scale_y = 1.5
if idle:
icon='RENDER_STILL'
operator_text = "Bake!"
operator_object = "object.bake_operator"
progress_text = f"({0}/{total_objects} Objects)"
elif baking:
row.alert = True
icon='CANCEL'
operator_text = "Cancel"
operator_object = "object.cancel_bake"
progress_text = f"{progress_value * 100:.0f}% ({current_index}/{total_objects} Objects)"
elif aborting:
row.enabled = False
icon='NONE'
operator_text = "Aborting..."
operator_object = "object.bake_operator"
progress_text = f"{progress_value * 100:.0f}% ({current_index}/{total_objects} Objects)"
elif canceled:
row.enabled = True
icon='RENDER_STILL'
operator_text = "Bake!"
operator_object = "object.bake_operator"
progress_text = "Canceled!"
elif completed:
row.enabled = True
icon='RENDER_STILL'
operator_text = "Bake!"
operator_object = "object.bake_operator"
progress_text = "Completed!"
row.operator(operator_object, text=operator_text, icon=icon, emboss=True)
layout.progress(factor=progress_value, text=progress_text)
# Display elapsed time 00:00.00
layout.label(text=f"Elapsed Time: {format_time(context.scene.lightmap_baker_properties.elapsed_time)}")
class LIGHTMAPBAKER_MT_preview_context_menu(bpy.types.Menu):
bl_label = "Preview Settings"
def draw(self, context):
layout = self.layout
layout.operator("object.remove_lightmap_nodes", text="Remove Lightmap Nodes")
layout.prop(context.scene.lightmap_baker_properties, "automatic_lightmap_preview", text="Automatically Preview Lightmaps", toggle=True)
class LIGHTMAPBAKER_UL_objects_list(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
obj = bpy.data.objects.get(item.objects_list)
if obj:
layout.label(text=obj.name, icon='CUBE')
layout.operator("object.remove_single_from_bake_list", text="", icon='X', emboss=False).index = index # Change here
else:
layout.label(text="Invalid Object", icon='ERROR')
def format_time(seconds):
minutes, seconds = divmod(seconds, 60)
return f"{int(minutes):02d}:{int(seconds):02d}.{int((seconds - int(seconds)) * 100):02d}"
classes = [
LIGHTMAPBAKER_PT_title,
LIGHTMAPBAKER_PT_objects,
LIGHTMAPBAKER_UL_objects_list,
LIGHTMAPBAKER_PT_uv,
LIGHTMAPBAKER_PT_filtering,
LIGHTMAPBAKER_PT_settings,
LIGHTMAPBAKER_PT_export,
LIGHTMAPBAKER_PT_bake,
LightmapBakerMenu,
LIGHTMAPBAKER_MT_preview_context_menu,
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)