Fix:
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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     COMPAT_ENGINES = {'BLENDER_RENDER'}
109
110     def draw_header(self, context):
111         world = context.world
112
113         self.layout.prop(world.mist, "enabled", text="")
114
115     def draw(self, context):
116         layout = self.layout
117         wide_ui = context.region.width > narrowui
118         world = context.world
119
120         layout.active = world.mist.enabled
121
122         split = layout.split()
123
124         col = split.column()
125         col.prop(world.mist, "intensity", slider=True)
126         col.prop(world.mist, "start")
127
128         if wide_ui:
129             col = split.column()
130         col.prop(world.mist, "depth")
131         col.prop(world.mist, "height")
132
133         layout.prop(world.mist, "falloff")
134
135
136 class WORLD_PT_stars(WorldButtonsPanel):
137     bl_label = "Stars"
138     COMPAT_ENGINES = {'BLENDER_RENDER'}
139
140     def draw_header(self, context):
141         world = context.world
142
143         self.layout.prop(world.stars, "enabled", text="")
144
145     def draw(self, context):
146         layout = self.layout
147         wide_ui = context.region.width > narrowui
148         world = context.world
149
150         layout.active = world.stars.enabled
151
152         split = layout.split()
153
154         col = split.column()
155         col.prop(world.stars, "size")
156         col.prop(world.stars, "color_randomization", text="Colors")
157
158         if wide_ui:
159             col = split.column()
160         col.prop(world.stars, "min_distance", text="Min. Dist")
161         col.prop(world.stars, "average_separation", text="Separation")
162
163
164 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
165     bl_label = "Ambient Occlusion"
166     COMPAT_ENGINES = {'BLENDER_RENDER'}
167
168     def draw_header(self, context):
169         world = context.world
170
171         self.layout.prop(world.ambient_occlusion, "enabled", text="")
172
173     def draw(self, context):
174         layout = self.layout
175         wide_ui = context.region.width > narrowui
176         ao = context.world.ambient_occlusion
177
178         layout.active = ao.enabled
179
180         layout.prop(ao, "gather_method", expand=True)
181
182         split = layout.split()
183
184         col = split.column()
185         col.label(text="Attenuation:")
186         if ao.gather_method == 'RAYTRACE':
187             col.prop(ao, "distance")
188         col.prop(ao, "falloff")
189         sub = col.row()
190         sub.active = ao.falloff
191         sub.prop(ao, "falloff_strength", text="Strength")
192
193         if ao.gather_method == 'RAYTRACE':
194             if wide_ui:
195                 col = split.column()
196
197             col.label(text="Sampling:")
198             col.prop(ao, "sample_method", text="")
199
200             sub = col.column()
201             sub.prop(ao, "samples")
202
203             if ao.sample_method == 'ADAPTIVE_QMC':
204                 sub.prop(ao, "threshold")
205                 sub.prop(ao, "adapt_to_speed", slider=True)
206             elif ao.sample_method == 'CONSTANT_JITTERED':
207                 sub.prop(ao, "bias")
208
209         if ao.gather_method == 'APPROXIMATE':
210             if wide_ui:
211                 col = split.column()
212
213             col.label(text="Sampling:")
214             col.prop(ao, "passes")
215             col.prop(ao, "error_tolerance", text="Error")
216             col.prop(ao, "pixel_cache")
217             col.prop(ao, "correction")
218
219         col = layout.column()
220         col.label(text="Influence:")
221
222         col.row().prop(ao, "blend_mode", expand=True)
223
224         split = layout.split()
225
226         col = split.column()
227         col.prop(ao, "energy")
228         col.prop(ao, "indirect_energy")
229
230         if wide_ui:
231             col = split.column()
232         col.prop(ao, "color")
233         col.prop(ao, "indirect_bounces")
234
235 bpy.types.register(WORLD_PT_context_world)
236 bpy.types.register(WORLD_PT_preview)
237 bpy.types.register(WORLD_PT_world)
238 bpy.types.register(WORLD_PT_ambient_occlusion)
239 bpy.types.register(WORLD_PT_mist)
240 bpy.types.register(WORLD_PT_stars)
241
242 bpy.types.register(WORLD_PT_custom_props)