facf54d358a0778e272a3f6690a217a89b11a8d8
[blender-staging.git] / release / scripts / startup / bl_ui / properties_scene.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Panel, UIList
22 from rna_prop_ui import PropertyPanel
23
24 from bl_ui.properties_physics_common import (
25         point_cache_ui,
26         effector_weights_ui,
27         )
28
29
30 class SCENE_UL_keying_set_paths(UIList):
31     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
32         # assert(isinstance(item, bpy.types.KeyingSetPath)
33         kspath = item
34         icon = layout.enum_item_icon(kspath, "id_type", kspath.id_type)
35         if self.layout_type in {'DEFAULT', 'COMPACT'}:
36             # Do not make this one editable in uiList for now...
37             layout.label(text=kspath.data_path, translate=False, icon_value=icon)
38         elif self.layout_type in {'GRID'}:
39             layout.alignment = 'CENTER'
40             layout.label(text="", icon_value=icon)
41
42
43 class SceneButtonsPanel:
44     bl_space_type = 'PROPERTIES'
45     bl_region_type = 'WINDOW'
46     bl_context = "scene"
47
48     @classmethod
49     def poll(cls, context):
50         rd = context.scene.render
51         return context.scene and (rd.engine in cls.COMPAT_ENGINES)
52
53
54 class SCENE_PT_scene(SceneButtonsPanel, Panel):
55     bl_label = "Scene"
56     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
57
58     def draw(self, context):
59         layout = self.layout
60
61         scene = context.scene
62
63         layout.prop(scene, "camera")
64         layout.prop(scene, "background_set", text="Background")
65         if context.scene.render.engine != 'BLENDER_GAME':
66             layout.prop(scene, "active_clip", text="Active Clip")
67
68
69 class SCENE_PT_unit(SceneButtonsPanel, Panel):
70     bl_label = "Units"
71     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
72
73     def draw(self, context):
74         layout = self.layout
75
76         unit = context.scene.unit_settings
77
78         col = layout.column()
79         col.row().prop(unit, "system", expand=True)
80         col.row().prop(unit, "system_rotation", expand=True)
81
82         if unit.system != 'NONE':
83             row = layout.row()
84             row.prop(unit, "scale_length", text="Scale")
85             row.prop(unit, "use_separate")
86
87
88 class SceneKeyingSetsPanel:
89     def draw_keyframing_settings(self, context, layout, ks, ksp):
90         self.draw_keyframing_setting(context, layout, ks, ksp, "Needed",
91                                      "use_insertkey_override_needed", "use_insertkey_needed",
92                                      userpref_fallback="use_keyframe_insert_needed")
93
94         self.draw_keyframing_setting(context, layout, ks, ksp, "Visual",
95                                      "use_insertkey_override_visual", "use_insertkey_visual",
96                                      userpref_fallback="use_visual_keying")
97
98         self.draw_keyframing_setting(context, layout, ks, ksp, "XYZ to RGB",
99                                      "use_insertkey_override_xyz_to_rgb", "use_insertkey_xyz_to_rgb")
100
101     def draw_keyframing_setting(self, context, layout, ks, ksp, label, toggle_prop, prop, userpref_fallback=None):
102         if ksp:
103             item = ksp
104
105             if getattr(ks, toggle_prop):
106                 owner = ks
107                 propname = prop
108             else:
109                 owner = context.user_preferences.edit
110                 if userpref_fallback:
111                     propname = userpref_fallback
112                 else:
113                     propname = prop
114         else:
115             item = ks
116
117             owner = context.user_preferences.edit
118             if userpref_fallback:
119                 propname = userpref_fallback
120             else:
121                 propname = prop
122
123         row = layout.row(align=True)
124         row.prop(item, toggle_prop, text="", icon='STYLUS_PRESSURE', toggle=True)  # XXX: needs dedicated icon
125
126         subrow = row.row()
127         subrow.active = getattr(item, toggle_prop)
128         if subrow.active:
129             subrow.prop(item, prop, text=label)
130         else:
131             subrow.prop(owner, propname, text=label)
132
133
134 class SCENE_PT_keying_sets(SceneButtonsPanel, SceneKeyingSetsPanel, Panel):
135     bl_label = "Keying Sets"
136     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
137
138     def draw(self, context):
139         layout = self.layout
140
141         scene = context.scene
142         row = layout.row()
143
144         col = row.column()
145         col.template_list("UI_UL_list", "keying_sets", scene, "keying_sets", scene.keying_sets, "active_index", rows=1)
146
147         col = row.column(align=True)
148         col.operator("anim.keying_set_add", icon='ZOOMIN', text="")
149         col.operator("anim.keying_set_remove", icon='ZOOMOUT', text="")
150
151         ks = scene.keying_sets.active
152         if ks and ks.is_path_absolute:
153             row = layout.row()
154
155             col = row.column()
156             col.prop(ks, "bl_description")
157
158             subcol = col.column()
159             subcol.operator_context = 'INVOKE_DEFAULT'
160             subcol.operator("anim.keying_set_export", text="Export to File").filepath = "keyingset.py"
161
162             col = row.column()
163             col.label(text="Keyframing Settings:")
164             self.draw_keyframing_settings(context, col, ks, None)
165
166
167 class SCENE_PT_keying_set_paths(SceneButtonsPanel, SceneKeyingSetsPanel, Panel):
168     bl_label = "Active Keying Set"
169     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
170
171     @classmethod
172     def poll(cls, context):
173         ks = context.scene.keying_sets.active
174         return (ks and ks.is_path_absolute)
175
176     def draw(self, context):
177         layout = self.layout
178
179         scene = context.scene
180         ks = scene.keying_sets.active
181
182         row = layout.row()
183         row.label(text="Paths:")
184
185         row = layout.row()
186
187         col = row.column()
188         col.template_list("SCENE_UL_keying_set_paths", "", ks, "paths", ks.paths, "active_index", rows=1)
189
190         col = row.column(align=True)
191         col.operator("anim.keying_set_path_add", icon='ZOOMIN', text="")
192         col.operator("anim.keying_set_path_remove", icon='ZOOMOUT', text="")
193
194         ksp = ks.paths.active
195         if ksp:
196             col = layout.column()
197             col.label(text="Target:")
198             col.template_any_ID(ksp, "id", "id_type")
199             col.template_path_builder(ksp, "data_path", ksp.id)
200
201             row = col.row(align=True)
202             row.label(text="Array Target:")
203             row.prop(ksp, "use_entire_array", text="All Items")
204             if ksp.use_entire_array:
205                 row.label(text=" ")  # padding
206             else:
207                 row.prop(ksp, "array_index", text="Index")
208
209             layout.separator()
210
211             row = layout.row()
212             col = row.column()
213             col.label(text="F-Curve Grouping:")
214             col.prop(ksp, "group_method", text="")
215             if ksp.group_method == 'NAMED':
216                 col.prop(ksp, "group")
217
218             col = row.column()
219             col.label(text="Keyframing Settings:")
220             self.draw_keyframing_settings(context, col, ks, ksp)
221
222
223 class SCENE_PT_color_management(SceneButtonsPanel, Panel):
224     bl_label = "Color Management"
225     bl_options = {'DEFAULT_CLOSED'}
226     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
227
228     def draw(self, context):
229         layout = self.layout
230
231         scene = context.scene
232
233         col = layout.column()
234         col.label(text="Display:")
235         col.prop(scene.display_settings, "display_device")
236
237         col = layout.column()
238         col.separator()
239         col.label(text="Render:")
240         col.template_colormanaged_view_settings(scene, "view_settings")
241
242         col = layout.column()
243         col.separator()
244         col.label(text="Sequencer:")
245         col.prop(scene.sequencer_colorspace_settings, "name")
246
247
248 class SCENE_PT_audio(SceneButtonsPanel, Panel):
249     bl_label = "Audio"
250     bl_options = {'DEFAULT_CLOSED'}
251     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
252
253     def draw(self, context):
254         layout = self.layout
255
256         scene = context.scene
257         rd = context.scene.render
258         ffmpeg = rd.ffmpeg
259
260         layout.prop(scene, "audio_volume")
261         layout.operator("sound.bake_animation")
262
263         split = layout.split()
264
265         col = split.column()
266         col.label("Distance Model:")
267         col.prop(scene, "audio_distance_model", text="")
268         sub = col.column(align=True)
269         sub.prop(scene, "audio_doppler_speed", text="Speed")
270         sub.prop(scene, "audio_doppler_factor", text="Doppler")
271
272         col = split.column()
273         col.label("Format:")
274         col.prop(ffmpeg, "audio_channels", text="")
275         col.prop(ffmpeg, "audio_mixrate", text="Rate")
276
277
278 class SCENE_PT_physics(SceneButtonsPanel, Panel):
279     bl_label = "Gravity"
280     COMPAT_ENGINES = {'BLENDER_RENDER'}
281
282     def draw_header(self, context):
283         self.layout.prop(context.scene, "use_gravity", text="")
284
285     def draw(self, context):
286         layout = self.layout
287
288         scene = context.scene
289
290         layout.active = scene.use_gravity
291
292         layout.prop(scene, "gravity", text="")
293
294
295 class SCENE_PT_rigid_body_world(SceneButtonsPanel, Panel):
296     bl_label = "Rigid Body World"
297     COMPAT_ENGINES = {'BLENDER_RENDER'}
298
299     @classmethod
300     def poll(cls, context):
301         scene = context.scene
302         rd = scene.render
303         return scene and (rd.engine in cls.COMPAT_ENGINES)
304
305     def draw_header(self, context):
306         scene = context.scene
307         rbw = scene.rigidbody_world
308         if rbw is not None:
309             self.layout.prop(rbw, "enabled", text="")
310
311     def draw(self, context):
312         layout = self.layout
313
314         scene = context.scene
315
316         rbw = scene.rigidbody_world
317
318         if rbw is None:
319             layout.operator("rigidbody.world_add")
320         else:
321             layout.operator("rigidbody.world_remove")
322
323             col = layout.column()
324             col.active = rbw.enabled
325
326             col = col.column()
327             col.prop(rbw, "group")
328             col.prop(rbw, "constraints")
329
330             split = col.split()
331
332             col = split.column()
333             col.prop(rbw, "time_scale", text="Speed")
334             col.prop(rbw, "use_split_impulse")
335
336             col = split.column()
337             col.prop(rbw, "steps_per_second", text="Steps Per Second")
338             col.prop(rbw, "solver_iterations", text="Solver Iterations")
339
340
341 class SCENE_PT_rigid_body_cache(SceneButtonsPanel, Panel):
342     bl_label = "Rigid Body Cache"
343     bl_options = {'DEFAULT_CLOSED'}
344     COMPAT_ENGINES = {'BLENDER_RENDER'}
345
346     @classmethod
347     def poll(cls, context):
348         rd = context.scene.render
349         scene = context.scene
350         return scene and scene.rigidbody_world and (rd.engine in cls.COMPAT_ENGINES)
351
352     def draw(self, context):
353         scene = context.scene
354         rbw = scene.rigidbody_world
355
356         point_cache_ui(self, context, rbw.point_cache, rbw.point_cache.is_baked is False and rbw.enabled, 'RIGID_BODY')
357
358
359 class SCENE_PT_rigid_body_field_weights(SceneButtonsPanel, Panel):
360     bl_label = "Rigid Body Field Weights"
361     bl_options = {'DEFAULT_CLOSED'}
362     COMPAT_ENGINES = {'BLENDER_RENDER'}
363
364     @classmethod
365     def poll(cls, context):
366         rd = context.scene.render
367         scene = context.scene
368         return scene and scene.rigidbody_world and (rd.engine in cls.COMPAT_ENGINES)
369
370     def draw(self, context):
371         scene = context.scene
372         rbw = scene.rigidbody_world
373
374         effector_weights_ui(self, context, rbw.effector_weights, 'RIGID_BODY')
375
376
377 class SCENE_PT_simplify(SceneButtonsPanel, Panel):
378     bl_label = "Simplify"
379     COMPAT_ENGINES = {'BLENDER_RENDER'}
380
381     def draw_header(self, context):
382         rd = context.scene.render
383         self.layout.prop(rd, "use_simplify", text="")
384
385     def draw(self, context):
386         layout = self.layout
387
388         rd = context.scene.render
389
390         layout.active = rd.use_simplify
391
392         split = layout.split()
393
394         col = split.column()
395         col.prop(rd, "simplify_subdivision", text="Subdivision")
396         col.prop(rd, "simplify_child_particles", text="Child Particles")
397
398         col.prop(rd, "use_simplify_triangulate")
399
400         col = split.column()
401         col.prop(rd, "simplify_shadow_samples", text="Shadow Samples")
402         col.prop(rd, "simplify_ao_sss", text="AO and SSS")
403
404
405 class SCENE_PT_custom_props(SceneButtonsPanel, PropertyPanel, Panel):
406     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
407     _context_path = "scene"
408     _property_type = bpy.types.Scene
409
410 if __name__ == "__main__":  # only for live edit.
411     bpy.utils.register_module(__name__)