[Bf-blender-cvs] [5c38de41055] asset-browser: Support reading all asset meta-data from external repositories

Julian Eisel noreply at git.blender.org
Mon Nov 23 16:35:36 CET 2020


Commit: 5c38de41055014d8270847487a65862f49757bcb
Author: Julian Eisel
Date:   Mon Nov 23 16:26:39 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB5c38de41055014d8270847487a65862f49757bcb

Support reading all asset meta-data from external repositories

When displaying a repository that is not the "Current File" one, we can now
show all the meta-data of its assets in the UI. Editing is currently possible,
but changes will be lost on reload of the repository. Editing should simply not
be disabled for now.

Note that this also works for custom properties. So assets can store custom
properties, and the Asset Browser can show them, even if they are stored in an
external repository.
One important thing is that custom asset properties must not store pointers to
other data-blocks, but the BPY should forbid this already for assets.

Addresses T82860.

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

M	source/blender/blenkernel/intern/asset.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/editors/space_file/filelist.c
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index aa28651399c..1780439bbfd 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -190,4 +190,5 @@ void BKE_assetdata_read(BlendDataReader *reader, AssetData *asset_data)
 
   BLO_read_data_address(reader, &asset_data->description);
   BLO_read_list(reader, &asset_data->tags);
+  asset_data->preview = NULL;
 }
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 35133854a0e..c60b6677a8c 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -124,7 +124,7 @@ void BLO_blendfiledata_free(BlendFileData *bfd);
 
 struct BLODataBlockInfo {
   char name[64]; /* MAX_NAME */
-  bool is_asset;
+  struct AssetData *asset_data;
 };
 
 BlendHandle *BLO_blendhandle_from_file(const char *filepath, struct ReportList *reports);
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 011d509f9eb..33f59987176 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -184,7 +184,15 @@ LinkNode *BLO_blendhandle_get_datablock_info(BlendHandle *bh, int ofblocktype, i
       const char *name = blo_bhead_id_name(fd, bhead) + 2;
 
       STRNCPY(info->name, name);
-      info->is_asset = blo_bhead_id_asset_data(fd, bhead) != NULL;
+
+      /* Lastly, read asset data from the following blocks. */
+      info->asset_data = blo_bhead_id_asset_data_address(fd, bhead);
+      if (info->asset_data) {
+        bhead = blo_read_asset_data_block(fd, bhead, &info->asset_data);
+        /* blo_read_asset_data_block() reads all DATA heads and already advances bhead to the next
+         * non-DATA one. Go back, so the loop doesn't skip the non-DATA head. */
+        bhead = blo_bhead_prev(fd, bhead);
+      }
 
       BLI_linklist_prepend(&infos, info);
       tot++;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 08779463b69..039b9cb9e90 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -968,8 +968,9 @@ const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead)
 }
 
 /* Warning! Caller's responsibility to ensure given bhead **is** and ID one! */
-AssetData *blo_bhead_id_asset_data(const FileData *fd, const BHead *bhead)
+AssetData *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) ?
              *(AssetData **)POINTER_OFFSET(bhead, sizeof(*bhead) + fd->id_asset_data_offs) :
              NULL;
@@ -3627,6 +3628,27 @@ static BHead *read_libblock(FileData *fd,
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Read Asset Data
+ * \{ */
+
+BHead *blo_read_asset_data_block(FileData *fd, BHead *bhead, AssetData **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_assetdata_read(&reader, *r_asset_data);
+
+  oldnewmap_clear(fd->datamap);
+
+  return bhead;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Read Global Data
  * \{ */
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 381ef98533d..00fb476bb1a 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -162,6 +162,8 @@ void blo_end_packed_pointer_map(FileData *fd, struct Main *oldmain);
 void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd);
 void blo_make_old_idmap_from_main(FileData *fd, struct Main *bmain);
 
+BHead *blo_read_asset_data_block(FileData *fd, BHead *bhead, struct AssetData **r_asset_data);
+
 void blo_cache_storage_init(FileData *fd, struct Main *bmain);
 void blo_cache_storage_old_bmain_clear(FileData *fd, struct Main *bmain_old);
 void blo_cache_storage_end(FileData *fd);
@@ -173,7 +175,7 @@ BHead *blo_bhead_next(FileData *fd, BHead *thisblock);
 BHead *blo_bhead_prev(FileData *fd, BHead *thisblock);
 
 const char *blo_bhead_id_name(const FileData *fd, const BHead *bhead);
-struct AssetData *blo_bhead_id_asset_data(const FileData *fd, const BHead *bhead);
+struct AssetData *blo_bhead_id_asset_data_address(const FileData *fd, const BHead *bhead);
 
 /* do versions stuff */
 
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 1a4bc3b53dc..40d11e2526d 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1402,6 +1402,11 @@ static void filelist_intern_entry_free(FileListInternEntry *entry)
   if (entry->name) {
     MEM_freeN(entry->name);
   }
+  /* If we own the asset-data (it was generated from external file data), free it. */
+  if (entry->asset_data &&
+      ((entry->typeflag & FILE_TYPE_ASSET_EXTERNAL) == FILE_TYPE_ASSET_EXTERNAL)) {
+    BKE_asset_data_free(entry->asset_data);
+  }
   MEM_freeN(entry);
 }
 
@@ -2838,8 +2843,9 @@ static int filelist_readjob_list_lib(const char *root, ListBase *entries, const
     entry = MEM_callocN(sizeof(*entry), __func__);
     entry->relpath = BLI_strdup(blockname);
     entry->typeflag |= FILE_TYPE_BLENDERLIB;
-    if (info && info->is_asset) {
-      entry->typeflag |= FILE_TYPE_ASSET;
+    if (info && info->asset_data) {
+      entry->typeflag |= FILE_TYPE_ASSET_EXTERNAL;
+      entry->asset_data = info->asset_data;
     }
     if (!(group && idcode)) {
       entry->typeflag |= FILE_TYPE_DIR;
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 29a25d9f8c2..101bd1357fe 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -978,7 +978,9 @@ typedef enum eFileSel_File_Types {
   FILE_TYPE_USD = (1 << 18),
   FILE_TYPE_VOLUME = (1 << 19),
 
-  FILE_TYPE_ASSET = (1 << 29),
+  FILE_TYPE_ASSET = (1 << 28),
+  /* The file is an asset, but read from a file. So the file-list owns the asset-data. */
+  FILE_TYPE_ASSET_EXTERNAL = FILE_TYPE_ASSET | (1 << 29),
   /** An FS directory (i.e. S_ISDIR on its path is true). */
   FILE_TYPE_DIR = (1 << 30),
   FILE_TYPE_BLENDERLIB = (1ul << 31),



More information about the Bf-blender-cvs mailing list