diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_bake_api.c | 12 | ||||
-rw-r--r-- | source/blender/editors/space_file/asset_catalog_tree_view.cc | 299 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 12 |
4 files changed, 203 insertions, 122 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 8b3e3b11cff..24c4143e587 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -329,7 +329,7 @@ MINLINE float dither_random_value(float s, float t) hash0 -= floorf(hash0); hash1 -= floorf(hash1); /* Convert uniform distribution into triangle-shaped distribution. */ - return hash0 + hash0 - 0.5f; + return hash0 + hash1 - 0.5f; } MINLINE void float_to_byte_dither_v3( diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 26f5b21a311..475e0e581fb 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -1532,22 +1532,22 @@ static int bake(const BakeAPIRender *bkr, if (md) { mode = md->mode; md->mode &= ~eModifierMode_Render; - } - /* Evaluate modifiers again. */ - me_nores = BKE_mesh_new_from_object(NULL, ob_low_eval, false, false); - bake_targets_populate_pixels(bkr, &targets, ob_low, me_nores, pixel_array_low); + /* Evaluate modifiers again. */ + me_nores = BKE_mesh_new_from_object(NULL, ob_low_eval, false, false); + bake_targets_populate_pixels(bkr, &targets, ob_low, me_nores, pixel_array_low); + } RE_bake_normal_world_to_tangent(pixel_array_low, targets.num_pixels, targets.num_channels, targets.result, - me_nores, + (me_nores) ? me_nores : me_low_eval, bkr->normal_swizzle, ob_low_eval->obmat); - BKE_id_free(NULL, &me_nores->id); if (md) { + BKE_id_free(NULL, &me_nores->id); md->mode = mode; } } 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 92e4e668885..883bc6d7890 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -74,6 +74,7 @@ class AssetCatalogTreeView : public ui::AbstractTreeView { void add_unassigned_item(); bool is_active_catalog(CatalogID catalog_id) const; }; + /* ---------------------------------------------------------------------- */ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem { @@ -81,111 +82,23 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem { AssetCatalogTreeItem &catalog_item_; public: - AssetCatalogTreeViewItem(AssetCatalogTreeItem *catalog_item) - : BasicTreeViewItem(catalog_item->get_name()), catalog_item_(*catalog_item) - { - } - - void on_activate() override - { - const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( - get_tree_view()); - tree_view.params_->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG; - tree_view.params_->catalog_id = catalog_item_.get_catalog_id(); - WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); - } - - void build_row(uiLayout &row) override - { - ui::BasicTreeViewItem::build_row(row); - - if (!is_active()) { - return; - } + AssetCatalogTreeViewItem(AssetCatalogTreeItem *catalog_item); - PointerRNA *props; - const CatalogID catalog_id = catalog_item_.get_catalog_id(); + static bool has_droppable_item(const wmDrag &drag); + static bool drop_into_catalog(const AssetCatalogTreeView &tree_view, + const wmDrag &drag, + CatalogID catalog_id, + StringRefNull simple_name = ""); - props = UI_but_extra_operator_icon_add( - button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); - RNA_string_set(props, "parent_path", catalog_item_.catalog_path().c_str()); - - /* Tree items without a catalog ID represent components of catalog paths that are not - * associated with an actual catalog. They exist merely by the presence of a child catalog, and - * thus cannot be deleted themselves. */ - if (!BLI_uuid_is_nil(catalog_id)) { - char catalog_id_str_buffer[UUID_STRING_LEN] = ""; - BLI_uuid_format(catalog_id_str_buffer, catalog_id); - - props = UI_but_extra_operator_icon_add( - button(), "ASSET_OT_catalog_delete", WM_OP_INVOKE_DEFAULT, ICON_X); - RNA_string_set(props, "catalog_id", catalog_id_str_buffer); - } - } - - bool has_droppable_item(const wmDrag &drag) const - { - const ListBase *asset_drags = WM_drag_asset_list_get(&drag); - - /* There needs to be at least one asset from the current file. */ - LISTBASE_FOREACH (const wmDragAssetListItem *, asset_item, asset_drags) { - if (!asset_item->is_external) { - return true; - } - } - return false; - } + void on_activate() override; - bool can_drop(const wmDrag &drag) const override - { - if (drag.type != WM_DRAG_ASSET_LIST) { - return false; - } - return has_droppable_item(drag); - } + void build_row(uiLayout &row) override; - std::string drop_tooltip(const bContext & /*C*/, + bool can_drop(const wmDrag &drag) const override; + std::string drop_tooltip(const bContext &C, const wmDrag &drag, - const wmEvent & /*event*/) const override - { - const ListBase *asset_drags = WM_drag_asset_list_get(&drag); - const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags); - - /* Don't try to be smart by dynamically adding the 's' for the plural. Just makes translation - * harder, so use full literals. */ - std::string basic_tip = is_multiple_assets ? TIP_("Move assets to catalog") : - TIP_("Move asset to catalog"); - - return basic_tip + ": " + catalog_item_.get_name() + " (" + - catalog_item_.catalog_path().str() + ")"; - } - - bool on_drop(const wmDrag &drag) override - { - const ListBase *asset_drags = WM_drag_asset_list_get(&drag); - if (!asset_drags) { - return false; - } - - const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( - get_tree_view()); - - LISTBASE_FOREACH (wmDragAssetListItem *, asset_item, asset_drags) { - if (asset_item->is_external) { - /* Only internal assets can be modified! */ - continue; - } - BKE_asset_metadata_catalog_id_set(asset_item->asset_data.local_id->asset_data, - catalog_item_.get_catalog_id(), - catalog_item_.get_simple_name().c_str()); - - /* Trigger re-run of filtering to update visible assets. */ - filelist_tag_needs_filtering(tree_view.space_file_.files); - file_select_deselect_all(&tree_view.space_file_, FILE_SEL_SELECTED | FILE_SEL_HIGHLIGHTED); - } - - return true; - } + const wmEvent &event) const override; + bool on_drop(const wmDrag &drag) override; }; /** Only reason this isn't just `BasicTreeViewItem` is to add a '+' icon for adding a root level @@ -193,22 +106,21 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem { class AssetCatalogTreeViewAllItem : public ui::BasicTreeViewItem { using BasicTreeViewItem::BasicTreeViewItem; - void build_row(uiLayout &row) override - { - ui::BasicTreeViewItem::build_row(row); + void build_row(uiLayout &row) override; +}; - if (!is_active()) { - return; - } +class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem { + using BasicTreeViewItem::BasicTreeViewItem; - PointerRNA *props; - props = UI_but_extra_operator_icon_add( - button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); - /* No parent path to use the root level. */ - RNA_string_set(props, "parent_path", nullptr); - } + bool can_drop(const wmDrag &drag) const override; + std::string drop_tooltip(const bContext &C, + const wmDrag &drag, + const wmEvent &event) const override; + bool on_drop(const wmDrag &drag) override; }; +/* ---------------------------------------------------------------------- */ + AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library, FileAssetSelectParams *params, SpaceFile &space_file) @@ -267,7 +179,7 @@ void AssetCatalogTreeView::add_unassigned_item() { FileAssetSelectParams *params = params_; - ui::AbstractTreeViewItem &item = add_tree_item<ui::BasicTreeViewItem>( + AssetCatalogTreeViewUnassignedItem &item = add_tree_item<AssetCatalogTreeViewUnassignedItem>( IFACE_("Unassigned"), ICON_FILE_HIDDEN, [params](ui::BasicTreeViewItem & /*item*/) { params->asset_catalog_visibility = FILE_SHOW_ASSETS_WITHOUT_CATALOG; WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); @@ -283,6 +195,167 @@ bool AssetCatalogTreeView::is_active_catalog(CatalogID catalog_id) const (params_->catalog_id == catalog_id); } +/* ---------------------------------------------------------------------- */ + +AssetCatalogTreeViewItem::AssetCatalogTreeViewItem(AssetCatalogTreeItem *catalog_item) + : BasicTreeViewItem(catalog_item->get_name()), catalog_item_(*catalog_item) +{ +} + +void AssetCatalogTreeViewItem::on_activate() +{ + const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( + get_tree_view()); + tree_view.params_->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG; + tree_view.params_->catalog_id = catalog_item_.get_catalog_id(); + WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); +} + +void AssetCatalogTreeViewItem::build_row(uiLayout &row) +{ + ui::BasicTreeViewItem::build_row(row); + + if (!is_active()) { + return; + } + + PointerRNA *props; + const CatalogID catalog_id = catalog_item_.get_catalog_id(); + + props = UI_but_extra_operator_icon_add( + button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); + RNA_string_set(props, "parent_path", catalog_item_.catalog_path().c_str()); + + /* Tree items without a catalog ID represent components of catalog paths that are not + * associated with an actual catalog. They exist merely by the presence of a child catalog, and + * thus cannot be deleted themselves. */ + if (!BLI_uuid_is_nil(catalog_id)) { + char catalog_id_str_buffer[UUID_STRING_LEN] = ""; + BLI_uuid_format(catalog_id_str_buffer, catalog_id); + + props = UI_but_extra_operator_icon_add( + button(), "ASSET_OT_catalog_delete", WM_OP_INVOKE_DEFAULT, ICON_X); + RNA_string_set(props, "catalog_id", catalog_id_str_buffer); + } +} + +bool AssetCatalogTreeViewItem::has_droppable_item(const wmDrag &drag) +{ + const ListBase *asset_drags = WM_drag_asset_list_get(&drag); + + /* There needs to be at least one asset from the current file. */ + LISTBASE_FOREACH (const wmDragAssetListItem *, asset_item, asset_drags) { + if (!asset_item->is_external) { + return true; + } + } + return false; +} + +bool AssetCatalogTreeViewItem::can_drop(const wmDrag &drag) const +{ + if (drag.type != WM_DRAG_ASSET_LIST) { + return false; + } + return has_droppable_item(drag); +} + +std::string AssetCatalogTreeViewItem::drop_tooltip(const bContext & /*C*/, + const wmDrag &drag, + const wmEvent & /*event*/) const +{ + const ListBase *asset_drags = WM_drag_asset_list_get(&drag); + const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags); + + /* Don't try to be smart by dynamically adding the 's' for the plural. Just makes translation + * harder, so use full literals. */ + std::string basic_tip = is_multiple_assets ? TIP_("Move assets to catalog") : + TIP_("Move asset to catalog"); + + return basic_tip + ": " + catalog_item_.get_name() + " (" + catalog_item_.catalog_path().str() + + ")"; +} + +bool AssetCatalogTreeViewItem::drop_into_catalog(const AssetCatalogTreeView &tree_view, + const wmDrag &drag, + CatalogID catalog_id, + StringRefNull simple_name) +{ + const ListBase *asset_drags = WM_drag_asset_list_get(&drag); + if (!asset_drags) { + return false; + } + + LISTBASE_FOREACH (wmDragAssetListItem *, asset_item, asset_drags) { + if (asset_item->is_external) { + /* Only internal assets can be modified! */ + continue; + } + BKE_asset_metadata_catalog_id_set( + asset_item->asset_data.local_id->asset_data, catalog_id, simple_name.c_str()); + + /* Trigger re-run of filtering to update visible assets. */ + filelist_tag_needs_filtering(tree_view.space_file_.files); + file_select_deselect_all(&tree_view.space_file_, FILE_SEL_SELECTED | FILE_SEL_HIGHLIGHTED); + } + + return true; +} + +bool AssetCatalogTreeViewItem::on_drop(const wmDrag &drag) +{ + const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( + get_tree_view()); + return drop_into_catalog( + tree_view, drag, catalog_item_.get_catalog_id(), catalog_item_.get_simple_name()); +} + +/* ---------------------------------------------------------------------- */ + +void AssetCatalogTreeViewAllItem::build_row(uiLayout &row) +{ + ui::BasicTreeViewItem::build_row(row); + + if (!is_active()) { + return; + } + + PointerRNA *props; + props = UI_but_extra_operator_icon_add( + button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); + /* No parent path to use the root level. */ + RNA_string_set(props, "parent_path", nullptr); +} + +/* ---------------------------------------------------------------------- */ + +bool AssetCatalogTreeViewUnassignedItem::can_drop(const wmDrag &drag) const +{ + if (drag.type != WM_DRAG_ASSET_LIST) { + return false; + } + return AssetCatalogTreeViewItem::has_droppable_item(drag); +} + +std::string AssetCatalogTreeViewUnassignedItem::drop_tooltip(const bContext & /*C*/, + const wmDrag &drag, + const wmEvent & /*event*/) const +{ + const ListBase *asset_drags = WM_drag_asset_list_get(&drag); + const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags); + + return is_multiple_assets ? TIP_("Move assets out of any catalog") : + TIP_("Move asset out of any catalog"); +} + +bool AssetCatalogTreeViewUnassignedItem::on_drop(const wmDrag &drag) +{ + const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( + get_tree_view()); + /* Assign to nil catalog ID. */ + return AssetCatalogTreeViewItem::drop_into_catalog(tree_view, drag, CatalogID{}); +} + } // namespace blender::ed::asset_browser /* ---------------------------------------------------------------------- */ diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index b58a04d6d4f..a927b62fd6e 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -3295,6 +3295,7 @@ typedef struct FileListReadJob { } FileListReadJob; static bool filelist_readjob_should_recurse_into_entry(const int max_recursion, + const bool is_lib, const int current_recursion_level, FileListInternEntry *entry) { @@ -3302,10 +3303,16 @@ static bool filelist_readjob_should_recurse_into_entry(const int max_recursion, /* Recursive loading is disabled. */ return false; } - if (current_recursion_level >= max_recursion) { + if (!is_lib && current_recursion_level > max_recursion) { /* No more levels of recursion left. */ return false; } + /* Show entries when recursion is set to `Blend file` even when `current_recursion_level` exceeds + * `max_recursion`. */ + if (!is_lib && (current_recursion_level >= max_recursion) && + ((entry->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) == 0)) { + return false; + } if (entry->typeflag & FILE_TYPE_BLENDERLIB) { /* Libraries are already loaded recursively when recursive loaded is used. No need to add * them another time. This loading is done with the `LIST_LIB_RECURSIVE` option. */ @@ -3421,7 +3428,8 @@ static void filelist_readjob_do(const bool do_lib, entry->name = fileentry_uiname(root, entry->relpath, entry->typeflag, dir); entry->free_name = true; - if (filelist_readjob_should_recurse_into_entry(max_recursion, recursion_level, entry)) { + if (filelist_readjob_should_recurse_into_entry( + max_recursion, is_lib, recursion_level, entry)) { /* We have a directory we want to list, add it to todo list! */ BLI_join_dirfile(dir, sizeof(dir), root, entry->relpath); BLI_path_normalize_dir(job_params->main_name, dir); |