~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/startup/bl_operators/anim.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-80 compliant>
 
20
 
 
21
if "bpy" in locals():
 
22
    import imp
 
23
    if "anim_utils" in locals():
 
24
        imp.reload(anim_utils)
 
25
 
 
26
import bpy
 
27
from bpy.types import Operator
 
28
from bpy.props import (IntProperty,
 
29
                       BoolProperty,
 
30
                       EnumProperty,
 
31
                       StringProperty,
 
32
                       )
 
33
 
 
34
 
 
35
class ANIM_OT_keying_set_export(Operator):
 
36
    "Export Keying Set to a python script"
 
37
    bl_idname = "anim.keying_set_export"
 
38
    bl_label = "Export Keying Set..."
 
39
 
 
40
    filepath = StringProperty(
 
41
            subtype='FILE_PATH',
 
42
            )
 
43
    filter_folder = BoolProperty(
 
44
            name="Filter folders",
 
45
            default=True,
 
46
            options={'HIDDEN'},
 
47
            )
 
48
    filter_text = BoolProperty(
 
49
            name="Filter text",
 
50
            default=True,
 
51
            options={'HIDDEN'},
 
52
            )
 
53
    filter_python = BoolProperty(
 
54
            name="Filter python",
 
55
            default=True,
 
56
            options={'HIDDEN'},
 
57
            )
 
58
 
 
59
    def execute(self, context):
 
60
        if not self.filepath:
 
61
            raise Exception("Filepath not set")
 
62
 
 
63
        f = open(self.filepath, "w")
 
64
        if not f:
 
65
            raise Exception("Could not open file")
 
66
 
 
67
        scene = context.scene
 
68
        ks = scene.keying_sets.active
 
69
 
 
70
        f.write("# Keying Set: %s\n" % ks.bl_idname)
 
71
 
 
72
        f.write("import bpy\n\n")
 
73
        f.write("scene = bpy.context.scene\n\n")
 
74
 
 
75
        # Add KeyingSet and set general settings
 
76
        f.write("# Keying Set Level declarations\n")
 
77
        f.write("ks = scene.keying_sets.new(idname=\"%s\", name=\"%s\")\n"
 
78
                "" % (ks.bl_idname, ks.bl_label))
 
79
        f.write("ks.bl_description = \"%s\"\n" % ks.bl_description)
 
80
 
 
81
        if not ks.is_path_absolute:
 
82
            f.write("ks.is_path_absolute = False\n")
 
83
        f.write("\n")
 
84
 
 
85
        f.write("ks.bl_options = %r\n" % ks.bl_options)
 
86
        f.write("\n")
 
87
 
 
88
        # --------------------------------------------------------
 
89
        # generate and write set of lookups for id's used in paths
 
90
 
 
91
        # cache for syncing ID-blocks to bpy paths + shorthand's
 
92
        id_to_paths_cache = {}
 
93
 
 
94
        for ksp in ks.paths:
 
95
            if ksp.id is None:
 
96
                continue
 
97
            if ksp.id in id_to_paths_cache:
 
98
                continue
 
99
 
 
100
            """
 
101
            - idtype_list is used to get the list of id-datablocks from
 
102
              bpy.data.* since this info isn't available elsewhere
 
103
            - id.bl_rna.name gives a name suitable for UI,
 
104
              with a capitalised first letter, but we need
 
105
              the plural form that's all lower case
 
106
            """
 
107
 
 
108
            idtype_list = ksp.id.bl_rna.name.lower() + "s"
 
109
            id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, ksp.id.name)
 
110
 
 
111
            # shorthand ID for the ID-block (as used in the script)
 
112
            short_id = "id_%d" % len(id_to_paths_cache)
 
113
 
 
114
            # store this in the cache now
 
115
            id_to_paths_cache[ksp.id] = [short_id, id_bpy_path]
 
116
 
 
117
        f.write("# ID's that are commonly used\n")
 
118
        for id_pair in id_to_paths_cache.values():
 
119
            f.write("%s = %s\n" % (id_pair[0], id_pair[1]))
 
120
        f.write("\n")
 
121
 
 
122
        # write paths
 
123
        f.write("# Path Definitions\n")
 
124
        for ksp in ks.paths:
 
125
            f.write("ksp = ks.paths.add(")
 
126
 
 
127
            # id-block + data_path
 
128
            if ksp.id:
 
129
                # find the relevant shorthand from the cache
 
130
                id_bpy_path = id_to_paths_cache[ksp.id][0]
 
131
            else:
 
132
                id_bpy_path = "None"  # XXX...
 
133
            f.write("%s, '%s'" % (id_bpy_path, ksp.data_path))
 
134
 
 
135
            # array index settings (if applicable)
 
136
            if ksp.use_entire_array:
 
137
                f.write(", index=-1")
 
138
            else:
 
139
                f.write(", index=%d" % ksp.array_index)
 
140
 
 
141
            # grouping settings (if applicable)
 
142
            # NOTE: the current default is KEYINGSET, but if this changes,
 
143
            # change this code too
 
