[Bf-blender-cvs] [38bdde852f1] master: Fix T90715: Remove correct particle modifier through Python API

Robert Guetzkow noreply at git.blender.org
Tue Aug 24 18:48:48 CEST 2021


Commit: 38bdde852f1c38a2eaba2b8efc15b49f226baffd
Author: Robert Guetzkow
Date:   Tue Aug 24 18:38:28 2021 +0200
Branches: master
https://developer.blender.org/rB38bdde852f1c38a2eaba2b8efc15b49f226baffd

Fix T90715: Remove correct particle modifier through Python API

Before this patch attempting to remove a particle modifier programmatically
through Python would fail, because it deleted the modifier associated with
the currently active particle system instead of the one passed as an argument
to `bpy.types.ObjectModifiers.remove()`.

This fix  adds an additional argument for the particle system to
`object_remove_particle_system`. This allows to specify which particle system
and its associated modifier shall be removed. In case of
`particle_system_remove_exec` it will remain the currently active particle
system, whereas `object_remove_particle_system` passes the particle system
of the modifier. Hence, the correct modifier will be removed.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D12234

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/physics/particle_object.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index e5b547d2557..78a6e47ec48 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -368,7 +368,10 @@ struct ModifierData *object_copy_particle_system(struct Main *bmain,
                                                  struct Scene *scene,
                                                  struct Object *ob,
                                                  const struct ParticleSystem *psys_orig);
-void object_remove_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob);
+void object_remove_particle_system(struct Main *bmain,
+                                   struct Scene *scene,
+                                   struct Object *ob,
+                                   struct ParticleSystem *psys);
 struct ParticleSettings *BKE_particlesettings_add(struct Main *bmain, const char *name);
 void psys_reset(struct ParticleSystem *psys, int mode);
 
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 29849c69b6f..50b0fb1c9f5 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3967,16 +3967,18 @@ ModifierData *object_copy_particle_system(Main *bmain,
   return object_add_or_copy_particle_system(bmain, scene, ob, NULL, psys_orig);
 }
 
-void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob)
+void object_remove_particle_system(Main *bmain,
+                                   Scene *UNUSED(scene),
+                                   Object *ob,
+                                   ParticleSystem *psys)
 {
-  ParticleSystem *psys = psys_get_current(ob);
-  ParticleSystemModifierData *psmd;
-  ModifierData *md;
-
-  if (!psys) {
+  if (!ob || !psys) {
     return;
   }
 
+  ParticleSystemModifierData *psmd;
+  ModifierData *md;
+
   /* Clear particle system in fluid modifier. */
   if ((md = BKE_modifiers_findby_type(ob, eModifierType_Fluid))) {
     FluidModifierData *fmd = (FluidModifierData *)md;
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index e9142742d15..e1e0a0600be 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -352,7 +352,7 @@ static bool object_modifier_remove(
 
   /* special cases */
   if (md->type == eModifierType_ParticleSystem) {
-    object_remove_particle_system(bmain, scene, ob);
+    object_remove_particle_system(bmain, scene, ob, ((ParticleSystemModifierData *)md)->psys);
     return true;
   }
 
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 2668846284d..3ac6dca3044 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -124,7 +124,8 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
   }
 
   mode_orig = ob->mode;
-  object_remove_particle_system(bmain, scene, ob);
+  ParticleSystem *psys = psys_get_current(ob);
+  object_remove_particle_system(bmain, scene, ob, psys);
 
   /* possible this isn't the active object
    * object_remove_particle_system() clears the mode on the last psys



More information about the Bf-blender-cvs mailing list