[Bf-blender-cvs] [a834c819ee2] master: GPencil: Add support for Link Modifiers

Antonio Vazquez noreply at git.blender.org
Thu May 7 10:01:35 CEST 2020


Commit: a834c819ee25d0107ad0d53786d67f3b766b37a6
Author: Antonio  Vazquez
Date:   Thu May 7 09:57:28 2020 +0200
Branches: master
https://developer.blender.org/rBa834c819ee25d0107ad0d53786d67f3b766b37a6

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

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

M	source/blender/blenkernel/intern/object.c

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

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 4df8b6f595a..ba0e113d25c 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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;
-    }
+      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;
-    }
+      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));
+      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);
+      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);
     }
+  }
 
-    modifier_copyData(md, nmd);
-    BLI_addtail(&ob_dst->modifiers, nmd);
-    modifier_unique_name(&ob_dst->modifiers, nmd);
+  /* 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);
+    }
   }
 
   BKE_object_copy_particlesystems(ob_dst, ob_src, 0);



More information about the Bf-blender-cvs mailing list