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/Scripts/Animation/AnimAll',
28 'tracker_url': 'https://developer.blender.org/T24874',
29 'category': 'Animation'}
31 """-------------------------------------------------------------------------
32 Thanks to Campbell Barton and Joshua Leung for hes API additions and fixes
33 Daniel 'ZanQdo' Salazar
34 -------------------------------------------------------------------------"""
37 from bpy
.props
import *
41 # Property Definitions
43 bpy
.types
.WindowManager
.key_shape
= BoolProperty(
45 description
="Insert keyframes on active Shape Key layer",
48 bpy
.types
.WindowManager
.key_uvs
= BoolProperty(
50 description
="Insert keyframes on active UV coordinates",
53 bpy
.types
.WindowManager
.key_bevel
= BoolProperty(
55 description
="Insert keyframes on edge bevel weight",
58 bpy
.types
.WindowManager
.key_crease
= BoolProperty(
60 description
="Insert keyframes on edge creases",
63 bpy
.types
.WindowManager
.key_vcols
= BoolProperty(
65 description
="Insert keyframes on active Vertex Color values",
68 bpy
.types
.WindowManager
.key_vgroups
= BoolProperty(
70 description
="Insert keyframes on active Vertex Group values",
73 bpy
.types
.WindowManager
.key_points
= BoolProperty(
75 description
="Insert keyframes on point locations",
78 bpy
.types
.WindowManager
.key_radius
= BoolProperty(
80 description
="Insert keyframes on point radius (Shrink/Fatten)",
83 bpy
.types
.WindowManager
.key_tilt
= BoolProperty(
85 description
="Insert keyframes on point tilt",
91 class VIEW3D_PT_animall(bpy
.types
.Panel
):
93 bl_space_type
= 'VIEW_3D'
94 bl_region_type
= 'TOOLS'
95 bl_category
= "Animation"
97 #bl_options = {'DEFAULT_CLOSED'}
99 def poll(self
, context
):
100 if context
.active_object
and context
.active_object
.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
101 return context
.active_object
.type
104 def draw(self
, context
):
106 Obj
= context
.active_object
109 col
= layout
.column(align
=True)
112 if Obj
.type == 'LATTICE':
113 row
.prop(context
.window_manager
, "key_points")
114 row
.prop(context
.window_manager
, "key_shape")
116 elif Obj
.type == 'MESH':
117 row
.prop(context
.window_manager
, "key_points")
118 row
.prop(context
.window_manager
, "key_shape")
120 row
.prop(context
.window_manager
, "key_bevel")
121 row
.prop(context
.window_manager
, "key_crease")
123 row
.prop(context
.window_manager
, "key_vcols")
124 row
.prop(context
.window_manager
, "key_vgroups")
126 row
.prop(context
.window_manager
, "key_uvs")
128 elif Obj
.type == 'CURVE':
129 row
.prop(context
.window_manager
, "key_points")
130 row
.prop(context
.window_manager
, "key_shape")
132 row
.prop(context
.window_manager
, "key_radius")
133 row
.prop(context
.window_manager
, "key_tilt")
135 elif Obj
.type == 'SURFACE':
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")
143 row
.operator('anim.insert_keyframe_animall', icon
='KEY_HLT')
144 row
.operator('anim.delete_keyframe_animall', icon
='KEY_DEHLT')
146 row
.operator('anim.clear_animation_animall', icon
='X')
148 if context
.window_manager
.key_shape
:
150 ShapeKey
= Obj
.active_shape_key
151 ShapeKeyIndex
= Obj
.active_shape_key_index
153 split
= layout
.split()
156 if ShapeKeyIndex
> 0:
157 row
.label(ShapeKey
.name
, icon
='SHAPEKEY_DATA')
158 row
.prop(ShapeKey
, "value", text
="")
159 row
.prop(Obj
, "show_only_shape_key", text
="")
160 if ShapeKey
.value
< 1:
162 row
.label('Maybe set "%s" to 1.0?' % ShapeKey
.name
, icon
='INFO')
164 row
.label('Can not key on Basis Shape', icon
='ERROR')
166 row
.label('No active Shape Key', icon
='ERROR')
168 if context
.window_manager
.key_points
and context
.window_manager
.key_shape
:
170 row
.label('"Points" and "Shape" are redundant?', icon
='INFO')
173 class ANIM_OT_insert_keyframe_animall(bpy
.types
.Operator
):
175 bl_idname
= 'anim.insert_keyframe_animall'
176 bl_description
= 'Insert a Keyframe'
177 bl_options
= {'REGISTER', 'UNDO'}
181 def invoke(self
, context
, event
):
183 self
.execute(context
)
188 def execute(op
, context
):
190 Obj
= context
.active_object
192 if Obj
.type == 'MESH':
194 if context
.mode
== 'EDIT_MESH':
196 bpy
.ops
.object.editmode_toggle()
200 if context
.window_manager
.key_shape
:
201 if Obj
.active_shape_key_index
> 0:
202 for Vert
in Obj
.active_shape_key
.data
:
203 Vert
.keyframe_insert('co')
205 if context
.window_manager
.key_points
:
206 for Vert
in Data
.vertices
:
207 Vert
.keyframe_insert('co')
209 if context
.window_manager
.key_bevel
:
210 for Edge
in Data
.edges
:
211 Edge
.keyframe_insert('bevel_weight')
213 if context
.window_manager
.key_crease
:
214 for Edge
in Data
.edges
:
215 Edge
.keyframe_insert('crease')
217 if context
.window_manager
.key_vgroups
:
218 for Vert
in Data
.vertices
:
219 for Group
in Vert
.groups
:
220 Group
.keyframe_insert('weight')
222 if context
.window_manager
.key_uvs
:
223 for UV
in Data
.uv_layers
.active
.data
:
224 UV
.keyframe_insert('uv')
226 if context
.window_manager
.key_vcols
:
227 for VColLayer
in Data
.vertex_colors
:
228 if VColLayer
.active
: # only insert in active VCol layer
229 for Data
in VColLayer
.data
:
230 Data
.keyframe_insert('color')
233 bpy
.ops
.object.editmode_toggle()
235 if Obj
.type == 'LATTICE':
237 if context
.mode
!= 'OBJECT':
239 bpy
.ops
.object.editmode_toggle()
243 if context
.window_manager
.key_shape
:
244 if Obj
.active_shape_key_index
> 0:
245 for Point
in Obj
.active_shape_key
.data
:
246 Point
.keyframe_insert('co')
248 if context
.window_manager
.key_points
:
249 for Point
in Data
.points
:
250 Point
.keyframe_insert('co_deform')
253 bpy
.ops
.object.editmode_toggle()
255 if Obj
.type in {'CURVE', 'SURFACE'}:
257 if context
.mode
!= 'OBJECT':
259 bpy
.ops
.object.editmode_toggle()
263 # run this outside the splines loop (only once)
264 if context
.window_manager
.key_shape
:
265 if Obj
.active_shape_key_index
> 0:
266 for CV
in Obj
.active_shape_key
.data
:
267 CV
.keyframe_insert('co')
268 try: # in case spline has no handles
269 CV
.keyframe_insert('handle_left')
270 CV
.keyframe_insert('handle_right')
273 for Spline
in Data
.splines
:
274 if Spline
.type == 'BEZIER':
276 for CV
in Spline
.bezier_points
:
278 if context
.window_manager
.key_points
:
279 CV
.keyframe_insert('co')
280 CV
.keyframe_insert('handle_left')
281 CV
.keyframe_insert('handle_right')
283 if context
.window_manager
.key_radius
:
284 CV
.keyframe_insert('radius')
286 if context
.window_manager
.key_tilt
:
287 CV
.keyframe_insert('tilt')
289 elif Spline
.type == 'NURBS':
291 for CV
in Spline
.points
:
293 if context
.window_manager
.key_points
:
294 CV
.keyframe_insert('co')
296 if context
.window_manager
.key_radius
:
297 CV
.keyframe_insert('radius')
299 if context
.window_manager
.key_tilt
:
300 CV
.keyframe_insert('tilt')
303 bpy
.ops
.object.editmode_toggle()
309 class ANIM_OT_delete_keyframe_animall(bpy
.types
.Operator
):
311 bl_idname
= 'anim.delete_keyframe_animall'
312 bl_description
= 'Delete a Keyframe'
313 bl_options
= {'REGISTER', 'UNDO'}
317 def invoke(self
, context
, event
):
319 self
.execute(context
)
324 def execute(op
, context
):
326 Obj
= context
.active_object
328 if Obj
.type == 'MESH':
330 if context
.mode
== 'EDIT_MESH':
332 bpy
.ops
.object.editmode_toggle()
336 if context
.window_manager
.key_shape
:
337 if Obj
.active_shape_key
:
338 for Vert
in Obj
.active_shape_key
.data
:
339 Vert
.keyframe_delete('co')
341 if context
.window_manager
.key_points
:
342 for Vert
in Data
.vertices
:
343 Vert
.keyframe_delete('co')
345 if context
.window_manager
.key_bevel
:
346 for Edge
in Data
.edges
:
347 Edge
.keyframe_delete('bevel_weight')
349 if context
.window_manager
.key_crease
:
350 for Edge
in Data
.edges
:
351 Edge
.keyframe_delete('crease')
353 if context
.window_manager
.key_vgroups
:
354 for Vert
in Data
.vertices
:
355 for Group
in Vert
.groups
:
356 Group
.keyframe_delete('weight')
358 if context
.window_manager
.key_uvs
:
359 for UV
in Data
.uv_layers
.active
.data
:
360 UV
.keyframe_delete('uv')
362 if context
.window_manager
.key_vcols
:
363 for VColLayer
in Data
.vertex_colors
:
364 if VColLayer
.active
: # only delete in active VCol layer
365 for Data
in VColLayer
.data
:
366 Data
.keyframe_delete('color')
369 bpy
.ops
.object.editmode_toggle()
371 if Obj
.type == 'LATTICE':
374 if context
.mode
!= 'OBJECT':
376 bpy
.ops
.object.editmode_toggle()
380 if context
.window_manager
.key_shape
:
381 if Obj
.active_shape_key
:
382 for Point
in Obj
.active_shape_key
.data
:
383 Point
.keyframe_delete('co')
385 if context
.window_manager
.key_points
:
386 for Point
in Data
.points
:
387 Point
.keyframe_delete('co_deform')
390 bpy
.ops
.object.editmode_toggle()
392 if Obj
.type in {'CURVE', 'SURFACE'}:
394 if context
.mode
!= 'OBJECT':
396 bpy
.ops
.object.editmode_toggle()
400 # run this outside the splines loop (only once)
401 if context
.window_manager
.key_shape
:
402 if Obj
.active_shape_key_index
> 0:
403 for CV
in Obj
.active_shape_key
.data
:
404 CV
.keyframe_delete('co')
405 try: # in case spline has no handles
406 CV
.keyframe_delete('handle_left')
407 CV
.keyframe_delete('handle_right')
410 for Spline
in Data
.splines
:
411 if Spline
.type == 'BEZIER':
412 for CV
in Spline
.bezier_points
:
413 if context
.window_manager
.key_points
:
414 CV
.keyframe_delete('co')
415 CV
.keyframe_delete('handle_left')
416 CV
.keyframe_delete('handle_right')
417 if context
.window_manager
.key_radius
:
418 CV
.keyframe_delete('radius')
419 if context
.window_manager
.key_tilt
:
420 CV
.keyframe_delete('tilt')
422 elif Spline
.type == 'NURBS':
423 for CV
in Spline
.points
:
424 if context
.window_manager
.key_points
:
425 CV
.keyframe_delete('co')
426 if context
.window_manager
.key_radius
:
427 CV
.keyframe_delete('radius')
428 if context
.window_manager
.key_tilt
:
429 CV
.keyframe_delete('tilt')
432 bpy
.ops
.object.editmode_toggle()
438 class ANIM_OT_clear_animation_animall(bpy
.types
.Operator
):
439 bl_label
= 'Clear Animation'
440 bl_idname
= 'anim.clear_animation_animall'
441 bl_description
= 'Delete all keyframes for this object'
442 bl_options
= {'REGISTER', 'UNDO'}
445 def invoke(self
, context
, event
):
447 wm
= context
.window_manager
448 return wm
.invoke_confirm(self
, event
)
451 def execute(op
, context
):
453 Data
= context
.active_object
.data
454 Data
.animation_data_clear()
460 bpy
.utils
.register_module(__name__
)
465 bpy
.utils
.unregister_module(__name__
)
469 if __name__
== "__main__":