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 #####
21 "author": "Daniel Salazar <zanqdo@gmail.com>",
23 "blender": (2, 69, 7),
24 "location": "Tool bar > Animation tab > AnimAll",
25 "description": "Allows animation of mesh, lattice, curve and surface data",
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 -------------------------------------------------------------------------"""
38 from bpy
.props
import *
42 # Property Definitions
44 bpy
.types
.WindowManager
.key_shape
= BoolProperty(
46 description
="Insert keyframes on active Shape Key layer",
49 bpy
.types
.WindowManager
.key_uvs
= BoolProperty(
51 description
="Insert keyframes on active UV coordinates",
54 bpy
.types
.WindowManager
.key_bevel
= BoolProperty(
56 description
="Insert keyframes on edge bevel weight",
59 bpy
.types
.WindowManager
.key_crease
= BoolProperty(
61 description
="Insert keyframes on edge creases",
64 bpy
.types
.WindowManager
.key_vcols
= BoolProperty(
66 description
="Insert keyframes on active Vertex Color values",
69 bpy
.types
.WindowManager
.key_vgroups
= BoolProperty(
71 description
="Insert keyframes on active Vertex Group values",
74 bpy
.types
.WindowManager
.key_points
= BoolProperty(
76 description
="Insert keyframes on point locations",
79 bpy
.types
.WindowManager
.key_radius
= BoolProperty(
81 description
="Insert keyframes on point radius (Shrink/Fatten)",
84 bpy
.types
.WindowManager
.key_tilt
= BoolProperty(
86 description
="Insert keyframes on point tilt",
92 class VIEW3D_PT_animall(bpy
.types
.Panel
):
94 bl_space_type
= 'VIEW_3D'
95 bl_region_type
= 'TOOLS'
96 bl_category
= "Animation"
98 #bl_options = {'DEFAULT_CLOSED'}
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
105 def draw(self
, context
):
107 Obj
= context
.active_object
110 col
= layout
.column(align
=True)
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")
121 row
.prop(context
.window_manager
, "key_bevel")
122 row
.prop(context
.window_manager
, "key_crease")
124 row
.prop(context
.window_manager
, "key_vcols")
125 row
.prop(context
.window_manager
, "key_vgroups")
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")
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")
140 row
.prop(context
.window_manager
, "key_radius")
141 row
.prop(context
.window_manager
, "key_tilt")
144 row
.operator('anim.insert_keyframe_animall', icon
='KEY_HLT')
145 row
.operator('anim.delete_keyframe_animall', icon
='KEY_DEHLT')
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()
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:
163 row
.label('Maybe set "%s" to 1.0?' % ShapeKey
.name
, icon
='INFO')
165 row
.label('Can not key on Basis Shape', icon
='ERROR')
167 row
.label('No active Shape Key', icon
='ERROR')
169 if context
.window_manager
.key_points
and context
.window_manager
.key_shape
:
171 row
.label('"Points" and "Shape" are redundant?', icon
='INFO')
174 class ANIM_OT_insert_keyframe_animall(bpy
.types
.Operator
):
176 bl_idname
= 'anim.insert_keyframe_animall'
177 bl_description
= 'Insert a Keyframe'
178 bl_options
= {'REGISTER', 'UNDO'}
182 def invoke(self
, context
, event
):
184 self
.execute(context
)
189 def execute(op
, context
):
191 Obj
= context
.active_object
193 if Obj
.type == 'MESH':
195 if context
.mode
== 'EDIT_MESH':
197 bpy
.ops
.object.editmode_toggle()
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')
234 bpy
.ops
.object.editmode_toggle()
236 if Obj
.type == 'LATTICE':
238 if context
.mode
!= 'OBJECT':
240 bpy
.ops
.object.editmode_toggle()
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')
254 bpy
.ops
.object.editmode_toggle()
256 if Obj
.type in {'CURVE', 'SURFACE'}:
258 if context
.mode
!= 'OBJECT':
260 bpy
.ops
.object.editmode_toggle()
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')
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')
304 bpy
.ops
.object.editmode_toggle()
310 class ANIM_OT_delete_keyframe_animall(bpy
.types
.Operator
):
312 bl_idname
= 'anim.delete_keyframe_animall'
313 bl_description
= 'Delete a Keyframe'
314 bl_options
= {'REGISTER', 'UNDO'}
318 def invoke(self
, context
, event
):
320 self
.execute(context
)
325 def execute(op
, context
):
327 Obj
= context
.active_object
329 if Obj
.type == 'MESH':
331 if context
.mode
== 'EDIT_MESH':
333 bpy
.ops
.object.editmode_toggle()
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')
370 bpy
.ops
.object.editmode_toggle()
372 if Obj
.type == 'LATTICE':
375 if context
.mode
!= 'OBJECT':
377 bpy
.ops
.object.editmode_toggle()
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')
391 bpy
.ops
.object.editmode_toggle()
393 if Obj
.type in {'CURVE', 'SURFACE'}:
395 if context
.mode
!= 'OBJECT':
397 bpy
.ops
.object.editmode_toggle()
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')
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')
433 bpy
.ops
.object.editmode_toggle()
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'}
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()
461 bpy
.utils
.register_module(__name__
)
466 bpy
.utils
.unregister_module(__name__
)
470 if __name__
== "__main__":