diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/fluid.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 40 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 4 |
4 files changed, 63 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 73ca490c395..1bdc2a5dfd2 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -4559,7 +4559,7 @@ void BKE_fluid_particle_system_destroy(struct Object *ob, const int particle_typ if (psys->part->type == particle_type) { /* clear modifier */ pfmd = psys_get_modifier(ob, psys); - BLI_remlink(&ob->modifiers, (ModifierData *)pfmd); + BKE_modifier_remove_from_list(ob, (ModifierData *)pfmd); BKE_modifier_free((ModifierData *)pfmd); /* clear particle system */ diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 3c8b685a0e0..c9bdaecfa2a 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -212,6 +212,26 @@ void BKE_modifier_free(ModifierData *md) BKE_modifier_free_ex(md, 0); } +/** + * Use instead of `BLI_remlink` when the object's active modifier should change. + */ +void BKE_modifier_remove_from_list(Object *ob, ModifierData *md) +{ + BLI_assert(BLI_findindex(&ob->modifiers, md) != -1); + + if (md->flag & eModifierFlag_Active) { + /* Prefer the previous modifier but use the next if this modifier is the first in the list. */ + if (md->next != NULL) { + BKE_object_modifier_set_active(ob, md->next); + } + else if (md->prev != NULL) { + BKE_object_modifier_set_active(ob, md->prev); + } + } + + BLI_remlink(&ob->modifiers, md); +} + void BKE_modifier_session_uuid_generate(ModifierData *md) { md->session_uuid = BLI_session_uuid_generate(); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 31d2e3738f4..d747da2213e 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1274,6 +1274,46 @@ void BKE_object_modifier_gpencil_hook_reset(Object *ob, HookGpencilModifierData } } +/** + * Set the object's active modifier. + * + * \param md: If NULL, only clear the active modifier, otherwise + * it must be in the #Object.modifiers list. + */ +void BKE_object_modifier_set_active(Object *ob, ModifierData *md) +{ + LISTBASE_FOREACH (ModifierData *, md_iter, &ob->modifiers) { + md_iter->flag &= ~eModifierFlag_Active; + } + + if (md != NULL) { + BLI_assert(BLI_findindex(&ob->modifiers, md) != -1); + md->flag |= eModifierFlag_Active; + } +} + +ModifierData *BKE_object_active_modifier(const Object *ob) +{ + /* In debug mode, check for only one active modifier. */ +#ifndef NDEBUG + int active_count = 0; + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { + if (md->flag & eModifierFlag_Active) { + active_count++; + } + } + BLI_assert(ELEM(active_count, 0, 1)); +#endif + + LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) { + if (md->flag & eModifierFlag_Active) { + return md; + } + } + + return NULL; +} + bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type) { const ModifierTypeInfo *mti; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 0b331fb88d2..d516de535f9 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -4046,7 +4046,7 @@ void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob /* Clear modifier, skip empty ones. */ psmd = psys_get_modifier(ob, psys); if (psmd) { - BLI_remlink(&ob->modifiers, psmd); + BKE_modifier_remove_from_list(ob, (ModifierData *)psmd); BKE_modifier_free((ModifierData *)psmd); } @@ -5401,7 +5401,7 @@ void BKE_particle_system_blend_read_lib(BlendLibReader *reader, else { /* particle modifier must be removed before particle system */ ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - BLI_remlink(&ob->modifiers, psmd); + BKE_modifier_remove_from_list(ob, (ModifierData *)psmd); BKE_modifier_free((ModifierData *)psmd); BLI_remlink(particles, psys); |