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>",
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_ebevel
= BoolProperty(
56 description
="Insert keyframes on edge bevel weight",
59 bpy
.types
.WindowManager
.key_vbevel
= BoolProperty(
61 description
="Insert keyframes on vertex bevel weight",
64 bpy
.types
.WindowManager
.key_crease
= BoolProperty(
66 description
="Insert keyframes on edge creases",
69 bpy
.types
.WindowManager
.key_vcols
= BoolProperty(
71 description
="Insert keyframes on active Vertex Color values",
74 bpy
.types
.WindowManager
.key_vgroups
= BoolProperty(
76 description
="Insert keyframes on active Vertex Group values",
79 bpy
.types
.WindowManager
.key_points
= BoolProperty(
81 description
="Insert keyframes on point locations",
84 bpy
.types
.WindowManager
.key_radius
= BoolProperty(
86 description
="Insert keyframes on point radius (Shrink/Fatten)",
89 bpy
.types
.WindowManager
.key_tilt
= BoolProperty(
91 description
="Insert keyframes on point tilt",
97 class VIEW3D_PT_animall(bpy
.types
.Panel
):
99 bl_space_type
= 'VIEW_3D'
100 bl_region_type
= 'TOOLS'
101 bl_category
= "Animation"
103 #bl_options = {'DEFAULT_CLOSED'}
105 def poll(self
, context
):
106 if context
.active_object
and context
.active_object
.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
107 return context
.active_object
.type
110 def draw(self
, context
):
112 Obj
= context
.active_object
115 col
= layout
.column(align
=True)
118 if Obj
.type == 'LATTICE':
119 row
.prop(context
.window_manager
, "key_points")
120 row
.prop(context
.window_manager
, "key_shape")
122 elif Obj
.type == 'MESH':
123 row
.prop(context
.window_manager
, "key_points")
124 row
.prop(context
.window_manager
, "key_shape")
126 row
.prop(context
.window_manager
, "key_ebevel")
127 row
.prop(context
.window_manager
, "key_vbevel")
128 col
.prop(context
.window_manager
, "key_crease")
130 row
.prop(context
.window_manager
, "key_vcols")
131 row
.prop(context
.window_manager
, "key_vgroups")
133 row
.prop(context
.window_manager
, "key_uvs")
135 elif Obj
.type == 'CURVE':
136 row
.prop(context
.window_manager
, "key_points")
137 row
.prop(context
.window_manager
, "key_shape")
139 row
.prop(context
.window_manager
, "key_radius")
140 row
.prop(context
.window_manager
, "key_tilt")
142 elif Obj
.type == 'SURFACE':
143 row
.prop(context
.window_manager
, "key_points")
144 row
.prop(context
.window_manager
, "key_shape")
146 row
.prop(context
.window_manager
, "key_radius")
147 row
.prop(context
.window_manager
, "key_tilt")
150 row
.operator('anim.insert_keyframe_animall', icon
='KEY_HLT')
151 row
.operator('anim.delete_keyframe_animall', icon
='KEY_DEHLT')
153 row
.operator('anim.clear_animation_animall', icon
='X')
155 if context
.window_manager
.key_shape
:
157 ShapeKey
= Obj
.active_shape_key
158 ShapeKeyIndex
= Obj
.active_shape_key_index
160 split
= layout
.split()
163 if ShapeKeyIndex
> 0:
164 row
.label(ShapeKey
.name
, icon
='SHAPEKEY_DATA')
165 row
.prop(ShapeKey
, "value", text
="")
166 row
.prop(Obj
, "show_only_shape_key", text
="")
167 if ShapeKey
.value
< 1:
169 row
.label('Maybe set "%s" to 1.0?' % ShapeKey
.name
, icon
='INFO')
171 row
.label('Can not key on Basis Shape', icon
='ERROR')
173 row
.label('No active Shape Key', icon
='ERROR')
175 if context
.window_manager
.key_points
and context
.window_manager
.key_shape
:
177 row
.label('"Points" and "Shape" are redundant?', icon
='INFO')
180 class ANIM_OT_insert_keyframe_animall(bpy
.types
.Operator
):
182 bl_idname
= 'anim.insert_keyframe_animall'
183 bl_description
= 'Insert a Keyframe'
184 bl_options
= {'REGISTER', 'UNDO'}
188 def invoke(self
, context
, event
):
190 self
.execute(context
)
195 def execute(op
, context
):
197 Obj
= context
.active_object
199 if Obj
.type == 'MESH':
201 if context
.mode
== 'EDIT_MESH':
203 bpy
.ops
.object.editmode_toggle()
207 if context
.window_manager
.key_shape
:
208 if Obj
.active_shape_key_index
> 0:
209 for Vert
in Obj
.active_shape_key
.data
:
210 Vert
.keyframe_insert('co')
212 if context
.window_manager
.key_points
:
213 for Vert
in Data
.vertices
:
214 Vert
.keyframe_insert('co')
216 if context
.window_manager
.key_ebevel
:
217 for Edge
in Data
.edges
:
218 Edge
.keyframe_insert('bevel_weight')
220 if context
.window_manager
.key_vbevel
:
221 for Vert
in Data
.vertices
:
222 Vert
.keyframe_insert('bevel_weight')
224 if context
.window_manager
.key_crease
:
225 for Edge
in Data
.edges
:
226 Edge
.keyframe_insert('crease')
228 if context
.window_manager
.key_vgroups
:
229 for Vert
in Data
.vertices
:
230 for Group
in Vert
.groups
:
231 Group
.keyframe_insert('weight')
233 if context
.window_manager
.key_uvs
:
234 for UV
in Data
.uv_layers
.active
.data
:
235 UV
.keyframe_insert('uv')
237 if context
.window_manager
.key_vcols
:
238 for VColLayer
in Data
.vertex_colors
:
239 if VColLayer
.active
: # only insert in active VCol layer
240 for Data
in VColLayer
.data
:
241 Data
.keyframe_insert('color')
244 bpy
.ops
.object.editmode_toggle()
246 if Obj
.type == 'LATTICE':
248 if context
.mode
!= 'OBJECT':
250 bpy
.ops
.object.editmode_toggle()
254 if context
.window_manager
.key_shape
:
255 if Obj
.active_shape_key_index
> 0:
256 for Point
in Obj
.active_shape_key
.data
:
257 Point
.keyframe_insert('co')
259 if context
.window_manager
.key_points
:
260 for Point
in Data
.points
:
261 Point
.keyframe_insert('co_deform')
264 bpy
.ops
.object.editmode_toggle()
266 if Obj
.type in {'CURVE', 'SURFACE'}:
268 if context
.mode
!= 'OBJECT':
270 bpy
.ops
.object.editmode_toggle()
274 # run this outside the splines loop (only once)
275 if context
.window_manager
.key_shape
:
276 if Obj
.active_shape_key_index
> 0:
277 for CV
in Obj
.active_shape_key
.data
:
278 CV
.keyframe_insert('co')
279 try: # in case spline has no handles
280 CV
.keyframe_insert('handle_left')
281 CV
.keyframe_insert('handle_right')
284 for Spline
in Data
.splines
:
285 if Spline
.type == 'BEZIER':
287 for CV
in Spline
.bezier_points
:
289 if context
.window_manager
.key_points
:
290 CV
.keyframe_insert('co')
291 CV
.keyframe_insert('handle_left')
292 CV
.keyframe_insert('handle_right')
294 if context
.window_manager
.key_radius
:
295 CV
.keyframe_insert('radius')
297 if context
.window_manager
.key_tilt
:
298 CV
.keyframe_insert('tilt')
300 elif Spline
.type == 'NURBS':
302 for CV
in Spline
.points
:
304 if context
.window_manager
.key_points
:
305 CV
.keyframe_insert('co')
307 if context
.window_manager
.key_radius
:
308 CV
.keyframe_insert('radius')
310 if context
.window_manager
.key_tilt
:
311 CV
.keyframe_insert('tilt')
314 bpy
.ops
.object.editmode_toggle()
320 class ANIM_OT_delete_keyframe_animall(bpy
.types
.Operator
):
322 bl_idname
= 'anim.delete_keyframe_animall'
323 bl_description
= 'Delete a Keyframe'
324 bl_options
= {'REGISTER', 'UNDO'}
328 def invoke(self
, context
, event
):
330 self
.execute(context
)
335 def execute(op
, context
):
337 Obj
= context
.active_object
339 if Obj
.type == 'MESH':
341 if context
.mode
== 'EDIT_MESH':
343 bpy
.ops
.object.editmode_toggle()
347 if context
.window_manager
.key_shape
:
348 if Obj
.active_shape_key
:
349 for Vert
in Obj
.active_shape_key
.data
:
350 Vert
.keyframe_delete('co')
352 if context
.window_manager
.key_points
:
353 for Vert
in Data
.vertices
:
354 Vert
.keyframe_delete('co')
356 if context
.window_manager
.key_ebevel
:
357 for Edge
in Data
.edges
:
358 Edge
.keyframe_delete('bevel_weight')
360 if context
.window_manager
.key_vbevel
:
361 for Vert
in Data
.vertices
:
362 Vert
.keyframe_delete('bevel_weight')
364 if context
.window_manager
.key_crease
:
365 for Edge
in Data
.edges
:
366 Edge
.keyframe_delete('crease')
368 if context
.window_manager
.key_vgroups
:
369 for Vert
in Data
.vertices
:
370 for Group
in Vert
.groups
:
371 Group
.keyframe_delete('weight')
373 if context
.window_manager
.key_uvs
:
374 for UV
in Data
.uv_layers
.active
.data
:
375 UV
.keyframe_delete('uv')
377 if context
.window_manager
.key_vcols
:
378 for VColLayer
in Data
.vertex_colors
:
379 if VColLayer
.active
: # only delete in active VCol layer
380 for Data
in VColLayer
.data
:
381 Data
.keyframe_delete('color')
384 bpy
.ops
.object.editmode_toggle()
386 if Obj
.type == 'LATTICE':
389 if context
.mode
!= 'OBJECT':
391 bpy
.ops
.object.editmode_toggle()
395 if context
.window_manager
.key_shape
:
396 if Obj
.active_shape_key
:
397 for Point
in Obj
.active_shape_key
.data
:
398 Point
.keyframe_delete('co')
400 if context
.window_manager
.key_points
:
401 for Point
in Data
.points
:
402 Point
.keyframe_delete('co_deform')
405 bpy
.ops
.object.editmode_toggle()
407 if Obj
.type in {'CURVE', 'SURFACE'}:
409 if context
.mode
!= 'OBJECT':
411 bpy
.ops
.object.editmode_toggle()
415 # run this outside the splines loop (only once)
416 if context
.window_manager
.key_shape
:
417 if Obj
.active_shape_key_index
> 0:
418 for CV
in Obj
.active_shape_key
.data
:
419 CV
.keyframe_delete('co')
420 try: # in case spline has no handles
421 CV
.keyframe_delete('handle_left')
422 CV
.keyframe_delete('handle_right')
425 for Spline
in Data
.splines
:
426 if Spline
.type == 'BEZIER':
427 for CV
in Spline
.bezier_points
:
428 if context
.window_manager
.key_points
:
429 CV
.keyframe_delete('co')
430 CV
.keyframe_delete('handle_left')
431 CV
.keyframe_delete('handle_right')
432 if context
.window_manager
.key_radius
:
433 CV
.keyframe_delete('radius')
434 if context
.window_manager
.key_tilt
:
435 CV
.keyframe_delete('tilt')
437 elif Spline
.type == 'NURBS':
438 for CV
in Spline
.points
:
439 if context
.window_manager
.key_points
:
440 CV
.keyframe_delete('co')
441 if context
.window_manager
.key_radius
:
442 CV
.keyframe_delete('radius')
443 if context
.window_manager
.key_tilt
:
444 CV
.keyframe_delete('tilt')
447 bpy
.ops
.object.editmode_toggle()
453 class ANIM_OT_clear_animation_animall(bpy
.types
.Operator
):
454 bl_label
= 'Clear Animation'
455 bl_idname
= 'anim.clear_animation_animall'
456 bl_description
= 'Delete all keyframes for this object'
457 bl_options
= {'REGISTER', 'UNDO'}
460 def invoke(self
, context
, event
):
462 wm
= context
.window_manager
463 return wm
.invoke_confirm(self
, event
)
466 def execute(op
, context
):
468 Data
= context
.active_object
.data
469 Data
.animation_data_clear()
475 bpy
.utils
.register_module(__name__
)
480 bpy
.utils
.unregister_module(__name__
)
484 if __name__
== "__main__":