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