custom properties panels for most ID types. use subclassing to keep panel UI definiti...
[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     _context_path = "world"
75
76
77 class WORLD_PT_world(WorldButtonsPanel):
78     bl_label = "World"
79     COMPAT_ENGINES = {'BLENDER_RENDER'}
80
81     def draw(self, context):
82         layout = self.layout
83         wide_ui = context.region.width > narrowui
84         world = context.world
85
86         if wide_ui:
87             row = layout.row()
88             row.prop(world, "paper_sky")
89             row.prop(world, "blend_sky")
90             row.prop(world, "real_sky")
91         else:
92             col = layout.column()
93             col.prop(world, "paper_sky")
94             col.prop(world, "blend_sky")
95             col.prop(world, "real_sky")
96
97         row = layout.row()
98         row.column().prop(world, "horizon_color")
99         col = row.column()
100         col.prop(world, "zenith_color")
101         col.active = world.blend_sky
102         row.column().prop(world, "ambient_color")
103
104
105 class WORLD_PT_mist(WorldButtonsPanel):
106     bl_label = "Mist"
107     COMPAT_ENGINES = {'BLENDER_RENDER'}
108
109     def draw_header(self, context):
110         world = context.world
111
112         self.layout.prop(world.mist, "enabled", text="")
113
114     def draw(self, context):
115         layout = self.layout
116         wide_ui = context.region.width > narrowui
117         world = context.world
118
119         layout.active = world.mist.enabled
120
121         split = layout.split()
122
123         col = split.column()
124         col.prop(world.mist, "intensity", slider=True)
125         col.prop(world.mist, "start")
126
127         if wide_ui:
128             col = split.column()
129         col.prop(world.mist, "depth")
130         col.prop(world.mist, "height")
131
132         layout.prop(world.mist, "falloff")
133
134
135 class WORLD_PT_stars(WorldButtonsPanel):
136     bl_label = "Stars"
137     COMPAT_ENGINES = {'BLENDER_RENDER'}
138
139     def draw_header(self, context):
140         world = context.world
141
142         self.layout.prop(world.stars, "enabled", text="")
143
144     def draw(self, context):
145         layout = self.layout
146         wide_ui = context.region.width > narrowui
147         world = context.world
148
149         layout.active = world.stars.enabled
150
151         split = layout.split()
152
153         col = split.column()
154         col.prop(world.stars, "size")
155         col.prop(world.stars, "color_randomization", text="Colors")
156
157         if wide_ui:
158             col = split.column()
159         col.prop(world.stars, "min_distance", text="Min. Dist")
160         col.prop(world.stars, "average_separation", text="Separation")
161
162
163 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
164     bl_label = "Ambient Occlusion"
165     COMPAT_ENGINES = {'BLENDER_RENDER'}
166
167     def draw_header(self, context):
168         world = context.world
169
170         self.layout.prop(world.ambient_occlusion, "enabled", text="")
171
172     def draw(self, context):
173         layout = self.layout
174         wide_ui = context.region.width > narrowui
175         ao = context.world.ambient_occlusion
176
177         layout.active = ao.enabled
178
179         layout.prop(ao, "gather_method", expand=True)
180
181         split = layout.split()
182
183         col = split.column()
184         col.label(text="Attenuation:")
185         if ao.gather_method == 'RAYTRACE':
186             col.prop(ao, "distance")
187         col.prop(ao, "falloff")
188         sub = col.row()
189         sub.active = ao.falloff
190         sub.prop(ao, "falloff_strength", text="Strength")
191
192         if ao.gather_method == 'RAYTRACE':
193             if wide_ui:
194                 col = split.column()
195
196             col.label(text="Sampling:")
197             col.prop(ao, "sample_method", text="")
198
199             sub = col.column()
200             sub.prop(ao, "samples")
201
202             if ao.sample_method == 'ADAPTIVE_QMC':
203                 sub.prop(ao, "threshold")
204                 sub.prop(ao, "adapt_to_speed", slider=True)
205             elif ao.sample_method == 'CONSTANT_JITTERED':
206                 sub.prop(ao, "bias")
207
208         if ao.gather_method == 'APPROXIMATE':
209             if wide_ui:
210                 col = split.column()
211
212             col.label(text="Sampling:")
213             col.prop(ao, "passes")
214             col.prop(ao, "error_tolerance", text="Error")
215             col.prop(ao, "pixel_cache")
216             col.prop(ao, "correction")
217
218         col = layout.column()
219         col.label(text="Influence:")
220
221         col.row().prop(ao, "blend_mode", expand=True)
222
223         split = layout.split()
224
225         col = split.column()
226         col.prop(ao, "energy")
227         col.prop(ao, "indirect_energy")
228
229         if wide_ui:
230             col = split.column()
231         col.prop(ao, "color")
232         col.prop(ao, "indirect_bounces")
233
234 bpy.types.register(WORLD_PT_context_world)
235 bpy.types.register(WORLD_PT_preview)
236 bpy.types.register(WORLD_PT_world)
237 bpy.types.register(WORLD_PT_ambient_occlusion)
238 bpy.types.register(WORLD_PT_mist)
239 bpy.types.register(WORLD_PT_stars)
240
241 bpy.types.register(WORLD_PT_custom_props)