[Bf-blender-cvs] [921390221dd] temp-angavrilov-constraints: Collision: allow disabling collision without removing the modifier.

Alexander Gavrilov noreply at git.blender.org
Sun Jan 10 11:50:46 CET 2021


Commit: 921390221dd419bb894cc9deb778e89dd1d1c81d
Author: Alexander Gavrilov
Date:   Sat Jan 9 21:15:53 2021 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rB921390221dd419bb894cc9deb778e89dd1d1c81d

Collision: allow disabling collision without removing the modifier.

The `object.collision.use` flag was treated as a redundant marker
of the existence of the modifier, going as far as adding/removing
it when the value was changed, which is not actually very useful.
Removing the modifier loses its position in the stack, and requires
a dependency graph rebuild. It feels it may be a legacy flag?

What would be useful however is the ability to toggle collisions
dynamically without removing the modifier. This patch adjusts the
code to only add the modifier when the flag is enabled. Disabling
the setting on the other hand keeps the modifier, which now checks
the flag at the start. The redesigned setting is exposed in the UI.

Collisions can't be disabled by simply using the modifier enable
flags because it still needs to be able to delete the stale data.

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

M	release/scripts/startup/bl_ui/properties_physics_field.py
M	source/blender/makesrna/intern/rna_object_force.c
M	source/blender/modifiers/intern/MOD_collision.c
M	source/blender/modifiers/intern/MOD_ui_common.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py b/release/scripts/startup/bl_ui/properties_physics_field.py
index c8c49ee02b0..3e3f73d3b2d 100644
--- a/release/scripts/startup/bl_ui/properties_physics_field.py
+++ b/release/scripts/startup/bl_ui/properties_physics_field.py
@@ -325,9 +325,10 @@ class PHYSICS_PT_collision(PhysicButtonsPanel, Panel):
 
         settings = context.object.collision
 
-        layout.active = settings.use
+        layout.prop(settings, "use", text="Enable Collision")
 
         col = layout.column()
+        col.active = settings.use
         col.prop(settings, "absorption", text="Field Absorption")
 
 
diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c
index 12fd2b78d91..b20df165da8 100644
--- a/source/blender/makesrna/intern/rna_object_force.c
+++ b/source/blender/makesrna/intern/rna_object_force.c
@@ -859,13 +859,10 @@ static void rna_CollisionSettings_dependency_update(Main *bmain, Scene *scene, P
   Object *ob = (Object *)ptr->owner_id;
   ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Collision);
 
-  /* add/remove modifier as needed */
+  /* add the modifier if needed */
   if (ob->pd->deflect && !md) {
     ED_object_modifier_add(NULL, bmain, scene, ob, NULL, eModifierType_Collision);
   }
-  else if (!ob->pd->deflect && md) {
-    ED_object_modifier_remove(NULL, bmain, scene, ob, md);
-  }
 
   WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
 }
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index a80bac7c6de..04b68a7a800 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -111,6 +111,16 @@ static void deformVerts(ModifierData *md,
   MVert *tempVert = NULL;
   Object *ob = ctx->object;
 
+  /* If collision is disabled, free the stale data and exit. */
+  if (!ob->pd || !ob->pd->deflect) {
+    if (!ob->pd) {
+      printf("CollisionModifier: collision settings are missing!\n");
+    }
+
+    freeData(md);
+    return;
+  }
+
   if (mesh == NULL) {
     mesh_src = MOD_deform_mesh_eval_get(ob, NULL, NULL, NULL, numVerts, false, false);
   }
@@ -120,11 +130,6 @@ static void deformVerts(ModifierData *md,
     mesh_src = (Mesh *)BKE_id_copy_ex(NULL, (ID *)mesh, NULL, LIB_ID_COPY_LOCALIZE);
   }
 
-  if (!ob->pd) {
-    printf("CollisionModifier deformVerts: Should not happen!\n");
-    return;
-  }
-
   if (mesh_src) {
     float current_time = 0;
     uint mvert_num = 0;
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index 58eeba35ca9..c5ee96491b8 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -351,8 +351,7 @@ static void modifier_panel_header(const bContext *C, Panel *panel)
     }
   }
   /* Collision and Surface are always enabled, hide buttons. */
-  if (((md->type != eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) &&
-      (md->type != eModifierType_Surface)) {
+  if ((md->type != eModifierType_Collision) && (md->type != eModifierType_Surface)) {
     if (mti->flags & eModifierTypeFlag_SupportsEditmode) {
       sub = uiLayoutRow(row, true);
       uiLayoutSetActive(sub, (md->mode & eModifierMode_Realtime));



More information about the Bf-blender-cvs mailing list