COLLADA branch: merge from trunk -r 24522:24758.
[blender.git] / release / scripts / ui / properties_data_lamp.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 class DataButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "data"
29
30     def poll(self, context):
31         return context.lamp
32
33
34 class DATA_PT_preview(DataButtonsPanel):
35     bl_label = "Preview"
36
37     def draw(self, context):
38         self.layout.template_preview(context.lamp)
39
40
41 class DATA_PT_context_lamp(DataButtonsPanel):
42     bl_label = ""
43     bl_show_header = False
44
45     def draw(self, context):
46         layout = self.layout
47
48         ob = context.object
49         lamp = context.lamp
50         space = context.space_data
51         wide_ui = context.region.width > narrowui
52
53         if wide_ui:
54             split = layout.split(percentage=0.65)
55             if ob:
56                 split.template_ID(ob, "data")
57                 split.itemS()
58             elif lamp:
59                 split.template_ID(space, "pin_id")
60                 split.itemS()
61         else:
62             if ob:
63                 layout.template_ID(ob, "data")
64             elif lamp:
65                 layout.template_ID(space, "pin_id")
66
67
68 class DATA_PT_lamp(DataButtonsPanel):
69     bl_label = "Lamp"
70
71     def draw(self, context):
72         layout = self.layout
73
74         lamp = context.lamp
75         wide_ui = context.region.width > narrowui
76
77         if wide_ui:
78             layout.itemR(lamp, "type", expand=True)
79         else:
80             layout.itemR(lamp, "type", text="")
81
82         split = layout.split()
83
84         col = split.column()
85         sub = col.column()
86         sub.itemR(lamp, "color", text="")
87         sub.itemR(lamp, "energy")
88
89         if lamp.type in ('POINT', 'SPOT'):
90             sub.itemL(text="Falloff:")
91             sub.itemR(lamp, "falloff_type", text="")
92             sub.itemR(lamp, "distance")
93
94             if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
95                 col.itemL(text="Attenuation Factors:")
96                 sub = col.column(align=True)
97                 sub.itemR(lamp, "linear_attenuation", slider=True, text="Linear")
98                 sub.itemR(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
99
100             col.itemR(lamp, "sphere")
101
102         if lamp.type == 'AREA':
103             col.itemR(lamp, "distance")
104             col.itemR(lamp, "gamma")
105
106         if wide_ui:
107             col = split.column()
108         col.itemR(lamp, "negative")
109         col.itemR(lamp, "layer", text="This Layer Only")
110         col.itemR(lamp, "specular")
111         col.itemR(lamp, "diffuse")
112
113
114 class DATA_PT_sunsky(DataButtonsPanel):
115     bl_label = "Sky & Atmosphere"
116
117     def poll(self, context):
118         lamp = context.lamp
119         return (lamp and lamp.type == 'SUN')
120
121     def draw(self, context):
122         layout = self.layout
123
124         lamp = context.lamp.sky
125         wide_ui = context.region.width > narrowui
126
127         layout.itemR(lamp, "sky")
128
129         row = layout.row()
130         row.active = lamp.sky or lamp.atmosphere
131         row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
132
133         split = layout.split()
134
135         col = split.column()
136         col.active = lamp.sky
137         col.itemL(text="Blending:")
138         sub = col.column()
139         sub.itemR(lamp, "sky_blend_type", text="")
140         sub.itemR(lamp, "sky_blend", text="Factor")
141
142         col.itemL(text="Color Space:")
143         sub = col.column()
144         sub.row().itemR(lamp, "sky_color_space", expand=True)
145         sub.itemR(lamp, "sky_exposure", text="Exposure")
146
147         if wide_ui:
148             col = split.column()
149         col.active = lamp.sky
150         col.itemL(text="Horizon:")
151         sub = col.column()
152         sub.itemR(lamp, "horizon_brightness", text="Brightness")
153         sub.itemR(lamp, "spread", text="Spread")
154
155         col.itemL(text="Sun:")
156         sub = col.column()
157         sub.itemR(lamp, "sun_brightness", text="Brightness")
158         sub.itemR(lamp, "sun_size", text="Size")
159         sub.itemR(lamp, "backscattered_light", slider=True, text="Back Light")
160
161         layout.itemS()
162
163         layout.itemR(lamp, "atmosphere")
164
165         split = layout.split()
166
167         col = split.column()
168         col.active = lamp.atmosphere
169         col.itemL(text="Intensity:")
170         col.itemR(lamp, "sun_intensity", text="Sun")
171         col.itemR(lamp, "atmosphere_distance_factor", text="Distance")
172
173         if wide_ui:
174             col = split.column()
175         col.active = lamp.atmosphere
176         col.itemL(text="Scattering:")
177         sub = col.column(align=True)
178         sub.itemR(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
179         sub.itemR(lamp, "atmosphere_extinction", slider=True, text="Extinction")
180
181
182 class DATA_PT_shadow(DataButtonsPanel):
183     bl_label = "Shadow"
184
185     def poll(self, context):
186         lamp = context.lamp
187         return (lamp and lamp.type in ('POINT', 'SUN', 'SPOT', 'AREA'))
188
189     def draw(self, context):
190         layout = self.layout
191
192         lamp = context.lamp
193         wide_ui = context.region.width > narrowui
194
195         if wide_ui:
196             layout.itemR(lamp, "shadow_method", expand=True)
197         else:
198             layout.itemR(lamp, "shadow_method", text="")
199
200         if lamp.shadow_method != 'NOSHADOW':
201             split = layout.split()
202
203             col = split.column()
204             col.itemR(lamp, "shadow_color", text="")
205
206             if wide_ui:
207                 col = split.column()
208             col.itemR(lamp, "shadow_layer", text="This Layer Only")
209             col.itemR(lamp, "only_shadow")
210
211         if lamp.shadow_method == 'RAY_SHADOW':
212             col = layout.column()
213             col.itemL(text="Sampling:")
214             if wide_ui:
215                 col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
216             else:
217                 col.itemR(lamp, "shadow_ray_sampling_method", text="")
218
219             if lamp.type in ('POINT', 'SUN', 'SPOT'):
220                 split = layout.split()
221
222                 col = split.column()
223                 col.itemR(lamp, "shadow_soft_size", text="Soft Size")
224
225                 col.itemR(lamp, "shadow_ray_samples", text="Samples")
226                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
227                     col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
228                 if wide_ui:
229                     col = split.column()
230
231             elif lamp.type == 'AREA':
232                 split = layout.split()
233
234                 col = split.column()
235
236                 if lamp.shape == 'SQUARE':
237                     col.itemR(lamp, "shadow_ray_samples_x", text="Samples")
238                 elif lamp.shape == 'RECTANGLE':
239                     col.itemR(lamp, "shadow_ray_samples_x", text="Samples X")
240                     col.itemR(lamp, "shadow_ray_samples_y", text="Samples Y")
241
242                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
243                     col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
244                     if wide_ui:
245                         col = split.column()
246
247                 elif lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
248                     if wide_ui:
249                         col = split.column()
250                     col.itemR(lamp, "umbra")
251                     col.itemR(lamp, "dither")
252                     col.itemR(lamp, "jitter")
253                 else:
254                     if wide_ui:
255                         col = split.column()
256
257
258         elif lamp.shadow_method == 'BUFFER_SHADOW':
259             col = layout.column()
260             col.itemL(text="Buffer Type:")
261             if wide_ui:
262                 col.row().itemR(lamp, "shadow_buffer_type", expand=True)
263             else:
264                 col.row().itemR(lamp, "shadow_buffer_type", text="")
265
266             if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY', 'DEEP'):
267                 split = layout.split()
268
269                 col = split.column()
270                 col.itemL(text="Filter Type:")
271                 col.itemR(lamp, "shadow_filter_type", text="")
272                 sub = col.column(align=True)
273                 sub.itemR(lamp, "shadow_buffer_soft", text="Soft")
274                 sub.itemR(lamp, "shadow_buffer_bias", text="Bias")
275
276                 if wide_ui:
277                     col = split.column()
278                 col.itemL(text="Sample Buffers:")
279                 col.itemR(lamp, "shadow_sample_buffers", text="")
280                 sub = col.column(align=True)
281                 sub.itemR(lamp, "shadow_buffer_size", text="Size")
282                 sub.itemR(lamp, "shadow_buffer_samples", text="Samples")
283                 if lamp.shadow_buffer_type == 'DEEP':
284                     col.itemR(lamp, "compression_threshold")
285
286             elif lamp.shadow_buffer_type == 'IRREGULAR':
287                 layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
288
289             split = layout.split()
290
291             col = split.column()
292             col.itemR(lamp, "auto_clip_start", text="Autoclip Start")
293             sub = col.column()
294             sub.active = not lamp.auto_clip_start
295             sub.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
296
297             if wide_ui:
298                 col = split.column()
299             col.itemR(lamp, "auto_clip_end", text="Autoclip End")
300             sub = col.column()
301             sub.active = not lamp.auto_clip_end
302             sub.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
303
304
305 class DATA_PT_area(DataButtonsPanel):
306     bl_label = "Area Shape"
307
308     def poll(self, context):
309         lamp = context.lamp
310         return (lamp and lamp.type == 'AREA')
311
312     def draw(self, context):
313         layout = self.layout
314
315         lamp = context.lamp
316
317         split = layout.split()
318
319         col = split.column()
320         col.row().itemR(lamp, "shape", expand=True)
321
322         sub = col.column(align=True)
323         if (lamp.shape == 'SQUARE'):
324             sub.itemR(lamp, "size")
325         elif (lamp.shape == 'RECTANGLE'):
326             sub.itemR(lamp, "size", text="Size X")
327             sub.itemR(lamp, "size_y", text="Size Y")
328
329
330 class DATA_PT_spot(DataButtonsPanel):
331     bl_label = "Spot Shape"
332
333     def poll(self, context):
334         lamp = context.lamp
335         return (lamp and lamp.type == 'SPOT')
336
337     def draw(self, context):
338         layout = self.layout
339
340         lamp = context.lamp
341         wide_ui = context.region.width > narrowui
342
343         split = layout.split()
344
345         col = split.column()
346         sub = col.column()
347         sub.itemR(lamp, "spot_size", text="Size")
348         sub.itemR(lamp, "spot_blend", text="Blend", slider=True)
349         col.itemR(lamp, "square")
350
351         if wide_ui:
352             col = split.column()
353         else:
354             col.itemS()
355         col.itemR(lamp, "halo")
356         sub = col.column(align=True)
357         sub.active = lamp.halo
358         sub.itemR(lamp, "halo_intensity", text="Intensity")
359         if lamp.shadow_method == 'BUFFER_SHADOW':
360             sub.itemR(lamp, "halo_step", text="Step")
361
362
363 class DATA_PT_falloff_curve(DataButtonsPanel):
364     bl_label = "Falloff Curve"
365     bl_default_closed = True
366
367     def poll(self, context):
368         lamp = context.lamp
369
370         return (lamp and lamp.type in ('POINT', 'SPOT') and lamp.falloff_type == 'CUSTOM_CURVE')
371
372     def draw(self, context):
373         lamp = context.lamp
374
375         self.layout.template_curve_mapping(lamp, "falloff_curve")
376
377 bpy.types.register(DATA_PT_context_lamp)
378 bpy.types.register(DATA_PT_preview)
379 bpy.types.register(DATA_PT_lamp)
380 bpy.types.register(DATA_PT_falloff_curve)
381 bpy.types.register(DATA_PT_area)
382 bpy.types.register(DATA_PT_spot)
383 bpy.types.register(DATA_PT_shadow)
384 bpy.types.register(DATA_PT_sunsky)