readfile: add id_tag_extra argument
This allows adding ID tags when linking/loading data. This is needed to implement loading non 'G.main' ID data-blocks, see D10612.
This commit is contained in:
@@ -94,8 +94,9 @@ bool BKE_copybuffer_read(Main *bmain_dst,
|
|||||||
}
|
}
|
||||||
/* Here appending/linking starts. */
|
/* Here appending/linking starts. */
|
||||||
const int flag = 0;
|
const int flag = 0;
|
||||||
|
const int id_tag_extra = 0;
|
||||||
struct LibraryLink_Params liblink_params;
|
struct LibraryLink_Params liblink_params;
|
||||||
BLO_library_link_params_init(&liblink_params, bmain_dst, flag);
|
BLO_library_link_params_init(&liblink_params, bmain_dst, flag, id_tag_extra);
|
||||||
Main *mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
Main *mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||||
BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
||||||
BLO_library_link_end(mainl, &bh, &liblink_params);
|
BLO_library_link_end(mainl, &bh, &liblink_params);
|
||||||
@@ -130,6 +131,7 @@ int BKE_copybuffer_paste(bContext *C,
|
|||||||
Main *mainl = NULL;
|
Main *mainl = NULL;
|
||||||
Library *lib;
|
Library *lib;
|
||||||
BlendHandle *bh;
|
BlendHandle *bh;
|
||||||
|
const int id_tag_extra = 0;
|
||||||
|
|
||||||
bh = BLO_blendhandle_from_file(libname, reports);
|
bh = BLO_blendhandle_from_file(libname, reports);
|
||||||
|
|
||||||
@@ -148,7 +150,8 @@ int BKE_copybuffer_paste(bContext *C,
|
|||||||
|
|
||||||
/* here appending/linking starts */
|
/* here appending/linking starts */
|
||||||
struct LibraryLink_Params liblink_params;
|
struct LibraryLink_Params liblink_params;
|
||||||
BLO_library_link_params_init_with_context(&liblink_params, bmain, flag, scene, view_layer, v3d);
|
BLO_library_link_params_init_with_context(
|
||||||
|
&liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
|
||||||
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||||
|
|
||||||
const int num_pasted = BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
const int num_pasted = BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ struct LibraryLink_Params {
|
|||||||
struct Main *bmain;
|
struct Main *bmain;
|
||||||
/** Options for linking, used for instantiating. */
|
/** Options for linking, used for instantiating. */
|
||||||
int flag;
|
int flag;
|
||||||
|
/** Additional tag for #ID.tag. */
|
||||||
|
int id_tag_extra;
|
||||||
/** Context for instancing objects (optional, no instantiation will be performed when NULL). */
|
/** Context for instancing objects (optional, no instantiation will be performed when NULL). */
|
||||||
struct {
|
struct {
|
||||||
/** The scene in which to instantiate objects/collections. */
|
/** The scene in which to instantiate objects/collections. */
|
||||||
@@ -195,10 +197,12 @@ struct LibraryLink_Params {
|
|||||||
|
|
||||||
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
||||||
struct Main *bmain,
|
struct Main *bmain,
|
||||||
const int flag);
|
const int flag,
|
||||||
|
const int id_tag_extra);
|
||||||
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
||||||
struct Main *bmain,
|
struct Main *bmain,
|
||||||
const int flag,
|
const int flag,
|
||||||
|
const int id_tag_extra,
|
||||||
struct Scene *scene,
|
struct Scene *scene,
|
||||||
struct ViewLayer *view_layer,
|
struct ViewLayer *view_layer,
|
||||||
const struct View3D *v3d);
|
const struct View3D *v3d);
|
||||||
|
|||||||
@@ -4411,7 +4411,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
|
|||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
/* ID has not been read yet, add placeholder to the main of the
|
/* ID has not been read yet, add placeholder to the main of the
|
||||||
* library it belongs to, so that it will be read later. */
|
* library it belongs to, so that it will be read later. */
|
||||||
read_libblock(fd, libmain, bhead, LIB_TAG_INDIRECT, false, NULL);
|
read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, NULL);
|
||||||
/* commented because this can print way too much */
|
/* commented because this can print way too much */
|
||||||
// if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->filepath);
|
// if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->filepath);
|
||||||
|
|
||||||
@@ -4466,7 +4466,12 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
|
|||||||
|
|
||||||
ID *id = is_yet_read(fd, mainvar, bhead);
|
ID *id = is_yet_read(fd, mainvar, bhead);
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
read_libblock(fd, mainvar, bhead, LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT, false, NULL);
|
read_libblock(fd,
|
||||||
|
mainvar,
|
||||||
|
bhead,
|
||||||
|
fd->id_tag_extra | LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT,
|
||||||
|
false,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Convert any previously read weak link to regular link
|
/* Convert any previously read weak link to regular link
|
||||||
@@ -4847,7 +4852,7 @@ static ID *link_named_part(
|
|||||||
id = is_yet_read(fd, mainl, bhead);
|
id = is_yet_read(fd, mainl, bhead);
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
/* not read yet */
|
/* not read yet */
|
||||||
const int tag = force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN;
|
const int tag = ((force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN) | fd->id_tag_extra);
|
||||||
read_libblock(fd, mainl, bhead, tag | LIB_TAG_NEED_EXPAND, false, &id);
|
read_libblock(fd, mainl, bhead, tag | LIB_TAG_NEED_EXPAND, false, &id);
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
@@ -4988,10 +4993,13 @@ static void library_link_clear_tag(Main *mainvar, const int flag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Main *library_link_begin(Main *mainvar, FileData **fd, const char *filepath, const int flag)
|
static Main *library_link_begin(
|
||||||
|
Main *mainvar, FileData **fd, const char *filepath, const int flag, const int id_tag_extra)
|
||||||
{
|
{
|
||||||
Main *mainl;
|
Main *mainl;
|
||||||
|
|
||||||
|
(*fd)->id_tag_extra = id_tag_extra;
|
||||||
|
|
||||||
(*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist");
|
(*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist");
|
||||||
|
|
||||||
if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) {
|
if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) {
|
||||||
@@ -5017,22 +5025,25 @@ static Main *library_link_begin(Main *mainvar, FileData **fd, const char *filepa
|
|||||||
|
|
||||||
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
||||||
struct Main *bmain,
|
struct Main *bmain,
|
||||||
const int flag)
|
const int flag,
|
||||||
|
const int id_tag_extra)
|
||||||
{
|
{
|
||||||
memset(params, 0, sizeof(*params));
|
memset(params, 0, sizeof(*params));
|
||||||
params->bmain = bmain;
|
params->bmain = bmain;
|
||||||
params->flag = flag;
|
params->flag = flag;
|
||||||
|
params->id_tag_extra = id_tag_extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
||||||
struct Main *bmain,
|
struct Main *bmain,
|
||||||
const int flag,
|
const int flag,
|
||||||
|
const int id_tag_extra,
|
||||||
/* Context arguments. */
|
/* Context arguments. */
|
||||||
struct Scene *scene,
|
struct Scene *scene,
|
||||||
struct ViewLayer *view_layer,
|
struct ViewLayer *view_layer,
|
||||||
const struct View3D *v3d)
|
const struct View3D *v3d)
|
||||||
{
|
{
|
||||||
BLO_library_link_params_init(params, bmain, flag);
|
BLO_library_link_params_init(params, bmain, flag, id_tag_extra);
|
||||||
if (scene != NULL) {
|
if (scene != NULL) {
|
||||||
/* Tagging is needed for instancing. */
|
/* Tagging is needed for instancing. */
|
||||||
params->flag |= BLO_LIBLINK_NEEDS_ID_TAG_DOIT;
|
params->flag |= BLO_LIBLINK_NEEDS_ID_TAG_DOIT;
|
||||||
@@ -5057,7 +5068,7 @@ Main *BLO_library_link_begin(BlendHandle **bh,
|
|||||||
const struct LibraryLink_Params *params)
|
const struct LibraryLink_Params *params)
|
||||||
{
|
{
|
||||||
FileData *fd = (FileData *)(*bh);
|
FileData *fd = (FileData *)(*bh);
|
||||||
return library_link_begin(params->bmain, &fd, filepath, params->flag);
|
return library_link_begin(params->bmain, &fd, filepath, params->flag, params->id_tag_extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void split_main_newid(Main *mainptr, Main *main_newid)
|
static void split_main_newid(Main *mainptr, Main *main_newid)
|
||||||
|
|||||||
@@ -120,6 +120,14 @@ typedef struct FileData {
|
|||||||
/** Optionally skip some data-blocks when they're not needed. */
|
/** Optionally skip some data-blocks when they're not needed. */
|
||||||
eBLOReadSkip skip_flags;
|
eBLOReadSkip skip_flags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag to apply to all loaded ID data-blocks.
|
||||||
|
*
|
||||||
|
* \note This is initialized from #LibraryLink_Params.id_tag_extra since passing it as an
|
||||||
|
* argument would need an additional argument to be passed around when expanding library data.
|
||||||
|
*/
|
||||||
|
int id_tag_extra;
|
||||||
|
|
||||||
struct OldNewMap *datamap;
|
struct OldNewMap *datamap;
|
||||||
struct OldNewMap *globmap;
|
struct OldNewMap *globmap;
|
||||||
struct OldNewMap *libmap;
|
struct OldNewMap *libmap;
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
|||||||
|
|
||||||
/* here appending/linking starts */
|
/* here appending/linking starts */
|
||||||
struct LibraryLink_Params liblink_params;
|
struct LibraryLink_Params liblink_params;
|
||||||
BLO_library_link_params_init(&liblink_params, bmain, self->flag);
|
BLO_library_link_params_init(&liblink_params, bmain, self->flag, 0);
|
||||||
|
|
||||||
mainl = BLO_library_link_begin(&(self->blo_handle), self->relpath, &liblink_params);
|
mainl = BLO_library_link_begin(&(self->blo_handle), self->relpath, &liblink_params);
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,7 @@ static void wm_link_do(WMLinkAppendData *lapp_data,
|
|||||||
Library *lib;
|
Library *lib;
|
||||||
|
|
||||||
const int flag = lapp_data->flag;
|
const int flag = lapp_data->flag;
|
||||||
|
const int id_tag_extra = 0;
|
||||||
|
|
||||||
LinkNode *liblink, *itemlink;
|
LinkNode *liblink, *itemlink;
|
||||||
int lib_idx, item_idx;
|
int lib_idx, item_idx;
|
||||||
@@ -255,7 +256,7 @@ static void wm_link_do(WMLinkAppendData *lapp_data,
|
|||||||
/* here appending/linking starts */
|
/* here appending/linking starts */
|
||||||
struct LibraryLink_Params liblink_params;
|
struct LibraryLink_Params liblink_params;
|
||||||
BLO_library_link_params_init_with_context(
|
BLO_library_link_params_init_with_context(
|
||||||
&liblink_params, bmain, flag, scene, view_layer, v3d);
|
&liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
|
||||||
|
|
||||||
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||||
lib = mainl->curlib;
|
lib = mainl->curlib;
|
||||||
|
|||||||
Reference in New Issue
Block a user