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