Blender  V2.93
lib_override.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "CLG_log.h"
28 
29 #include "MEM_guardedalloc.h"
30 
31 #include "DNA_ID.h"
32 #include "DNA_collection_types.h"
33 #include "DNA_key_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 
37 #include "DEG_depsgraph.h"
38 #include "DEG_depsgraph_build.h"
39 
40 #include "BKE_armature.h"
41 #include "BKE_collection.h"
42 #include "BKE_global.h"
43 #include "BKE_idtype.h"
44 #include "BKE_key.h"
45 #include "BKE_layer.h"
46 #include "BKE_lib_id.h"
47 #include "BKE_lib_override.h"
48 #include "BKE_lib_query.h"
49 #include "BKE_lib_remap.h"
50 #include "BKE_main.h"
51 #include "BKE_node.h"
52 #include "BKE_report.h"
53 #include "BKE_scene.h"
54 
55 #include "BLI_ghash.h"
56 #include "BLI_listbase.h"
57 #include "BLI_string.h"
58 #include "BLI_task.h"
59 #include "BLI_utildefines.h"
60 
61 #include "RNA_access.h"
62 #include "RNA_types.h"
63 
64 #include "atomic_ops.h"
65 
66 #define OVERRIDE_AUTO_CHECK_DELAY 0.2 /* 200ms between auto-override checks. */
67 //#define DEBUG_OVERRIDE_TIMEIT
68 
69 #ifdef DEBUG_OVERRIDE_TIMEIT
70 # include "PIL_time_utildefines.h"
71 #endif
72 
73 static CLG_LogRef LOG = {"bke.liboverride"};
74 
79 
83 
86 {
87  /* If reference_id is NULL, we are creating an override template for purely local data.
88  * Else, reference *must* be linked data. */
89  BLI_assert(reference_id == NULL || reference_id->lib != NULL);
90  BLI_assert(local_id->override_library == NULL);
91 
92  ID *ancestor_id;
93  for (ancestor_id = reference_id; ancestor_id != NULL && ancestor_id->override_library != NULL &&
94  ancestor_id->override_library->reference != NULL;
95  ancestor_id = ancestor_id->override_library->reference) {
96  /* pass */
97  }
98 
99  if (ancestor_id != NULL && ancestor_id->override_library != NULL) {
100  /* Original ID has a template, use it! */
101  BKE_lib_override_library_copy(local_id, ancestor_id, true);
102  if (local_id->override_library->reference != reference_id) {
104  local_id->override_library->reference = reference_id;
106  }
107  return local_id->override_library;
108  }
109 
110  /* Else, generate new empty override. */
111  local_id->override_library = MEM_callocN(sizeof(*local_id->override_library), __func__);
112  local_id->override_library->reference = reference_id;
114  local_id->tag &= ~LIB_TAG_OVERRIDE_LIBRARY_REFOK;
115  /* TODO do we want to add tag or flag to referee to mark it as such? */
116  return local_id->override_library;
117 }
118 
120 void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_full_copy)
121 {
123 
124  if (dst_id->override_library != NULL) {
125  if (src_id->override_library == NULL) {
127  return;
128  }
129 
131  }
132  else if (src_id->override_library == NULL) {
133  /* Virtual overrides of embedded data does not require any extra work. */
134  return;
135  }
136  else {
138  }
139 
140  /* If source is already overriding data, we copy it but reuse its reference for dest ID.
141  * Otherwise, source is only an override template, it then becomes reference of dest ID. */
143  src_id->override_library->reference :
144  (ID *)src_id;
146 
147  if (do_full_copy) {
149  &src_id->override_library->properties);
151  *op_src = src_id->override_library->properties.first;
152  op_dst;
153  op_dst = op_dst->next, op_src = op_src->next) {
154  lib_override_library_property_copy(op_dst, op_src);
155  }
156  }
157 
159 }
160 
162 void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_id_user)
163 {
164  BLI_assert(override != NULL);
165 
166  if (!ELEM(NULL, override->runtime, override->runtime->rna_path_to_override_properties)) {
167  BLI_ghash_clear(override->runtime->rna_path_to_override_properties, NULL, NULL);
168  }
169 
170  LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) {
172  }
173  BLI_freelistN(&override->properties);
174 
175  if (do_id_user) {
176  id_us_min(override->reference);
177  /* override->storage should never be refcounted... */
178  }
179 }
180 
182 void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bool do_id_user)
183 {
184  BLI_assert(*override != NULL);
185 
186  if ((*override)->runtime != NULL) {
187  if ((*override)->runtime->rna_path_to_override_properties != NULL) {
188  BLI_ghash_free((*override)->runtime->rna_path_to_override_properties, NULL, NULL);
189  }
190  MEM_SAFE_FREE((*override)->runtime);
191  }
192 
193  BKE_lib_override_library_clear(*override, do_id_user);
194  MEM_freeN(*override);
195  *override = NULL;
196 }
197 
198 static ID *lib_override_library_create_from(Main *bmain, ID *reference_id)
199 {
200  /* Note: We do not want to copy possible override data from reference here (whether it is an
201  * override template, or already an override of some other ref data). */
202  ID *local_id = BKE_id_copy_ex(
203  bmain, reference_id, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_NO_LIB_OVERRIDE);
204 
205  if (local_id == NULL) {
206  return NULL;
207  }
208  id_us_min(local_id);
209 
210  BKE_lib_override_library_init(local_id, reference_id);
211 
212  /* Note: From liboverride perspective (and RNA one), shape keys are considered as local embedded
213  * data-blocks, just like root node trees or master collections. Therefore, we never need to
214  * create overrides for them. We need a way to mark them as overrides though. */
215  Key *reference_key;
216  if ((reference_key = BKE_key_from_id(reference_id)) != NULL) {
217  Key *local_key = BKE_key_from_id(local_id);
218  BLI_assert(local_key != NULL);
219  local_key->id.flag |= LIB_EMBEDDED_DATA_LIB_OVERRIDE;
220  }
221 
222  return local_id;
223 }
224 
232 {
233  if (!ID_IS_OVERRIDE_LIBRARY(id)) {
234  return false;
235  }
236 
238  LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
239  if ((opop->flag & IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) != 0) {
240  continue;
241  }
242  if (opop->operation == IDOVERRIDE_LIBRARY_OP_NOOP) {
243  continue;
244  }
245  /* If an operation does not match the filters above, it is considered as a user-editing one,
246  * therefore this override is user-edited. */
247  return true;
248  }
249  }
250  return false;
251 }
252 
255  ID *reference_id,
256  const bool do_tagged_remap)
257 {
258  BLI_assert(reference_id != NULL);
259  BLI_assert(reference_id->lib != NULL);
260 
261  ID *local_id = lib_override_library_create_from(bmain, reference_id);
262 
263  if (do_tagged_remap) {
264  Key *reference_key, *local_key = NULL;
265  if ((reference_key = BKE_key_from_id(reference_id)) != NULL) {
266  local_key = BKE_key_from_id(local_id);
267  BLI_assert(local_key != NULL);
268  }
269 
270  ID *other_id;
271  FOREACH_MAIN_ID_BEGIN (bmain, other_id) {
272  if ((other_id->tag & LIB_TAG_DOIT) != 0 && other_id->lib == NULL) {
273  /* Note that using ID_REMAP_SKIP_INDIRECT_USAGE below is superfluous, as we only remap
274  * local IDs usages anyway. */
276  other_id,
277  reference_id,
278  local_id,
280  if (reference_key != NULL) {
282  other_id,
283  &reference_key->id,
284  &local_key->id,
286  }
287  }
288  }
290  }
291 
292  return local_id;
293 }
294 
309 {
310  ID *reference_id;
311  bool success = true;
312 
313  ListBase todo_ids = {NULL};
314  LinkData *todo_id_iter;
315 
316  /* Get all IDs we want to override. */
317  FOREACH_MAIN_ID_BEGIN (bmain, reference_id) {
318  if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL &&
319  BKE_idtype_idcode_is_linkable(GS(reference_id->name))) {
320  todo_id_iter = MEM_callocN(sizeof(*todo_id_iter), __func__);
321  todo_id_iter->data = reference_id;
322  BLI_addtail(&todo_ids, todo_id_iter);
323  }
324  }
326 
327  /* Override the IDs. */
328  for (todo_id_iter = todo_ids.first; todo_id_iter != NULL; todo_id_iter = todo_id_iter->next) {
329  reference_id = todo_id_iter->data;
330  if (reference_id->newid == NULL) {
331  /* If `newid` is already set, assume it has been handled by calling code.
332  * Only current use case: re-using proxy ID when converting to liboverride. */
333  if ((reference_id->newid = lib_override_library_create_from(bmain, reference_id)) == NULL) {
334  success = false;
335  break;
336  }
337  }
338  /* We also tag the new IDs so that in next step we can remap their pointers too. */
339  reference_id->newid->tag |= LIB_TAG_DOIT;
340 
341  Key *reference_key;
342  if ((reference_key = BKE_key_from_id(reference_id)) != NULL) {
343  reference_key->id.tag |= LIB_TAG_DOIT;
344 
345  Key *local_key = BKE_key_from_id(reference_id->newid);
346  BLI_assert(local_key != NULL);
347  reference_key->id.newid = &local_key->id;
348  /* We also tag the new IDs so that in next step we can remap their pointers too. */
349  local_key->id.tag |= LIB_TAG_DOIT;
350  }
351  }
352 
353  /* Only remap new local ID's pointers, we don't want to force our new overrides onto our whole
354  * existing linked IDs usages. */
355  if (success) {
356  for (todo_id_iter = todo_ids.first; todo_id_iter != NULL; todo_id_iter = todo_id_iter->next) {
357  ID *other_id;
358  reference_id = todo_id_iter->data;
359  ID *local_id = reference_id->newid;
360 
361  if (local_id == NULL) {
362  continue;
363  }
364 
365  Key *reference_key, *local_key = NULL;
366  if ((reference_key = BKE_key_from_id(reference_id)) != NULL) {
367  local_key = BKE_key_from_id(reference_id->newid);
368  BLI_assert(local_key != NULL);
369  }
370 
371  /* Still checking the whole Main, that way we can tag other local IDs as needing to be
372  * remapped to use newly created overriding IDs, if needed. */
373  FOREACH_MAIN_ID_BEGIN (bmain, other_id) {
374  if ((other_id->tag & LIB_TAG_DOIT) != 0 && other_id->lib == NULL) {
375  /* Note that using ID_REMAP_SKIP_INDIRECT_USAGE below is superfluous, as we only remap
376  * local IDs usages anyway. */
378  other_id,
379  reference_id,
380  local_id,
382  if (reference_key != NULL) {
384  other_id,
385  &reference_key->id,
386  &local_key->id,
388  }
389  }
390  }
392  }
393  }
394  else {
395  /* We need to cleanup potentially already created data. */
396  for (todo_id_iter = todo_ids.first; todo_id_iter != NULL; todo_id_iter = todo_id_iter->next) {
397  reference_id = todo_id_iter->data;
398  BKE_id_delete(bmain, reference_id->newid);
399  reference_id->newid = NULL;
400  }
401  }
402 
403  BLI_freelistN(&todo_ids);
404 
405  return success;
406 }
407 
408 typedef struct LibOverrideGroupTagData {
414 
415 /* Tag all IDs in dependency relationships within an override hierarchy/group.
416  *
417  * Requires existing `Main.relations`.
418  *
419  * NOTE: This is typically called to complete `lib_override_linked_group_tag()`.
420  */
422 {
423  Main *bmain = data->bmain;
424  ID *id = data->id_root;
425 
427  BLI_assert(entry != NULL);
428 
430  /* This ID has already been processed. */
431  return (*(uint *)&id->tag & data->tag) != 0;
432  }
433  /* This way we won't process again that ID, should we encounter it again through another
434  * relationship hierarchy. */
436 
437  for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
438  to_id_entry = to_id_entry->next) {
439  if ((to_id_entry->usage_flag & IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE) != 0) {
440  /* Never consider non-overridable relationships ('from', 'parents', 'owner' etc. pointers) as
441  * actual dependencies. */
442  continue;
443  }
444  /* We only consider IDs from the same library. */
445  ID *to_id = *to_id_entry->id_pointer.to;
446  if (!ID_IS_LINKED(to_id) && !ID_IS_OVERRIDE_LIBRARY(to_id)) {
447  /* Pure local data is a barrier of dependency in override cases. */
448  continue;
449  }
450  if (to_id != NULL && to_id->lib == id->lib) {
451  LibOverrideGroupTagData sub_data = *data;
452  sub_data.id_root = to_id;
454  id->tag |= data->tag;
455  }
456  }
457  }
458 
459  return (*(uint *)&id->tag & data->tag) != 0;
460 }
461 
463 {
464  Main *bmain = data->bmain;
465  ID *id_owner = data->id_root;
466  BLI_assert(ID_IS_LINKED(id_owner));
467  const uint tag = data->tag;
468  const uint missing_tag = data->missing_tag;
469 
471  id_owner);
472  BLI_assert(entry != NULL);
473 
475  /* This ID has already been processed. */
476  return;
477  }
478  /* This way we won't process again that ID, should we encounter it again through another
479  * relationship hierarchy. */
481 
482  for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
483  to_id_entry = to_id_entry->next) {
484  if ((to_id_entry->usage_flag & IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE) != 0) {
485  /* Never consider non-overridable relationships as actual dependencies. */
486  continue;
487  }
488 
489  ID *to_id = *to_id_entry->id_pointer.to;
490  if (ELEM(to_id, NULL, id_owner)) {
491  continue;
492  }
493  /* We only consider IDs from the same library. */
494  if (to_id->lib != id_owner->lib) {
495  continue;
496  }
497  BLI_assert(ID_IS_LINKED(to_id));
498 
499  /* We tag all collections and objects for override. And we also tag all other data-blocks which
500  * would use one of those.
501  * Note: missing IDs (aka placeholders) are never overridden. */
502  if (ELEM(GS(to_id->name), ID_OB, ID_GR)) {
503  if ((to_id->tag & LIB_TAG_MISSING)) {
504  to_id->tag |= missing_tag;
505  }
506  else {
507  to_id->tag |= tag;
508  }
509  }
510 
511  /* Recursively process the dependencies. */
512  LibOverrideGroupTagData sub_data = *data;
513  sub_data.id_root = to_id;
515  }
516 }
517 
518 /* This will tag at least all 'boundary' linked IDs for a potential override group.
519  *
520  * Requires existing `Main.relations`.
521  *
522  * Note that you will then need to call #lib_override_hierarchy_dependencies_recursive_tag to
523  * complete tagging of all dependencies within the override group.
524  *
525  * We currently only consider Collections and Objects (that are not used as bone shapes) as valid
526  * boundary IDs to define an override group.
527  */
529 {
530  Main *bmain = data->bmain;
531  ID *id_root = data->id_root;
532 
533  if ((id_root->tag & LIB_TAG_MISSING)) {
534  id_root->tag |= data->missing_tag;
535  }
536  else {
537  id_root->tag |= data->tag;
538  }
539 
540  if (ELEM(GS(id_root->name), ID_OB, ID_GR)) {
541  /* Tag all collections and objects. */
543 
544  /* Then, we remove (untag) bone shape objects, you shall never want to directly/explicitly
545  * override those. */
546  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
547  if (ob->type == OB_ARMATURE && ob->pose != NULL && (ob->id.tag & data->tag)) {
548  for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan != NULL; pchan = pchan->next) {
549  if (pchan->custom != NULL) {
550  pchan->custom->id.tag &= ~(data->tag | data->missing_tag);
551  }
552  }
553  }
554  }
555  }
556 }
557 
559 {
560  Main *bmain = data->bmain;
561  ID *id_owner = data->id_root;
563  const uint tag = data->tag;
564  const uint missing_tag = data->missing_tag;
565 
567  id_owner);
568  BLI_assert(entry != NULL);
569 
571  /* This ID has already been processed. */
572  return;
573  }
574  /* This way we won't process again that ID, should we encounter it again through another
575  * relationship hierarchy. */
577 
578  for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
579  to_id_entry = to_id_entry->next) {
580  if ((to_id_entry->usage_flag & IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE) != 0) {
581  /* Never consider non-overridable relationships as actual dependencies. */
582  continue;
583  }
584 
585  ID *to_id = *to_id_entry->id_pointer.to;
586  if (ELEM(to_id, NULL, id_owner)) {
587  continue;
588  }
589  if (!ID_IS_OVERRIDE_LIBRARY(to_id) || ID_IS_LINKED(to_id)) {
590  continue;
591  }
592 
593  /* Do not tag 'virtual' overrides (shape keys here, as we already rejected embedded case
594  * above). */
595  if (ID_IS_OVERRIDE_LIBRARY_REAL(to_id)) {
596  Library *reference_lib = NULL;
597  if (GS(id_owner->name) == ID_KE) {
598  reference_lib = ((Key *)id_owner)->from->override_library->reference->lib;
599  }
600  else {
601  reference_lib = id_owner->override_library->reference->lib;
602  }
603  if (to_id->override_library->reference->lib != reference_lib) {
604  /* We do not override data-blocks from other libraries, nor do we process them. */
605  continue;
606  }
607 
609  to_id->tag |= missing_tag;
610  }
611  else {
612  to_id->tag |= tag;
613  }
614  }
615 
616  /* Recursively process the dependencies. */
617  LibOverrideGroupTagData sub_data = *data;
618  sub_data.id_root = to_id;
620  }
621 }
622 
623 /* This will tag all override IDs of an override group defined by the given `id_root`. */
625 {
626  ID *id_root = data->id_root;
627  BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_root) && !ID_IS_LINKED(id_root));
628 
629  if ((id_root->override_library->reference->tag & LIB_TAG_MISSING)) {
630  id_root->tag |= data->missing_tag;
631  }
632  else {
633  id_root->tag |= data->tag;
634  }
635 
636  /* Tag all local overrides in id_root's group. */
638 }
639 
640 static bool lib_override_library_create_do(Main *bmain, ID *id_root)
641 {
642  BKE_main_relations_create(bmain, 0);
644  .bmain = bmain, .id_root = id_root, .tag = LIB_TAG_DOIT, .missing_tag = LIB_TAG_MISSING};
646 
649 
651 
653 }
654 
656  Scene *scene,
657  ViewLayer *view_layer,
658  ID *id_root,
659  ID *id_reference,
660  Collection *residual_storage,
661  const bool is_resync)
662 {
664 
665  /* We create a set of all objects referenced into the scene by its hierarchy of collections.
666  * NOTE: This is different that the list of bases, since objects in excluded collections etc.
667  * won't have a base, but are still considered as instanced from our point of view. */
668  GSet *all_objects_in_scene = BKE_scene_objects_as_gset(scene, NULL);
669 
670  /* Instantiating the root collection or object should never be needed in resync case, since the
671  * old override would be remapped to the new one. */
672  if (!is_resync && id_root != NULL && id_root->newid != NULL) {
673  switch (GS(id_root->name)) {
674  case ID_GR: {
675  Object *ob_reference = id_reference != NULL && GS(id_reference->name) == ID_OB ?
676  (Object *)id_reference :
677  NULL;
678  Collection *collection_new = ((Collection *)id_root->newid);
679  if (is_resync && BKE_collection_is_in_scene(collection_new)) {
680  break;
681  }
682  if (ob_reference != NULL) {
683  BKE_collection_add_from_object(bmain, scene, ob_reference, collection_new);
684  }
685  else if (id_reference != NULL) {
686  BLI_assert(GS(id_reference->name) == ID_GR);
688  bmain, scene, ((Collection *)id_reference), collection_new);
689  }
690  else {
692  bmain, scene, ((Collection *)id_root), collection_new);
693  }
694 
695  BLI_assert(BKE_collection_is_in_scene(collection_new));
696 
697  all_objects_in_scene = BKE_scene_objects_as_gset(scene, all_objects_in_scene);
698  break;
699  }
700  case ID_OB: {
701  Object *ob_new = (Object *)id_root->newid;
702  if (BLI_gset_lookup(all_objects_in_scene, ob_new) == NULL) {
703  BKE_collection_object_add_from(bmain, scene, (Object *)id_root, ob_new);
704  all_objects_in_scene = BKE_scene_objects_as_gset(scene, all_objects_in_scene);
705  }
706  break;
707  }
708  default:
709  break;
710  }
711  }
712 
713  /* We need to ensure all new overrides of objects are properly instantiated. */
714  Collection *default_instantiating_collection = residual_storage;
715  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
716  Object *ob_new = (Object *)ob->id.newid;
717  if (ob_new != NULL) {
718  BLI_assert(ob_new->id.override_library != NULL &&
719  ob_new->id.override_library->reference == &ob->id);
720 
721  if (BLI_gset_lookup(all_objects_in_scene, ob_new) == NULL) {
722  if (id_root != NULL && default_instantiating_collection == NULL) {
723  ID *id_ref = id_root->newid != NULL ? id_root->newid : id_root;
724  switch (GS(id_ref->name)) {
725  case ID_GR: {
726  /* Adding the object to a specific collection outside of the root overridden one is a
727  * fairly bad idea (it breaks the override hierarchy concept). But htere is no other
728  * way to do this currently (we cannot add new collections to overridden root one,
729  * this is not currently supported).
730  * Since that will be fairly annoying and noisy, only do that in case the override
731  * object is not part of any existing collection (i.e. its user count is 0). In
732  * practice this should never happen I think. */
733  if (ID_REAL_USERS(ob_new) != 0) {
734  continue;
735  }
736  default_instantiating_collection = BKE_collection_add(
737  bmain, (Collection *)id_root, "OVERRIDE_HIDDEN");
738  /* Hide the collection from viewport and render. */
739  default_instantiating_collection->flag |= COLLECTION_RESTRICT_VIEWPORT |
741  break;
742  }
743  case ID_OB: {
744  /* Add the other objects to one of the collections instantiating the
745  * root object, or scene's master collection if none found. */
746  Object *ob_ref = (Object *)id_ref;
747  LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
748  if (BKE_collection_has_object(collection, ob_ref) &&
749  BKE_view_layer_has_collection(view_layer, collection) &&
750  !ID_IS_LINKED(collection) && !ID_IS_OVERRIDE_LIBRARY(collection)) {
751  default_instantiating_collection = collection;
752  }
753  }
754  break;
755  }
756  default:
757  BLI_assert(0);
758  }
759  }
760  if (default_instantiating_collection == NULL) {
761  default_instantiating_collection = scene->master_collection;
762  }
763 
764  BKE_collection_object_add(bmain, default_instantiating_collection, ob_new);
766  }
767  }
768  }
769 
770  BLI_gset_free(all_objects_in_scene, NULL);
771 }
772 
789  Main *bmain, Scene *scene, ViewLayer *view_layer, ID *id_root, ID *id_reference)
790 {
791  const bool success = lib_override_library_create_do(bmain, id_root);
792 
793  if (!success) {
794  return success;
795  }
796 
798  bmain, scene, view_layer, id_root, id_reference, NULL, false);
799 
800  /* Cleanup. */
802  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
803 
804  /* We need to rebuild some of the deleted override rules (for UI feedback purpose). */
806 
807  return success;
808 }
809 
814 {
815  if (ID_IS_LINKED(id)) {
816  return false;
817  }
818  if (ID_IS_OVERRIDE_LIBRARY(id)) {
819  return false;
820  }
821 
823  return true;
824 }
825 
835  Scene *scene,
836  ViewLayer *view_layer,
837  Object *ob_proxy)
838 {
839  /* `proxy_group`, if defined, is the empty instantiating the collection from which the proxy is
840  * coming. */
841  Object *ob_proxy_group = ob_proxy->proxy_group;
842  const bool is_override_instancing_object = ob_proxy_group != NULL;
843  ID *id_root = is_override_instancing_object ? &ob_proxy_group->instance_collection->id :
844  &ob_proxy->proxy->id;
845  ID *id_reference = is_override_instancing_object ? &ob_proxy_group->id : &ob_proxy->id;
846 
847  /* In some cases the instance collection of a proxy object may be local (see e.g. T83875). Not
848  * sure this is a valid state, but for now just abort the overriding process. */
849  if (!ID_IS_OVERRIDABLE_LIBRARY(id_root)) {
850  return false;
851  }
852 
853  /* We manually convert the proxy object into a library override, further override handling will
854  * then be handled by `BKE_lib_override_library_create()` just as for a regular override
855  * creation.
856  */
857  ob_proxy->proxy->id.tag |= LIB_TAG_DOIT;
858  ob_proxy->proxy->id.newid = &ob_proxy->id;
859  BKE_lib_override_library_init(&ob_proxy->id, &ob_proxy->proxy->id);
860 
861  ob_proxy->proxy->proxy_from = NULL;
862  ob_proxy->proxy = ob_proxy->proxy_group = NULL;
863 
865 
866  return BKE_lib_override_library_create(bmain, scene, view_layer, id_root, id_reference);
867 }
868 
877  Scene *scene,
878  ViewLayer *view_layer,
879  ID *id_root,
880  Collection *override_resync_residual_storage,
881  const bool do_hierarchy_enforce,
882  const bool do_post_process)
883 {
885  BLI_assert(!ID_IS_LINKED(id_root));
886 
887  ID *id_root_reference = id_root->override_library->reference;
888 
889  BKE_main_relations_create(bmain, 0);
891  .bmain = bmain, .id_root = id_root, .tag = LIB_TAG_DOIT, .missing_tag = LIB_TAG_MISSING};
893 
895  data.id_root = id_root_reference;
897 
900 
901  /* Make a mapping 'linked reference IDs' -> 'Local override IDs' of existing overrides. */
902  GHash *linkedref_to_old_override = BLI_ghash_new(
904  ID *id;
905  FOREACH_MAIN_ID_BEGIN (bmain, id) {
906  /* IDs that get fully removed from linked data remain as local overrides (using place-holder
907  * linked IDs as reference), but they are often not reachable from any current valid local
908  * override hierarchy anymore. This will ensure they get properly deleted at the end of this
909  * function. */
910  if (!ID_IS_LINKED(id) && ID_IS_OVERRIDE_LIBRARY_REAL(id) &&
912  /* Unfortunately deleting obdata means deleting their objects too. Since there is no
913  * guarantee that a valid override object using an obsolete override obdata gets properly
914  * updated, we ignore those here for now. In practice this should not be a big issue. */
916  id->tag |= LIB_TAG_MISSING;
917  }
918 
920  /* While this should not happen in typical cases (and won't be properly supported here), user
921  * is free to do all kind of very bad things, including having different local overrides of a
922  * same linked ID in a same hierarchy. */
923  if (!BLI_ghash_haskey(linkedref_to_old_override, id->override_library->reference)) {
924  BLI_ghash_insert(linkedref_to_old_override, id->override_library->reference, id);
925  if ((id->override_library->reference->tag & LIB_TAG_DOIT) == 0) {
926  /* We have an override, but now it does not seem to be necessary to override that ID
927  * anymore. Check if there are some actual overrides from the user, otherwise assume
928  * that we can get rid of this local override. */
930  if (!ELEM(op->rna_prop_type, PROP_POINTER, PROP_COLLECTION)) {
931  id->override_library->reference->tag |= LIB_TAG_DOIT;
932  break;
933  }
934 
935  bool do_break = false;
936  LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
937  if ((opop->flag & IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) == 0) {
938  id->override_library->reference->tag |= LIB_TAG_DOIT;
939  do_break = true;
940  break;
941  }
942  }
943  if (do_break) {
944  break;
945  }
946  }
947  }
948  }
949  }
950  }
952 
953  /* Code above may have added some tags, we need to update this too. */
956 
958 
959  /* Make new override from linked data. */
960  /* Note that this call also remaps all pointers of tagged IDs from old override IDs to new
961  * override IDs (including within the old overrides themselves, since those are tagged too
962  * above). */
963  const bool success = BKE_lib_override_library_create_from_tag(bmain);
964 
965  if (!success) {
966  return success;
967  }
968 
969  ListBase *lb;
970  FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
972  if (id->tag & LIB_TAG_DOIT && id->newid != NULL && ID_IS_LINKED(id)) {
973  ID *id_override_new = id->newid;
974  ID *id_override_old = BLI_ghash_lookup(linkedref_to_old_override, id);
975 
976  BLI_assert((id_override_new->tag & LIB_TAG_LIB_OVERRIDE_NEED_RESYNC) == 0);
977 
978  if (id_override_old != NULL) {
979  /* Swap the names between old override ID and new one. */
980  char id_name_buf[MAX_ID_NAME];
981  memcpy(id_name_buf, id_override_old->name, sizeof(id_name_buf));
982  memcpy(id_override_old->name, id_override_new->name, sizeof(id_override_old->name));
983  memcpy(id_override_new->name, id_name_buf, sizeof(id_override_new->name));
984  /* Note that this is a very efficient way to keep BMain IDs ordered as expected after
985  * swapping their names.
986  * However, one has to be very careful with this when iterating over the listbase at the
987  * same time. Here it works because we only execute this code when we are in the linked
988  * IDs, which are always *after* all local ones, and we only affect local IDs. */
989  BLI_listbase_swaplinks(lb, id_override_old, id_override_new);
990 
991  /* Remap the whole local IDs to use the new override. */
993  bmain, id_override_old, id_override_new, ID_REMAP_SKIP_INDIRECT_USAGE);
994 
995  /* Copy over overrides rules from old override ID to new one. */
996  BLI_duplicatelist(&id_override_new->override_library->properties,
997  &id_override_old->override_library->properties);
999  op_new = id_override_new->override_library->properties.first,
1000  *op_old = id_override_old->override_library->properties.first;
1001  op_new;
1002  op_new = op_new->next, op_old = op_old->next) {
1003  lib_override_library_property_copy(op_new, op_old);
1004  }
1005  }
1006  }
1007  }
1009  }
1011 
1012  /* We need to apply override rules in a separate loop, after all ID pointers have been properly
1013  * remapped, and all new local override IDs have gotten their proper original names, otherwise
1014  * override operations based on those ID names would fail. */
1015  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1016  if (id->tag & LIB_TAG_DOIT && id->newid != NULL && ID_IS_LINKED(id)) {
1017  ID *id_override_new = id->newid;
1018  ID *id_override_old = BLI_ghash_lookup(linkedref_to_old_override, id);
1019 
1020  if (id_override_old != NULL) {
1021  /* Apply rules on new override ID using old one as 'source' data. */
1022  /* Note that since we already remapped ID pointers in old override IDs to new ones, we
1023  * can also apply ID pointer override rules safely here. */
1024  PointerRNA rnaptr_src, rnaptr_dst;
1025  RNA_id_pointer_create(id_override_old, &rnaptr_src);
1026  RNA_id_pointer_create(id_override_new, &rnaptr_dst);
1027 
1028  /* We remove any operation tagged with `IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE`,
1029  * that way the potentially new pointer will be properly kept, when old one is still valid
1030  * too (typical case: assigning new ID to some usage, while old one remains used elsewhere
1031  * in the override hierarchy). */
1033  IDOverrideLibraryProperty *, op, &id_override_new->override_library->properties) {
1037  BLI_freelinkN(&op->operations, opop);
1038  }
1039  }
1040  if (BLI_listbase_is_empty(&op->operations)) {
1042  }
1043  }
1044 
1046  &rnaptr_dst,
1047  &rnaptr_src,
1048  NULL,
1049  id_override_new->override_library,
1050  do_hierarchy_enforce ?
1053  }
1054  }
1055  }
1057 
1058  /* Delete old override IDs.
1059  * Note that we have to use tagged group deletion here, since ID deletion also uses LIB_TAG_DOIT.
1060  * This improves performances anyway, so everything is fine. */
1061  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1062  if (id->tag & LIB_TAG_DOIT) {
1063  /* Note that this works because linked IDs are always after local ones (including overrides),
1064  * so we will only ever tag an old override ID after we have already checked it in this loop,
1065  * hence we cannot untag it later. */
1066  if (id->newid != NULL && ID_IS_LINKED(id)) {
1067  ID *id_override_old = BLI_ghash_lookup(linkedref_to_old_override, id);
1068 
1069  if (id_override_old != NULL) {
1070  id->newid->tag &= ~LIB_TAG_DOIT;
1071  id_override_old->tag |= LIB_TAG_DOIT;
1072  }
1073  }
1074  id->tag &= ~LIB_TAG_DOIT;
1075  }
1076  /* Also deal with old overrides that went missing in new linked data. */
1077  else if (id->tag & LIB_TAG_MISSING && !ID_IS_LINKED(id)) {
1080  /* If user never edited them, we can delete them. */
1081  id->tag |= LIB_TAG_DOIT;
1082  id->tag &= ~LIB_TAG_MISSING;
1083  CLOG_INFO(&LOG, 2, "Old override %s is being deleted", id->name);
1084  }
1085  else {
1086  /* Otherwise, keep them, user needs to decide whether what to do with them. */
1087  BLI_assert((id->tag & LIB_TAG_DOIT) == 0);
1088  id_fake_user_set(id);
1090  CLOG_INFO(&LOG, 2, "Old override %s is being kept around as it was user-edited", id->name);
1091  }
1092  }
1093  }
1096 
1097  /* At this point, `id_root` has very likely been deleted, we need to update it to its new
1098  * version.
1099  */
1100  id_root = id_root_reference->newid;
1101 
1102  if (do_post_process) {
1103  /* Essentially ensures that potentially new overrides of new objects will be instantiated. */
1104  /* Note: Here 'reference' collection and 'newly added' collection are the same, which is fine
1105  * since we already relinked old root override collection to new resync'ed one above. So this
1106  * call is not expected to instantiate this new resync'ed collection anywhere, just to ensure
1107  * that we do not have any stray objects. */
1109  scene,
1110  view_layer,
1111  id_root_reference,
1112  id_root,
1113  override_resync_residual_storage,
1114  true);
1115  }
1116 
1117  /* Cleanup. */
1118  BLI_ghash_free(linkedref_to_old_override, NULL, NULL);
1119 
1121  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); /* That one should not be needed in fact. */
1122 
1123  return success;
1124 }
1125 
1141 {
1142  /* We use a specific collection to gather/store all 'orphaned' override collections and objects
1143  * generated by re-sync-process. This avoids putting them in scene's master collection. */
1144 #define OVERRIDE_RESYNC_RESIDUAL_STORAGE_NAME "OVERRIDE_RESYNC_LEFTOVERS"
1145  Collection *override_resync_residual_storage = BLI_findstring(
1146  &bmain->collections, OVERRIDE_RESYNC_RESIDUAL_STORAGE_NAME, offsetof(ID, name) + 2);
1147  if (override_resync_residual_storage != NULL &&
1148  override_resync_residual_storage->id.lib != NULL) {
1149  override_resync_residual_storage = NULL;
1150  }
1151  if (override_resync_residual_storage == NULL) {
1152  override_resync_residual_storage = BKE_collection_add(
1154  /* Hide the collection from viewport and render. */
1155  override_resync_residual_storage->flag |= COLLECTION_RESTRICT_VIEWPORT |
1157  }
1158 
1159  BKE_main_relations_create(bmain, 0);
1160  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
1161 
1162  /* NOTE: in code below, the order in which `FOREACH_MAIN_ID_BEGIN` processes ID types ensures
1163  * that we always process 'higher-level' overrides first (i.e. scenes, then collections, then
1164  * objects, then other types). */
1165 
1166  /* Detect all linked data that would need to be overridden if we had to create an override from
1167  * those used by current existing overrides. */
1168  ID *id;
1169  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1170  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id) || ID_IS_LINKED(id)) {
1171  continue;
1172  }
1173  if (id->tag & (LIB_TAG_DOIT | LIB_TAG_MISSING)) {
1174  /* We already processed that ID as part of another ID's hierarchy. */
1175  continue;
1176  }
1177 
1178  LibOverrideGroupTagData data = {.bmain = bmain,
1179  .id_root = id->override_library->reference,
1180  .tag = LIB_TAG_DOIT,
1181  .missing_tag = LIB_TAG_MISSING};
1186  }
1188 
1189  /* Now check existing overrides, those needing resync will be the one either already tagged as
1190  * such, or the one using linked data that is now tagged as needing override. */
1191  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1192  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id) || ID_IS_LINKED(id)) {
1193  continue;
1194  }
1195 
1197  CLOG_INFO(&LOG, 4, "ID %s was already tagged as needing resync", id->name);
1198  continue;
1199  }
1200 
1202  BLI_assert(entry != NULL);
1203 
1204  for (MainIDRelationsEntryItem *entry_item = entry->to_ids; entry_item != NULL;
1205  entry_item = entry_item->next) {
1206  if (entry_item->usage_flag & IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE) {
1207  continue;
1208  }
1209  ID *id_to = *entry_item->id_pointer.to;
1210 
1211  /* Case where this ID pointer was to a linked ID, that now needs to be overridden. */
1212  if (ID_IS_LINKED(id_to) && (id_to->tag & LIB_TAG_DOIT) != 0) {
1214  CLOG_INFO(&LOG,
1215  3,
1216  "ID %s now tagged as needing resync because they use linked %s that now needs "
1217  "to be overridden",
1218  id->name,
1219  id_to->name);
1220  break;
1221  }
1222  }
1223  }
1225 
1226  BKE_main_relations_free(bmain);
1227  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
1228 
1229  /* And do the actual resync for all IDs detected as needing it.
1230  * NOTE: Since this changes `bmain` (adding **and** removing IDs), we cannot use
1231  * `FOREACH_MAIN_ID_BEGIN/END` here, and need special multi-loop processing. */
1232  bool do_continue = true;
1233  while (do_continue) {
1234  ListBase *lb;
1235  do_continue = false;
1236  FOREACH_MAIN_LISTBASE_BEGIN (bmain, lb) {
1238  if ((id->tag & LIB_TAG_LIB_OVERRIDE_NEED_RESYNC) == 0) {
1239  continue;
1240  }
1242  if (ID_IS_LINKED(id)) {
1243  continue;
1244  }
1245  do_continue = true;
1246 
1247  /* In complex non-supported cases, with several different override hierarchies sharing
1248  * relations between each-other, we may end up not actually updating/replacing the given
1249  * root id (see e.g. pro/shots/110_rextoria/110_0150_A/110_0150_A.anim.blend of sprites
1250  * project repository, r2687).
1251  * This can lead to infinite loop here, at least avoid this. */
1253 
1254  CLOG_INFO(&LOG, 2, "Resyncing %s...", id->name);
1255  const bool success = BKE_lib_override_library_resync(
1256  bmain, scene, view_layer, id, override_resync_residual_storage, false, false);
1257  CLOG_INFO(&LOG, 2, "\tSuccess: %d", success);
1258  break;
1259  }
1261  if (do_continue) {
1262  break;
1263  }
1264  }
1266  }
1267 
1268  /* Essentially ensures that potentially new overrides of new objects will be instantiated. */
1270  bmain, scene, view_layer, NULL, NULL, override_resync_residual_storage, true);
1271 
1272  if (BKE_collection_is_empty(override_resync_residual_storage)) {
1273  BKE_collection_delete(bmain, override_resync_residual_storage, true);
1274  }
1275 }
1276 
1286 {
1288 
1289  /* Tag all library overrides in the chains of dependencies from the given root one. */
1290  BKE_main_relations_create(bmain, 0);
1292  .bmain = bmain, .id_root = id_root, .tag = LIB_TAG_DOIT, .missing_tag = LIB_TAG_MISSING};
1294 
1295  BKE_main_relations_free(bmain);
1296 
1297  ID *id;
1298  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1299  if (id->tag & LIB_TAG_DOIT) {
1300  if (ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
1301  ID *id_override_reference = id->override_library->reference;
1302 
1303  /* Remap the whole local IDs to use the linked data. */
1304  BKE_libblock_remap(bmain, id, id_override_reference, ID_REMAP_SKIP_INDIRECT_USAGE);
1305  }
1306  }
1307  }
1309 
1310  /* Delete the override IDs. */
1312 
1313  /* Should not actually be needed here. */
1314  BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
1315 }
1316 
1323 {
1324  if (!ID_IS_OVERRIDE_LIBRARY(id)) {
1325  return;
1326  }
1328  /* We should never directly 'make local' virtual overrides (aka shape keys). */
1330  id->flag &= ~LIB_EMBEDDED_DATA_LIB_OVERRIDE;
1331  return;
1332  }
1333 
1335 
1336  Key *shape_key = BKE_key_from_id(id);
1337  if (shape_key != NULL) {
1338  shape_key->id.flag &= ~LIB_EMBEDDED_DATA_LIB_OVERRIDE;
1339  }
1340 
1341  if (GS(id->name) == ID_SCE) {
1342  Collection *master_collection = ((Scene *)id)->master_collection;
1343  if (master_collection != NULL) {
1344  master_collection->id.flag &= ~LIB_EMBEDDED_DATA_LIB_OVERRIDE;
1345  }
1346  }
1347 
1349  if (node_tree != NULL) {
1351  }
1352 }
1353 
1355  IDOverrideLibrary *override)
1356 {
1357  if (override->runtime == NULL) {
1358  override->runtime = MEM_callocN(sizeof(*override->runtime), __func__);
1359  }
1360  return override->runtime;
1361 }
1362 
1363 /* We only build override GHash on request. */
1365 {
1367  if (override_runtime->rna_path_to_override_properties == NULL) {
1368  override_runtime->rna_path_to_override_properties = BLI_ghash_new(
1370  for (IDOverrideLibraryProperty *op = override->properties.first; op != NULL; op = op->next) {
1371  BLI_ghash_insert(override_runtime->rna_path_to_override_properties, op->rna_path, op);
1372  }
1373  }
1374 
1375  return override_runtime->rna_path_to_override_properties;
1376 }
1377 
1382  const char *rna_path)
1383 {
1384  GHash *override_runtime = override_library_rna_path_mapping_ensure(override);
1385  return BLI_ghash_lookup(override_runtime, rna_path);
1386 }
1387 
1392  const char *rna_path,
1393  bool *r_created)
1394 {
1396 
1397  if (op == NULL) {
1398  op = MEM_callocN(sizeof(IDOverrideLibraryProperty), __func__);
1399  op->rna_path = BLI_strdup(rna_path);
1400  BLI_addtail(&override->properties, op);
1401 
1402  GHash *override_runtime = override_library_rna_path_mapping_ensure(override);
1403  BLI_ghash_insert(override_runtime, op->rna_path, op);
1404 
1405  if (r_created) {
1406  *r_created = true;
1407  }
1408  }
1409  else if (r_created) {
1410  *r_created = false;
1411  }
1412 
1413  return op;
1414 }
1415 
1424  const IDOverrideLibraryProperty *library_prop,
1425  PointerRNA *r_override_poin,
1426  PropertyRNA **r_override_prop)
1427 {
1430  idpoin, library_prop->rna_path, r_override_poin, r_override_prop);
1431 }
1432 
1434  IDOverrideLibraryProperty *op_src)
1435 {
1436  op_dst->rna_path = BLI_strdup(op_src->rna_path);
1437  BLI_duplicatelist(&op_dst->operations, &op_src->operations);
1438 
1439  for (IDOverrideLibraryPropertyOperation *opop_dst = op_dst->operations.first,
1440  *opop_src = op_src->operations.first;
1441  opop_dst;
1442  opop_dst = opop_dst->next, opop_src = opop_src->next) {
1444  }
1445 }
1446 
1448 {
1449  BLI_assert(op->rna_path != NULL);
1450 
1451  MEM_freeN(op->rna_path);
1452 
1455  }
1456  BLI_freelistN(&op->operations);
1457 }
1458 
1463  IDOverrideLibraryProperty *override_property)
1464 {
1465  if (!ELEM(NULL, override->runtime, override->runtime->rna_path_to_override_properties)) {
1466  BLI_ghash_remove(override->runtime->rna_path_to_override_properties,
1467  override_property->rna_path,
1468  NULL,
1469  NULL);
1470  }
1471  lib_override_library_property_clear(override_property);
1472  BLI_freelinkN(&override->properties, override_property);
1473 }
1474 
1479  IDOverrideLibraryProperty *override_property,
1480  const char *subitem_refname,
1481  const char *subitem_locname,
1482  const int subitem_refindex,
1483  const int subitem_locindex,
1484  const bool strict,
1485  bool *r_strict)
1486 {
1488  const int subitem_defindex = -1;
1489 
1490  if (r_strict) {
1491  *r_strict = true;
1492  }
1493 
1494  if (subitem_locname != NULL) {
1495  opop = BLI_findstring_ptr(&override_property->operations,
1496  subitem_locname,
1497  offsetof(IDOverrideLibraryPropertyOperation, subitem_local_name));
1498 
1499  if (opop == NULL) {
1500  return NULL;
1501  }
1502 
1503  if (subitem_refname == NULL || opop->subitem_reference_name == NULL) {
1504  return subitem_refname == opop->subitem_reference_name ? opop : NULL;
1505  }
1506  return (subitem_refname != NULL && opop->subitem_reference_name != NULL &&
1507  STREQ(subitem_refname, opop->subitem_reference_name)) ?
1508  opop :
1509  NULL;
1510  }
1511 
1512  if (subitem_refname != NULL) {
1513  opop = BLI_findstring_ptr(
1514  &override_property->operations,
1515  subitem_refname,
1516  offsetof(IDOverrideLibraryPropertyOperation, subitem_reference_name));
1517 
1518  if (opop == NULL) {
1519  return NULL;
1520  }
1521 
1522  if (subitem_locname == NULL || opop->subitem_local_name == NULL) {
1523  return subitem_locname == opop->subitem_local_name ? opop : NULL;
1524  }
1525  return (subitem_locname != NULL && opop->subitem_local_name != NULL &&
1526  STREQ(subitem_locname, opop->subitem_local_name)) ?
1527  opop :
1528  NULL;
1529  }
1530 
1531  if ((opop = BLI_listbase_bytes_find(
1532  &override_property->operations,
1533  &subitem_locindex,
1534  sizeof(subitem_locindex),
1535  offsetof(IDOverrideLibraryPropertyOperation, subitem_local_index)))) {
1536  return ELEM(subitem_refindex, -1, opop->subitem_reference_index) ? opop : NULL;
1537  }
1538 
1539  if ((opop = BLI_listbase_bytes_find(
1540  &override_property->operations,
1541  &subitem_refindex,
1542  sizeof(subitem_refindex),
1543  offsetof(IDOverrideLibraryPropertyOperation, subitem_reference_index)))) {
1544  return ELEM(subitem_locindex, -1, opop->subitem_local_index) ? opop : NULL;
1545  }
1546 
1547  /* `index == -1` means all indices, that is a valid fallback in case we requested specific index.
1548  */
1549  if (!strict && (subitem_locindex != subitem_defindex) &&
1550  (opop = BLI_listbase_bytes_find(
1551  &override_property->operations,
1552  &subitem_defindex,
1553  sizeof(subitem_defindex),
1554  offsetof(IDOverrideLibraryPropertyOperation, subitem_local_index)))) {
1555  if (r_strict) {
1556  *r_strict = false;
1557  }
1558  return opop;
1559  }
1560 
1561  return NULL;
1562 }
1563 
1568  IDOverrideLibraryProperty *override_property,
1569  const short operation,
1570  const char *subitem_refname,
1571  const char *subitem_locname,
1572  const int subitem_refindex,
1573  const int subitem_locindex,
1574  const bool strict,
1575  bool *r_strict,
1576  bool *r_created)
1577 {
1579  override_property,
1580  subitem_refname,
1581  subitem_locname,
1582  subitem_refindex,
1583  subitem_locindex,
1584  strict,
1585  r_strict);
1586 
1587  if (opop == NULL) {
1588  opop = MEM_callocN(sizeof(IDOverrideLibraryPropertyOperation), __func__);
1589  opop->operation = operation;
1590  if (subitem_locname) {
1591  opop->subitem_local_name = BLI_strdup(subitem_locname);
1592  }
1593  if (subitem_refname) {
1594  opop->subitem_reference_name = BLI_strdup(subitem_refname);
1595  }
1596  opop->subitem_local_index = subitem_locindex;
1597  opop->subitem_reference_index = subitem_refindex;
1598 
1599  BLI_addtail(&override_property->operations, opop);
1600 
1601  if (r_created) {
1602  *r_created = true;
1603  }
1604  }
1605  else if (r_created) {
1606  *r_created = false;
1607  }
1608 
1609  return opop;
1610 }
1611 
1614 {
1615  if (opop_src->subitem_reference_name) {
1617  }
1618  if (opop_src->subitem_local_name) {
1619  opop_dst->subitem_local_name = BLI_strdup(opop_src->subitem_local_name);
1620  }
1621 }
1622 
1624 {
1625  if (opop->subitem_reference_name) {
1627  }
1628  if (opop->subitem_local_name) {
1630  }
1631 }
1632 
1637  IDOverrideLibraryProperty *override_property,
1638  IDOverrideLibraryPropertyOperation *override_property_operation)
1639 {
1640  lib_override_library_property_operation_clear(override_property_operation);
1641  BLI_freelinkN(&override_property->operations, override_property_operation);
1642 }
1643 
1648  struct IDOverrideLibraryPropertyOperation *override_property_operation,
1649  struct PointerRNA *ptr_dst,
1650  struct PointerRNA *ptr_src,
1651  struct PointerRNA *ptr_storage,
1652  struct PropertyRNA *prop_dst,
1653  struct PropertyRNA *prop_src,
1654  struct PropertyRNA *prop_storage)
1655 {
1656  switch (override_property_operation->operation) {
1658  return true;
1664  if (ptr_storage == NULL || ptr_storage->data == NULL || prop_storage == NULL) {
1665  BLI_assert(!"Missing data to apply differential override operation.");
1666  return false;
1667  }
1674  if ((ptr_dst == NULL || ptr_dst->data == NULL || prop_dst == NULL) ||
1675  (ptr_src == NULL || ptr_src->data == NULL || prop_src == NULL)) {
1676  BLI_assert(!"Missing data to apply override operation.");
1677  return false;
1678  }
1679  }
1680 
1681  return true;
1682 }
1683 
1686 {
1687  if (id->override_library == NULL) {
1688  return;
1689  }
1690  if (id->override_library->reference == NULL) {
1691  /* This is a template ID, could be linked or local, not an override. */
1692  return;
1693  }
1694  if (id->override_library->reference == id) {
1695  /* Very serious data corruption, cannot do much about it besides removing the reference
1696  * (therefore making the id a local override template one only). */
1697  BKE_reportf(reports,
1698  RPT_ERROR,
1699  "Data corruption: data-block '%s' is using itself as library override reference",
1700  id->name);
1701  id->override_library->reference = NULL;
1702  return;
1703  }
1704  if (id->override_library->reference->lib == NULL) {
1705  /* Very serious data corruption, cannot do much about it besides removing the reference
1706  * (therefore making the id a local override template one only). */
1707  BKE_reportf(reports,
1708  RPT_ERROR,
1709  "Data corruption: data-block '%s' is using another local data-block ('%s') as "
1710  "library override reference",
1711  id->name,
1713  id->override_library->reference = NULL;
1714  return;
1715  }
1716 }
1717 
1720 {
1721  ID *id;
1722 
1723  FOREACH_MAIN_ID_BEGIN (bmain, id) {
1724  if (id->override_library != NULL) {
1725  BKE_lib_override_library_validate(bmain, id, reports);
1726  }
1727  }
1729 }
1730 
1742 {
1744 
1745  ID *reference = local->override_library->reference;
1746 
1747  if (reference == NULL) {
1748  /* This is an override template, local status is always OK! */
1749  return true;
1750  }
1751 
1752  BLI_assert(GS(local->name) == GS(reference->name));
1753 
1754  if (GS(local->name) == ID_OB) {
1755  /* Our beloved pose's bone cross-data pointers. Usually, depsgraph evaluation would
1756  * ensure this is valid, but in some situations (like hidden collections etc.) this won't
1757  * be the case, so we need to take care of this ourselves. */
1758  Object *ob_local = (Object *)local;
1759  if (ob_local->type == OB_ARMATURE) {
1760  Object *ob_reference = (Object *)local->override_library->reference;
1761  BLI_assert(ob_local->data != NULL);
1762  BLI_assert(ob_reference->data != NULL);
1763  BKE_pose_ensure(bmain, ob_local, ob_local->data, true);
1764  BKE_pose_ensure(bmain, ob_reference, ob_reference->data, true);
1765  }
1766  }
1767 
1768  /* Note that reference is assumed always valid, caller has to ensure that itself. */
1769 
1770  PointerRNA rnaptr_local, rnaptr_reference;
1771  RNA_id_pointer_create(local, &rnaptr_local);
1772  RNA_id_pointer_create(reference, &rnaptr_reference);
1773 
1774  if (!RNA_struct_override_matches(bmain,
1775  &rnaptr_local,
1776  &rnaptr_reference,
1777  NULL,
1778  0,
1779  local->override_library,
1782  NULL)) {
1784  return false;
1785  }
1786 
1787  return true;
1788 }
1789 
1801 {
1803 
1804  ID *reference = local->override_library->reference;
1805 
1806  if (reference == NULL) {
1807  /* This is an override template, reference is virtual, so its status is always OK! */
1808  return true;
1809  }
1810 
1811  BLI_assert(GS(local->name) == GS(reference->name));
1812 
1813  if (reference->override_library && (reference->tag & LIB_TAG_OVERRIDE_LIBRARY_REFOK) == 0) {
1814  if (!BKE_lib_override_library_status_check_reference(bmain, reference)) {
1815  /* If reference is also an override of another data-block, and its status is not OK,
1816  * then this override is not OK either.
1817  * Note that this should only happen when reloading libraries. */
1819  return false;
1820  }
1821  }
1822 
1823  if (GS(local->name) == ID_OB) {
1824  /* Our beloved pose's bone cross-data pointers. Usually, depsgraph evaluation would
1825  * ensure this is valid, but in some situations (like hidden collections etc.) this won't
1826  * be the case, so we need to take care of this ourselves. */
1827  Object *ob_local = (Object *)local;
1828  if (ob_local->type == OB_ARMATURE) {
1829  Object *ob_reference = (Object *)local->override_library->reference;
1830  BLI_assert(ob_local->data != NULL);
1831  BLI_assert(ob_reference->data != NULL);
1832  BKE_pose_ensure(bmain, ob_local, ob_local->data, true);
1833  BKE_pose_ensure(bmain, ob_reference, ob_reference->data, true);
1834  }
1835  }
1836 
1837  PointerRNA rnaptr_local, rnaptr_reference;
1838  RNA_id_pointer_create(local, &rnaptr_local);
1839  RNA_id_pointer_create(reference, &rnaptr_reference);
1840 
1841  if (!RNA_struct_override_matches(bmain,
1842  &rnaptr_local,
1843  &rnaptr_reference,
1844  NULL,
1845  0,
1846  local->override_library,
1848  NULL)) {
1850  return false;
1851  }
1852 
1853  return true;
1854 }
1855 
1871 {
1872  BLI_assert(local->override_library != NULL);
1873  const bool is_template = (local->override_library->reference == NULL);
1874  bool created = false;
1875 
1876  if (!is_template) {
1877  /* Do not attempt to generate overriding rules from an empty place-holder generated by link
1878  * code when it cannot find the actual library/ID. Much better to keep the local data-block as
1879  * is in the file in that case, until broken lib is fixed. */
1880  if (ID_MISSING(local->override_library->reference)) {
1881  return created;
1882  }
1883 
1884  if (GS(local->name) == ID_OB) {
1885  /* Our beloved pose's bone cross-data pointers. Usually, depsgraph evaluation would
1886  * ensure this is valid, but in some situations (like hidden collections etc.) this won't
1887  * be the case, so we need to take care of this ourselves. */
1888  Object *ob_local = (Object *)local;
1889  if (ob_local->type == OB_ARMATURE) {
1890  Object *ob_reference = (Object *)local->override_library->reference;
1891  BLI_assert(ob_local->data != NULL);
1892  BLI_assert(ob_reference->data != NULL);
1893  BKE_pose_ensure(bmain, ob_local, ob_local->data, true);
1894  BKE_pose_ensure(bmain, ob_reference, ob_reference->data, true);
1895  }
1896  }
1897 
1898  PointerRNA rnaptr_local, rnaptr_reference;
1899  RNA_id_pointer_create(local, &rnaptr_local);
1900  RNA_id_pointer_create(local->override_library->reference, &rnaptr_reference);
1901 
1902  eRNAOverrideMatchResult report_flags = 0;
1904  &rnaptr_local,
1905  &rnaptr_reference,
1906  NULL,
1907  0,
1908  local->override_library,
1910  &report_flags);
1911 
1912  if (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) {
1913  created = true;
1914  }
1915 
1916  if (report_flags & RNA_OVERRIDE_MATCH_RESULT_RESTORED) {
1917  CLOG_INFO(&LOG, 2, "We did restore some properties of %s from its reference", local->name);
1918  }
1919  if (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) {
1920  CLOG_INFO(&LOG, 2, "We did generate library override rules for %s", local->name);
1921  }
1922  else {
1923  CLOG_INFO(&LOG, 2, "No new library override rules for %s", local->name);
1924  }
1925  }
1926  return created;
1927 }
1928 
1931  bool changed;
1932 };
1933 
1934 static void lib_override_library_operations_create_cb(TaskPool *__restrict pool, void *taskdata)
1935 {
1936  struct LibOverrideOpCreateData *create_data = BLI_task_pool_user_data(pool);
1937  ID *id = taskdata;
1938 
1939  if (BKE_lib_override_library_operations_create(create_data->bmain, id)) {
1940  /* Technically no need for atomic, all jobs write the same value and we only care if one did
1941  * it. But play safe and avoid implicit assumptions. */
1942  atomic_fetch_and_or_uint8((uint8_t *)&create_data->changed, true);
1943  }
1944 }
1945 
1948 {
1949  ID *id;
1950 
1951 #ifdef DEBUG_OVERRIDE_TIMEIT
1953 #endif
1954 
1955  /* When force-auto is set, we also remove all unused existing override properties & operations.
1956  */
1957  if (force_auto) {
1959  }
1960 
1961  /* Usual pose bones issue, need to be done outside of the threaded process or we may run into
1962  * concurrency issues here.
1963  * Note that calling #BKE_pose_ensure again in thread in
1964  * #BKE_lib_override_library_operations_create is not a problem then. */
1965  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
1966  if (ob->type == OB_ARMATURE) {
1967  BLI_assert(ob->data != NULL);
1968  BKE_pose_ensure(bmain, ob, ob->data, true);
1969  }
1970  }
1971 
1972  struct LibOverrideOpCreateData create_pool_data = {.bmain = bmain, .changed = false};
1974 
1976  if (ID_IS_OVERRIDE_LIBRARY_REAL(id) &&
1977  (force_auto || (id->tag & LIB_TAG_OVERRIDE_LIBRARY_AUTOREFRESH))) {
1978  /* Usual issue with pose, it's quiet rare but sometimes they may not be up to date when this
1979  * function is called. */
1980  if (GS(id->name) == ID_OB) {
1981  Object *ob = (Object *)id;
1982  if (ob->type == OB_ARMATURE) {
1983  BLI_assert(ob->data != NULL);
1984  BKE_pose_ensure(bmain, ob, ob->data, true);
1985  }
1986  }
1987  /* Only check overrides if we do have the real reference data available, and not some empty
1988  * 'placeholder' for missing data (broken links). */
1989  if ((id->override_library->reference->tag & LIB_TAG_MISSING) == 0) {
1991  }
1992  else {
1995  }
1996  }
1998  }
2000 
2002 
2004 
2005  if (force_auto) {
2007  }
2008 
2009 #ifdef DEBUG_OVERRIDE_TIMEIT
2011 #endif
2012 
2013  return create_pool_data.changed;
2014 }
2015 
2017 {
2018  bool was_op_deleted = false;
2019 
2022  bool do_op_delete = true;
2023  const bool is_collection = op->rna_prop_type == PROP_COLLECTION;
2024  if (is_collection || op->rna_prop_type == PROP_POINTER) {
2025  PointerRNA ptr_root, ptr_root_lib, ptr, ptr_lib;
2026  PropertyRNA *prop, *prop_lib;
2027 
2028  RNA_pointer_create(id_root, &RNA_ID, id_root, &ptr_root);
2030  &RNA_ID,
2031  id_root->override_library->reference,
2032  &ptr_root_lib);
2033 
2034  bool prop_exists = RNA_path_resolve_property(&ptr_root, op->rna_path, &ptr, &prop);
2035  if (prop_exists) {
2036  prop_exists = RNA_path_resolve_property(&ptr_root_lib, op->rna_path, &ptr_lib, &prop_lib);
2037 
2038  if (prop_exists) {
2040  BLI_assert(RNA_property_type(prop) == RNA_property_type(prop_lib));
2041  if (is_collection) {
2043  ptr_lib.type = RNA_property_pointer_type(&ptr_lib, prop_lib);
2044  }
2045  else {
2046  ptr = RNA_property_pointer_get(&ptr, prop);
2047  ptr_lib = RNA_property_pointer_get(&ptr_lib, prop_lib);
2048  }
2049  if (ptr.owner_id != NULL && ptr_lib.owner_id != NULL) {
2050  BLI_assert(ptr.type == ptr_lib.type);
2051  do_op_delete = !(RNA_struct_is_ID(ptr.type) &&
2054  }
2055  }
2056  }
2057  }
2058 
2059  if (do_op_delete) {
2061  was_op_deleted = true;
2062  }
2063  }
2064 
2065  if (was_op_deleted) {
2068  id_root->override_library);
2069  override_runtime->tag |= IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RELOAD;
2070  }
2071 
2072  return was_op_deleted;
2073 }
2074 
2077 {
2078  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root)) {
2079  return;
2080  }
2081 
2082  if (lib_override_library_id_reset_do(bmain, id_root)) {
2083  if (id_root->override_library->runtime != NULL &&
2085  0) {
2088  }
2089  }
2090 }
2091 
2093 {
2094  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id_root)) {
2095  return;
2096  }
2097 
2098  void **entry_vp = BLI_ghash_lookup_p(bmain->relations->relations_from_pointers, id_root);
2099  if (entry_vp == NULL) {
2100  /* This ID is not used by nor using any other ID. */
2102  return;
2103  }
2104 
2105  MainIDRelationsEntry *entry = *entry_vp;
2107  /* This ID has already been processed. */
2108  return;
2109  }
2110 
2112 
2113  /* This way we won't process again that ID, should we encounter it again through another
2114  * relationship hierarchy. */
2116 
2117  for (MainIDRelationsEntryItem *to_id_entry = entry->to_ids; to_id_entry != NULL;
2118  to_id_entry = to_id_entry->next) {
2119  if ((to_id_entry->usage_flag & IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE) != 0) {
2120  /* Never consider non-overridable relationships ('from', 'parents', 'owner' etc. pointers) as
2121  * actual dependencies. */
2122  continue;
2123  }
2124  /* We only consider IDs from the same library. */
2125  if (*to_id_entry->id_pointer.to != NULL) {
2126  ID *to_id = *to_id_entry->id_pointer.to;
2127  if (to_id->override_library != NULL) {
2129  }
2130  }
2131  }
2132 }
2133 
2136 {
2138 
2140 
2142 
2143  ID *id;
2147  continue;
2148  }
2150  id->override_library->runtime->tag &= ~IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RELOAD;
2151  }
2153 }
2154 
2157  const short tag,
2158  const bool do_set)
2159 {
2160  if (override_property != NULL) {
2161  if (do_set) {
2162  override_property->tag |= tag;
2163  }
2164  else {
2165  override_property->tag &= ~tag;
2166  }
2167 
2168  LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &override_property->operations) {
2169  if (do_set) {
2170  opop->tag |= tag;
2171  }
2172  else {
2173  opop->tag &= ~tag;
2174  }
2175  }
2176  }
2177 }
2178 
2181  const short tag,
2182  const bool do_set)
2183 {
2184  if (override != NULL) {
2185  LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &override->properties) {
2186  BKE_lib_override_library_operations_tag(op, tag, do_set);
2187  }
2188  }
2189 }
2190 
2192 void BKE_lib_override_library_main_tag(struct Main *bmain, const short tag, const bool do_set)
2193 {
2194  ID *id;
2195 
2197  if (ID_IS_OVERRIDE_LIBRARY(id)) {
2199  }
2200  }
2202 }
2203 
2206 {
2207  if (ID_IS_OVERRIDE_LIBRARY_REAL(local)) {
2210  if (op->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) {
2212  }
2213  else {
2215  if (opop->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) {
2217  }
2218  }
2219  }
2220  }
2221  }
2222 }
2223 
2226 {
2227  ID *id;
2228 
2230  if (ID_IS_OVERRIDE_LIBRARY(id)) {
2232  }
2233  }
2235 }
2236 
2237 static void lib_override_id_swap(Main *bmain, ID *id_local, ID *id_temp)
2238 {
2239  BKE_lib_id_swap(bmain, id_local, id_temp);
2240  /* We need to keep these tags from temp ID into orig one.
2241  * ID swap does not swap most of ID data itself. */
2242  id_local->tag |= (id_temp->tag & LIB_TAG_LIB_OVERRIDE_NEED_RESYNC);
2243 }
2244 
2247 {
2248  if (!ID_IS_OVERRIDE_LIBRARY_REAL(local)) {
2249  return;
2250  }
2251 
2252  /* Do not attempt to apply overriding rules over an empty place-holder generated by link code
2253  * when it cannot find the actual library/ID. Much better to keep the local data-block as loaded
2254  * from the file in that case, until broken lib is fixed. */
2255  if (ID_MISSING(local->override_library->reference)) {
2256  return;
2257  }
2258 
2259  /* Recursively do 'ancestor' overrides first, if any. */
2263  }
2264 
2265  /* We want to avoid having to remap here, however creating up-to-date override is much simpler
2266  * if based on reference than on current override.
2267  * So we work on temp copy of reference, and 'swap' its content with local. */
2268 
2269  /* XXX We need a way to get off-Main copies of IDs (similar to localized mats/texts/ etc.)!
2270  * However, this is whole bunch of code work in itself, so for now plain stupid ID copy
2271  * will do, as inefficient as it is. :/
2272  * Actually, maybe not! Since we are swapping with original ID's local content, we want to
2273  * keep user-count in correct state when freeing tmp_id
2274  * (and that user-counts of IDs used by 'new' local data also remain correct). */
2275  /* This would imply change in handling of user-count all over RNA
2276  * (and possibly all over Blender code).
2277  * Not impossible to do, but would rather see first if extra useless usual user handling
2278  * is actually a (performances) issue here. */
2279 
2280  ID *tmp_id = BKE_id_copy(bmain, local->override_library->reference);
2281 
2282  if (tmp_id == NULL) {
2283  return;
2284  }
2285 
2286  /* This ID name is problematic, since it is an 'rna name property' it should not be editable or
2287  * different from reference linked ID. But local ID names need to be unique in a given type
2288  * list of Main, so we cannot always keep it identical, which is why we need this special
2289  * manual handling here. */
2290  BLI_strncpy(tmp_id->name, local->name, sizeof(tmp_id->name));
2291 
2292  /* Those ugly loop-back pointers again. Luckily we only need to deal with the shape keys here,
2293  * collections' parents are fully runtime and reconstructed later. */
2294  Key *local_key = BKE_key_from_id(local);
2295  Key *tmp_key = BKE_key_from_id(tmp_id);
2296  if (local_key != NULL && tmp_key != NULL) {
2297  tmp_key->id.flag |= (local_key->id.flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE);
2298  }
2299 
2300  PointerRNA rnaptr_src, rnaptr_dst, rnaptr_storage_stack, *rnaptr_storage = NULL;
2301  RNA_id_pointer_create(local, &rnaptr_src);
2302  RNA_id_pointer_create(tmp_id, &rnaptr_dst);
2303  if (local->override_library->storage) {
2304  rnaptr_storage = &rnaptr_storage_stack;
2305  RNA_id_pointer_create(local->override_library->storage, rnaptr_storage);
2306  }
2307 
2309  &rnaptr_dst,
2310  &rnaptr_src,
2311  rnaptr_storage,
2312  local->override_library,
2314 
2315  /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa.
2316  * So when we'll free tmp_id, we'll actually free old, outdated data from local. */
2317  lib_override_id_swap(bmain, local, tmp_id);
2318 
2319  if (local_key != NULL && tmp_key != NULL) {
2320  /* This is some kind of hard-coded 'always enforced override'. */
2321  lib_override_id_swap(bmain, &local_key->id, &tmp_key->id);
2322  tmp_key->id.flag |= (local_key->id.flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE);
2323  /* The swap of local and tmp_id inverted those pointers, we need to redefine proper
2324  * relationships. */
2325  *BKE_key_from_id_p(local) = local_key;
2326  *BKE_key_from_id_p(tmp_id) = tmp_key;
2327  local_key->from = local;
2328  tmp_key->from = tmp_id;
2329  }
2330 
2331  /* Again, horribly inefficient in our case, we need something off-Main
2332  * (aka more generic nolib copy/free stuff)! */
2334 
2335  if (GS(local->name) == ID_AR) {
2336  /* Fun times again, thanks to bone pointers in pose data of objects. We keep same ID addresses,
2337  * but internal data has changed for sure, so we need to invalidate pose-bones caches. */
2338  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
2339  if (ob->pose != NULL && ob->data == local) {
2340  BLI_assert(ob->type == OB_ARMATURE);
2341  ob->pose->flag |= POSE_RECALC;
2342  /* We need to clear pose bone pointers immediately, some code may access those before pose
2343  * is actually recomputed, which can lead to segfault. */
2344  BKE_pose_clear_pointers(ob->pose);
2345  }
2346  }
2347  }
2348 
2349  if (local->override_library->storage) {
2350  /* We know this data-block is not used anywhere besides local->override->storage. */
2351  /* XXX For until we get fully shadow copies, we still need to ensure storage releases
2352  * its usage of any ID pointers it may have. */
2354  local->override_library->storage = NULL;
2355  }
2356 
2358 
2359  /* Note: Since we reload full content from linked ID here, potentially from edited local
2360  * override, we do not really have a way to know *what* is changed, so we need to rely on the
2361  * massive destruction weapon of `ID_RECALC_ALL` here. */
2363  /* For same reason as above, also assume that the relationships between IDs changed. */
2365 }
2366 
2369 {
2370  ID *id;
2371 
2372  /* This temporary swap of G_MAIN is rather ugly,
2373  * but necessary to avoid asserts checks in some RNA assignment functions,
2374  * since those always use on G_MAIN when they need access to a Main database. */
2375  Main *orig_gmain = G_MAIN;
2376  G_MAIN = bmain;
2377 
2379  if (id->override_library != NULL) {
2381  }
2382  }
2384 
2385  G_MAIN = orig_gmain;
2386 }
2387 
2406 {
2407  return BKE_main_new();
2408 }
2409 
2416  OverrideLibraryStorage *override_storage,
2417  ID *local)
2418 {
2420  /* This is actually purely local data with an override template, or one of those embedded IDs
2421  * (root node trees, master collections or shapekeys) that cannot have their own override.
2422  * Nothing to do here! */
2423  return NULL;
2424  }
2425 
2427  BLI_assert(override_storage != NULL);
2428  UNUSED_VARS_NDEBUG(override_storage);
2429 
2430  /* Forcefully ensure we know about all needed override operations. */
2432 
2433  ID *storage_id;
2434 #ifdef DEBUG_OVERRIDE_TIMEIT
2436 #endif
2437 
2438  /* This is fully disabled for now, as it generated very hard to solve issues with Collections and
2439  * how they reference each-other in their parents/children relations.
2440  * Core of the issue is creating and storing those copies in a separate Main, while collection
2441  * copy code re-assign blindly parents/children, even if they do not belong to the same Main.
2442  * One solution could be to implement special flag as discussed below, and prevent any
2443  * other-ID-reference creation/update in that case (since no differential operation is expected
2444  * to involve those anyway). */
2445 #if 0
2446  /* XXX TODO We may also want a specialized handling of things here too, to avoid copying heavy
2447  * never-overridable data (like Mesh geometry etc.)? And also maybe avoid lib
2448  * reference-counting completely (shallow copy). */
2449  /* This would imply change in handling of user-count all over RNA
2450  * (and possibly all over Blender code).
2451  * Not impossible to do, but would rather see first is extra useless usual user handling is
2452  * actually a (performances) issue here, before doing it. */
2453  storage_id = BKE_id_copy((Main *)override_storage, local);
2454 
2455  if (storage_id != NULL) {
2456  PointerRNA rnaptr_reference, rnaptr_final, rnaptr_storage;
2457  RNA_id_pointer_create(local->override_library->reference, &rnaptr_reference);
2458  RNA_id_pointer_create(local, &rnaptr_final);
2459  RNA_id_pointer_create(storage_id, &rnaptr_storage);
2460 
2462  bmain, &rnaptr_final, &rnaptr_reference, &rnaptr_storage, local->override_library)) {
2463  BKE_id_free_ex(override_storage, storage_id, LIB_ID_FREE_NO_UI_USER, true);
2464  storage_id = NULL;
2465  }
2466  }
2467 #else
2468  storage_id = NULL;
2469 #endif
2470 
2471  local->override_library->storage = storage_id;
2472 
2473 #ifdef DEBUG_OVERRIDE_TIMEIT
2475 #endif
2476  return storage_id;
2477 }
2478 
2484  OverrideLibraryStorage *UNUSED(override_storage), ID *local)
2485 {
2487 
2488  /* Nothing else to do here really, we need to keep all temp override storage data-blocks in
2489  * memory until whole file is written anyway (otherwise we'd get mem pointers overlap). */
2490  local->override_library->storage = NULL;
2491 }
2492 
2494 {
2495  /* We cannot just call BKE_main_free(override_storage), not until we have option to make
2496  * 'ghost' copies of IDs without increasing usercount of used data-blocks. */
2497  ID *id;
2498 
2499  FOREACH_MAIN_ID_BEGIN (override_storage, id) {
2500  BKE_id_free_ex(override_storage, id, LIB_ID_FREE_NO_UI_USER, true);
2501  }
2503 
2504  BKE_main_free(override_storage);
2505 }
void BKE_pose_ensure(struct Main *bmain, struct Object *ob, struct bArmature *arm, const bool do_id_user)
Definition: armature.c:2608
void BKE_pose_clear_pointers(struct bPose *pose)
Definition: armature.c:2490
struct Collection * BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name)
Definition: collection.c:435
void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
Definition: collection.c:1168
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1134
struct GSet * BKE_scene_objects_as_gset(struct Scene *scene, struct GSet *objects_gset)
Definition: collection.c:2196
void BKE_collection_add_from_object(struct Main *bmain, struct Scene *scene, const struct Object *ob_src, struct Collection *collection_dst)
bool BKE_collection_has_object(struct Collection *collection, const struct Object *ob)
void BKE_collection_add_from_collection(struct Main *bmain, struct Scene *scene, struct Collection *collection_src, struct Collection *collection_dst)
Definition: collection.c:476
bool BKE_collection_is_in_scene(struct Collection *collection)
Definition: collection.c:1391
bool BKE_collection_is_empty(const struct Collection *collection)
bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy)
Definition: collection.c:520
#define G_MAIN
Definition: BKE_global.h:232
bool BKE_idtype_idcode_is_linkable(const short idcode)
Definition: idtype.c:232
struct Key * BKE_key_from_id(struct ID *id)
Definition: key.c:1786
struct Key ** BKE_key_from_id_p(struct ID *id)
Definition: key.c:1761
void BKE_main_collection_sync(const struct Main *bmain)
bool BKE_view_layer_has_collection(struct ViewLayer *view_layer, const struct Collection *collection)
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value)
Definition: lib_id.c:923
void id_fake_user_set(struct ID *id)
Definition: lib_id.c:328
@ LIB_ID_COPY_NO_LIB_OVERRIDE
Definition: BKE_lib_id.h:124
@ LIB_ID_COPY_DEFAULT
Definition: BKE_lib_id.h:139
@ LIB_ID_FREE_NO_UI_USER
Definition: BKE_lib_id.h:204
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_main_id_clear_newpoins(struct Main *bmain)
Definition: lib_id.c:1738
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
void BKE_id_delete(struct Main *bmain, void *idv) ATTR_NONNULL()
size_t BKE_id_multi_tagged_delete(struct Main *bmain) ATTR_NONNULL()
void BKE_id_free_ex(struct Main *bmain, void *idv, int flag, const bool use_flag_from_idtag)
void BKE_lib_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b)
Definition: lib_id.c:729
@ IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE
Definition: BKE_lib_query.h:74
void void BKE_libblock_remap(struct Main *bmain, void *old_idv, void *new_idv, const short remap_flags) ATTR_NONNULL(1
void BKE_libblock_relink_ex(struct Main *bmain, void *idv, void *old_idv, void *new_idv, const short remap_flags) ATTR_NONNULL(1
@ ID_REMAP_SKIP_OVERRIDE_LIBRARY
Definition: BKE_lib_remap.h:78
@ ID_REMAP_SKIP_INDIRECT_USAGE
Definition: BKE_lib_remap.h:46
#define FOREACH_MAIN_ID_END
Definition: BKE_main.h:250
struct Main * BKE_main_new(void)
Definition: main.c:45
void BKE_main_relations_create(struct Main *bmain, const short flag)
Definition: main.c:265
#define FOREACH_MAIN_LISTBASE_ID_END
Definition: BKE_main.h:219
#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id)
Definition: BKE_main.h:213
void BKE_main_relations_tag_set(struct Main *bmain, const MainIDRelationsEntryTags tag, const bool value)
Definition: main.c:313
#define FOREACH_MAIN_LISTBASE_END
Definition: BKE_main.h:231
@ MAINIDRELATIONS_ENTRY_TAGS_PROCESSED
Definition: BKE_main.h:96
void BKE_main_relations_free(struct Main *bmain)
Definition: main.c:300
#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb)
Definition: BKE_main.h:224
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
Definition: BKE_main.h:244
void BKE_main_free(struct Main *mainvar)
Definition: main.c:53
struct bNodeTree * ntreeFromID(struct ID *id)
Definition: node.cc:3147
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert_unreachable()
Definition: BLI_assert.h:96
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define ATTR_FALLTHROUGH
#define BLI_INLINE
struct GSet GSet
Definition: BLI_ghash.h:189
bool BLI_ghashutil_strcmp(const void *a, const void *b)
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:996
unsigned int BLI_ghashutil_ptrhash(const void *key)
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:718
bool BLI_ghash_haskey(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:941
bool BLI_ghashutil_ptrcmp(const void *a, const void *b)
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr)
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:900
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:830
void * BLI_gset_lookup(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:1280
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
Definition: BLI_ghash.c:1253
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
void * BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:281
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:188
void * BLI_listbase_bytes_find(const ListBase *listbase, const void *bytes, const size_t bytes_size, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_listbase_swaplinks(struct ListBase *listbase, void *vlinka, void *vlinkb) ATTR_NONNULL(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
void * BLI_task_pool_user_data(TaskPool *pool)
Definition: task_pool.cc:541
void BLI_task_pool_work_and_wait(TaskPool *pool)
Definition: task_pool.cc:496
TaskPool * BLI_task_pool_create(void *userdata, TaskPriority priority)
Definition: task_pool.cc:406
void BLI_task_pool_free(TaskPool *pool)
Definition: task_pool.cc:456
@ TASK_PRIORITY_HIGH
Definition: BLI_task.h:67
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Definition: task_pool.cc:475
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
#define ELEM(...)
#define STREQ(a, b)
#define CLOG_INFO(clg_ref, level,...)
Definition: CLG_log.h:201
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
ID and Library types, which are fundamental for sdna.
#define ID_IS_OVERRIDE_LIBRARY_VIRTUAL(_id)
Definition: DNA_ID.h:442
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_ALL
Definition: DNA_ID.h:697
@ ID_RECALC_BASE_FLAGS
Definition: DNA_ID.h:641
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition: DNA_ID.h:438
@ LIB_TAG_DOIT
Definition: DNA_ID.h:554
@ LIB_TAG_OVERRIDE_LIBRARY_REFOK
Definition: DNA_ID.h:540
@ LIB_TAG_MISSING
Definition: DNA_ID.h:537
@ LIB_TAG_LIB_OVERRIDE_NEED_RESYNC
Definition: DNA_ID.h:590
@ LIB_TAG_OVERRIDE_LIBRARY_AUTOREFRESH
Definition: DNA_ID.h:542
#define ID_IS_OVERRIDABLE_LIBRARY(_id)
Definition: DNA_ID.h:430
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define MAX_ID_NAME
Definition: DNA_ID.h:269
@ LIB_LIB_OVERRIDE_RESYNC_LEFTOVER
Definition: DNA_ID.h:498
@ LIB_EMBEDDED_DATA_LIB_OVERRIDE
Definition: DNA_ID.h:493
@ IDOVERRIDE_LIBRARY_RUNTIME_TAG_NEEDS_RELOAD
Definition: DNA_ID.h:244
@ IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE
Definition: DNA_ID.h:200
@ IDOVERRIDE_LIBRARY_TAG_UNUSED
Definition: DNA_ID.h:231
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:413
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:445
#define ID_IS_OVERRIDE_LIBRARY_TEMPLATE(_id)
Definition: DNA_ID.h:448
@ IDOVERRIDE_LIBRARY_OP_MULTIPLY
Definition: DNA_ID.h:183
@ IDOVERRIDE_LIBRARY_OP_INSERT_AFTER
Definition: DNA_ID.h:186
@ IDOVERRIDE_LIBRARY_OP_NOOP
Definition: DNA_ID.h:174
@ IDOVERRIDE_LIBRARY_OP_SUBTRACT
Definition: DNA_ID.h:181
@ IDOVERRIDE_LIBRARY_OP_ADD
Definition: DNA_ID.h:179
@ IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE
Definition: DNA_ID.h:187
@ IDOVERRIDE_LIBRARY_OP_REPLACE
Definition: DNA_ID.h:176
#define ID_MISSING(_id)
Definition: DNA_ID.h:424
@ ID_AR
Definition: DNA_ID_enums.h:78
@ ID_KE
Definition: DNA_ID_enums.h:70
@ ID_SCE
Definition: DNA_ID_enums.h:57
@ ID_GR
Definition: DNA_ID_enums.h:77
@ ID_OB
Definition: DNA_ID_enums.h:59
@ POSE_RECALC
Object groups, one object can be in many groups at once.
@ COLLECTION_RESTRICT_RENDER
@ COLLECTION_RESTRICT_VIEWPORT
Object is a sort of wrapper for general info.
#define OB_DATA_SUPPORT_ID(_id_type)
@ OB_ARMATURE
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Utility defines for timing/benchmarks.
#define TIMEIT_START_AVERAGED(var)
#define TIMEIT_END_AVERAGED(var)
@ RNA_OVERRIDE_APPLY_FLAG_IGNORE_ID_POINTERS
Definition: RNA_access.h:1527
@ RNA_OVERRIDE_APPLY_FLAG_NOP
Definition: RNA_access.h:1522
@ RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN
Definition: RNA_access.h:1477
@ RNA_OVERRIDE_COMPARE_CREATE
Definition: RNA_access.h:1480
@ RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE
Definition: RNA_access.h:1475
@ RNA_OVERRIDE_COMPARE_RESTORE
Definition: RNA_access.h:1482
StructRNA RNA_ID
eRNAOverrideMatchResult
Definition: RNA_access.h:1485
@ RNA_OVERRIDE_MATCH_RESULT_RESTORED
Definition: RNA_access.h:1492
@ RNA_OVERRIDE_MATCH_RESULT_CREATED
Definition: RNA_access.h:1490
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_COLLECTION
Definition: RNA_types.h:79
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE uint8_t atomic_fetch_and_or_uint8(uint8_t *p, uint8_t b)
Scene scene
TaskPool * task_pool
#define GS(x)
Definition: iris.c:241
static bool lib_override_hierarchy_dependencies_recursive_tag(LibOverrideGroupTagData *data)
Definition: lib_override.c:421
void BKE_lib_override_library_operations_store_finalize(OverrideLibraryStorage *override_storage)
static void lib_override_library_property_clear(IDOverrideLibraryProperty *op)
bool BKE_lib_override_library_resync(Main *bmain, Scene *scene, ViewLayer *view_layer, ID *id_root, Collection *override_resync_residual_storage, const bool do_hierarchy_enforce, const bool do_post_process)
Definition: lib_override.c:876
void BKE_lib_override_library_validate(Main *UNUSED(bmain), ID *id, ReportList *reports)
bool BKE_lib_override_library_proxy_convert(Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob_proxy)
Definition: lib_override.c:834
static void lib_override_library_create_post_process(Main *bmain, Scene *scene, ViewLayer *view_layer, ID *id_root, ID *id_reference, Collection *residual_storage, const bool is_resync)
Definition: lib_override.c:655
ID * BKE_lib_override_library_create_from_id(Main *bmain, ID *reference_id, const bool do_tagged_remap)
Definition: lib_override.c:254
void BKE_lib_override_library_main_validate(Main *bmain, ReportList *reports)
bool BKE_lib_override_library_create(Main *bmain, Scene *scene, ViewLayer *view_layer, ID *id_root, ID *id_reference)
Definition: lib_override.c:788
static void lib_override_linked_group_tag(LibOverrideGroupTagData *data)
Definition: lib_override.c:528
IDOverrideLibraryProperty * BKE_lib_override_library_property_get(IDOverrideLibrary *override, const char *rna_path, bool *r_created)
bool BKE_lib_override_library_template_create(struct ID *id)
Definition: lib_override.c:813
void BKE_lib_override_library_main_tag(struct Main *bmain, const short tag, const bool do_set)
ID * BKE_lib_override_library_operations_store_start(Main *bmain, OverrideLibraryStorage *override_storage, ID *local)
#define OVERRIDE_RESYNC_RESIDUAL_STORAGE_NAME
static void lib_override_local_group_tag(LibOverrideGroupTagData *data)
Definition: lib_override.c:624
static void lib_override_library_property_operation_copy(IDOverrideLibraryPropertyOperation *opop_dst, IDOverrideLibraryPropertyOperation *opop_src)
void BKE_lib_override_library_clear(IDOverrideLibrary *override, const bool do_id_user)
Definition: lib_override.c:162
bool BKE_lib_override_library_status_check_reference(Main *bmain, ID *local)
bool BKE_lib_override_library_operations_create(Main *bmain, ID *local)
void BKE_lib_override_library_update(Main *bmain, ID *local)
void BKE_lib_override_library_id_unused_cleanup(struct ID *local)
static void lib_override_id_swap(Main *bmain, ID *id_local, ID *id_temp)
static void lib_override_local_group_tag_recursive(LibOverrideGroupTagData *data)
Definition: lib_override.c:558
OverrideLibraryStorage * BKE_lib_override_library_operations_store_init(void)
BLI_INLINE GHash * override_library_rna_path_mapping_ensure(IDOverrideLibrary *override)
IDOverrideLibraryPropertyOperation * BKE_lib_override_library_property_operation_get(IDOverrideLibraryProperty *override_property, const short operation, const char *subitem_refname, const char *subitem_locname, const int subitem_refindex, const int subitem_locindex, const bool strict, bool *r_strict, bool *r_created)
IDOverrideLibrary * BKE_lib_override_library_init(ID *local_id, ID *reference_id)
Definition: lib_override.c:85
void BKE_lib_override_library_main_unused_cleanup(struct Main *bmain)
static void lib_override_library_operations_create_cb(TaskPool *__restrict pool, void *taskdata)
bool BKE_lib_override_library_create_from_tag(Main *bmain)
Definition: lib_override.c:308
static ID * lib_override_library_create_from(Main *bmain, ID *reference_id)
Definition: lib_override.c:198
void BKE_lib_override_library_main_resync(Main *bmain, Scene *scene, ViewLayer *view_layer)
void BKE_lib_override_library_operations_store_end(OverrideLibraryStorage *UNUSED(override_storage), ID *local)
void BKE_lib_override_library_id_reset(Main *bmain, ID *id_root)
bool BKE_lib_override_library_status_check_local(Main *bmain, ID *local)
void BKE_lib_override_library_properties_tag(struct IDOverrideLibrary *override, const short tag, const bool do_set)
bool BKE_lib_override_library_is_user_edited(struct ID *id)
Definition: lib_override.c:231
void BKE_lib_override_library_operations_tag(struct IDOverrideLibraryProperty *override_property, const short tag, const bool do_set)
bool BKE_lib_override_library_property_operation_operands_validate(struct IDOverrideLibraryPropertyOperation *override_property_operation, struct PointerRNA *ptr_dst, struct PointerRNA *ptr_src, struct PointerRNA *ptr_storage, struct PropertyRNA *prop_dst, struct PropertyRNA *prop_src, struct PropertyRNA *prop_storage)
void BKE_lib_override_library_property_delete(IDOverrideLibrary *override, IDOverrideLibraryProperty *override_property)
static void lib_override_library_id_hierarchy_recursive_reset(Main *bmain, ID *id_root)
void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bool do_id_user)
Definition: lib_override.c:182
static bool lib_override_library_create_do(Main *bmain, ID *id_root)
Definition: lib_override.c:640
void BKE_lib_override_library_delete(Main *bmain, ID *id_root)
static CLG_LogRef LOG
Definition: lib_override.c:73
static void lib_override_linked_group_tag_recursive(LibOverrideGroupTagData *data)
Definition: lib_override.c:462
static void lib_override_library_property_operation_clear(IDOverrideLibraryPropertyOperation *opop)
void BKE_lib_override_library_main_update(Main *bmain)
void BKE_lib_override_library_make_local(ID *id)
BLI_INLINE IDOverrideLibraryRuntime * override_library_rna_path_runtime_ensure(IDOverrideLibrary *override)
IDOverrideLibraryPropertyOperation * BKE_lib_override_library_property_operation_find(IDOverrideLibraryProperty *override_property, const char *subitem_refname, const char *subitem_locname, const int subitem_refindex, const int subitem_locindex, const bool strict, bool *r_strict)
void BKE_lib_override_library_id_hierarchy_reset(Main *bmain, ID *id_root)
static bool lib_override_library_id_reset_do(Main *bmain, ID *id_root)
IDOverrideLibraryProperty * BKE_lib_override_library_property_find(IDOverrideLibrary *override, const char *rna_path)
bool BKE_lib_override_library_main_operations_create(Main *bmain, const bool force_auto)
struct LibOverrideGroupTagData LibOverrideGroupTagData
void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_full_copy)
Definition: lib_override.c:120
void BKE_lib_override_library_property_operation_delete(IDOverrideLibraryProperty *override_property, IDOverrideLibraryPropertyOperation *override_property_operation)
bool BKE_lib_override_rna_property_find(PointerRNA *idpoin, const IDOverrideLibraryProperty *library_prop, PointerRNA *r_override_poin, PropertyRNA **r_override_prop)
static void lib_override_library_property_copy(IDOverrideLibraryProperty *op_dst, IDOverrideLibraryProperty *op_src)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
bool RNA_struct_is_ID(const StructRNA *type)
Definition: rna_access.c:797
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1155
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3641
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1567
bool RNA_path_resolve_property(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5434
bool RNA_struct_override_store(Main *bmain, PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage, IDOverrideLibrary *override)
void RNA_struct_override_apply(Main *bmain, PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *ptr_storage, IDOverrideLibrary *override, const eRNAOverrideApplyFlag flag)
bool RNA_struct_override_matches(Main *bmain, PointerRNA *ptr_local, PointerRNA *ptr_reference, const char *root_path, const size_t root_path_len, IDOverrideLibrary *override, const eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags)
unsigned char uint8_t
Definition: stdint.h:81
struct GHash * rna_path_to_override_properties
Definition: DNA_ID.h:237
struct ID * storage
Definition: DNA_ID.h:257
ListBase properties
Definition: DNA_ID.h:252
struct ID * reference
Definition: DNA_ID.h:250
IDOverrideLibraryRuntime * runtime
Definition: DNA_ID.h:259
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
struct Library * lib
Definition: DNA_ID.h:277
struct ID * newid
Definition: DNA_ID.h:275
IDOverrideLibrary * override_library
Definition: DNA_ID.h:317
short flag
Definition: DNA_ID.h:288
char name[66]
Definition: DNA_ID.h:283
ID * from
ID id
Definition: DNA_key_types.h:79
void * data
Definition: DNA_listBase.h:42
struct LinkData * next
Definition: DNA_listBase.h:41
void * first
Definition: DNA_listBase.h:47
struct MainIDRelationsEntryItem * to_ids
Definition: BKE_main.h:82
struct GHash * relations_from_pointers
Definition: BKE_main.h:102
Definition: BKE_main.h:116
struct MainIDRelations * relations
Definition: BKE_main.h:192
ListBase collections
Definition: BKE_main.h:167
ListBase objects
Definition: BKE_main.h:148
struct Object * proxy_group
struct Collection * instance_collection
struct Object * proxy_from
struct Object * proxy
void * data
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
struct Collection * master_collection
PointerRNA * ptr
Definition: wm_files.c:3157
bool override
Definition: wm_files.c:854