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
This commit is contained in:
Robert Guetzkow
2021-08-24 18:38:28 +02:00
committed by Robert Guetzkow
parent 551521cfa4
commit 38bdde852f
4 changed files with 15 additions and 9 deletions

View File

@@ -368,7 +368,10 @@ struct ModifierData *object_copy_particle_system(struct Main *bmain,
struct Scene *scene, struct Scene *scene,
struct Object *ob, struct Object *ob,
const struct ParticleSystem *psys_orig); 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); struct ParticleSettings *BKE_particlesettings_add(struct Main *bmain, const char *name);
void psys_reset(struct ParticleSystem *psys, int mode); void psys_reset(struct ParticleSystem *psys, int mode);

View File

@@ -3967,16 +3967,18 @@ ModifierData *object_copy_particle_system(Main *bmain,
return object_add_or_copy_particle_system(bmain, scene, ob, NULL, psys_orig); 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); if (!ob || !psys) {
ParticleSystemModifierData *psmd;
ModifierData *md;
if (!psys) {
return; return;
} }
ParticleSystemModifierData *psmd;
ModifierData *md;
/* Clear particle system in fluid modifier. */ /* Clear particle system in fluid modifier. */
if ((md = BKE_modifiers_findby_type(ob, eModifierType_Fluid))) { if ((md = BKE_modifiers_findby_type(ob, eModifierType_Fluid))) {
FluidModifierData *fmd = (FluidModifierData *)md; FluidModifierData *fmd = (FluidModifierData *)md;

View File

@@ -352,7 +352,7 @@ static bool object_modifier_remove(
/* special cases */ /* special cases */
if (md->type == eModifierType_ParticleSystem) { if (md->type == eModifierType_ParticleSystem) {
object_remove_particle_system(bmain, scene, ob); object_remove_particle_system(bmain, scene, ob, ((ParticleSystemModifierData *)md)->psys);
return true; return true;
} }

View File

@@ -124,7 +124,8 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
} }
mode_orig = ob->mode; 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 /* possible this isn't the active object
* object_remove_particle_system() clears the mode on the last psys * object_remove_particle_system() clears the mode on the last psys