Proxies Removal: Handle conversion to liboverrides also for linked data.

So far linked proxies were just kept as-is, this is no longer an option.

Attempt to convert them into liboverrides as much as possible, though
some cases won't be supported:
- Appending proxies is broken since a long time, so conversion will fail
  here as well.
- When linking data, some cases will fail to convert properly. in
  particular, if the linked proxy object is not instanced in a scene
  (e.g. when linking a collection containing a proxy as an
  epty-instanced collection instead of a view-layer-instanced collection).

NOTE: converion when linking/appending is done unconditionnaly, option
to not convert on file load will be removed in next commit anyway.

Part of T91671.
This commit is contained in:
Bastien Montagne 2022-02-01 12:09:26 +01:00
parent 286fcb3a60
commit 049df7ef94
4 changed files with 57 additions and 26 deletions

View File

@ -993,6 +993,24 @@ static int foreach_libblock_link_append_callback(LibraryIDLinkCallbackData *cb_d
/** \name Library link/append code.
* \{ */
static void blendfile_link_append_proxies_convert(Main *bmain, ReportList *reports)
{
BlendFileReadReport bf_reports = {.reports = reports};
BKE_lib_override_library_main_proxy_convert(bmain, &bf_reports);
if (bf_reports.count.proxies_to_lib_overrides_success != 0 ||
bf_reports.count.proxies_to_lib_overrides_failures != 0) {
BKE_reportf(
bf_reports.reports,
RPT_WARNING,
"Proxies have been removed from Blender (%d proxies were automatically converted "
"to library overrides, %d proxies could not be converted and were cleared). "
"Please consider re-saving any library .blend file with the newest Blender version.",
bf_reports.count.proxies_to_lib_overrides_success,
bf_reports.count.proxies_to_lib_overrides_failures);
}
}
void BKE_blendfile_append(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
{
if (lapp_context->num_items == 0) {
@ -1259,6 +1277,8 @@ void BKE_blendfile_append(BlendfileLinkAppendContext *lapp_context, ReportList *
}
BKE_main_id_newptr_and_tag_clear(bmain);
blendfile_link_append_proxies_convert(bmain, reports);
}
void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
@ -1361,6 +1381,10 @@ void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *re
.active_collection = NULL};
loose_data_instantiate(&instantiate_context);
}
if ((lapp_context->params->flag & FILE_LINK) != 0) {
blendfile_link_append_proxies_convert(lapp_context->params->bmain, reports);
}
}
/** \} */

View File

@ -1040,7 +1040,12 @@ bool BKE_lib_override_library_proxy_convert(Main *bmain,
/* In some cases the instance collection of a proxy object may be local (see e.g. T83875). Not
* sure this is a valid state, but for now just abort the overriding process. */
if (!ID_IS_OVERRIDABLE_LIBRARY(id_root)) {
if (!ID_IS_OVERRIDABLE_LIBRARY_HIERARCHY(id_root)) {
if (ob_proxy->proxy != NULL) {
ob_proxy->proxy->proxy_from = NULL;
}
id_us_min((ID *)ob_proxy->proxy);
ob_proxy->proxy = ob_proxy->proxy_group = NULL;
return false;
}
@ -1058,12 +1063,12 @@ bool BKE_lib_override_library_proxy_convert(Main *bmain,
DEG_id_tag_update(&ob_proxy->id, ID_RECALC_COPY_ON_WRITE);
/* In case of proxy conversion, remap all local ID usages to linked IDs to their newly created
* overrides.
* overrides. Also do that for the IDs from the same lib as the proxy in case it is linked.
* While this might not be 100% the desired behavior, it is likely to be the case most of the
* time. Ref: T91711. */
ID *id_iter;
FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
if (!ID_IS_LINKED(id_iter)) {
if (!ID_IS_LINKED(id_iter) || id_iter->lib == ob_proxy->id.lib) {
id_iter->tag |= LIB_TAG_DOIT;
}
}
@ -1120,18 +1125,24 @@ void BKE_lib_override_library_main_proxy_convert(Main *bmain, BlendFileReadRepor
}
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ID_IS_LINKED(object)) {
if (object->proxy != NULL) {
CLOG_WARN(&LOG, "Did not try to convert linked proxy object '%s'", object->id.name);
reports->count.linked_proxies++;
}
continue;
}
if (object->proxy_group != NULL || object->proxy != NULL) {
CLOG_WARN(
&LOG, "Proxy object '%s' failed to be converted to library override", object->id.name);
if (ID_IS_LINKED(object)) {
CLOG_WARN(&LOG,
"Linked proxy object '%s' from '%s' failed to be converted to library override",
object->id.name + 2,
object->id.lib->filepath);
}
else {
CLOG_WARN(&LOG,
"Proxy object '%s' failed to be converted to library override",
object->id.name + 2);
}
reports->count.proxies_to_lib_overrides_failures++;
if (object->proxy != NULL) {
object->proxy->proxy_from = NULL;
}
id_us_min((ID *)object->proxy);
object->proxy = object->proxy_group = NULL;
}
}
}

View File

@ -117,8 +117,6 @@ typedef struct BlendFileReadReport {
/* Number of root override IDs that were resynced. */
int resynced_lib_overrides;
/* Number of (non-converted) linked proxies. */
int linked_proxies;
/* Number of proxies converted to library overrides. */
int proxies_to_lib_overrides_success;
/* Number of proxies that failed to convert to library overrides. */

View File

@ -874,18 +874,16 @@ static void file_read_reports_finalize(BlendFileReadReport *bf_reports)
duration_lib_override_recursive_resync_seconds);
}
if (bf_reports->count.linked_proxies != 0 ||
bf_reports->count.proxies_to_lib_overrides_success != 0 ||
if (bf_reports->count.proxies_to_lib_overrides_success != 0 ||
bf_reports->count.proxies_to_lib_overrides_failures != 0) {
BKE_reportf(bf_reports->reports,
RPT_WARNING,
"Proxies are deprecated (%d proxies were automatically converted to library "
"overrides, %d proxies could not be converted and %d linked proxies were kept "
"untouched). If you need to keep proxies for the time being, please disable the "
"`Proxy to Override Auto Conversion` in Experimental user preferences",
bf_reports->count.proxies_to_lib_overrides_success,
bf_reports->count.proxies_to_lib_overrides_failures,
bf_reports->count.linked_proxies);
BKE_reportf(
bf_reports->reports,
RPT_WARNING,
"Proxies have been removed from Blender (%d proxies were automatically converted "
"to library overrides, %d proxies could not be converted and were cleared). "
"Please also consider re-saving any library .blend file with the newest Blender version.",
bf_reports->count.proxies_to_lib_overrides_success,
bf_reports->count.proxies_to_lib_overrides_failures);
}
if (bf_reports->count.sequence_strips_skipped != 0) {