[Bf-blender-cvs] [46da935c55b] asset-browser: Support storing asset repository data in files

Julian Eisel noreply at git.blender.org
Thu Oct 29 15:28:49 CET 2020


Commit: 46da935c55b0b585f4feced6035ff0a0e3b01bdb
Author: Julian Eisel
Date:   Thu Oct 29 13:02:03 2020 +0100
Branches: asset-browser
https://developer.blender.org/rB46da935c55b0b585f4feced6035ff0a0e3b01bdb

Support storing asset repository data in files

Given that a repository can be built up from a single, or multiple
.blends, it's not clear where the repository data should live. It should
still be possible to easily share a .blend file to share assets,
including relevant meta-data that is not solely stored on the asset
level.
E.g. if you want to share a single pose library, that should be
doable by sharing a single .blend. So the .blend needs to have the pose
library meta-data, i.e. the name of the library and which poses belong
to it. The current design forsees that the Pose Library is implemented
as a "cataloge" (aka "smart-filter", to be determined). These should be
stored per asset category in the repository.

So this commit works towards the following design idea:
Each .blend file with assets can additionally store repository
meta-data. When reading a repository, we don't only read the asset
meta-data but also the repository meta-data in each .blend file. The
union over all the .blend files is the total repository meta-data the
asset browser can display.
That way each .blend file still is an isolated unit that doesn't
necessarily depend on the existence of other .blend files (or an index)
in the same repository.

This commit implements the storage framework of the repository meta-data.

I also added a temporary define to help spotting the related changes in
future.

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

M	CMakeLists.txt
M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/intern/asset.c
M	source/blender/blenkernel/intern/blender.c
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/BLO_blend_defs.h
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/BLO_writefile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/asset/asset_ops.c
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb04da749ab..ca2b3da1d9b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -446,6 +446,8 @@ else()
   set(WITH_EXPERIMENTAL_FEATURES ON)
 endif()
 
+add_definitions(-DWITH_ASSET_REPO_INFO)
+
 # Unit testsing
 option(WITH_GTESTS "Enable GTest unit testing" OFF)
 option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index a4a794691a3..43604b1cefe 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -32,6 +32,13 @@ struct BlendDataReader;
 struct ID;
 struct PreviewImage;
 
+#ifdef WITH_ASSET_REPO_INFO
+struct AssetRepositoryInfo *BKE_asset_repository_info_global_ensure(void);
+void BKE_asset_repository_info_free(struct AssetRepositoryInfo **repository_info);
+void BKE_asset_repository_info_global_free(void);
+void BKE_asset_repository_info_update_for_file_read(struct AssetRepositoryInfo **repository_info);
+#endif
+
 struct AssetData *BKE_asset_data_create(void);
 void BKE_asset_data_free(struct AssetData *asset_data);
 
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 7950adee2f4..5351cc1c8f0 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -35,6 +35,36 @@
 
 #include "MEM_guardedalloc.h"
 
