[Bf-blender-cvs] [286fcb3a605] master: LibOverride: Add 'owner library' info to some liboverride code.

Bastien Montagne noreply at git.blender.org
Wed Feb 2 10:23:53 CET 2022


Commit: 286fcb3a605a51a2d8e542095ffa87ceb71fdd08
Author: Bastien Montagne
Date:   Tue Feb 1 16:11:59 2022 +0100
Branches: master
https://developer.blender.org/rB286fcb3a605a51a2d8e542095ffa87ceb71fdd08

LibOverride: Add 'owner library' info to some liboverride code.

This will help when dealing with liboverrides from other library files,
e.g for resync or proxies conversion.

This commit only affects proxy conversion.

Part of T91671.

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

M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/space_outliner/outliner_tools.cc
M	source/blender/makesrna/intern/rna_ID.c

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

diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 30e75259967..e8065566c97 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -100,6 +100,9 @@ struct ID *BKE_lib_override_library_create_from_id(struct Main *bmain,
  * main. You can add more local IDs to be remapped to use new overriding ones by setting their
  * LIB_TAG_DOIT tag.
  *
+ * \param owner_library: the library in which the overrides should be created. Besides versioning
+ * and resync code path, this should always be NULL (i.e. the local .blend file).
+ *
  * \param reference_library: the library from which the linked data being overridden come from
  * (i.e. the library of the linked reference ID).
  *
@@ -109,6 +112,7 @@ struct ID *BKE_lib_override_library_create_from_id(struct Main *bmain,
  * \return \a true on success, \a false otherwise.
  */
 bool BKE_lib_override_library_create_from_tag(struct Main *bmain,
+                                              struct Library *owner_library,
                                               const struct Library *reference_library,
                                               bool do_no_main);
 /**
@@ -122,16 +126,24 @@ bool BKE_lib_override_library_create_from_tag(struct Main *bmain,
  *
  * \param view_layer: the active view layer to search instantiated collections in, can be NULL (in
  *                    which case \a scene's master collection children hierarchy is used instead).
+ *
+ * \param owner_library: the library in which the overrides should be created. Besides versioning
+ * and resync code path, this should always be NULL (i.e. the local .blend file).
+ *
  * \param id_root: The root ID to create an override from.
+ *
  * \param id_reference: Some reference ID used to do some post-processing after overrides have been
  * created, may be NULL. Typically, the Empty object instantiating the linked collection we
  * override, currently.
+ *
  * \param r_id_root_override: if not NULL, the override generated for the given \a id_root.
+ *
  * \return true if override was successfully created.
  */
 bool BKE_lib_override_library_create(struct Main *bmain,
                                      struct Scene *scene,
                                      struct ViewLayer *view_layer,
+                                     struct Library *owner_library,
                                      struct ID *id_root,
                                      struct ID *id_reference,
                                      struct ID **r_id_root_override);
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index d1375b1e5b5..a2c3cafc029 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -211,6 +211,7 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bo
 }
 
 static ID *lib_override_library_create_from(Main *bmain,
+                                            Library *owner_library,
                                             ID *reference_id,
                                             const int lib_id_copy_flags)
 {
@@ -227,6 +228,12 @@ static ID *lib_override_library_create_from(Main *bmain,
   }
   id_us_min(local_id);
 
+  /* TODO: Handle this properly in LIB_NO_MAIN case as well (i.e. resync case). Or offload to
+   * generic ID copy code? */
+  if ((lib_id_copy_flags & LIB_ID_CREATE_NO_MAIN) == 0) {
+    local_id->lib = owner_library;
+  }
+
   BKE_lib_override_library_init(local_id, reference_id);
 
   /* NOTE: From liboverride perspective (and RNA one), shape keys are considered as local embedded
@@ -281,7 +288,7 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain,
   BLI_assert(reference_id != NULL);
   BLI_assert(ID_IS_LINKED(reference_id));
 
-  ID *local_id = lib_override_library_create_from(bmain, reference_id, 0);
+  ID *local_id = lib_override_library_create_from(bmain, NULL, reference_id, 0);
   /* We cannot allow automatic hierarchy resync on this ID, it is highly likely to generate a giant
    * mess in case there are a lot of hidden, non-instantiated, non-properly organized dependencies.
    * Ref T94650. */
@@ -320,6 +327,7 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain,
 }
 
 bool BKE_lib_override_library_create_from_tag(Main *bmain,
+                                              Library *owner_library,
                                               const Library *reference_library,
                                               const bool do_no_main)
 {
@@ -351,7 +359,7 @@ bool BKE_lib_override_library_create_from_tag(Main *bmain,
        * This requires extra care further down the resync process,
        * see: #BKE_lib_override_library_resync. */
       reference_id->newid = lib_override_library_create_from(
-          bmain, reference_id, do_no_main ? LIB_ID_CREATE_NO_MAIN : 0);
+          bmain, owner_library, reference_id, do_no_main ? LIB_ID_CREATE_NO_MAIN : 0);
       if (reference_id->newid == NULL) {
         success = false;
         break;
@@ -813,7 +821,10 @@ static void lib_override_overrides_group_tag(LibOverrideGroupTagData *data)
   lib_override_overrides_group_tag_recursive(data);
 }
 
-static bool lib_override_library_create_do(Main *bmain, Scene *scene, ID *id_root)
+static bool lib_override_library_create_do(Main *bmain,
+                                           Scene *scene,
+                                           Library *owner_library,
+                                           ID *id_root)
 {
   BKE_main_relations_create(bmain, 0);
   LibOverrideGroupTagData data = {.bmain = bmain,
@@ -832,12 +843,13 @@ static bool lib_override_library_create_do(Main *bmain, Scene *scene, ID *id_roo
   BKE_main_relations_free(bmain);
   lib_override_group_tag_data_clear(&data);
 
-  return BKE_lib_override_library_create_from_tag(bmain, id_root->lib, false);
+  return BKE_lib_override_library_create_from_tag(bmain, owner_library, id_root->lib, false);
 }
 
 static void lib_override_library_create_post_process(Main *bmain,
                                                      Scene *scene,
                                                      ViewLayer *view_layer,
+                                                     const Library *owner_library,
                                                      ID *id_root,
                                                      ID *id_reference,
                                                      Collection *residual_storage,
@@ -859,7 +871,8 @@ static void lib_override_library_create_post_process(Main *bmain,
 
   /* Instantiating the root collection or object should never be needed in resync case, since the
    * old override would be remapped to the new one. */
-  if (!is_resync && id_root != NULL && id_root->newid != NULL && !ID_IS_LINKED(id_root->newid)) {
+  if (!is_resync && id_root != NULL && id_root->newid != NULL &&
+      (!ID_IS_LINKED(id_root->newid) || id_root->newid->lib == owner_library)) {
     switch (GS(id_root->name)) {
       case ID_GR: {
         Object *ob_reference = id_reference != NULL && GS(id_reference->name) == ID_OB ?
@@ -904,7 +917,7 @@ static void lib_override_library_create_post_process(Main *bmain,
   Collection *default_instantiating_collection = residual_storage;
   LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
     Object *ob_new = (Object *)ob->id.newid;
-    if (ob_new == NULL || ID_IS_LINKED(ob_new)) {
+    if (ob_new == NULL || (ID_IS_LINKED(ob_new) && ob_new->id.lib != owner_library)) {
       continue;
     }
 
@@ -967,6 +980,7 @@ static void lib_override_library_create_post_process(Main *bmain,
 bool BKE_lib_override_library_create(Main *bmain,
                                      Scene *scene,
                                      ViewLayer *view_layer,
+                                     Library *owner_library,
                                      ID *id_root,
                                      ID *id_reference,
                                      ID **r_id_root_override)
@@ -975,7 +989,7 @@ bool BKE_lib_override_library_create(Main *bmain,
     *r_id_root_override = NULL;
   }
 
-  const bool success = lib_override_library_create_do(bmain, scene, id_root);
+  const bool success = lib_override_library_create_do(bmain, scene, owner_library, id_root);
 
   if (!success) {
     return success;
@@ -986,7 +1000,7 @@ bool BKE_lib_override_library_create(Main *bmain,
   }
 
   lib_override_library_create_post_process(
-      bmain, scene, view_layer, id_root, id_reference, NULL, false);
+      bmain, scene, view_layer, owner_library, id_root, id_reference, NULL, false);
 
   /* Cleanup. */
   BKE_main_id_newptr_and_tag_clear(bmain);
@@ -1055,7 +1069,8 @@ bool BKE_lib_override_library_proxy_convert(Main *bmain,
   }
   FOREACH_MAIN_ID_END;
 
-  return BKE_lib_override_library_create(bmain, scene, view_layer, id_root, id_reference, NULL);
+  return BKE_lib_override_library_create(
+      bmain, scene, view_layer, ob_proxy->id.lib, id_root, id_reference, NULL);
 }
 
 static void lib_override_library_proxy_convert_do(Main *bmain,
@@ -1288,7 +1303,7 @@ static bool lib_override_library_resync(Main *bmain,
    * override IDs (including within the old overrides themselves, since those are tagged too
    * above). */
   const bool success = BKE_lib_override_library_create_from_tag(
-      bmain, id_root_reference->lib, true);
+      bmain, NULL, id_root_reference->lib, true);
 
   if (!success) {
     return success;
@@ -1502,6 +1517,7 @@ static bool lib_override_library_resync(Main *bmain,
     lib_override_library_create_post_process(bmain,
                                              scene,
                                              view_layer,
+                                             NULL,
                                              id_root_reference,
                                              id_root,
                                              override_resync_residual_storage,
@@ -1926,7 +1942,7 @@ void BKE_lib_override_library_main_resync(Main *bmain,
 
   /* Essentially ensures that potentially new overrides of 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list