made scripts pass the pep8 test (though not fully pep8 yet)
[blender-staging.git] / release / scripts / ui / properties_world.py
1 # This software is distributable under the terms of the GNU
2 # General Public License (GPL) v2, the text of which can be found at
3 # http://www.gnu.org/copyleft/gpl.html. Installing, importing or otherwise
4 # using this module constitutes acceptance of the terms of this License.
5
6 # <pep8 compliant>
7 import bpy
8
9
10 class WorldButtonsPanel(bpy.types.Panel):
11     bl_space_type = 'PROPERTIES'
12     bl_region_type = 'WINDOW'
13     bl_context = "world"
14     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
15
16     def poll(self, context):
17         rd = context.scene.render_data
18         return (context.world) and (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
19
20
21 class WORLD_PT_preview(WorldButtonsPanel):
22     bl_label = "Preview"
23     COMPAT_ENGINES = set(['BLENDER_RENDER'])
24
25     def draw(self, context):
26         self.layout.template_preview(context.world)
27
28
29 class WORLD_PT_context_world(WorldButtonsPanel):
30     bl_label = ""
31     bl_show_header = False
32     COMPAT_ENGINES = set(['BLENDER_RENDER'])
33
34     def poll(self, context):
35         rd = context.scene.render_data
36         return (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
37
38     def draw(self, context):
39         layout = self.layout
40
41         scene = context.scene
42         world = context.world
43         space = context.space_data
44
45         split = layout.split(percentage=0.65)
46
47         if scene:
48             split.template_ID(scene, "world", new="world.new")
49         elif world:
50             split.template_ID(space, "pin_id")
51
52
53 class WORLD_PT_world(WorldButtonsPanel):
54     bl_label = "World"
55     COMPAT_ENGINES = set(['BLENDER_RENDER'])
56
57     def draw(self, context):
58         layout = self.layout
59
60         world = context.world
61
62         row = layout.row()
63         row.itemR(world, "paper_sky")
64         row.itemR(world, "blend_sky")
65         row.itemR(world, "real_sky")
66
67         row = layout.row()
68         row.column().itemR(world, "horizon_color")
69         col = row.column()
70         col.itemR(world, "zenith_color")
71         col.active = world.blend_sky
72         row.column().itemR(world, "ambient_color")
73
74
75 class WORLD_PT_mist(WorldButtonsPanel):
76     bl_label = "Mist"
77     COMPAT_ENGINES = set(['BLENDER_RENDER'])
78
79     def draw_header(self, context):
80         world = context.world
81
82         self.layout.itemR(world.mist, "enabled", text="")
83
84     def draw(self, context):
85         layout = self.layout
86
87         world = context.world
88
89         layout.active = world.mist.enabled
90
91         flow = layout.column_flow()
92         flow.itemR(world.mist, "intensity", slider=True)
93         flow.itemR(world.mist, "start")
94         flow.itemR(world.mist, "depth")
95         flow.itemR(world.mist, "height")
96
97         layout.itemR(world.mist, "falloff")
98
99
100 class WORLD_PT_stars(WorldButtonsPanel):
101     bl_label = "Stars"
102     COMPAT_ENGINES = set(['BLENDER_RENDER'])
103
104     def draw_header(self, context):
105         world = context.world
106
107         self.layout.itemR(world.stars, "enabled", text="")
108
109     def draw(self, context):
110         layout = self.layout
111
112         world = context.world
113
114         layout.active = world.stars.enabled
115
116         flow = layout.column_flow()
117         flow.itemR(world.stars, "size")
118         flow.itemR(world.stars, "color_randomization", text="Colors")
119         flow.itemR(world.stars, "min_distance", text="Min. Dist")
120         flow.itemR(world.stars, "average_separation", text="Separation")
121
122
123 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
124     bl_label = "Ambient Occlusion"
125     COMPAT_ENGINES = set(['BLENDER_RENDER'])
126
127     def draw_header(self, context):
128         world = context.world
129
130         self.layout.itemR(world.ambient_occlusion, "enabled", text="")
131
132     def draw(self, context):
133         layout = self.layout
134
135         ao = context.world.ambient_occlusion
136
137         layout.active = ao.enabled
138
139         layout.itemR(ao, "gather_method", expand=True)
140
141         split = layout.split()
142
143         col = split.column()
144         col.itemL(text="Attenuation:")
145         if ao.gather_method == 'RAYTRACE':
146             col.itemR(ao, "distance")
147         col.itemR(ao, "falloff")
148         sub = col.row()
149         sub.active = ao.falloff
150         sub.itemR(ao, "falloff_strength", text="Strength")
151
152         if ao.gather_method == 'RAYTRACE':
153             col = split.column()
154
155             col.itemL(text="Sampling:")
156             col.itemR(ao, "sample_method", text="")
157
158             sub = col.column()
159             sub.itemR(ao, "samples")
160
161             if ao.sample_method == 'ADAPTIVE_QMC':
162                 sub.itemR(ao, "threshold")
163                 sub.itemR(ao, "adapt_to_speed", slider=True)
164             elif ao.sample_method == 'CONSTANT_JITTERED':
165                 sub.itemR(ao, "bias")
166
167         if ao.gather_method == 'APPROXIMATE':
168             col = split.column()
169
170             col.itemL(text="Sampling:")
171             col.itemR(ao, "passes")
172             col.itemR(ao, "error_tolerance", text="Error")
173             col.itemR(ao, "pixel_cache")
174             col.itemR(ao, "correction")
175
176         col = layout.column()
177         col.itemL(text="Influence:")
178
179         col.row().itemR(ao, "blend_mode", expand=True)
180
181         split = layout.split()
182
183         col = split.column()
184         col.itemR(ao, "energy")
185
186         col = split.column()
187         sub = col.split(percentage=0.3)
188         sub.itemL(text="Color:")
189         sub.itemR(ao, "color", text="")
190
191 bpy.types.register(WORLD_PT_context_world)
192 bpy.types.register(WORLD_PT_preview)
193 bpy.types.register(WORLD_PT_world)
194 bpy.types.register(WORLD_PT_ambient_occlusion)
195 bpy.types.register(WORLD_PT_mist)
196 bpy.types.register(WORLD_PT_stars)