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
385
386
387
388
389
390
|
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
import bpy
from bpy.types import Menu, Panel
from rna_prop_ui import PropertyPanel
from blf import gettext as _
class LAMP_MT_sunsky_presets(Menu):
bl_label = _("Sun & Sky Presets")
preset_subdir = "sunsky"
preset_operator = "script.execute_preset"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
draw = Menu.draw_preset
class DataButtonsPanel():
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(cls, context):
engine = context.scene.render.engine
return context.lamp and (engine in cls.COMPAT_ENGINES)
class DATA_PT_context_lamp(DataButtonsPanel, Panel):
bl_label = ""
bl_options = {'HIDE_HEADER'}
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
def draw(self, context):
layout = self.layout
ob = context.object
lamp = context.lamp
space = context.space_data
split = layout.split(percentage=0.65)
texture_count = len(lamp.texture_slots.keys())
if ob:
split.template_ID(ob, "data")
elif lamp:
split.template_ID(space, "pin_id")
if texture_count != 0:
split.label(text=str(texture_count), icon='TEXTURE')
class DATA_PT_preview(DataButtonsPanel, Panel):
bl_label = _("Preview")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
def draw(self, context):
self.layout.template_preview(context.lamp)
class DATA_PT_lamp(DataButtonsPanel, Panel):
bl_label = _("Lamp")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
def draw(self, context):
layout = self.layout
lamp = context.lamp
layout.prop(lamp, "type", expand=True)
split = layout.split()
col = split.column()
sub = col.column()
sub.prop(lamp, "color", text="")
sub.prop(lamp, "energy")
if lamp.type in {'POINT', 'SPOT'}:
sub.label(text=_("Falloff:"))
sub.prop(lamp, "falloff_type", text="")
sub.prop(lamp, "distance")
if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
col.label(text=_("Attenuation Factors:"))
sub = col.column(align=True)
sub.prop(lamp, "linear_attenuation", slider=True, text=_("Linear"))
sub.prop(lamp, "quadratic_attenuation", slider=True, text=_("Quadratic"))
col.prop(lamp, "use_sphere")
if lamp.type == 'AREA':
col.prop(lamp, "distance")
col.prop(lamp, "gamma")
col = split.column()
col.prop(lamp, "use_negative")
col.prop(lamp, "use_own_layer", text=_("This Layer Only"))
col.prop(lamp, "use_specular")
col.prop(lamp, "use_diffuse")
class DATA_PT_sunsky(DataButtonsPanel, Panel):
bl_label = _("Sky & Atmosphere")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
@classmethod
def poll(cls, context):
lamp = context.lamp
engine = context.scene.render.engine
return (lamp and lamp.type == 'SUN') and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
lamp = context.lamp.sky
row = layout.row(align=True)
row.prop(lamp, "use_sky")
row.menu("LAMP_MT_sunsky_presets", text=bpy.types.LAMP_MT_sunsky_presets.bl_label)
row.operator("lamp.sunsky_preset_add", text="", icon="ZOOMIN")
row.operator("lamp.sunsky_preset_add", text="", icon="ZOOMOUT").remove_active = True
row = layout.row()
row.active = lamp.use_sky or lamp.use_atmosphere
row.prop(lamp, "atmosphere_turbidity", text=_("Turbidity"))
split = layout.split()
col = split.column()
col.active = lamp.use_sky
col.label(text=_("Blending:"))
sub = col.column()
sub.prop(lamp, "sky_blend_type", text="")
sub.prop(lamp, "sky_blend", text=_("Factor"))
col.label(text=_("Color Space:"))
sub = col.column()
sub.row().prop(lamp, "sky_color_space", expand=True)
sub.prop(lamp, "sky_exposure", text=_("Exposure"))
col = split.column()
col.active = lamp.use_sky
col.label(text=_("Horizon:"))
sub = col.column()
sub.prop(lamp, "horizon_brightness", text=_("Brightness"))
sub.prop(lamp, "spread", text=_("Spread"))
col.label(text=_("Sun:"))
sub = col.column()
sub.prop(lamp, "sun_brightness", text=_("Brightness"))
sub.prop(lamp, "sun_size", text=_("Size"))
sub.prop(lamp, "backscattered_light", slider=True, text=_("Back Light"))
layout.separator()
layout.prop(lamp, "use_atmosphere")
split = layout.split()
col = split.column()
col.active = lamp.use_atmosphere
col.label(text=_("Intensity:"))
col.prop(lamp, "sun_intensity", text=_("Sun"))
col.prop(lamp, "atmosphere_distance_factor", text=_("Distance"))
col = split.column()
col.active = lamp.use_atmosphere
col.label(text=_("Scattering:"))
sub = col.column(align=True)
sub.prop(lamp, "atmosphere_inscattering", slider=True, text=_("Inscattering"))
sub.prop(lamp, "atmosphere_extinction", slider=True, text=_("Extinction"))
class DATA_PT_shadow(DataButtonsPanel, Panel):
bl_label = _("Shadow")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
@classmethod
def poll(cls, context):
lamp = context.lamp
engine = context.scene.render.engine
return (lamp and lamp.type in {'POINT', 'SUN', 'SPOT', 'AREA'}) and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
lamp = context.lamp
layout.prop(lamp, "shadow_method", expand=True)
if lamp.shadow_method == 'NOSHADOW' and lamp.type == 'AREA':
split = layout.split()
col = split.column()
col.label(text=_("Form factor sampling:"))
sub = col.row(align=True)
if lamp.shape == 'SQUARE':
sub.prop(lamp, "shadow_ray_samples_x", text=_("Samples"))
elif lamp.shape == 'RECTANGLE':
sub.prop(lamp, "shadow_ray_samples_x", text=_("Samples X"))
sub.prop(lamp, "shadow_ray_samples_y", text=_("Samples Y"))
if lamp.shadow_method != 'NOSHADOW':
split = layout.split()
col = split.column()
col.prop(lamp, "shadow_color", text="")
col = split.column()
col.prop(lamp, "use_shadow_layer", text=_("This Layer Only"))
col.prop(lamp, "use_only_shadow")
if lamp.shadow_method == 'RAY_SHADOW':
split = layout.split()
col = split.column()
col.label(text=_("Sampling:"))
if lamp.type in {'POINT', 'SUN', 'SPOT'}:
sub = col.row()
sub.prop(lamp, "shadow_ray_samples", text=_("Samples"))
sub.prop(lamp, "shadow_soft_size", text=_("Soft Size"))
elif lamp.type == 'AREA':
sub = col.row(align=True)
if lamp.shape == 'SQUARE':
sub.prop(lamp, "shadow_ray_samples_x", text=_("Samples"))
elif lamp.shape == 'RECTANGLE':
sub.prop(lamp, "shadow_ray_samples_x", text=_("Samples X"))
sub.prop(lamp, "shadow_ray_samples_y", text=_("Samples Y"))
col.row().prop(lamp, "shadow_ray_sample_method", expand=True)
if lamp.shadow_ray_sample_method == 'ADAPTIVE_QMC':
layout.prop(lamp, "shadow_adaptive_threshold", text=_("Threshold"))
if lamp.type == 'AREA' and lamp.shadow_ray_sample_method == 'CONSTANT_JITTERED':
row = layout.row()
row.prop(lamp, "use_umbra")
row.prop(lamp, "use_dither")
row.prop(lamp, "use_jitter")
elif lamp.shadow_method == 'BUFFER_SHADOW':
col = layout.column()
col.label(text=_("Buffer Type:"))
col.row().prop(lamp, "shadow_buffer_type", expand=True)
if lamp.shadow_buffer_type in {'REGULAR', 'HALFWAY', 'DEEP'}:
split = layout.split()
col = split.column()
col.label(text=_("Filter Type:"))
col.prop(lamp, "shadow_filter_type", text="")
sub = col.column(align=True)
sub.prop(lamp, "shadow_buffer_soft", text=_("Soft"))
sub.prop(lamp, "shadow_buffer_bias", text=_("Bias"))
col = split.column()
col.label(text=_("Sample Buffers:"))
col.prop(lamp, "shadow_sample_buffers", text="")
sub = col.column(align=True)
sub.prop(lamp, "shadow_buffer_size", text=_("Size"))
sub.prop(lamp, "shadow_buffer_samples", text=_("Samples"))
if lamp.shadow_buffer_type == 'DEEP':
col.prop(lamp, "compression_threshold")
elif lamp.shadow_buffer_type == 'IRREGULAR':
layout.prop(lamp, "shadow_buffer_bias", text=_("Bias"))
split = layout.split()
col = split.column()
col.prop(lamp, "use_auto_clip_start", text=_("Autoclip Start"))
sub = col.column()
sub.active = not lamp.use_auto_clip_start
sub.prop(lamp, "shadow_buffer_clip_start", text=_("Clip Start"))
col = split.column()
col.prop(lamp, "use_auto_clip_end", text=_("Autoclip End"))
sub = col.column()
sub.active = not lamp.use_auto_clip_end
sub.prop(lamp, "shadow_buffer_clip_end", text=_(" Clip End"))
class DATA_PT_area(DataButtonsPanel, Panel):
bl_label = _("Area Shape")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
@classmethod
def poll(cls, context):
lamp = context.lamp
engine = context.scene.render.engine
return (lamp and lamp.type == 'AREA') and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
lamp = context.lamp
col = layout.column()
col.row().prop(lamp, "shape", expand=True)
sub = col.row(align=True)
if (lamp.shape == 'SQUARE'):
sub.prop(lamp, "size")
elif (lamp.shape == 'RECTANGLE'):
sub.prop(lamp, "size", text=_("Size X"))
sub.prop(lamp, "size_y", text=_("Size Y"))
class DATA_PT_spot(DataButtonsPanel, Panel):
bl_label = _("Spot Shape")
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
@classmethod
def poll(cls, context):
lamp = context.lamp
engine = context.scene.render.engine
return (lamp and lamp.type == 'SPOT') and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
lamp = context.lamp
split = layout.split()
col = split.column()
sub = col.column()
sub.prop(lamp, "spot_size", text=_("Size"))
sub.prop(lamp, "spot_blend", text=_("Blend"), slider=True)
col.prop(lamp, "use_square")
col.prop(lamp, "show_cone")
col = split.column()
col.prop(lamp, "use_halo")
sub = col.column(align=True)
sub.active = lamp.use_halo
sub.prop(lamp, "halo_intensity", text=_("Intensity"))
if lamp.shadow_method == 'BUFFER_SHADOW':
sub.prop(lamp, "halo_step", text=_("Step"))
class DATA_PT_falloff_curve(DataButtonsPanel, Panel):
bl_label = _("Falloff Curve")
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
@classmethod
def poll(cls, context):
lamp = context.lamp
engine = context.scene.render.engine
return (lamp and lamp.type in {'POINT', 'SPOT'} and lamp.falloff_type == 'CUSTOM_CURVE') and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
lamp = context.lamp
self.layout.template_curve_mapping(lamp, "falloff_curve")
class DATA_PT_custom_props_lamp(DataButtonsPanel, PropertyPanel, Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
_context_path = "object.data"
_property_type = bpy.types.Lamp
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
|