[Bf-blender-cvs] [ffb581e7f4e] asset-engine: AssetUUID: add basic search for Asset UUIDs in current .blend file.
Bastien Montagne
noreply at git.blender.org
Wed Nov 6 17:09:01 CET 2019
Commit: ffb581e7f4e3ecede1c6928a431cd35776a08228
Author: Bastien Montagne
Date: Wed Nov 6 16:52:27 2019 +0100
Branches: asset-engine
https://developer.blender.org/rBffb581e7f4e3ecede1c6928a431cd35776a08228
AssetUUID: add basic search for Asset UUIDs in current .blend file.
Needed for Cosmos pipeline R&D.
===================================================================
M release/scripts/modules/bpy_types.py
M source/blender/blenkernel/BKE_asset_engine.h
M source/blender/blenkernel/intern/asset_engine.c
M source/blender/python/intern/bpy_rna_id_collection.c
===================================================================
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index af37e5bb8a7..52a6fdfd5d1 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -29,6 +29,7 @@ bpy_types.BlendDataLibraries.load = _bpy._library_load
bpy_types.BlendDataLibraries.write = _bpy._library_write
bpy_types.BlendData.user_map = _bpy._rna_id_collection_user_map
bpy_types.BlendData.batch_remove = _bpy._rna_id_collection_batch_remove
+bpy_types.BlendData.asset_uuid_search = _bpy._rna_id_collection_asset_uuid_search
class Context(StructRNA):
diff --git a/source/blender/blenkernel/BKE_asset_engine.h b/source/blender/blenkernel/BKE_asset_engine.h
index 4738d3225af..d2a936c95f2 100644
--- a/source/blender/blenkernel/BKE_asset_engine.h
+++ b/source/blender/blenkernel/BKE_asset_engine.h
@@ -81,20 +81,22 @@ typedef void (*ae_kill)(struct AssetEngine *engine, const int job_id);
/* ***** All callbacks below shall be non-blocking (i.e. return immediately). ***** */
/**************************************************************************************/
-/* Those callbacks will be called from a 'fake-job' start *and* update functions (i.e. main thread, working one will
- * just sleep).
+/* Those callbacks will be called from a 'fake-job' start *and* update functions (i.e. main thread,
+ * working one will just sleep).
*
- * If given id is not AE_JOB_ID_UNSET, engine should update from a running job if available, otherwise it should
- * start a new one.
- * It is the responsability of the engine to start/stop background processes to actually perform tasks as/if needed.
+ * If given id is not AE_JOB_ID_UNSET, engine should update from a running job if available,
+ * otherwise it should start a new one. It is the responsability of the engine to start/stop
+ * background processes to actually perform tasks as/if needed.
*
- * If the engine returns AE_JOB_ID_INVALID as job id, then code assumes whole execution was done in that single first
- * call (i.e. allows engine that do not need it to not bother with whole async crap - they should then process
- * the whole request in a very short amount of time (typically below 100ms).
+ * If the engine returns AE_JOB_ID_INVALID as job id, then code assumes whole execution was done in
+ * that single first call (i.e. allows engine that do not need it to not bother with whole async
+ * crap - they should then process the whole request in a very short amount of time (typically
+ * below 100ms).
*
- * Most of those callbacks shall not return actual entries, but only (mainly) total number of available entries.
- * The only callback returning actual entries should be ae_entries_block_get() (which returns a limited subset
- * of all available ones, the visible ones usually), and ae_entries_uuid_get().
+ * Most of those callbacks shall not return actual entries, but only (mainly) total number of
+ * available entries. The only callback returning actual entries should be ae_entries_block_get()
+ * (which returns a limited subset of all available ones, the visible ones usually), and
+ * ae_entries_uuid_get().
*/
#define AE_JOB_ID_UNSET 0
#define AE_JOB_ID_INVALID -1
@@ -106,8 +108,9 @@ typedef int (*ae_list_dir)(struct AssetEngine *engine,
struct FileDirEntryArr *entries_r);
/* FILEBROWSER - Get previews of given entries.
- * XXX WARNING! Currently, only asset part of uuids is valid here (because fileentries only store this one)...
- * Think this makes more sense anyway, or do we want different previews per variants or revisions too? */
+ * XXX WARNING! Currently, only asset part of uuids is valid here (because fileentries only store
+ * this one)... Think this makes more sense anyway, or do we want different previews per variants
+ * or revisions too? */
typedef int (*ae_previews_get)(struct AssetEngine *engine,
const int job_id,
struct AssetUUIDList *uuids);
@@ -123,9 +126,9 @@ typedef int (*ae_update_check)(struct AssetEngine *engine,
const int job_id,
struct AssetUUIDList *uuids);
-/* Ensure given assets (uuids) are really available for append/link (some kind of 'anticipated loading'...).
- * Note: Engine should expect any kind of UUIDs it produced here
- * (i.e. real ones as well as 'virtual' filebrowsing ones). */
+/* Ensure given assets (uuids) are really available for append/link (some kind of 'anticipated
+ * loading'...). Note: Engine should expect any kind of UUIDs it produced here (i.e. real ones as
+ * well as 'virtual' filebrowsing ones). */
typedef int (*ae_ensure_uuids)(struct AssetEngine *engine,
const int job_id,
struct AssetUUIDList *uuids);
@@ -156,12 +159,13 @@ typedef bool (*ae_entries_uuid_get)(struct AssetEngine *engine,
struct FileDirEntryArr *entries_r);
/* 'pre-loading' hook, called before opening/appending/linking/updating given entries.
- * Note first given uuid is the one of 'active' entry, and first entry in returned list will be considered as such too.
- * E.g. allows the engine to ensure entries' paths are actually valid by downloading requested data, etc.
- * If is_virtual is True, then there is no requirement that returned paths actually exist.
- * Note that the generated list shall be simpler than the one generated by ae_list_dir, since only the path from
- * active revision is used, no need to bother with variants, previews, etc.
- * This allows to present 'fake' entries to user, and then import actual data.
+ * Note first given uuid is the one of 'active' entry, and first entry in returned list will be
+ * considered as such too. E.g. allows the engine to ensure entries' paths are actually valid by
+ * downloading requested data, etc. If is_virtual is True, then there is no requirement that
+ * returned paths actually exist. Note that the generated list shall be simpler than the one
+ * generated by ae_list_dir, since only the path from active revision is used, no need to bother
+ * with variants, previews, etc. This allows to present 'fake' entries to user, and then import
+ * actual data.
*/
typedef bool (*ae_load_pre)(struct AssetEngine *engine,
struct AssetUUIDList *uuids,
@@ -174,9 +178,8 @@ typedef bool (*ae_load_post)(struct bContext *C,
struct AssetEngine *engine,
struct AssetUUIDList *uuids);
-/* Check if given dirpath is valid for current asset engine, it can also modify it if do_change is true.
- * r_dir is assumed to be least FILE_MAX.
- * returns true if path in r_dir is valid. */
+/* Check if given dirpath is valid for current asset engine, it can also modify it if do_change is
+ * true. r_dir is assumed to be least FILE_MAX. returns true if path in r_dir is valid. */
typedef bool (*ae_check_dir)(struct AssetEngine *engine, char *r_dir, bool do_change);
typedef struct AssetEngineType {
@@ -287,6 +290,11 @@ unsigned int BKE_asset_uuid_hash(const void *key);
bool BKE_asset_uuid_cmp(const void *a, const void *b);
void BKE_asset_uuid_print(const struct AssetUUID *uuid);
+void BKE_asset_uuid_list_free(struct AssetUUIDList *uuid_list);
+
+void BKE_asset_main_search(struct Main *bmain, struct AssetUUID *uuid);
+struct AssetUUIDList *BKE_asset_main_list(struct Main *bmain);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/asset_engine.c b/source/blender/blenkernel/intern/asset_engine.c
index 4ac44324b6d..82e85f9e137 100644
--- a/source/blender/blenkernel/intern/asset_engine.c
+++ b/source/blender/blenkernel/intern/asset_engine.c
@@ -503,3 +503,64 @@ void BKE_asset_uuid_print(const AssetUUID *uuid)
uuid->uuid_view[2],
uuid->uuid_view[3]);
}
+
+void BKE_asset_uuid_list_free(struct AssetUUIDList *uuid_list)
+{
+ MEM_SAFE_FREE(uuid_list->uuids);
+ MEM_freeN(uuid_list);
+}
+
+/** Search the whole Main for a given asset uuid.
+ *
+ * \note if found, ID is put into uuid->id pointer. */
+void BKE_asset_main_search(Main *bmain, AssetUUID *uuid)
+{
+ uuid->id = NULL;
+
+ ID *id;
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ if (id->uuid == NULL) {
+ continue;
+ }
+ if (ASSETUUID_EQUAL(id->uuid, uuid)) {
+ uuid->id = id;
+ return;
+ }
+ }
+ FOREACH_MAIN_ID_END;
+}
+
+/** Get a list of all IDs/assets and their uuids present in current bmain
+ * (includes local ones and linked ones).
+ * Returned uuid list should be freed with \a BKE_asset_uuid_list_free. */
+struct AssetUUIDList *BKE_asset_main_list(struct Main *bmain)
+{
+ ID *id;
+ AssetUUIDList *uuid_list = MEM_callocN(sizeof(*uuid_list), __func__);
+
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ if (id->uuid != NULL) {
+ uuid_list->nbr_uuids++;
+ }
+ }
+ FOREACH_MAIN_ID_END;
+
+ if (uuid_list->nbr_uuids == 0) {
+ return uuid_list;
+ }
+
+ uuid_list->uuids = MEM_mallocN(sizeof(*uuid_list->uuids) * (size_t)uuid_list->nbr_uuids,
+ __func__);
+ int uuid_index = 0;
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ if (id->uuid != NULL) {
+ uuid_list->uuids[uuid_index] = *id->uuid;
+ uuid_list->uuids[uuid_index].id = id;
+ uuid_index++;
+ }
+ }
+ FOREACH_MAIN_ID_END;
+ BLI_assert(uuid_index == uuid_list->nbr_uuids);
+
+ return uuid_list;
+}
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 6ff1849f646..a30fa30cc49 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -28,6 +28,11 @@
#include "BLI_utildefines.h"
#include "BLI_bitmap.h"
+#include "RNA_access.h"
+#include "RNA_types.h"
+#include "RNA_enum_types.h"
+
+#include "BKE_asset_engine.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -48,10 +53,6 @@
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
-#include "RNA_access.h"
-#include "RNA_types.h"
-#include "RNA_enum_types.h"
-
#incl
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list