[Bf-blender-cvs] [4d8e034ab8e] asset-engine: Merge branch 'id_override_static' into asset-engine

Bastien Montagne noreply at git.blender.org
Fri Nov 10 10:59:33 CET 2017


Commit: 4d8e034ab8e3be35e1d8c277c2ffa5c235745ab8
Author: Bastien Montagne
Date:   Fri Nov 10 10:45:20 2017 +0100
Branches: asset-engine
https://developer.blender.org/rB4d8e034ab8e3be35e1d8c277c2ffa5c235745ab8

Merge branch 'id_override_static' into asset-engine

Conflicts:
	source/blender/blenloader/BLO_readfile.h
	source/blender/blenloader/intern/readfile.c
	source/blender/windowmanager/intern/wm_files_link.c

===================================================================



===================================================================

diff --cc source/blender/blenloader/BLO_readfile.h
index 2d160659dfb,676d3a7bcca..0bac52afc36
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@@ -126,14 -124,9 +126,15 @@@ struct ID *BLO_library_link_named_part(
  struct ID *BLO_library_link_named_part_ex(
          struct Main *mainl, BlendHandle **bh,
          const short idcode, const char *name, const short flag,
-         struct Scene *scene, struct SceneLayer *sl,
+         struct Scene *scene, struct SceneLayer *scene_layer,
          const bool use_placeholders, const bool force_indirect);
 -void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct SceneLayer *scene_layer);
 +struct ID *BLO_library_link_named_part_asset(
 +        struct Main *mainl, BlendHandle **bh, const struct AssetEngineType *aet, const char *root,
 +        const short idcode, const char *name, const struct AssetUUID *uuid, const short flag,
-         struct Scene *scene, struct SceneLayer *sl,
++        struct Scene *scene, struct SceneLayer *scene_layer,
 +        const bool use_placeholders, const bool force_indirect);
- void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct SceneLayer *sl);
++void BLO_library_link_end(
++        struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct SceneLayer *scene_layer);
  
  void BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh);
  
diff --cc source/blender/blenloader/intern/readfile.c
index 238740b5038,92690f1ed90..82fa166ae95
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -10442,10 -10402,8 +10440,10 @@@ void BLO_library_link_copypaste(Main *m
  }
  
  static ID *link_named_part_ex(
 -        Main *mainl, FileData *fd, const short idcode, const char *name, const short flag,
 -        Scene *scene, SceneLayer *scene_layer, const bool use_placeholders, const bool force_indirect)
 +        Main *mainl, FileData *fd, const AssetEngineType *aet, const char *root,
 +        const short idcode, const char *name, const AssetUUID *uuid, const short flag,
-         Scene *scene, SceneLayer *sl,
++        Scene *scene, SceneLayer *scene_layer,
 +        const bool use_placeholders, const bool force_indirect)
  {
  	ID *id = link_named_part(mainl, fd, idcode, name, use_placeholders, force_indirect);
  
@@@ -10512,33 -10456,7 +10510,34 @@@ ID *BLO_library_link_named_part_ex
          const bool use_placeholders, const bool force_indirect)
  {
  	FileData *fd = (FileData*)(*bh);
- 	return link_named_part_ex(mainl, fd, NULL, NULL, idcode, name, NULL, flag, scene, sl, use_placeholders, force_indirect);
 -	return link_named_part_ex(mainl, fd, idcode, name, flag, scene, scene_layer, use_placeholders, force_indirect);
++	return link_named_part_ex(
++	            mainl, fd, NULL, NULL, idcode, name, NULL, flag, scene, scene_layer, use_placeholders, force_indirect);
 +}
 +
 +/**
 + * Link a named datablock from an external blend file, using given asset engine & asset UUID.
 + * Optionally instantiate the object/group in the scene when the flags are set.
 + *
 + * \param mainl The main database to link from (not the active one).
 + * \param bh The blender file handle.
 + * \param aet The asset engine type (NULL when no asset engine is used).
 + * \param root the 'path' of the asset repository.
 + * \param idcode The kind of datablock to link.
 + * \param name The name of the datablock (without the 2 char ID prefix).
 + * \param uuid The asset engine's UUID of this datablock (NULL when no asset engine is used).
 + * \param flag Options for linking, used for instantiating.
 + * \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done).
 + * \param sl The active SceneLayer (where objects & groups would be instantiated, can be NULL).
 + * \return the linked ID when found.
 + */
 +struct ID *BLO_library_link_named_part_asset(
 +        Main *mainl, BlendHandle **bh, const AssetEngineType *aet, const char *root,
 +        const short idcode, const char *name, const AssetUUID *uuid, const short flag,
-         Scene *scene, SceneLayer *sl,
++        Scene *scene, SceneLayer *scene_layer,
 +        const bool use_placeholders, const bool force_indirect)
 +{
 +	FileData *fd = (FileData*)(*bh);
- 	return link_named_part_ex(mainl, fd, aet, root, idcode, name, uuid, flag, scene, sl, use_placeholders, force_indirect);
++	return link_named_part_ex(mainl, fd, aet, root, idcode, name, uuid, flag, scene, scene_layer, use_placeholders, force_indirect);
  }
  
  static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id)
