e44d71025112f91675bbf806009c57cfe0aa58f4
[blender.git] / release / ui / buttons_world.py
1
2 import bpy
3
4 # If python version is less than 2.4, try to get set stuff from module
5 try:
6         set
7 except:
8         from sets import Set as set
9
10 class WorldButtonsPanel(bpy.types.Panel):
11         __space_type__ = "BUTTONS_WINDOW"
12         __region_type__ = "WINDOW"
13         __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 != None) and (not rd.use_game_engine) and (rd.engine in self.COMPAT_ENGINES)
19
20 class WORLD_PT_preview(WorldButtonsPanel):
21         __label__ = "Preview"
22         COMPAT_ENGINES = set(['BLENDER_RENDER'])
23         
24         def draw(self, context):
25                 layout = self.layout
26                 world = context.world
27                 
28                 layout.template_preview(world)
29         
30 class WORLD_PT_context_world(WorldButtonsPanel):
31         __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 class WORLD_PT_world(WorldButtonsPanel):
53         __label__ = "World"
54         COMPAT_ENGINES = set(['BLENDER_RENDER'])
55
56         def draw(self, context):
57                 layout = self.layout
58
59                 world = context.world
60
61                 if world:
62                 
63                         row = layout.row()
64                         row.itemR(world, "blend_sky")
65                         row.itemR(world, "paper_sky")
66                         row.itemR(world, "real_sky")
67                         
68                         row = layout.row()
69                         row.column().itemR(world, "horizon_color")
70                         col = row.column()
71                         col.itemR(world, "zenith_color")
72                         col.active = world.blend_sky
73                         row.column().itemR(world, "ambient_color")
74                 
75 class WORLD_PT_mist(WorldButtonsPanel):
76         __label__ = "Mist"
77         COMPAT_ENGINES = set(['BLENDER_RENDER'])
78
79         def draw_header(self, context):
80                 layout = self.layout
81                 world = context.world
82
83                 layout.itemR(world.mist, "enabled", text="")
84
85         def draw(self, context):
86                 layout = self.layout
87                 world = context.world
88
89                 layout.active = world.mist.enabled
90
91                 flow = layout.column_flow()
92                 flow.itemR(world.mist, "start")
93                 flow.itemR(world.mist, "depth")
94                 flow.itemR(world.mist, "height")
95                 flow.itemR(world.mist, "intensity", slider=True)
96
97                 layout.itemR(world.mist, "falloff")
98                 
99 class WORLD_PT_stars(WorldButtonsPanel):
100         __label__ = "Stars"
101         COMPAT_ENGINES = set(['BLENDER_RENDER'])
102
103         def draw_header(self, context):
104                 layout = self.layout
105                 world = context.world
106
107                 layout.itemR(world.stars, "enabled", text="")
108
109         def draw(self, context):
110                 layout = self.layout
111                 world = context.world
112
113                 layout.active = world.stars.enabled
114
115                 flow = layout.column_flow()
116                 flow.itemR(world.stars, "size")
117                 flow.itemR(world.stars, "color_randomization", text="Colors")
118                 flow.itemR(world.stars, "min_distance", text="Min. Dist")
119                 flow.itemR(world.stars, "average_separation", text="Separation")
120                 
121 class WORLD_PT_ambient_occlusion(WorldButtonsPanel):
122         __label__ = "Ambient Occlusion"
123         COMPAT_ENGINES = set(['BLENDER_RENDER'])
124
125         def draw_header(self, context):
126                 layout = self.layout
127                 world = context.world
128
129                 layout.itemR(world.ambient_occlusion, "enabled", text="")
130
131         def draw(self, context):
132                 layout = self.layout
133                 ao = context.world.ambient_occlusion
134                 
135                 layout.active = ao.enabled
136                 
137                 layout.itemR(ao, "gather_method", expand=True)
138
139                 split = layout.split()
140                 
141                 col = split.column()
142                 col.itemL(text="Attenuation:")
143                 col.itemR(ao, "distance")
144                 col.itemR(ao, "falloff")
145                 sub = col.row()
146                 sub.active = ao.falloff
147                 sub.itemR(ao, "falloff_strength", text="Strength")
148         
149                 if ao.gather_method == 'RAYTRACE':
150                         col = split.column()
151                         
152                         col.itemL(text="Sampling:")
153                         col.itemR(ao, "sample_method", text="")
154
155                         sub = col.column(align=True)
156                         sub.itemR(ao, "samples")
157
158                         if ao.sample_method == 'ADAPTIVE_QMC':
159                                 sub.itemR(ao, "threshold")
160                                 sub.itemR(ao, "adapt_to_speed")
161                         elif ao.sample_method == 'CONSTANT_JITTERED':
162                                 sub.itemR(ao, "bias")
163                                                 
164                 if ao.gather_method == 'APPROXIMATE':
165                         col = split.column()
166                         
167                         col.itemL(text="Sampling:")
168                         col.itemR(ao, "error_tolerance", text="Error")
169                         col.itemR(ao, "pixel_cache")
170                         col.itemR(ao, "correction")
171                         
172                 col = layout.column()
173                 col.itemL(text="Influence:")
174                 
175                 col.row().itemR(ao, "blend_mode", expand=True)
176                 
177                 split = layout.split()
178                 
179                 col = split.column()
180                 col.itemR(ao, "energy")
181                 
182                 col = split.column()
183                 colsub = col.split(percentage=0.3)
184                 colsub.itemL(text="Color:")
185                 colsub.itemR(ao, "color", text="")
186                 
187
188 bpy.types.register(WORLD_PT_context_world)      
189 bpy.types.register(WORLD_PT_preview)
190 bpy.types.register(WORLD_PT_world)
191 bpy.types.register(WORLD_PT_ambient_occlusion)
192 bpy.types.register(WORLD_PT_mist)
193 bpy.types.register(WORLD_PT_stars)
194