2.5 Lamp Buttons:
[blender.git] / release / ui / buttons_data_lamp.py
1
2 import bpy
3
4 class DataButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "data"
8         
9         def poll(self, context):
10                 return (context.lamp)
11                 
12 class DATA_PT_preview(DataButtonsPanel):
13         __label__ = "Preview"
14
15         def draw(self, context):
16                 layout = self.layout
17
18                 layout.template_preview(context.lamp)
19         
20 class DATA_PT_context_lamp(DataButtonsPanel):
21         __show_header__ = False
22         
23         def draw(self, context):
24                 layout = self.layout
25                 
26                 ob = context.object
27                 lamp = context.lamp
28                 space = context.space_data
29
30                 split = layout.split(percentage=0.65)
31
32                 if ob:
33                         split.template_ID(ob, "data")
34                         split.itemS()
35                 elif lamp:
36                         split.template_ID(space, "pin_id")
37                         split.itemS()
38
39 class DATA_PT_lamp(DataButtonsPanel):
40         __label__ = "Lamp"
41
42         def draw(self, context):
43                 layout = self.layout
44                 
45                 lamp = context.lamp
46                 
47                 layout.itemR(lamp, "type", expand=True)
48                 
49                 split = layout.split()
50                 
51                 col = split.column()
52                 col.itemR(lamp, "color", text="")
53                 col.itemR(lamp, "energy")
54                 col.itemR(lamp, "negative")
55                 col.itemR(lamp, "distance")
56         
57                 col = split.column()
58                 col.itemR(lamp, "layer", text="This Layer Only")
59                 col.itemR(lamp, "specular")
60                 col.itemR(lamp, "diffuse")
61                 
62                 split = layout.split()
63                 
64                 if lamp.type in ('POINT', 'SPOT'):
65                         col = split.column()
66                         col.itemL(text="Falloff:")
67                         sub = col.column(align=True)
68                         sub.itemR(lamp, "falloff_type", text="")
69                         sub.itemR(lamp, "distance")
70                         sub.itemR(lamp, "sphere")
71                         
72                         if lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED':
73                                 col = split.column()
74                                 col.itemL(text="Attenuation Distance:")
75                                 sub = col.column(align=True)
76                                 sub.itemR(lamp, "linear_attenuation", slider=True, text="Linear")
77                                 sub.itemR(lamp, "quadratic_attenuation", slider=True, text="Quadratic")
78                         else:
79                                 split.column()
80                         
81                 if lamp.type == 'AREA':
82                         col = split.column()
83                         col.itemL(text="Shape:")
84                         sub = col.column(align=True)
85                         sub.itemR(lamp, "shape", text="")
86                         if (lamp.shape == 'SQUARE'):
87                                 sub.itemR(lamp, "size")
88                         elif (lamp.shape == 'RECTANGLE'):
89                                 sub.itemR(lamp, "size", text="Size X")
90                                 sub.itemR(lamp, "size_y", text="Size Y")
91                         
92                         col = split.column()
93                         col.itemL(text="Gamma:")
94                         col.itemR(lamp, "gamma", text="Value")
95
96 class DATA_PT_sunsky(DataButtonsPanel):
97         __label__ = "Sun/Sky"
98         
99         def poll(self, context):
100                 lamp = context.lamp
101                 return (lamp and lamp.type == 'SUN')
102
103         def draw(self, context):
104                 layout = self.layout
105                 
106                 lamp = context.lamp.sky
107
108                 row = layout.row()
109                 row.itemR(lamp, "sky")
110                 row.itemR(lamp, "atmosphere")
111                 
112                 row = layout.row()
113                 row.active = lamp.sky or lamp.atmosphere
114                 row.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
115                         
116                 split = layout.split()
117                 
118                 col = split.column()
119                 col.active = lamp.sky
120                 col.itemL(text="Blend Mode:")
121                 sub = col.column(align=True)
122                 sub.itemR(lamp, "sky_blend_type", text="")
123                 sub.itemR(lamp, "sky_blend", text="Factor")
124                 
125                 col.itemL(text="Color Space:")
126                 sub = col.column(align=True)
127                 sub.itemR(lamp, "sky_color_space", text="")
128                 sub.itemR(lamp, "sky_exposure", text="Exposure")
129                         
130                 col = split.column()
131                 col.active = lamp.sky
132                 col.itemL(text="Horizon:")
133                 sub = col.column(align=True)
134                 sub.itemR(lamp, "horizon_brightness", text="Brightness")
135                 sub.itemR(lamp, "spread", text="Spread")
136                 
137                 col.itemL(text="Sun:")
138                 sub = col.column(align=True)
139                 sub.itemR(lamp, "sun_brightness", text="Brightness")
140                 sub.itemR(lamp, "sun_size", text="Size")
141                 sub.itemR(lamp, "backscattered_light", slider=True,text="Back Light")
142                 
143                 layout.itemS()
144                 
145                 split = layout.split()
146                 
147                 col = split.column()
148                 col.active = lamp.atmosphere
149                 col.itemL(text="Sun:")
150                 col.itemR(lamp, "sun_intensity", text="Intensity")
151                 col.itemL(text="Scale Distance:")
152                 col.itemR(lamp, "atmosphere_distance_factor", text="Distance")
153                         
154                 col = split.column()
155                 col.active = lamp.atmosphere
156                 col.itemL(text="Scattering:")
157                 sub = col.column(align=True)
158                 sub.itemR(lamp, "atmosphere_inscattering", slider=True, text="Inscattering")
159                 sub.itemR(lamp, "atmosphere_extinction", slider=True ,text="Extinction")
160                 
161 class DATA_PT_shadow(DataButtonsPanel):
162         __label__ = "Shadow"
163         
164         def poll(self, context):
165                 lamp = context.lamp
166                 return (lamp and lamp.type in ('POINT','SUN', 'SPOT', 'AREA'))
167
168         def draw(self, context):
169                 layout = self.layout
170                 
171                 lamp = context.lamp
172
173                 layout.itemR(lamp, "shadow_method", expand=True)
174                 
175                 if lamp.shadow_method != 'NOSHADOW':
176                         split = layout.split()
177                         
178                         col = split.column()
179                         col.itemR(lamp, "shadow_color", text="")
180                         
181                         col = split.column()
182                         col.itemR(lamp, "shadow_layer", text="This Layer Only")
183                         col.itemR(lamp, "only_shadow")
184                 
185                 if lamp.shadow_method == 'RAY_SHADOW':
186                         col = layout.column()
187                         col.itemL(text="Sampling:")
188                         col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
189                                 
190                         if lamp.type in ('POINT', 'SUN', 'SPOT'):
191                                 split = layout.split()
192                                 
193                                 col = split.column(align=True)
194                                 col.itemR(lamp, "shadow_soft_size", text="Soft Size")
195                                 
196                                 col = split.column(align=True)
197                                 col.itemR(lamp, "shadow_ray_samples", text="Samples")
198                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
199                                         col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
200                                                 
201                         elif lamp.type == 'AREA':
202                                 split = layout.split()
203                                 
204                                 col = split.column(align=True)
205                                 if lamp.shape == 'SQUARE':
206                                         col.itemR(lamp, "shadow_ray_samples_x", text="Samples")
207                                 elif lamp.shape == 'RECTANGLE':
208                                         col.itemR(lamp, "shadow_ray_samples_x", text="Samples X")
209                                         col.itemR(lamp, "shadow_ray_samples_y", text="Samples Y")
210                                         
211                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
212                                         col.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
213                                         split.column()
214                                 elif lamp.shadow_ray_sampling_method == 'CONSTANT_QMC':
215                                         split.column()
216                                 elif lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
217                                         col = split.column()
218                                         col.itemR(lamp, "umbra")
219                                         col.itemR(lamp, "dither")
220                                         col.itemR(lamp, "jitter")       
221
222                 if lamp.shadow_method == 'BUFFER_SHADOW':
223                         col = layout.column()
224                         col.itemL(text="Buffer Type:")
225                         col.row().itemR(lamp, "shadow_buffer_type", expand=True)
226
227                         if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY'):
228                                 split = layout.split()
229                                 
230                                 col = split.column()
231                                 col.itemL(text="Filter Type:")
232                                 col.itemR(lamp, "shadow_filter_type", text="")
233                                 sub = col.column(align=True)
234                                 sub.itemR(lamp, "shadow_buffer_soft", text="Soft")
235                                 sub.itemR(lamp, "shadow_buffer_bias", text="Bias")
236                                 
237                                 col = split.column()
238                                 col.itemL(text="Sample Buffers:")
239                                 col.itemR(lamp, "shadow_sample_buffers", text="")
240                                 sub = col.column(align=True)
241                                 sub.itemR(lamp, "shadow_buffer_size", text="Size")
242                                 sub.itemR(lamp, "shadow_buffer_samples", text="Samples")
243                                 
244                         elif lamp.shadow_buffer_type == 'IRREGULAR':
245                                 layout.itemR(lamp, "shadow_buffer_bias", text="Bias")
246                         
247                         row = layout.row()
248                         row.itemR(lamp, "auto_clip_start", text="Autoclip Start")
249                         sub = row.row()
250                         sub.active = not lamp.auto_clip_start
251                         sub.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
252
253                         row = layout.row()
254                         row.itemR(lamp, "auto_clip_end", text="Autoclip End")
255                         sub = row.row()
256                         sub.active = not lamp.auto_clip_end
257                         sub.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
258
259 class DATA_PT_spot(DataButtonsPanel):
260         __label__ = "Spot"
261         
262         def poll(self, context):
263                 lamp = context.lamp
264                 return (lamp and lamp.type == 'SPOT')
265
266         def draw(self, context):
267                 layout = self.layout
268                 
269                 lamp = context.lamp
270
271                 split = layout.split()
272                 
273                 col = split.column()
274                 sub = col.column(align=True)
275                 sub.itemR(lamp, "spot_size", text="Size")
276                 sub.itemR(lamp, "spot_blend", text="Blend")
277                 col.itemR(lamp, "square")
278                 
279                 col = split.column()
280                 col.itemR(lamp, "halo")
281                 sub = col.column(align=True)
282                 sub.active = lamp.halo
283                 sub.itemR(lamp, "halo_intensity", text="Intensity")
284                 if lamp.shadow_method == 'BUFFER_SHADOW':
285                         sub.itemR(lamp, "halo_step", text="Step")
286
287 class DATA_PT_falloff_curve(DataButtonsPanel):
288         __label__ = "Falloff Curve"
289         __default_closed__ = True
290         
291         def poll(self, context):
292                 lamp = context.lamp
293
294                 if lamp and lamp.type in ('POINT', 'SPOT'):
295                         if lamp.falloff_type == 'CUSTOM_CURVE':
296                                 return True
297
298                 return False
299
300         def draw(self, context):
301                 layout = self.layout
302                 
303                 lamp = context.lamp
304
305                 layout.template_curve_mapping(lamp.falloff_curve)
306
307 bpy.types.register(DATA_PT_context_lamp)
308 bpy.types.register(DATA_PT_preview)
309 bpy.types.register(DATA_PT_lamp)
310 bpy.types.register(DATA_PT_falloff_curve)
311 bpy.types.register(DATA_PT_spot)
312 bpy.types.register(DATA_PT_shadow)
313 bpy.types.register(DATA_PT_sunsky)