diff --cc source/blender/windowmanager/intern/wm_files_link.c
index 5b0b0456d8d,ac3b0ef8fdf..4b9afa249be
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@@ -233,89 -213,9 +233,90 @@@ static WMLinkAppendDataItem *wm_link_ap
  	return item;
  }
  
 +static int path_to_idcode(const char *path)
 +{
 +	const int filetype = ED_path_extension_type(path);
 +	switch (filetype) {
 +		case FILE_TYPE_IMAGE:
 +		case FILE_TYPE_MOVIE:
 +			return ID_IM;
 +		case FILE_TYPE_FTFONT:
 +			return ID_VF;
 +		case FILE_TYPE_SOUND:
 +			return ID_SO;
 +		case FILE_TYPE_PYSCRIPT:
 +		case FILE_TYPE_TEXT:
 +			return ID_TXT;
 +		default:
 +			return 0;
 +	}
 +}
 +
 +static void wm_link_virtual_lib(
 +        WMLinkAppendData *lapp_data, Main *bmain, AssetEngineType *aet, const int lib_idx, const bool generate_overrides)
 +{
 +	LinkNode *itemlink;
 +	int item_idx;
 +
 +	BLI_assert(aet);
 +
 +	/* Find or add virtual library matching current asset engine. */
 +	Library *virtlib = BKE_library_asset_virtual_ensure(bmain, aet);
 +
 +	for (item_idx = 0, itemlink = lapp_data->items.list; itemlink; item_idx++, itemlink = itemlink->next) {
 +		WMLinkAppendDataItem *item = itemlink->link;
 +		ID *new_id = NULL;
 +		bool id_exists = false;
 +
 +		if (!BLI_BITMAP_TEST(item->libraries, lib_idx)) {
 +			continue;
 +		}
 +
 +		switch (item->idcode) {
 +			case ID_IM:
 +				new_id = (ID *)BKE_image_load_exists_ex(item->name, &id_exists);
 +				if (id_exists) {
 +					if (!new_id->uuid || !ASSETUUID_COMPARE(new_id->uuid, item->uuid)) {
 +						/* Fake 'same ID' (same path, but different uuid or whatever), force loading into new ID. */
 +						BLI_assert(new_id->lib != virtlib);
 +						new_id = (ID *)BKE_image_load(bmain, item->name);
 +						id_exists = false;
 +					}
 +				}
 +				break;
 +			default:
 +				break;
 +		}
 +
 +		if (new_id) {
 +			new_id->lib = virtlib;
 +			new_id->tag |= LIB_TAG_EXTERN | LIB_ASSET;
 +
 +			if (!id_exists) {
 +				new_id->uuid = MEM_mallocN(sizeof(*new_id->uuid), __func__);
 +				*new_id->uuid = *item->uuid;
 +			}
 +
 +			if (generate_overrides) {
 +				/* Create local override of virtually linked datablock, since we nearly always want to be able
 +				 * to edit pretty much everything about it. */
 +				new_id = BKE_override_create_from(bmain, new_id);
 +				/* TODO: will need to protect some fields on type-by-type case (path field). */
 +			}
 +
 +			/* If the link is sucessful, clear item's libs 'todo' flags.
 +			 * This avoids trying to link same item with other libraries to come. */
 +			BLI_BITMAP_SET_ALL(item->libraries, false, lapp_data->num_libraries);
 +			item->new_id = new_id;
 +		}
 +	}
 +	BKE_libraries_asset_repositories_rebuild(bmain);
 +}
 +
  static void wm_link_do(
-         WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, AssetEngineType *aet, Scene *scene, SceneLayer *sl,
 -        WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, SceneLayer *scene_layer,
 -        const bool use_placeholders, const bool force_indirect)
++        WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, AssetEngineType *aet,
++        Scene *scene, SceneLayer *scene_layer,
 +        const bool use_placeholders, const bool force_indirect, const bool generate_overrides)
  {
  	Main *mainl;
  	BlendHandle *bh;
@@@ -368,9 -262,8 +369,10 @@@
  				continue;
  			}
  
 -			new_id = BLO_library_link_named_part_ex(
 -			             mainl, &bh, item->idcode, item->name, flag, scene, scene_layer, use_placeholders, force_indirect);
 +			new_id = BLO_library_link_named_part_asset(
- 			             mainl, &bh, aet, lapp_data->root, item->idcode, item->name, item->uuid, flag, scene, sl,
++			             mainl, &bh, aet, lapp_data->root, item->idcode, item->name, item->uuid,
++			             flag, scene, scene_layer,
 +			             use_placeholders, force_indirect);
  
  			if (new_id) {
  				/* If the link is successful, clear item's libs 'todo' flags.
@@@ -617,7 -453,7 +619,7 @@@ static int wm_link_append_exec(bContex
  	/* XXX We'd need re-entrant locking on Main for this to work... */
  	/* BKE_main_lock(bmain); */
  
- 	wm_link_do(lapp_data, op->reports, bmain, aet, scene, sl, false, false, (flag & FILE_LINK) != 0);
 -	wm_link_do(lapp_data, op->reports, bmain, scene, scene_layer, false, false);
++	wm_link_do(lapp_data, op->reports, bmain, aet, scene, scene_layer, false, false, (flag & FILE_LINK) != 0);
  
  	/* BKE_main_unlock(bmain); */



More information about the Bf-blender-cvs mailing list