[Bf-blender-cvs] [33bcc4f4309] temp-asset-library-all: Initial "All" asset library loading support

Julian Eisel noreply at git.blender.org
Tue Nov 22 18:00:28 CET 2022


Commit: 33bcc4f43092c10d37d4120c860c3a222c05d9f7
Author: Julian Eisel
Date:   Tue Nov 22 17:56:36 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB33bcc4f43092c10d37d4120c860c3a222c05d9f7

Initial "All" asset library loading support

An "All" asset library can be selected in the Asset Browser and asset
view templates now, and that will load all assets from all asset
libraries. Preview loading, drag & drop and asset catalogs don't work
yet.

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

M	source/blender/asset_system/AS_asset_library.hh
M	source/blender/asset_system/intern/asset_library.cc
M	source/blender/asset_system/intern/asset_library_service.cc
M	source/blender/asset_system/intern/asset_library_service.hh
M	source/blender/asset_system/intern/asset_storage.hh
M	source/blender/editors/asset/intern/asset_library_reference_enum.cc
M	source/blender/editors/asset/intern/asset_list.cc
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/filelist.cc
M	source/blender/editors/space_file/filesel.c
M	source/blender/makesdna/DNA_asset_defaults.h
M	source/blender/makesdna/DNA_asset_types.h
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/asset_system/AS_asset_library.hh b/source/blender/asset_system/AS_asset_library.hh
index 1a558c4e322..ece3426731c 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -120,6 +120,9 @@ Vector<AssetLibraryReference> all_valid_asset_library_refs();
 blender::asset_system::AssetLibrary *AS_asset_library_load(
     const Main *bmain, const AssetLibraryReference &library_reference);
 
+std::string AS_asset_library_root_path_from_library_ref(
+    const AssetLibraryReference &library_reference);
+
 /**
  * Try to find an appropriate location for an asset library root from a file or directory path.
  * Does not check if \a input_path exists.
diff --git a/source/blender/asset_system/intern/asset_library.cc b/source/blender/asset_system/intern/asset_library.cc
index 45196a218aa..eebbc8db837 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -64,6 +64,12 @@ bool AS_asset_library_has_any_unsaved_catalogs()
   return service->has_any_unsaved_catalogs();
 }
 
+std::string AS_asset_library_root_path_from_library_ref(
+    const AssetLibraryReference &library_reference)
+{
+  return AssetLibraryService::root_path_from_library_ref(library_reference);
+}
+
 std::string AS_asset_library_find_suitable_root_path_from_path(
     const blender::StringRefNull input_path)
 {
@@ -224,6 +230,7 @@ void AssetLibrary::refresh_catalog_simplename(struct AssetMetaData *asset_data)
   STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
 }
 
+/* TODO get rid of this. */
 Vector<AssetLibraryReference> all_valid_asset_library_refs()
 {
   Vector<AssetLibraryReference> result;
diff --git a/source/blender/asset_system/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc
index 9bd2eecd468..c40e6059f66 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -68,12 +68,17 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 
     return get_asset_library_on_disk(root_path);
   }
+
+  /* TODO */
+  if (library_reference.type == ASSET_LIBRARY_ALL) {
+    return get_asset_library_current_file();
+  }
+
   if (library_reference.type == ASSET_LIBRARY_CUSTOM) {
-    bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
-        &U, library_reference.custom_library_index);
+    std::string root_path = root_path_from_library_ref(library_reference);
 
-    if (user_library) {
-      return get_asset_library_on_disk(user_library->path);
+    if (!root_path.empty()) {
+      return get_asset_library_on_disk(root_path);
     }
   }
 
@@ -133,6 +138,31 @@ AssetLibrary *AssetLibraryService::get_asset_library_current_file()
   return lib;
 }
 
