diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index a6a96df87a4..02a26c5bd27 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -8433,7 +8433,7 @@ class VIEW3D_AST_sculpt_brushes(bpy.types.AssetShelf): @classmethod def asset_poll(cls, asset): - return asset.file_data.id_type == 'BRUSH' + return asset.id_type == 'BRUSH' classes = ( diff --git a/scripts/templates_py/ui_asset_shelf.py b/scripts/templates_py/ui_asset_shelf.py index f35b6225c12..36803b06a5f 100644 --- a/scripts/templates_py/ui_asset_shelf.py +++ b/scripts/templates_py/ui_asset_shelf.py @@ -11,7 +11,7 @@ class MyAssetShelf(bpy.types.AssetShelf): @classmethod def asset_poll(cls, asset): - return asset.file_data.id_type in {'MATERIAL', 'OBJECT'} + return asset.id_type in {'MATERIAL', 'OBJECT'} def register(): diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 9d60a9fe199..cd80ee80cc3 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -13,6 +13,15 @@ #include "BKE_context.h" +#ifdef __cplusplus +namespace blender::asset_system { +class AssetRepresentation; +} +using AssetRepresentationHandle = blender::asset_system::AssetRepresentation; +#else +typedef struct AssetRepresentationHandle AssetRepresentationHandle; +#endif + #ifdef __cplusplus extern "C" { #endif @@ -464,12 +473,13 @@ typedef struct AssetShelfType { /** Determine if an individual asset should be visible or not. May be a temporary design, * visibility should first and foremost be controlled by asset traits. */ - bool (*asset_poll)(const struct AssetShelfType *shelf_type, const struct AssetHandle *asset); + bool (*asset_poll)(const struct AssetShelfType *shelf_type, + const AssetRepresentationHandle *asset); /** Asset shelves can define their own context menu via this layout definition callback. */ void (*draw_context_menu)(const struct bContext *C, const struct AssetShelfType *shelf_type, - const struct AssetHandle *asset, + const AssetRepresentationHandle *asset, struct uiLayout *layout); /* RNA integration */ diff --git a/source/blender/editors/asset/ED_asset_filter.hh b/source/blender/editors/asset/ED_asset_filter.hh index b9474c6bf4d..42189599f91 100644 --- a/source/blender/editors/asset/ED_asset_filter.hh +++ b/source/blender/editors/asset/ED_asset_filter.hh @@ -18,7 +18,6 @@ #include "AS_asset_catalog_tree.hh" struct AssetFilterSettings; -struct AssetHandle; struct AssetLibraryReference; struct bContext; @@ -55,7 +54,7 @@ struct AssetItemTree { asset_system::AssetCatalogTree build_filtered_catalog_tree( const asset_system::AssetLibrary &library, const AssetLibraryReference &library_ref, - blender::FunctionRef is_asset_visible_fn); + blender::FunctionRef is_asset_visible_fn); AssetItemTree build_filtered_all_catalog_tree( const AssetLibraryReference &library_ref, const bContext &C, diff --git a/source/blender/editors/asset/intern/asset_filter.cc b/source/blender/editors/asset/intern/asset_filter.cc index 71e1370a261..90c6b5cde3e 100644 --- a/source/blender/editors/asset/intern/asset_filter.cc +++ b/source/blender/editors/asset/intern/asset_filter.cc @@ -55,17 +55,17 @@ namespace blender::ed::asset { asset_system::AssetCatalogTree build_filtered_catalog_tree( const asset_system::AssetLibrary &library, const AssetLibraryReference &library_ref, - const blender::FunctionRef is_asset_visible_fn) + const blender::FunctionRef + is_asset_visible_fn) { Set known_paths; /* Collect paths containing assets. */ - ED_assetlist_iterate(library_ref, [&](AssetHandle asset_handle) { - if (!is_asset_visible_fn(asset_handle)) { + ED_assetlist_iterate(library_ref, [&](asset_system::AssetRepresentation &asset) { + if (!is_asset_visible_fn(asset)) { return true; } - asset_system::AssetRepresentation &asset = *ED_asset_handle_get_representation(&asset_handle); const AssetMetaData &meta_data = asset.get_metadata(); if (BLI_uuid_is_nil(meta_data.catalog_id)) { return true; diff --git a/source/blender/editors/asset/intern/asset_shelf_asset_view.cc b/source/blender/editors/asset/intern/asset_shelf_asset_view.cc index 8b2f7349e9a..8ef2413c378 100644 --- a/source/blender/editors/asset/intern/asset_shelf_asset_view.cc +++ b/source/blender/editors/asset/intern/asset_shelf_asset_view.cc @@ -104,12 +104,13 @@ void AssetView::build_items() } ED_assetlist_iterate(library_ref_, [&](AssetHandle asset_handle) { - if (shelf_.type->asset_poll && !shelf_.type->asset_poll(shelf_.type, &asset_handle)) { + const asset_system::AssetRepresentation *asset = ED_asset_handle_get_representation( + &asset_handle); + + if (shelf_.type->asset_poll && !shelf_.type->asset_poll(shelf_.type, asset)) { return true; } - const asset_system::AssetRepresentation *asset = ED_asset_handle_get_representation( - &asset_handle); const AssetMetaData &asset_data = asset->get_metadata(); if (catalog_filter_ && !catalog_filter_->contains(asset_data.catalog_id)) { @@ -213,7 +214,8 @@ void AssetViewItem::build_context_menu(bContext &C, uiLayout &column) const const AssetView &asset_view = dynamic_cast(get_view()); const AssetShelfType &shelf_type = *asset_view.shelf_.type; if (shelf_type.draw_context_menu) { - shelf_type.draw_context_menu(&C, &shelf_type, &asset_, &column); + asset_system::AssetRepresentation *asset = ED_asset_handle_get_representation(&asset_); + shelf_type.draw_context_menu(&C, &shelf_type, asset, &column); } } diff --git a/source/blender/editors/asset/intern/asset_shelf_catalog_selector.cc b/source/blender/editors/asset/intern/asset_shelf_catalog_selector.cc index c310ffdba0e..25ec6477538 100644 --- a/source/blender/editors/asset/intern/asset_shelf_catalog_selector.cc +++ b/source/blender/editors/asset/intern/asset_shelf_catalog_selector.cc @@ -45,8 +45,10 @@ class AssetCatalogSelectorTree : public ui::AbstractTreeView { : shelf_(shelf), shelf_settings_(shelf_.settings) { catalog_tree_ = build_filtered_catalog_tree( - library, asset_system::all_library_reference(), [this](const AssetHandle asset_handle) { - return (!shelf_.type->asset_poll || shelf_.type->asset_poll(shelf_.type, &asset_handle)); + library, + asset_system::all_library_reference(), + [this](const asset_system::AssetRepresentation &asset) { + return (!shelf_.type->asset_poll || shelf_.type->asset_poll(shelf_.type, &asset)); }); } diff --git a/source/blender/editors/include/UI_interface_c.hh b/source/blender/editors/include/UI_interface_c.hh index 515f8bea627..baa17dd3d44 100644 --- a/source/blender/editors/include/UI_interface_c.hh +++ b/source/blender/editors/include/UI_interface_c.hh @@ -23,7 +23,6 @@ struct ARegion; struct AssetFilterSettings; -struct AssetRepresentation; struct AutoComplete; struct EnumPropertyItem; struct FileSelectParams; diff --git a/source/blender/makesrna/intern/rna_asset.cc b/source/blender/makesrna/intern/rna_asset.cc index 8a9c4cba37f..d9801e40d13 100644 --- a/source/blender/makesrna/intern/rna_asset.cc +++ b/source/blender/makesrna/intern/rna_asset.cc @@ -610,6 +610,8 @@ static void rna_def_asset_representation(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Data-block Type", + /* Won't ever actually return 'NONE' currently, this is just for information for once non-ID + * assets are supported. */ "The type of the data-block, if the asset represents one ('NONE' otherwise)"); RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ID); } diff --git a/source/blender/makesrna/intern/rna_ui.cc b/source/blender/makesrna/intern/rna_ui.cc index e53038af73d..ead05e0b4d0 100644 --- a/source/blender/makesrna/intern/rna_ui.cc +++ b/source/blender/makesrna/intern/rna_ui.cc @@ -1071,7 +1071,8 @@ static StructRNA *rna_Menu_refine(PointerRNA *mtr) /* Asset Shelf */ -static bool asset_shelf_asset_poll(const AssetShelfType *shelf_type, const AssetHandle *asset) +static bool asset_shelf_asset_poll(const AssetShelfType *shelf_type, + const AssetRepresentationHandle *asset) { extern FunctionRNA rna_AssetShelf_asset_poll_func; @@ -1080,7 +1081,7 @@ static bool asset_shelf_asset_poll(const AssetShelfType *shelf_type, const Asset ParameterList list; RNA_parameter_list_create(&list, &ptr, func); - RNA_parameter_set_lookup(&list, "asset_handle", &asset); + RNA_parameter_set_lookup(&list, "asset", &asset); shelf_type->rna_ext.call(nullptr, &ptr, func, &list); void *ret; @@ -1117,7 +1118,7 @@ static bool asset_shelf_poll(const bContext *C, const AssetShelfType *shelf_type static void asset_shelf_draw_context_menu(const bContext *C, const AssetShelfType *shelf_type, - const AssetHandle *asset, + const AssetRepresentationHandle *asset, uiLayout *layout) { extern FunctionRNA rna_AssetShelf_draw_context_menu_func; @@ -1130,7 +1131,7 @@ static void asset_shelf_draw_context_menu(const bContext *C, ParameterList list; RNA_parameter_list_create(&list, &ptr, func); RNA_parameter_set_lookup(&list, "context", &C); - RNA_parameter_set_lookup(&list, "asset_handle", &asset); + RNA_parameter_set_lookup(&list, "asset", &asset); RNA_parameter_set_lookup(&list, "layout", &layout); shelf_type->rna_ext.call((bContext *)C, &ptr, func, &list); @@ -2143,7 +2144,7 @@ static void rna_def_asset_shelf(BlenderRNA *brna) "non-null output, the asset will be visible"); RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL); RNA_def_function_return(func, RNA_def_boolean(func, "visible", true, "", "")); - parm = RNA_def_pointer(func, "asset_handle", "AssetHandle", "", ""); + parm = RNA_def_pointer(func, "asset", "AssetRepresentation", "", ""); RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); func = RNA_def_function(srna, "draw_context_menu", nullptr); @@ -2152,7 +2153,7 @@ static void rna_def_asset_shelf(BlenderRNA *brna) RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL); parm = RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); - parm = RNA_def_pointer(func, "asset_handle", "AssetHandle", "", ""); + parm = RNA_def_pointer(func, "asset", "AssetRepresentation", "", ""); RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED); parm = RNA_def_pointer(func, "layout", "UILayout", "", ""); RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);