Revert "Fix for exporting animation on armature bones that have keys for a rotation_m...
[blender-addons.git] / animation_animall.py
blob4edcf43954066dd32874eec7ff39ff48e5094370
1 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17 # ##### END GPL LICENSE BLOCK #####
19 bl_info = {
20 "name": "AnimAll",
21 "author": "Daniel Salazar <zanqdo@gmail.com>",
22 "version": (0, 7),
23 "blender": (2, 69, 7),
24 "location": "Tool bar > Animation tab > AnimAll",
25 "description": "Allows animation of mesh, lattice, curve and surface data",
26 "warning": "",
27 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
28 "Scripts/Animation/AnimAll",
29 "category": "Animation",
32 """-------------------------------------------------------------------------
33 Thanks to Campbell Barton and Joshua Leung for hes API additions and fixes
34 Daniel 'ZanQdo' Salazar
35 -------------------------------------------------------------------------"""
37 import bpy
38 from bpy.props import *
42 # Property Definitions
44 bpy.types.WindowManager.key_shape = BoolProperty(
45 name="Shape",
46 description="Insert keyframes on active Shape Key layer",
47 default=False)
49 bpy.types.WindowManager.key_uvs = BoolProperty(
50 name="UVs",
51 description="Insert keyframes on active UV coordinates",
52 default=False)
54 bpy.types.WindowManager.key_bevel = BoolProperty(
55 name="Bevel",
56 description="Insert keyframes on edge bevel weight",
57 default=False)
59 bpy.types.WindowManager.key_crease = BoolProperty(
60 name="Crease",
61 description="Insert keyframes on edge creases",
62 default=False)
64 bpy.types.WindowManager.key_vcols = BoolProperty(
65 name="VCols",
66 description="Insert keyframes on active Vertex Color values",
67 default=False)
69 bpy.types.WindowManager.key_vgroups = BoolProperty(
70 name="VGroups",
71 description="Insert keyframes on active Vertex Group values",
72 default=False)
74 bpy.types.WindowManager.key_points = BoolProperty(
75 name="Points",
76 description="Insert keyframes on point locations",
77 default=False)
79 bpy.types.WindowManager.key_radius = BoolProperty(
80 name="Radius",
81 description="Insert keyframes on point radius (Shrink/Fatten)",
82 default=False)
84 bpy.types.WindowManager.key_tilt = BoolProperty(
85 name="Tilt",
86 description="Insert keyframes on point tilt",
87 default=False)
90 # GUI (Panel)
92 class VIEW3D_PT_animall(bpy.types.Panel):
94 bl_space_type = 'VIEW_3D'
95 bl_region_type = 'TOOLS'
96 bl_category = "Animation"
97 bl_label = 'AnimAll'
98 #bl_options = {'DEFAULT_CLOSED'}
99 @classmethod
100 def poll(self, context):
101 if context.active_object and context.active_object.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
102 return context.active_object.type
104 # draw the gui
105 def draw(self, context):
107 Obj = context.active_object
109 layout = self.layout
110 col = layout.column(align=True)
111 row = col.row()
113 if Obj.type == 'LATTICE':
114 row.prop(context.window_manager, "key_points")
115 row.prop(context.window_manager, "key_shape")
117 elif Obj.type == 'MESH':
118 row.prop(context.window_manager, "key_points")
119 row.prop(context.window_manager, "key_shape")
120 row = col.row()
121 row.prop(context.window_manager, "key_bevel")
122 row.prop(context.window_manager, "key_crease")
123 row = col.row()
124 row.prop(context.window_manager, "key_vcols")
125 row.prop(context.window_manager, "key_vgroups")
126 row = col.row()
127 row.prop(context.window_manager, "key_uvs")
129 elif Obj.type == 'CURVE':
130 row.prop(context.window_manager, "key_points")
131 row.prop(context.window_manager, "key_shape")
132 row = col.row()
133 row.prop(context.window_manager, "key_radius")
134 row.prop(context.window_manager, "key_tilt")
136 elif Obj.type == 'SURFACE':
137 row.prop(context.window_manager, "key_points")
138 row.prop(context.window_manager, "key_shape")
139 row = col.row()
140 row.prop(context.window_manager, "key_radius")
141 row.prop(context.window_manager, "key_tilt")
143 row = col.row()
144 row.operator('anim.insert_keyframe_animall', icon='KEY_HLT')
145 row.operator('anim.delete_keyframe_animall', icon='KEY_DEHLT')
146 row = layout.row()
147 row.operator('anim.clear_animation_animall', icon='X')
149 if context.window_manager.key_shape:
151 ShapeKey = Obj.active_shape_key
152 ShapeKeyIndex = Obj.active_shape_key_index
154 split = layout.split()
155 row = split.row()
157 if ShapeKeyIndex > 0:
158 row.label(ShapeKey.name, icon='SHAPEKEY_DATA')
159 row.prop(ShapeKey, "value", text="")
160 row.prop(Obj, "show_only_shape_key", text="")
161 if ShapeKey.value < 1:
162 row = layout.row()
163 row.label('Maybe set "%s" to 1.0?' % ShapeKey.name, icon='INFO')
164 elif ShapeKey:
165 row.label('Can not key on Basis Shape', icon='ERROR')
166 else:
167 row.label('No active Shape Key', icon='ERROR')
169 if context.window_manager.key_points and context.window_manager.key_shape:
170 row = layout.row()
171 row.label('"Points" and "Shape" are redundant?', icon='INFO')
174 class ANIM_OT_insert_keyframe_animall(bpy.types.Operator):
175 bl_label = 'Insert'
176 bl_idname = 'anim.insert_keyframe_animall'
177 bl_description = 'Insert a Keyframe'
178 bl_options = {'REGISTER', 'UNDO'}
181 # on mouse up:
182 def invoke(self, context, event):
184 self.execute(context)
186 return {'FINISHED'}
189 def execute(op, context):
191 Obj = context.active_object
193 if Obj.type == 'MESH':
194 Mode = False
195 if context.mode == 'EDIT_MESH':
196 Mode = not Mode
197 bpy.ops.object.editmode_toggle()
199 Data = Obj.data
201 if context.window_manager.key_shape:
202 if Obj.active_shape_key_index > 0:
203 for Vert in Obj.active_shape_key.data:
204 Vert.keyframe_insert('co')
206 if context.window_manager.key_points:
207 for Vert in Data.vertices:
208 Vert.keyframe_insert('co')
210 if context.window_manager.key_bevel:
211 for Edge in Data.edges:
212 Edge.keyframe_insert('bevel_weight')
214 if context.window_manager.key_crease:
215 for Edge in Data.edges:
216 Edge.keyframe_insert('crease')
218 if context.window_manager.key_vgroups:
219 for Vert in Data.vertices:
220 for Group in Vert.groups:
221 Group.keyframe_insert('weight')
223 if context.window_manager.key_uvs:
224 for UV in Data.uv_layers.active.data:
225 UV.keyframe_insert('uv')
227 if context.window_manager.key_vcols:
228 for VColLayer in Data.vertex_colors:
229 if VColLayer.active: # only insert in active VCol layer
230 for Data in VColLayer.data:
231 Data.keyframe_insert('color')
233 if Mode:
234 bpy.ops.object.editmode_toggle()
236 if Obj.type == 'LATTICE':
237 Mode = False
238 if context.mode != 'OBJECT':
239 Mode = not Mode
240 bpy.ops.object.editmode_toggle()
242 Data = Obj.data
244 if context.window_manager.key_shape:
245 if Obj.active_shape_key_index > 0:
246 for Point in Obj.active_shape_key.data:
247 Point.keyframe_insert('co')
249 if context.window_manager.key_points:
250 for Point in Data.points:
251 Point.keyframe_insert('co_deform')
253 if Mode:
254 bpy.ops.object.editmode_toggle()
256 if Obj.type in {'CURVE', 'SURFACE'}:
257 Mode = False
258 if context.mode != 'OBJECT':
259 Mode = not Mode
260 bpy.ops.object.editmode_toggle()
262 Data = Obj.data
264 # run this outside the splines loop (only once)
265 if context.window_manager.key_shape:
266 if Obj.active_shape_key_index > 0:
267 for CV in Obj.active_shape_key.data:
268 CV.keyframe_insert('co')
269 try: # in case spline has no handles
270 CV.keyframe_insert('handle_left')
271 CV.keyframe_insert('handle_right')
272 except: pass
274 for Spline in Data.splines:
275 if Spline.type == 'BEZIER':
277 for CV in Spline.bezier_points:
279 if context.window_manager.key_points:
280 CV.keyframe_insert('co')
281 CV.keyframe_insert('handle_left')
282 CV.keyframe_insert('handle_right')
284 if context.window_manager.key_radius:
285 CV.keyframe_insert('radius')
287 if context.window_manager.key_tilt:
288 CV.keyframe_insert('tilt')
290 elif Spline.type == 'NURBS':
292 for CV in Spline.points:
294 if context.window_manager.key_points:
295 CV.keyframe_insert('co')
297 if context.window_manager.key_radius:
298 CV.keyframe_insert('radius')
300 if context.window_manager.key_tilt:
301 CV.keyframe_insert('tilt')
303 if Mode:
304 bpy.ops.object.editmode_toggle()
307 return {'FINISHED'}
310 class ANIM_OT_delete_keyframe_animall(bpy.types.Operator):
311 bl_label = 'Delete'
312 bl_idname = 'anim.delete_keyframe_animall'
313 bl_description = 'Delete a Keyframe'
314 bl_options = {'REGISTER', 'UNDO'}
317 # on mouse up:
318 def invoke(self, context, event):
320 self.execute(context)
322 return {'FINISHED'}
325 def execute(op, context):
327 Obj = context.active_object
329 if Obj.type == 'MESH':
330 Mode = False
331 if context.mode == 'EDIT_MESH':
332 Mode = not Mode
333 bpy.ops.object.editmode_toggle()
335 Data = Obj.data
337 if context.window_manager.key_shape:
338 if Obj.active_shape_key:
339 for Vert in Obj.active_shape_key.data:
340 Vert.keyframe_delete('co')
342 if context.window_manager.key_points:
343 for Vert in Data.vertices:
344 Vert.keyframe_delete('co')
346 if context.window_manager.key_bevel:
347 for Edge in Data.edges:
348 Edge.keyframe_delete('bevel_weight')
350 if context.window_manager.key_crease:
351 for Edge in Data.edges:
352 Edge.keyframe_delete('crease')
354 if context.window_manager.key_vgroups:
355 for Vert in Data.vertices:
356 for Group in Vert.groups:
357 Group.keyframe_delete('weight')
359 if context.window_manager.key_uvs:
360 for UV in Data.uv_layers.active.data:
361 UV.keyframe_delete('uv')
363 if context.window_manager.key_vcols:
364 for VColLayer in Data.vertex_colors:
365 if VColLayer.active: # only delete in active VCol layer
366 for Data in VColLayer.data:
367 Data.keyframe_delete('color')
369 if Mode:
370 bpy.ops.object.editmode_toggle()
372 if Obj.type == 'LATTICE':
374 Mode = False
375 if context.mode != 'OBJECT':
376 Mode = not Mode
377 bpy.ops.object.editmode_toggle()
379 Data = Obj.data
381 if context.window_manager.key_shape:
382 if Obj.active_shape_key:
383 for Point in Obj.active_shape_key.data:
384 Point.keyframe_delete('co')
386 if context.window_manager.key_points:
387 for Point in Data.points:
388 Point.keyframe_delete('co_deform')
390 if Mode:
391 bpy.ops.object.editmode_toggle()
393 if Obj.type in {'CURVE', 'SURFACE'}:
394 Mode = False
395 if context.mode != 'OBJECT':
396 Mode = not Mode
397 bpy.ops.object.editmode_toggle()
399 Data = Obj.data
401 # run this outside the splines loop (only once)
402 if context.window_manager.key_shape:
403 if Obj.active_shape_key_index > 0:
404 for CV in Obj.active_shape_key.data:
405 CV.keyframe_delete('co')
406 try: # in case spline has no handles
407 CV.keyframe_delete('handle_left')
408 CV.keyframe_delete('handle_right')
409 except: pass
411 for Spline in Data.splines:
412 if Spline.type == 'BEZIER':
413 for CV in Spline.bezier_points:
414 if context.window_manager.key_points:
415 CV.keyframe_delete('co')
416 CV.keyframe_delete('handle_left')
417 CV.keyframe_delete('handle_right')
418 if context.window_manager.key_radius:
419 CV.keyframe_delete('radius')
420 if context.window_manager.key_tilt:
421 CV.keyframe_delete('tilt')
423 elif Spline.type == 'NURBS':
424 for CV in Spline.points:
425 if context.window_manager.key_points:
426 CV.keyframe_delete('co')
427 if context.window_manager.key_radius:
428 CV.keyframe_delete('radius')
429 if context.window_manager.key_tilt:
430 CV.keyframe_delete('tilt')
432 if Mode:
433 bpy.ops.object.editmode_toggle()
436 return {'FINISHED'}
439 class ANIM_OT_clear_animation_animall(bpy.types.Operator):
440 bl_label = 'Clear Animation'
441 bl_idname = 'anim.clear_animation_animall'
442 bl_description = 'Delete all keyframes for this object'
443 bl_options = {'REGISTER', 'UNDO'}
445 # on mouse up:
446 def invoke(self, context, event):
448 wm = context.window_manager
449 return wm.invoke_confirm(self, event)
452 def execute(op, context):
454 Data = context.active_object.data
455 Data.animation_data_clear()
457 return {'FINISHED'}
460 def register():
461 bpy.utils.register_module(__name__)
463 pass
465 def unregister():
466 bpy.utils.unregister_module(__name__)
468 pass
470 if __name__ == "__main__":
471 register()