+std::string AssetLibraryService::root_path_from_library_ref(
+    const AssetLibraryReference &library_reference)
+{
+  if (ELEM(library_reference.type, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL)) {
+    return "";
+  }
+
+  const char *top_level_directory = nullptr;
+
+  BLI_assert(library_reference.type == ASSET_LIBRARY_CUSTOM);
+  BLI_assert(library_reference.custom_library_index >= 0);
+
+  bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
+      &U, library_reference.custom_library_index);
+  if (user_library) {
+    top_level_directory = user_library->path;
+  }
+
+  if (!top_level_directory) {
+    return "";
+  }
+
+  return normalize_directory_path(top_level_directory);
+}
+
 void AssetLibraryService::allocate_service_instance()
 {
   instance_ = std::make_unique<AssetLibraryService>();
diff --git a/source/blender/asset_system/intern/asset_library_service.hh b/source/blender/asset_system/intern/asset_library_service.hh
index 6045060e91e..c492b798fc3 100644
--- a/source/blender/asset_system/intern/asset_library_service.hh
+++ b/source/blender/asset_system/intern/asset_library_service.hh
@@ -54,6 +54,8 @@ class AssetLibraryService {
   /** Destroy the AssetLibraryService singleton. It will be reallocated by #get() if necessary. */
   static void destroy();
 
+  static std::string root_path_from_library_ref(const AssetLibraryReference &library_reference);
+
   AssetLibrary *get_asset_library(const Main *bmain,
                                   const AssetLibraryReference &library_reference);
 
diff --git a/source/blender/asset_system/intern/asset_storage.hh b/source/blender/asset_system/intern/asset_storage.hh
index 9278b3f41d1..0814c258442 100644
--- a/source/blender/asset_system/intern/asset_storage.hh
+++ b/source/blender/asset_system/intern/asset_storage.hh
@@ -30,6 +30,8 @@ class AssetStorage {
    * faster lookups. Not possible until each asset is only represented once in the storage. */
   StorageT local_id_assets_;
 
+  friend class AssetLibrary;
+
  public:
   /** See #AssetLibrary::add_external_asset(). */
   AssetRepresentation &add_external_asset(StringRef name, std::unique_ptr<AssetMetaData> metadata);
diff --git a/source/blender/editors/asset/intern/asset_library_reference_enum.cc b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
index 773838a54cd..f88afdd8487 100644
--- a/source/blender/editors/asset/intern/asset_library_reference_enum.cc
+++ b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
@@ -47,7 +47,7 @@ AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
   if (value < ASSET_LIBRARY_CUSTOM) {
     library.type = value;
     library.custom_library_index = -1;
-    BLI_assert(ELEM(value, ASSET_LIBRARY_LOCAL));
+    BLI_assert(ELEM(value, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL));
     return library;
   }
 
@@ -78,8 +78,11 @@ const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(
 
   if (include_local_library) {
     const EnumPropertyItem predefined_items[] = {
-        /* For the future. */
-        // {ASSET_REPO_BUNDLED, "BUNDLED", 0, "Bundled", "Show the default user assets"},
+        {ASSET_LIBRARY_ALL,
+         "ALL",
+         ICON_NONE,
+         "All",
+         "Show assets from all of the listed asset libraries"},
         {ASSET_LIBRARY_LOCAL,
          "LOCAL",
          ICON_CURRENT_FILE,
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index bb72c5cc1bb..a14c5eea807 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -12,6 +12,8 @@
 #include <optional>
 #include <string>
 
+#include "AS_asset_library.hh"
+
 #include "BKE_context.h"
 
 #include "BLI_map.hh"
@@ -130,16 +132,7 @@ AssetList::AssetList(eFileSelectType filesel_type, const AssetLibraryReference &
 void AssetList::setup()
 {
   FileList *files = filelist_;
-
-  bUserAssetLibrary *user_library = nullptr;
-
-  /* Ensure valid repository, or fall-back to local one. */
-  if (library_ref_.type == ASSET_LIBRARY_CUSTOM) {
-    BLI_assert(library_ref_.custom_library_index >= 0);
-
-    user_library = BKE_preferences_asset_library_find_from_index(
-        &U, library_ref_.custom_library_index);
-  }
+  std::string asset_lib_path = AS_asset_library_root_path_from_library_ref(library_ref_);
 
   /* Relevant bits from file_refresh(). */
   /* TODO pass options properly. */
@@ -161,13 +154,10 @@ void AssetList::setup()
   filelist_setindexer(files, use_asset_indexer ? &file_indexer_asset : &file_indexer_noop);
 
   char path[FILE_MAXDIR] = "";
-  if (user_library) {
-    BLI_strncpy(path, user_library->path, sizeof(path));
-    filelist_setdir(files, path);
-  }
-  else {
-    filelist_setdir(files, path);
+  if (!asset_lib_path.empty()) {
+    BLI_strncpy(path, asset_lib_path.c_str(), sizeof(path));
   }
+  filelist_setdir(files, path);
 }
 
 void AssetList::fetch(const bContext &C)
@@ -376,7 +366,9 @@ void AssetListStorage::remapID(ID *id_new, ID *id_old)
 std::optional<eFileSelectType> AssetListStorage::asset_library_reference_to_fileselect_type(
     const AssetLibraryReference &library_reference)
 {
-  switch (library_reference.type) {
+  switch (eAssetLibraryType(library_reference.type)) {
+    case ASSET_LIBRARY_ALL:
+      return FILE_ASSET_LIBRARY_ALL;
     case ASSET_LIBRARY_CUSTOM:
       return FILE_ASSET_LIBRARY;
     case ASSET_LIBRARY_LOCAL:
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index ed0132c6990..d21c5b4fa99 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -555,6 +555,7 @@ static void file_draw_preview(const SpaceFile *sfile,
     /* path is no more static, cannot give it directly to but... */
     else if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS &&
              (file->typeflag & FILE_TYPE_ASSET) != 0) {
+      /* TODO enable drag & drop support, get path from asset representation. */
       char blend_path[FILE_MAX_LIBEXTRA];
 
       if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc
index dc59bb1286d..b0ac3277961 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -320,6 +320,10 @@ static void filelist_readjob_main_assets(FileListReadJob *job_params,
                                          bool *stop,
                                          bool *do_update,
                                          float *progress);
+static void filelist_readjob_all_asset_libraries(FileListReadJob *job_params,
+                                                 bool *stop,
+                                                 bool *do_update,
+                                                 float *progress);
 
 /* helper, could probably go in BKE actually? */
 static int groupname_to_code(const char *group);
@@ -854,13 +858,16 @@ static bool is_filtered_lib_type(FileListInternEntry *file,
                                  const char *root,
                                  FileListFilter *filter)
 {
-  char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name;
+  i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list