Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-12-11 20:15:25 +0300
committerJulian Eisel <julian@blender.org>2020-12-15 19:03:00 +0300
commitb71eb3a105b8f7fb216a48082386215a6ea81cc4 (patch)
treebb23ee7e71f10dd2ed10d71f27f2c1beeb571afc /source/blender/blenloader/intern/readfile.c
parent82645ff739687e4d58715869778c8860e832513c (diff)
Asset System: Data-block asset metadata storage, reading and API
Asset metadata is what turns a regular data-block into an asset. It is a small data-structure, but a key part of the technical design of the asset system. The design foresees that asset data-blocks store an `ID.asset_data` pointer of type `AssetMetaData`. This data **must not** have dependencies on other data-blocks or data-block data, it must be an independent unit. That way we can read asset-metadata from .blends without reading anything else from the file. The Asset Browser will use this metadata (together with the data-block name, preview and file path) to represent assets in the file list. Includes: * New `ID.asset_data` for asset metadata. * Asset tags, description and custom properties. * BKE code to manage asset meta-data and asset tags. * Code to read asset data from files, without reading IDs. * RNA for asset metadata (including tags) Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1 project milestone on developer.blender.org. Differential Revision: https://developer.blender.org/D9716 Reviewed by: Bastien Montagne, Brecht Van Lommel
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fd10eac4302..8dff1aa1ed0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -44,6 +44,7 @@
#define DNA_DEPRECATED_ALLOW
#include "DNA_anim_types.h"
+#include "DNA_asset_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_collection_types.h"
#include "DNA_fileglobal_types.h"
@@ -73,6 +74,7 @@
#include "BKE_anim_data.h"
#include "BKE_animsys.h"
+#include "BKE_asset.h"
#include "BKE_collection.h"
#include "BKE_global.h" /* for G */
#include "BKE_idprop.h"
@@ -957,12 +959,21 @@ static BHead *blo_bhead_read_full(FileData *fd, BHead *thisblock)
}
#endif /* USE_BHEAD_READ_ON_DEMAND */
-/* Warning! Caller's responsibility to ensure given bhead **is** and ID one! */
+/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */
const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead)
{
return (const char *)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_name_offs);
}
+/* Warning! Caller's responsibility to ensure given bhead **is** an ID one! */
+AssetMetaData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead)
+{
+ BLI_assert(BKE_idtype_idcode_is_valid(bhead->code));
+ return (fd->id_asset_data_offs >= 0) ?
+ *(AssetMetaData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offs) :
+ NULL;
+}
+
static void decode_blender_header(FileData *fd)
{
char header[SIZEOFBLENDERHEADER], num[4];
@@ -1040,6 +1051,8 @@ static bool read_file_dna(FileData *fd, const char **r_error_message)
/* used to retrieve ID names from (bhead+1) */
fd->id_name_offs = DNA_elem_offset(fd->filesdna, "ID", "char", "name[]");
BLI_assert(fd->id_name_offs != -1);
+ fd->id_asset_data_offs = DNA_elem_offset(
+ fd->filesdna, "ID", "AssetMetaData", "*asset_data");
return true;
}
@@ -2360,6 +2373,11 @@ static void direct_link_id_common(
return;
}
+ if (id->asset_data) {
+ BLO_read_data_address(reader, &id->asset_data);
+ BKE_asset_metadata_read(reader, id->asset_data);
+ }
+
/*link direct data of ID properties*/
if (id->properties) {
BLO_read_data_address(reader, &id->properties);
@@ -3608,6 +3626,27 @@ static BHead *read_libblock(FileData *fd,
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Read Asset Data
+ * \{ */
+
+BHead *blo_read_asset_data_block(FileData *fd, BHead *bhead, AssetMetaData **r_asset_data)
+{
+ BLI_assert(BKE_idtype_idcode_is_valid(bhead->code));
+
+ bhead = read_data_into_datamap(fd, bhead, "asset-data read");
+
+ BlendDataReader reader = {fd};
+ BLO_read_data_address(&reader, r_asset_data);
+ BKE_asset_metadata_read(&reader, *r_asset_data);
+
+ oldnewmap_clear(fd->datamap);
+
+ return bhead;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Read Global Data
* \{ */