[Bf-blender-cvs] [e63671c21d7] blender-projects-basics: Support & use new asset library path query from master

Julian Eisel noreply at git.blender.org
Tue Jan 10 16:46:26 CET 2023


Commit: e63671c21d7b07dfb0966ba710aac9b6d7e9306c
Author: Julian Eisel
Date:   Tue Jan 10 16:45:39 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rBe63671c21d7b07dfb0966ba710aac9b6d7e9306c

Support & use new asset library path query from master

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

M	source/blender/asset_system/intern/asset_library_service.cc
M	source/blender/editors/asset/intern/asset_list.cc
M	source/blender/editors/space_file/filesel.cc

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

diff --git a/source/blender/asset_system/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc
index acfb49770cd..f2e0250dde6 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -4,9 +4,14 @@
  * \ingroup asset_system
  */
 
+#include <memory>
+#include <string>
+
 #include "BKE_asset_library_custom.h"
 #include "BKE_blender.h"
+#include "BKE_blender_project.h"
 
+#include "BLI_path_util.h"
 #include "BLI_string_ref.hh"
 
 #include "DNA_asset_types.h"
@@ -188,16 +193,49 @@ std::string AssetLibraryService::root_path_from_library_ref(
     return "";
   }
 
-  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 || !user_library->path[0]) {
-    return "";
+  switch (library_reference.type) {
+    case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES: {
+      CustomAssetLibraryDefinition *user_library = BKE_asset_library_custom_find_from_index(
+          &U.asset_libraries, library_reference.custom_library_index);
+      if (user_library && user_library->path[0]) {
+        return user_library->path;
+      }
+      break;
+    }
+    case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
+      BlenderProject *project = BKE_project_active_get();
+      if (!project) {
+        return "";
+      }
+
+      ListBase *project_libraries = BKE_project_custom_asset_libraries_get(project);
+      CustomAssetLibraryDefinition *project_library_ = BKE_asset_library_custom_find_from_index(
+          project_libraries, library_reference.custom_library_index);
+      if (!project_library_) {
+        return "";
+      }
+
+      /* Project asset libraries typically use relative paths (relative to project root directory).
+       */
+      if (BLI_path_is_rel(project_library_->path)) {
+        const char *project_root_path = BKE_project_root_path_get(project);
+        char path[1024]; /* FILE_MAX */
+        BLI_path_join(path, sizeof(path), project_root_path, project_library_->path);
+        return path;
+      }
+      else {
+        return project_library_->path;
+      }
+      break;
+    }
+    default:
+      BLI_assert_unreachable();
+      break;
   }
 
-  return user_library->path;
+  return "";
 }
 
 void AssetLibraryService::allocate_service_instance()
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index b23223ed02b..a6089cf8ae6 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -153,16 +153,6 @@ void AssetList::setup()
   filelist_setindexer(files, use_asset_indexer ? &file_indexer_asset : &file_indexer_noop);
 
   char path[FILE_MAXDIR] = "";
-#if 0
-   /* Project asset libraries typically use relative paths (relative to project root directory).
-   */
-  if ((library_ref_.type == ASSET_LIBRARY_CUSTOM_FROM_PROJECT) &&
-      BLI_path_is_rel(custom_library->path)) {
-    BlenderProject *project = CTX_wm_project();
-    const char *project_root_path = BKE_project_root_path_get(project);
-    BLI_path_join(path, sizeof(path), project_root_path, custom_library->path);
-  }
-#endif
   if (!asset_lib_path.empty()) {
     BLI_strncpy(path, asset_lib_path.c_str(), sizeof(path));
   }
diff --git a/source/blender/editors/space_file/filesel.cc b/source/blender/editors/space_file/filesel.cc
index 3654979d661..da76ba81da9 100644
--- a/source/blender/editors/space_file/filesel.cc
+++ b/source/blender/editors/space_file/filesel.cc
@@ -23,6 +23,8 @@
 #  include <unistd.h>
 #endif
 
+#include "AS_asset_library.hh"
+
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
@@ -412,45 +414,26 @@ static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
 {
   AssetLibraryReference *library = &asset_params->asset_library_ref;
   FileSelectParams *base_params = &asset_params->base_params;
-  CustomAssetLibraryDefinition *custom_library =
-      ED_asset_library_find_custom_library_from_reference(library);
 
   /* Ensure valid asset library, or fall-back to local one. */
-  if (!custom_library) {
+  if (!ED_asset_library_find_custom_library_from_reference(library)) {
     library->type = ASSET_LIBRARY_LOCAL;
   }
 
+  std::string root_path = AS_asset_library_root_path_from_library_ref(*library);
+  BLI_strncpy(base_params->dir, root_path.c_str(), sizeof(base_params->dir));
+
   switch (library->type) {
     case ASSET_LIBRARY_ALL:
-      base_params->dir[0] = '\0';
       base_params->type = FILE_ASSET_LIBRARY_ALL;
       break;
     case ASSET_LIBRARY_LOCAL:
-      base_params->dir[0] = '\0';
       base_params->type = FILE_MAIN_ASSET;
       break;
     case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES:
-      BLI_assert(custom_library);
-      BLI_strncpy(base_params->dir, custom_library->path, sizeof(base_params->dir));
+    case ASSET_LIBRARY_CUSTOM_FROM_PROJECT:
       base_params->type = FILE_ASSET_LIBRARY;
       break;
-      /* Project asset libraries typically use relative paths (relative to project root directory).
-       */
-    case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
-      BlenderProject *project = CTX_wm_project();
-      BLI_assert(custom_library);
-      BLI_assert(project);
-
-      if (BLI_path_is_rel(custom_library->path)) {
-        const char *project_root_path = BKE_project_root_path_get(project);
-        BLI_path_join(
-            base_params->dir, sizeof(base_params->dir), project_root_path, custom_library->path);
-      }
-      else {
-        BLI_strncpy(base_params->dir, custom_library->path, sizeof(base_params->dir));
-      }
-      break;
-    }
   }
 }



More information about the Bf-blender-cvs mailing list