change python scripts so modules which register with blender have a register() functi...
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
185 class WORLD_PT_environment_lighting(WorldButtonsPanel):
186     bl_label = "Environment Lighting"
187     COMPAT_ENGINES = {'BLENDER_RENDER'}
188
189     def draw_header(self, context):
190         light = context.world.lighting
191         self.layout.prop(light, "use_environment_lighting", text="")
192
193     def draw(self, context):
194         layout = self.layout
195         light = context.world.lighting
196
197         layout.active = light.use_environment_lighting
198
199         split = layout.split()
200         split.prop(light, "environment_energy", text="Energy")
201         split.prop(light, "environment_color", text="")
202
203
204 class WORLD_PT_indirect_lighting(WorldButtonsPanel):
205     bl_label = "Indirect Lighting"
206     COMPAT_ENGINES = {'BLENDER_RENDER'}
207
208     def draw_header(self, context):
209         light = context.world.lighting
210         self.layout.prop(light, "use_indirect_lighting", text="")
211
212     def draw(self, context):
213         layout = self.layout
214         light = context.world.lighting
215
216         layout.active = light.use_indirect_lighting
217
218         split = layout.split()
219         split.prop(light, "indirect_factor", text="Factor")
220         split.prop(light, "indirect_bounces", text="Bounces")
221
222
223 class WORLD_PT_gather(WorldButtonsPanel):
224     bl_label = "Gather"
225     COMPAT_ENGINES = {'BLENDER_RENDER'}
226
227     def draw(self, context):
228         layout = self.layout
229         light = context.world.lighting
230
231         layout.active = light.use_ambient_occlusion or light.use_environment_lighting or light.use_indirect_lighting
232
233         layout.prop(light, "gather_method", expand=True)
234
235         split = layout.split()
236
237         col = split.column()
238         col.label(text="Attenuation:")
239         if light.gather_method == 'RAYTRACE':
240             col.prop(light, "distance")
241         col.prop(light, "falloff")
242         sub = col.row()
243         sub.active = light.falloff
244         sub.prop(light, "falloff_strength", text="Strength")
245
246         if light.gather_method == 'RAYTRACE':
247             col = split.column()
248
249             col.label(text="Sampling:")
250             col.prop(light, "sample_method", text="")
251
252             sub = col.column()
253             sub.prop(light, "samples")
254
255             if light.sample_method == 'ADAPTIVE_QMC':
256                 sub.prop(light, "threshold")
257                 sub.prop(light, "adapt_to_speed", slider=True)
258             elif light.sample_method == 'CONSTANT_JITTERED':
259                 sub.prop(light, "bias")
260
261         if light.gather_method == 'APPROXIMATE':
262             col = split.column()
263
264             col.label(text="Sampling:")
265             col.prop(light, "passes")
266             col.prop(light, "error_tolerance", text="Error")
267             col.prop(light, "pixel_cache")
268             col.prop(light, "correction")
269
270
271 classes = [
272     WORLD_PT_context_world,
273     WORLD_PT_preview,
274     WORLD_PT_world,
275     WORLD_PT_ambient_occlusion,
276     WORLD_PT_environment_lighting,
277     WORLD_PT_indirect_lighting,
278     WORLD_PT_gather,
279     WORLD_PT_mist,
280     WORLD_PT_stars,
281
282     WORLD_PT_custom_props]
283
284
285 def register():
286     register = bpy.types.register
287     for cls in classes:
288         register(cls)
289
290 def unregister():
291     unregister = bpy.types.unregister
292     for cls in classes:
293         unregister(cls)