BKE lib remap: Add option to allow remapping of `ID.lib` pointers.

Usually Library pointers should not be affected by remapping, but this
can be needed in some cases.

WARNING: Use with caution, this is potentially a dangerous operation for
Main data integrity/validity.
This commit is contained in:
Bastien Montagne 2023-12-01 15:12:50 +01:00
parent 854840b35f
commit 2064af64e5
2 changed files with 16 additions and 7 deletions

View File

@ -72,6 +72,13 @@ enum {
* the 'separate' mesh operator.
*/
ID_REMAP_FORCE_OBDATA_IN_EDITMODE = 1 << 7,
/** Do remapping of `lib` Library pointers of IDs (by default these are completely ignored).
*
* WARNING: Use with caution. This is currently a 'raw' remapping, with no further processing. In
* particular, DO NOT use this to make IDs local (i.e. remap a library pointer to NULL), unless
* the calling code takes care of the rest of the required changes (ID tags & flags updates,
* etc.). */
ID_REMAP_DO_LIBRARY_POINTERS = 1 << 8,
/**
* Don't touch the special user counts (use when the 'old' remapped ID remains in use):

View File

@ -487,13 +487,15 @@ static void libblock_remap_data(
{
IDRemap id_remap_data = {eIDRemapType(0)};
const bool include_ui = (remap_flags & ID_REMAP_FORCE_UI_POINTERS) != 0;
const int foreach_id_flags = (((remap_flags & ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS) != 0 ?
IDWALK_DO_INTERNAL_RUNTIME_POINTERS :
IDWALK_NOP) |
(include_ui ? IDWALK_INCLUDE_UI : IDWALK_NOP) |
((remap_flags & ID_REMAP_NO_ORIG_POINTERS_ACCESS) != 0 ?
IDWALK_NO_ORIG_POINTERS_ACCESS :
IDWALK_NOP));
const int foreach_id_flags =
(((remap_flags & ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS) != 0 ?
IDWALK_DO_INTERNAL_RUNTIME_POINTERS :
IDWALK_NOP) |
(include_ui ? IDWALK_INCLUDE_UI : IDWALK_NOP) |
((remap_flags & ID_REMAP_NO_ORIG_POINTERS_ACCESS) != 0 ? IDWALK_NO_ORIG_POINTERS_ACCESS :
IDWALK_NOP) |
((remap_flags & ID_REMAP_DO_LIBRARY_POINTERS) != 0 ? IDWALK_DO_LIBRARY_POINTER : IDWALK_NOP));
id_remap_data.id_remapper = id_remapper;
id_remap_data.type = remap_type;