[Bf-blender-cvs] [9f290467ca3] master: Blendread: Remove all instantiation logic from `BLO_library_link_` code.
Bastien Montagne
noreply at git.blender.org
Thu Dec 2 11:14:19 CET 2021
Commit: 9f290467ca3a8517b13d81031099744d86f3ae21
Author: Bastien Montagne
Date: Tue Nov 30 17:52:58 2021 +0100
Branches: master
https://developer.blender.org/rB9f290467ca3a8517b13d81031099744d86f3ae21
Blendread: Remove all instantiation logic from `BLO_library_link_` code.
Instantiation is now fully handled by BKE_blendfile_link_append module.
Note that this also allows removal of the `BLO_LIBLINK_NEEDS_ID_TAG_DOIT`
flag.
Part of T91414: Unify link/append between WM operators and BPY context
manager API, and cleanup usages of `BKE_library_make_local`.
===================================================================
M source/blender/blenkernel/intern/blendfile_link_append.c
M source/blender/blenloader/BLO_readfile.h
M source/blender/blenloader/intern/readfile.c
===================================================================
diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c b/source/blender/blenkernel/intern/blendfile_link_append.c
index 8c6213d8957..7c06613f437 100644
--- a/source/blender/blenkernel/intern/blendfile_link_append.c
+++ b/source/blender/blenkernel/intern/blendfile_link_append.c
@@ -1324,12 +1324,6 @@ void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *re
/* here appending/linking starts */
- /* NOTE: This is temporary hot-fix until whole code using link/append features has been moved
- * to use new BKE code. */
- /* Do not handle instantiation in linking process anymore, we do it here in
- * #loose_data_instantiate instead. */
- lapp_context->params->flag &= ~BLO_LIBLINK_NEEDS_ID_TAG_DOIT;
-
mainl = BLO_library_link_begin(&blo_handle, libname, lapp_context->params);
lib = mainl->curlib;
BLI_assert(lib);
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 7d6d471adc3..70006bb6d23 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -212,14 +212,6 @@ typedef enum eBLOLibLinkFlags {
BLO_LIBLINK_USE_PLACEHOLDERS = 1 << 16,
/** Force loaded ID to be tagged as #LIB_TAG_INDIRECT (used in reload context only). */
BLO_LIBLINK_FORCE_INDIRECT = 1 << 17,
- /**
- * When set, tag ID types that pass the internal check #library_link_idcode_needs_tag_check
- *
- * Currently this is only used to instantiate objects in the scene.
- * Set this from #BLO_library_link_params_init_with_context so callers
- * don't need to remember to set this flag.
- */
- BLO_LIBLINK_NEEDS_ID_TAG_DOIT = 1 << 18,
/** Set fake user on appended IDs. */
BLO_LIBLINK_APPEND_SET_FAKEUSER = 1 << 19,
/** Append (make local) also indirect dependencies of appended IDs coming from other libraries.
@@ -335,14 +327,6 @@ void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef);
struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath);
-void BLO_object_instantiate_object_base_instance_init(struct Main *bmain,
- struct Collection *collection,
- struct Object *ob,
- struct ViewLayer *view_layer,
- const struct View3D *v3d,
- const int flag,
- bool set_active);
-
/* datafiles (generated theme) */
extern const struct bTheme U_theme_default;
extern const struct UserDef U_default;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 1d1127329e1..3ed32b196eb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -195,7 +195,6 @@ static void read_libraries(FileData *basefd, ListBase *mainlist);
static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name);
static BHead *find_bhead_from_idname(FileData *fd, const char *idname);
-static bool library_link_idcode_needs_tag_check(const short idcode, const int flag);
typedef struct BHeadN {
struct BHeadN *next, *prev;
@@ -4441,290 +4440,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
/** \name Library Linking (helper functions)
* \{ */
-static bool object_in_any_scene(Main *bmain, Object *ob)
-{
- LISTBASE_FOREACH (Scene *, sce, &bmain->scenes) {
- if (BKE_scene_object_find(sce, ob)) {
- return true;
- }
- }
-
- return false;
-}
-
-static bool object_in_any_collection(Main *bmain, Object *ob)
-{
- LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
- if (BKE_collection_has_object(collection, ob)) {
- return true;
- }
- }
-
- LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
- if (scene->master_collection != NULL &&
- BKE_collection_has_object(scene->master_collection, ob)) {
- return true;
- }
- }
-
- return false;
-}
-
-/**
- * Shared operations to perform on the object's base after adding it to the scene.
- */
-static void object_base_instance_init(
- Object *ob, ViewLayer *view_layer, const View3D *v3d, const int flag, bool set_active)
-{
- Base *base = BKE_view_layer_base_find(view_layer, ob);
-
- if (v3d != NULL) {
- base->local_view_bits |= v3d->local_view_uuid;
- }
-
- if (flag & FILE_AUTOSELECT) {
- /* All objects that use #FILE_AUTOSELECT must be selectable (unless linking data). */
- BLI_assert((base->flag & BASE_SELECTABLE) || (flag & FILE_LINK));
- if (base->flag & BASE_SELECTABLE) {
- base->flag |= BASE_SELECTED;
- }
- }
-
- if (set_active) {
- view_layer->basact = base;
- }
-
- BKE_scene_object_base_flag_sync_from_base(base);
-}
-
-/**
- * Exported for link/append to create objects as well.
- */
-void BLO_object_instantiate_object_base_instance_init(Main *bmain,
- Collection *collection,
- Object *ob,
- ViewLayer *view_layer,
- const View3D *v3d,
- const int flag,
- bool set_active)
-{
- /* Auto-select and appending. */
- if ((flag & FILE_AUTOSELECT) && ((flag & FILE_LINK) == 0)) {
- /* While in general the object should not be manipulated,
- * when the user requests the object to be selected, ensure it's visible and selectable. */
- ob->visibility_flag &= ~(OB_HIDE_VIEWPORT | OB_HIDE_SELECT);
- }
-
- BKE_collection_object_add(bmain, collection, ob);
-
- object_base_instance_init(ob, view_layer, v3d, flag, set_active);
-}
-
-static void add_loose_objects_to_scene(Main *mainvar,
- Main *bmain,
- Scene *scene,
- ViewLayer *view_layer,
- const View3D *v3d,
- Library *lib,
- const int flag)
-{
- Collection *active_collection = NULL;
- const bool do_append = (flag & FILE_LINK) == 0;
-
- BLI_assert(scene);
-
- /* Give all objects which are LIB_TAG_INDIRECT a base,
- * or for a collection when *lib has been set. */
- LISTBASE_FOREACH (Object *, ob, &mainvar->objects) {
- /* NOTE: Even if this is a directly linked object and is tagged for instantiation, it might
- * have already been instantiated through one of its owner collections, in which case we do not
- * want to re-instantiate it in the active collection here. */
- bool do_it = (ob->id.tag & LIB_TAG_DOIT) != 0 && !BKE_scene_object_find(scene, ob);
- if (do_it ||
- ((ob->id.tag & LIB_TAG_INDIRECT) != 0 && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0)) {
- if (do_append) {
- if (ob->id.us == 0) {
- do_it = true;
- }
- else if ((ob->id.lib == lib) && !object_in_any_collection(bmain, ob)) {
- /* When appending, make sure any indirectly loaded object gets a base,
- * when they are not part of any collection yet. */
- do_it = true;
- }
- }
-
- if (do_it) {
- /* Find or add collection as needed. */
- if (active_collection == NULL) {
- if (flag & FILE_ACTIVE_COLLECTION) {
- LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
- active_collection = lc->collection;
- }
- else {
- active_collection = BKE_collection_add(bmain, scene->master_collection, NULL);
- }
- }
-
- CLAMP_MIN(ob->id.us, 0);
- ob->mode = OB_MODE_OBJECT;
-
- /* Do NOT make base active here! screws up GUI stuff,
- * if you want it do it at the editor level. */
- const bool set_active = false;
- BLO_object_instantiate_object_base_instance_init(
- bmain, active_collection, ob, view_layer, v3d, flag, set_active);
-
- ob->id.tag &= ~LIB_TAG_INDIRECT;
- ob->id.flag &= ~LIB_INDIRECT_WEAK_LINK;
- ob->id.tag |= LIB_TAG_EXTERN;
- }
- }
- }
-}
-
-static void add_loose_object_data_to_scene(Main *mainvar,
- Main *bmain,
- Scene *scene,
- ViewLayer *view_layer,
- const View3D *v3d,
- const int flag)
-{
- if ((flag & BLO_LIBLINK_OBDATA_INSTANCE) == 0) {
- return;
- }
-
- Collection *active_collection = scene->master_collection;
- if (flag & FILE_ACTIVE_COLLECTION) {
- LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
- active_collection = lc->collection;
- }
-
- /* Do not re-instantiate obdata IDs that are already instantiated by an object. */
- LISTBASE_FOREACH (Object *, ob, &mainvar->objects) {
- if ((ob->id.tag & LIB_TAG_PRE_EXISTING) == 0 && ob->data != NULL) {
- ID *obdata = ob->data;
- BLI_assert(ID_REAL_USERS(obdata) > 0);
- if ((obdata->tag & LIB_TAG_PRE_EXISTING) == 0) {
- obdata->tag &= ~LIB_TAG_DOIT;
- }
- }
- }
-
- /* Loop over all ID types, instancing object-data for ID types that have support for it. */
- ListBase *lbarray[INDEX_ID_MAX];
- int i = set_listbasepointers(mainvar, lbarray);
- while (i--) {
- const short idcode = BKE_idtype_idcode_from_index(i);
- if (!OB_DATA_SUPPORT_ID(idcode)) {
- continue;
- }
-
- LISTBASE_FOREACH (ID *, id, lbarray[i]) {
- if (id->tag & LIB_TAG_DOIT) {
- const int type = BKE_object_obdata_to_type(id);
- BLI_assert(type != -1);
- Object *ob = BKE_object_add_only_object(bmain, type, id->name + 2);
- ob->data = id;
- id_us_plus(id);
- BKE_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list