diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt index 4dd596ad93a..0df742603f1 100644 --- a/source/blender/CMakeLists.txt +++ b/source/blender/CMakeLists.txt @@ -129,6 +129,7 @@ set(SRC_DNA_DEFAULTS_INC add_subdirectory(datatoc) add_subdirectory(editors) add_subdirectory(windowmanager) +add_subdirectory(asset_system) add_subdirectory(blenkernel) add_subdirectory(blenlib) add_subdirectory(bmesh) diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/asset_system/AS_asset_catalog.hh similarity index 98% rename from source/blender/blenkernel/BKE_asset_catalog.hh rename to source/blender/asset_system/AS_asset_catalog.hh index 73c2e00c4c4..8160676603d 100644 --- a/source/blender/blenkernel/BKE_asset_catalog.hh +++ b/source/blender/asset_system/AS_asset_catalog.hh @@ -1,15 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #pragma once -#ifndef __cplusplus -# error This is a C++ header. The C interface is yet to be implemented/designed. -#endif - #include "BLI_function_ref.hh" #include "BLI_map.hh" #include "BLI_set.hh" @@ -17,14 +13,14 @@ #include "BLI_uuid.h" #include "BLI_vector.hh" -#include "BKE_asset_catalog_path.hh" +#include "AS_asset_catalog_path.hh" #include #include #include #include -namespace blender::bke { +namespace blender::asset_system { class AssetCatalog; class AssetCatalogCollection; @@ -521,4 +517,4 @@ class AssetCatalogFilter { Set &&known_catalog_ids); }; -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/blenkernel/BKE_asset_catalog_path.hh b/source/blender/asset_system/AS_asset_catalog_path.hh similarity index 97% rename from source/blender/blenkernel/BKE_asset_catalog_path.hh rename to source/blender/asset_system/AS_asset_catalog_path.hh index 93ab0389daf..0ac50ab00c9 100644 --- a/source/blender/blenkernel/BKE_asset_catalog_path.hh +++ b/source/blender/asset_system/AS_asset_catalog_path.hh @@ -1,22 +1,18 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #pragma once -#ifndef __cplusplus -# error This is a C++ header. -#endif - #include "BLI_function_ref.hh" #include "BLI_string_ref.hh" #include "BLI_sys_types.h" #include -namespace blender::bke { +namespace blender::asset_system { /** * Location of an Asset Catalog in the catalog tree, denoted by slash-separated path components. @@ -129,4 +125,4 @@ class AssetCatalogPath { /** Output the path as string. */ std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append); -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/blenkernel/BKE_asset_library.h b/source/blender/asset_system/AS_asset_library.h similarity index 69% rename from source/blender/blenkernel/BKE_asset_library.h rename to source/blender/asset_system/AS_asset_library.h index fc648ff6976..8c5c4633c4e 100644 --- a/source/blender/blenkernel/BKE_asset_library.h +++ b/source/blender/asset_system/AS_asset_library.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #pragma once @@ -23,18 +23,18 @@ typedef struct AssetLibrary AssetLibrary; * * To get the in-memory-only "current file" asset library, pass an empty path. */ -struct AssetLibrary *BKE_asset_library_load(const char *library_path); +struct AssetLibrary *AS_asset_library_load(const char *library_path); /** Look up the asset's catalog and copy its simple name into #asset_data. */ -void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library, - struct AssetMetaData *asset_data); +void AS_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library, + struct AssetMetaData *asset_data); /** Return whether any loaded AssetLibrary has unsaved changes to its catalogs. */ -bool BKE_asset_library_has_any_unsaved_catalogs(void); +bool AS_asset_library_has_any_unsaved_catalogs(void); /** An asset library can include local IDs (IDs in the current file). Their pointers need to be * remapped on change (or assets removed as IDs gets removed). */ -void BKE_asset_library_remap_ids(struct IDRemapper *mappings); +void AS_asset_library_remap_ids(struct IDRemapper *mappings); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_asset_library.hh b/source/blender/asset_system/AS_asset_library.hh similarity index 85% rename from source/blender/blenkernel/BKE_asset_library.hh rename to source/blender/asset_system/AS_asset_library.hh index f69847bd1ed..a0f1214ad39 100644 --- a/source/blender/blenkernel/BKE_asset_library.hh +++ b/source/blender/asset_system/AS_asset_library.hh @@ -1,31 +1,27 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #pragma once -#ifndef __cplusplus -# error This is a C++-only header file. Use BKE_asset_library.h instead. -#endif - #include "DNA_asset_types.h" #include "BLI_string_ref.hh" #include "BLI_vector.hh" -#include "BKE_asset_library.h" - -#include "BKE_asset_catalog.hh" +#include "AS_asset_catalog.hh" #include "BKE_callbacks.h" #include +struct AssetLibrary; struct AssetLibraryReference; +struct AssetMetaData; struct Main; -namespace blender::bke { +namespace blender::asset_system { class AssetRepresentation; @@ -101,10 +97,10 @@ struct AssetLibrary { Vector all_valid_asset_library_refs(); -} // namespace blender::bke +} // namespace blender::asset_system -blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain, - const AssetLibraryReference &library_reference); +blender::asset_system::AssetLibrary *AS_asset_library_load( + const Main *bmain, const AssetLibraryReference &library_reference); /** * Try to find an appropriate location for an asset library root from a file or directory path. @@ -127,19 +123,20 @@ blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain, * \return True if the function could find a valid, that is, a non-empty path to return in \a * r_library_path. */ -std::string BKE_asset_library_find_suitable_root_path_from_path(blender::StringRefNull input_path); +std::string AS_asset_library_find_suitable_root_path_from_path(blender::StringRefNull input_path); /** * Uses the current location on disk of the file represented by \a bmain as input to - * #BKE_asset_library_find_suitable_root_path_from_path(). Refer to it for a design + * #AS_asset_library_find_suitable_root_path_from_path(). Refer to it for a design * description. * * \return True if the function could find a valid, that is, a non-empty path to return in \a * r_library_path. If \a bmain wasn't saved into a file yet, the return value will be * false. */ -std::string BKE_asset_library_find_suitable_root_path_from_main(const struct Main *bmain); +std::string AS_asset_library_find_suitable_root_path_from_main(const struct Main *bmain); -blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service( +blender::asset_system::AssetCatalogService *AS_asset_library_get_catalog_service( + const ::AssetLibrary *library); +blender::asset_system::AssetCatalogTree *AS_asset_library_get_catalog_tree( const ::AssetLibrary *library); -blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library); diff --git a/source/blender/asset_system/AS_asset_representation.h b/source/blender/asset_system/AS_asset_representation.h new file mode 100644 index 00000000000..6a5425979aa --- /dev/null +++ b/source/blender/asset_system/AS_asset_representation.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup asset_system + */ + +#pragma once + +#include "BLI_compiler_attrs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct AssetMetaData; + +/** C handle for #asset_system::AssetRepresentation. */ +typedef struct AssetRepresentation AssetRepresentation; + +const char *AS_asset_representation_name_get(const AssetRepresentation *asset) + ATTR_WARN_UNUSED_RESULT; +AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset) + ATTR_WARN_UNUSED_RESULT; +bool AS_asset_representation_is_local_id(const AssetRepresentation *asset) ATTR_WARN_UNUSED_RESULT; + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/blenkernel/BKE_asset_representation.hh b/source/blender/asset_system/AS_asset_representation.hh similarity index 95% rename from source/blender/blenkernel/BKE_asset_representation.hh rename to source/blender/asset_system/AS_asset_representation.hh index edaa5a203ba..66c49c445dc 100644 --- a/source/blender/blenkernel/BKE_asset_representation.hh +++ b/source/blender/asset_system/AS_asset_representation.hh @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #pragma once @@ -14,7 +14,7 @@ struct AssetMetaData; struct ID; -namespace blender::bke { +namespace blender::asset_system { /** * \brief Abstraction to reference an asset, with necessary data for display & interaction. @@ -61,4 +61,4 @@ class AssetRepresentation { bool is_local_id() const; }; -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/asset_system/CMakeLists.txt b/source/blender/asset_system/CMakeLists.txt new file mode 100644 index 00000000000..8bf7a135155 --- /dev/null +++ b/source/blender/asset_system/CMakeLists.txt @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +set(INC + . + intern + ../blenkernel + ../blenlib + ../makesdna + ../../../intern/clog + ../../../intern/guardedalloc +) + +set(INC_SYS +) + +set(SRC + intern/asset_catalog.cc + intern/asset_catalog_path.cc + intern/asset_library.cc + intern/asset_library_service.cc + intern/asset_representation.cc + + AS_asset_catalog.hh + AS_asset_catalog_path.hh + AS_asset_library.hh + AS_asset_representation.hh + intern/asset_library_service.hh + + AS_asset_library.h + AS_asset_representation.h +) + +set(LIB +) + + +blender_add_lib(bf_asset_system "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") + +if(WITH_GTESTS) + set(TEST_SRC + tests/asset_catalog_test.cc + tests/asset_catalog_path_test.cc + tests/asset_library_service_test.cc + tests/asset_library_test.cc + ) + set(TEST_LIB + bf_asset_system + ) + include(GTestTesting) + blender_add_test_lib(bf_asset_system_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}") +endif() diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/asset_system/intern/asset_catalog.cc similarity index 99% rename from source/blender/blenkernel/intern/asset_catalog.cc rename to source/blender/asset_system/intern/asset_catalog.cc index a9fe59eba64..e7790236583 100644 --- a/source/blender/blenkernel/intern/asset_catalog.cc +++ b/source/blender/asset_system/intern/asset_catalog.cc @@ -1,15 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #include #include -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.h" -#include "BKE_asset_library.hh" +#include "AS_asset_catalog.hh" +#include "AS_asset_library.h" +#include "AS_asset_library.hh" #include "BLI_fileops.hh" #include "BLI_path_util.h" @@ -21,9 +21,9 @@ #include "CLG_log.h" -static CLG_LogRef LOG = {"bke.asset_service"}; +static CLG_LogRef LOG = {"asset_system.asset_catalog_service"}; -namespace blender::bke { +namespace blender::asset_system { const CatalogFilePath AssetCatalogService::DEFAULT_CATALOG_FILENAME = "blender_assets.cats.txt"; @@ -508,7 +508,7 @@ CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing( "catalog definition file should be put"); /* Ask the asset library API for an appropriate location. */ - const std::string suitable_root_path = BKE_asset_library_find_suitable_root_path_from_path( + const std::string suitable_root_path = AS_asset_library_find_suitable_root_path_from_path( blend_file_path); if (!suitable_root_path.empty()) { char asset_lib_cdf_path[PATH_MAX]; @@ -1132,4 +1132,4 @@ bool AssetCatalogFilter::is_known(const CatalogID asset_catalog_id) const return known_catalog_ids.contains(asset_catalog_id); } -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/blenkernel/intern/asset_catalog_path.cc b/source/blender/asset_system/intern/asset_catalog_path.cc similarity index 97% rename from source/blender/blenkernel/intern/asset_catalog_path.cc rename to source/blender/asset_system/intern/asset_catalog_path.cc index 9c653c1a137..fe835c555a8 100644 --- a/source/blender/blenkernel/intern/asset_catalog_path.cc +++ b/source/blender/asset_system/intern/asset_catalog_path.cc @@ -1,14 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ -#include "BKE_asset_catalog_path.hh" +#include "AS_asset_catalog_path.hh" #include "BLI_path_util.h" -namespace blender::bke { +namespace blender::asset_system { const char AssetCatalogPath::SEPARATOR = '/'; @@ -221,4 +221,4 @@ AssetCatalogPath AssetCatalogPath::rebase(const AssetCatalogPath &from_path, return to_path / path_suffix; } -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/blenkernel/intern/asset_library.cc b/source/blender/asset_system/intern/asset_library.cc similarity index 75% rename from source/blender/blenkernel/intern/asset_library.cc rename to source/blender/asset_system/intern/asset_library.cc index 4dccee425c6..b52594fa20c 100644 --- a/source/blender/blenkernel/intern/asset_library.cc +++ b/source/blender/asset_system/intern/asset_library.cc @@ -1,13 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #include -#include "BKE_asset_library.hh" -#include "BKE_asset_representation.hh" +#include "AS_asset_library.h" +#include "AS_asset_library.hh" +#include "AS_asset_representation.hh" + #include "BKE_lib_remap.h" #include "BKE_main.h" #include "BKE_preferences.h" @@ -21,12 +23,15 @@ #include "asset_library_service.hh" -bool blender::bke::AssetLibrary::save_catalogs_when_file_is_saved = true; +using namespace blender; +using namespace blender::asset_system; -blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain, - const AssetLibraryReference &library_reference) +bool asset_system::AssetLibrary::save_catalogs_when_file_is_saved = true; + +asset_system::AssetLibrary *AS_asset_library_load(const Main *bmain, + const AssetLibraryReference &library_reference) { - blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); + AssetLibraryService *service = AssetLibraryService::get(); return service->get_asset_library(bmain, library_reference); } @@ -34,26 +39,26 @@ blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain, * Loading an asset library at this point only means loading the catalogs. Later on this should * invoke reading of asset representations too. */ -struct AssetLibrary *BKE_asset_library_load(const char *library_path) +struct ::AssetLibrary *AS_asset_library_load(const char *library_path) { - blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); - blender::bke::AssetLibrary *lib; + AssetLibraryService *service = AssetLibraryService::get(); + asset_system::AssetLibrary *lib; if (library_path == nullptr || library_path[0] == '\0') { lib = service->get_asset_library_current_file(); } else { lib = service->get_asset_library_on_disk(library_path); } - return reinterpret_cast(lib); + return reinterpret_cast(lib); } -bool BKE_asset_library_has_any_unsaved_catalogs() +bool AS_asset_library_has_any_unsaved_catalogs() { - blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); + AssetLibraryService *service = AssetLibraryService::get(); return service->has_any_unsaved_catalogs(); } -std::string BKE_asset_library_find_suitable_root_path_from_path( +std::string AS_asset_library_find_suitable_root_path_from_path( const blender::StringRefNull input_path) { if (bUserAssetLibrary *preferences_lib = BKE_preferences_asset_library_containing_path( @@ -66,27 +71,25 @@ std::string BKE_asset_library_find_suitable_root_path_from_path( return buffer; } -std::string BKE_asset_library_find_suitable_root_path_from_main(const Main *bmain) +std::string AS_asset_library_find_suitable_root_path_from_main(const Main *bmain) { - return BKE_asset_library_find_suitable_root_path_from_path(bmain->filepath); + return AS_asset_library_find_suitable_root_path_from_path(bmain->filepath); } -blender::bke::AssetCatalogService *BKE_asset_library_get_catalog_service( - const ::AssetLibrary *library_c) +AssetCatalogService *AS_asset_library_get_catalog_service(const ::AssetLibrary *library_c) { if (library_c == nullptr) { return nullptr; } - const blender::bke::AssetLibrary &library = reinterpret_cast( + const asset_system::AssetLibrary &library = reinterpret_cast( *library_c); return library.catalog_service.get(); } -blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::AssetLibrary *library) +AssetCatalogTree *AS_asset_library_get_catalog_tree(const ::AssetLibrary *library) { - blender::bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service( - library); + AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service(library); if (catalog_service == nullptr) { return nullptr; } @@ -94,21 +97,21 @@ blender::bke::AssetCatalogTree *BKE_asset_library_get_catalog_tree(const ::Asset return catalog_service->get_catalog_tree(); } -void BKE_asset_library_refresh_catalog_simplename(struct AssetLibrary *asset_library, - struct AssetMetaData *asset_data) +void AS_asset_library_refresh_catalog_simplename(struct ::AssetLibrary *asset_library, + struct AssetMetaData *asset_data) { - blender::bke::AssetLibrary *lib = reinterpret_cast(asset_library); + asset_system::AssetLibrary *lib = reinterpret_cast(asset_library); lib->refresh_catalog_simplename(asset_data); } -void BKE_asset_library_remap_ids(IDRemapper *mappings) +void AS_asset_library_remap_ids(IDRemapper *mappings) { - blender::bke::AssetLibraryService *service = blender::bke::AssetLibraryService::get(); + AssetLibraryService *service = AssetLibraryService::get(); service->foreach_loaded_asset_library( - [mappings](blender::bke::AssetLibrary &library) { library.remap_ids(*mappings); }); + [mappings](asset_system::AssetLibrary &library) { library.remap_ids(*mappings); }); } -namespace blender::bke { +namespace blender::asset_system { AssetLibrary::AssetLibrary() : catalog_service(std::make_unique()) { @@ -272,4 +275,4 @@ Vector all_valid_asset_library_refs() return result; } -} // namespace blender::bke +} // namespace blender::asset_system diff --git a/source/blender/blenkernel/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc similarity index 94% rename from source/blender/blenkernel/intern/asset_library_service.cc rename to source/blender/asset_system/intern/asset_library_service.cc index 35441b9b795..e46557e1b29 100644 --- a/source/blender/blenkernel/intern/asset_library_service.cc +++ b/source/blender/asset_system/intern/asset_library_service.cc @@ -1,12 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file - * \ingroup bke + * \ingroup asset_system */ #include "asset_library_service.hh" +#include "AS_asset_library.hh" -#include "BKE_asset_library.hh" #include "BKE_blender.h" #include "BKE_preferences.h" @@ -19,9 +19,9 @@ #include "CLG_log.h" -static CLG_LogRef LOG = {"bke.asset_service"}; +static CLG_LogRef LOG = {"asset_system.asset_library_service"}; -namespace blender::bke { +namespace blender::asset_system { std::unique_ptr AssetLibraryService::instance_; bool AssetLibraryService::atexit_handler_registered_ = false; @@ -48,8 +48,7 @@ AssetLibrary *AssetLibraryService::get_asset_library( { if (library_reference.type == ASSET_LIBRARY_LOCAL) { /* For the "Current File" library we get the asset library root path based on main. */ - std::string root_path = bmain ? BKE_asset_library_find_suitable_root_path_from_main(bmain) : - ""; + std::string root_path = bmain ? AS_asset_library_find_suitable_root_path_from_main(bmain) : ""; if (root_path.empty()) { /* File wasn't saved yet. */ @@ -187,4 +186,4 @@ void AssetLibraryService::foreach_loaded_asset_library(FunctionRef @@ -9,10 +9,12 @@ #include "DNA_ID.h" #include "DNA_asset_types.h" -#include "BKE_asset.h" -#include "BKE_asset_representation.hh" +#include "AS_asset_representation.h" +#include "AS_asset_representation.hh" -namespace blender::bke { +#include "BKE_asset.h" + +namespace blender::asset_system { AssetRepresentation::AssetRepresentation(StringRef name, std::unique_ptr metadata) : is_local_id_(false), external_asset_() @@ -66,7 +68,7 @@ bool AssetRepresentation::is_local_id() const return is_local_id_; } -} // namespace blender::bke +} // namespace blender::asset_system /* ---------------------------------------------------------------------- */ /** \name C-API @@ -74,24 +76,24 @@ bool AssetRepresentation::is_local_id() const using namespace blender; -const char *BKE_asset_representation_name_get(const AssetRepresentation *asset_handle) +const char *AS_asset_representation_name_get(const AssetRepresentation *asset_handle) { - const bke::AssetRepresentation *asset = reinterpret_cast( - asset_handle); + const asset_system::AssetRepresentation *asset = + reinterpret_cast(asset_handle); return asset->get_name().c_str(); } -AssetMetaData *BKE_asset_representation_metadata_get(const AssetRepresentation *asset_handle) +AssetMetaData *AS_asset_representation_metadata_get(const AssetRepresentation *asset_handle) { - const bke::AssetRepresentation *asset = reinterpret_cast( - asset_handle); + const asset_system::AssetRepresentation *asset = + reinterpret_cast(asset_handle); return &asset->get_metadata(); } -bool BKE_asset_representation_is_local_id(const AssetRepresentation *asset_handle) +bool AS_asset_representation_is_local_id(const AssetRepresentation *asset_handle) { - const bke::AssetRepresentation *asset = reinterpret_cast( - asset_handle); + const asset_system::AssetRepresentation *asset = + reinterpret_cast(asset_handle); return asset->is_local_id(); } diff --git a/source/blender/blenkernel/intern/asset_catalog_path_test.cc b/source/blender/asset_system/tests/asset_catalog_path_test.cc similarity index 98% rename from source/blender/blenkernel/intern/asset_catalog_path_test.cc rename to source/blender/asset_system/tests/asset_catalog_path_test.cc index 731d128e3da..380f7243529 100644 --- a/source/blender/blenkernel/intern/asset_catalog_path_test.cc +++ b/source/blender/asset_system/tests/asset_catalog_path_test.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2020 Blender Foundation. All rights reserved. */ -#include "BKE_asset_catalog_path.hh" +#include "AS_asset_catalog_path.hh" #include "BLI_set.hh" #include "BLI_vector.hh" @@ -11,7 +11,7 @@ #include "testing/testing.h" -namespace blender::bke::tests { +namespace blender::asset_system::tests { TEST(AssetCatalogPathTest, construction) { @@ -265,4 +265,4 @@ TEST(AssetCatalogPathTest, parent) EXPECT_EQ(empty.parent(), ""); } -} // namespace blender::bke::tests +} // namespace blender::asset_system::tests diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/asset_system/tests/asset_catalog_test.cc similarity index 99% rename from source/blender/blenkernel/intern/asset_catalog_test.cc rename to source/blender/asset_system/tests/asset_catalog_test.cc index ee2dd652b61..ba13cf8df07 100644 --- a/source/blender/blenkernel/intern/asset_catalog_test.cc +++ b/source/blender/asset_system/tests/asset_catalog_test.cc @@ -1,8 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2020 Blender Foundation. All rights reserved. */ +#include "AS_asset_catalog.hh" + #include "BKE_appdir.h" -#include "BKE_asset_catalog.hh" #include "BKE_preferences.h" #include "BLI_fileops.h" @@ -15,7 +16,7 @@ #include "testing/testing.h" -namespace blender::bke::tests { +namespace blender::asset_system::tests { /* UUIDs from lib/tests/asset_library/blender_assets.cats.txt */ const bUUID UUID_ID_WITHOUT_PATH("e34dd2c5-5d2e-4668-9794-1db5de2a4f71"); @@ -1538,4 +1539,4 @@ TEST_F(AssetCatalogTest, undo_redo_more_complex) EXPECT_EQ(service.find_catalog(UUID_POSES_ELLIE)->path, "character/Ellie/poselib"); /* Undone. */ } -} // namespace blender::bke::tests +} // namespace blender::asset_system::tests diff --git a/source/blender/blenkernel/intern/asset_library_service_test.cc b/source/blender/asset_system/tests/asset_library_service_test.cc similarity index 98% rename from source/blender/blenkernel/intern/asset_library_service_test.cc rename to source/blender/asset_system/tests/asset_library_service_test.cc index 18fdcb80155..a975e9c0631 100644 --- a/source/blender/blenkernel/intern/asset_library_service_test.cc +++ b/source/blender/asset_system/tests/asset_library_service_test.cc @@ -16,7 +16,7 @@ #include "testing/testing.h" -namespace blender::bke::tests { +namespace blender::asset_system::tests { const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78"); @@ -219,4 +219,4 @@ TEST_F(AssetLibraryServiceTest, has_any_unsaved_catalogs_after_write) EXPECT_FALSE(cat->flags.has_unsaved_changes); } -} // namespace blender::bke::tests +} // namespace blender::asset_system::tests diff --git a/source/blender/blenkernel/intern/asset_library_test.cc b/source/blender/asset_system/tests/asset_library_test.cc similarity index 78% rename from source/blender/blenkernel/intern/asset_library_test.cc rename to source/blender/asset_system/tests/asset_library_test.cc index 1d862e5e4d4..059f3d9a46c 100644 --- a/source/blender/blenkernel/intern/asset_library_test.cc +++ b/source/blender/asset_system/tests/asset_library_test.cc @@ -1,9 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2020 Blender Foundation. All rights reserved. */ +#include "AS_asset_catalog.hh" +#include "AS_asset_library.h" +#include "AS_asset_library.hh" + #include "BKE_appdir.h" -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.hh" #include "BKE_callbacks.h" #include "asset_library_service.hh" @@ -12,7 +14,7 @@ #include "testing/testing.h" -namespace blender::bke::tests { +namespace blender::asset_system::tests { class AssetLibraryTest : public testing::Test { public: @@ -29,11 +31,11 @@ class AssetLibraryTest : public testing::Test { void TearDown() override { - AssetLibraryService::destroy(); + asset_system::AssetLibraryService::destroy(); } }; -TEST_F(AssetLibraryTest, bke_asset_library_load) +TEST_F(AssetLibraryTest, AS_asset_library_load) { const std::string test_files_dir = blender::tests::flags_test_asset_dir(); if (test_files_dir.empty()) { @@ -42,11 +44,11 @@ TEST_F(AssetLibraryTest, bke_asset_library_load) /* Load the asset library. */ const std::string library_path = test_files_dir + "/" + "asset_library"; - ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); + ::AssetLibrary *library_c_ptr = AS_asset_library_load(library_path.data()); ASSERT_NE(nullptr, library_c_ptr); /* Check that it can be cast to the C++ type and has a Catalog Service. */ - blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast( + asset_system::AssetLibrary *library_cpp_ptr = reinterpret_cast( library_c_ptr); AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); ASSERT_NE(nullptr, service); @@ -70,11 +72,11 @@ TEST_F(AssetLibraryTest, load_nonexistent_directory) /* Load the asset library. */ const std::string library_path = test_files_dir + "/" + "asset_library/this/subdir/does/not/exist"; - ::AssetLibrary *library_c_ptr = BKE_asset_library_load(library_path.data()); + ::AssetLibrary *library_c_ptr = AS_asset_library_load(library_path.data()); ASSERT_NE(nullptr, library_c_ptr); /* Check that it can be cast to the C++ type and has a Catalog Service. */ - blender::bke::AssetLibrary *library_cpp_ptr = reinterpret_cast( + asset_system::AssetLibrary *library_cpp_ptr = reinterpret_cast( library_c_ptr); AssetCatalogService *service = library_cpp_ptr->catalog_service.get(); ASSERT_NE(nullptr, service); @@ -83,4 +85,4 @@ TEST_F(AssetLibraryTest, load_nonexistent_directory) EXPECT_TRUE(service->is_empty()); } -} // namespace blender::bke::tests +} // namespace blender::asset_system::tests diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h index bcbe19c0f3e..81a132a8f91 100644 --- a/source/blender/blenkernel/BKE_asset.h +++ b/source/blender/blenkernel/BKE_asset.h @@ -23,9 +23,6 @@ struct ID; struct IDProperty; struct PreviewImage; -/** C handle for #bke::AssetRepresentation. */ -typedef struct AssetRepresentation AssetRepresentation; - typedef void (*PreSaveFn)(void *asset_ptr, struct AssetMetaData *asset_data); typedef struct AssetTypeInfo { @@ -71,13 +68,6 @@ struct PreviewImage *BKE_asset_metadata_preview_get_from_id(const struct AssetMe void BKE_asset_metadata_write(struct BlendWriter *writer, struct AssetMetaData *asset_data); void BKE_asset_metadata_read(struct BlendDataReader *reader, struct AssetMetaData *asset_data); -const char *BKE_asset_representation_name_get(const AssetRepresentation *asset) - ATTR_WARN_UNUSED_RESULT; -AssetMetaData *BKE_asset_representation_metadata_get(const AssetRepresentation *asset) - ATTR_WARN_UNUSED_RESULT; -bool BKE_asset_representation_is_local_id(const AssetRepresentation *asset) - ATTR_WARN_UNUSED_RESULT; - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 6b8160aaeda..59d58ed2f98 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -3,6 +3,7 @@ set(INC . + ../asset_system ../blenfont ../blenlib ../blenloader @@ -71,11 +72,6 @@ set(SRC intern/armature_selection.cc intern/armature_update.c intern/asset.cc - intern/asset_catalog.cc - intern/asset_catalog_path.cc - intern/asset_library.cc - intern/asset_library_service.cc - intern/asset_representation.cc intern/attribute.cc intern/attribute_access.cc intern/attribute_math.cc @@ -322,11 +318,6 @@ set(SRC BKE_armature.h BKE_armature.hh BKE_asset.h - BKE_asset_catalog.hh - BKE_asset_catalog_path.hh - BKE_asset_library.h - BKE_asset_library.hh - BKE_asset_representation.hh BKE_attribute.h BKE_attribute.hh BKE_attribute_math.hh @@ -503,7 +494,6 @@ set(SRC intern/CCGSubSurf.h intern/CCGSubSurf_inline.h intern/CCGSubSurf_intern.h - intern/asset_library_service.hh intern/attribute_access_intern.hh intern/data_transfer_intern.h intern/lib_intern.h @@ -517,6 +507,7 @@ set(SRC ) set(LIB + bf_asset_system bf_blenfont bf_blenlib bf_blenloader @@ -834,11 +825,7 @@ if(WITH_GTESTS) set(TEST_SRC intern/action_test.cc intern/armature_test.cc - intern/asset_catalog_path_test.cc - intern/asset_catalog_test.cc - intern/asset_library_service_test.cc - intern/asset_library_test.cc - intern/asset_test.cc + intern/asset_metadata_test.cc intern/bpath_test.cc intern/cryptomatte_test.cc intern/curves_geometry_test.cc diff --git a/source/blender/blenkernel/intern/asset_test.cc b/source/blender/blenkernel/intern/asset_metadata_test.cc similarity index 100% rename from source/blender/blenkernel/intern/asset_test.cc rename to source/blender/blenkernel/intern/asset_metadata_test.cc diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 92b34b9e1af..45787a5e3a0 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -19,9 +19,10 @@ #include "BLI_linklist.h" #include "BLI_listbase.h" +#include "AS_asset_library.h" + #include "BKE_anim_data.h" #include "BKE_asset.h" -#include "BKE_asset_library.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_key.h" @@ -159,7 +160,7 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_i } } - BKE_asset_library_remap_ids(remapper); + AS_asset_library_remap_ids(remapper); BKE_id_remapper_free(remapper); BKE_libblock_free_data(id, (flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0); diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 5feb528b6bb..a4d05ebaffe 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -3,6 +3,7 @@ set(INC . ../include + ../../asset_system ../../blenkernel ../../blenlib ../../blenloader diff --git a/source/blender/editors/asset/ED_asset_catalog.hh b/source/blender/editors/asset/ED_asset_catalog.hh index 48ca58c6dc6..4d61f816085 100644 --- a/source/blender/editors/asset/ED_asset_catalog.hh +++ b/source/blender/editors/asset/ED_asset_catalog.hh @@ -3,8 +3,8 @@ /** \file * \ingroup edasset * - * UI/Editor level API for catalog operations, creating richer functionality than the BKE catalog - * API provides (which this uses internally). + * UI/Editor level API for catalog operations, creating richer functionality than the asset system + * catalog API provides (which this uses internally). * * Note that `ED_asset_catalog.h` is part of this API. */ @@ -13,22 +13,19 @@ #include -#include "BKE_asset_catalog.hh" +#include "AS_asset_catalog.hh" #include "BLI_string_ref.hh" struct AssetLibrary; -namespace blender::bke { -class AssetCatalog; -} // namespace blender::bke -blender::bke::AssetCatalog *ED_asset_catalog_add(AssetLibrary *library, - blender::StringRefNull name, - blender::StringRef parent_path = nullptr); -void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id); +blender::asset_system::AssetCatalog *ED_asset_catalog_add( + AssetLibrary *library, blender::StringRefNull name, blender::StringRef parent_path = nullptr); +void ED_asset_catalog_remove(AssetLibrary *library, + const blender::asset_system::CatalogID &catalog_id); void ED_asset_catalog_rename(AssetLibrary *library, - blender::bke::CatalogID catalog_id, + blender::asset_system::CatalogID catalog_id, blender::StringRefNull new_name); /** * Reinsert catalog identified by \a src_catalog_id as child to catalog identified by \a @@ -43,5 +40,5 @@ void ED_asset_catalog_rename(AssetLibrary *library, */ void ED_asset_catalog_move( AssetLibrary *library, - blender::bke::CatalogID src_catalog_id, - std::optional dst_parent_catalog_id = std::nullopt); + blender::asset_system::CatalogID src_catalog_id, + std::optional dst_parent_catalog_id = std::nullopt); diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc index 29aba1e2c90..10aa27a7687 100644 --- a/source/blender/editors/asset/intern/asset_catalog.cc +++ b/source/blender/editors/asset/intern/asset_catalog.cc @@ -4,8 +4,9 @@ * \ingroup edasset */ -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.hh" +#include "AS_asset_library.hh" + +#include "AS_asset_catalog.hh" #include "BKE_main.h" #include "BLI_string_utils.h" @@ -16,7 +17,7 @@ #include "WM_api.h" using namespace blender; -using namespace blender::bke; +using namespace blender::asset_system; struct CatalogUniqueNameFnData { const AssetCatalogService &catalog_service; @@ -43,11 +44,12 @@ static std::string catalog_name_ensure_unique(AssetCatalogService &catalog_servi return unique_name; } -AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library, - StringRefNull name, - StringRef parent_path) +asset_system::AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library, + StringRefNull name, + StringRef parent_path) { - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + asset_system::AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( + library); if (!catalog_service) { return nullptr; } @@ -56,7 +58,7 @@ AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library, AssetCatalogPath fullpath = AssetCatalogPath(parent_path) / unique_name; catalog_service->undo_push(); - bke::AssetCatalog *new_catalog = catalog_service->create_catalog(fullpath); + asset_system::AssetCatalog *new_catalog = catalog_service->create_catalog(fullpath); if (!new_catalog) { return nullptr; } @@ -68,7 +70,8 @@ AssetCatalog *ED_asset_catalog_add(::AssetLibrary *library, void ED_asset_catalog_remove(::AssetLibrary *library, const CatalogID &catalog_id) { - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + asset_system::AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( + library); if (!catalog_service) { BLI_assert_unreachable(); return; @@ -84,7 +87,8 @@ void ED_asset_catalog_rename(::AssetLibrary *library, const CatalogID catalog_id, const StringRefNull new_name) { - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + asset_system::AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( + library); if (!catalog_service) { BLI_assert_unreachable(); return; @@ -110,7 +114,8 @@ void ED_asset_catalog_move(::AssetLibrary *library, const CatalogID src_catalog_id, const std::optional dst_parent_catalog_id) { - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + asset_system::AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( + library); if (!catalog_service) { BLI_assert_unreachable(); return; @@ -150,7 +155,8 @@ void ED_asset_catalog_move(::AssetLibrary *library, void ED_asset_catalogs_save_from_main_path(::AssetLibrary *library, const Main *bmain) { - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + asset_system::AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( + library); if (!catalog_service) { BLI_assert_unreachable(); return; @@ -164,10 +170,10 @@ void ED_asset_catalogs_save_from_main_path(::AssetLibrary *library, const Main * void ED_asset_catalogs_set_save_catalogs_when_file_is_saved(const bool should_save) { - bke::AssetLibrary::save_catalogs_when_file_is_saved = should_save; + asset_system::AssetLibrary::save_catalogs_when_file_is_saved = should_save; } bool ED_asset_catalogs_get_save_catalogs_when_file_is_saved() { - return bke::AssetLibrary::save_catalogs_when_file_is_saved; + return asset_system::AssetLibrary::save_catalogs_when_file_is_saved; } diff --git a/source/blender/editors/asset/intern/asset_handle.cc b/source/blender/editors/asset/intern/asset_handle.cc index 0b2cd352d77..73686e02098 100644 --- a/source/blender/editors/asset/intern/asset_handle.cc +++ b/source/blender/editors/asset/intern/asset_handle.cc @@ -6,10 +6,9 @@ #include -#include "DNA_space_types.h" +#include "AS_asset_representation.h" -#include "BKE_asset.h" -#include "BKE_asset_representation.hh" +#include "DNA_space_types.h" #include "BLO_readfile.h" @@ -20,12 +19,12 @@ const char *ED_asset_handle_get_name(const AssetHandle *asset) { - return BKE_asset_representation_name_get(asset->file_data->asset); + return AS_asset_representation_name_get(asset->file_data->asset); } AssetMetaData *ED_asset_handle_get_metadata(const AssetHandle *asset_handle) { - return BKE_asset_representation_metadata_get(asset_handle->file_data->asset); + return AS_asset_representation_metadata_get(asset_handle->file_data->asset); } ID *ED_asset_handle_get_local_id(const AssetHandle *asset) diff --git a/source/blender/editors/asset/intern/asset_indexer.cc b/source/blender/editors/asset/intern/asset_indexer.cc index cc06fa80429..a604ab813d7 100644 --- a/source/blender/editors/asset/intern/asset_indexer.cc +++ b/source/blender/editors/asset/intern/asset_indexer.cc @@ -22,9 +22,9 @@ #include "BLI_string_ref.hh" #include "BLI_uuid.h" +#include "AS_asset_catalog.hh" #include "BKE_appdir.h" #include "BKE_asset.h" -#include "BKE_asset_catalog.hh" #include "BKE_idprop.hh" #include "BKE_preferences.h" @@ -34,8 +34,8 @@ static CLG_LogRef LOG = {"ed.asset"}; namespace blender::ed::asset::index { +using namespace blender::asset_system; using namespace blender::io::serialize; -using namespace blender::bke; using namespace blender::bke::idprop; /** diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index d1c46a8259f..da4e0794fe8 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -4,7 +4,9 @@ * \ingroup edasset */ -#include "BKE_asset_library.hh" +#include "AS_asset_library.h" +#include "AS_asset_library.hh" + #include "BKE_bpath.h" #include "BKE_context.h" #include "BKE_global.h" @@ -445,7 +447,7 @@ static int asset_catalog_new_exec(bContext *C, wmOperator *op) struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); char *parent_path = RNA_string_get_alloc(op->ptr, "parent_path", nullptr, 0, nullptr); - blender::bke::AssetCatalog *new_catalog = ED_asset_catalog_add( + blender::asset_system::AssetCatalog *new_catalog = ED_asset_catalog_add( asset_library, "Catalog", parent_path); if (sfile) { @@ -484,7 +486,7 @@ static int asset_catalog_delete_exec(bContext *C, wmOperator *op) SpaceFile *sfile = CTX_wm_space_file(C); struct AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); char *catalog_id_str = RNA_string_get_alloc(op->ptr, "catalog_id", nullptr, 0, nullptr); - bke::CatalogID catalog_id; + asset_system::CatalogID catalog_id; if (!BLI_uuid_parse_string(&catalog_id, catalog_id_str)) { return OPERATOR_CANCELLED; } @@ -515,7 +517,7 @@ static void ASSET_OT_catalog_delete(struct wmOperatorType *ot) RNA_def_string(ot->srna, "catalog_id", nullptr, 0, "Catalog ID", "ID of the catalog to delete"); } -static bke::AssetCatalogService *get_catalog_service(bContext *C) +static asset_system::AssetCatalogService *get_catalog_service(bContext *C) { const SpaceFile *sfile = CTX_wm_space_file(C); if (!sfile) { @@ -523,12 +525,12 @@ static bke::AssetCatalogService *get_catalog_service(bContext *C) } AssetLibrary *asset_lib = ED_fileselect_active_asset_library_get(sfile); - return BKE_asset_library_get_catalog_service(asset_lib); + return AS_asset_library_get_catalog_service(asset_lib); } static int asset_catalog_undo_exec(bContext *C, wmOperator * /*op*/) { - bke::AssetCatalogService *catalog_service = get_catalog_service(C); + asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); if (!catalog_service) { return OPERATOR_CANCELLED; } @@ -540,7 +542,7 @@ static int asset_catalog_undo_exec(bContext *C, wmOperator * /*op*/) static bool asset_catalog_undo_poll(bContext *C) { - const bke::AssetCatalogService *catalog_service = get_catalog_service(C); + const asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); return catalog_service && catalog_service->is_undo_possbile(); } @@ -558,7 +560,7 @@ static void ASSET_OT_catalog_undo(struct wmOperatorType *ot) static int asset_catalog_redo_exec(bContext *C, wmOperator * /*op*/) { - bke::AssetCatalogService *catalog_service = get_catalog_service(C); + asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); if (!catalog_service) { return OPERATOR_CANCELLED; } @@ -570,7 +572,7 @@ static int asset_catalog_redo_exec(bContext *C, wmOperator * /*op*/) static bool asset_catalog_redo_poll(bContext *C) { - const bke::AssetCatalogService *catalog_service = get_catalog_service(C); + const asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); return catalog_service && catalog_service->is_redo_possbile(); } @@ -588,7 +590,7 @@ static void ASSET_OT_catalog_redo(struct wmOperatorType *ot) static int asset_catalog_undo_push_exec(bContext *C, wmOperator * /*op*/) { - bke::AssetCatalogService *catalog_service = get_catalog_service(C); + asset_system::AssetCatalogService *catalog_service = get_catalog_service(C); if (!catalog_service) { return OPERATOR_CANCELLED; } @@ -631,7 +633,7 @@ static bool asset_catalogs_save_poll(bContext *C) return false; } - if (!BKE_asset_library_has_any_unsaved_catalogs()) { + if (!AS_asset_library_has_any_unsaved_catalogs()) { CTX_wm_operator_poll_msg_set(C, "No changes to be saved"); return false; } @@ -748,7 +750,7 @@ static int asset_bundle_install_exec(bContext *C, wmOperator *op) } WM_cursor_wait(true); - bke::AssetCatalogService *cat_service = get_catalog_service(C); + asset_system::AssetCatalogService *cat_service = get_catalog_service(C); /* Store undo step, such that on a failed save the 'prepare_to_merge_on_write' call can be * un-done. */ cat_service->undo_push(); diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 6a531c88762..56af318b2fa 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -3,6 +3,7 @@ set(INC . ../include + ../../asset_system ../../blenfont ../../blenkernel ../../blenlib diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt index 76564f38da8..ede48060126 100644 --- a/source/blender/editors/space_file/CMakeLists.txt +++ b/source/blender/editors/space_file/CMakeLists.txt @@ -3,6 +3,7 @@ set(INC ../asset ../include + ../../asset_system ../../blenfont ../../blenkernel ../../blenlib diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index fe2e46fc056..15f62da3f76 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -7,9 +7,10 @@ #include "DNA_space_types.h" +#include "AS_asset_library.hh" + +#include "AS_asset_catalog.hh" #include "BKE_asset.h" -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.hh" #include "BLI_string_ref.hh" @@ -33,7 +34,7 @@ #include "filelist.h" using namespace blender; -using namespace blender::bke; +using namespace blender::asset_system; namespace blender::ed::asset_browser { @@ -42,7 +43,7 @@ class AssetCatalogTreeViewAllItem; class AssetCatalogTreeView : public ui::AbstractTreeView { ::AssetLibrary *asset_library_; /** The asset catalog tree this tree-view represents. */ - bke::AssetCatalogTree *catalog_tree_; + asset_system::AssetCatalogTree *catalog_tree_; FileAssetSelectParams *params_; SpaceFile &space_file_; @@ -173,7 +174,7 @@ AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library, FileAssetSelectParams *params, SpaceFile &space_file) : asset_library_(library), - catalog_tree_(BKE_asset_library_get_catalog_tree(library)), + catalog_tree_(AS_asset_library_get_catalog_tree(library)), params_(params), space_file_(space_file) { @@ -486,7 +487,7 @@ AssetCatalog *AssetCatalogDropController::get_drag_catalog(const wmDrag &drag, if (drag.type != WM_DRAG_ASSET_CATALOG) { return nullptr; } - const bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service( + const AssetCatalogService *catalog_service = AS_asset_library_get_catalog_service( &asset_library); const wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag); @@ -708,7 +709,7 @@ bool file_set_asset_catalog_filter_settings( void file_ensure_updated_catalog_filter_data( FileAssetCatalogFilterSettingsHandle *filter_settings_handle, - const bke::AssetLibrary *asset_library) + const asset_system::AssetLibrary *asset_library) { AssetCatalogFilterSettings *filter_settings = reinterpret_cast( filter_settings_handle); diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 0ca09487507..f4577b960d3 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -225,7 +225,7 @@ void file_create_asset_catalog_tree_view_in_layout(struct AssetLibrary *asset_li #ifdef __cplusplus -namespace blender::bke { +namespace blender::asset_system { struct AssetLibrary; } @@ -242,7 +242,7 @@ bool file_set_asset_catalog_filter_settings( bUUID catalog_id); void file_ensure_updated_catalog_filter_data( FileAssetCatalogFilterSettingsHandle *filter_settings_handle, - const blender::bke::AssetLibrary *asset_library); + const blender::asset_system::AssetLibrary *asset_library); bool file_is_asset_visible_in_catalog_filter_settings( const FileAssetCatalogFilterSettingsHandle *filter_settings_handle, const AssetMetaData *asset_data); diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index c4d99d41a60..22c94065234 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -19,6 +19,11 @@ # include # include #endif + +#include "AS_asset_library.h" +#include "AS_asset_library.hh" +#include "AS_asset_representation.hh" + #include "MEM_guardedalloc.h" #include "BLF_api.h" @@ -42,9 +47,6 @@ #endif #include "BKE_asset.h" -#include "BKE_asset_library.h" -#include "BKE_asset_library.hh" -#include "BKE_asset_representation.hh" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_icons.h" @@ -117,7 +119,7 @@ struct FileListInternEntry { } local_data; /* References an asset in the asset library storage. */ - bke::AssetRepresentation *asset; /* Non-owning. */ + asset_system::AssetRepresentation *asset; /* Non-owning. */ /* See #FILE_ENTRY_BLENDERLIB_NO_PREVIEW. */ bool blenderlib_has_no_preview; @@ -213,7 +215,7 @@ struct FileList { eFileSelectType type; /* The library this list was created for. Stored here so we know when to re-read. */ AssetLibraryReference *asset_library_ref; - bke::AssetLibrary *asset_library; /* Non-owning. */ + asset_system::AssetLibrary *asset_library; /* Non-owning. */ short flags; @@ -3672,8 +3674,8 @@ static void filelist_readjob_load_asset_library_data(FileListReadJob *job_params /* Load asset catalogs, into the temp filelist for thread-safety. * #filelist_readjob_endjob() will move it into the real filelist. */ - tmp_filelist->asset_library = BKE_asset_library_load(job_params->current_main, - *job_params->filelist->asset_library_ref); + tmp_filelist->asset_library = AS_asset_library_load(job_params->current_main, + *job_params->filelist->asset_library_ref); *do_update = true; } diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index ff9e5352d0a..f8289b42463 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -2,6 +2,7 @@ set(INC ../include + ../../asset_system ../../blenfont ../../blenkernel ../../blenlib diff --git a/source/blender/editors/space_node/add_menu_assets.cc b/source/blender/editors/space_node/add_menu_assets.cc index 5458a25d74a..c4cd5819d60 100644 --- a/source/blender/editors/space_node/add_menu_assets.cc +++ b/source/blender/editors/space_node/add_menu_assets.cc @@ -1,13 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "AS_asset_catalog.hh" +#include "AS_asset_library.hh" + #include "BLI_multi_value_map.hh" #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "BKE_asset.h" -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.hh" #include "BKE_idprop.h" #include "BKE_screen.h" @@ -48,19 +49,20 @@ struct LibraryAsset { }; struct LibraryCatalog { - bke::AssetLibrary *library; - const bke::AssetCatalog *catalog; + asset_system::AssetLibrary *library; + const asset_system::AssetCatalog *catalog; }; struct AssetItemTree { - bke::AssetCatalogTree catalogs; - MultiValueMap assets_per_path; - Map full_catalog_per_tree_item; + asset_system::AssetCatalogTree catalogs; + MultiValueMap assets_per_path; + Map + full_catalog_per_tree_item; }; static bool all_loading_finished() { - for (const AssetLibraryReference &library : bke::all_valid_asset_library_refs()) { + for (const AssetLibraryReference &library : asset_system::all_valid_asset_library_refs()) { if (!ED_assetlist_is_loaded(&library)) { return false; } @@ -74,19 +76,19 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node return {}; } const Main &bmain = *CTX_data_main(&C); - const Vector all_libraries = bke::all_valid_asset_library_refs(); + const Vector all_libraries = asset_system::all_valid_asset_library_refs(); /* Merge catalogs from all libraries to deduplicate menu items. Also store the catalog and * library for each asset ID in order to use them later when retrieving assets and removing * empty catalogs. */ - Map id_to_catalog_map; - bke::AssetCatalogTree catalogs_from_all_libraries; + Map id_to_catalog_map; + asset_system::AssetCatalogTree catalogs_from_all_libraries; for (const AssetLibraryReference &library_ref : all_libraries) { - if (bke::AssetLibrary *library = BKE_asset_library_load(&bmain, library_ref)) { - if (bke::AssetCatalogTree *tree = library->catalog_service->get_catalog_tree()) { - tree->foreach_item([&](bke::AssetCatalogTreeItem &item) { - const bke::CatalogID &id = item.get_catalog_id(); - bke::AssetCatalog *catalog = library->catalog_service->find_catalog(id); + if (asset_system::AssetLibrary *library = AS_asset_library_load(&bmain, library_ref)) { + if (asset_system::AssetCatalogTree *tree = library->catalog_service->get_catalog_tree()) { + tree->foreach_item([&](asset_system::AssetCatalogTreeItem &item) { + const asset_system::CatalogID &id = item.get_catalog_id(); + asset_system::AssetCatalog *catalog = library->catalog_service->find_catalog(id); catalogs_from_all_libraries.insert_item(*catalog); id_to_catalog_map.add(item.get_catalog_id(), LibraryCatalog{library, catalog}); }); @@ -95,7 +97,7 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node } /* Find all the matching node group assets for every catalog path. */ - MultiValueMap assets_per_path; + MultiValueMap assets_per_path; for (const AssetLibraryReference &library_ref : all_libraries) { AssetFilterSettings type_filter{}; type_filter.id_types = FILTER_ID_NT; @@ -124,21 +126,23 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node } /* Build the final tree without any of the catalogs that don't have proper node group assets. */ - bke::AssetCatalogTree catalogs_with_node_assets; - catalogs_from_all_libraries.foreach_item([&](bke::AssetCatalogTreeItem &item) { + asset_system::AssetCatalogTree catalogs_with_node_assets; + catalogs_from_all_libraries.foreach_item([&](asset_system::AssetCatalogTreeItem &item) { if (!assets_per_path.lookup(item.catalog_path()).is_empty()) { - const bke::CatalogID &id = item.get_catalog_id(); + const asset_system::CatalogID &id = item.get_catalog_id(); const LibraryCatalog &library_catalog = id_to_catalog_map.lookup(id); - bke::AssetCatalog *catalog = library_catalog.library->catalog_service->find_catalog(id); + asset_system::AssetCatalog *catalog = library_catalog.library->catalog_service->find_catalog( + id); catalogs_with_node_assets.insert_item(*catalog); } }); /* Build another map storing full asset paths for each tree item, in order to have stable * pointers to asset catalog paths to use for context pointers. This is necessary because - * #bke::AssetCatalogTreeItem doesn't store its full path directly. */ - Map full_catalog_per_tree_item; - catalogs_with_node_assets.foreach_item([&](bke::AssetCatalogTreeItem &item) { + * #asset_system::AssetCatalogTreeItem doesn't store its full path directly. */ + Map + full_catalog_per_tree_item; + catalogs_with_node_assets.foreach_item([&](asset_system::AssetCatalogTreeItem &item) { full_catalog_per_tree_item.add_new(&item, item.catalog_path()); }); @@ -165,11 +169,11 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu) if (RNA_pointer_is_null(&menu_path_ptr)) { return; } - const bke::AssetCatalogPath &menu_path = *static_cast( - menu_path_ptr.data); + const asset_system::AssetCatalogPath &menu_path = + *static_cast(menu_path_ptr.data); const Span asset_items = tree.assets_per_path.lookup(menu_path); - bke::AssetCatalogTreeItem *catalog_item = tree.catalogs.find_item(menu_path); + asset_system::AssetCatalogTreeItem *catalog_item = tree.catalogs.find_item(menu_path); BLI_assert(catalog_item != nullptr); if (asset_items.is_empty() && !catalog_item->has_children()) { @@ -193,10 +197,11 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu) uiItemO(col, ED_asset_handle_get_name(&item.handle), ICON_NONE, "NODE_OT_add_group_asset"); } - catalog_item->foreach_child([&](bke::AssetCatalogTreeItem &child_item) { - const bke::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup(&child_item); + catalog_item->foreach_child([&](asset_system::AssetCatalogTreeItem &child_item) { + const asset_system::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup( + &child_item); PointerRNA path_ptr{ - &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; + &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; uiLayout *col = uiLayoutColumn(layout, false); uiLayoutSetContextPointer(col, "asset_catalog_path", &path_ptr); uiItemM(col, "NODE_MT_node_add_catalog_assets", path.name().c_str(), ICON_NONE); @@ -260,13 +265,13 @@ static void add_root_catalogs_draw(const bContext *C, Menu *menu) return menus; }(); - tree.catalogs.foreach_root_item([&](bke::AssetCatalogTreeItem &item) { + tree.catalogs.foreach_root_item([&](asset_system::AssetCatalogTreeItem &item) { if (all_builtin_menus.contains(item.get_name())) { return; } - const bke::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup(&item); + const asset_system::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup(&item); PointerRNA path_ptr{ - &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; + &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; uiLayout *col = uiLayoutColumn(layout, false); uiLayoutSetContextPointer(col, "asset_catalog_path", &path_ptr); uiItemM(col, "NODE_MT_node_add_catalog_assets", path.name().c_str(), ICON_NONE); @@ -303,13 +308,13 @@ void uiTemplateNodeAssetMenuItems(uiLayout *layout, bContext *C, const char *cat bScreen &screen = *CTX_wm_screen(C); SpaceNode &snode = *CTX_wm_space_node(C); AssetItemTree &tree = *snode.runtime->assets_for_menu; - const bke::AssetCatalogTreeItem *item = tree.catalogs.find_root_item(catalog_path); + const asset_system::AssetCatalogTreeItem *item = tree.catalogs.find_root_item(catalog_path); if (!item) { return; } - const bke::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup(item); + const asset_system::AssetCatalogPath &path = tree.full_catalog_per_tree_item.lookup(item); PointerRNA path_ptr{ - &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; + &screen.id, &RNA_AssetCatalogPath, const_cast(&path)}; uiItemS(layout); uiLayout *col = uiLayoutColumn(layout, false); uiLayoutSetContextPointer(col, "asset_catalog_path", &path_ptr); diff --git a/source/blender/editors/space_node/add_node_search.cc b/source/blender/editors/space_node/add_node_search.cc index 28e18c20f46..adeddfd115d 100644 --- a/source/blender/editors/space_node/add_node_search.cc +++ b/source/blender/editors/space_node/add_node_search.cc @@ -2,14 +2,15 @@ #include +#include "AS_asset_catalog.hh" +#include "AS_asset_library.hh" + #include "BLI_listbase.h" #include "BLI_string_search.h" #include "DNA_space_types.h" #include "BKE_asset.h" -#include "BKE_asset_catalog.hh" -#include "BKE_asset_library.hh" #include "BKE_context.h" #include "BKE_idprop.h" #include "BKE_lib_id.h" diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 128cb897ac4..8430f69b632 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -3,6 +3,7 @@ set(INC ../include ../space_sequencer + ../../asset_system ../../blenfont ../../blenkernel ../../blenlib diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 5c2bdc214d1..f370d47b3f7 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -187,6 +187,7 @@ set(SRC set(INC . .. + ../../asset_system ../../blenfont ../../blenkernel ../../blenlib diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c index 3c7eb3d208f..d844c419835 100644 --- a/source/blender/makesrna/intern/rna_asset.c +++ b/source/blender/makesrna/intern/rna_asset.c @@ -17,8 +17,9 @@ #ifdef RNA_RUNTIME +# include "AS_asset_library.h" + # include "BKE_asset.h" -# include "BKE_asset_library.h" # include "BKE_context.h" # include "BKE_idprop.h" @@ -251,7 +252,7 @@ void rna_AssetMetaData_catalog_id_update(struct bContext *C, struct PointerRNA * } AssetMetaData *asset_data = ptr->data; - BKE_asset_library_refresh_catalog_simplename(asset_library, asset_data); + AS_asset_library_refresh_catalog_simplename(asset_library, asset_data); } static PointerRNA rna_AssetHandle_file_data_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index b0311d63d44..c35917bd714 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -530,6 +530,8 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = { #ifdef RNA_RUNTIME +# include "AS_asset_representation.h" + # include "DNA_anim_types.h" # include "DNA_asset_types.h" # include "DNA_scene_types.h" @@ -540,7 +542,6 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = { # include "BLI_string.h" # include "BKE_anim_data.h" -# include "BKE_asset.h" # include "BKE_brush.h" # include "BKE_colortools.h" # include "BKE_context.h" @@ -2766,14 +2767,14 @@ static PointerRNA rna_FileBrowser_FileSelectEntry_asset_data_get(PointerRNA *ptr return PointerRNA_NULL; } - AssetMetaData *asset_data = BKE_asset_representation_metadata_get(entry->asset); + AssetMetaData *asset_data = AS_asset_representation_metadata_get(entry->asset); /* Note that the owning ID of the RNA pointer (`ptr->owner_id`) has to be set carefully: * Local IDs (`entry->id`) own their asset metadata themselves. Asset metadata from other blend * files are owned by the file browser (`entry`). Only if this is set correctly, we can tell from * the metadata RNA pointer if the metadata is stored locally and can thus be edited or not. */ - if (BKE_asset_representation_is_local_id(entry->asset)) { + if (AS_asset_representation_is_local_id(entry->asset)) { PointerRNA id_ptr; RNA_id_pointer_create(entry->id, &id_ptr); return rna_pointer_inherit_refine(&id_ptr, &RNA_AssetMetaData, asset_data); diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 9da150e0b7a..3ab024841e8 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -5,6 +5,7 @@ set(INC . gizmo gizmo/intern + ../asset_system ../blenfont ../blenkernel ../blenlib diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index b009a67efba..bdac91e990c 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -57,9 +57,10 @@ #include "DNA_windowmanager_types.h" #include "DNA_workspace_types.h" +#include "AS_asset_library.h" + #include "BKE_addon.h" #include "BKE_appdir.h" -#include "BKE_asset_library.h" #include "BKE_autoexec.h" #include "BKE_blender.h" #include "BKE_blendfile.h" @@ -159,7 +160,7 @@ void WM_file_tag_modified(void) bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm) { return !wm->file_saved || ED_image_should_save_modified(bmain) || - BKE_asset_library_has_any_unsaved_catalogs(); + AS_asset_library_has_any_unsaved_catalogs(); } /** \} */ @@ -3746,7 +3747,7 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C, has_extra_checkboxes = true; } - if (BKE_asset_library_has_any_unsaved_catalogs()) { + if (AS_asset_library_has_any_unsaved_catalogs()) { static char save_catalogs_when_file_is_closed; save_catalogs_when_file_is_closed = ED_asset_catalogs_get_save_catalogs_when_file_is_saved();