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>2021-09-29 14:18:44 +0300
committerJulian Eisel <julian@blender.org>2021-09-29 14:18:44 +0300
commitadaf4f56e1ed2d8ff55be4681838c9705da022ad (patch)
tree45e3551e250709edad62e220f1c3b41075ae4856 /source/blender/blenkernel/intern/asset_catalog.cc
parent78b9a8c7b993991c22ac2bd1ffbfaf1d896e4431 (diff)
Support loading catalogs in the Current File asset library
When the Asset Browser shows the "Current File" asset library, now it also attempts to load an asset catalog definition file from location of the current .blend file. This happens as follows: * First, see if the file is inside of an asset library that is "mounted" in the Preferences. Load the catalogs from there if so. * Otherwise, if the file is saved, load the catalogs from the directory the file is saved in. * If the file is not saved, no catalogs will be loaded. Unit tests are being worked on in D12689. Creating catalogs from the "Current File" asset library still doesn't work, as the asset catalog service doesn't construct an in-memory catalog definition file in that case yet. Differential Revision: https://developer.blender.org/D12675
Diffstat (limited to 'source/blender/blenkernel/intern/asset_catalog.cc')
-rw-r--r--source/blender/blenkernel/intern/asset_catalog.cc36
1 files changed, 17 insertions, 19 deletions
diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc
index d54e3b93dda..b00f4305aa6 100644
--- a/source/blender/blenkernel/intern/asset_catalog.cc
+++ b/source/blender/blenkernel/intern/asset_catalog.cc
@@ -19,6 +19,7 @@
*/
#include "BKE_asset_catalog.hh"
+#include "BKE_asset_library.h"
#include "BKE_preferences.h"
#include "BLI_fileops.h"
@@ -299,6 +300,10 @@ bool AssetCatalogService::write_to_disk_on_blendfile_save(const CatalogFilePath
CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing(
const CatalogFilePath &blend_file_path)
{
+ BLI_assert_msg(!blend_file_path.empty(),
+ "A non-empty .blend file path is required to be able to determine where the "
+ "catalog definition file should be put");
+
/* Determine the default CDF path in the same directory of the blend file. */
char blend_dir_path[PATH_MAX];
BLI_split_dir_part(blend_file_path.c_str(), blend_dir_path, sizeof(blend_dir_path));
@@ -311,26 +316,19 @@ CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing(
return cdf_path_next_to_blend;
}
- const bUserAssetLibrary *asset_lib_pref = BKE_preferences_asset_library_containing_path(
- &U, blend_file_path.c_str());
- if (asset_lib_pref) {
- /* - The directory containing the blend file is part of an asset library, as per
- * the user's preferences?
- * -> Merge with & write to ${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt */
-
- char asset_lib_cdf_path[PATH_MAX];
- BLI_path_join(asset_lib_cdf_path,
- sizeof(asset_lib_cdf_path),
- asset_lib_pref->path,
- DEFAULT_CATALOG_FILENAME.c_str(),
- NULL);
-
- return asset_lib_cdf_path;
- }
+ /* - There's no definition file next to the .blend file.
+ * -> Ask the asset library API for an appropriate location. */
+ char suitable_root_path[PATH_MAX];
+ BKE_asset_library_find_suitable_root_path_from_path(blend_file_path.c_str(),
+ suitable_root_path);
+ char asset_lib_cdf_path[PATH_MAX];
+ BLI_path_join(asset_lib_cdf_path,
+ sizeof(asset_lib_cdf_path),
+ suitable_root_path,
+ DEFAULT_CATALOG_FILENAME.c_str(),
+ NULL);
- /* - Otherwise
- * -> Create a new file blender_assets.cats.txt next to the blend file. */
- return cdf_path_next_to_blend;
+ return asset_lib_cdf_path;
}
std::unique_ptr<AssetCatalogDefinitionFile> AssetCatalogService::construct_cdf_in_memory(