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