Code cleanup: unused python vars & imports
[blender-staging.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
24
25 class WorldButtonsPanel():
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "world"
29     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
30
31     @classmethod
32     def poll(cls, context):
33         return (context.world and context.scene.render.engine in cls.COMPAT_ENGINES)
34
35
36 class WORLD_PT_context_world(WorldButtonsPanel, Panel):
37     bl_label = ""
38     bl_options = {'HIDE_HEADER'}
39     COMPAT_ENGINES = {'BLENDER_RENDER'}
40
41     @classmethod
42     def poll(cls, context):
43         rd = context.scene.render
44         return (not rd.use_game_engine) and (rd.engine in cls.COMPAT_ENGINES)
45
46     def draw(self, context):
47         layout = self.layout
48
49         scene = context.scene
50         world = context.world
51         space = context.space_data
52         rd = context.scene.render
53
54         texture_count = world and len(world.texture_slots.keys())
55
56         split = layout.split(percentage=0.85)
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 and rd.engine != 'CYCLES':
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
86         world = context.world
87
88         row = layout.row()
89         row.prop(world, "use_sky_paper")
90         row.prop(world, "use_sky_blend")
91         row.prop(world, "use_sky_real")
92
93         row = layout.row()
94         row.column().prop(world, "horizon_color")
95         col = row.column()
96         col.prop(world, "zenith_color")
97         col.active = world.use_sky_blend
98         row.column().prop(world, "ambient_color")
99
100         row = layout.row()
101         row.prop(world, "exposure")
102         row.prop(world, "color_range")
103
104
105 class WORLD_PT_ambient_occlusion(WorldButtonsPanel, Panel):
106     bl_label = "Ambient Occlusion"
107     COMPAT_ENGINES = {'BLENDER_RENDER'}
108
109     def draw_header(self, context):
110         light = context.world.light_settings
111         self.layout.prop(light, "use_ambient_occlusion", text="")
112
113     def draw(self, context):
114         layout = self.layout
115
116         light = context.world.light_settings
117
118         layout.active = light.use_ambient_occlusion
119
120         split = layout.split()
121         split.prop(light, "ao_factor", text="Factor")
122         split.prop(light, "ao_blend_type", text="")
123
124
125 class WORLD_PT_environment_lighting(WorldButtonsPanel, Panel):
126     bl_label = "Environment Lighting"
127     COMPAT_ENGINES = {'BLENDER_RENDER'}
128
129     def draw_header(self, context):
130         light = context.world.light_settings
131         self.layout.prop(light, "use_environment_light", text="")
132
133     def draw(self, context):
134         layout = self.layout
135
136         light = context.world.light_settings
137
138         layout.active = light.use_environment_light
139
140         split = layout.split()
141         split.prop(light, "environment_energy", text="Energy")
142         split.prop(light, "environment_color", text="")
143
144
145 class WORLD_PT_indirect_lighting(WorldButtonsPanel, Panel):
146     bl_label = "Indirect Lighting"
147     COMPAT_ENGINES = {'BLENDER_RENDER'}
148
149     def draw_header(self, context):
150         light = context.world.light_settings
151         self.layout.prop(light, "use_indirect_light", text="")
152
153     def draw(self, context):
154         layout = self.layout
155
156         light = context.world.light_settings
157
158         layout.active = light.use_indirect_light and light.gather_method == 'APPROXIMATE'
159
160         split = layout.split()
161         split.prop(light, "indirect_factor", text="Factor")
162         split.prop(light, "indirect_bounces", text="Bounces")
163
164         if light.gather_method == 'RAYTRACE':
165             layout.label(text="Only works with Approximate gather method")
166
167
168 class WORLD_PT_gather(WorldButtonsPanel, Panel):
169     bl_label = "Gather"
170     COMPAT_ENGINES = {'BLENDER_RENDER'}
171
172     def draw(self, context):
173         layout = self.layout
174
175         light = context.world.light_settings
176
177         layout.active = light.use_ambient_occlusion or light.use_environment_light or light.use_indirect_light
178
179         layout.prop(light, "gather_method", expand=True)
180
181         split = layout.split()
182
183         col = split.column()
184         col.label(text="Attenuation:")
185         if light.gather_method == 'RAYTRACE':
186             col.prop(light, "distance")
187         col.prop(light, "use_falloff")
188         sub = col.row()
189         sub.active = light.use_falloff
190         sub.prop(light, "falloff_strength", text="Strength")
191
192         if light.gather_method == 'RAYTRACE':
193             col = split.column()
194
195             col.label(text="Sampling:")
196             col.prop(light, "sample_method", text="")
197
198             sub = col.column()
199             sub.prop(light, "samples")
200
201             if light.sample_method == 'ADAPTIVE_QMC':
202                 sub.prop(light, "threshold")
203                 sub.prop(light, "adapt_to_speed", slider=True)
204             elif light.sample_method == 'CONSTANT_JITTERED':
205                 sub.prop(light, "bias")
206
207         if light.gather_method == 'APPROXIMATE':
208             col = split.column()
209
210             col.label(text="Sampling:")
211             col.prop(light, "passes")
212             col.prop(light, "error_threshold", text="Error")
213             col.prop(light, "use_cache")
214             col.prop(light, "correction")
215
216
217 class WORLD_PT_mist(WorldButtonsPanel, Panel):
218     bl_label = "Mist"
219     bl_options = {'DEFAULT_CLOSED'}
220     COMPAT_ENGINES = {'BLENDER_RENDER'}
221
222     def draw_header(self, context):
223         world = context.world
224
225         self.layout.prop(world.mist_settings, "use_mist", text="")
226
227     def draw(self, context):
228         layout = self.layout
229
230         world = context.world
231
232         layout.active = world.mist_settings.use_mist
233
234         split = layout.split()
235
236         col = split.column()
237         col.prop(world.mist_settings, "intensity")
238         col.prop(world.mist_settings, "start")
239
240         col = split.column()
241         col.prop(world.mist_settings, "depth")
242         col.prop(world.mist_settings, "height")
243
244         layout.prop(world.mist_settings, "falloff")
245
246
247 class WORLD_PT_custom_props(WorldButtonsPanel, PropertyPanel, Panel):
248     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
249     _context_path = "world"
250     _property_type = bpy.types.World
251
252 if __name__ == "__main__":  # only for live edit.
253     bpy.utils.register_module(__name__)