GPencil: Add support for Link Modifiers

This adds support to the Link modifiers data. This was missing.

Also I did a small cleanup using LISTBASE_FOREACH macro.

Related to T76478

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D7643
This commit is contained in:
Antonio Vazquez 2020-05-07 09:57:28 +02:00 committed by Antonio Vazquez
parent b1374a8ce9
commit a834c819ee
Notes: blender-bot 2023-02-14 04:07:50 +01:00
Referenced by issue #76478, GPencil: Linking Modifier Data not supported
1 changed files with 49 additions and 31 deletions

View File

@ -544,48 +544,66 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
{
ModifierData *md;
BKE_object_free_modifiers(ob_dst, 0);
if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
/* only objects listed above can have modifiers and linking them to objects
* which doesn't have modifiers stack is quite silly */
return;
}
for (md = ob_src->modifiers.first; md; md = md->next) {
ModifierData *nmd = NULL;
/* No grease pencil modifiers. */
if ((ob_src->type != OB_GPENCIL) && (ob_dst->type != OB_GPENCIL)) {
LISTBASE_FOREACH (ModifierData *, md, &ob_src->modifiers) {
ModifierData *nmd = NULL;
if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
continue;
if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
continue;
}
if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) {
continue;
}
switch (md->type) {
case eModifierType_Softbody:
BKE_object_copy_softbody(ob_dst, ob_src, 0);
break;
case eModifierType_Skin:
/* ensure skin-node customdata exists */
BKE_mesh_ensure_skin_customdata(ob_dst->data);
break;
}
nmd = modifier_new(md->type);
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
if (md->type == eModifierType_Multires) {
/* Has to be done after mod creation, but *before* we actually copy its settings! */
multiresModifier_sync_levels_ex(
ob_dst, (MultiresModifierData *)md, (MultiresModifierData *)nmd);
}
modifier_copyData(md, nmd);
BLI_addtail(&ob_dst->modifiers, nmd);
modifier_unique_name(&ob_dst->modifiers, nmd);
}
}
if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) {
continue;
/* Copy grease pencil modifiers. */
if ((ob_src->type == OB_GPENCIL) && (ob_dst->type == OB_GPENCIL)) {
LISTBASE_FOREACH (GpencilModifierData *, md, &ob_src->greasepencil_modifiers) {
GpencilModifierData *nmd = NULL;
nmd = BKE_gpencil_modifier_new(md->type);
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type);
mti->copyData(md, nmd);
BLI_addtail(&ob_dst->greasepencil_modifiers, nmd);
BKE_gpencil_modifier_unique_name(&ob_dst->greasepencil_modifiers, nmd);
}
switch (md->type) {
case eModifierType_Softbody:
BKE_object_copy_softbody(ob_dst, ob_src, 0);
break;
case eModifierType_Skin:
/* ensure skin-node customdata exists */
BKE_mesh_ensure_skin_customdata(ob_dst->data);
break;
}
nmd = modifier_new(md->type);
BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
if (md->type == eModifierType_Multires) {
/* Has to be done after mod creation, but *before* we actually copy its settings! */
multiresModifier_sync_levels_ex(
ob_dst, (MultiresModifierData *)md, (MultiresModifierData *)nmd);
}
modifier_copyData(md, nmd);
BLI_addtail(&ob_dst->modifiers, nmd);
modifier_unique_name(&ob_dst->modifiers, nmd);
}
BKE_object_copy_particlesystems(ob_dst, ob_src, 0);