+#ifdef WITH_ASSET_REPO_INFO
+AssetRepositoryInfo *G_asset_repository_info;
+
+AssetRepositoryInfo *BKE_asset_repository_info_global_ensure(void)
+{
+  if (!G_asset_repository_info) {
+    G_asset_repository_info = MEM_callocN(sizeof(*G_asset_repository_info), __func__);
+  }
+
+  return G_asset_repository_info;
+}
+
+void BKE_asset_repository_info_free(AssetRepositoryInfo **repository_info)
+{
+  MEM_SAFE_FREE(*repository_info);
+}
+
+void BKE_asset_repository_info_global_free(void)
+{
+  BKE_asset_repository_info_free(&G_asset_repository_info);
+}
+
+void BKE_asset_repository_info_update_for_file_read(AssetRepositoryInfo **old_repository_info)
+{
+  /* Force recreation of the repository info. */
+  BKE_asset_repository_info_free(old_repository_info);
+}
+
+#endif
+
 AssetData *BKE_asset_data_create(void)
 {
   AssetData *asset_data = MEM_callocN(sizeof(AssetData), __func__);
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index fc43c065351..1cde20434ba 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -37,6 +37,9 @@
 #include "IMB_moviecache.h"
 
 #include "BKE_addon.h"
+#ifdef WITH_ASSET_REPO_INFO
+#  include "BKE_asset.h"
+#endif
 #include "BKE_blender.h" /* own include */
 #include "BKE_blender_user_menu.h"
 #include "BKE_blender_version.h" /* own include */
@@ -80,6 +83,9 @@ void BKE_blender_free(void)
 
   BKE_main_free(G_MAIN);
   G_MAIN = NULL;
+#ifdef WITH_ASSET_REPO_INFO
+  BKE_asset_repository_info_global_free();
+#endif
 
   if (G.log.file != NULL) {
     fclose(G.log.file);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index f0f2049d92f..f890ddf206b 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -26,6 +26,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#ifdef WITH_ASSET_REPO_INFO
+#  include "DNA_asset_types.h"
+#endif
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_workspace_types.h"
@@ -40,6 +43,9 @@
 
 #include "BKE_addon.h"
 #include "BKE_appdir.h"
+#ifdef WITH_ASSET_REPO_INFO
+#  include "BKE_asset.h"
+#endif
 #include "BKE_blender.h"
 #include "BKE_blender_version.h"
 #include "BKE_blendfile.h"
@@ -283,6 +289,17 @@ static void setup_app_data(bContext *C,
   bmain = G_MAIN = bfd->main;
   bfd->main = NULL;
 
+#ifdef WITH_ASSET_REPO_INFO
+  if (mode != LOAD_UNDO) {
+    /* Close old repository info. */
+    BKE_asset_repository_info_update_for_file_read(&G_asset_repository_info);
+
+    /* Move read repository info to the current app. */
+    G_asset_repository_info = bfd->asset_repository_info;
+    bfd->asset_repository_info = NULL;
+  }
+#endif
+
   CTX_data_main_set(C, bmain);
 
   /* case G_FILE_NO_UI or no screens in file */
diff --git a/source/blender/blenloader/BLO_blend_defs.h b/source/blender/blenloader/BLO_blend_defs.h
index 40da63f20e8..c30412b61b8 100644
--- a/source/blender/blenloader/BLO_blend_defs.h
+++ b/source/blender/blenloader/BLO_blend_defs.h
@@ -64,6 +64,18 @@ enum {
    * (written to #BLENDER_STARTUP_FILE & #BLENDER_USERPREF_FILE).
    */
   USER = BLEND_MAKE_ID('U', 'S', 'E', 'R'),
+#ifdef WITH_ASSET_REPO_INFO
+  /**
+   * Used for #AssetRepositoryInfo, meta-data to add to repositories for files containing assets.
+   *
+   * If the blend contains any asset data-blocks, it becomes a potential repository, or part of
+   * one. So #AssetRepositoryInfo is added to the file, allowing assets to be queried together with
+   * the meta-data they want to add to the repository. A repositories meta-data is then established
+   * by creating a union of all meta-data written into all the repository's .blend files (possibly
+   * extended by an Asset Manager Bride add-on).
+   */
+  ASSET_REPOSITORY_INFO = BLEND_MAKE_ID('A', 'R', 'E', 'P'),
+#endif
   /**
    * Terminate reading (no data).
    */
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 7e152775f21..35133854a0e 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -68,6 +68,9 @@ typedef enum eBlenFileType {
 typedef struct BlendFileData {
   struct Main *main;
   struct UserDef *user;
+#ifdef WITH_ASSET_REPO_INFO
+  struct AssetRepositoryInfo *asset_repository_info;
+#endif
 
   int fileflags;
   int globalf;
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h
index 746c663926d..c596eb8b8e9 100644
--- a/source/blender/blenloader/BLO_writefile.h
+++ b/source/blender/blenloader/BLO_writefile.h
@@ -58,6 +58,9 @@ struct BlendFileWriteParams {
   uint use_save_as_copy : 1;
   uint use_userdef : 1;
   const struct BlendThumbnail *thumb;
+#ifdef WITH_ASSET_REPO_INFO
+  const struct AssetRepositoryInfo *asset_repository_info;
+#endif
 };
 
 extern bool BLO_write_file(struct Main *mainvar,
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index e4ef56c68e5..d28c24950d3 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -40,6 +40,9 @@
 #include "DNA_genfile.h"
 #include "DNA_sdna_types.h"
 
+#ifdef WITH_ASSET_REPO_INFO
+#  include "BKE_asset.h"
+#endif
 #include "BKE_idtype.h"
 #include "BKE_main.h"
 
@@ -466,5 +469,11 @@ void BLO_blendfiledata_free(BlendFileData *bfd)
     MEM_freeN(bfd->user);
   }
 
+#ifdef WITH_ASSET_REPO_INFO
+  if (bfd->asset_repository_info) {
+    BKE_asset_repository_info_free(&bfd->asset_repository_info);
+  }
+#endif
+
   MEM_freeN(bfd);
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index af077c9b208..2636bc9a2c8 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6918,6 +6918,30 @@ static void link_global(FileData *fd, BlendFileData *bfd)
 
 /** \} */
 
+#ifdef WITH_ASSET_REPO_INFO
+/* -------------------------------------------------------------------- */
+/** \name Read Asset Repository Data
+ * \{ */
+
+static BHead *read_asset_repository_info(BlendFileData *bfd, FileData *fd, BHead *bhead)
+{
+  AssetRepositoryInfo *repository_info = read_struct(fd, bhead, "asset repository info");
+
+  bfd->asset_repository_info = repository_info;
+
+  bhead = read_data_into_datamap(fd, bhead, "asset repository data");
+
+  BlendDataReader reader_ = {fd};
+  BlendDataReader *reader = &reader_;
+
+  BLO_read_list(reader, &repository_info->catalogs);
+
+  return bhead;
+}
+
+/** \} */
+#endif
+
 /* -------------------------------------------------------------------- */
 /** \name Versioning
  * \{ */
@@ -7299,6 +7323,11 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
           bhead = read_userdef(bfd, fd, bhead);
         }
         break;
+#ifdef WITH_ASSET_REPO_INFO
+      case ASSET_REPOSITORY_INFO:
+        bhead = read_asset_repository_info(bfd, fd, bhead);
+        break;
+#endif
       case ENDB:
         bhead = NULL;
         break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9407f5f5d10..3994d732135 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2208,6 +2208,15 @@ static void write_thumb(WriteData *wd, const BlendThumbnail *thumb)
   }
 }
 
+#ifdef WITH_ASSET_REPO_INFO
+static void write_asset_repository_info(WriteData *wd, const AssetRepositoryInfo *repository_info)
+{
+  if (repository_info) {
+    writestruct(wd, ASSET_REPOSITORY_INFO, AssetRepositoryInfo, 1, repository_info);
+  }
+}
+#endif
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -2221,7 +2230,12 @@ static bool write_file_handle(Main *mainvar,
                               MemFile *current,
                               int write_flags,
                               bool use_userdef,
-                              const BlendThumbnail *thumb)
+                              const BlendThumbnail *thumb
+#ifdef WITH_ASSET_REPO_INFO
+                              ,
+                              const AssetRepositoryInfo *repository_info
+#endif
+)
 {
   BHead bhead;
   ListBase mainlist;
@@ -2243,6 +2257,9 @@ static bool write_file_handle(Main *mainvar,
 
   write_renderinfo(wd, mainvar);
   write_thumb(wd, thumb);
+#ifdef WITH_ASSET_REPO_INFO
+  write_asset_repository_info(wd, repository_info);
+#endif
   write_global(wd, write_flags, mainvar);
 
   /* The windowmanager and screen often change,
@@ -2507,6 +2524,9 @@ bool BLO_write_file(Main *mainvar,
   const bool use_save_as_copy = params->use_save_as_copy;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list