synched with trunk at revision 30243
[blender.git] / release / scripts / 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 narrowui = bpy.context.user_preferences.view.properties_width_check
24
25
26 class SceneButtonsPanel(bpy.types.Panel):
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "scene"
30
31     def poll(self, context):
32         return context.scene
33
34
35 class SCENE_PT_scene(SceneButtonsPanel):
36     bl_label = "Scene"
37     COMPAT_ENGINES = {'BLENDER_RENDER'}
38
39     def draw(self, context):
40         layout = self.layout
41         wide_ui = context.region.width > narrowui
42         scene = context.scene
43
44         if wide_ui:
45             layout.prop(scene, "camera")
46             layout.prop(scene, "set", text="Background")
47         else:
48             layout.prop(scene, "camera", text="")
49             layout.prop(scene, "set", text="")
50
51
52 class SCENE_PT_custom_props(SceneButtonsPanel, PropertyPanel):
53     _context_path = "scene"
54
55
56 class SCENE_PT_unit(SceneButtonsPanel):
57     bl_label = "Units"
58     COMPAT_ENGINES = {'BLENDER_RENDER'}
59
60     def draw(self, context):
61         layout = self.layout
62         wide_ui = context.region.width > narrowui
63         unit = context.scene.unit_settings
64
65         col = layout.column()
66         col.row().prop(unit, "system", expand=True)
67
68         split = layout.split()
69         split.active = (unit.system != 'NONE')
70
71         col = split.column()
72         col.prop(unit, "scale_length", text="Scale")
73
74         if wide_ui:
75             col = split.column()
76         col.prop(unit, "use_separate")
77
78         layout.column().prop(unit, "rotation_units")
79
80
81 class SCENE_PT_keying_sets(SceneButtonsPanel):
82     bl_label = "Keying Sets"
83
84     def draw(self, context):
85         layout = self.layout
86
87         scene = context.scene
88         wide_ui = context.region.width > narrowui
89         row = layout.row()
90
91         col = row.column()
92         col.template_list(scene, "keying_sets", scene, "active_keying_set_index", rows=2)
93
94         col = row.column(align=True)
95         col.operator("anim.keying_set_add", icon='ZOOMIN', text="")
96         col.operator("anim.keying_set_remove", icon='ZOOMOUT', text="")
97
98         ks = scene.active_keying_set
99         if ks and ks.absolute:
100             row = layout.row()
101
102             col = row.column()
103             col.prop(ks, "name")
104
105             subcol = col.column()
106             subcol.operator_context = 'INVOKE_DEFAULT'
107             op = subcol.operator("anim.keying_set_export", text="Export to File")
108             op.filepath = "keyingset.py"
109
110             if wide_ui:
111                 col = row.column()
112             col.label(text="Keyframing Settings:")
113             col.prop(ks, "insertkey_needed", text="Needed")
114             col.prop(ks, "insertkey_visual", text="Visual")
115             col.prop(ks, "insertkey_xyz_to_rgb", text="XYZ to RGB")
116
117
118 class SCENE_PT_keying_set_paths(SceneButtonsPanel):
119     bl_label = "Active Keying Set"
120
121     def poll(self, context):
122         return (context.scene.active_keying_set and context.scene.active_keying_set.absolute)
123
124     def draw(self, context):
125         layout = self.layout
126
127         scene = context.scene
128         ks = scene.active_keying_set
129         wide_ui = context.region.width > narrowui
130
131         row = layout.row()
132         row.label(text="Paths:")
133
134         row = layout.row()
135
136         col = row.column()
137         col.template_list(ks, "paths", ks, "active_path_index", rows=2)
138
139         col = row.column(align=True)
140         col.operator("anim.keying_set_path_add", icon='ZOOMIN', text="")
141         col.operator("anim.keying_set_path_remove", icon='ZOOMOUT', text="")
142
143         ksp = ks.active_path
144         if ksp:
145             col = layout.column()
146             col.label(text="Target:")
147             col.template_any_ID(ksp, "id", "id_type")
148             col.template_path_builder(ksp, "data_path", ksp.id)
149
150
151             row = layout.row()
152
153             col = row.column()
154             col.label(text="Array Target:")
155             col.prop(ksp, "entire_array")
156             if ksp.entire_array is False:
157                 col.prop(ksp, "array_index")
158
159             if wide_ui:
160                 col = row.column()
161             col.label(text="F-Curve Grouping:")
162             col.prop(ksp, "grouping")
163             if ksp.grouping == 'NAMED':
164                 col.prop(ksp, "group")
165
166             col.label(text="Keyframing Settings:")
167             col.prop(ksp, "insertkey_needed", text="Needed")
168             col.prop(ksp, "insertkey_visual", text="Visual")
169             col.prop(ksp, "insertkey_xyz_to_rgb", text="XYZ to RGB")
170
171
172 class SCENE_PT_physics(SceneButtonsPanel):
173     bl_label = "Gravity"
174     COMPAT_ENGINES = {'BLENDER_RENDER'}
175
176     def draw_header(self, context):
177         self.layout.prop(context.scene, "use_gravity", text="")
178
179     def draw(self, context):
180         layout = self.layout
181
182         scene = context.scene
183         wide_ui = context.region.width > narrowui
184
185         layout.active = scene.use_gravity
186
187         if wide_ui:
188             layout.prop(scene, "gravity", text="")
189         else:
190             layout.column().prop(scene, "gravity", text="")
191
192
193 class SCENE_PT_simplify(SceneButtonsPanel):
194     bl_label = "Simplify"
195     COMPAT_ENGINES = {'BLENDER_RENDER'}
196
197     def draw_header(self, context):
198         scene = context.scene
199         rd = scene.render
200         self.layout.prop(rd, "use_simplify", text="")
201
202     def draw(self, context):
203         layout = self.layout
204         scene = context.scene
205         rd = scene.render
206         wide_ui = context.region.width > narrowui
207
208         layout.active = rd.use_simplify
209
210         split = layout.split()
211
212         col = split.column()
213         col.prop(rd, "simplify_subdivision", text="Subdivision")
214         col.prop(rd, "simplify_child_particles", text="Child Particles")
215
216         col.prop(rd, "simplify_triangulate")
217
218         if wide_ui:
219             col = split.column()
220         col.prop(rd, "simplify_shadow_samples", text="Shadow Samples")
221         col.prop(rd, "simplify_ao_sss", text="AO and SSS")
222
223
224 from bpy.props import *
225
226
227 class ANIM_OT_keying_set_export(bpy.types.Operator):
228     "Export Keying Set to a python script."
229     bl_idname = "anim.keying_set_export"
230     bl_label = "Export Keying Set..."
231
232     filepath = bpy.props.StringProperty(name="File Path", description="Filepath to write file to.")
233     filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
234     filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
235     filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
236
237     def execute(self, context):
238         if not self.properties.filepath:
239             raise Exception("Filepath not set.")
240
241         f = open(self.properties.filepath, "w")
242         if not f:
243             raise Exception("Could not open file.")
244
245         scene = context.scene
246         ks = scene.active_keying_set
247
248
249         f.write("# Keying Set: %s\n" % ks.name)
250
251         f.write("import bpy\n\n")
252         f.write("scene= bpy.data.scenes[0]\n\n")
253
254         # Add KeyingSet and set general settings
255         f.write("# Keying Set Level declarations\n")
256         f.write("ks= scene.add_keying_set(name=\"%s\")\n" % ks.name)
257
258         if ks.absolute is False:
259             f.write("ks.absolute = False\n")
260         f.write("\n")
261
262         f.write("ks.insertkey_needed = %s\n" % ks.insertkey_needed)
263         f.write("ks.insertkey_visual = %s\n" % ks.insertkey_visual)
264         f.write("ks.insertkey_xyz_to_rgb = %s\n" % ks.insertkey_xyz_to_rgb)
265         f.write("\n")
266
267
268         # generate and write set of lookups for id's used in paths
269         id_to_paths_cache = {} # cache for syncing ID-blocks to bpy paths + shorthands
270
271         for ksp in ks.paths:
272             if ksp.id is None:
273                 continue
274             if ksp.id in id_to_paths_cache:
275                 continue
276
277             # - idtype_list is used to get the list of id-datablocks from bpy.data.*
278             #   since this info isn't available elsewhere
279             # - id.bl_rna.name gives a name suitable for UI,
280             #   with a capitalised first letter, but we need
281             #   the plural form that's all lower case
282             idtype_list = ksp.id.bl_rna.name.lower() + "s"
283             id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, ksp.id.name)
284
285             # shorthand ID for the ID-block (as used in the script)
286             short_id = "id_%d" % len(id_to_paths_cache)
287
288             # store this in the cache now
289             id_to_paths_cache[ksp.id] = [short_id, id_bpy_path]
290
291         f.write("# ID's that are commonly used\n")
292         for id_pair in id_to_paths_cache.values():
293             f.write("%s = %s\n" % (id_pair[0], id_pair[1]))
294         f.write("\n")
295
296
297         # write paths
298         f.write("# Path Definitions\n")
299         for ksp in ks.paths:
300             f.write("ksp = ks.paths.add(")
301
302             # id-block + data_path
303             if ksp.id:
304                 # find the relevant shorthand from the cache
305                 id_bpy_path = id_to_paths_cache[ksp.id][0]
306             else:
307                 id_bpy_path = "None" # XXX...
308             f.write("%s, '%s'" % (id_bpy_path, ksp.data_path))
309
310             # array index settings (if applicable)
311             if ksp.entire_array:
312                 f.write(", index=-1")
313             else:
314                 f.write(", index=%d" % ksp.array_index)
315
316             # grouping settings (if applicable)
317             # NOTE: the current default is KEYINGSET, but if this changes, change this code too
318             if ksp.grouping == 'NAMED':
319                 f.write(", grouping_method='%s', group_name=\"%s\"" % (ksp.grouping, ksp.group))
320             elif ksp.grouping != 'KEYINGSET':
321                 f.write(", grouping_method='%s'" % ksp.grouping)
322
323             # finish off
324             f.write(")\n")
325
326         f.write("\n")
327         f.close()
328
329         return {'FINISHED'}
330
331     def invoke(self, context, event):
332         wm = context.manager
333         wm.add_fileselect(self)
334         return {'RUNNING_MODAL'}
335
336 class SCENE_PT_navmesh(SceneButtonsPanel):
337     bl_label = "Navmesh"
338     bl_default_closed = True
339     COMPAT_ENGINES = {'BLENDER_RENDER'}
340
341     def draw(self, context):
342         layout = self.layout
343
344         rd = context.scene.game_data.recast_data
345         wide_ui = context.region.width > narrowui
346
347         layout.operator("object.create_navmesh", text='Build navigation mesh')
348
349         layout.label(text="Rasterization:")
350         split = layout.split()
351
352         col = split.column()
353         col.prop(rd, "cellsize")
354         if wide_ui:
355             col = split.column()
356         col.prop(rd, "cellheight")
357
358         layout.separator()
359
360         layout.label(text="Agent:")
361         split = layout.split()
362         col = split.column()
363         row = col.row()
364         row.prop(rd, "agentheight")
365         row = col.row()
366         row.prop(rd, "agentradius")
367         if wide_ui:
368             col = split.column()
369         row = col.row()
370         row.prop(rd, "agentmaxslope")
371         row = col.row()
372         row.prop(rd, "agentmaxclimb")
373
374         layout.separator()
375
376         layout.label(text="Region:")
377         split = layout.split()
378         col = split.column()
379         col.prop(rd, "regionminsize")
380         if wide_ui:
381             col = split.column()
382         col.prop(rd, "regionmergesize")
383
384         layout.separator()
385
386         layout.label(text="Polygonization:")
387         split = layout.split()
388         col = split.column()
389         row = col.row()
390         row.prop(rd, "edgemaxlen")
391         row = col.row()
392         row.prop(rd, "edgemaxerror")
393         if wide_ui:
394             col = split.column()
395         row = col.row()
396         row.prop(rd, "vertsperpoly")
397
398         layout.separator()
399
400         layout.label(text="Detail Mesh:")
401         split = layout.split()
402         col = split.column()
403         col.prop(rd, "detailsampledist")
404         if wide_ui:
405             col = split.column()
406         col.prop(rd, "detailsamplemaxerror")
407
408
409 classes = [
410     SCENE_PT_scene,
411     SCENE_PT_unit,
412     SCENE_PT_keying_sets,
413     SCENE_PT_keying_set_paths,
414     SCENE_PT_physics,
415     SCENE_PT_simplify,
416         SCENE_PT_navmesh,
417
418     SCENE_PT_custom_props,
419
420     ANIM_OT_keying_set_export]
421
422
423 def register():
424     register = bpy.types.register
425     for cls in classes:
426         register(cls)
427
428
429 def unregister():
430     unregister = bpy.types.unregister
431     for cls in classes:
432         unregister(cls)
433
434 if __name__ == "__main__":
435     register()