migrated NDOF code from soc-2010-merwin, SpaceNavigator now works on Mac 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 rna_prop_ui import PropertyPanel
22
23 # TODO, "color_range" not in the UI
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, bpy.types.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, bpy.types.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, bpy.types.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
100 class WORLD_PT_ambient_occlusion(WorldButtonsPanel, bpy.types.Panel):
101     bl_label = "Ambient Occlusion"
102     COMPAT_ENGINES = {'BLENDER_RENDER'}
103
104     def draw_header(self, context):
105         light = context.world.light_settings
106         self.layout.prop(light, "use_ambient_occlusion", text="")
107
108     def draw(self, context):
109         layout = self.layout
110         light = context.world.light_settings
111
112         layout.active = light.use_ambient_occlusion
113
114         split = layout.split()
115         split.prop(light, "ao_factor", text="Factor")
116         split.prop(light, "ao_blend_type", text="")
117
118
119 class WORLD_PT_environment_lighting(WorldButtonsPanel, bpy.types.Panel):
120     bl_label = "Environment Lighting"
121     COMPAT_ENGINES = {'BLENDER_RENDER'}
122
123     def draw_header(self, context):
124         light = context.world.light_settings
125         self.layout.prop(light, "use_environment_light", text="")
126
127     def draw(self, context):
128         layout = self.layout
129         light = context.world.light_settings
130
131         layout.active = light.use_environment_light
132
133         split = layout.split()
134         split.prop(light, "environment_energy", text="Energy")
135         split.prop(light, "environment_color", text="")
136
137
138 class WORLD_PT_indirect_lighting(WorldButtonsPanel, bpy.types.Panel):
139     bl_label = "Indirect Lighting"
140     COMPAT_ENGINES = {'BLENDER_RENDER'}
141
142     def draw_header(self, context):
143         light = context.world.light_settings
144         self.layout.prop(light, "use_indirect_light", text="")
145
146     def draw(self, context):
147         layout = self.layout
148         light = context.world.light_settings
149
150         layout.active = light.use_indirect_light and light.gather_method == 'APPROXIMATE'
151
152         split = layout.split()
153         split.prop(light, "indirect_factor", text="Factor")
154         split.prop(light, "indirect_bounces", text="Bounces")
155
156         if light.gather_method == 'RAYTRACE':
157             layout.label(text="Only works with Approximate gather method")
158
159
160 class WORLD_PT_gather(WorldButtonsPanel, bpy.types.Panel):
161     bl_label = "Gather"
162     COMPAT_ENGINES = {'BLENDER_RENDER'}
163
164     def draw(self, context):
165         layout = self.layout
166         light = context.world.light_settings
167
168         layout.active = light.use_ambient_occlusion or light.use_environment_light or light.use_indirect_light
169
170         layout.prop(light, "gather_method", expand=True)
171
172         split = layout.split()
173
174         col = split.column()
175         col.label(text="Attenuation:")
176         if light.gather_method == 'RAYTRACE':
177             col.prop(light, "distance")
178         col.prop(light, "use_falloff")
179         sub = col.row()
180         sub.active = light.use_falloff
181         sub.prop(light, "falloff_strength", text="Strength")
182
183         if light.gather_method == 'RAYTRACE':
184             col = split.column()
185
186             col.label(text="Sampling:")
187             col.prop(light, "sample_method", text="")
188
189             sub = col.column()
190             sub.prop(light, "samples")
191
192             if light.sample_method == 'ADAPTIVE_QMC':
193                 sub.prop(light, "threshold")
194                 sub.prop(light, "adapt_to_speed", slider=True)
195             elif light.sample_method == 'CONSTANT_JITTERED':
196                 sub.prop(light, "bias")
197
198         if light.gather_method == 'APPROXIMATE':
199             col = split.column()
200
201             col.label(text="Sampling:")
202             col.prop(light, "passes")
203             col.prop(light, "error_threshold", text="Error")
204             col.prop(light, "use_cache")
205             col.prop(light, "correction")
206
207
208 class WORLD_PT_mist(WorldButtonsPanel, bpy.types.Panel):
209     bl_label = "Mist"
210     bl_options = {'DEFAULT_CLOSED'}
211     COMPAT_ENGINES = {'BLENDER_RENDER'}
212
213     def draw_header(self, context):
214         world = context.world
215
216         self.layout.prop(world.mist_settings, "use_mist", text="")
217
218     def draw(self, context):
219         layout = self.layout
220         world = context.world
221
222         layout.active = world.mist_settings.use_mist
223
224         split = layout.split()
225
226         col = split.column()
227         col.prop(world.mist_settings, "intensity", slider=True)
228         col.prop(world.mist_settings, "start")
229
230         col = split.column()
231         col.prop(world.mist_settings, "depth")
232         col.prop(world.mist_settings, "height")
233
234         layout.prop(world.mist_settings, "falloff")
235
236
237 class WORLD_PT_stars(WorldButtonsPanel, bpy.types.Panel):
238     bl_label = "Stars"
239     bl_options = {'DEFAULT_CLOSED'}
240     COMPAT_ENGINES = {'BLENDER_RENDER'}
241
242     def draw_header(self, context):
243         world = context.world
244
245         self.layout.prop(world.star_settings, "use_stars", text="")
246
247     def draw(self, context):
248         layout = self.layout
249         world = context.world
250
251         layout.active = world.star_settings.use_stars
252
253         split = layout.split()
254
255         col = split.column()
256         col.prop(world.star_settings, "size")
257         col.prop(world.star_settings, "color_random", text="Colors")
258
259         col = split.column()
260         col.prop(world.star_settings, "distance_min", text="Min. Dist")
261         col.prop(world.star_settings, "average_separation", text="Separation")
262
263
264 class WORLD_PT_custom_props(WorldButtonsPanel, PropertyPanel, bpy.types.Panel):
265     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
266     _context_path = "world"
267     _property_type = bpy.types.World
268
269 if __name__ == "__main__":  # only for live edit.
270     bpy.utils.register_module(__name__)