[Bf-extensions-cvs] [fe627477] master: animation_animall: multi-object editing

Damien Picard noreply at git.blender.org
Tue Aug 27 12:47:06 CEST 2019


Commit: fe627477c2501c1e38311c97b3b5e3ffa731947e
Author: Damien Picard
Date:   Sun Aug 25 16:01:56 2019 +0200
Branches: master
https://developer.blender.org/rBAfe627477c2501c1e38311c97b3b5e3ffa731947e

animation_animall: multi-object editing

===================================================================

M	animation_animall.py

===================================================================

diff --git a/animation_animall.py b/animation_animall.py
index b2f655ce..df658ff3 100644
--- a/animation_animall.py
+++ b/animation_animall.py
@@ -19,7 +19,7 @@
 bl_info = {
     "name": "AnimAll",
     "author": "Daniel Salazar <zanqdo at gmail.com>",
-    "version": (0, 8, 2),
+    "version": (0, 8, 3),
     "blender": (2, 80, 0),
     "location": "3D View > Toolbox > Animation tab > AnimAll",
     "description": "Allows animation of mesh, lattice, curve and surface data",
@@ -116,9 +116,12 @@ def refresh_ui_keyframes():
         pass
 
 
-def insert_key(data, key, group=''):
+def insert_key(data, key, group=None):
     try:
-        data.keyframe_insert(key, group=group)
+        if group is not None:
+            data.keyframe_insert(key, group=group)
+        else:
+            data.keyframe_insert(key)
     except:
         pass
 
@@ -222,137 +225,148 @@ class ANIM_OT_insert_keyframe_animall(Operator):
     bl_description = "Insert a Keyframe"
     bl_options = {'REGISTER', 'UNDO'}
 
-    def invoke(self, context, event):
-        self.execute(context)
-
-        return {'FINISHED'}
-
     def execute(op, context):
-        obj = context.active_object
         animall_properties = context.window_manager.animall_properties
 
-        # Maybe this should be done for all object types,
-        # but keys can only be inserted in Edit Mode for CURVEs and SURFACEs,
-        # and Object Mode for MESHes and LATTICEs.
-        # Putting it inside if blocks for now
-        # # Set object mode
-        # if obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'}:
-        #     mode = obj.mode
-        #     bpy.ops.object.mode_set(mode='OBJECT')
-        #     data = obj.data
-
-        if obj.type == 'MESH':
-            mode = obj.mode
-            bpy.ops.object.mode_set(mode='OBJECT')
-            data = obj.data
+        if context.mode == 'OBJECT':
+            objects = context.selected_objects
+        else:
+            objects = context.objects_in_mode_unique_data[:]
 
-            if animall_properties.key_points:
-                for v_i, vert in enumerate(data.vertices):
-                    if not animall_properties.key_selected or vert.select:
-                        insert_key(vert, 'co', group="vertex %s" % v_i)
-
-            if animall_properties.key_vbevel:
-                for v_i, vert in enumerate(data.vertices):
-                    if not animall_properties.key_selected or vert.select:
-                        insert_key(vert, 'bevel_weight', group="vertex %s" % v_i)
-
-            if animall_properties.key_vgroups:
-                for v_i, vert in enumerate(data.vertices):
-                    if not animall_properties.key_selected or vert.select:
-                        for group in vert.groups:
-                            insert_key(group, 'weight', group="vertex %s" % v_i)
-
-            if animall_properties.key_ebevel:
-                for e_i, edge in enumerate(data.edges):
-                    if not animall_properties.key_selected or edge.select:
-                        insert_key(edge, 'bevel_weight', group="edge %s" % e_i)
-
-            if animall_properties.key_crease:
-                for e_i, edge in enumerate(data.edges):
-                    if not animall_properties.key_selected or edge.select:
-                        insert_key(edge, 'crease', group="edge %s" % e_i)
-
-            if animall_properties.key_shape:
-                if obj.active_shape_key_index > 0:
-                    for v_i, vert in enumerate(obj.active_shape_key.data):
-                        insert_key(vert, 'co', group="vertex %s" % v_i)
-
-            if animall_properties.key_uvs:
-                if data.uv_layers.active is not None:
-                    for uv_i, uv in enumerate(data.uv_layers.active.data):
-                        insert_key(uv, 'uv', group="UV layer %s" % uv_i)
-
-            if animall_properties.key_vcols:
-                for v_col_layer in data.vertex_colors:
-                    if v_col_layer.active:  # only insert in active VCol layer
-                        for v_i, data in enumerate(v_col_layer.data):
-                            insert_key(data, 'color', group="Loop %s" % v_i)
-
-            bpy.ops.object.mode_set(mode=mode)
-
-        elif obj.type == 'LATTICE':
-            mode = obj.mode
-            bpy.ops.object.mode_set(mode='OBJECT')
-            data = obj.data
+        mode = context.object.mode
 
-            if animall_properties.key_shape:
-                if obj.active_shape_key_index > 0:
-                    for p_i, point in enumerate(obj.active_shape_key.data):
-                        insert_key(point, 'co', group="Point %s" % p_i)
+        # Separate loop for lattices, curves and surfaces, since keyframe insertion
+        # has to happen in Edit Mode, otherwise points move back upon mode switch...
+        # (except for curve shape keys)
+        for obj in [o for o in objects if o.type in {'CURVE', 'SURFACE', 'LATTICE'}]:
+            data = obj.data
 
-            if animall_properties.key_points:
-                for p_i, point in enumerate(data.points):
-                    if not animall_properties.key_selected or point.select:
-                        insert_key(point, 'co_deform', group="Point %s" % p_i)
+            if obj.type == 'LATTICE':
+                if animall_properties.key_shape:
+                    if obj.active_shape_key_index > 0:
+                        sk_name = obj.active_shape_key.name
+                        for p_i, point in enumerate(obj.active_shape_key.data):
+                            if not animall_properties.key_selected or data.points[p_i].select:
+                                insert_key(point, 'co', group="%s Point %s" % (sk_name, p_i))
 
-            bpy.ops.object.mode_set(mode=mode)
+                if animall_properties.key_points:
+                    for p_i, point in enumerate(data.points):
+                        if not animall_properties.key_selected or point.select:
+                            insert_key(point, 'co_deform', group="Point %s" % p_i)
 
-        elif obj.type in {'CURVE', 'SURFACE'}:
+            else:
+                for s_i, spline in enumerate(data.splines):
+                    if spline.type == 'BEZIER':
+                        for v_i, CV in enumerate(spline.bezier_points):
+                            if (not animall_properties.key_selected
+                                    or CV.select_control_point
+                                    or CV.select_left_handle
+                                    or CV.select_right_handle):
+                                if animall_properties.key_points:
+                                    insert_key(CV, 'co', group="Spline %s CV %s" % (s_i, v_i))
+                                    insert_key(CV, 'handle_left', group="Spline %s CV %s" % (s_i, v_i))
+                                    insert_key(CV, 'handle_right', group="Spline %s CV %s" % (s_i, v_i))
+
+                                if animall_properties.key_radius:
+                                    insert_key(CV, 'radius', group="Spline %s CV %s" % (s_i, v_i))
+
+                                if animall_properties.key_tilt:
+                                    insert_key(CV, 'tilt', group="Spline %s CV %s" % (s_i, v_i))
+
+                    elif spline.type in ('POLY', 'NURBS'):
+                        for v_i, CV in enumerate(spline.points):
+                            if not animall_properties.key_selected or CV.select:
+                                if animall_properties.key_points:
+                                    insert_key(CV, 'co', group="Spline %s CV %s" % (s_i, v_i))
+
+                                if animall_properties.key_radius:
+                                    insert_key(CV, 'radius', group="Spline %s CV %s" % (s_i, v_i))
+
+                                if animall_properties.key_tilt:
+                                    insert_key(CV, 'tilt', group="Spline %s CV %s" % (s_i, v_i))
+
+        bpy.ops.object.mode_set(mode='OBJECT')
+
+        for obj in [o for o in objects if o.type in {'MESH', 'CURVE', 'SURFACE'}]:
             data = obj.data
-
-            # run this outside the splines loop (only once)
-            if animall_properties.key_shape:
-                if obj.active_shape_key_index > 0:
-                    for CV in obj.active_shape_key.data:
-                        insert_key(CV, 'co')
-                        insert_key(CV, 'handle_left')
-                        insert_key(CV, 'handle_right')
-
-            for s_i, spline in enumerate(data.splines):
-                if spline.type == 'BEZIER':
-                    for v_i, CV in enumerate(spline.bezier_points):
-                        if (not animall_properties.key_selected
-                                or CV.select_control_point
-                                or CV.select_left_handle
-                                or CV.select_right_handle):
-                            if animall_properties.key_points:
-                                insert_key(CV, 'co', group="spline %s CV %s" % (s_i, v_i))
-                                insert_key(CV, 'handle_left', group="spline %s CV %s" % (s_i, v_i))
-                                insert_key(CV, 'handle_right', group="spline %s CV %s" % (s_i, v_i))
-
-                            if animall_properties.key_radius:
-                                insert_key(CV, 'radius', group="spline %s CV %s" % (s_i, v_i))
-
-                            if animall_properties.key_tilt:
-                                insert_key(CV, 'tilt', group="spline %s CV %s" % (s_i, v_i))
-
-                elif spline.type in ('POLY', 'NURBS'):
-                    for v_i, CV in enumerate(spline.points):
-                        if not animall_properties.key_selected or CV.select:
-                            if animall_properties.key_points:
-                                insert_key(CV, 'co', group="spline %s CV %s" % (s_i, v_i))
-
-                            if animall_properties.key_radius:
-                                insert_key(CV, 'radius', group="spline %s CV %s" % (s_i, v_i))
-
-                            if animall_properties.key_tilt:
-               

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list