patch from William
[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                 split = layout.split(percentage=0.2)
52                 split.itemL(text="Type:")
53                 split.itemR(lamp, "type", text="")
54                 
55                 split = layout.split()
56                 
57                 sub = split.column()
58                 sub.itemR(lamp, "color")
59                 sub.itemR(lamp, "energy")
60                 sub.itemR(lamp, "distance")
61                 sub.itemR(lamp, "negative")
62         
63                 sub = split.column()
64                 sub.itemR(lamp, "layer", text="This Layer Only")
65                 sub.itemR(lamp, "specular")
66                 sub.itemR(lamp, "diffuse")
67                 
68                 if lamp.type in ('POINT', 'SPOT'):
69                         split = sub.split(percentage=0.3)
70                         split.itemL(text="Falloff:")
71                         split.itemR(lamp, "falloff_type", text="")
72                         sub.itemR(lamp, "sphere")
73                         
74                         if (lamp.falloff_type == 'LINEAR_QUADRATIC_WEIGHTED'):
75                                 sub.itemR(lamp, "linear_attenuation")
76                                 sub.itemR(lamp, "quadratic_attenuation")
77                         
78                 if lamp.type == 'AREA':
79                         sub.column()
80                         sub.itemR(lamp, "gamma")
81                         sub.itemR(lamp, "shape")
82                         if (lamp.shape == 'SQUARE'):
83                                 sub.itemR(lamp, "size")
84                         if (lamp.shape == 'RECTANGLE'):
85                                 sub.itemR(lamp, "size", text="Size X")
86                                 sub.itemR(lamp, "size_y")
87                                 
88 class DATA_PT_sky(DataButtonsPanel):
89         __idname__ = "DATA_PT_sky"
90         __label__ = "Sky"
91         
92         def poll(self, context):
93                 lamp = context.lamp
94                 return (lamp and lamp.type == 'SUN')
95                 
96         def draw_header(self, context):
97                 layout = self.layout
98                 lamp = context.lamp.sky
99
100                 layout.itemR(lamp, "sky", text="")
101
102         def draw(self, context):
103                 layout = self.layout
104                 lamp = context.lamp.sky
105
106                 layout.active = lamp.sky
107                 
108                 split = layout.split()
109                 col = split.column()
110
111                 col.itemL(text="Colors:")
112                 col.itemR(lamp, "sky_blend_type", text="Blend Type")
113                 col.itemR(lamp, "sky_blend")
114                 col.itemR(lamp, "sky_color_space", text="Color Space")
115                 col.itemR(lamp, "sky_exposure", text="Exposure")
116                 
117                 col = split.column()
118                 col.itemL(text="Horizon:")
119                 col.itemR(lamp, "horizon_brightness", text="Brightness")
120                 col.itemR(lamp, "spread", text="Spread")
121                 col.itemL(text="Sun:")
122                 col.itemR(lamp, "sun_brightness", text="Brightness")
123                 col.itemR(lamp, "sun_size", text="Size")
124                 col.itemR(lamp, "backscattered_light", text="Back Light")
125                                 
126
127                 
128                 
129 class DATA_PT_atmosphere(DataButtonsPanel):
130         __idname__ = "DATA_PT_atmosphere"
131         __label__ = "Atmosphere"
132         
133         def poll(self, context):
134                 lamp = context.lamp
135                 return (lamp and lamp.type == 'SUN')
136
137         def draw_header(self, context):
138                 layout = self.layout
139                 lamp = context.lamp.sky
140
141                 layout.itemR(lamp, "atmosphere", text="")
142
143         def draw(self, context):
144                 layout = self.layout
145                 lamp = context.lamp.sky
146         
147                 layout.active = lamp.atmosphere
148                 
149                 split = layout.split()
150                 sub = split.column()
151                 sub.itemR(lamp, "atmosphere_turbidity", text="Turbidity")
152                 sub.itemR(lamp, "sun_intensity", text="Sun Intensity")
153                 sub = split.column()
154                 sub.itemR(lamp, "atmosphere_inscattering", text="Inscattering", slider=True)
155                 sub.itemR(lamp, "atmosphere_extinction", text="Extinction", slider=True)
156                 sub.itemR(lamp, "atmosphere_distance_factor", text="Distance")          
157                                 
158 class DATA_PT_shadow(DataButtonsPanel):
159         __idname__ = "DATA_PT_shadow"
160         __label__ = "Shadow"
161         
162         def poll(self, context):
163                 lamp = context.lamp
164                 return (lamp and lamp.type in ('POINT','SUN', 'SPOT', 'AREA'))
165
166         def draw(self, context):
167                 layout = self.layout
168                 lamp = context.lamp
169
170                 layout.itemR(lamp, "shadow_method", expand=True)
171                 
172                 if lamp.shadow_method in ('BUFFER_SHADOW', 'RAY_SHADOW'):
173                 
174                         split = layout.split()
175                         
176                         sub = split.column()
177                         sub.itemR(lamp, "shadow_color")
178                         
179                         sub = split.column()
180                         sub.itemR(lamp, "shadow_layer", text="This Layer Only")
181                         sub.itemR(lamp, "only_shadow")
182                 
183                 if lamp.shadow_method == 'RAY_SHADOW':
184                 
185                         col = layout.column()
186                         col.itemL(text="Sampling:")
187                         col.row().itemR(lamp, "shadow_ray_sampling_method", expand=True)
188                                 
189                         if lamp.type in ('POINT', 'SUN', 'SPOT'):
190                                 flow = layout.column_flow()
191                                 flow.itemR(lamp, "shadow_soft_size", text="Soft Size")
192                                 flow.itemR(lamp, "shadow_ray_samples", text="Samples")
193                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
194                                         flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
195                                                 
196                         if lamp.type == 'AREA':
197                                 flow = layout.column_flow()
198                                 flow.itemR(lamp, "shadow_ray_samples_x", text="Samples")
199                                 if lamp.shadow_ray_sampling_method == 'ADAPTIVE_QMC':
200                                         flow.itemR(lamp, "shadow_adaptive_threshold", text="Threshold")
201                                 if lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
202                                         flow.itemR(lamp, "umbra")
203                                         flow.itemR(lamp, "dither")
204                                         flow.itemR(lamp, "jitter")      
205         
206                 if lamp.shadow_method == 'BUFFER_SHADOW':
207                         col = layout.column()
208                         col.itemL(text="Buffer Type:")
209                         col.row().itemR(lamp, "shadow_buffer_type", expand=True)
210
211                         if lamp.shadow_buffer_type in ('REGULAR', 'HALFWAY'):
212                                 flow = layout.column_flow()
213                                 flow.itemL(text="Sample Buffers:")
214                                 flow.itemR(lamp, "shadow_sample_buffers", text="")
215                                 flow.itemL(text="Filter Type:")
216                                 flow.itemR(lamp, "shadow_filter_type", text="")
217                                 
218                                 flow = layout.column_flow()
219                                 flow.itemR(lamp, "shadow_buffer_size", text="Size")
220                                 flow.itemR(lamp, "shadow_buffer_samples", text="Samples")
221                                 flow.itemR(lamp, "shadow_buffer_bias", text="Bias")
222                                 flow.itemR(lamp, "shadow_buffer_soft", text="Soft")
223                                 
224                         if (lamp.shadow_buffer_type == 'IRREGULAR'):
225                                 row = layout.row()
226                                 row.itemR(lamp, "shadow_buffer_bias", text="Bias")
227                         
228                         row = layout.row()
229                         row.itemR(lamp, "auto_clip_start", text="Autoclip Start")
230                         if not (lamp.auto_clip_start):
231                                 row.itemR(lamp, "shadow_buffer_clip_start", text="Clip Start")
232                         row = layout.row()
233                         row.itemR(lamp, "auto_clip_end", text="Autoclip End")
234                         if not (lamp.auto_clip_end):
235                                 row.itemR(lamp, "shadow_buffer_clip_end", text=" Clip End")
236
237 class DATA_PT_spot(DataButtonsPanel):
238         __idname__ = "DATA_PT_spot"
239         __label__ = "Spot"
240         
241         def poll(self, context):
242                 lamp = context.lamp
243                 return (lamp and lamp.type == 'SPOT')
244
245         def draw(self, context):
246                 layout = self.layout
247                 lamp = context.lamp
248
249                 split = layout.split()
250                 
251                 sub = split.column()
252                 sub.itemR(lamp, "spot_size", text="Size")
253                 sub.itemR(lamp, "spot_blend", text="Blend")
254                 sub.itemR(lamp, "square")
255                 
256                 col = split.column()
257                 col.itemR(lamp, "halo")
258                 colsub = col.column()
259                 colsub.active = lamp.halo
260                 colsub.itemR(lamp, "halo_intensity", text="Intensity")
261                 if lamp.shadow_method == 'BUFFER_SHADOW':
262                         colsub.itemR(lamp, "halo_step", text="Step")
263
264 class DATA_PT_falloff_curve(DataButtonsPanel):
265         __idname__ = "DATA_PT_falloff_curve"
266         __label__ = "Falloff Curve"
267         
268         def poll(self, context):
269                 lamp = context.lamp
270
271                 if lamp and lamp.type in ('POINT', 'SPOT'):
272                         if lamp.falloff_type == 'CUSTOM_CURVE':
273                                 return True
274
275                 return False
276
277         def draw(self, context):
278                 layout = self.layout
279                 lamp = context.lamp
280
281                 layout.template_curve_mapping(lamp.falloff_curve)
282
283 bpy.types.register(DATA_PT_context_lamp)
284 bpy.types.register(DATA_PT_preview)
285 bpy.types.register(DATA_PT_lamp)
286 bpy.types.register(DATA_PT_shadow)
287 bpy.types.register(DATA_PT_sky)
288 bpy.types.register(DATA_PT_atmosphere)
289 bpy.types.register(DATA_PT_spot)
290 bpy.types.register(DATA_PT_falloff_curve)
291