Brush Assets: Add catalog option to asset pushing operator #118382

Merged
Hans Goudey merged 26 commits from HooglyBoogly/blender:brush-assets-save-catalog-option into brush-assets-project 2024-02-21 14:03:41 +01:00
1 changed files with 13 additions and 1 deletions
Showing only changes of commit 160a2fa1b1 - Show all commits

View File

@ -1268,6 +1268,17 @@ static asset_system::AssetCatalog &asset_library_ensure_catalog(
return *library.catalog_service->create_catalog(path);
}
static asset_system::AssetCatalog &asset_library_ensure_catalogs_in_path(
asset_system::AssetLibrary &library, const asset_system::AssetCatalogPath &path)
{
asset_system::AssetCatalogPath parent = "";
path.iterate_components([&](StringRef component_name, bool is_last_component) {
asset_library_ensure_catalog(library, parent / component_name);
parent = parent / component_name;

Creating a catalog with missing parent catalogs should work fine, the parents would be created with create_missing_catalogs(). Is this not working for you?

Creating a catalog with missing parent catalogs should work fine, the parents would be created with `create_missing_catalogs()`. Is this not working for you?

No, that's the infinite recursion I was mentioning in chat. It creates the missing parent catalogs with a null catalog ID and an empty simple name. If you want, you should be able to reproduce it by calling asset_library_ensure_catalog instead of asset_library_ensure_catalogs_in_path below.

No, that's the infinite recursion I was mentioning in chat. It creates the missing parent catalogs with a null catalog ID and an empty simple name. If you want, you should be able to reproduce it by calling `asset_library_ensure_catalog` instead of `asset_library_ensure_catalogs_in_path` below.
});
return *library.catalog_service->find_catalog_by_path(path);
}
static AssetLibraryReference user_library_to_library_ref(const bUserAssetLibrary &user_library)
{
AssetLibraryReference library_ref{};
@ -1320,7 +1331,8 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
/* Add asset to catalog. */
char catalog_path[MAX_NAME];
RNA_string_get(op->ptr, "catalog_path", catalog_path);
const asset_system::AssetCatalog &catalog = asset_library_ensure_catalog(*library, catalog_path);
const asset_system::AssetCatalog &catalog = asset_library_ensure_catalogs_in_path(*library,
catalog_path);
const asset_system::CatalogID catalog_id = catalog.catalog_id;
const std::string catalog_simple_name = catalog.simple_name;