svn merge -r39834:40222 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / release / scripts / startup / bl_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 bpy.types import Panel
22 from rna_prop_ui import PropertyPanel
23 from blf import gettext as _
24
25
26 class WorldButtonsPanel():
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     @classmethod
33     def poll(cls, context):
34         return (context.world and context.scene.render.engine in cls.COMPAT_ENGINES)
35
36
37 class WORLD_PT_context_world(WorldButtonsPanel, Panel):
38     bl_label = ""
39     bl_options = {'HIDE_HEADER'}
40     COMPAT_ENGINES = {'BLENDER_RENDER'}
41
42     @classmethod
43     def poll(cls, context):
44         rd = context.scene.render
45         return (not rd.use_game_engine) and (rd.engine in cls.COMPAT_ENGINES)
46
47     def draw(self, context):
48         layout = self.layout
49
50         scene = context.scene
51         world = context.world
52         space = context.space_data
53
54         texture_count = world and len(world.texture_slots.keys())
55
56         split = layout.split(percentage=0.65)
57         if scene:
58             split.template_ID(scene, "world", new="world.new")
59         elif world:
60             split.template_ID(space, "pin_id")
61
62         if texture_count:
63             split.label(text=str(texture_count), icon='TEXTURE')
64
65
66 class WORLD_PT_preview(WorldButtonsPanel, Panel):
67     bl_label = _("Preview")
68     COMPAT_ENGINES = {'BLENDER_RENDER'}
69
70     @classmethod
71     def poll(cls, context):
72         rd = context.scene.render
73         return (context.world) and (not rd.use_game_engine) and (rd.engine in cls.COMPAT_ENGINES)
74
75     def draw(self, context):
76         self.layout.template_preview(context.world)
77
78
79 class WORLD_PT_world(WorldButtonsPanel, Panel):
80     bl_label = _("World")
81     COMPAT_ENGINES = {'BLENDER_RENDER'}
82
83     def draw(self, context):
84         layout = self.layout
85         world = context.world
86
87         row = layout.row()
88         row.prop(world, "use_sky_paper")
89         row.prop(world, "use_sky_blend")
90         row.prop(world, "use_sky_real")
91
92         row = layout.row()
93         row.column().prop(world, "horizon_color")
94         col = row.column()
95         col.prop(world, "zenith_color")
96         col.active = world.use_sky_blend
97         row.column().prop(world, "ambient_color")
98
99         row = layout.row()
100         row.prop(world, "exposure")
101         row.prop(world, "color_range")
102
103
104 class WORLD_PT_ambient_occlusion(WorldButtonsPanel, Panel):
105     bl_label = _("Ambient Occlusion")
106     COMPAT_ENGINES = {'BLENDER_RENDER'}
107
108     def draw_header(self, context):
109         light = context.world.light_settings
110         self.layout.prop(light, "use_ambient_occlusion", text="")
111
112     def draw(self, context):
113         layout = self.layout
114         light = context.world.light_settings
115
116         layout.active = light.use_ambient_occlusion
117
118         split = layout.split()
119         split.prop(light, "ao_factor", text=_("Factor"))
120         split.prop(light, "ao_blend_type", text="")
121
122
123 class WORLD_PT_environment_lighting(WorldButtonsPanel, Panel):
124     bl_label = _("Environment Lighting")
125     COMPAT_ENGINES = {'BLENDER_RENDER'}
126
127     def draw_header(self, context):
128         light = context.world.light_settings
129         self.layout.prop(light, "use_environment_light", text="")
130
131     def draw(self, context):
132         layout = self.layout
133         light = context.world.light_settings
134
135         layout.active = light.use_environment_light
136
137         split = layout.split()
138         split.prop(light, "environment_energy", text=_("Energy"))
139         split.prop(light, "environment_color", text="")
140
141
142 class WORLD_PT_indirect_lighting(WorldButtonsPanel, Panel):
143     bl_label = _("Indirect Lighting")
144     COMPAT_ENGINES = {'BLENDER_RENDER'}
145
146     def draw_header(self, context):
147         light = context.world.light_settings
148         self.layout.prop(light, "use_indirect_light", text="")
149
150     def draw(self, context):
151         layout = self.layout
152         light = context.world.light_settings
153
154         layout.active = light.use_indirect_light and light.gather_method == 'APPROXIMATE'
155
156         split = layout.split()
157         split.prop(light, "indirect_factor", text=_("Factor"))
158         split.prop(light, "indirect_bounces", text=_("Bounces"))
159
160         if light.gather_method == 'RAYTRACE':
161             layout.label(text=_("Only works with Approximate gather method"))
162
163
164 class WORLD_PT_gather(WorldButtonsPanel, Panel):
165     bl_label = _("Gather")
166     COMPAT_ENGINES = {'BLENDER_RENDER'}
167
168     def draw(self, context):
169         layout = self.layout
170         light = context.world.light_settings
171
172         layout.active = light.use_ambient_occlusion or light.use_environment_light or light.use_indirect_light
173
174         layout.prop(light, "gather_method", expand=True)
175
176         split = layout.split()
177
178         col = split.column()
179         col.label(text=_("Attenuation:"))
180         if light.gather_method == 'RAYTRACE':
181             col.prop(light, "distance")
182         col.prop(light, "use_falloff")
183         sub = col.row()
184         sub.active = light.use_falloff
185         sub.prop(light, "falloff_strength", text=_("Strength"))
186
187         if light.gather_method == 'RAYTRACE':
188             col = split.column()
189
190             col.label(text=_("Sampling:"))
191             col.prop(light, "sample_method", text="")
192
193             sub = col.column()
194             sub.prop(light, "samples")
195
196             if light.sample_method == 'ADAPTIVE_QMC':
197                 sub.prop(light, "threshold")
198                 sub.prop(light, "adapt_to_speed", slider=True)
199             elif light.sample_method == 'CONSTANT_JITTERED':
200                 sub.prop(light, "bias")
201
202         if light.gather_method == 'APPROXIMATE':
203             col = split.column()
204
205             col.label(text=_("Sampling:"))
206             col.prop(light, "passes")
207             col.prop(light, "error_threshold", text=_("Error"))
208             col.prop(light, "use_cache")
209             col.prop(light, "correction")
210
211
212 class WORLD_PT_mist(WorldButtonsPanel, Panel):
213     bl_label = _("Mist")
214     bl_options = {'DEFAULT_CLOSED'}
215     COMPAT_ENGINES = {'BLENDER_RENDER'}
216
217     def draw_header(self, context):
218         world = context.world
219
220         self.layout.prop(world.mist_settings, "use_mist", text="")
221
222     def draw(self, context):
223         layout = self.layout
224         world = context.world
225
226         layout.active = world.mist_settings.use_mist
227
228         split = layout.split()
229
230         col = split.column()
231         col.prop(world.mist_settings, "intensity", slider=True)
232         col.prop(world.mist_settings, "start")
233
234         col = split.column()
235         col.prop(world.mist_settings, "depth")
236         col.prop(world.mist_settings, "height")
237
238         layout.prop(world.mist_settings, "falloff")
239
240
241 class WORLD_PT_stars(WorldButtonsPanel, Panel):
242     bl_label = _("Stars")
243     bl_options = {'DEFAULT_CLOSED'}
244     COMPAT_ENGINES = {'BLENDER_RENDER'}
245
246     def draw_header(self, context):
247         world = context.world
248
249         self.layout.prop(world.star_settings, "use_stars", text="")
250
251     def draw(self, context):
252         layout = self.layout
253         world = context.world
254
255         layout.active = world.star_settings.use_stars
256
257         split = layout.split()
258
259         col = split.column()
260         col.prop(world.star_settings, "size")
261         col.prop(world.star_settings, "color_random", text=_("Colors"))
262
263         col = split.column()
264         col.prop(world.star_settings, "distance_min", text=_("Min. Dist"))
265         col.prop(world.star_settings, "average_separation", text=_("Separation"))
266
267
268 class WORLD_PT_custom_props(WorldButtonsPanel, PropertyPanel, Panel):
269     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
270     _context_path = "world"
271     _property_type = bpy.types.World
272
273 if __name__ == "__main__":  # only for live edit.
274     bpy.utils.register_module(__name__)