[Bf-blender-cvs] [f0eba2fe6c2] blender-projects-basics: Merge branch 'master' into blender-projects-basics
Julian Eisel
noreply at git.blender.org
Tue Jan 10 16:24:04 CET 2023
Commit: f0eba2fe6c2a7d2d0d44b27c595b14b43956d26e
Author: Julian Eisel
Date: Tue Jan 10 15:54:27 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rBf0eba2fe6c2a7d2d0d44b27c595b14b43956d26e
Merge branch 'master' into blender-projects-basics
===================================================================
===================================================================
diff --cc source/blender/asset_system/intern/asset_library_service.cc
index 41d44867d7e,af48a173bc0..acfb49770cd
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@@ -56,26 -57,31 +57,32 @@@ void AssetLibraryService::destroy(
AssetLibrary *AssetLibraryService::get_asset_library(
const Main *bmain, const AssetLibraryReference &library_reference)
{
- 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 ? AS_asset_library_find_suitable_root_path_from_main(bmain) : "";
-
- if (root_path.empty()) {
- /* File wasn't saved yet. */
- return get_asset_library_current_file();
+ const eAssetLibraryType type = eAssetLibraryType(library_reference.type);
+
+ switch (type) {
+ case ASSET_LIBRARY_LOCAL: {
+ /* For the "Current File" library we get the asset library root path based on main. */
+ std::string root_path = bmain ? AS_asset_library_find_suitable_root_path_from_main(bmain) :
+ "";
+
+ if (root_path.empty()) {
+ /* File wasn't saved yet. */
+ return get_asset_library_current_file();
+ }
+ return get_asset_library_on_disk(root_path);
}
-
- return get_asset_library_on_disk(root_path);
- }
- if (library_reference.type == 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) {
- return get_asset_library_on_disk(user_library->path);
+ case ASSET_LIBRARY_ALL:
+ return get_asset_library_all(bmain);
- case ASSET_LIBRARY_CUSTOM: {
++ case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES: {
+ std::string root_path = root_path_from_library_ref(library_reference);
+
+ if (!root_path.empty()) {
+ return get_asset_library_on_disk(root_path);
+ }
+ break;
}
}
+ /* TODO project libraries */
return nullptr;
}
diff --cc source/blender/editors/asset/ED_asset_library.h
index c5f526e18d5,c4baadc23c8..4746e0bb3e7
--- a/source/blender/editors/asset/ED_asset_library.h
+++ b/source/blender/editors/asset/ED_asset_library.h
@@@ -29,13 -29,14 +29,16 @@@ AssetLibraryReference ED_asset_library_
* Since this is meant for UI display, skips non-displayable libraries, that is, libraries with an
* empty name or path.
*
- * \param include_local_library: Whether to include the "Current File" library or not.
+ * \param include_generated: Whether to include libraries that are generated and thus cannot be
+ * written to. Setting this to false means only custom libraries will be
+ * included, since they are stored on disk with a single root directory,
+ * thus have a well defined location that can be written to.
*/
const struct EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(
- bool include_local_library);
+ bool include_generated);
+struct CustomAssetLibraryDefinition *ED_asset_library_find_custom_library_from_reference(
+ const AssetLibraryReference *library_ref);
#ifdef __cplusplus
}
#endif
diff --cc source/blender/editors/asset/intern/asset_library_reference_enum.cc
index 7d75dc83854,d20f3205a77..0bbc2b81038
--- a/source/blender/editors/asset/intern/asset_library_reference_enum.cc
+++ b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
@@@ -44,10 -44,10 +44,10 @@@ AssetLibraryReference ED_asset_library_
AssetLibraryReference library;
/* Simple case: Predefined repository, just set the value. */
- if (value < ASSET_LIBRARY_CUSTOM) {
+ if (value < ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES) {
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;
}
@@@ -74,35 -70,7 +74,34 @@@
return library;
}
+static void add_custom_asset_library_enum_items(
+ const ListBase * /*CustomAssetLibraryDefinition*/ libraries,
+ const eAssetLibraryType library_type,
+ EnumPropertyItem **items,
+ int *totitem)
+{
+ int i;
+ LISTBASE_FOREACH_INDEX (CustomAssetLibraryDefinition *, custom_library, libraries, i) {
+ /* Note that the path itself isn't checked for validity here. If an invalid library path is
+ * used, the Asset Browser can give a nice hint on what's wrong. */
+ const bool is_valid = (custom_library->name[0] && custom_library->path[0]);
+ if (!is_valid) {
+ continue;
+ }
+
+ AssetLibraryReference library_reference;
+ library_reference.type = library_type;
+ library_reference.custom_library_index = i;
+
+ const int enum_value = ED_asset_library_reference_to_enum_value(&library_reference);
+ /* Use library path as description, it's a nice hint for users. */
+ EnumPropertyItem tmp = {
+ enum_value, custom_library->name, ICON_NONE, custom_library->name, custom_library->path};
+ RNA_enum_item_add(items, totitem, &tmp);
+ }
+}
+
- const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(
- const bool include_local_library)
+ const EnumPropertyItem *ED_asset_library_reference_to_rna_enum_itemf(const bool include_generated)
{
EnumPropertyItem *item = nullptr;
int totitem = 0;
@@@ -119,25 -90,34 +121,26 @@@
{0, nullptr, 0, nullptr, nullptr},
};
- /* Add predefined items. */
- RNA_enum_items_add(&item, &totitem, predefined_items);
+ /* Add predefined libraries that are generated and not simple directories that can be written
+ * to. */
+ RNA_enum_items_add(&item, &totitem, generated_items);
}
- /* Add separator if needed. */
- if (!BLI_listbase_is_empty(&U.asset_libraries)) {
+ BlenderProject *project = CTX_wm_project();
+ if (project && !BLI_listbase_is_empty(BKE_project_custom_asset_libraries_get(project))) {
RNA_enum_item_add_separator(&item, &totitem);
- }
- int i;
- LISTBASE_FOREACH_INDEX (bUserAssetLibrary *, user_library, &U.asset_libraries, i) {
- /* Note that the path itself isn't checked for validity here. If an invalid library path is
- * used, the Asset Browser can give a nice hint on what's wrong. */
- const bool is_valid = (user_library->name[0] && user_library->path[0]);
- if (!is_valid) {
- continue;
- }
+ add_custom_asset_library_enum_items(BKE_project_custom_asset_libraries_get(project),
+ ASSET_LIBRARY_CUSTOM_FROM_PROJECT,
+ &item,
+ &totitem);
+ }
- AssetLibraryReference library_reference;
- library_reference.type = ASSET_LIBRARY_CUSTOM;
- library_reference.custom_library_index = i;
+ if (!BLI_listbase_is_empty(&U.asset_libraries)) {
+ RNA_enum_item_add_separator(&item, &totitem);
- const int enum_value = ED_asset_library_reference_to_enum_value(&library_reference);
- /* Use library path as description, it's a nice hint for users. */
- EnumPropertyItem tmp = {
- enum_value, user_library->name, ICON_NONE, user_library->name, user_library->path};
- RNA_enum_item_add(&item, &totitem, &tmp);
+ add_custom_asset_library_enum_items(
+ &U.asset_libraries, ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES, &item, &totitem);
}
RNA_enum_item_end(&item, &totitem);
diff --cc source/blender/editors/asset/intern/asset_list.cc
index 8bb078ded74,64934316413..b23223ed02b
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@@ -12,7 -12,8 +12,9 @@@
#include <optional>
#include <string>
+ #include "AS_asset_library.hh"
+
+#include "BKE_blender_project.h"
#include "BKE_context.h"
#include "BLI_map.hh"
@@@ -152,23 -152,10 +153,20 @@@ void AssetList::setup(
filelist_setindexer(files, use_asset_indexer ? &file_indexer_asset : &file_indexer_noop);
char path[FILE_MAXDIR] = "";
- if (custom_library) {
- /* 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);
- }
- else {
- BLI_strncpy(path, custom_library->path, sizeof(path));
- }
- filelist_setdir(files, path);
++#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);
+ }
- else {
- filelist_setdir(files, path);
++#endif
+ 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)
@@@ -377,9 -369,10 +380,11 @@@ void AssetListStorage::remapID(ID *id_n
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:
+ case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES:
+ case ASSET_LIBRARY_CUSTOM_FROM_PROJECT:
return FILE_ASSET_LIBRARY;
case ASSET_LIBRARY_LOCAL:
return FIL
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list