a9310fcc532f57a1778297c85b6081b270d366b3
[blender.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 rna_prop_ui import PropertyPanel
22
23
24 class SceneButtonsPanel():
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "scene"
28
29     @classmethod
30     def poll(cls, context):
31         return context.scene
32
33
34 class SCENE_PT_scene(SceneButtonsPanel, bpy.types.Panel):
35     bl_label = "Scene"
36     COMPAT_ENGINES = {'BLENDER_RENDER'}
37
38     def draw(self, context):
39         layout = self.layout
40         scene = context.scene
41
42         layout.prop(scene, "camera")
43         layout.prop(scene, "background_set", text="Background")
44
45
46 class SCENE_PT_audio(SceneButtonsPanel, bpy.types.Panel):
47     bl_label = "Audio"
48     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
49
50     def draw(self, context):
51         layout = self.layout
52         scene = context.scene
53         rd = context.scene.render
54
55         layout.prop(scene, "audio_volume")
56         layout.operator("sound.bake_animation")
57
58         split = layout.split()
59
60         col = split.column()
61
62         col.label("Listener:")
63         col.prop(scene, "audio_distance_model", text="")
64         col.prop(scene, "audio_doppler_speed", text="Speed")
65         col.prop(scene, "audio_doppler_factor", text="Doppler")
66
67         col = split.column()
68
69         col.label("Format:")
70         col.prop(rd, "ffmpeg_audio_channels", text="")
71         col.prop(rd, "ffmpeg_audio_mixrate", text="Rate")
72
73
74 class SCENE_PT_unit(SceneButtonsPanel, bpy.types.Panel):
75     bl_label = "Units"
76     COMPAT_ENGINES = {'BLENDER_RENDER'}
77
78     def draw(self, context):
79         layout = self.layout
80         unit = context.scene.unit_settings
81
82         col = layout.column()
83         col.row().prop(unit, "system", expand=True)
84         col.row().prop(unit, "system_rotation", expand=True)
85
86         row = layout.row()
87         row.active = (unit.system != 'NONE')
88         row.prop(unit, "scale_length", text="Scale")
89         row.prop(unit, "use_separate")
90
91
92 class SCENE_PT_keying_sets(SceneButtonsPanel, bpy.types.Panel):
93     bl_label = "Keying Sets"
94
95     def draw(self, context):
96         layout = self.layout
97
98         scene = context.scene
99         row = layout.row()
100
101         col = row.column()
102         col.template_list(scene, "keying_sets", scene.keying_sets, "active_index", rows=2)
103
104         col = row.column(align=True)
105         col.operator("anim.keying_set_add", icon='ZOOMIN', text="")
106         col.operator("anim.keying_set_remove", icon='ZOOMOUT', text="")
107
108         ks = scene.keying_sets.active
109         if ks and ks.is_path_absolute:
110             row = layout.row()
111
112             col = row.column()
113             col.prop(ks, "name")
114
115             subcol = col.column()
116             subcol.operator_context = 'INVOKE_DEFAULT'
117             op = subcol.operator("anim.keying_set_export", text="Export to File")
118             op.filepath = "keyingset.py"
119
120             col = row.column()
121             col.label(text="Keyframing Settings:")
122             col.prop(ks, "bl_options")
123
124
125 class SCENE_PT_keying_set_paths(SceneButtonsPanel, bpy.types.Panel):
126     bl_label = "Active Keying Set"
127
128     @classmethod
129     def poll(cls, context):
130         ks = context.scene.keying_sets.active
131         return (ks and ks.is_path_absolute)
132
133     def draw(self, context):
134         layout = self.layout
135
136         scene = context.scene
137         ks = scene.keying_sets.active
138
139         row = layout.row()
140         row.label(text="Paths:")
141
142         row = layout.row()
143
144         col = row.column()
145         col.template_list(ks, "paths", ks.paths, "active_index", rows=2)
146
147         col = row.column(align=True)
148         col.operator("anim.keying_set_path_add", icon='ZOOMIN', text="")
149         col.operator("anim.keying_set_path_remove", icon='ZOOMOUT', text="")
150
151         ksp = ks.paths.active
152         if ksp:
153             col = layout.column()
154             col.label(text="Target:")
155             col.template_any_ID(ksp, "id", "id_type")
156             col.template_path_builder(ksp, "data_path", ksp.id)
157
158             row = layout.row()
159
160             col = row.column()
161             col.label(text="Array Target:")
162             col.prop(ksp, "use_entire_array")
163             if ksp.use_entire_array is False:
164                 col.prop(ksp, "array_index")
165
166             col = row.column()
167             col.label(text="F-Curve Grouping:")
168             col.prop(ksp, "group_method")
169             if ksp.group_method == 'NAMED':
170                 col.prop(ksp, "group")
171
172             col.prop(ksp, "bl_options")
173
174
175 class SCENE_PT_physics(SceneButtonsPanel, bpy.types.Panel):
176     bl_label = "Gravity"
177     COMPAT_ENGINES = {'BLENDER_RENDER'}
178
179     def draw_header(self, context):
180         self.layout.prop(context.scene, "use_gravity", text="")
181
182     def draw(self, context):
183         layout = self.layout
184
185         scene = context.scene
186
187         layout.active = scene.use_gravity
188
189         layout.prop(scene, "gravity", text="")
190
191
192 class SCENE_PT_simplify(SceneButtonsPanel, bpy.types.Panel):
193     bl_label = "Simplify"
194     COMPAT_ENGINES = {'BLENDER_RENDER'}
195
196     def draw_header(self, context):
197         scene = context.scene
198         rd = scene.render
199         self.layout.prop(rd, "use_simplify", text="")
200
201     def draw(self, context):
202         layout = self.layout
203         scene = context.scene
204         rd = scene.render
205
206         layout.active = rd.use_simplify
207
208         split = layout.split()
209
210         col = split.column()
211         col.prop(rd, "simplify_subdivision", text="Subdivision")
212         col.prop(rd, "simplify_child_particles", text="Child Particles")
213
214         col.prop(rd, "use_simplify_triangulate")
215
216         col = split.column()
217         col.prop(rd, "simplify_shadow_samples", text="Shadow Samples")
218         col.prop(rd, "simplify_ao_sss", text="AO and SSS")
219
220
221 class SCENE_PT_custom_props(SceneButtonsPanel, PropertyPanel, bpy.types.Panel):
222     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
223     _context_path = "scene"
224     _property_type = bpy.types.Scene
225
226 #  XXX, move operator to op/ dir
227
228
229 class ANIM_OT_keying_set_export(bpy.types.Operator):
230     "Export Keying Set to a python script."
231     bl_idname = "anim.keying_set_export"
232     bl_label = "Export Keying Set..."
233
234     filepath = bpy.props.StringProperty(name="File Path", description="Filepath to write file to.")
235     filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
236     filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
237     filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
238
239     def execute(self, context):
240         if not self.filepath:
241             raise Exception("Filepath not set.")
242
243         f = open(self.filepath, "w")
244         if not f:
245             raise Exception("Could not open file.")
246
247         scene = context.scene
248         ks = scene.keying_sets.active
249
250         f.write("# Keying Set: %s\n" % ks.name)
251
252         f.write("import bpy\n\n")
253         f.write("scene= bpy.data.scenes[0]\n\n")  # XXX, why not use the current scene?
254
255         # Add KeyingSet and set general settings
256         f.write("# Keying Set Level declarations\n")
257         f.write("ks= scene.keying_sets.new(name=\"%s\")\n" % ks.name)
258
259         if not ks.is_path_absolute:
260             f.write("ks.is_path_absolute = False\n")
261         f.write("\n")
262
263         f.write("ks.bl_options = %r\n" % ks.bl_options)
264         f.write("\n")
265
266         # generate and write set of lookups for id's used in paths
267         id_to_paths_cache = {}  # cache for syncing ID-blocks to bpy paths + shorthands
268
269         for ksp in ks.paths:
270             if ksp.id is None:
271                 continue
272             if ksp.id in id_to_paths_cache:
273                 continue
274
275             # - idtype_list is used to get the list of id-datablocks from bpy.data.*
276             #   since this info isn't available elsewhere
277             # - id.bl_rna.name gives a name suitable for UI,
278             #   with a capitalised first letter, but we need
279             #   the plural form that's all lower case
280             idtype_list = ksp.id.bl_rna.name.lower() + "s"
281             id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, ksp.id.name)
282
283             # shorthand ID for the ID-block (as used in the script)
284             short_id = "id_%d" % len(id_to_paths_cache)
285
286             # store this in the cache now
287             id_to_paths_cache[ksp.id] = [short_id, id_bpy_path]
288
289         f.write("# ID's that are commonly used\n")
290         for id_pair in id_to_paths_cache.values():
291             f.write("%s = %s\n" % (id_pair[0], id_pair[1]))
292         f.write("\n")
293
294         # write paths
295         f.write("# Path Definitions\n")
296         for ksp in ks.paths:
297             f.write("ksp = ks.paths.add(")
298
299             # id-block + data_path
300             if ksp.id:
301                 # find the relevant shorthand from the cache
302                 id_bpy_path = id_to_paths_cache[ksp.id][0]
303             else:
304                 id_bpy_path = "None"  # XXX...
305             f.write("%s, '%s'" % (id_bpy_path, ksp.data_path))
306
307             # array index settings (if applicable)
308             if ksp.use_entire_array:
309                 f.write(", index=-1")
310             else:
311                 f.write(", index=%d" % ksp.array_index)
312
313             # grouping settings (if applicable)
314             # NOTE: the current default is KEYINGSET, but if this changes, change this code too
315             if ksp.group_method == 'NAMED':
316                 f.write(", group_method='%s', group_name=\"%s\"" % (ksp.group_method, ksp.group))
317             elif ksp.group_method != 'KEYINGSET':
318                 f.write(", group_method='%s'" % ksp.group_method)
319
320             # finish off
321             f.write(")\n")
322
323         f.write("\n")
324         f.close()
325
326         return {'FINISHED'}
327
328     def invoke(self, context, event):
329         wm = context.window_manager
330         wm.fileselect_add(self)
331         return {'RUNNING_MODAL'}
332
333 if __name__ == "__main__":  # only for live edit.
334     bpy.utils.register_module(__name__)