-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathgui.py
384 lines (312 loc) · 14.4 KB
/
gui.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import bpy
import os
from . common import getLightMesh
from . auto_load import force_register
from . import operators
import traceback
@force_register
class LLS_PT_Studio(bpy.types.Panel):
bl_idname = "LLS_PT_studio"
bl_label = "Studio"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
# determine the correct EEVEE engine name based on Blender version
eevee_engine = "BLENDER_EEVEE_NEXT" if bpy.app.version >= (4, 2, 0) else "BLENDER_EEVEE"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT'
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
if not context.scene.LLStudio.initialized: col.operator('scene.create_leomoon_light_studio')
if context.scene.LLStudio.initialized: col.operator('scene.delete_leomoon_light_studio')
col.separator()
col.operator('light_studio.control_panel', icon='MENU_PANEL')
sub = col.row(align=True)
sub.operator('scene.switch_to_renderer', text="Cycles", depress=context.scene.render.engine == 'CYCLES').engine='CYCLES'
sub.operator('scene.switch_to_renderer', text="EEVEE", depress=context.scene.render.engine == self.eevee_engine).engine = self.eevee_engine
@force_register
class LLS_PT_Mode(bpy.types.Panel):
bl_idname = "LLS_PT_mode"
bl_label = "Mode"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
def draw(self, context):
layout = self.layout
scene = context.scene
props = scene.LLStudio
row = layout.row(align=True)
row.prop(props, 'lls_mode', expand=True)
@force_register
class LLS_PT_ProfileList(bpy.types.Panel):
bl_idname = "LLS_PT_profile_list"
bl_label = "Profiles"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
def draw(self, context):
layout = self.layout
scene = context.scene
props = scene.LLStudio
row = layout.row()
col = row.column()
col.prop(props, 'profile_multimode', expand=True)
col.template_list("LLS_UL_ProfileList", "Profile_List", props, "profile_list", props, "profile_list_index", rows=5)
col = row.column(align=True)
col.operator('lls_list.new_profile', icon='ADD', text="")
col.operator('lls_list.delete_profile', icon='REMOVE', text="")
col.operator('lls_list.copy_profile_menu', icon='DUPLICATE', text="")
col.separator()
col.operator('lls_list.move_profile', text='', icon="TRIA_UP").direction = 'UP'
col.operator('lls_list.move_profile', text='', icon="TRIA_DOWN").direction = 'DOWN'
col = layout.column(align=True)
col.operator('lls_list.select_profile_handle')
row = col.row(align=True)
list = props.profile_list
index = props.profile_list_index
if not list:
return
handle = [o for o in bpy.data.objects[list[index].empty_name].children if o.name.startswith("LLS_HANDLE")][0]
if "LLS Child Of" in handle.constraints:
row.prop(handle.constraints["LLS Child Of"], 'target', expand=True, text="Constrain to")
row.operator('lls_list.constraint_toggle_parent_inverse', text="", icon="ORIENTATION_PARENT")
row.operator('lls_list.remove_constraint', text="", icon="X")
else:
row.operator('lls_list.create_profile_constraint')
@force_register
class LLS_PT_Lights(bpy.types.Panel):
bl_idname = "LLS_PT_lights"
bl_label = "Lights"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and len(context.scene.LLStudio.profile_list)
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
props = context.scene.LLStudio
row = layout.row()
col = row.column()
if props.profile_multimode and props.profile_list_index < len(props.profile_list):
col.label(text="Profile: "+props.profile_list[props.profile_list_index].name)
col.template_list("LLS_UL_LightList", "Light_List", props, "light_list", props, "light_list_index", rows=5)
col = row.column(align=True)
col.operator('scene.add_leomoon_studio_light', icon='ADD', text="")
col.operator('scene.delete_leomoon_studio_light', icon='REMOVE', text="").confirm=False
col.operator('lls_list.copy_light', icon='DUPLICATE', text="")
col.separator()
col.operator('lls_list.move_light', text='', icon="TRIA_UP").direction = 'UP'
col.operator('lls_list.move_light', text='', icon="TRIA_DOWN").direction = 'DOWN'
@force_register
class LLS_PT_Selected(bpy.types.Panel):
bl_idname = "LLS_PT_selected"
bl_label = "Selected Light"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
# return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT'
def draw(self, context):
if context.active_object and context.active_object.name.startswith('LLS_LIGHT_'):
layout = self.layout
wm = context.window_manager
col = layout.column(align=True)
# col.operator('lls.light_brush', text="3D Edit", icon='PIVOT_CURSOR')
row = col.row()
# row.prop(context.scene.LLStudio, 'active_light_type', expand=True)
row.prop(context.object.parent.LLStudio, 'type', expand=True)
col.separator()
if context.object.type == 'LIGHT':
row = col.row()
row.prop(context.object.data.LLStudio, 'color')
col.prop(context.object.data.LLStudio, 'color_saturation', slider=True)
col.prop(context.object.data.LLStudio, 'intensity')
elif context.object.type == 'MESH':
box = layout.box()
col = box.column()
col.template_icon_view(wm, "lls_tex_previews", show_labels=True)
col.label(text=os.path.splitext(wm.lls_tex_previews)[0])
layout.separator()
try:
lls_inputs = getLightMesh().active_material.node_tree.nodes["Group"].inputs
for input in lls_inputs[2:]:
if input.type == "RGBA":
layout.prop(input, 'default_value', text=input.name)
col = layout.column(align=True)
else:
col.prop(input, 'default_value', text=input.name)
except:
col.label(text="LLS_light material is not valid.")
if operators.VERBOSE:
traceback.print_exc()
col.prop(getLightMesh().parent, 'location', index=2, text="Distance") #light radius
@force_register
class LLS_PT_Background(bpy.types.Panel):
bl_idname = "LLS_PT_background"
bl_label = "Background"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
def draw(self, context):
layout = self.layout
scene = context.scene
col = layout.column(align=True)
col.operator('scene.set_light_studio_background')
col.prop(scene.render, "film_transparent", text="Transparent Background")
@force_register
class LLS_PT_ProfileImportExport(bpy.types.Panel):
bl_idname = "LLS_PT_profile_import_export"
bl_label = "Import/Export"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
def draw(self, context):
layout = self.layout
scene = context.scene
box = layout.box()
box.label(text="Animation not supported.", icon='ERROR')
col = layout.column(align=True)
col.operator('lls.render_lights_exr')
col.operator('lls_list.export_profiles', text="Export Selected Profile")
col.operator('lls_list.export_profiles', text="Export All Profiles").all=True
col.operator('lls_list.import_profiles', text="Import Profiles")
from . import bl_info
@force_register
class LLS_PT_Misc(bpy.types.Panel):
bl_idname = "LLS_PT_misc"
bl_label = "Misc"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
col.operator('lls.camera_toggle_all_lights', text='Show Lights in Camera').visible_camera = True
col.operator('lls.camera_toggle_all_lights', text='Hide Lights in Camera').visible_camera = False
col.operator('lls.find_missing_textures')
col.operator('lls.open_textures_folder')
col.operator('light_studio.reset_control_panel')
col.operator('lls.lls_keyingset')
if context.scene.keying_sets.active and context.scene.keying_sets.active.bl_idname == "BUILTIN_KSI_LightStudio":
box = layout.box()
box.label(text="Keying Set is active.", icon='CHECKMARK')
class LLSKeyingSet(bpy.types.Operator):
bl_idname = "lls.lls_keyingset"
bl_description = "Activate LightStudio Keying Set to animate lights"
bl_label = "LightStudio Keying Set"
bl_options = {"INTERNAL", "UNDO"}
@classmethod
def poll(self, context):
""" Enable if there's something in the list """
return len(context.scene.LLStudio.profile_list)
def execute(self, context):
context.scene.keying_sets.active = [k for k in context.scene.keying_sets_all if k.bl_idname == "BUILTIN_KSI_LightStudio"][0]
return {"FINISHED"}
@force_register
class LLS_PT_Hotkeys(bpy.types.Panel):
bl_idname = "LLS_PT_hotkeys"
bl_label = "Hotkeys"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "LightStudio"
#bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D' and context.mode == 'OBJECT' and context.scene.LLStudio.initialized
scale_kmi_type = 'X'
rotate_kmi_type = 'X'
def draw(self, context):
layout = self.layout
scene = context.scene
props = scene.LLStudio
box = layout.box()
box.label(text="Move light", icon='MOUSE_LMB')
row = box.row(align=True)
row.label(text="Scale light", icon=self.__class__.scale_kmi_type)
row = box.row(align=True)
row.label(text="Rotate light", icon=self.__class__.rotate_kmi_type)
row = box.row(align=True)
row.label(text="Precision mode", icon='EVENT_SHIFT')
row = box.row(align=True)
box.label(text="Mute light", icon='MOUSE_LMB_DRAG')
box.label(text="Isolate light", icon='MOUSE_RMB')
row = box.row(align=True)
row.label(text="", icon='EVENT_CTRL')
row.label(text="Loop overlapping lights", icon='MOUSE_LMB')
row = box.row(align=True)
box.label(text="(numpad) Icon scale up", icon='ADD')
box.label(text="(numpad) Icon scale down", icon='REMOVE')
import rna_keymap_ui
from . common import get_user_keymap_item
from . import light_brush, deleteOperator
from . operators import modal
class LLSPreferences(bpy.types.AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __package__
def draw(self, context):
layout = self.layout
col = layout.column()
kc = bpy.context.window_manager.keyconfigs.user
keymap_modified = False
for km, kmi in light_brush.addon_keymaps + modal.addon_keymaps:
km = km.active()
col.context_pointer_set("keymap", km)
user_km, user_kmi = get_user_keymap_item(km.name, kmi.idname)
if user_kmi:
rna_keymap_ui.draw_kmi(["ADDON", "USER", "DEFAULT"], kc, user_km, user_kmi, col, 0)
else:
keymap_modified = True
if keymap_modified:
col.operator("preferences.keymap_restore", text="Restore")
col.separator()
box = layout.box()
box.label(text="Internal object.delete operator wrappers to handle deleting of Light Studio objects.")
box.label(text="Wrapper operators copy their counterparts's settings during addon start.")
user_keymap_items = set()
for km, kmi in deleteOperator.addon_keymaps:
km = km.active()
box.context_pointer_set("keymap", km)
user_km, user_kmis = get_user_keymap_item(km.name, kmi.idname, multiple_entries=True)
new_set = set(user_kmis) - user_keymap_items
for new_item in new_set:
rna_keymap_ui.draw_kmi(["ADDON", "USER", "DEFAULT"], kc, user_km, new_item, box, 0)
user_keymap_items |= new_set
def register():
import functools
def read_keymaps(counter):
if counter == 0:
print("Keymaps not read.")
return
try:
km, kmi = get_user_keymap_item('Object Mode', 'light_studio.scale')
LLS_PT_Hotkeys.scale_kmi_type = f'EVENT_{kmi.type}'
km, kmi = get_user_keymap_item('Object Mode', 'light_studio.rotate')
LLS_PT_Hotkeys.rotate_kmi_type = f'EVENT_{kmi.type}'
except Exception:
if operators.VERBOSE:
traceback.print_exc()
bpy.app.timers.register(functools.partial(read_keymaps, counter-1), first_interval=0.1)
bpy.app.timers.register(functools.partial(read_keymaps, 10), first_interval=0.1)