[Bf-blender-cvs] [83e245023c4] blender-v3.0-release: Fix (unreported) wrong behavior of constraints in liboverrides.

Bastien Montagne noreply at git.blender.org
Fri Nov 19 12:09:41 CET 2021


Commit: 83e245023c481aa2f57588724915e554c00c05d2
Author: Bastien Montagne
Date:   Fri Nov 19 11:48:25 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB83e245023c481aa2f57588724915e554c00c05d2

Fix (unreported) wrong behavior of constraints in liboverrides.

All constraints were 'made local', including the ones comming from the
reference linked object.

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

M	source/blender/blenkernel/BKE_lib_id.h
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/editors/object/object_constraint.c
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_pose.c

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

diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index b38125b791d..68399959a37 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -123,6 +123,9 @@ enum {
   LIB_ID_COPY_CD_REFERENCE = 1 << 20,
   /** Do not copy id->override_library, used by ID datablock override routines. */
   LIB_ID_COPY_NO_LIB_OVERRIDE = 1 << 21,
+  /** When copying local sub-data (like constraints or modifiers), do not set their "library
+   * override local data" flag. */
+  LIB_ID_COPY_NO_LIB_OVERRIDE_LOCAL_DATA_FLAG = 1 << 22,
 
   /* *** XXX Hackish/not-so-nice specific behaviors needed for some corner cases. *** */
   /* *** Ideally we should not have those, but we need them for now... *** */
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index b2b03d28483..7ddbaa0e9ee 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -6022,7 +6022,6 @@ bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const
   bConstraint *dst = MEM_dupallocN(src);
   constraint_copy_data_ex(dst, src, flag, do_extern);
   dst->next = dst->prev = NULL;
-  dst->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
   return dst;
 }
 
@@ -6057,7 +6056,9 @@ void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag,
   for (con = dst->first, srccon = src->first; con && srccon;
        srccon = srccon->next, con = con->next) {
     constraint_copy_data_ex(con, srccon, flag, do_extern);
-    con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+    if ((flag & LIB_ID_COPY_NO_LIB_OVERRIDE_LOCAL_DATA_FLAG) == 0) {
+      con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+    }
   }
 }
 
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 5117c8bd64c..9ed7218027f 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -2874,7 +2874,10 @@ void BKE_lib_override_library_update(Main *bmain, ID *local)
    * Not impossible to do, but would rather see first if extra useless usual user handling
    * is actually a (performances) issue here. */
 
-  ID *tmp_id = BKE_id_copy(bmain, local->override_library->reference);
+  ID *tmp_id = BKE_id_copy_ex(bmain,
+                              local->override_library->reference,
+                              NULL,
+                              LIB_ID_COPY_DEFAULT | LIB_ID_COPY_NO_LIB_OVERRIDE_LOCAL_DATA_FLAG);
 
   if (tmp_id == NULL) {
     return;
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 8702b18a46f..47c2998ed3d 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -1449,7 +1449,9 @@ void ED_object_constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListB
 
 void ED_object_constraint_copy_for_object(Main *bmain, Object *ob_dst, bConstraint *con)
 {
-  BKE_constraint_copy_for_object(ob_dst, con);
+  bConstraint *copy_con = BKE_constraint_copy_for_object(ob_dst, con);
+  copy_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+
   ED_object_constraint_dependency_tag_update(bmain, ob_dst, con);
   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob_dst);
 }
@@ -1459,7 +1461,9 @@ void ED_object_constraint_copy_for_pose(Main *bmain,
                                         bPoseChannel *pchan,
                                         bConstraint *con)
 {
-  BKE_constraint_copy_for_pose(ob_dst, pchan, con);
+  bConstraint *copy_con = BKE_constraint_copy_for_pose(ob_dst, pchan, con);
+  copy_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+
   ED_object_constraint_dependency_tag_update(bmain, ob_dst, con);
   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob_dst);
 }
@@ -1654,6 +1658,8 @@ static int constraint_copy_exec(bContext *C, wmOperator *op)
     /* Couldn't remove due to some invalid data. */
     return OPERATOR_CANCELLED;
   }
+  copy_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+
   /* Move constraint to correct position. */
   const int new_index = BLI_findindex(constraints, con) + 1;
   const int current_index = BLI_findindex(constraints, copy_con);
@@ -1731,7 +1737,9 @@ static int constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
         continue;
       }
 
-      BKE_constraint_copy_for_pose(ob, chan, con);
+      bConstraint *copy_con = BKE_constraint_copy_for_pose(ob, chan, con);
+      copy_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+
       /* Update flags (need to add here, not just copy). */
       chan->constflag |= pchan->constflag;
 
@@ -1753,7 +1761,9 @@ static int constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
         continue;
       }
 
-      BKE_constraint_copy_for_object(ob, con);
+      bConstraint *copy_con = BKE_constraint_copy_for_object(ob, con);
+      copy_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
+
       DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM);
     }
     CTX_DATA_END;
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 99865078cbe..bf64196c8ab 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1673,6 +1673,7 @@ static bConstraint *rna_Object_constraints_copy(Object *object, Main *bmain, Poi
 {
   bConstraint *con = con_ptr->data;
   bConstraint *new_con = BKE_constraint_copy_for_object(object, con);
+  new_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
 
   ED_object_constraint_tag_update(bmain, object, new_con);
   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, object);
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index ee509fa92d4..cdf7fe5a7aa 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -650,6 +650,7 @@ static bConstraint *rna_PoseChannel_constraints_copy(ID *id,
   Object *ob = (Object *)id;
   bConstraint *con = con_ptr->data;
   bConstraint *new_con = BKE_constraint_copy_for_pose(ob, pchan, con);
+  new_con->flag |= CONSTRAINT_OVERRIDE_LIBRARY_LOCAL;
 
   ED_object_constraint_dependency_tag_update(bmain, ob, new_con);
   WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, id);



More information about the Bf-blender-cvs mailing list