144
            if ksp.group_method == 'NAMED':
 
145
                f.write(", group_method='%s', group_name=\"%s\"" %
 
146
                        (ksp.group_method, ksp.group))
 
147
            elif ksp.group_method != 'KEYINGSET':
 
148
                f.write(", group_method='%s'" % ksp.group_method)
 
149
 
 
150
            # finish off
 
151
            f.write(")\n")
 
152
 
 
153
        f.write("\n")
 
154
        f.close()
 
155
 
 
156
        return {'FINISHED'}
 
157
 
 
158
    def invoke(self, context, event):
 
159
        wm = context.window_manager
 
160
        wm.fileselect_add(self)
 
161
        return {'RUNNING_MODAL'}
 
162
 
 
163
 
 
164
class BakeAction(Operator):
 
165
    """Bake object/pose loc/scale/rotation animation to a new action"""
 
166
    bl_idname = "nla.bake"
 
167
    bl_label = "Bake Action"
 
168
    bl_options = {'REGISTER', 'UNDO'}
 
169
 
 
170
    frame_start = IntProperty(
 
171
            name="Start Frame",
 
172
            description="Start frame for baking",
 
173
            min=0, max=300000,
 
174
            default=1,
 
175
            )
 
176
    frame_end = IntProperty(
 
177
            name="End Frame",
 
178
            description="End frame for baking",
 
179
            min=1, max=300000,
 
180
            default=250,
 
181
            )
 
182
    step = IntProperty(
 
183
            name="Frame Step",
 
184
            description="Frame Step",
 
185
            min=1, max=120,
 
186
            default=1,
 
187
            )
 
188
    only_selected = BoolProperty(
 
189
            name="Only Selected",
 
190
            default=True,
 
191
            )
 
192
    clear_consraints = BoolProperty(
 
193
            name="Clear Constraints",
 
194
            default=False,
 
195
            )
 
196
    bake_types = EnumProperty(
 
197
            name="Bake Data",
 
198
            options={'ENUM_FLAG'},
 
199
            items=(('POSE', "Pose", ""),
 
200
                   ('OBJECT', "Object", ""),
 
201
                   ),
 
202
            default={'POSE'},
 
203
            )
 
204
 
 
205
    def execute(self, context):
 
206
 
 
207
        from bpy_extras import anim_utils
 
208
 
 
209
        action = anim_utils.bake_action(self.frame_start,
 
210
                                        self.frame_end,
 
211
                                        self.step,
 
212
                                        self.only_selected,
 
213
                                        'POSE' in self.bake_types,
 
214
                                        'OBJECT' in self.bake_types,
 
215
                                        self.clear_consraints,
 
216
                                        True,
 
217
                                 )
 
218
 
 
219
        if action is None:
 
220
            self.report({'INFO'}, "Nothing to bake")
 
221
            return {'CANCELLED'}
 
222
 
 
223
        return {'FINISHED'}
 
224
 
 
225
    def invoke(self, context, event):
 
226
        wm = context.window_manager
 
227
        return wm.invoke_props_dialog(self)
 
228
 
 
229
 
 
230
class ClearUselessActions(Operator):
 
231
    """Mark actions with no F-Curves for deletion after save & reload of """ \
 
232
    """file preserving \"action libraries\""""
 
233
    bl_idname = "anim.clear_useless_actions"
 
234
    bl_label = "Clear Useless Actions"
 
235
    bl_options = {'REGISTER', 'UNDO'}
 
236
 
 
237
    only_unused = BoolProperty(name="Only Unused",
 
238
            description="Only unused (Fake User only) actions get considered",
 
239
            default=True)
 
240
 
 
241
    @classmethod
 
242
    def poll(cls, context):
 
243
        return bool(bpy.data.actions)
 
244
 
 
245
    def execute(self, context):
 
246
        removed = 0
 
247
 
 
248
        for action in bpy.data.actions:
 
249
            # if only user is "fake" user...
 
250
            if ((self.only_unused is False) or
 
251
                (action.use_fake_user and action.users == 1)):
 
252
 
 
253
                # if it has F-Curves, then it's a "action library"
 
254
                # (i.e. walk, wave, jump, etc.)
 
255
                # and should be left alone as that's what fake users are for!
 
256
                if not action.fcurves:
 
257
                    # mark action for deletion
 
258
                    action.user_clear()
 
259
                    removed += 1
 
260
 
 
261
        self.report({'INFO'}, "Removed %d empty and/or fake-user only Actions"
 
262
                              % removed)
 
263
        return {'FINISHED'}
 
264
 
 
265
 
 
266
class UpdateAnimData(Operator):
 
267
    """Update data paths from 2.56 and previous versions, """ \
 
268
    """modifying data paths of drivers and fcurves"""
 
269
    bl_idname = "anim.update_data_paths"
 
270
    bl_label = "Update Animation Data"
 
271
 
 
272
    def execute(self, context):
 
273
        import animsys_refactor
 
274
        animsys_refactor.update_data_paths(animsys_refactor.data_2_56_to_2_59)
 
275
        return {'FINISHED'}