[Bf-blender-cvs] [a8b24ca61b1] asset-uuid: Merge branch 'master' into asset-uuid
Julian Eisel
noreply at git.blender.org
Thu Jun 11 11:55:52 CEST 2020
Commit: a8b24ca61b1859b659dd22f411cb74cef54dc229
Author: Julian Eisel
Date: Thu Jun 11 10:13:12 2020 +0200
Branches: asset-uuid
https://developer.blender.org/rBa8b24ca61b1859b659dd22f411cb74cef54dc229
Merge branch 'master' into asset-uuid
===================================================================
===================================================================
diff --cc source/blender/blenkernel/intern/lib_remap.c
index 00000000000,ba986b1661b..bc009c80849
mode 000000,100644..100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@@ -1,0 -1,693 +1,1123 @@@
+ /*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+ /** \file
+ * \ingroup bke
+ *
+ * Contains management of ID's for remapping.
+ */
+
+ #include "CLG_log.h"
+
+ #include "BLI_utildefines.h"
+
+ #include "DNA_object_types.h"
+
+ #include "BKE_armature.h"
+ #include "BKE_collection.h"
+ #include "BKE_curve.h"
+ #include "BKE_layer.h"
+ #include "BKE_lib_id.h"
+ #include "BKE_lib_query.h"
+ #include "BKE_lib_remap.h"
+ #include "BKE_main.h"
+ #include "BKE_material.h"
+ #include "BKE_mball.h"
+ #include "BKE_modifier.h"
+ #include "BKE_multires.h"
+ #include "BKE_node.h"
+ #include "BKE_object.h"
+
+ #include "DEG_depsgraph.h"
+ #include "DEG_depsgraph_build.h"
+
+ #include "lib_intern.h" /* own include */
+
+ static CLG_LogRef LOG = {.identifier = "bke.lib_remap"};
+
+ BKE_library_free_notifier_reference_cb free_notifier_reference_cb = NULL;
+
+ void BKE_library_callback_free_notifier_reference_set(BKE_library_free_notifier_reference_cb func)
+ {
+ free_notifier_reference_cb = func;
+ }
+
+ BKE_library_remap_editor_id_reference_cb remap_editor_id_reference_cb = NULL;
+
+ void BKE_library_callback_remap_editor_id_reference_set(
+ BKE_library_remap_editor_id_reference_cb func)
+ {
+ remap_editor_id_reference_cb = func;
+ }
+
+ typedef struct IDRemap {
+ Main *bmain; /* Only used to trigger depsgraph updates in the right bmain. */
+ ID *old_id;
+ ID *new_id;
+ /** The ID in which we are replacing old_id by new_id usages. */
+ ID *id_owner;
+ short flag;
+
+ /* 'Output' data. */
+ short status;
+ /** Number of direct usecases that could not be remapped (e.g.: obdata when in edit mode). */
+ int skipped_direct;
+ /** Number of indirect usecases that could not be remapped. */
+ int skipped_indirect;
+ /** Number of skipped usecases that refcount the datablock. */
+ int skipped_refcounted;
+ } IDRemap;
+
+ /* IDRemap->flag enums defined in BKE_lib.h */
+
+ /* IDRemap->status */
+ enum {
+ /* *** Set by callback. *** */
+ ID_REMAP_IS_LINKED_DIRECT = 1 << 0, /* new_id is directly linked in current .blend. */
+ ID_REMAP_IS_USER_ONE_SKIPPED = 1 << 1, /* There was some skipped 'user_one' usages of old_id. */
+ };
+
+ static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
+ {
+ const int cb_flag = cb_data->cb_flag;
+
+ if (cb_flag & IDWALK_CB_EMBEDDED) {
+ return IDWALK_RET_NOP;
+ }
+
+ ID *id_owner = cb_data->id_owner;
+ ID *id_self = cb_data->id_self;
+ ID **id_p = cb_data->id_pointer;
+ IDRemap *id_remap_data = cb_data->user_data;
+ ID *old_id = id_remap_data->old_id;
+ ID *new_id = id_remap_data->new_id;
+
+ /* Those asserts ensure the general sanity of ID tags regarding 'embedded' ID data (root
+ * nodetrees and co). */
+ BLI_assert(id_owner == id_remap_data->id_owner);
+ BLI_assert(id_self == id_owner || (id_self->flag & LIB_EMBEDDED_DATA) != 0);
+
+ if (!old_id) { /* Used to cleanup all IDs used by a specific one. */
+ BLI_assert(!new_id);
+ old_id = *id_p;
+ }
+
+ if (*id_p && (*id_p == old_id)) {
+ /* Better remap to NULL than not remapping at all,
+ * then we can handle it as a regular remap-to-NULL case. */
+ if ((cb_flag & IDWALK_CB_NEVER_SELF) && (new_id == id_self)) {
+ new_id = NULL;
+ }
+
+ const bool is_reference = (cb_flag & IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE) != 0;
+ const bool is_indirect = (cb_flag & IDWALK_CB_INDIRECT_USAGE) != 0;
+ const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0;
+ /* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct,
+ * on the other hand since they get reset to lib data on file open/reload it is indirect too.
+ * Edit Mode is also a 'skip direct' case. */
+ const bool is_obj = (GS(id_owner->name) == ID_OB);
+ const bool is_obj_proxy = (is_obj &&
+ (((Object *)id_owner)->proxy || ((Object *)id_owner)->proxy_group));
+ const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id_owner));
+ const bool is_never_null = ((cb_flag & IDWALK_CB_NEVER_NULL) && (new_id == NULL) &&
+ (id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0);
+ const bool skip_reference = (id_remap_data->flag & ID_REMAP_SKIP_OVERRIDE_LIBRARY) != 0;
+ const bool skip_never_null = (id_remap_data->flag & ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0;
+
+ #ifdef DEBUG_PRINT
+ printf(
+ "In %s (lib %p): Remapping %s (%p) to %s (%p) "
+ "(is_indirect: %d, skip_indirect: %d, is_reference: %d, skip_reference: %d)\n",
+ id->name,
+ id->lib,
+ old_id->name,
+ old_id,
+ new_id ? new_id->name : "<NONE>",
+ new_id,
+ is_indirect,
+ skip_indirect,
+ is_reference,
+ skip_reference);
+ #endif
+
+ if ((id_remap_data->flag & ID_REMAP_FLAG_NEVER_NULL_USAGE) &&
+ (cb_flag & IDWALK_CB_NEVER_NULL)) {
+ id_owner->tag |= LIB_TAG_DOIT;
+ }
+
+ /* Special hack in case it's Object->data and we are in edit mode, and new_id is not NULL
+ * (otherwise, we follow common NEVER_NULL flags).
+ * (skipped_indirect too). */
+ if ((is_never_null && skip_never_null) ||
+ (is_obj_editmode && (((Object *)id_owner)->data == *id_p) && new_id != NULL) ||
+ (skip_indirect && is_indirect) || (is_reference && skip_reference)) {
+ if (is_indirect) {
+ id_remap_data->skipped_indirect++;
+ if (is_obj) {
+ Object *ob = (Object *)id_owner;
+ if (ob->data == *id_p && ob->proxy != NULL) {
+ /* And another 'Proudly brought to you by Proxy Hell' hack!
+ * This will allow us to avoid clearing 'LIB_EXTERN' flag of obdata of proxies... */
+ id_remap_data->skipped_direct++;
+ }
+ }
+ }
+ else if (is_never_null || is_obj_editmode || is_reference) {
+ id_remap_data->skipped_direct++;
+ }
+ else {
+ BLI_assert(0);
+ }
+ if (cb_flag & IDWALK_CB_USER) {
+ id_remap_data->skipped_refcounted++;
+ }
+ else if (cb_flag & IDWALK_CB_USER_ONE) {
+ /* No need to count number of times this happens, just a flag is enough. */
+ id_remap_data->status |= ID_REMAP_IS_USER_ONE_SKIPPED;
+ }
+ }
+ else {
+ if (!is_never_null) {
+ *id_p = new_id;
+ DEG_id_tag_update_ex(id_remap_data->bmain,
+ id_self,
+ ID_RECALC_COPY_ON_WRITE | ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+ if (id_self != id_owner) {
+ DEG_id_tag_update_ex(id_remap_data->bmain,
+ id_owner,
+ ID_RECALC_COPY_ON_WRITE | ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+ }
+ }
+ if (cb_flag & IDWALK_CB_USER) {
+ /* NOTE: We don't user-count IDs which are not in the main database.
+ * This is because in certain conditions we can have data-blocks in
+ * the main which are referencing data-blocks outside of it.
+ * For example, BKE_mesh_new_from_object() called on an evaluated
+ * object will cause such situation.
+ */
+ if ((old_id->tag & LIB_TAG_NO_MAIN) == 0) {
+ id_us_min(old_id);
+ }
+ if (new_id != NULL && (new_id->tag & LIB_TAG_NO_MAIN) == 0) {
+ /* We do not want to handle LIB_TAG_INDIRECT/LIB_TAG_EXTERN here. */
+ new_id->us++;
+ }
+ }
+ else if (cb_flag & IDWALK_CB_USER_ONE) {
+ id_us_ensure_real(new_id);
+ /* We cannot affect old_id->us directly, LIB_TAG_EXTRAUSER(_SET)
+ * are assumed to be set as needed, that extra user is processed in final handling. */
+ }
+ if (!is_indirect || is_obj_proxy) {
+ id_remap_data->status |= ID_REMAP_IS_LINKED_DIRECT;
+ }
+ /* We need to remap proxy_from pointer of remapped proxy... sigh. */
+ if (is_obj_proxy && new_id != NULL) {
+ Object *ob = (Object *)id_owner;
+ if (ob->proxy == (Object *)new_id) {
+ ob->proxy->proxy_from = ob;
+ }
+ }
+ }
+ }
+
+ return IDWALK_RET_NOP;
+ }
+
+ static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data)
+ {
+ switch (GS(r_id_remap_data->id_owner->name)) {
+ case ID_OB: {
+ ID *old_id = r_id_remap_data->old_id;
+ if (!old_id || GS(old_id->name) == ID_AR) {
+ Object *ob = (Object *)r_id_remap_data->id_owner;
+ /* Object's pose holds reference to armature bones... sic */
+ /* Note that in theory, we should have to bother about
+ * linked/non-linked/never-null/etc. flags/states.
+ * Fortunately, this is just a tag, so we can accept to 'over-tag' a bit for pose recalc,
+ * and avoid another complex and risky condition nightmare like the one we have in
+ * foreach_libblock_remap_callback()... */
+ if (ob->pose && (!old_id || ob->data == old_id)) {
+ BLI_assert(ob->type == OB_ARMATURE);
+ ob->pose->flag |= POSE_RECALC;
+ /*
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list