COLLADA branch: merge from trunk -r 25745:26429.
[blender.git] / release / scripts / ui / properties_world.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 from rna_prop_ui import PropertyPanel
22
23 narrowui = 180
24
25
26 class WorldButtonsPanel(bpy.types.Panel):
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "world"
30     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
31
32     def poll(self, context):
33         rd = context.scene.render_data
34         return (context.world) and (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
35
36
37 class WORLD_PT_preview(WorldButtonsPanel):
38     bl_label = "Preview"
39     COMPAT_ENGINES = {'BLENDER_RENDER'}
40
41     def draw(self, context):
42         self.layout.template_preview(context.world)
43
44
45 class WORLD_PT_context_world(WorldButtonsPanel):
46     bl_label = ""
47     bl_show_header = False
48     COMPAT_ENGINES = {'BLENDER_RENDER'}
49
50     def poll(self, context):
51         rd = context.scene.render_data
52         return (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
53
54     def draw(self, context):
55         layout = self.layout
56
57         scene = context.scene
58         world = context.world
59         space = context.space_data
60         wide_ui = context.region.width > narrowui
61
62
63         if wide_ui:
64             split = layout.split(percentage=0.65)
65             if scene:
66                 split.template_ID(scene, "world", new="world.new")
67             elif world:
68                 split.template_ID(space, "pin_id")
69         else:
70             layout.template_ID(scene, "world", new="world.new")
71
72
73 class WORLD_PT_custom_props(WorldButtonsPanel, PropertyPanel):
74     COMPAT_ENGINES = {'BLENDER_RENDER'}
75     _context_path = "world"
76
77
78 class WORLD_PT_world(WorldButtonsPanel):
79     bl_label = "World"
80     COMPAT_ENGINES = {'BLENDER_RENDER'}
81
82     def draw(self, context):
83         layout = self.layout
84         wide_ui = context.region.width > narrowui
85         world = context.world
86
87         if wide_ui:
88             row = layout.row()
89             row.prop(world, "paper_sky")
90             row.prop(world, "blend_sky")
91             row.prop(world, "real_sky")
92         else:
93             col = layout.column()
94             col.prop(world, "paper_sky")
95             col.prop(world, "blend_sky")
96             col.prop(world, "real_sky")
97
98         row = layout.row()
99         row.column().prop(world, "horizon_color")
100         col = row.column()
101         col.prop(world, "zenith_color")
102         col.active = world.blend_sky
103         row.column().prop(world, "ambient_color")
104
105
106 class WORLD_PT_mist(WorldButtonsPanel):
107     bl_label = "Mist"
108     bl_default_closed = True
109     COMPAT_ENGINES = {'BLENDER_RENDER'}
110
111     def draw_header(self, context):
112         world = context.world
113
114         self.layout.prop(world.mist, "enabled", text="")
115
116     def draw(self, context):
117         layout = self.layout
118         wide_ui = context.region.width > narrowui
119         world = context.world
120
121         layout.active = world.mist.enabled
122
123         split = layout.split()
124
125         col = split.column()
126         col.prop(world.mist, "intensity", slider=True)
127         col.prop(world.mist, "start")
128
129         if wide_ui:
130             col = split.column()
131         col.prop(world.mist, "depth")
132         col.prop(world.mist, "height")
133
134         layout.prop(world.mist, "falloff")
135
136
137 class WORLD_PT_stars(WorldButtonsPanel):
138     bl_label = "Stars"
139     bl_default_closed = True
140     COMPAT_ENGINES = {'BLENDER_RENDER'}
141
142     def draw_header(self, context):
143         world = context.world
144
145         self.layout.prop(world.stars, "enabled", text="")
146
147     def draw(self, context):
148         layout = self.layout
149         wide_ui = context.region.width > narrowui
150         world = context.world
151
152         layout.active = world.stars.enabled
153
154         split = layout.split()
155
156         col = split.column()
157         col.prop(world.stars, "size")
158         col.prop(world.stars, "color_randomization", text="Colors")
159
160         if wide_ui:
161             col = split.column()
162         col.prop(world.stars, "min_distance", text="Min. Dist")
163         col.prop(world.stars, "average_separation", text="Separation")
164
165
166 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
167     bl_label = "Ambient Occlusion"
168     COMPAT_ENGINES = {'BLENDER_RENDER'}
169
170     def draw_header(self, context):
171         light = context.world.lighting
172         self.layout.prop(light, "use_ambient_occlusion", text="")
173
174     def draw(self, context):
175         layout = self.layout
176         light = context.world.lighting
177
178         layout.active = light.use_ambient_occlusion
179
180         split = layout.split()
181         split.prop(light, "ao_factor", text="Factor")
182         split.prop(light, "ao_blend_mode", text="")
183
184 class WORLD_PT_environment_lighting(WorldButtonsPanel):
185     bl_label = "Environment Lighting"
186     COMPAT_ENGINES = {'BLENDER_RENDER'}
187
188     def draw_header(self, context):
189         light = context.world.lighting
190         self.layout.prop(light, "use_environment_lighting", text="")
191
192     def draw(self, context):
193         layout = self.layout
194         light = context.world.lighting
195
196         layout.active = light.use_environment_lighting
197
198         split = layout.split()
199         split.prop(light, "environment_energy", text="Energy")
200         split.prop(light, "environment_color", text="")
201
202 class WORLD_PT_indirect_lighting(WorldButtonsPanel):
203     bl_label = "Indirect Lighting"
204     COMPAT_ENGINES = {'BLENDER_RENDER'}
205
206     def draw_header(self, context):
207         light = context.world.lighting
208         self.layout.prop(light, "use_indirect_lighting", text="")
209
210     def draw(self, context):
211         layout = self.layout
212         light = context.world.lighting
213
214         layout.active = light.use_indirect_lighting
215
216         split = layout.split()
217         split.prop(light, "indirect_factor", text="Factor")
218         split.prop(light, "indirect_bounces", text="Bounces")
219
220 class WORLD_PT_gather(WorldButtonsPanel):
221     bl_label = "Gather"
222     COMPAT_ENGINES = {'BLENDER_RENDER'}
223
224     def draw(self, context):
225         layout = self.layout
226         light = context.world.lighting
227
228         layout.active = light.use_ambient_occlusion or light.use_environment_lighting or light.use_indirect_lighting
229
230         layout.prop(light, "gather_method", expand=True)
231
232         split = layout.split()
233
234         col = split.column()
235         col.label(text="Attenuation:")
236         if light.gather_method == 'RAYTRACE':
237             col.prop(light, "distance")
238         col.prop(light, "falloff")
239         sub = col.row()
240         sub.active = light.falloff
241         sub.prop(light, "falloff_strength", text="Strength")
242
243         if light.gather_method == 'RAYTRACE':
244             col = split.column()
245
246             col.label(text="Sampling:")
247             col.prop(light, "sample_method", text="")
248
249             sub = col.column()
250             sub.prop(light, "samples")
251
252             if light.sample_method == 'ADAPTIVE_QMC':
253                 sub.prop(light, "threshold")
254                 sub.prop(light, "adapt_to_speed", slider=True)
255             elif light.sample_method == 'CONSTANT_JITTERED':
256                 sub.prop(light, "bias")
257
258         if light.gather_method == 'APPROXIMATE':
259             col = split.column()
260
261             col.label(text="Sampling:")
262             col.prop(light, "passes")
263             col.prop(light, "error_tolerance", text="Error")
264             col.prop(light, "pixel_cache")
265             col.prop(light, "correction")
266
267 bpy.types.register(WORLD_PT_context_world)
268 bpy.types.register(WORLD_PT_preview)
269 bpy.types.register(WORLD_PT_world)
270 bpy.types.register(WORLD_PT_ambient_occlusion)
271 bpy.types.register(WORLD_PT_environment_lighting)
272 bpy.types.register(WORLD_PT_indirect_lighting)
273 bpy.types.register(WORLD_PT_gather)
274 bpy.types.register(WORLD_PT_mist)
275 bpy.types.register(WORLD_PT_stars)
276
277 bpy.types.register(WORLD_PT_custom_props)