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