diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2020-01-21 21:59:39 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2020-01-21 22:10:02 +0300 |
commit | 56c7ee99b85833006bbda9c8f8ca4452278aae84 (patch) | |
tree | ee804400e23e6b65301e771869aec9c49ebec975 /source/blender/makesrna/intern | |
parent | 367d60dab13723a5a2d7a5336af0efa64b3c446d (diff) |
Fix T72619: Fix/implement support of particle modifiers in liboverride.
Some modifiers (like particle system, but also some other physics
simulations) require extra steps besides creating the modifier itself,
so had to switch to higher-level `ED_object_modifier_add()` to add
inserted modifiers in an overriding object data-block.
Due to how particle modifier handles copying, some extra nasty
hacks/work-around were also needed to get it working.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 950fa49db2e..40622894145 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1514,7 +1514,7 @@ static void rna_Object_modifier_clear(Object *object, bContext *C) WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object); } -bool rna_Object_modifiers_override_apply(Main *UNUSED(bmain), +bool rna_Object_modifiers_override_apply(Main *bmain, PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *UNUSED(ptr_storage), @@ -1537,7 +1537,7 @@ bool rna_Object_modifiers_override_apply(Main *UNUSED(bmain), /* Remember that insertion operations are defined and stored in correct order, which means that * even if we insert several items in a row, we always insert first one, then second one, etc. - * So we should always find 'anchor' constraint in both _src *and* _dst. */ + * So we should always find 'anchor' modifier in both _src *and* _dst. */ ModifierData *mod_anchor = NULL; if (opop->subitem_local_name && opop->subitem_local_name[0]) { mod_anchor = BLI_findstring( @@ -1560,18 +1560,32 @@ bool rna_Object_modifiers_override_apply(Main *UNUSED(bmain), BLI_assert(mod_src != NULL); - ModifierData *mod_dst = modifier_new(mod_src->type); + /* While it would be nicer to use lower-level modifier_new() here, this one is lacking + * special-cases handling (particles and other physics modifiers mostly), so using the ED version + * instead, to avoid duplicating code. */ + ModifierData *mod_dst = ED_object_modifier_add( + NULL, bmain, NULL, ob_dst, mod_src->name, mod_src->type); + + /* XXX Current handling of 'copy' from particlesystem modifier is *very* bad (it keeps same psys + * pointer as source, then calling code copies psys of object separately and do some magic + * remapping of pointers...), unfortunately several pieces of code in Obejct editing area rely on + * this behavior. So for now, hacking around it to get it doing what we want it to do, as getting + * a proper behavior would be everything but trivial, and this whole particle thingy is + * end-of-life. */ + ParticleSystem *psys_dst = (mod_dst->type == eModifierType_ParticleSystem) ? + ((ParticleSystemModifierData *)mod_dst)->psys : + NULL; modifier_copyData(mod_src, mod_dst); + if (mod_dst->type == eModifierType_ParticleSystem) { + psys_dst->flag &= ~PSYS_DELETE; + ((ParticleSystemModifierData *)mod_dst)->psys = psys_dst; + } + BLI_remlink(&ob_dst->modifiers, mod_dst); /* This handles NULL anchor as expected by adding at head of list. */ BLI_insertlinkafter(&ob_dst->modifiers, mod_anchor, mod_dst); - /* This should actually *not* be needed in typical cases. - * However, if overridden source was edited, - * we *may* have some new conflicting names. */ - modifier_unique_name(&ob_dst->modifiers, mod_dst); - - // printf("%s: We inserted a modifier...\n", __func__); + // printf("%s: We inserted a modifier '%s'...\n", __func__, mod_dst->name); return true; } |