[Bf-blender-cvs] [2ae04254b37] blender-v2.93-release: Speedup rigid body "Copy from Active" operator

Jagannadhan Ravi noreply at git.blender.org
Mon Aug 9 08:42:33 CEST 2021


Commit: 2ae04254b374f3648a121f654cd2ecf8c79d8428
Author: Jagannadhan Ravi
Date:   Tue Jul 20 18:57:12 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rB2ae04254b374f3648a121f654cd2ecf8c79d8428

Speedup rigid body "Copy from Active" operator

If there were lots of selected objects without an existing rigid body,
we would add rigid bodies to them one by one.

This would be slow in python, now we instead do this as a batch
operation in C.

On my (Intel) MacBook it used to take 60 seconds and with this change it
takes about 0.3 seconds.

Reviewed By: Sebastian Parborg

Differential Revision: http://developer.blender.org/D11957

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

M	release/scripts/startup/bl_operators/rigidbody.py

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

diff --git a/release/scripts/startup/bl_operators/rigidbody.py b/release/scripts/startup/bl_operators/rigidbody.py
index bc80500c888..7f5edac4dfb 100644
--- a/release/scripts/startup/bl_operators/rigidbody.py
+++ b/release/scripts/startup/bl_operators/rigidbody.py
@@ -60,17 +60,22 @@ class CopyRigidbodySettings(Operator):
 
     def execute(self, context):
         obj_act = context.object
-        view_layer = context.view_layer
 
-        # deselect all but mesh objects
+        # Deselect all non mesh objects and objects that
+        # already have a rigid body attached.
+        rb_objects = []
         for o in context.selected_objects:
-            if o.type != 'MESH':
+            if o.type != 'MESH' or o.rigid_body is not None:
                 o.select_set(False)
-            elif o.rigid_body is None:
-                # Add rigidbody to object!
-                view_layer.objects.active = o
-                bpy.ops.rigidbody.object_add()
-        view_layer.objects.active = obj_act
+                if o.rigid_body is not None:
+                    rb_objects.append(o)
+
+        bpy.ops.rigidbody.objects_add()
+
+        # Ensure that the rigid body objects
+        # we've de-selected are selected again.
+        for o in rb_objects:
+            o.select_set(True)
 
         objects = context.selected_objects
         if objects:



More information about the Bf-blender-cvs mailing list