[Bf-blender-cvs] [7faebce4146] soc-2020-outliner: Outliner: Add modifier copy with drag and drop

Nathan Craddock noreply at git.blender.org
Sat Jul 18 19:44:30 CEST 2020


Commit: 7faebce41463875753e1fce3f2dfbccb285da34a
Author: Nathan Craddock
Date:   Sat Jul 18 11:43:35 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rB7faebce41463875753e1fce3f2dfbccb285da34a

Outliner: Add modifier copy with drag and drop

Allow copying single modifiers with drag and drop between objects. The
next step is to generalize the code for modifiers and use it for
contraints, modifiers, and shaderfx.

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/space_outliner/outliner_dragdrop.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index f2a022c84a3..c1efd594aaf 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -78,6 +78,10 @@ bool BKE_object_shaderfx_use_time(struct Object *ob, struct ShaderFxData *md);
 
 bool BKE_object_support_modifier_type_check(const struct Object *ob, int modifier_type);
 
+bool BKE_object_link_modifier(struct Object *ob_dst,
+                              const struct Object *ob_src,
+                              struct ModifierData *md);
+bool BKE_object_link_gpencil_modifier(struct Object *ob_dst, struct GpencilModifierData *md);
 void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src);
 void BKE_object_free_modifiers(struct Object *ob, const int flag);
 void BKE_object_free_shaderfx(struct Object *ob, const int flag);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index d48ea33cc65..10b463846a3 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -689,6 +689,60 @@ bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
   return false;
 }
 
+bool BKE_object_link_modifier(struct Object *ob_dst, const struct Object *ob_src, ModifierData *md)
+{
+  ModifierData *nmd = NULL;
+
+  if (ELEM(md->type, eModifierType_Hook, eModifierType_Collision)) {
+    return false;
+  }
+
+  if (!BKE_object_support_modifier_type_check(ob_dst, md->type)) {
+    return false;
+  }
+
+  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 = BKE_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);
+  }
+
+  BKE_modifier_copydata(md, nmd);
+  BLI_addtail(&ob_dst->modifiers, nmd);
+  BKE_modifier_unique_name(&ob_dst->modifiers, nmd);
+
+  return true;
+}
+
+bool BKE_object_link_gpencil_modifier(struct Object *ob_dst, GpencilModifierData *md)
+{
+  GpencilModifierData *nmd = NULL;
+
+  nmd = BKE_gpencil_modifier_new(md->type);
+  BLI_strncpy(nmd->name, md->name, sizeof(nmd->name));
+
+  const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info(md->type);
+  mti->copyData(md, nmd);
+
+  BLI_addtail(&ob_dst->greasepencil_modifiers, nmd);
+  BKE_gpencil_modifier_unique_name(&ob_dst->greasepencil_modifiers, nmd);
+
+  return true;
+}
+
 void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_src)
 {
   BKE_object_free_modifiers(ob_dst, 0);
@@ -702,54 +756,14 @@ void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_sr
   /* 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 (!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 = BKE_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);
-      }
-
-      BKE_modifier_copydata(md, nmd);
-      BLI_addtail(&ob_dst->modifiers, nmd);
-      BKE_modifier_unique_name(&ob_dst->modifiers, nmd);
+      BKE_object_link_modifier(ob_dst, ob_src, md);
     }
   }
 
   /* 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_modifier_get_info(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_link_gpencil_modifier(ob_dst, md);
     }
   }
 
diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c
index f22c4904581..87be29f0e27 100644
--- a/source/blender/editors/space_outliner/outliner_dragdrop.c
+++ b/source/blender/editors/space_outliner/outliner_dragdrop.c
@@ -769,14 +769,9 @@ static bool modifier_drop_poll(bContext *C,
     ob = (Object *)outliner_search_back(te_target, ID_OB);
   }
 
-  if (ob != drop_data->ob_parent) {
-    return false;
-  }
-
-  /* TODO (Nathan): Add ED_object_modifier_copy_to_object(). */
   if (outliner_ID_drop_find(C, event, ID_OB)) {
     *r_tooltip = TIP_("Copy modifier to object");
-    return false;
+    return true;
   }
 
   /* Reorder modifiers. */
@@ -830,6 +825,7 @@ static int modifier_drop_invoke(bContext *C, wmOperator *op, const wmEvent *even
 
   TreeElementInsertType insert_type;
   TreeElement *te = outliner_drop_insert_find(C, event, &insert_type);
+  TreeStoreElem *tselem = TREESTORE(te);
 
   if (drop_data->drag_tselem->type == TSE_MODIFIER_BASE) {
     Object *ob = (Object *)TREESTORE(te)->id;
@@ -841,6 +837,16 @@ static int modifier_drop_invoke(bContext *C, wmOperator *op, const wmEvent *even
     return OPERATOR_FINISHED;
   }
 
+  /* Copy if dropping on a different object. */
+  if ((Object *)tselem->id != drop_data->ob_parent) {
+    Object *ob_dst = (Object *)tselem->id;
+
+    BKE_object_link_modifier(ob_dst, drop_data->ob_parent, drop_data->drag_directdata);
+    WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob_dst);
+    DEG_id_tag_update(&ob_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
+    return OPERATOR_FINISHED;
+  }
+
   Object *ob = drop_data->ob_parent;
   int index = (insert_type == TE_INSERT_BEFORE) ? te->index : te->index + 1;
   index = (index > drop_data->drag_index) ? index - 1 : index;



More information about the Bf-blender-cvs mailing list