COLLADA: merge from trunk -r 24390:24522.
[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
22 narrowui = 180
23
24 class WorldButtonsPanel(bpy.types.Panel):
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     def poll(self, context):
31         rd = context.scene.render_data
32         return (context.world) and (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
33
34
35 class WORLD_PT_preview(WorldButtonsPanel):
36     bl_label = "Preview"
37     COMPAT_ENGINES = set(['BLENDER_RENDER'])
38
39     def draw(self, context):
40         self.layout.template_preview(context.world)
41
42
43 class WORLD_PT_context_world(WorldButtonsPanel):
44     bl_label = ""
45     bl_show_header = False
46     COMPAT_ENGINES = set(['BLENDER_RENDER'])
47
48     def poll(self, context):
49         rd = context.scene.render_data
50         return (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
51
52     def draw(self, context):
53         layout = self.layout
54
55         scene = context.scene
56         world = context.world
57         space = context.space_data
58
59         split = layout.split(percentage=0.65)
60
61         if scene:
62             split.template_ID(scene, "world", new="world.new")
63         elif world:
64             split.template_ID(space, "pin_id")
65
66
67 class WORLD_PT_world(WorldButtonsPanel):
68     bl_label = "World"
69     COMPAT_ENGINES = set(['BLENDER_RENDER'])
70
71     def draw(self, context):
72         layout = self.layout
73         col2 = context.region.width > narrowui
74         world = context.world
75         
76         if col2:
77             row = layout.row()
78             row.itemR(world, "paper_sky")
79             row.itemR(world, "blend_sky")
80             row.itemR(world, "real_sky")
81         else:
82             col = layout.column()
83             col.itemR(world, "paper_sky")
84             col.itemR(world, "blend_sky")
85             col.itemR(world, "real_sky")
86
87         row = layout.row()
88         row.column().itemR(world, "horizon_color")
89         col = row.column()
90         col.itemR(world, "zenith_color")
91         col.active = world.blend_sky
92         row.column().itemR(world, "ambient_color")
93
94
95 class WORLD_PT_mist(WorldButtonsPanel):
96     bl_label = "Mist"
97     COMPAT_ENGINES = set(['BLENDER_RENDER'])
98
99     def draw_header(self, context):
100         world = context.world
101
102         self.layout.itemR(world.mist, "enabled", text="")
103
104     def draw(self, context):
105         layout = self.layout
106         col2 = context.region.width > narrowui
107         world = context.world
108
109         layout.active = world.mist.enabled
110         
111         split = layout.split()
112         
113         col = split.column()
114         col.itemR(world.mist, "intensity", slider=True)
115         col.itemR(world.mist, "start")
116
117         if col2:
118             col = split.column()
119         col.itemR(world.mist, "depth")
120         col.itemR(world.mist, "height")
121
122         layout.itemR(world.mist, "falloff")
123
124
125 class WORLD_PT_stars(WorldButtonsPanel):
126     bl_label = "Stars"
127     COMPAT_ENGINES = set(['BLENDER_RENDER'])
128
129     def draw_header(self, context):
130         world = context.world
131
132         self.layout.itemR(world.stars, "enabled", text="")
133
134     def draw(self, context):
135         layout = self.layout
136         col2 = context.region.width > narrowui
137         world = context.world
138
139         layout.active = world.stars.enabled
140
141         split = layout.split()
142         
143         col = split.column()
144         col.itemR(world.stars, "size")
145         col.itemR(world.stars, "color_randomization", text="Colors")
146
147         if col2:
148             col = split.column()
149         col.itemR(world.stars, "min_distance", text="Min. Dist")
150         col.itemR(world.stars, "average_separation", text="Separation")
151
152
153 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
154     bl_label = "Ambient Occlusion"
155     COMPAT_ENGINES = set(['BLENDER_RENDER'])
156
157     def draw_header(self, context):
158         world = context.world
159
160         self.layout.itemR(world.ambient_occlusion, "enabled", text="")
161
162     def draw(self, context):
163         layout = self.layout
164         col2 = context.region.width > narrowui
165         ao = context.world.ambient_occlusion
166
167         layout.active = ao.enabled
168
169         layout.itemR(ao, "gather_method", expand=True)
170
171         split = layout.split()
172
173         col = split.column()
174         col.itemL(text="Attenuation:")
175         if ao.gather_method == 'RAYTRACE':
176             col.itemR(ao, "distance")
177         col.itemR(ao, "falloff")
178         sub = col.row()
179         sub.active = ao.falloff
180         sub.itemR(ao, "falloff_strength", text="Strength")
181
182         if ao.gather_method == 'RAYTRACE':
183             if col2:
184                 col = split.column()
185
186             col.itemL(text="Sampling:")
187             col.itemR(ao, "sample_method", text="")
188
189             sub = col.column()
190             sub.itemR(ao, "samples")
191
192             if ao.sample_method == 'ADAPTIVE_QMC':
193                 sub.itemR(ao, "threshold")
194                 sub.itemR(ao, "adapt_to_speed", slider=True)
195             elif ao.sample_method == 'CONSTANT_JITTERED':
196                 sub.itemR(ao, "bias")
197
198         if ao.gather_method == 'APPROXIMATE':
199             if col2:
200                 col = split.column()
201
202             col.itemL(text="Sampling:")
203             col.itemR(ao, "passes")
204             col.itemR(ao, "error_tolerance", text="Error")
205             col.itemR(ao, "pixel_cache")
206             col.itemR(ao, "correction")
207
208         col = layout.column()
209         col.itemL(text="Influence:")
210
211         col.row().itemR(ao, "blend_mode", expand=True)
212
213         split = layout.split()
214
215         col = split.column()
216         col.itemR(ao, "energy")
217
218         if col2:
219             col = split.column()
220         col.itemR(ao, "color")
221
222 bpy.types.register(WORLD_PT_context_world)
223 bpy.types.register(WORLD_PT_preview)
224 bpy.types.register(WORLD_PT_world)
225 bpy.types.register(WORLD_PT_ambient_occlusion)
226 bpy.types.register(WORLD_PT_mist)
227 bpy.types.register(WORLD_PT_stars)