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:
-rw-r--r--source/blender/editors/asset/CMakeLists.txt2
-rw-r--r--source/blender/editors/asset/ED_asset_filter.h35
-rw-r--r--source/blender/editors/asset/ED_asset_list.h1
-rw-r--r--source/blender/editors/asset/intern/asset_filter.cc64
-rw-r--r--source/blender/editors/asset/intern/asset_list.cc27
-rw-r--r--source/blender/editors/include/ED_asset.h1
-rw-r--r--source/blender/editors/interface/interface_template_asset_view.cc11
-rw-r--r--source/blender/makesdna/DNA_asset_types.h3
8 files changed, 121 insertions, 23 deletions
diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt
index 2e25be51781..7e578b78809 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC_SYS
)
set(SRC
+ intern/asset_filter.cc
intern/asset_handle.cc
intern/asset_library_reference.cc
intern/asset_library_reference_enum.cc
@@ -39,6 +40,7 @@ set(SRC
intern/asset_ops.cc
intern/asset_temp_id_consumer.cc
+ ED_asset_filter.h
ED_asset_handle.h
ED_asset_library.h
ED_asset_list.h
diff --git a/source/blender/editors/asset/ED_asset_filter.h b/source/blender/editors/asset/ED_asset_filter.h
new file mode 100644
index 00000000000..fb2d3bfb273
--- /dev/null
+++ b/source/blender/editors/asset/ED_asset_filter.h
@@ -0,0 +1,35 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AssetHandle;
+struct AssetFilterSettings;
+
+bool ED_asset_filter_matches_asset(const struct AssetFilterSettings *filter,
+ const struct AssetHandle *asset);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index 1e7f0f0de55..55a0ac0b500 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -32,7 +32,6 @@ struct ID;
struct wmNotifier;
void ED_assetlist_storage_fetch(const struct AssetLibraryReference *library_reference,
- const struct AssetFilterSettings *filter_settings,
const struct bContext *C);
void ED_assetlist_ensure_previews_job(const struct AssetLibraryReference *library_reference,
struct bContext *C);
diff --git a/source/blender/editors/asset/intern/asset_filter.cc b/source/blender/editors/asset/intern/asset_filter.cc
new file mode 100644
index 00000000000..397df33d596
--- /dev/null
+++ b/source/blender/editors/asset/intern/asset_filter.cc
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#include "BKE_idtype.h"
+
+#include "BLI_listbase.h"
+
+#include "DNA_ID.h"
+#include "DNA_asset_types.h"
+
+#include "ED_asset_filter.h"
+#include "ED_asset_handle.h"
+
+/**
+ * Compare \a asset against the settings of \a filter.
+ *
+ * Individual filter parameters are ORed with the asset properties. That means:
+ * * The asset type must be one of the ID types filtered by, and
+ * * The asset must contain at least one of the tags filtered by.
+ * However for an asset to be matching it must have one match in each of the parameters. I.e. one
+ * matching type __and__ at least one matching tag.
+ *
+ * \returns True if the asset should be visible with these filter settings (parameters match).
+ * Otherwise returns false (mismatch).
+ */
+bool ED_asset_filter_matches_asset(const AssetFilterSettings *filter, const AssetHandle *asset)
+{
+ ID_Type asset_type = ED_asset_handle_get_id_type(asset);
+ uint64_t asset_id_filter = BKE_idtype_idcode_to_idfilter(asset_type);
+
+ if ((filter->id_types & asset_id_filter) == 0) {
+ return false;
+ }
+ /* Not very efficient (O(n^2)), could be improved quite a bit. */
+ LISTBASE_FOREACH (const AssetTag *, filter_tag, &filter->tags) {
+ AssetMetaData *asset_data = ED_asset_handle_get_metadata(asset);
+
+ AssetTag *matched_tag = (AssetTag *)BLI_findstring(
+ &asset_data->tags, filter_tag->name, offsetof(AssetTag, name));
+ if (matched_tag == nullptr) {
+ return false;
+ }
+ }
+
+ /* Succesfully passed through all filters. */
+ return true;
+}
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index d94a2bbf438..57c25e1614b 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -122,7 +122,7 @@ class AssetList : NonCopyable {
AssetList(AssetList &&other) = default;
~AssetList() = default;
- void setup(const AssetFilterSettings *filter_settings = nullptr);
+ void setup();
void fetch(const bContext &C);
void ensurePreviewsJob(bContext *C);
void clear(bContext *C);
@@ -141,7 +141,7 @@ AssetList::AssetList(eFileSelectType filesel_type, const AssetLibraryReference &
{
}
-void AssetList::setup(const AssetFilterSettings *filter_settings)
+void AssetList::setup()
{
FileList *files = filelist_;
@@ -160,17 +160,13 @@ void AssetList::setup(const AssetFilterSettings *filter_settings)
filelist_setrecursion(files, 1);
filelist_setsorting(files, FILE_SORT_ALPHA, false);
filelist_setlibrary(files, &library_ref_);
- /* TODO different filtering settings require the list to be reread. That's a no-go for when we
- * want to allow showing the same asset library with different filter settings (as in,
- * different ID types). The filelist needs to be made smarter somehow, maybe goes together with
- * the plan to separate the view (preview caching, filtering, etc. ) from the data. */
filelist_setfilter_options(
files,
- filter_settings != nullptr,
+ false,
true,
true, /* Just always hide parent, prefer to not add an extra user option for this. */
FILE_TYPE_BLENDERLIB,
- filter_settings ? filter_settings->id_types : FILTER_ID_ALL,
+ FILTER_ID_ALL,
true,
"",
"");
@@ -333,9 +329,7 @@ class AssetListStorage {
/* Purely static class, can't instantiate this. */
AssetListStorage() = delete;
- static void fetch_library(const AssetLibraryReference &library_reference,
- const bContext &C,
- const AssetFilterSettings *filter_settings = nullptr);
+ static void fetch_library(const AssetLibraryReference &library_reference, const bContext &C);
static void destruct();
static AssetList *lookup_list(const AssetLibraryReference &library_ref);
static void tagMainDataDirty();
@@ -353,8 +347,7 @@ class AssetListStorage {
};
void AssetListStorage::fetch_library(const AssetLibraryReference &library_reference,
- const bContext &C,
- const AssetFilterSettings *filter_settings)
+ const bContext &C)
{
std::optional filesel_type = asset_library_reference_to_fileselect_type(library_reference);
if (!filesel_type) {
@@ -363,7 +356,7 @@ void AssetListStorage::fetch_library(const AssetLibraryReference &library_refere
auto [list, is_new] = ensure_list_storage(library_reference, *filesel_type);
if (is_new || list.needsRefetch()) {
- list.setup(filter_settings);
+ list.setup();
list.fetch(C);
}
}
@@ -440,11 +433,9 @@ using namespace blender::ed::asset;
* Invoke asset list reading, potentially in a parallel job. Won't wait until the job is done,
* and may return earlier.
*/
-void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference,
- const AssetFilterSettings *filter_settings,
- const bContext *C)
+void ED_assetlist_storage_fetch(const AssetLibraryReference *library_reference, const bContext *C)
{
- AssetListStorage::fetch_library(*library_reference, *C, filter_settings);
+ AssetListStorage::fetch_library(*library_reference, *C);
}
void ED_assetlist_ensure_previews_job(const AssetLibraryReference *library_reference, bContext *C)
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index 42faf716560..8f19c97e671 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -36,6 +36,7 @@ void ED_operatortypes_asset(void);
}
#endif
+#include "../asset/ED_asset_filter.h"
#include "../asset/ED_asset_handle.h"
#include "../asset/ED_asset_library.h"
#include "../asset/ED_asset_list.h"
diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc
index 8babea5d18c..b4ba6a7feab 100644
--- a/source/blender/editors/interface/interface_template_asset_view.cc
+++ b/source/blender/editors/interface/interface_template_asset_view.cc
@@ -154,6 +154,7 @@ uiListType *UI_UL_asset_view()
static void asset_view_template_refresh_asset_collection(
const AssetLibraryReference &asset_library,
+ const AssetFilterSettings &filter_settings,
PointerRNA &assets_dataptr,
const char *assets_propname)
{
@@ -175,6 +176,11 @@ static void asset_view_template_refresh_asset_collection(
RNA_property_collection_clear(&assets_dataptr, assets_prop);
ED_assetlist_iterate(&asset_library, [&](AssetHandle asset) {
+ if (!ED_asset_filter_matches_asset(&filter_settings, &asset)) {
+ /* Don't do anything else, but return true to continue iterating. */
+ return true;
+ }
+
PointerRNA itemptr, fileptr;
RNA_property_collection_add(&assets_dataptr, assets_prop, &itemptr);
@@ -219,11 +225,12 @@ void uiTemplateAssetView(uiLayout *layout,
uiItemO(row, "", ICON_FILE_REFRESH, "ASSET_OT_list_refresh");
}
- ED_assetlist_storage_fetch(&asset_library, filter_settings, C);
+ ED_assetlist_storage_fetch(&asset_library, C);
ED_assetlist_ensure_previews_job(&asset_library, C);
const int tot_items = ED_assetlist_size(&asset_library);
- asset_view_template_refresh_asset_collection(asset_library, *assets_dataptr, assets_propname);
+ asset_view_template_refresh_asset_collection(
+ asset_library, *filter_settings, *assets_dataptr, assets_propname);
AssetViewListData *list_data = (AssetViewListData *)MEM_mallocN(sizeof(*list_data),
"AssetViewListData");
diff --git a/source/blender/makesdna/DNA_asset_types.h b/source/blender/makesdna/DNA_asset_types.h
index 316f8631ece..ca16e6728dd 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -41,8 +41,7 @@ typedef struct AssetTag {
#
typedef struct AssetFilterSettings {
/** Tags to match against. These are newly allocated, and compared against the
- * #AssetMetaData.tags.
- * TODO not used and doesn't do anything yet. */
+ * #AssetMetaData.tags. */
ListBase tags; /* AssetTag */
uint64_t id_types; /* rna_enum_id_type_filter_items */
} AssetFilterSettings;