[Bf-blender-cvs] [6590a288b05] master: Fix number sliders not working

2023-02-03 Thread Julian Eisel
Commit: 6590a288b0538c58fac68fb55ffd0819a8d6d5b8
Author: Julian Eisel
Date:   Fri Feb 3 18:42:14 2023 +0100
Branches: master
https://developer.blender.org/rB6590a288b0538c58fac68fb55ffd0819a8d6d5b8

Fix number sliders not working

Own mistake in d204830107ef.

For some buttons the type is changed after construction, which means the button
has to be reconstructed. For example number buttons can be turned into number
slider buttons this way. New code was unintentionally overriding the button
type after reconstruction with the old type again.

===

M   source/blender/editors/interface/interface.cc

===

diff --git a/source/blender/editors/interface/interface.cc 
b/source/blender/editors/interface/interface.cc
index bf1f276d702..3e355af823a 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -4048,6 +4048,8 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
   /* Copy construct button with the new type. */
   but = ui_but_new(new_type);
   *but = *old_but_ptr;
+  /* We didn't mean to override this :) */
+  but->type = new_type;
   if (has_str_ptr_to_self) {
 but->str = but->strdata;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a1c01e0c06c] master: Attempt to fix build errors with NDOF enabled

2023-02-03 Thread Julian Eisel
Commit: a1c01e0c06c05728d0d9983013ac7940ba393ed6
Author: Julian Eisel
Date:   Fri Feb 3 17:02:51 2023 +0100
Branches: master
https://developer.blender.org/rBa1c01e0c06c05728d0d9983013ac7940ba393ed6

Attempt to fix build errors with NDOF enabled

===

M   source/blender/editors/interface/interface_handlers.cc

===

diff --git a/source/blender/editors/interface/interface_handlers.cc 
b/source/blender/editors/interface/interface_handlers.cc
index 22d6ecce398..36737b20f83 100644
--- a/source/blender/editors/interface/interface_handlers.cc
+++ b/source/blender/editors/interface/interface_handlers.cc
@@ -6531,14 +6531,14 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube 
*hsv_but,
 const enum eSnapType snap,
 const bool shift)
 {
-  ColorPicker *cpicker = static_cast(hsv_but->but.custom_data);
+  ColorPicker *cpicker = static_cast(hsv_but->custom_data);
   float *hsv = cpicker->hsv_perceptual;
-  const float hsv_v_max = max_ff(hsv[2], hsv_but->but.softmax);
+  const float hsv_v_max = max_ff(hsv[2], hsv_but->softmax);
   float rgb[3];
   const float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt;
 
-  ui_but_v3_get(_but->but, rgb);
-  ui_scene_linear_to_perceptual_space(_but->but, rgb);
+  ui_but_v3_get(hsv_but, rgb);
+  ui_scene_linear_to_perceptual_space(hsv_but, rgb);
   ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
 
   switch (hsv_but->gradient_type) {
@@ -6570,7 +6570,7 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but,
   /* exception only for value strip - use the range set in but->min/max */
   hsv[2] += ndof->rvec[0] * sensitivity;
 
-  CLAMP(hsv[2], hsv_but->but.softmin, hsv_but->but.softmax);
+  CLAMP(hsv[2], hsv_but->softmin, hsv_but->softmax);
   break;
 default:
   BLI_assert_msg(0, "invalid hsv type");
@@ -6587,10 +6587,10 @@ static void ui_ndofedit_but_HSVCUBE(uiButHSVCube 
*hsv_but,
   hsv_clamp_v(hsv, hsv_v_max);
 
   ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb);
-  ui_perceptual_to_scene_linear_space(_but->but, rgb);
+  ui_perceptual_to_scene_linear_space(hsv_but, rgb);
 
   copy_v3_v3(data->vec, rgb);
-  ui_but_v3_set(_but->but, data->vec);
+  ui_but_v3_set(hsv_but, data->vec);
 }
 #endif /* WITH_INPUT_NDOF */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d204830107e] master: UI: Make uiBut safe for non-trivial construction

2023-02-03 Thread Julian Eisel
Commit: d204830107ef7f6f5802543cbb4cad7489f5507c
Author: Julian Eisel
Date:   Fri Feb 3 16:12:14 2023 +0100
Branches: master
https://developer.blender.org/rBd204830107ef7f6f5802543cbb4cad7489f5507c

UI: Make uiBut safe for non-trivial construction

No user-visible changes expected.

Essentially, this makes it possible to use C++ types like `std::function`
inside `uiBut`. This has plenty of benefits, for example this should help
significantly reducing unsafe `void *` use (since a `std::function` can hold
arbitrary data while preserving types).



I wanted to use a non-trivially-constructible C++ type (`std::function`) inside
`uiBut`. But this would mean we can't use `MEM_cnew()` like allocation anymore.

Rather than writing worse code, allow non-trivial construction for `uiBut`.
Member-initializing all members is annoying since there are so many, but rather
safe than sorry. As we use more C++ types (e.g. convert callbacks to use
`std::function`), this should become less since they initialize properly on
default construction.

Also use proper C++ inheritance for `uiBut` subtypes, the old way to allocate
based on size isn't working anymore.

Differential Revision: https://developer.blender.org/D17164

Reviewed by: Hans Goudey

===

M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/interface/interface.cc
M   source/blender/editors/interface/interface_anim.cc
M   source/blender/editors/interface/interface_context_menu.cc
M   source/blender/editors/interface/interface_handlers.cc
M   source/blender/editors/interface/interface_intern.hh
M   source/blender/editors/interface/interface_layout.cc
M   source/blender/editors/interface/interface_ops.cc
M   source/blender/editors/interface/interface_region_color_picker.cc
M   source/blender/editors/interface/interface_region_search.cc
M   source/blender/editors/interface/interface_templates.cc
M   source/blender/editors/interface/interface_widgets.cc
M   source/blender/editors/interface/views/grid_view.cc
M   source/blender/editors/interface/views/tree_view.cc

===

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index db3f0dc41fb..cf2c0ea2ebb 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -322,6 +322,8 @@ enum {
  * - bit  9-15: button type (now 6 bits, 64 types)
  */
 typedef enum {
+  UI_BUT_POIN_NONE = 0,
+
   UI_BUT_POIN_CHAR = 32,
   UI_BUT_POIN_SHORT = 64,
   UI_BUT_POIN_INT = 96,
diff --git a/source/blender/editors/interface/interface.cc 
b/source/blender/editors/interface/interface.cc
index 2a21356b9aa..bf1f276d702 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -3474,7 +3474,7 @@ static void ui_but_free(const bContext *C, uiBut *but)
 
   BLI_assert(UI_butstore_is_registered(but->block, but) == false);
 
-  MEM_freeN(but);
+  MEM_delete(but);
 }
 
 void UI_block_free(const bContext *C, uiBlock *block)
@@ -3975,89 +3975,57 @@ void ui_block_cm_to_display_space_v3(uiBlock *block, 
float pixel[3])
   IMB_colormanagement_scene_linear_to_display_v3(pixel, display);
 }
 
-static void ui_but_alloc_info(const eButType type,
-  size_t *r_alloc_size,
-  const char **r_alloc_str,
-  bool *r_has_custom_type)
+/**
+ * Factory function: Allocate button and set #uiBut.type.
+ */
+static uiBut *ui_but_new(const eButType type)
 {
-  size_t alloc_size;
-  const char *alloc_str;
-  bool has_custom_type = true;
+  uiBut *but = nullptr;
 
   switch (type) {
 case UI_BTYPE_NUM:
-  alloc_size = sizeof(uiButNumber);
-  alloc_str = "uiButNumber";
+  but = MEM_new("uiButNumber");
   break;
 case UI_BTYPE_COLOR:
-  alloc_size = sizeof(uiButColor);
-  alloc_str = "uiButColor";
+  but = MEM_new("uiButColor");
   break;
 case UI_BTYPE_DECORATOR:
-  alloc_size = sizeof(uiButDecorator);
-  alloc_str = "uiButDecorator";
+  but = MEM_new("uiButDecorator");
   break;
 case UI_BTYPE_TAB:
-  alloc_size = sizeof(uiButTab);
-  alloc_str = "uiButTab";
+  but = MEM_new("uiButTab");
   break;
 case UI_BTYPE_SEARCH_MENU:
-  alloc_size = sizeof(uiButSearch);
-  alloc_str = "uiButSearch";
+  but = MEM_new("uiButSearch");
   break;
 case UI_BTYPE_PROGRESS_BAR:
-  alloc_size = sizeof(uiButProgressbar);
-  alloc_str = "uiButProgressbar";
+  but = MEM_new("uiButProgressbar");
   break;
 case UI_BTYPE_HSVCUBE:
-  alloc_size = sizeof(uiButHSVCube);
-  alloc_str = &

[Bf-blender-cvs] [baf45e1ac8a] asset-shelf: Show asset name in tooltip, add a small gap before catalog tabs

2023-02-03 Thread Julian Eisel
Commit: baf45e1ac8ab944fead1f41e17cfc499ec422604
Author: Julian Eisel
Date:   Fri Feb 3 15:50:22 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBbaf45e1ac8ab944fead1f41e17cfc499ec422604

Show asset name in tooltip, add a small gap before catalog tabs

===

M   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/interface/interface_template_asset_shelf.cc

===

diff --git a/source/blender/editors/asset/intern/asset_shelf.cc 
b/source/blender/editors/asset/intern/asset_shelf.cc
index 6974397abfe..f770e2e668b 100644
--- a/source/blender/editors/asset/intern/asset_shelf.cc
+++ b/source/blender/editors/asset/intern/asset_shelf.cc
@@ -488,6 +488,8 @@ static void asset_shelf_footer_draw(const bContext *C, 
Header *header)
 UI_UNIT_Y,
 TIP_("Select catalogs to display"));
 
+  uiItemS(layout);
+
   AssetShelfSettings *shelf_settings = 
get_asset_shelf_settings_from_context(C);
   if (shelf_settings) {
 add_catalog_toggle_buttons(*shelf_settings, *layout);
diff --git a/source/blender/editors/interface/interface_template_asset_shelf.cc 
b/source/blender/editors/interface/interface_template_asset_shelf.cc
index 114062716f9..d709df573e2 100644
--- a/source/blender/editors/interface/interface_template_asset_shelf.cc
+++ b/source/blender/editors/interface/interface_template_asset_shelf.cc
@@ -66,11 +66,13 @@ static void asset_tile_draw(uiLayout ,
   uiLayoutSetContextPointer(, "active_file", _ptr);
 
   uiBlock *block = uiLayoutGetBlock();
+  const StringRefNull name = ED_asset_handle_get_name(_handle);
+
   uiBut *but = uiDefIconTextBut(block,
 UI_BTYPE_PREVIEW_TILE,
 0,
 
ED_asset_handle_get_preview_icon_id(_handle),
-show_names ? 
ED_asset_handle_get_name(_handle) : "",
+show_names ? name.c_str() : "",
 0,
 0,
 width,
@@ -80,7 +82,7 @@ static void asset_tile_draw(uiLayout ,
 0,
 0,
 0,
-"");
+name.c_str());
   ui_def_but_icon(but,
   ED_asset_handle_get_preview_icon_id(_handle),
   /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [002158c26fc] asset-shelf: Fix asset shelf footer region resizing using wrong coordinates

2023-02-03 Thread Julian Eisel
Commit: 002158c26fc78829dea3d77d09bf0df4a857925f
Author: Julian Eisel
Date:   Fri Feb 3 15:43:39 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB002158c26fc78829dea3d77d09bf0df4a857925f

Fix asset shelf footer region resizing using wrong coordinates

===

M   source/blender/editors/screen/area.c

===

diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index 8fcba51d6f9..7a21ee5590b 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -944,9 +944,14 @@ static void fullscreen_azone_init(ScrArea *area, ARegion 
*region)
 #define AZONEPAD_ICON (0.45f * U.widget_unit)
 static void region_azone_edge(AZone *az, ARegion *region)
 {
-  /* If region is overlapped (transparent background), move #AZone to content.
-   * Note this is an arbitrary amount that matches nicely with numbers 
elsewhere. */
-  int overlap_padding = (region->overlap) ? (int)(0.4f * U.widget_unit) : 0;
+  /* If there is no visible region background, users typically expect the 
#AZone to be closer to
+   * the content, so move it a bit. Headers-like regions are usually thin and 
there's not much
+   * padding around them, so don't touch the #AZone there (also avoids mouse 
hover conflicts with
+   * actual contents).
+   * Note that this is an arbitrary amount that matches nicely with numbers 
elsewhere. */
+  const int overlap_padding = (region->overlap && 
!RGN_TYPE_IS_HEADER_ANY(region->regiontype)) ?
+  (int)(0.4f * U.widget_unit) :
+  0;
 
   switch (az->edge) {
 case AE_TOP_TO_BOTTOMRIGHT:

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2110b71f1cc] asset-shelf: Allow operators to override asset applying on click through the keymap

2023-02-03 Thread Julian Eisel
Commit: 2110b71f1cc8eac5e7494a827e0f83618e99bab2
Author: Julian Eisel
Date:   Fri Feb 3 15:40:32 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB2110b71f1cc8eac5e7494a827e0f83618e99bab2

Allow operators to override asset applying on click through the keymap

===

M   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/include/ED_screen.h
M   source/blender/editors/interface/interface_template_asset_shelf.cc
M   source/blender/editors/screen/area.c
M   source/blender/editors/space_view3d/space_view3d.cc

===

diff --git a/source/blender/editors/asset/intern/asset_shelf.cc 
b/source/blender/editors/asset/intern/asset_shelf.cc
index 8e9f65c4270..6974397abfe 100644
--- a/source/blender/editors/asset/intern/asset_shelf.cc
+++ b/source/blender/editors/asset/intern/asset_shelf.cc
@@ -207,6 +207,7 @@ int ED_asset_shelf_context(const bContext *C,
 {
   static const char *context_dir[] = {
   "asset_shelf_settings",
+  "active_file", /* XXX yuk... */
   nullptr,
   };
 
@@ -223,6 +224,28 @@ int ED_asset_shelf_context(const bContext *C,
 return CTX_RESULT_OK;
   }
 
+  /* XXX hack. Get the asset from the hovered button, but needs to be the 
file... */
+  if (CTX_data_equals(member, "active_file")) {
+const uiBut *but = UI_context_active_but_get(C);
+if (!but) {
+  return CTX_RESULT_NO_DATA;
+}
+
+const bContextStore *but_context = UI_but_context_get(but);
+if (!but_context) {
+  return CTX_RESULT_NO_DATA;
+}
+
+const PointerRNA *file_ptr = CTX_store_ptr_lookup(
+but_context, "active_file", _FileSelectEntry);
+if (!file_ptr) {
+  return CTX_RESULT_NO_DATA;
+}
+
+CTX_data_pointer_set_ptr(result, file_ptr);
+return CTX_RESULT_OK;
+  }
+
   return CTX_RESULT_MEMBER_NOT_FOUND;
 }
 
diff --git a/source/blender/editors/include/ED_screen.h 
b/source/blender/editors/include/ED_screen.h
index b71fa39543c..2ad8e68c05d 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -701,7 +701,7 @@ enum {
   ED_KEYMAP_FOOTER = (1 << 9),
   ED_KEYMAP_GPENCIL = (1 << 10),
   ED_KEYMAP_NAVBAR = (1 << 11),
-  ED_KEYMAP_ASSET_SHELF_FOOTER = (1 << 12),
+  ED_KEYMAP_ASSET_SHELF = (1 << 12),
 };
 
 /** #SCREEN_OT_space_context_cycle direction. */
diff --git a/source/blender/editors/interface/interface_template_asset_shelf.cc 
b/source/blender/editors/interface/interface_template_asset_shelf.cc
index abab93c3612..114062716f9 100644
--- a/source/blender/editors/interface/interface_template_asset_shelf.cc
+++ b/source/blender/editors/interface/interface_template_asset_shelf.cc
@@ -13,6 +13,8 @@
 
 #include "ED_asset.h"
 
+#include "RNA_access.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 #include "interface_intern.hh"
@@ -53,6 +55,16 @@ static void asset_tile_draw(uiLayout ,
 const int height,
 const bool show_names)
 {
+  PointerRNA file_ptr;
+  RNA_pointer_create(
+  nullptr,
+  _FileSelectEntry,
+  /* XXX passing file pointer here, should be asset handle or asset 
representation. */
+  const_cast(asset_handle.file_data),
+  _ptr);
+
+  uiLayoutSetContextPointer(, "active_file", _ptr);
+
   uiBlock *block = uiLayoutGetBlock();
   uiBut *but = uiDefIconTextBut(block,
 UI_BTYPE_PREVIEW_TILE,
diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index 9f77fc80ddd..8fcba51d6f9 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1743,9 +1743,9 @@ static void ed_default_handlers(
 wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Region Context 
Menu", 0, 0);
 WM_event_add_keymap_handler(>handlers, keymap);
   }
-  if (flag & ED_KEYMAP_ASSET_SHELF_FOOTER) {
+  if (flag & ED_KEYMAP_ASSET_SHELF) {
 /* standard keymap for Navigation bar regions */
-wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Region Context 
Menu", 0, 0);
+wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Asset Shelf", 0, 0);
 WM_event_add_keymap_handler(>handlers, keymap);
   }
 
diff --git a/source/blender/editors/space_view3d/space_view3d.cc 
b/source/blender/editors/space_view3d/space_view3d.cc
index 694792b8a04..1d27dae2bca 100644
--- a/source/blender/editors/space_view3d/space_view3d.cc
+++ b/source/blender/editors/space_view3d/space_view3d.cc
@@ -2184,7 +2184,8 @@ void ED_spacetype_view3d()
   art = MEM_cnew("spacetype view3d asset shelf region");
   art->regionid = RGN_TYPE_ASSET_SHELF;
   art->prefsizey = HEADER

[Bf-blender-cvs] [4b4cf6da9af] asset-shelf: Merge branch 'master' into asset-shelf

2023-02-02 Thread Julian Eisel
Commit: 4b4cf6da9afffeb9b4f992e015abc52faa216eef
Author: Julian Eisel
Date:   Thu Feb 2 17:02:10 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB4b4cf6da9afffeb9b4f992e015abc52faa216eef

Merge branch 'master' into asset-shelf

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [56582fbf820] asset-shelf: Get filtering by asset catalog to work

2023-02-01 Thread Julian Eisel
Commit: 56582fbf820a6eccba3b0ba1c641640540a9e7ef
Author: Julian Eisel
Date:   Wed Feb 1 16:26:30 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB56582fbf820a6eccba3b0ba1c641640540a9e7ef

Get filtering by asset catalog to work

===

M   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/interface/interface_template_asset_shelf.cc
M   source/blender/editors/space_view3d/space_view3d.cc

===

diff --git a/source/blender/editors/asset/intern/asset_shelf.cc 
b/source/blender/editors/asset/intern/asset_shelf.cc
index dedbc58f036..8e9f65c4270 100644
--- a/source/blender/editors/asset/intern/asset_shelf.cc
+++ b/source/blender/editors/asset/intern/asset_shelf.cc
@@ -34,18 +34,16 @@
 
 using namespace blender;
 
+static void asset_shelf_send_redraw_notifier(bContext )
+{
+  WM_event_add_notifier(, NC_SPACE | ND_SPACE_ASSET_SHELF, nullptr);
+}
+
 /*  */
 /** \name Asset Shelf Regions
  * \{ */
 
-void ED_asset_shelf_region_listen(const wmRegionListenerParams *params)
-{
-  if (ED_assetlist_listen(params->notifier)) {
-ED_region_tag_redraw_no_rebuild(params->region);
-  }
-}
-
-void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params)
+static void asset_shelf_region_listen(const wmRegionListenerParams *params)
 {
   ARegion *region = params->region;
   const wmNotifier *wmn = params->notifier;
@@ -59,6 +57,22 @@ void ED_asset_shelf_footer_region_listen(const 
wmRegionListenerParams *params)
   }
 }
 
+void ED_asset_shelf_region_listen(const wmRegionListenerParams *params)
+{
+  if (ED_assetlist_listen(params->notifier)) {
+ED_region_tag_redraw_no_rebuild(params->region);
+  }
+  /* If the asset list didn't catch the notifier, let the region itself 
listen. */
+  else {
+asset_shelf_region_listen(params);
+  }
+}
+
+void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params)
+{
+  asset_shelf_region_listen(params);
+}
+
 void ED_asset_shelf_footer_region_init(wmWindowManager * /*wm*/, ARegion 
*region)
 {
   ED_region_header_init(region);
@@ -265,7 +279,7 @@ class AssetCatalogSelectorTree : public 
ui::AbstractTreeView {
 return view_item;
   }
 
-  void update_shelf_settings_from_enabled_catalogs(const bContext *C);
+  void update_shelf_settings_from_enabled_catalogs();
 
   class Item : public ui::BasicTreeViewItem {
 asset_system::AssetCatalogTreeItem catalog_item_;
@@ -294,6 +308,7 @@ class AssetCatalogSelectorTree : public 
ui::AbstractTreeView {
 
 void build_row(uiLayout ) override
 {
+  AssetCatalogSelectorTree  = dynamic_cast(get_tree_view());
   uiBlock *block = uiLayoutGetBlock();
 
   uiLayoutSetEmboss(, UI_EMBOSS);
@@ -316,29 +331,23 @@ class AssetCatalogSelectorTree : public 
ui::AbstractTreeView {
  0,
  0,
  TIP_("Toggle catalog visibility in the asset 
shelf"));
-  UI_but_func_set(
-  but,
-  [](bContext *C, void *selector_tree_ptr, void *) {
-AssetCatalogSelectorTree _tree = 
*static_cast(
-selector_tree_ptr);
-selector_tree.update_shelf_settings_from_enabled_catalogs(C);
-  },
-  _cast(get_tree_view()),
-  nullptr);
+  UI_but_func_set(but, [](bContext ) {
+tree.update_shelf_settings_from_enabled_catalogs();
+asset_shelf_send_redraw_notifier(C);
+  });
   UI_but_flag_disable(but, UI_BUT_UNDO);
 }
   };
 };
 
-void 
AssetCatalogSelectorTree::update_shelf_settings_from_enabled_catalogs(const 
bContext *C)
+void AssetCatalogSelectorTree::update_shelf_settings_from_enabled_catalogs()
 {
   asset_shelf_settings_clear_enabled_catalogs(shelf_settings_);
-  foreach_item([C, this](ui::AbstractTreeViewItem _item) {
+  foreach_item([this](ui::AbstractTreeViewItem _item) {
 const auto _tree_item = 
dynamic_cast(view_item);
 if (selector_tree_item.is_catalog_path_enabled()) {
   asset_shelf_settings_set_catalog_path_enabled(shelf_settings_,
 
selector_tree_item.catalog_path());
-  WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_SHELF, nullptr);
 }
   });
 }
@@ -420,8 +429,9 @@ static void add_catalog_toggle_buttons(AssetShelfSettings 
_settings, uiLay
 "Enable catalog, making contained assets visible in the asset 
shelf");
 
 UI_but_drawflag_enable(but, UI_BUT_ALIGN_TOP);
-UI_but_func_set(but, [_settings, path](bContext &) {
+UI_but_func_set(but, [_settings, path](bContext ) {
   asset_shelf_settings_set_active_catalog(shelf_settings, path);
+  asset_shelf_send_redraw_notifier(C);
 });
 UI_but_func_pushed_st

[Bf-blender-cvs] [d5c60f912f4] asset-shelf: Tabs to activate a catalog

2023-02-01 Thread Julian Eisel
Commit: d5c60f912f457a58d45b36f5e9c89a6b0cce9d69
Author: Julian Eisel
Date:   Wed Feb 1 12:47:52 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBd5c60f912f457a58d45b36f5e9c89a6b0cce9d69

Tabs to activate a catalog

The tabs should be fully working themselves, however we don't filter
the asset shelf contents based on the active catalog (well, catalog
path) yet.

Includes the changes from D17164.

===

M   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/include/UI_interface.hh
M   source/blender/editors/interface/interface.cc
M   source/blender/editors/interface/interface_handlers.cc
M   source/blender/editors/interface/interface_intern.hh
M   source/blender/makesdna/DNA_screen_types.h

===

diff --git a/source/blender/editors/asset/intern/asset_shelf.cc 
b/source/blender/editors/asset/intern/asset_shelf.cc
index 3ea457a9056..dedbc58f036 100644
--- a/source/blender/editors/asset/intern/asset_shelf.cc
+++ b/source/blender/editors/asset/intern/asset_shelf.cc
@@ -104,9 +104,23 @@ static void 
asset_shelf_settings_clear_enabled_catalogs(AssetShelfSettings 
   BLI_assert(BLI_listbase_is_empty(_settings.enabled_catalog_paths));
 }
 
+static void asset_shelf_settings_set_active_catalog(AssetShelfSettings 
_settings,
+const 
asset_system::AssetCatalogPath )
+{
+  MEM_delete(shelf_settings.active_catalog_path);
+  shelf_settings.active_catalog_path = BLI_strdupn(path.c_str(), 
path.length());
+}
+
+static bool asset_shelf_settings_is_active_catalog(const AssetShelfSettings 
_settings,
+   const 
asset_system::AssetCatalogPath )
+{
+  return shelf_settings.active_catalog_path && 
shelf_settings.active_catalog_path == path.str();
+}
+
 void ED_asset_shelf_settings_free(AssetShelfSettings *shelf_settings)
 {
   asset_shelf_settings_clear_enabled_catalogs(*shelf_settings);
+  MEM_delete(shelf_settings->active_catalog_path);
 }
 
 void ED_asset_shelf_settings_blend_write(BlendWriter *writer,
@@ -373,6 +387,50 @@ static uiBlock 
*asset_shelf_catalog_selector_block_draw(bContext *C,
 
 /** \} */
 
+/*  */
+/** \name Catalog toggle buttons
+ * \{ */
+
+static void add_catalog_toggle_buttons(AssetShelfSettings _settings, 
uiLayout )
+{
+  uiBlock *block = uiLayoutGetBlock();
+  const uiStyle *style = UI_style_get_dpi();
+
+  asset_shelf_settings_foreach_enabled_catalog_path(
+  shelf_settings, [_settings, block, style](const 
asset_system::AssetCatalogPath ) {
+const char *name = path.name().c_str();
+const int string_width = UI_fontstyle_string_width(>widget, 
name);
+const int pad_x = UI_UNIT_X * 0.3f;
+const int but_width = std::min(string_width + 2 * pad_x, UI_UNIT_X * 
8);
+
+uiBut *but = uiDefBut(
+block,
+UI_BTYPE_TAB,
+0,
+name,
+0,
+0,
+but_width,
+UI_UNIT_Y,
+nullptr,
+0,
+0,
+0,
+0,
+"Enable catalog, making contained assets visible in the asset 
shelf");
+
+UI_but_drawflag_enable(but, UI_BUT_ALIGN_TOP);
+UI_but_func_set(but, [_settings, path](bContext &) {
+  asset_shelf_settings_set_active_catalog(shelf_settings, path);
+});
+UI_but_func_pushed_state_set(but, [_settings, path](const uiBut 
&) -> bool {
+  return asset_shelf_settings_is_active_catalog(shelf_settings, path);
+});
+  });
+}
+
+/** \} */
+
 /*  */
 /** \name Asset Shelf Footer
  *
@@ -399,10 +457,7 @@ static void asset_shelf_footer_draw(const bContext *C, 
Header *header)
 
   AssetShelfSettings *shelf_settings = 
get_asset_shelf_settings_from_context(C);
   if (shelf_settings) {
-asset_shelf_settings_foreach_enabled_catalog_path(
-*shelf_settings, [layout](const asset_system::AssetCatalogPath ) {
-  uiItemL(layout, path.name().c_str(), ICON_NONE);
-});
+add_catalog_toggle_buttons(*shelf_settings, *layout);
   }
 }
 
diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index bd8046fe223..06cb79818a2 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1748,8 +1748,6 @@ void UI_but_focus_on_enter_event(struct wmWindow *win, 
uiBut *but);
 
 void UI_but_func_hold_set(uiBut *but, uiButHandleHoldFunc func, void *argN);
 
-void UI_but_func_pushed_state_set(uiBut *but, uiButPushedStateFunc func, cons

[Bf-blender-cvs] [b4edc40fb8f] asset-shelf: UI: Make uiBut safe for non-trivial construction

2023-02-01 Thread Julian Eisel
Commit: b4edc40fb8fa4fd74ab57a220d9c2a05f352c805
Author: Julian Eisel
Date:   Tue Jan 31 17:17:34 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBb4edc40fb8fa4fd74ab57a220d9c2a05f352c805

UI: Make uiBut safe for non-trivial construction

Essentially, I wanted to use a non-trivially-constructible C++ type
(`std::function`) inside `uiBut`. But this would mean we can't use
`MEM_cnew()` like allocation anymore.

Rather than writing worse code, allow non-trivial construction for
`uiBut`. Member-initializing all members is annoying since there are so
many, but rather safe than sorry. As we use more C++ types (e.g. convert
callbacks to use `std::function`), this should become less since they
initialize properly on default construction.

Also use proper C++ inheritance for `uiBut` subtypes, the old way to
allocate based on size isn't working anymore.

Differential Revision: https://developer.blender.org/D17164

===

M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/include/UI_interface.hh
M   source/blender/editors/interface/interface.cc
M   source/blender/editors/interface/interface_anim.cc
M   source/blender/editors/interface/interface_context_menu.cc
M   source/blender/editors/interface/interface_handlers.cc
M   source/blender/editors/interface/interface_intern.hh
M   source/blender/editors/interface/interface_layout.cc
M   source/blender/editors/interface/interface_ops.cc
M   source/blender/editors/interface/interface_region_color_picker.cc
M   source/blender/editors/interface/interface_region_search.cc
M   source/blender/editors/interface/interface_templates.cc
M   source/blender/editors/interface/interface_widgets.cc
M   source/blender/editors/interface/views/grid_view.cc
M   source/blender/editors/interface/views/tree_view.cc

===

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index db3f0dc41fb..cf2c0ea2ebb 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -322,6 +322,8 @@ enum {
  * - bit  9-15: button type (now 6 bits, 64 types)
  */
 typedef enum {
+  UI_BUT_POIN_NONE = 0,
+
   UI_BUT_POIN_CHAR = 32,
   UI_BUT_POIN_SHORT = 64,
   UI_BUT_POIN_INT = 96,
diff --git a/source/blender/editors/include/UI_interface.hh 
b/source/blender/editors/include/UI_interface.hh
index fc03b0218c0..4d3e40b30fc 100644
--- a/source/blender/editors/include/UI_interface.hh
+++ b/source/blender/editors/include/UI_interface.hh
@@ -19,6 +19,7 @@ struct GeometryAttributeInfo;
 
 struct StructRNA;
 struct uiBlock;
+struct uiBut;
 struct uiSearchItems;
 
 namespace blender::ui {
diff --git a/source/blender/editors/interface/interface.cc 
b/source/blender/editors/interface/interface.cc
index 2a21356b9aa..73f2efb6d19 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -3474,7 +3474,7 @@ static void ui_but_free(const bContext *C, uiBut *but)
 
   BLI_assert(UI_butstore_is_registered(but->block, but) == false);
 
-  MEM_freeN(but);
+  MEM_delete(but);
 }
 
 void UI_block_free(const bContext *C, uiBlock *block)
@@ -3975,89 +3975,60 @@ void ui_block_cm_to_display_space_v3(uiBlock *block, 
float pixel[3])
   IMB_colormanagement_scene_linear_to_display_v3(pixel, display);
 }
 
-static void ui_but_alloc_info(const eButType type,
-  size_t *r_alloc_size,
-  const char **r_alloc_str,
-  bool *r_has_custom_type)
+/**
+ * Factory function: Allocate button and set #uiBut.type.
+ */
+static uiBut *ui_but_new(const eButType type)
 {
-  size_t alloc_size;
-  const char *alloc_str;
-  bool has_custom_type = true;
+  uiBut *but = nullptr;
+
+#define NEW_BUT(type_name) MEM_new(#type_name)
 
   switch (type) {
 case UI_BTYPE_NUM:
-  alloc_size = sizeof(uiButNumber);
-  alloc_str = "uiButNumber";
+  but = MEM_new("uiButNumber");
   break;
 case UI_BTYPE_COLOR:
-  alloc_size = sizeof(uiButColor);
-  alloc_str = "uiButColor";
+  but = MEM_new("uiButColor");
   break;
 case UI_BTYPE_DECORATOR:
-  alloc_size = sizeof(uiButDecorator);
-  alloc_str = "uiButDecorator";
+  but = MEM_new("uiButDecorator");
   break;
 case UI_BTYPE_TAB:
-  alloc_size = sizeof(uiButTab);
-  alloc_str = "uiButTab";
+  but = MEM_new("uiButTab");
   break;
 case UI_BTYPE_SEARCH_MENU:
-  alloc_size = sizeof(uiButSearch);
-  alloc_str = "uiButSearch";
+  but = MEM_new("uiButSearch");
   break;
 case UI_BTYPE_PROGRESS_BAR:
-  alloc_size = sizeof(uiButProgressbar);
-  alloc_str =

[Bf-blender-cvs] [3700b74476d] asset-shelf: Merge branch 'temp-uibut-non-trivial-construction' into asset-shelf

2023-02-01 Thread Julian Eisel
Commit: 3700b74476d83b66d21b09593cc63115090ac67e
Author: Julian Eisel
Date:   Wed Feb 1 11:25:36 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB3700b74476d83b66d21b09593cc63115090ac67e

Merge branch 'temp-uibut-non-trivial-construction' into asset-shelf

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c4176781d3f] asset-shelf: Fix assert failures because of unexpected RNA index default

2023-02-01 Thread Julian Eisel
Commit: c4176781d3f8a97c1e20399b9d708edae98d73e0
Author: Julian Eisel
Date:   Tue Jan 31 17:37:36 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBc4176781d3f8a97c1e20399b9d708edae98d73e0

Fix assert failures because of unexpected RNA index default

===

M   source/blender/editors/interface/interface_intern.hh

===

diff --git a/source/blender/editors/interface/interface_intern.hh 
b/source/blender/editors/interface/interface_intern.hh
index e62a19ec146..b19a04145d1 100644
--- a/source/blender/editors/interface/interface_intern.hh
+++ b/source/blender/editors/interface/interface_intern.hh
@@ -246,7 +246,7 @@ struct uiBut {
   /* RNA data */
   PointerRNA rnapoin = {};
   PropertyRNA *rnaprop = nullptr;
-  int rnaindex = -1;
+  int rnaindex = 0;
 
   /* Operator data */
   wmOperatorType *optype = nullptr;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3a34c914486] asset-shelf: Cleanup: Remove unnecessary macro & unnecessary cast

2023-02-01 Thread Julian Eisel
Commit: 3a34c9144862742e773363628295995531d6f0f8
Author: Julian Eisel
Date:   Tue Jan 31 17:32:05 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB3a34c9144862742e773363628295995531d6f0f8

Cleanup: Remove unnecessary macro & unnecessary cast

===

M   source/blender/editors/interface/interface.cc
M   source/blender/editors/interface/interface_anim.cc

===

diff --git a/source/blender/editors/interface/interface.cc 
b/source/blender/editors/interface/interface.cc
index 73f2efb6d19..bf1f276d702 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -3982,8 +3982,6 @@ static uiBut *ui_but_new(const eButType type)
 {
   uiBut *but = nullptr;
 
-#define NEW_BUT(type_name) MEM_new(#type_name)
-
   switch (type) {
 case UI_BTYPE_NUM:
   but = MEM_new("uiButNumber");
@@ -4022,10 +4020,9 @@ static uiBut *ui_but_new(const eButType type)
   but = MEM_new("uiButViewItem");
   break;
 default:
-  but = NEW_BUT(uiBut);
+  but = MEM_new("uiBut");
   break;
   }
-#undef NEW_BUT
 
   but->type = type;
   return but;
diff --git a/source/blender/editors/interface/interface_anim.cc 
b/source/blender/editors/interface/interface_anim.cc
index 78dccbaf1f8..c0b5f1f46f4 100644
--- a/source/blender/editors/interface/interface_anim.cc
+++ b/source/blender/editors/interface/interface_anim.cc
@@ -121,7 +121,7 @@ static uiBut 
*ui_but_anim_decorate_find_attached_button(uiButDecorator *but)
   BLI_assert(but->rnapoin.data && but->rnaprop);
 
   LISTBASE_CIRCULAR_BACKWARD_BEGIN (uiBut *, >block->buttons, but_iter, 
but->prev) {
-if (but_iter != (uiBut *)but &&
+if (but_iter != but &&
 ui_but_rna_equals_ex(but_iter, >rnapoin, but->rnaprop, 
but->rnaindex)) {
   return but_iter;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [db77a9c55ec] asset-shelf: Merge branch 'master' into asset-shelf

2023-01-31 Thread Julian Eisel
Commit: db77a9c55ec52e7843e0cb7ea8403c54686bc5a1
Author: Julian Eisel
Date:   Tue Jan 31 11:24:51 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBdb77a9c55ec52e7843e0cb7ea8403c54686bc5a1

Merge branch 'master' into asset-shelf

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6e4e5f64845] master: UI: Allow spawning file browser dialog from regular file browser editor

2023-01-24 Thread Julian Eisel
Commit: 6e4e5f6484534aa38488d4605fd0e9c2432bbf68
Author: Julian Eisel
Date:   Tue Jan 24 15:30:10 2023 +0100
Branches: master
https://developer.blender.org/rB6e4e5f6484534aa38488d4605fd0e9c2432bbf68

UI: Allow spawning file browser dialog from regular file browser editor

When some path property was displayed in the File Browser, clicking the
icon to open a file browser dialog to choose a file/directory would
show an error. While this makes sense when you are already in a file
browser dialog (we don't support such nested file browser dialogs),
allow it when the file browser is opened as a normal editor, not as a
dialog.

===

M   source/blender/editors/space_buttons/buttons_ops.c

===

diff --git a/source/blender/editors/space_buttons/buttons_ops.c 
b/source/blender/editors/space_buttons/buttons_ops.c
index 9c8d46a41f9..b45abcf8068 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -268,8 +268,9 @@ static int file_browse_invoke(bContext *C, wmOperator *op, 
const wmEvent *event)
   FileBrowseOp *fbo;
   char *str;
 
-  if (CTX_wm_space_file(C)) {
-BKE_report(op->reports, RPT_ERROR, "Cannot activate a file selector, one 
already open");
+  const SpaceFile *sfile = CTX_wm_space_file(C);
+  if (sfile && sfile->op) {
+BKE_report(op->reports, RPT_ERROR, "Cannot activate a file selector 
dialog, one already open");
 return OPERATOR_CANCELLED;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4fa69fbda88] asset-shelf: Popup to select which catalogs are displayed in the asset shelf footer

2023-01-19 Thread Julian Eisel
Commit: 4fa69fbda8871753fcd2d1ae09d62d8dac880a47
Author: Julian Eisel
Date:   Thu Jan 19 11:50:45 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB4fa69fbda8871753fcd2d1ae09d62d8dac880a47

Popup to select which catalogs are displayed in the asset shelf footer

The selected catalogs are currently listed as simple labels in the
footer, just for testing.

===

M   source/blender/editors/asset/CMakeLists.txt
M   source/blender/editors/asset/ED_asset_shelf.h
M   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/interface/interface_region_popup.cc
M   source/blender/editors/interface/views/tree_view.cc
M   source/blender/editors/space_view3d/space_view3d.cc
M   source/blender/makesdna/DNA_screen_types.h
M   source/blender/makesdna/DNA_view3d_types.h
M   source/blender/makesrna/intern/rna_ui.c
M   source/blender/windowmanager/WM_types.h

===

diff --git a/source/blender/editors/asset/CMakeLists.txt 
b/source/blender/editors/asset/CMakeLists.txt
index 3e45a0bccdf..bc6b9a474b8 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -13,6 +13,8 @@ set(INC
   ../../windowmanager
   ../../../../intern/clog
   ../../../../intern/guardedalloc
+  # dna_type_offsets.h
+  ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern
   # RNA_prototypes.h
   ${CMAKE_BINARY_DIR}/source/blender/makesrna
 )
diff --git a/source/blender/editors/asset/ED_asset_shelf.h 
b/source/blender/editors/asset/ED_asset_shelf.h
index 5d5a483ef0b..8298cf8f042 100644
--- a/source/blender/editors/asset/ED_asset_shelf.h
+++ b/source/blender/editors/asset/ED_asset_shelf.h
@@ -11,18 +11,54 @@ extern "C" {
 #endif
 
 struct ARegionType;
+struct AssetShelfSettings;
 struct bContext;
+struct bContextDataResult;
+struct BlendDataReader;
+struct BlendWriter;
 struct wmWindowManager;
 
-void ED_region_asset_shelf_footer_init(struct wmWindowManager *wm, struct 
ARegion *region);
-void ED_region_asset_shelf_footer(const struct bContext *C, struct ARegion 
*region);
+/*  */
+/* Asset Shelf Regions */
 
-void ED_region_asset_shelf_listen(const struct wmRegionListenerParams *params);
+/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). 
*/
+void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params);
 
+void ED_asset_shelf_footer_region_init(struct wmWindowManager *wm, struct 
ARegion *region);
+void ED_asset_shelf_footer_region(const struct bContext *C, struct ARegion 
*region);
+void ED_asset_shelf_footer_region_listen(const struct wmRegionListenerParams 
*params);
 void ED_asset_shelf_footer_register(struct ARegionType *region_type,
 const char *idname,
 const int space_type);
 
+/*  */
+/* Asset Shelf Settings */
+
+/**
+ * Deep-copies \a shelf_settings into newly allocated memory. Must be freed 
using #MEM_freeN() or
+ * #MEM_delete().
+ */
+AssetShelfSettings *ED_asset_shelf_settings_duplicate(const AssetShelfSettings 
*shelf_settings);
+/**
+ * Frees the contained data, not \a shelf_settings itself.
+ */
+void ED_asset_shelf_settings_free(AssetShelfSettings *shelf_settings);
+
+void ED_asset_shelf_settings_blend_write(struct BlendWriter *writer,
+ const struct AssetShelfSettings 
*storage);
+void ED_asset_shelf_settings_blend_read_data(struct BlendDataReader *reader,
+ struct AssetShelfSettings 
**storage);
+
+/*  */
+
+/**
+ * Creates an `"asset_shelf_settings"` context member, pointing to \a 
shelf_settings.
+ */
+int ED_asset_shelf_context(const struct bContext *C,
+   const char *member,
+   struct bContextDataResult *result,
+   struct AssetShelfSettings *shelf_settings);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/editors/asset/intern/asset_shelf.cc 
b/source/blender/editors/asset/intern/asset_shelf.cc
index 42396d5d435..3ea457a9056 100644
--- a/source/blender/editors/asset/intern/asset_shelf.cc
+++ b/source/blender/editors/asset/intern/asset_shelf.cc
@@ -1,44 +1,411 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 
 /** \file
  * \ingroup edasset
  */
 
+#include "AS_asset_catalog.hh"
+#include "AS_asset_catalog_tree.hh"
+#include "AS_asset_library.hh"
+
+#include "BKE_context.h"
 #include "BKE_screen.h"
 
+#include "BLO_re

[Bf-blender-cvs] [47c9c311384] asset-shelf: Merge branch 'master' into asset-shelf

2023-01-18 Thread Julian Eisel
Commit: 47c9c31138420e3bc3648ffdecf58933d7cb03b7
Author: Julian Eisel
Date:   Wed Jan 18 18:32:25 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB47c9c31138420e3bc3648ffdecf58933d7cb03b7

Merge branch 'master' into asset-shelf

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e4e91bf8301] master: Fix crash when listing assets repeatedly in node search menus

2023-01-18 Thread Julian Eisel
Commit: e4e91bf8301ace526c7bab8bfd2b06eeecf47e20
Author: Julian Eisel
Date:   Wed Jan 18 18:17:02 2023 +0100
Branches: master
https://developer.blender.org/rBe4e91bf8301ace526c7bab8bfd2b06eeecf47e20

Fix crash when listing assets repeatedly in node search menus

When doing partial reloads of asset libraries (only reload assets from
the current file, e.g. after undo re-allocated ID pointers), we'd end up
with assets that don't have their asset data read correctly. It would
execute a branch that didn't set the asset library object necessary to
create and store asset representations.

Steps to reproduce were:
* Open .blend file with geometry node assets in there
* In a geometry node editor, press Shift+A to open the add menu
* Cancel
* Move a node
* Undo
* Press Shift+A again

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 22986672650..7a982914878 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3724,7 +3724,8 @@ static void 
filelist_readjob_load_asset_library_data(FileListReadJob *job_params
 return;
   }
   if (tmp_filelist->asset_library != nullptr) {
-/* Asset library already loaded. */
+/* Asset library itself is already loaded. Load assets into this. */
+job_params->load_asset_library = tmp_filelist->asset_library;
 return;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b3ee7ad2ccb] asset-shelf: Extend asset shelf region with a region for the catalogs & options

2023-01-17 Thread Julian Eisel
Commit: b3ee7ad2ccbf9aba225b55d6e46b5d7a73ef26d9
Author: Julian Eisel
Date:   Tue Jan 17 16:24:03 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rBb3ee7ad2ccbf9aba225b55d6e46b5d7a73ef26d9

Extend asset shelf region with a region for the catalogs & options

The new region is empty, except of a dummy button.

===

M   source/blender/blenloader/intern/versioning_300.cc
M   source/blender/editors/asset/CMakeLists.txt
A   source/blender/editors/asset/ED_asset_shelf.h
A   source/blender/editors/asset/intern/asset_shelf.cc
M   source/blender/editors/include/ED_screen.h
M   source/blender/editors/interface/interface_handlers.cc
M   source/blender/editors/interface/resources.cc
M   source/blender/editors/screen/area.c
M   source/blender/editors/screen/screen_edit.c
M   source/blender/editors/screen/screen_ops.c
M   source/blender/editors/space_view3d/CMakeLists.txt
M   source/blender/editors/space_view3d/space_view3d.cc
M   source/blender/makesdna/DNA_screen_types.h
M   source/blender/makesrna/intern/rna_screen.c
M   source/blender/windowmanager/intern/wm_event_system.cc

===

diff --git a/source/blender/blenloader/intern/versioning_300.cc 
b/source/blender/blenloader/intern/versioning_300.cc
index 7393f4fc171..460ee3b8719 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -3918,15 +3918,27 @@ void blo_do_versions_300(FileData *fd, Library * 
/*lib*/, Main *bmain)
   if (sl->spacetype == SPACE_VIEW3D) {
 ListBase *regionbase = (sl == area->spacedata.first) ? 
>regionbase :

>regionbase;
-ARegion *new_asset_shelf = do_versions_add_region_if_not_found(
-regionbase,
-RGN_TYPE_ASSET_SHELF,
-"asset shelf for view3d (versioning)",
-RGN_TYPE_UI);
-if (new_asset_shelf != nullptr) {
-  new_asset_shelf->alignment = RGN_ALIGN_BOTTOM;
-  new_asset_shelf->flag |= RGN_FLAG_HIDDEN;
-  new_asset_shelf->flag = RGN_FLAG_HIDDEN | RGN_FLAG_DYNAMIC_SIZE;
+{
+  ARegion *new_asset_shelf_footer = 
do_versions_add_region_if_not_found(
+  regionbase,
+  RGN_TYPE_ASSET_SHELF_FOOTER,
+  "asset shelf footer for view3d (versioning)",
+  RGN_TYPE_UI);
+  if (new_asset_shelf_footer != nullptr) {
+new_asset_shelf_footer->alignment = RGN_ALIGN_BOTTOM;
+new_asset_shelf_footer->flag |= RGN_FLAG_HIDDEN;
+  }
+}
+{
+  ARegion *new_asset_shelf = do_versions_add_region_if_not_found(
+  regionbase,
+  RGN_TYPE_ASSET_SHELF,
+  "asset shelf for view3d (versioning)",
+  RGN_TYPE_ASSET_SHELF_FOOTER);
+  if (new_asset_shelf != nullptr) {
+new_asset_shelf->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
+new_asset_shelf->flag |= RGN_FLAG_DYNAMIC_SIZE;
+  }
 }
   }
 }
diff --git a/source/blender/editors/asset/CMakeLists.txt 
b/source/blender/editors/asset/CMakeLists.txt
index a4d05ebaffe..3e45a0bccdf 100644
--- a/source/blender/editors/asset/CMakeLists.txt
+++ b/source/blender/editors/asset/CMakeLists.txt
@@ -30,6 +30,7 @@ set(SRC
   intern/asset_list.cc
   intern/asset_mark_clear.cc
   intern/asset_ops.cc
+  intern/asset_shelf.cc
   intern/asset_temp_id_consumer.cc
   intern/asset_type.cc
 
@@ -42,6 +43,7 @@ set(SRC
   ED_asset_list.h
   ED_asset_list.hh
   ED_asset_mark_clear.h
+  ED_asset_shelf.h
   ED_asset_temp_id_consumer.h
   ED_asset_type.h
   intern/asset_library_reference.hh
diff --git a/source/blender/editors/asset/ED_asset_shelf.h 
b/source/blender/editors/asset/ED_asset_shelf.h
new file mode 100644
index 000..5d5a483ef0b
--- /dev/null
+++ b/source/blender/editors/asset/ED_asset_shelf.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup edasset
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ARegionType;
+struct bContext;
+struct wmWindowManager;
+
+void ED_region_asset_shelf_footer_init(struct wmWindowManager *wm, struct 
ARegion *region);
+void ED_region_asset_shelf_footer(const struct bContext *C, struct ARegion 
*region);
+
+void ED_region_asset_shelf_listen(const struct wmRegionListenerParams *params);
+
+void ED_asset_shelf_footer_register(struct ARegionType *region_type,
+const char *idname,
+const int space_type);
+
+#

[Bf-blender-cvs] [8ddf492e7cf] asset-shelf: Basic asset shelf prototype

2023-01-17 Thread Julian Eisel
Commit: 8ddf492e7cf677f34315dcf5a8726ce45982ab7a
Author: Julian Eisel
Date:   Tue Jan 17 15:18:17 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB8ddf492e7cf677f34315dcf5a8726ce45982ab7a

Basic asset shelf prototype

Adds the necessary bits to be able to show an asset shelf template via
the pose library add-on.

===

M   source/blender/blenloader/intern/versioning_300.cc
M   source/blender/blenloader/intern/versioning_defaults.cc
M   source/blender/editors/asset/ED_asset_list.h
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/include/ED_screen.h
M   source/blender/editors/include/UI_interface.h
M   source/blender/editors/interface/CMakeLists.txt
M   source/blender/editors/interface/interface_layout.cc
A   source/blender/editors/interface/interface_template_asset_shelf.cc
M   source/blender/editors/interface/interface_template_asset_view.cc
M   source/blender/editors/screen/area.c
M   source/blender/editors/space_view3d/space_view3d.cc
M   source/blender/makesdna/DNA_asset_defaults.h
M   source/blender/makesrna/intern/rna_ui_api.c

===

diff --git a/source/blender/blenloader/intern/versioning_300.cc 
b/source/blender/blenloader/intern/versioning_300.cc
index 19f075241af..7393f4fc171 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -3926,10 +3926,18 @@ void blo_do_versions_300(FileData *fd, Library * 
/*lib*/, Main *bmain)
 if (new_asset_shelf != nullptr) {
   new_asset_shelf->alignment = RGN_ALIGN_BOTTOM;
   new_asset_shelf->flag |= RGN_FLAG_HIDDEN;
+  new_asset_shelf->flag = RGN_FLAG_HIDDEN | RGN_FLAG_DYNAMIC_SIZE;
 }
   }
 }
   }
 }
+
+/* Should we really use the "All" library by default? Consider loading 
time and memory usage.
+ */
+LISTBASE_FOREACH (WorkSpace *, workspace, >workspaces) {
+  workspace->asset_library_ref.type = ASSET_LIBRARY_ALL;
+  workspace->asset_library_ref.custom_library_index = -1;
+}
   }
 }
diff --git a/source/blender/blenloader/intern/versioning_defaults.cc 
b/source/blender/blenloader/intern/versioning_defaults.cc
index f6fe45ddcdf..fb5599d1d77 100644
--- a/source/blender/blenloader/intern/versioning_defaults.cc
+++ b/source/blender/blenloader/intern/versioning_defaults.cc
@@ -260,6 +260,9 @@ void BLO_update_defaults_workspace(WorkSpace *workspace, 
const char *app_templat
   BKE_workspace_tool_remove(workspace, static_cast(workspace->tools.first));
 }
 
+workspace->asset_library_ref.type = ASSET_LIBRARY_ALL;
+workspace->asset_library_ref.custom_library_index = -1;
+
 /* For 2D animation template. */
 if (STREQ(workspace->id.name + 2, "Drawing")) {
   workspace->object_mode = OB_MODE_PAINT_GPENCIL;
diff --git a/source/blender/editors/asset/ED_asset_list.h 
b/source/blender/editors/asset/ED_asset_list.h
index 635dc3bff32..b33f909c50b 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -55,8 +55,7 @@ struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle 
*asset_handle);
 /**
  * \return True if the region needs a UI redraw.
  */
-bool ED_assetlist_listen(const struct AssetLibraryReference *library_reference,
- const struct wmNotifier *notifier);
+bool ED_assetlist_listen(const struct wmNotifier *notifier);
 /**
  * \return The number of assets stored in the asset list for \a 
library_reference, or -1 if there
  * is no list fetched for it.
diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index 64934316413..3b3a434f0cc 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -116,7 +116,7 @@ class AssetList : NonCopyable {
   bool isLoaded() const;
   asset_system::AssetLibrary *asset_library() const;
   void iterate(AssetListIterFn fn) const;
-  bool listen(const wmNotifier ) const;
+  static bool listen(const wmNotifier );
   int size() const;
   void tagMainDataDirty() const;
   void remapID(ID *id_old, ID *id_new) const;
@@ -249,7 +249,7 @@ void AssetList::clear(bContext *C)
 /**
  * \return True if the asset-list needs a UI redraw.
  */
-bool AssetList::listen(const wmNotifier ) const
+bool AssetList::listen(const wmNotifier )
 {
   switch (notifier.category) {
 case NC_ID: {
@@ -481,14 +481,9 @@ ImBuf *ED_assetlist_asset_image_get(const AssetHandle 
*asset_handle)
   return filelist_geticon_image_ex(asset_handle->file_data);
 }
 
-bool ED_assetlist_listen(const AssetLibraryReference *library_reference,
- const wmNotifier *notifi

[Bf-blender-cvs] [d6df32a6f84] asset-shelf: Add basic (empty) asset shelf region

2023-01-17 Thread Julian Eisel
Commit: d6df32a6f841836c9b83f116bd95440346cc74fe
Author: Julian Eisel
Date:   Wed Dec 7 20:00:27 2022 +0100
Branches: asset-shelf
https://developer.blender.org/rBd6df32a6f841836c9b83f116bd95440346cc74fe

Add basic (empty) asset shelf region

===

M   source/blender/blenloader/intern/versioning_300.cc
M   source/blender/editors/screen/area.c
M   source/blender/editors/screen/screen_edit.c
M   source/blender/editors/space_view3d/space_view3d.cc
M   source/blender/makesdna/DNA_screen_types.h
M   source/blender/makesrna/intern/rna_screen.c

===

diff --git a/source/blender/blenloader/intern/versioning_300.cc 
b/source/blender/blenloader/intern/versioning_300.cc
index 85078a9902d..2acc95b7339 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -3732,5 +3732,26 @@ void blo_do_versions_300(FileData *fd, Library * 
/*lib*/, Main *bmain)
 image->seam_margin = 8;
   }
 }
+
+/* Add a properties sidebar to the spreadsheet editor. */
+LISTBASE_FOREACH (bScreen *, screen, >screens) {
+  LISTBASE_FOREACH (ScrArea *, area, >areabase) {
+LISTBASE_FOREACH (SpaceLink *, sl, >spacedata) {
+  if (sl->spacetype == SPACE_VIEW3D) {
+ListBase *regionbase = (sl == area->spacedata.first) ? 
>regionbase :
+   
>regionbase;
+ARegion *new_asset_shelf = do_versions_add_region_if_not_found(
+regionbase,
+RGN_TYPE_ASSET_SHELF,
+"asset shelf for view3d (versioning)",
+RGN_TYPE_UI);
+if (new_asset_shelf != nullptr) {
+  new_asset_shelf->alignment = RGN_ALIGN_BOTTOM;
+  new_asset_shelf->flag |= RGN_FLAG_HIDDEN;
+}
+  }
+}
+  }
+}
   }
 }
diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index a62e027ba03..3721774842c 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1262,7 +1262,8 @@ bool ED_region_is_overlap(int spacetype, int regiontype)
RGN_TYPE_UI,
RGN_TYPE_TOOL_PROPS,
RGN_TYPE_FOOTER,
-   RGN_TYPE_TOOL_HEADER)) {
+   RGN_TYPE_TOOL_HEADER,
+   RGN_TYPE_ASSET_SHELF)) {
 return true;
   }
 }
diff --git a/source/blender/editors/screen/screen_edit.c 
b/source/blender/editors/screen/screen_edit.c
index 14ed5987cc7..0acae5b5ea5 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1435,7 +1435,8 @@ static bScreen *screen_state_to_nonnormal(bContext *C,
RGN_TYPE_FOOTER,
RGN_TYPE_TOOLS,
RGN_TYPE_NAV_BAR,
-   RGN_TYPE_EXECUTE)) {
+   RGN_TYPE_EXECUTE,
+   RGN_TYPE_ASSET_SHELF)) {
 region->flag |= RGN_FLAG_HIDDEN;
   }
 }
diff --git a/source/blender/editors/space_view3d/space_view3d.cc 
b/source/blender/editors/space_view3d/space_view3d.cc
index 05fb0c6a720..b2da6630b38 100644
--- a/source/blender/editors/space_view3d/space_view3d.cc
+++ b/source/blender/editors/space_view3d/space_view3d.cc
@@ -289,6 +289,14 @@ static SpaceLink *view3d_create(const ScrArea * /*area*/, 
const Scene *scene)
   region->alignment = RGN_ALIGN_RIGHT;
   region->flag = RGN_FLAG_HIDDEN;
 
+  /* asset shelf */
+  region = MEM_cnew("asset shelf for view3d");
+
+  BLI_addtail(>regionbase, region);
+  region->regiontype = RGN_TYPE_ASSET_SHELF;
+  region->alignment = RGN_ALIGN_BOTTOM;
+  region->flag = RGN_FLAG_HIDDEN;
+
   /* main region */
   region = MEM_cnew("main region for view3d");
 
@@ -2137,6 +2145,15 @@ void ED_spacetype_view3d()
   art->draw = view3d_header_region_draw;
   BLI_addhead(>regiontypes, art);
 
+  /* regions: asset shelf */
+  art = MEM_cnew("spacetype view3d asset shelf region");
+  art->regionid = RGN_TYPE_ASSET_SHELF;
+  art->prefsizey = HEADERY * 4;
+  art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | 
ED_KEYMAP_HEADER;
+  art->init = view3d_header_region_init;
+  art->draw = view3d_header_region_draw;
+  BLI_addhead(>regiontypes, art);
+
   /* regions: hud */
   art = ED_area_type_hud(st->spaceid);
   BLI_addhead(>regiontypes, art);
diff --git a/source/blender/makesdna/DNA_screen_types.h 
b/source/blender/makesdna/DNA_screen_types.h
index 4d4bd9ef775..4feab97b6b7 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -657,8 +657,9 @@ typedef enum eRegion_Type {
   /* Region type used exclusively by internal code and add-ons to register 

[Bf-blender-cvs] [0e3f5c66733] asset-shelf: Merge branch 'master' into asset-shelf

2023-01-17 Thread Julian Eisel
Commit: 0e3f5c66733b6b2c48c2c334b3d5a1c859aed9a5
Author: Julian Eisel
Date:   Tue Jan 17 13:08:57 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB0e3f5c66733b6b2c48c2c334b3d5a1c859aed9a5

Merge branch 'master' into asset-shelf

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9b00338ed47] asset-shelf: Merge branch 'master' into asset-shelf

2023-01-17 Thread Julian Eisel
Commit: 9b00338ed47c755921aef19e419d4802c47d929b
Author: Julian Eisel
Date:   Mon Jan 16 17:22:56 2023 +0100
Branches: asset-shelf
https://developer.blender.org/rB9b00338ed47c755921aef19e419d4802c47d929b

Merge branch 'master' into asset-shelf

===



===

diff --cc source/blender/blenloader/intern/versioning_300.cc
index 2acc95b7339,4c45e1433ab..19f075241af
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@@ -3733,25 -3818,99 +3818,118 @@@ void blo_do_versions_300(FileData *fd, 
}
  }
  
- /* Add a properties sidebar to the spreadsheet editor. */
+ LISTBASE_FOREACH (bNodeTree *, ntree, >nodetrees) {
+   if (ntree->type == NTREE_GEOMETRY) {
+ version_geometry_nodes_primitive_uv_maps(*ntree);
+   }
+ }
+   }
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 305, 6)) {
+ LISTBASE_FOREACH (bScreen *, screen, >screens) {
+   LISTBASE_FOREACH (ScrArea *, area, >areabase) {
+ LISTBASE_FOREACH (SpaceLink *, sl, >spacedata) {
+   if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ v3d->overlay.flag |= int(V3D_OVERLAY_SCULPT_SHOW_MASK |
+  V3D_OVERLAY_SCULPT_SHOW_FACE_SETS);
+   }
+ }
+   }
+ }
+   }
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 305, 7)) {
+ LISTBASE_FOREACH (Light *, light, >lights) {
+   light->radius = light->area_size;
+ }
+ /* Grease Pencil Build modifier:
+  * Set default value for new natural draw-speed factor and maximum gap. */
+ if (!DNA_struct_elem_find(fd->filesdna, "BuildGpencilModifierData", 
"float", "speed_fac") ||
+ !DNA_struct_elem_find(fd->filesdna, "BuildGpencilModifierData", 
"float", "speed_maxgap")) {
+   LISTBASE_FOREACH (Object *, ob, >objects) {
+ LISTBASE_FOREACH (GpencilModifierData *, md, 
>greasepencil_modifiers) {
+   if (md->type == eGpencilModifierType_Build) {
+ BuildGpencilModifierData *mmd = (BuildGpencilModifierData *)md;
+ mmd->speed_fac = 1.2f;
+ mmd->speed_maxgap = 0.5f;
+   }
+ }
+   }
+ }
+   }
+ 
+   if (!MAIN_VERSION_ATLEAST(bmain, 305, 8)) {
+ const int CV_SCULPT_SELECTION_ENABLED = (1 << 1);
+ LISTBASE_FOREACH (Curves *, curves_id, >hair_curves) {
+   curves_id->flag &= ~CV_SCULPT_SELECTION_ENABLED;
+ }
+ LISTBASE_FOREACH (Curves *, curves_id, >hair_curves) {
+   BKE_id_attribute_rename(_id->id, ".selection_point_float", 
".selection", nullptr);
+   BKE_id_attribute_rename(_id->id, ".selection_curve_float", 
".selection", nullptr);
+ }
+ 
+ /* Toggle the Invert Vertex Group flag on Armature modifiers in some 
cases. */
+ LISTBASE_FOREACH (Object *, ob, >objects) {
+   bool after_armature = false;
+   LISTBASE_FOREACH (ModifierData *, md, >modifiers) {
+ if (md->type == eModifierType_Armature) {
+   ArmatureModifierData *amd = (ArmatureModifierData *)md;
+   if (amd->multi) {
+ /* Toggle the invert vertex group flag on operational Multi 
Modifier entries. */
+ if (after_armature && amd->defgrp_name[0]) {
+   amd->deformflag ^= ARM_DEF_INVERT_VGROUP;
+ }
+   }
+   else {
+ /* Disabled multi modifiers don't reset propagation, but 
non-multi ones do. */
+ after_armature = false;
+   }
+   /* Multi Modifier is only valid and operational after an active 
Armature modifier. */
+   if (md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
+ after_armature = true;
+   }
+ }
+ else if (ELEM(md->type, eModifierType_Lattice, 
eModifierType_MeshDeform)) {
+   /* These modifiers will also allow a following Multi Modifier to 
work. */
+   after_armature = (md->mode & (eModifierMode_Realtime | 
eModifierMode_Render)) != 0;
+ }
+ else {
+   after_armature = false;
+ }
+   }
+ }
+   }
+ 
+   /**
+* Versioning code until next subversion bump goes here.
+*
+* \note Be sure to check when bumping the version:
+* - "versioning_userdef.c", #blo_do_versions_userdef
+* - "versioning_userdef.c", #do_versions_theme
+*
+* \note Keep this message at the bottom of the function.
+*/
+   {
+ /* Keep this block, even when empty. */
 +LISTBASE_FOREACH (bScreen *, screen, >screens) {
 +  LISTBASE_FOREACH (ScrArea *, area, >areabase) {
 +LISTBASE_FOREACH (

[Bf-blender-cvs] [2c6ed49c034] master: Cleanup: Rename confusing region variable

2023-01-17 Thread Julian Eisel
Commit: 2c6ed49c0343840a8ff05f326e5db4dd3a218775
Author: Julian Eisel
Date:   Tue Jan 17 13:07:05 2023 +0100
Branches: master
https://developer.blender.org/rB2c6ed49c0343840a8ff05f326e5db4dd3a218775

Cleanup: Rename confusing region variable

`scaleare` reads like "scale area", but should read "scale region".

===

M   source/blender/editors/screen/screen_ops.c

===

diff --git a/source/blender/editors/screen/screen_ops.c 
b/source/blender/editors/screen/screen_ops.c
index bd6d6d27d7c..a064f4632b5 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -2586,21 +2586,21 @@ typedef struct RegionMoveData {
 
 } RegionMoveData;
 
-static int area_max_regionsize(ScrArea *area, ARegion *scalear, AZEdge edge)
+static int area_max_regionsize(ScrArea *area, ARegion *scale_region, AZEdge 
edge)
 {
   int dist;
 
   /* regions in regions. */
-  if (scalear->alignment & RGN_SPLIT_PREV) {
-const int align = RGN_ALIGN_ENUM_FROM_MASK(scalear->alignment);
+  if (scale_region->alignment & RGN_SPLIT_PREV) {
+const int align = RGN_ALIGN_ENUM_FROM_MASK(scale_region->alignment);
 
 if (ELEM(align, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
-  ARegion *region = scalear->prev;
-  dist = region->winy + scalear->winy - U.pixelsize;
+  ARegion *region = scale_region->prev;
+  dist = region->winy + scale_region->winy - U.pixelsize;
 }
 else /* if (ELEM(align, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) */ {
-  ARegion *region = scalear->prev;
-  dist = region->winx + scalear->winx - U.pixelsize;
+  ARegion *region = scale_region->prev;
+  dist = region->winx + scale_region->winx - U.pixelsize;
 }
   }
   else {
@@ -2614,23 +2614,23 @@ static int area_max_regionsize(ScrArea *area, ARegion 
*scalear, AZEdge edge)
 /* Subtract the width of regions on opposite side
  * prevents dragging regions into other opposite regions. */
 LISTBASE_FOREACH (ARegion *, region, >regionbase) {
-  if (region == scalear) {
+  if (region == scale_region) {
 continue;
   }
 
-  if (scalear->alignment == RGN_ALIGN_LEFT && region->alignment == 
RGN_ALIGN_RIGHT) {
+  if (scale_region->alignment == RGN_ALIGN_LEFT && region->alignment == 
RGN_ALIGN_RIGHT) {
 dist -= region->winx;
   }
-  else if (scalear->alignment == RGN_ALIGN_RIGHT && region->alignment == 
RGN_ALIGN_LEFT) {
+  else if (scale_region->alignment == RGN_ALIGN_RIGHT && region->alignment 
== RGN_ALIGN_LEFT) {
 dist -= region->winx;
   }
-  else if (scalear->alignment == RGN_ALIGN_TOP &&
+  else if (scale_region->alignment == RGN_ALIGN_TOP &&
(region->alignment == RGN_ALIGN_BOTTOM ||
 ELEM(
 region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, 
RGN_TYPE_FOOTER))) {
 dist -= region->winy;
   }
-  else if (scalear->alignment == RGN_ALIGN_BOTTOM &&
+  else if (scale_region->alignment == RGN_ALIGN_BOTTOM &&
(region->alignment == RGN_ALIGN_TOP ||
 ELEM(
 region->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, 
RGN_TYPE_FOOTER))) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b999b79d087] blender-projects-basics: Support project asset libraries in new asset library loading

2023-01-12 Thread Julian Eisel
Commit: b999b79d087ce6633919971f37c4514421a2e60a
Author: Julian Eisel
Date:   Thu Jan 12 14:37:39 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rBb999b79d087ce6633919971f37c4514421a2e60a

Support project asset libraries in new asset library loading

===

M   source/blender/asset_system/intern/asset_library_service.cc

===

diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index f2e0250dde6..37ee0192f70 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -78,7 +78,8 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 }
 case ASSET_LIBRARY_ALL:
   return get_asset_library_all(bmain);
-case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES: {
+case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES:
+case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
   std::string root_path = root_path_from_library_ref(library_reference);
 
   if (!root_path.empty()) {
@@ -87,7 +88,6 @@ AssetLibrary *AssetLibraryService::get_asset_library(
   break;
 }
   }
-  /* TODO project libraries */
 
   return nullptr;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e63671c21d7] blender-projects-basics: Support & use new asset library path query from master

2023-01-10 Thread Julian Eisel
Commit: e63671c21d7b07dfb0966ba710aac9b6d7e9306c
Author: Julian Eisel
Date:   Tue Jan 10 16:45:39 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rBe63671c21d7b07dfb0966ba710aac9b6d7e9306c

Support & use new asset library path query from master

===

M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/space_file/filesel.cc

===

diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index acfb49770cd..f2e0250dde6 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -4,9 +4,14 @@
  * \ingroup asset_system
  */
 
+#include 
+#include 
+
 #include "BKE_asset_library_custom.h"
 #include "BKE_blender.h"
+#include "BKE_blender_project.h"
 
+#include "BLI_path_util.h"
 #include "BLI_string_ref.hh"
 
 #include "DNA_asset_types.h"
@@ -188,16 +193,49 @@ std::string 
AssetLibraryService::root_path_from_library_ref(
 return "";
   }
 
-  BLI_assert(library_reference.type == ASSET_LIBRARY_CUSTOM);
   BLI_assert(library_reference.custom_library_index >= 0);
 
-  bUserAssetLibrary *user_library = 
BKE_preferences_asset_library_find_from_index(
-  , library_reference.custom_library_index);
-  if (!user_library || !user_library->path[0]) {
-return "";
+  switch (library_reference.type) {
+case ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES: {
+  CustomAssetLibraryDefinition *user_library = 
BKE_asset_library_custom_find_from_index(
+  _libraries, library_reference.custom_library_index);
+  if (user_library && user_library->path[0]) {
+return user_library->path;
+  }
+  break;
+}
+case ASSET_LIBRARY_CUSTOM_FROM_PROJECT: {
+  BlenderProject *project = BKE_project_active_get();
+  if (!project) {
+return "";
+  }
+
+  ListBase *project_libraries = 
BKE_project_custom_asset_libraries_get(project);
+  CustomAssetLibraryDefinition *project_library_ = 
BKE_asset_library_custom_find_from_index(
+  project_libraries, library_reference.custom_library_index);
+  if (!project_library_) {
+return "";
+  }
+
+  /* Project asset libraries typically use relative paths (relative to 
project root directory).
+   */
+  if (BLI_path_is_rel(project_library_->path)) {
+const char *project_root_path = BKE_project_root_path_get(project);
+char path[1024]; /* FILE_MAX */
+BLI_path_join(path, sizeof(path), project_root_path, 
project_library_->path);
+return path;
+  }
+  else {
+return project_library_->path;
+  }
+  break;
+}
+default:
+  BLI_assert_unreachable();
+  break;
   }
 
-  return user_library->path;
+  return "";
 }
 
 void AssetLibraryService::allocate_service_instance()
diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index b23223ed02b..a6089cf8ae6 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -153,16 +153,6 @@ void AssetList::setup()
   filelist_setindexer(files, use_asset_indexer ? _indexer_asset : 
_indexer_noop);
 
   char path[FILE_MAXDIR] = "";
-#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);
-  }
-#endif
   if (!asset_lib_path.empty()) {
 BLI_strncpy(path, asset_lib_path.c_str(), sizeof(path));
   }
diff --git a/source/blender/editors/space_file/filesel.cc 
b/source/blender/editors/space_file/filesel.cc
index 3654979d661..da76ba81da9 100644
--- a/source/blender/editors/space_file/filesel.cc
+++ b/source/blender/editors/space_file/filesel.cc
@@ -23,6 +23,8 @@
 #  include 
 #endif
 
+#include "AS_asset_library.hh"
+
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
@@ -412,45 +414,26 @@ static void 
fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
 {
   AssetLibraryReference *library = _params->asset_library_ref;
   FileSelectParams *base_params = _params->base_params;
-  CustomAssetLibraryDefinition *custom_library =
-  ED_as

[Bf-blender-cvs] [3ff321bc982] blender-projects-basics: Merge branch 'master' into blender-projects-basics

2023-01-10 Thread Julian Eisel
Commit: 3ff321bc98233163b0b3e53107683b030a2ef936
Author: Julian Eisel
Date:   Tue Jan 10 16:37:29 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rB3ff321bc98233163b0b3e53107683b030a2ef936

Merge branch 'master' into blender-projects-basics

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9b8c2f91f60] master: Cleanup: Compile `filesel.c` in C++

2023-01-10 Thread Julian Eisel
Commit: 9b8c2f91f6065593aeed36067ce74fe5991233fb
Author: Julian Eisel
Date:   Tue Jan 10 16:33:00 2023 +0100
Branches: master
https://developer.blender.org/rB9b8c2f91f6065593aeed36067ce74fe5991233fb

Cleanup: Compile `filesel.c` in C++

This is a mere "get this to compile in C++", didn't do changes like
using `MEM_cnew()` instead of `MEM_calloc()`.

Needed for the blender-project-basics branch, so I don't have to write C
wrappers for a single call from this file.

===

M   source/blender/editors/space_file/CMakeLists.txt
R097source/blender/editors/space_file/filesel.c 
source/blender/editors/space_file/filesel.cc

===

diff --git a/source/blender/editors/space_file/CMakeLists.txt 
b/source/blender/editors/space_file/CMakeLists.txt
index ede48060126..2c3b775f796 100644
--- a/source/blender/editors/space_file/CMakeLists.txt
+++ b/source/blender/editors/space_file/CMakeLists.txt
@@ -32,7 +32,7 @@ set(SRC
   file_panels.c
   file_utils.c
   filelist.cc
-  filesel.c
+  filesel.cc
   folder_history.cc
   fsmenu.c
   space_file.c
diff --git a/source/blender/editors/space_file/filesel.c 
b/source/blender/editors/space_file/filesel.cc
similarity index 97%
rename from source/blender/editors/space_file/filesel.c
rename to source/blender/editors/space_file/filesel.cc
index 0b0ab2b0d66..32181a9f5f6 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.cc
@@ -5,9 +5,9 @@
  * \ingroup spfile
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -99,8 +99,8 @@ static void fileselect_ensure_updated_asset_params(SpaceFile 
*sfile)
   FileAssetSelectParams *asset_params = sfile->asset_params;
 
   if (!asset_params) {
-asset_params = sfile->asset_params = MEM_callocN(sizeof(*asset_params),
- "FileAssetSelectParams");
+asset_params = sfile->asset_params = static_cast(
+MEM_callocN(sizeof(*asset_params), "FileAssetSelectParams"));
 asset_params->base_params.details_flags = 
U_default.file_space_data.details_flags;
 asset_params->asset_library_ref.type = ASSET_LIBRARY_LOCAL;
 asset_params->asset_library_ref.custom_library_index = -1;
@@ -139,7 +139,8 @@ static FileSelectParams 
*fileselect_ensure_updated_file_params(SpaceFile *sfile)
 
   /* create new parameters if necessary */
   if (!sfile->params) {
-sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams");
+sfile->params = static_cast(
+MEM_callocN(sizeof(FileSelectParams), "fileselparams"));
 /* set path to most recently opened .blend */
 BLI_split_dirfile(blendfile_path,
   sfile->params->dir,
@@ -534,7 +535,7 @@ void ED_fileselect_activate_by_id(SpaceFile *sfile, ID 
*asset_id, const bool def
 
 static void on_reload_select_by_relpath(SpaceFile *sfile, onReloadFnData 
custom_data)
 {
-  const char *relative_path = custom_data;
+  const char *relative_path = static_cast(custom_data);
   ED_fileselect_activate_by_relpath(sfile, relative_path);
 }
 
@@ -879,7 +880,9 @@ FileAttributeColumnType 
file_attribute_column_type_find_isect(const View2D *v2d,
 /* Column header drawing doesn't use left tile border, so subtract it. */
 rel_x = mx - (tile_x - layout->tile_border_x);
 
-for (FileAttributeColumnType column = 0; column < ATTRIBUTE_COLUMN_MAX; 
column++) {
+for (FileAttributeColumnType column = FileAttributeColumnType(0);
+ column < ATTRIBUTE_COLUMN_MAX;
+ column = FileAttributeColumnType(int(column) + 1)) {
   if (!file_attribute_column_type_enabled(params, column)) {
 continue;
   }
@@ -940,8 +943,10 @@ static void file_attribute_columns_widths(const 
FileSelectParams *params, FileLa
   /* Name column uses remaining width */
   else {
 int remwidth = layout->tile_w;
-for (FileAttributeColumnType column_type = ATTRIBUTE_COLUMN_MAX - 1; 
column_type >= 0;
- column_type--) {
+for (FileAttributeColumnType column_type =
+ FileAttributeColumnType(int(ATTRIBUTE_COLUMN_MAX) - 1);
+ column_type >= 0;
+ column_type = FileAttributeColumnType(int(column_type) - 1)) {
   if ((column_type == COLUMN_NAME) ||
   !file_attribute_column_type_enabled(params, column_type)) {
 continue;
@@ -978,7 +983,8 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, 
ARegion *region)
   int textheight;
 
   if (sfile->layout == NULL) {
-sfile->layout = MEM_callocN(sizeof(struct FileLayout), "file_layout");
+sfile->layout = static_cast(
+MEM_callocN(sizeof(struct FileLayout), "file_layout"));
 sfile->layout->dirty = true;
   }
   else if (sfile->layout-&g

[Bf-blender-cvs] [f0eba2fe6c2] blender-projects-basics: Merge branch 'master' into blender-projects-basics

2023-01-10 Thread Julian Eisel
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 _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(
- _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 *, c

[Bf-blender-cvs] [35e54b52e6e] master: Assets: "All" asset library

2023-01-10 Thread Julian Eisel
Commit: 35e54b52e6ecbb0465f1a28e0915769160b7bf86
Author: Julian Eisel
Date:   Tue Jan 10 15:27:28 2023 +0100
Branches: master
https://developer.blender.org/rB35e54b52e6ecbb0465f1a28e0915769160b7bf86

Assets: "All" asset library

Adds a new built-in asset library that contains all other asset
libraries visible in the asset library selector menu. This also means
all their asset catalogs will be displayed as a single merged tree. The
asset catalogs are not editable, since this would require support for
writing multiple catalog definition files, which isn't there yet.

Often it's not relevant where an asset comes from. Users just want to be
able to get an asset quickly, comparable to how people use a search
engine to browse images or the web itself, instead of first going to a
dedicated platform. They don't want to bother with first choosing where
they want the result to come from.
This especially is needed for the Asset Shelf (T102879) that is being
developed for the brush assets project (T101895). With this, users will
have access to all their brushes efficiently from the 3D view, without
much browsing.

Did an informal review of the asset system bits with Sybren.

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_catalog.cc
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh
M   source/blender/editors/asset/ED_asset_catalog.h
M   source/blender/editors/asset/ED_asset_catalog.hh
M   source/blender/editors/asset/ED_asset_library.h
M   source/blender/editors/asset/ED_asset_list.hh
M   source/blender/editors/asset/intern/asset_catalog.cc
M   source/blender/editors/asset/intern/asset_library_reference_enum.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/asset/intern/asset_ops.cc
M   source/blender/editors/space_file/asset_catalog_tree_view.cc
M   source/blender/editors/space_file/filelist.cc
M   source/blender/editors/space_file/filesel.c
M   source/blender/makesdna/DNA_asset_defaults.h
M   source/blender/makesdna/DNA_asset_types.h
M   source/blender/makesdna/DNA_space_types.h

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 87b9425c8c6..8f818c6a768 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -45,11 +45,17 @@ class AssetCatalogService {
   Vector> undo_snapshots_;
   Vector> redo_snapshots_;
 
+  const bool is_read_only_ = false;
+
  public:
   static const CatalogFilePath DEFAULT_CATALOG_FILENAME;
 
+  struct read_only_tag {
+  };
+
  public:
   AssetCatalogService();
+  explicit AssetCatalogService(read_only_tag);
   explicit AssetCatalogService(const CatalogFilePath _library_root);
 
   /**
@@ -62,11 +68,24 @@ class AssetCatalogService {
   void tag_has_unsaved_changes(AssetCatalog *edited_catalog);
   bool has_unsaved_changes() const;
 
+  /**
+   * Check if this is a read-only service meaning the user shouldn't be able 
to do edits. This is
+   * not enforced by internal catalog code, the catalog service user is 
responsible for it. For
+   * example the UI should disallow edits.
+   */
+  bool is_read_only() const;
+
   /** Load asset catalog definitions from the files found in the asset 
library. */
   void load_from_disk();
   /** Load asset catalog definitions from the given file or directory. */
   void load_from_disk(const CatalogFilePath _or_directory_path);
 
+  /**
+   * Duplicate the catalogs from \a other_service into this one. Does not 
rebuild the tree, this
+   * needs to be done by the caller (call #rebuild_tree()!).
+   */
+  void add_from_existing(const AssetCatalogService _service);
+
   /**
* Write the catalog definitions to disk.
*
@@ -105,6 +124,15 @@ class AssetCatalogService {
*/
   void reload_catalogs();
 
+  /**
+   * Make sure the tree is updated to the latest collection of catalogs stored 
in this service.
+   * Does not depend on a CDF file being available so this can be called on a 
service that stores
+   * catalogs that are not stored in a CDF.
+   * Most API functions that modify catalog data will trigger this, unless 
otherwise specified (for
+   * batch operations).
+   */
+  void rebuild_tree();
+
   /** Return catalog with the given ID. Return nullptr if not found. */
   AssetCatalog *find_catalog(CatalogID catalog_id) const;
 
@@ -222,7 +250,6 @@ class AssetCatalogService {
   const CatalogFilePath _file_path);
 
   std::unique_ptr read_into_tree();
-  void rebuild_tree();
 
   /**
* For every catalog, ensure that

[Bf-blender-cvs] [66af16571df] master: Refactor: Use new "All" asset library to extend node menus with assets

2023-01-10 Thread Julian Eisel
Commit: 66af16571dfe3cb314a59edfee3469a557821e47
Author: Julian Eisel
Date:   Tue Jan 10 15:37:31 2023 +0100
Branches: master
https://developer.blender.org/rB66af16571dfe3cb314a59edfee3469a557821e47

Refactor: Use new "All" asset library to extend node menus with assets

Updates the add and search menu of the node editor to use the new "All"
asset library introduced in the previous commit. This simplifies code by
removing redundant logic to merge contents of multiple asset libraries.

===

M   source/blender/editors/space_node/add_menu_assets.cc
M   source/blender/editors/space_node/add_node_search.cc

===

diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index bb5f33f8cf0..fc250b63ffe 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -49,13 +49,6 @@ struct LibraryAsset {
   AssetHandle handle;
 };
 
-struct LibraryCatalog {
-  asset_system::AssetLibrary *library;
-  /* Catalog pointers are not save to store. Use the catalog ID instead and 
lookup the catalog when
-   * needed. */
-  const asset_system::CatalogID catalog_id;
-};
-
 struct AssetItemTree {
   asset_system::AssetCatalogTree catalogs;
   MultiValueMap assets_per_path;
@@ -63,14 +56,18 @@ struct AssetItemTree {
   full_catalog_per_tree_item;
 };
 
+static AssetLibraryReference all_library_reference()
+{
+  AssetLibraryReference all_library_ref{};
+  all_library_ref.custom_library_index = -1;
+  all_library_ref.type = ASSET_LIBRARY_ALL;
+  return all_library_ref;
+}
+
 static bool all_loading_finished()
 {
-  for (const AssetLibraryReference  : 
asset_system::all_valid_asset_library_refs()) {
-if (!ED_assetlist_is_loaded()) {
-  return false;
-}
-  }
-  return true;
+  AssetLibraryReference all_library_ref = all_library_reference();
+  return ED_assetlist_is_loaded(_library_ref);
 }
 
 static AssetItemTree build_catalog_tree(const bContext , const bNodeTree 
*node_tree)
@@ -78,68 +75,52 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
   if (!node_tree) {
 return {};
   }
-  const Main  = *CTX_data_main();
-  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;
-  asset_system::AssetCatalogTree catalogs_from_all_libraries;
-  for (const AssetLibraryReference _ref : all_libraries) {
-if (asset_system::AssetLibrary *library = AS_asset_library_load(, 
library_ref)) {
-  if (asset_system::AssetCatalogTree *tree = 
library->catalog_service->get_catalog_tree()) {
-tree->foreach_item([&](asset_system::AssetCatalogTreeItem ) {
-  const asset_system::CatalogID  = 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, 
id});
-});
-  }
-}
-  }
 
   /* Find all the matching node group assets for every catalog path. */
   MultiValueMap assets_per_path;
-  for (const AssetLibraryReference _ref : all_libraries) {
-AssetFilterSettings type_filter{};
-type_filter.id_types = FILTER_ID_NT;
-
-ED_assetlist_storage_fetch(_ref, );
-ED_assetlist_ensure_previews_job(_ref, );
-ED_assetlist_iterate(library_ref, [&](AssetHandle asset) {
-  if (!ED_asset_filter_matches_asset(_filter, )) {
-return true;
-  }
-  const AssetMetaData _data = *ED_asset_handle_get_metadata();
-  const IDProperty *tree_type = BKE_asset_metadata_idprop_find(_data, 
"type");
-  if (tree_type == nullptr || IDP_Int(tree_type) != node_tree->type) {
-return true;
-  }
-  if (BLI_uuid_is_nil(meta_data.catalog_id)) {
-return true;
-  }
-  const LibraryCatalog *library_catalog = 
id_to_catalog_map.lookup_ptr(meta_data.catalog_id);
-  if (library_catalog == nullptr) {
-return true;
-  }
-  const asset_system::AssetCatalog *catalog =
-  
library_catalog->library->catalog_service->find_catalog(library_catalog->catalog_id);
-  assets_per_path.add(catalog->path, LibraryAsset{library_ref, asset});
-  return true;
-});
+
+  AssetFilterSettings type_filter{};
+  type_filter.id_types = FILTER_ID_NT;
+
+  const AssetLibraryReference all_library_ref = all_library_reference();
+
+  ED_assetlist_storage_fetch(_library_ref, );
+  ED_assetlist_ensure_pre

[Bf-blender-cvs] [59eec2f67da] temp-asset-library-all: Cleanups after informal review with Sybren

2023-01-10 Thread Julian Eisel
Commit: 59eec2f67da3ed18768a6742b2a0c67c8cb778c9
Author: Julian Eisel
Date:   Tue Jan 10 15:12:12 2023 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB59eec2f67da3ed18768a6742b2a0c67c8cb778c9

Cleanups after informal review with Sybren

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/asset/ED_asset_catalog.hh
M   source/blender/editors/asset/ED_asset_list.hh
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 14d356c703e..b3b7d421724 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -56,7 +56,7 @@ class AssetLibrary {
*/
   std::unique_ptr asset_storage_;
 
-  std::function on_refresh_;
+  std::function on_refresh_;
 
   bCallbackFuncStore on_save_callback_store_{};
 
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 61d45bd4569..2379e738e37 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -160,7 +160,7 @@ void AssetLibrary::load_catalogs()
 void AssetLibrary::refresh()
 {
   if (on_refresh_) {
-on_refresh_();
+on_refresh_(*this);
   }
 }
 
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 1c212cb1136..af48a173bc0 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -79,7 +79,8 @@ AssetLibrary *AssetLibraryService::get_asset_library(
   if (!root_path.empty()) {
 return get_asset_library_on_disk(root_path);
   }
-} break;
+  break;
+}
   }
 
   return nullptr;
@@ -107,7 +108,7 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_on_disk(StringRefNull root_
   lib->on_blend_save_handler_register();
   lib->load_catalogs();
   /* Reload catalogs on refresh. */
-  lib->on_refresh_ = [lib]() { lib->catalog_service->reload_catalogs(); };
+  lib->on_refresh_ = [](AssetLibrary ) { 
self.catalog_service->reload_catalogs(); };
 
   on_disk_libraries_.add_new(normalized_root_path, std::move(lib_uptr));
   CLOG_INFO(, 2, "get \"%s\" (loaded)", normalized_root_path.c_str());
@@ -130,6 +131,23 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_current_file()
   return lib;
 }
 
+static void rebuild_all_library(AssetLibrary _library, const bool 
reload_catalogs)
+{
+  /* Start with empty catalog storage. */
+  all_library.catalog_service = std::make_unique(
+  AssetCatalogService::read_only_tag());
+
+  AssetLibrary::foreach_loaded(
+  [&](AssetLibrary ) {
+if (reload_catalogs) {
+  nested.catalog_service->reload_catalogs();
+}
+
all_library.catalog_service->add_from_existing(*nested.catalog_service);
+  },
+  false);
+  all_library.catalog_service->rebuild_tree();
+}
+
 AssetLibrary *AssetLibraryService::get_asset_library_all(const Main *bmain)
 {
   /* (Re-)load all other asset libraries. */
@@ -152,29 +170,14 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_all(const Main *bmain)
   CLOG_INFO(, 2, "get all lib (loaded)");
   all_library_ = std::make_unique();
 
-  AssetLibrary _library = *all_library_;
-  auto build_catalogs_fn = [_library](const bool is_first_load) {
-/* Start with empty catalog storage. */
-all_library.catalog_service = std::make_unique(
-AssetCatalogService::read_only_tag());
-
-/* (Re-)load catalogs on refresh, and merge them into the all library. */
-AssetLibrary::foreach_loaded(
-[&](AssetLibrary ) {
-  /* On first load the catalogs were read just above, no need to 
reload. */
-  if (!is_first_load) {
-nested.catalog_service->reload_catalogs();
-  }
-  
all_library.catalog_service->add_from_existing(*nested.catalog_service);
-},
-false);
-all_library.catalog_service->rebuild_tree();
-  };
+  /* Don't reload catalogs on this initial read, they've just been loaded 
above. */
+  rebuild_all_library(*all_library_, /*reload_catlogs=*/false);
 
-  build_catalogs_fn(true);
-  all_library.on_refresh_ = [build_catalogs_fn]() { build_catalogs_fn(false); 
};
+  all_library_->on_refresh_ = [](AssetLibrary _library) {
+rebuild_all_library(all_library, /*reload_catalogs=*/true);
+  };
 
-  return _library;
+  return all_l

[Bf-blender-cvs] [a83d40c497c] temp-asset-library-all: Fix all library always tagging catalogs as changed

2023-01-09 Thread Julian Eisel
Commit: a83d40c497c9ad78968c0e7ef3b1a832a33d5974
Author: Julian Eisel
Date:   Mon Jan 9 12:43:36 2023 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBa83d40c497c9ad78968c0e7ef3b1a832a33d5974

Fix all library always tagging catalogs as changed

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/intern/asset_catalog.cc
M   source/blender/asset_system/intern/asset_library_service.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 1d5401f0b0e..8f818c6a768 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -299,7 +299,7 @@ class AssetCatalogCollection {
   std::unique_ptr deep_copy() const;
   /**
* Copy the catalogs from \a other and append them to this collection. 
Copies no other data
-   * otherwise (but marks as having unsaved changes).
+   * otherwise.
*/
   void add_catalogs_from_existing(const AssetCatalogCollection );
 
diff --git a/source/blender/asset_system/intern/asset_catalog.cc 
b/source/blender/asset_system/intern/asset_catalog.cc
index 0be1d8aa30b..6fd01ab14f7 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -689,7 +689,6 @@ static void copy_catalog_map_into_existing(const 
OwningAssetCatalogMap ,
 
 void AssetCatalogCollection::add_catalogs_from_existing(const 
AssetCatalogCollection )
 {
-  has_unsaved_changes_ = true;
   copy_catalog_map_into_existing(other.catalogs_, catalogs_);
 }
 
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index d2bd6ff36c2..1c212cb1136 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -158,7 +158,7 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_all(const Main *bmain)
 all_library.catalog_service = std::make_unique(
 AssetCatalogService::read_only_tag());
 
-/* (Re-)load catalogs on refresh. */
+/* (Re-)load catalogs on refresh, and merge them into the all library. */
 AssetLibrary::foreach_loaded(
 [&](AssetLibrary ) {
   /* On first load the catalogs were read just above, no need to 
reload. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3af1113a96a] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2023-01-09 Thread Julian Eisel
Commit: 3af1113a96af9299668f8696a58e8d2cc9dee12d
Author: Julian Eisel
Date:   Mon Jan 9 11:40:03 2023 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB3af1113a96af9299668f8696a58e8d2cc9dee12d

Merge branch 'master' into temp-asset-library-all

===



===

diff --cc source/blender/editors/asset/intern/asset_list.cc
index e086e5702d1,caceedbd4a5..2adf2a170e5
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@@ -114,7 -111,7 +113,8 @@@ class AssetList : NonCopyable 
void clear(bContext *C);
  
bool needsRefetch() const;
+   bool isLoaded() const;
 +  asset_system::AssetLibrary *asset_library() const;
void iterate(AssetListIterFn fn) const;
bool listen(const wmNotifier ) const;
int size() const;
@@@ -181,11 -190,11 +181,16 @@@ bool AssetList::needsRefetch() cons
return filelist_needs_force_reset(filelist_) || 
filelist_needs_reading(filelist_);
  }
  
+ bool AssetList::isLoaded() const
+ {
+   return filelist_is_ready(filelist_);
+ }
+ 
 +asset_system::AssetLibrary *AssetList::asset_library() const
 +{
 +  return reinterpret_cast(filelist_asset_library(filelist_));
 +}
 +
  void AssetList::iterate(AssetListIterFn fn) const
  {
FileList *files = filelist_;
diff --cc source/blender/editors/space_file/filelist.cc
index 44f846f8595,cd1c3f8280b..7447f5d7986
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@@ -855,19 -850,12 +854,13 @@@ static bool is_filtered_asset(FileListI
  }
  
  static bool is_filtered_lib_type(FileListInternEntry *file,
-  const char *root,
+  const char * /*root*/,
   FileListFilter *filter)
  {
-   if (root) {
- char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name;
- 
- BLI_path_join(path, sizeof(path), root, file->relpath);
- 
- if (BLO_library_path_explode(path, dir, , )) {
-   return is_filtered_id_file_type(file, group, name, filter);
- }
+   if (file->typeflag & FILE_TYPE_BLENDERLIB) {
+ return is_filtered_id_file_type(file, file->blentype, file->name, filter);
}
 +
return is_filtered_file_type(file, filter);
  }
  
@@@ -2874,11 -2850,8 +2861,11 @@@ void filelist_entry_parent_select_set(F
}
  }
  
- bool filelist_islibrary(struct FileList *filelist, char *dir, char **r_group)
+ bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
  {
 +  if (filelist->asset_library) {
 +return true;
 +  }
return BLO_library_path_explode(filelist->filelist.root, dir, r_group, 
nullptr);
  }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [01f9ac24edf] blender-projects-basics: Adapt to changes in master, fixes all compile errors

2023-01-06 Thread Julian Eisel
Commit: 01f9ac24edfbc6e016e08eaa7206e4836289e4e4
Author: Julian Eisel
Date:   Fri Jan 6 17:20:03 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rB01f9ac24edfbc6e016e08eaa7206e4836289e4e4

Adapt to changes in master, fixes all compile errors

===

M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/blenkernel/intern/context.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/asset/intern/asset_ops.cc
M   source/blender/editors/project/project_ops.cc
M   source/blender/editors/space_project_settings/space_project_settings.cc

===

diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 9a6b73ef501..096c74947d1 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -12,8 +12,8 @@
 #include "AS_asset_library.hh"
 #include "AS_asset_representation.hh"
 
+#include "BKE_asset_library_custom.h"
 #include "BKE_main.h"
-#include "BKE_preferences.h"
 
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
@@ -68,8 +68,8 @@ bool AS_asset_library_has_any_unsaved_catalogs()
 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(
-  , input_path.c_str())) {
+  if (CustomAssetLibraryDefinition *preferences_lib = 
BKE_asset_library_custom_containing_path(
+  _libraries, input_path.c_str())) {
 return preferences_lib->path;
   }
 
@@ -243,15 +243,17 @@ Vector 
all_valid_asset_library_refs()
 {
   Vector result;
   int i;
-  LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, 
_libraries, i) {
+  LISTBASE_FOREACH_INDEX (
+  const CustomAssetLibraryDefinition *, asset_library, _libraries, 
i) {
 if (!BLI_is_dir(asset_library->path)) {
   continue;
 }
 AssetLibraryReference library_ref{};
 library_ref.custom_library_index = i;
-library_ref.type = ASSET_LIBRARY_CUSTOM;
+library_ref.type = ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES;
 result.append(library_ref);
   }
+  /* TODO project libraries */
 
   AssetLibraryReference library_ref{};
   library_ref.custom_library_index = -1;
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 79097ac8cd2..41d44867d7e 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -4,8 +4,8 @@
  * \ingroup asset_system
  */
 
+#include "BKE_asset_library_custom.h"
 #include "BKE_blender.h"
-#include "BKE_preferences.h"
 
 #include "BLI_string_ref.hh"
 
@@ -67,14 +67,15 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 
 return get_asset_library_on_disk(root_path);
   }
-  if (library_reference.type == ASSET_LIBRARY_CUSTOM) {
-bUserAssetLibrary *user_library = 
BKE_preferences_asset_library_find_from_index(
-, library_reference.custom_library_index);
+  if (library_reference.type == ASSET_LIBRARY_CUSTOM_FROM_PREFERENCES) {
+CustomAssetLibraryDefinition *user_library = 
BKE_asset_library_custom_find_from_index(
+_libraries, library_reference.custom_library_index);
 
 if (user_library) {
   return get_asset_library_on_disk(user_library->path);
 }
   }
+  /* TODO project libraries */
 
   return nullptr;
 }
diff --git a/source/blender/blenkernel/intern/context.cc 
b/source/blender/blenkernel/intern/context.cc
index 4105aa40358..c7b27e3c93d 100644
--- a/source/blender/blenkernel/intern/context.cc
+++ b/source/blender/blenkernel/intern/context.cc
@@ -939,9 +939,9 @@ SpaceProjectSettings *CTX_wm_space_project_settings(const 
bContext *C)
 {
   ScrArea *area = CTX_wm_area(C);
   if (area && area->spacetype == SPACE_PROJECT_SETTINGS) {
-return area->spacedata.first;
+return static_cast(area->spacedata.first);
   }
-  return NULL;
+  return nullptr;
 }
 
 void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index 86c9539f317..8bb078ded74 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -12,11 +12,11 @@
 #include 
 #include 
 
-#include "BKE_asset_library_custom.h"
 #include "BKE_blender_project.h"
 #include "BKE_context.h"
 
 #include "BLI_map.hh"
+#include "BL

[Bf-blender-cvs] [58d32e81852] blender-projects-basics: Merge branch 'master' into blender-projects-basics

2023-01-06 Thread Julian Eisel
Commit: 58d32e81852bca52fe7804d359a625bda54c22e0
Author: Julian Eisel
Date:   Fri Jan 6 15:26:21 2023 +0100
Branches: blender-projects-basics
https://developer.blender.org/rB58d32e81852bca52fe7804d359a625bda54c22e0

Merge branch 'master' into blender-projects-basics

===



===

diff --cc release/scripts/startup/bl_ui/space_userpref.py
index 7223c750f32,e58302fde06..dde39529df4
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@@ -2288,8 -2339,6 +2310,7 @@@ class USERPREF_PT_experimental_prototyp
  ({"property": "use_sculpt_texture_paint"}, "T96225"),
  ({"property": "use_full_frame_compositor"}, "T88150"),
  ({"property": "enable_eevee_next"}, "T93220"),
- ({"property": "use_draw_manager_acquire_lock"}, "T98016"),
 +({"property": "use_blender_projects"}, None),
  ),
  )
  
diff --cc source/blender/asset_system/tests/asset_catalog_test.cc
index 000,3e117e3da97..8e4b47bc40a
mode 00,100644..100644
--- a/source/blender/asset_system/tests/asset_catalog_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_test.cc
@@@ -1,0 -1,1277 +1,1277 @@@
+ /* SPDX-License-Identifier: GPL-2.0-or-later
+  * Copyright 2020 Blender Foundation. All rights reserved. */
+ 
+ #include "AS_asset_catalog.hh"
+ #include "AS_asset_catalog_tree.hh"
+ 
 -#include "BKE_preferences.h"
++#include "BKE_asset_library_custom.h"
+ 
+ #include "BLI_fileops.h"
+ #include "BLI_path_util.h"
+ 
+ #include "DNA_asset_types.h"
+ #include "DNA_userdef_types.h"
+ 
+ #include "testing/testing.h"
+ 
+ #include "asset_library_test_common.hh"
+ 
+ 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");
+ const bUUID UUID_POSES_ELLIE("df60e1f6-2259-475b-93d9-69a1b4a8db78");
+ const bUUID 
UUID_POSES_ELLIE_WHITESPACE("b06132f6-5687-4751-a6dd-392740eb3c46");
+ const bUUID 
UUID_POSES_ELLIE_TRAILING_SLASH("3376b94b-a28d-4d05-86c1-bf30b937130d");
+ const bUUID 
UUID_POSES_ELLIE_BACKSLASHES("a51e17ae-34fc-47d5-ba0f-64c2c9b771f7");
+ const bUUID UUID_POSES_RUZENA("79a4f887-ab60-4bd4-94da-d572e27d6aed");
+ const bUUID UUID_POSES_RUZENA_HAND("81811c31-1a88-4bd7-bb34-c6fc2607a12e");
+ const bUUID UUID_POSES_RUZENA_FACE("82162c1f-06cc-4d91-a9bf-4f72c104e348");
+ const bUUID UUID_WITHOUT_SIMPLENAME("d7916a31-6ca9-4909-955f-182ca2b81fa3");
+ const bUUID UUID_ANOTHER_RUZENA("-d9fa-4b91-b704-e6af1f1339ef");
+ 
+ /* UUIDs from lib/tests/asset_library/modified_assets.cats.txt */
+ const bUUID UUID_AGENT_47("c5744ba5-43f5-4f73-8e52-010ad4a61b34");
+ 
+ /* Subclass that adds accessors such that protected fields can be used in 
tests. */
+ class TestableAssetCatalogService : public AssetCatalogService {
+  public:
+   TestableAssetCatalogService() = default;
+ 
+   explicit TestableAssetCatalogService(const CatalogFilePath 
_library_root)
+   : AssetCatalogService(asset_library_root)
+   {
+   }
+ 
+   AssetCatalogDefinitionFile *get_catalog_definition_file()
+   {
+ return AssetCatalogService::get_catalog_definition_file();
+   }
+ 
+   OwningAssetCatalogMap _deleted_catalogs()
+   {
+ return AssetCatalogService::get_deleted_catalogs();
+   }
+ 
+   void create_missing_catalogs()
+   {
+ AssetCatalogService::create_missing_catalogs();
+   }
+ 
+   void delete_catalog_by_id_soft(CatalogID catalog_id)
+   {
+ AssetCatalogService::delete_catalog_by_id_soft(catalog_id);
+   }
+ 
+   int64_t count_catalogs_with_path(const CatalogFilePath )
+   {
+ int64_t count = 0;
+ for (auto _uptr : get_catalogs().values()) {
+   if (catalog_uptr->path == path) {
+ count++;
+   }
+ }
+ return count;
+   }
+ };
+ 
+ class AssetCatalogTest : public AssetLibraryTestBase {
+  protected:
+   /* Used by on_blendfile_save__from_memory_into_existing_asset_lib* test 
functions. */
+   void save_from_memory_into_existing_asset_lib(const bool 
should_top_level_cdf_exist)
+   {
+ const CatalogFilePath target_dir = create_temp_path(); /* Has trailing 
slash. */
+ const CatalogFilePath original_cdf_file = asset_library_root_ + SEP_STR +
+   "blender_assets.cats.txt";
+ const CatalogFilePath registered_asset_lib = target_dir + 
"my_asset_library" + SEP_STR;
+ const CatalogFilePath asset

[Bf-blender-cvs] [1229b966524] master: Fix empty asset index files after bug in asset loading

2023-01-06 Thread Julian Eisel
Commit: 1229b966524b7d7cb12d2bcb978391f0df5c7bb6
Author: Julian Eisel
Date:   Fri Jan 6 11:55:24 2023 +0100
Branches: master
https://developer.blender.org/rB1229b966524b7d7cb12d2bcb978391f0df5c7bb6

Fix empty asset index files after bug in asset loading

Initial error caused by 1efc94bb2f7b and fixed in 6a7917162c56. However
the empty index files (empty as in, they contain the version number but
no assets) will have to be fixed somehow, since otherwise assets don't
show up at all for people who saved asset files in a broken version.

Delete empty index files if the modification timestamp indicates a time
when the bug was present (plus a day before and after, to address
possible time zone differences). This will basically make Blender skip
the optimization for .blend files without assets for one load, but even
then the index should still produce faster results than a completely
non-index read.

This can be removed after a while, it's just a (much needed) fix for
people who were using alpha/beta builds.

Differential Revision: https://developer.blender.org/D16678

Reviewed by: Jeroen Bakker

===

M   source/blender/editors/asset/intern/asset_indexer.cc

===

diff --git a/source/blender/editors/asset/intern/asset_indexer.cc 
b/source/blender/editors/asset/intern/asset_indexer.cc
index 7db23161926..e1350b3119e 100644
--- a/source/blender/editors/asset/intern/asset_indexer.cc
+++ b/source/blender/editors/asset/intern/asset_indexer.cc
@@ -4,6 +4,7 @@
  * \ingroup edasset
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -413,17 +414,24 @@ static int 
init_indexer_entries_from_value(FileIndexerEntries _entries,
 /**
  * \brief References the asset library directory.
  *
- * The #AssetLibraryIndex instance is used to keep track of unused file 
indices. When reading any
- * used indices are removed from the list and when reading is finished the 
unused
- * indices are removed.
+ * The #AssetLibraryIndex instance collects file indices that are existing 
before the actual
+ * reading/updating starts. This way, the reading/updating can tag 
pre-existing files as used when
+ * they are still needed. Remaining ones (indices that are not tagged as used) 
can be removed once
+ * reading finishes.
  */
 struct AssetLibraryIndex {
+  struct PreexistingFileIndexInfo {
+bool is_used = false;
+  };
+
   /**
-   * Tracks indices that haven't been used yet.
+   * File indices that are existing already before reading/updating performs 
changes. The key is
+   * the absolute path. The value can store information like if the index is 
known to be used.
*
-   * Contains absolute paths to the indices.
+   * Note that when deleting a file index (#delete_index_file()), it's also 
removed from here,
+   * since it doesn't exist and isn't relevant to keep track of anymore.
*/
-  Set unused_file_indices;
+  Map preexisting_file_indices;
 
   /**
* \brief Absolute path where the indices of `library` are stored.
@@ -485,9 +493,10 @@ struct AssetLibraryIndex {
   }
 
   /**
-   * Initialize to keep track of unused file indices.
+   * Check for pre-existing index files to be able to track what is still used 
and what can be
+   * removed. See #AssetLibraryIndex::preexisting_file_indices.
*/
-  void init_unused_index_files()
+  void collect_preexisting_file_indices()
   {
 const char *index_path = indices_base_path.c_str();
 if (!BLI_is_dir(index_path)) {
@@ -498,7 +507,7 @@ struct AssetLibraryIndex {
 for (int i = 0; i < dir_entries_num; i++) {
   struct direntry *entry = _entries[i];
   if (BLI_str_endswith(entry->relname, ".index.json")) {
-unused_file_indices.add_as(std::string(entry->path));
+preexisting_file_indices.add_as(std::string(entry->path));
   }
 }
 
@@ -507,17 +516,53 @@ struct AssetLibraryIndex {
 
   void mark_as_used(const std::string )
   {
-unused_file_indices.remove(filename);
+PreexistingFileIndexInfo *preexisting = 
preexisting_file_indices.lookup_ptr(filename);
+if (preexisting) {
+  preexisting->is_used = true;
+}
   }
 
-  int remove_unused_index_files() const
+  /**
+   * Removes the file index from disk and #preexisting_file_indices 
(invalidating its iterators, so
+   * don't call while iterating).
+   * \return true if deletion was successful.
+   */
+  bool delete_file_index(const std::string )
+  {
+if (BLI_delete(filename.c_str(), false, false) == 0) {
+  preexisting_file_indices.remove(filename);
+  return true;
+}
+return false;
+  }
+
+  /**
+   * A bug was creating empty index files for a while (see D16665). Remove 
empty index files from
+   * this period, so they are regenerated.
+   */
+  /* Implemented further below. */
+  int remove_broken_index_files();
+
+  int remove_unused_index_files()
   {
 int num_files_deleted = 0;
-for 

[Bf-blender-cvs] [bf65f94f45b] blender-v2.93-release: Fix T89515: Clicking on Favorites in File Browser will rename them

2022-12-20 Thread Julian Eisel
Commit: bf65f94f45b720568cbb8a179493216cf0b4b192
Author: Julian Eisel
Date:   Mon Jun 28 19:41:28 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBbf65f94f45b720568cbb8a179493216cf0b4b192

Fix T89515: Clicking on Favorites in File Browser will rename them

Likely uncovered by 6c97c7f767c9, the actual mistake would be from
6942dd9f4900.

The hacks to display text buttons for renaming in UI-Lists used the emboss of
the text button for handling logic. It relied on the emboss `NONE` but we also
introduced `NONE_OR_STATUS` with 6942dd9f4900. Both values need to be treated
equally for the logic of this hack to work.

The change in `interface_layout.c` is actually not needed for this exact issue,
but it's the correct thing to do. There may actually be more cases where `NONE`
and `NONE_OR_STATUS` need to be treated equally. Something to be checked still.

===

M   source/blender/editors/interface/interface_handlers.c
M   source/blender/editors/interface/interface_layout.c
M   source/blender/editors/interface/interface_query.c

===

diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 3f0a7074dfc..7d85a570ca6 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4510,7 +4510,7 @@ static int ui_do_but_TEX(
   if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && 
(!UI_but_is_utf8(but))) {
 /* pass - allow filesel, enter to execute */
   }
-  else if (but->emboss == UI_EMBOSS_NONE && !event->ctrl) {
+  else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && 
!event->ctrl) {
 /* pass */
   }
   else {
diff --git a/source/blender/editors/interface/interface_layout.c 
b/source/blender/editors/interface/interface_layout.c
index 2c2ea70d0d2..a62c9b598e1 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2355,7 +2355,7 @@ void uiItemFullR(uiLayout *layout,
 
   /* Mark non-embossed textfields inside a listbox. */
   if (but && (block->flag & UI_BLOCK_LIST_ITEM) && (but->type == 
UI_BTYPE_TEXT) &&
-  (but->emboss & UI_EMBOSS_NONE)) {
+  ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS)) {
 UI_but_flag_enable(but, UI_BUT_LIST_ITEM);
   }
 
diff --git a/source/blender/editors/interface/interface_query.c 
b/source/blender/editors/interface/interface_query.c
index aa10d092f5e..4c6efb0ded2 100644
--- a/source/blender/editors/interface/interface_query.c
+++ b/source/blender/editors/interface/interface_query.c
@@ -90,7 +90,8 @@ bool ui_but_is_interactive(const uiBut *but, const bool 
labeledit)
   if (but->flag & UI_SCROLLED) {
 return false;
   }
-  if ((but->type == UI_BTYPE_TEXT) && (but->emboss == UI_EMBOSS_NONE) && 
!labeledit) {
+  if ((but->type == UI_BTYPE_TEXT) &&
+  (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS)) && 
!labeledit) {
 return false;
   }
   if ((but->type == UI_BTYPE_LISTROW) && labeledit) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a0ed3601c9f] geometry-nodes-simulation: Fix T103187: Opening node search menu is slow because of assets.

2022-12-19 Thread Julian Eisel
Commit: a0ed3601c9f299027d7f194894e6d81f1c584af9
Author: Julian Eisel
Date:   Fri Dec 16 17:01:03 2022 +0100
Branches: geometry-nodes-simulation
https://developer.blender.org/rBa0ed3601c9f299027d7f194894e6d81f1c584af9

Fix T103187: Opening node search menu is slow because of assets.

Avoid utility function call that would query the file system, this was a
bottleneck. The path joining was also problematic. See patch for more
details.

Differential Revision: https://developer.blender.org/D16768

Reviewed by: Jacques Lucke

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index bf0f9c865a8..c40ba5d016b 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -323,7 +323,6 @@ static void filelist_readjob_main_assets(FileListReadJob 
*job_params,
 
 /* helper, could probably go in BKE actually? */
 static int groupname_to_code(const char *group);
-static uint64_t groupname_to_filter_id(const char *group);
 
 static void filelist_cache_clear(FileListEntryCache *cache, size_t new_size);
 static bool filelist_intern_entry_is_main_file(const FileListInternEntry 
*intern_entry);
@@ -751,7 +750,7 @@ static bool is_filtered_file(FileListInternEntry *file,
 }
 
 static bool is_filtered_id_file_type(const FileListInternEntry *file,
- const char *id_group,
+ const short id_code,
  const char *name,
  const FileListFilter *filter)
 {
@@ -761,12 +760,12 @@ static bool is_filtered_id_file_type(const 
FileListInternEntry *file,
 
   /* We only check for types if some type are enabled in filtering. */
   if ((filter->filter || filter->filter_id) && (filter->flags & 
FLF_DO_FILTER)) {
-if (id_group) {
+if (id_code) {
   if (!name && (filter->flags & FLF_HIDE_LIB_DIR)) {
 return false;
   }
 
-  uint64_t filter_id = groupname_to_filter_id(id_group);
+  const uint64_t filter_id = BKE_idtype_idcode_to_idfilter(id_code);
   if (!(filter_id & filter->filter_id)) {
 return false;
   }
@@ -851,15 +850,11 @@ static bool is_filtered_asset(FileListInternEntry *file, 
FileListFilter *filter)
 }
 
 static bool is_filtered_lib_type(FileListInternEntry *file,
- const char *root,
+ const char * /*root*/,
  FileListFilter *filter)
 {
-  char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name;
-
-  BLI_path_join(path, sizeof(path), root, file->relpath);
-
-  if (BLO_library_path_explode(path, dir, , )) {
-return is_filtered_id_file_type(file, group, name, filter);
+  if (file->typeflag & FILE_TYPE_BLENDERLIB) {
+return is_filtered_id_file_type(file, file->blentype, file->name, filter);
   }
   return is_filtered_file_type(file, filter);
 }
@@ -881,7 +876,7 @@ static bool is_filtered_main_assets(FileListInternEntry 
*file,
 FileListFilter *filter)
 {
   /* "Filtered" means *not* being filtered out... So return true if the file 
should be visible. */
-  return is_filtered_id_file_type(file, file->relpath, file->name, filter) &&
+  return is_filtered_id_file_type(file, file->blentype, file->name, filter) &&
  is_filtered_asset(file, filter);
 }
 
@@ -2882,13 +2877,6 @@ static int groupname_to_code(const char *group)
   return buf[0] ? BKE_idtype_idcode_from_name(buf) : 0;
 }
 
-static uint64_t groupname_to_filter_id(const char *group)
-{
-  int id_code = groupname_to_code(group);
-
-  return BKE_idtype_idcode_to_idfilter(id_code);
-}
-
 /**
  * From here, we are in 'Job Context',
  * i.e. have to be careful about sharing stuff between background working 
thread.

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e01b98cdb60] blender-v3.4-release: Fix T103187: Opening node search menu is slow because of assets.

2022-12-19 Thread Julian Eisel
Commit: e01b98cdb603cff044173276d937ea5507289b8c
Author: Julian Eisel
Date:   Fri Dec 16 17:01:03 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rBe01b98cdb603cff044173276d937ea5507289b8c

Fix T103187: Opening node search menu is slow because of assets.

Avoid utility function call that would query the file system, this was a
bottleneck. The path joining was also problematic. See patch for more
details.

Differential Revision: https://developer.blender.org/D16768

Reviewed by: Jacques Lucke

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 3870178f119..b3deeccfe63 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -317,7 +317,6 @@ static void filelist_readjob_main_assets(FileListReadJob 
*job_params,
 
 /* helper, could probably go in BKE actually? */
 static int groupname_to_code(const char *group);
-static uint64_t groupname_to_filter_id(const char *group);
 
 static void filelist_cache_clear(FileListEntryCache *cache, size_t new_size);
 static bool filelist_intern_entry_is_main_file(const FileListInternEntry 
*intern_entry);
@@ -745,7 +744,7 @@ static bool is_filtered_file(FileListInternEntry *file,
 }
 
 static bool is_filtered_id_file_type(const FileListInternEntry *file,
- const char *id_group,
+ const short id_code,
  const char *name,
  const FileListFilter *filter)
 {
@@ -755,12 +754,12 @@ static bool is_filtered_id_file_type(const 
FileListInternEntry *file,
 
   /* We only check for types if some type are enabled in filtering. */
   if ((filter->filter || filter->filter_id) && (filter->flags & 
FLF_DO_FILTER)) {
-if (id_group) {
+if (id_code) {
   if (!name && (filter->flags & FLF_HIDE_LIB_DIR)) {
 return false;
   }
 
-  uint64_t filter_id = groupname_to_filter_id(id_group);
+  const uint64_t filter_id = BKE_idtype_idcode_to_idfilter(id_code);
   if (!(filter_id & filter->filter_id)) {
 return false;
   }
@@ -843,15 +842,11 @@ static bool is_filtered_asset(FileListInternEntry *file, 
FileListFilter *filter)
 }
 
 static bool is_filtered_lib_type(FileListInternEntry *file,
- const char *root,
+ const char * /*root*/,
  FileListFilter *filter)
 {
-  char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name;
-
-  BLI_path_join(path, sizeof(path), root, file->relpath);
-
-  if (BLO_library_path_explode(path, dir, , )) {
-return is_filtered_id_file_type(file, group, name, filter);
+  if (file->typeflag & FILE_TYPE_BLENDERLIB) {
+return is_filtered_id_file_type(file, file->blentype, file->name, filter);
   }
   return is_filtered_file_type(file, filter);
 }
@@ -873,7 +868,7 @@ static bool is_filtered_main_assets(FileListInternEntry 
*file,
 FileListFilter *filter)
 {
   /* "Filtered" means *not* being filtered out... So return true if the file 
should be visible. */
-  return is_filtered_id_file_type(file, file->relpath, file->name, filter) &&
+  return is_filtered_id_file_type(file, file->blentype, file->name, filter) &&
  is_filtered_asset(file, filter);
 }
 
@@ -2859,13 +2854,6 @@ static int groupname_to_code(const char *group)
   return buf[0] ? BKE_idtype_idcode_from_name(buf) : 0;
 }
 
-static uint64_t groupname_to_filter_id(const char *group)
-{
-  int id_code = groupname_to_code(group);
-
-  return BKE_idtype_idcode_to_idfilter(id_code);
-}
-
 /**
  * From here, we are in 'Job Context',
  * i.e. have to be careful about sharing stuff between background working 
thread.

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea731f42db3] master: Fix T103187: Opening node search menu is slow because of assets.

2022-12-16 Thread Julian Eisel
Commit: ea731f42db32bf8bf3bf0f799fb4a6d298922b52
Author: Julian Eisel
Date:   Fri Dec 16 17:01:03 2022 +0100
Branches: master
https://developer.blender.org/rBea731f42db32bf8bf3bf0f799fb4a6d298922b52

Fix T103187: Opening node search menu is slow because of assets.

Avoid utility function call that would query the file system, this was a
bottleneck. The path joining was also problematic. See patch for more
details.

Differential Revision: https://developer.blender.org/D16768

Reviewed by: Jacques Lucke

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index bf0f9c865a8..c40ba5d016b 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -323,7 +323,6 @@ static void filelist_readjob_main_assets(FileListReadJob 
*job_params,
 
 /* helper, could probably go in BKE actually? */
 static int groupname_to_code(const char *group);
-static uint64_t groupname_to_filter_id(const char *group);
 
 static void filelist_cache_clear(FileListEntryCache *cache, size_t new_size);
 static bool filelist_intern_entry_is_main_file(const FileListInternEntry 
*intern_entry);
@@ -751,7 +750,7 @@ static bool is_filtered_file(FileListInternEntry *file,
 }
 
 static bool is_filtered_id_file_type(const FileListInternEntry *file,
- const char *id_group,
+ const short id_code,
  const char *name,
  const FileListFilter *filter)
 {
@@ -761,12 +760,12 @@ static bool is_filtered_id_file_type(const 
FileListInternEntry *file,
 
   /* We only check for types if some type are enabled in filtering. */
   if ((filter->filter || filter->filter_id) && (filter->flags & 
FLF_DO_FILTER)) {
-if (id_group) {
+if (id_code) {
   if (!name && (filter->flags & FLF_HIDE_LIB_DIR)) {
 return false;
   }
 
-  uint64_t filter_id = groupname_to_filter_id(id_group);
+  const uint64_t filter_id = BKE_idtype_idcode_to_idfilter(id_code);
   if (!(filter_id & filter->filter_id)) {
 return false;
   }
@@ -851,15 +850,11 @@ static bool is_filtered_asset(FileListInternEntry *file, 
FileListFilter *filter)
 }
 
 static bool is_filtered_lib_type(FileListInternEntry *file,
- const char *root,
+ const char * /*root*/,
  FileListFilter *filter)
 {
-  char path[FILE_MAX_LIBEXTRA], dir[FILE_MAX_LIBEXTRA], *group, *name;
-
-  BLI_path_join(path, sizeof(path), root, file->relpath);
-
-  if (BLO_library_path_explode(path, dir, , )) {
-return is_filtered_id_file_type(file, group, name, filter);
+  if (file->typeflag & FILE_TYPE_BLENDERLIB) {
+return is_filtered_id_file_type(file, file->blentype, file->name, filter);
   }
   return is_filtered_file_type(file, filter);
 }
@@ -881,7 +876,7 @@ static bool is_filtered_main_assets(FileListInternEntry 
*file,
 FileListFilter *filter)
 {
   /* "Filtered" means *not* being filtered out... So return true if the file 
should be visible. */
-  return is_filtered_id_file_type(file, file->relpath, file->name, filter) &&
+  return is_filtered_id_file_type(file, file->blentype, file->name, filter) &&
  is_filtered_asset(file, filter);
 }
 
@@ -2882,13 +2877,6 @@ static int groupname_to_code(const char *group)
   return buf[0] ? BKE_idtype_idcode_from_name(buf) : 0;
 }
 
-static uint64_t groupname_to_filter_id(const char *group)
-{
-  int id_code = groupname_to_code(group);
-
-  return BKE_idtype_idcode_to_idfilter(id_code);
-}
-
 /**
  * From here, we are in 'Job Context',
  * i.e. have to be careful about sharing stuff between background working 
thread.

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [45dbd69296f] master: Fix compiler error on MSVC after a243a9dc79eb

2022-12-14 Thread Julian Eisel
Commit: 45dbd69296f0677481daff0c915dbc02db743e07
Author: Julian Eisel
Date:   Wed Dec 14 16:08:26 2022 +0100
Branches: master
https://developer.blender.org/rB45dbd69296f0677481daff0c915dbc02db743e07

Fix compiler error on MSVC after a243a9dc79eb

===

M   source/blender/editors/asset/intern/asset_ops.cc

===

diff --git a/source/blender/editors/asset/intern/asset_ops.cc 
b/source/blender/editors/asset/intern/asset_ops.cc
index 497b655c7ce..3bbfa2ac0f4 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -14,6 +14,7 @@
 #include "BKE_preferences.h"
 #include "BKE_report.h"
 
+#include "BLI_fileops.h" /* MSVC needs this for `PATH_MAX` */
 #include "BLI_fnmatch.h"
 #include "BLI_path_util.h"
 #include "BLI_set.hh"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a243a9dc79e] master: Cleanup: Remove unused headers in asset files

2022-12-14 Thread Julian Eisel
Commit: a243a9dc79ebe6cf4ee473be69a0d28b5b05375c
Author: Julian Eisel
Date:   Tue Dec 13 17:24:24 2022 +0100
Branches: master
https://developer.blender.org/rBa243a9dc79ebe6cf4ee473be69a0d28b5b05375c

Cleanup: Remove unused headers in asset files

===

M   source/blender/asset_system/intern/asset_catalog.cc
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_representation.cc
M   source/blender/asset_system/tests/asset_catalog_test.cc
M   source/blender/asset_system/tests/asset_catalog_tree_test.cc
M   source/blender/asset_system/tests/asset_library_test.cc
M   source/blender/editors/asset/intern/asset_handle.cc
M   source/blender/editors/asset/intern/asset_indexer.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/asset/intern/asset_ops.cc

===

diff --git a/source/blender/asset_system/intern/asset_catalog.cc 
b/source/blender/asset_system/intern/asset_catalog.cc
index 9b47aca1209..c295f2de16e 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -9,7 +9,6 @@
 
 #include "AS_asset_catalog.hh"
 #include "AS_asset_catalog_tree.hh"
-#include "AS_asset_library.h"
 #include "AS_asset_library.hh"
 
 #include "BLI_fileops.hh"
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 73f81a50e46..9a6b73ef501 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -17,7 +17,6 @@
 
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
-#include "BLI_set.hh"
 
 #include "DNA_userdef_types.h"
 
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 37136968946..79097ac8cd2 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -7,8 +7,6 @@
 #include "BKE_blender.h"
 #include "BKE_preferences.h"
 
-#include "BLI_fileops.h" /* For PATH_MAX (at least on Windows). */
-#include "BLI_path_util.h"
 #include "BLI_string_ref.hh"
 
 #include "DNA_asset_types.h"
diff --git a/source/blender/asset_system/intern/asset_representation.cc 
b/source/blender/asset_system/intern/asset_representation.cc
index c6bc5193570..573358b7df7 100644
--- a/source/blender/asset_system/intern/asset_representation.cc
+++ b/source/blender/asset_system/intern/asset_representation.cc
@@ -13,8 +13,6 @@
 #include "AS_asset_representation.h"
 #include "AS_asset_representation.hh"
 
-#include "BKE_asset.h"
-
 namespace blender::asset_system {
 
 AssetRepresentation::AssetRepresentation(AssetIdentifier &,
diff --git a/source/blender/asset_system/tests/asset_catalog_test.cc 
b/source/blender/asset_system/tests/asset_catalog_test.cc
index 87819f3683b..3e117e3da97 100644
--- a/source/blender/asset_system/tests/asset_catalog_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_test.cc
@@ -4,7 +4,6 @@
 #include "AS_asset_catalog.hh"
 #include "AS_asset_catalog_tree.hh"
 
-#include "BKE_appdir.h"
 #include "BKE_preferences.h"
 
 #include "BLI_fileops.h"
@@ -13,8 +12,6 @@
 #include "DNA_asset_types.h"
 #include "DNA_userdef_types.h"
 
-#include "CLG_log.h"
-
 #include "testing/testing.h"
 
 #include "asset_library_test_common.hh"
diff --git a/source/blender/asset_system/tests/asset_catalog_tree_test.cc 
b/source/blender/asset_system/tests/asset_catalog_tree_test.cc
index fb1cbde517d..3355423cb48 100644
--- a/source/blender/asset_system/tests/asset_catalog_tree_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_tree_test.cc
@@ -4,17 +4,8 @@
 #include "AS_asset_catalog.hh"
 #include "AS_asset_catalog_tree.hh"
 
-#include "BKE_appdir.h"
-#include "BKE_preferences.h"
-
-#include "BLI_fileops.h"
 #include "BLI_path_util.h"
 
-#include "DNA_asset_types.h"
-#include "DNA_userdef_types.h"
-
-#include "CLG_log.h"
-
 #include "testing/testing.h"
 
 #include "asset_library_test_common.hh"
diff --git a/source/blender/asset_system/tests/asset_library_test.cc 
b/source/blender/asset_system/tests/asset_library_test.cc
index 059f3d9a46c..1b8d2f8ff0c 100644
--- a/source/blender/asset_system/tests/asset_library_test.cc
+++ b/source/blender/asset_system/tests/asset_library_test.cc
@@ -5,7

[Bf-blender-cvs] [f4912e7f5b2] master: Fix asset loading indicator in node add menu disappearing too early

2022-12-14 Thread Julian Eisel
Commit: f4912e7f5b250b00e34888d79549f91562817654
Author: Julian Eisel
Date:   Tue Dec 13 17:25:40 2022 +0100
Branches: master
https://developer.blender.org/rBf4912e7f5b250b00e34888d79549f91562817654

Fix asset loading indicator in node add menu disappearing too early

The "Loading Asset Libraries" label in the menu would already disappear
before the asset libraries are done loading. It only queried if the
loading was started, not if it was finished. Especially notable when the
asset library was slow to load, e.g. because it is not yet in the asset
index.

===

M   source/blender/editors/asset/intern/asset_list.cc

===

diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index 5b3d256c70c..caceedbd4a5 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -111,6 +111,7 @@ class AssetList : NonCopyable {
   void clear(bContext *C);
 
   bool needsRefetch() const;
+  bool isLoaded() const;
   void iterate(AssetListIterFn fn) const;
   bool listen(const wmNotifier ) const;
   int size() const;
@@ -189,6 +190,11 @@ bool AssetList::needsRefetch() const
   return filelist_needs_force_reset(filelist_) || 
filelist_needs_reading(filelist_);
 }
 
+bool AssetList::isLoaded() const
+{
+  return filelist_is_ready(filelist_);
+}
+
 void AssetList::iterate(AssetListIterFn fn) const
 {
   FileList *files = filelist_;
@@ -422,7 +428,7 @@ bool ED_assetlist_is_loaded(const AssetLibraryReference 
*library_reference)
   if (list->needsRefetch()) {
 return false;
   }
-  return true;
+  return list->isLoaded();
 }
 
 void ED_assetlist_ensure_previews_job(const AssetLibraryReference 
*library_reference,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0e1877b7542] blender-v2.93-release: Fix T85870: ColorRamp Keyframes crash Blender

2022-12-14 Thread Julian Eisel
Commit: 0e1877b7542d9cbe5429577c4b0980a9c8c4590f
Author: Julian Eisel
Date:   Tue Nov 8 12:14:31 2022 +0100
Branches: blender-v2.93-release
https://developer.blender.org/rB0e1877b7542d9cbe5429577c4b0980a9c8c4590f

Fix T85870: ColorRamp Keyframes crash Blender

The color-band needs to do some special, rather awkward updating of the
UI state when certain values are changed. As @lichtwerk noted in the
report, this was done to the wrong buttons. Now lookup the proper
buttons, and don't assume that `uiItemR()` only adds a single button
(which often isn't the case).

===

M   source/blender/editors/interface/interface_templates.c

===

diff --git a/source/blender/editors/interface/interface_templates.c 
b/source/blender/editors/interface/interface_templates.c
index d455686fdaa..86629768b72 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -3362,13 +3362,9 @@ static void colorband_buttons_layout(uiLayout *layout,
 
   row = uiLayoutRow(split, false);
   uiItemR(row, , "position", 0, IFACE_("Pos"), ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_func_set(bt, colorband_update_cb, bt, coba);
 
   row = uiLayoutRow(layout, false);
   uiItemR(row, , "color", 0, "", ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
 }
 else {
   split = uiLayoutSplit(layout, 0.5f, false);
@@ -3393,13 +3389,28 @@ static void colorband_buttons_layout(uiLayout *layout,
 
   row = uiLayoutRow(subsplit, false);
   uiItemR(row, , "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), 
ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_func_set(bt, colorband_update_cb, bt, coba);
 
   row = uiLayoutRow(split, false);
   uiItemR(row, , "color", 0, "", ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
+}
+
+/* Some special (rather awkward) treatment to update UI state on certain 
property changes. */
+LISTBASE_FOREACH_BACKWARD (uiBut *, but, >buttons) {
+  if (but->rnapoin.data != ptr.data) {
+continue;
+  }
+  if (!but->rnaprop) {
+continue;
+  }
+
+  const char *prop_identifier = RNA_property_identifier(but->rnaprop);
+  if (STREQ(prop_identifier, "position")) {
+UI_but_func_set(but, colorband_update_cb, but, coba);
+  }
+
+  if (STREQ(prop_identifier, "color")) {
+UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), NULL);
+  }
 }
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [85d92afbd4d] master: Cleanup: Move asset catalog tree tests to own file

2022-12-12 Thread Julian Eisel
Commit: 85d92afbd4dd961327191ecc68579d25a8e653ea
Author: Julian Eisel
Date:   Mon Dec 12 17:07:55 2022 +0100
Branches: master
https://developer.blender.org/rB85d92afbd4dd961327191ecc68579d25a8e653ea

Cleanup: Move asset catalog tree tests to own file

The catalog tree is a unit on its own, and should be tested separately.
This makes the testing files smaller and more focused, which can help
maintaining them.

===

M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/tests/asset_catalog_test.cc
A   source/blender/asset_system/tests/asset_catalog_tree_test.cc
M   source/blender/asset_system/tests/asset_library_test_common.hh

===

diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index 6f4e058e78d..f8e1df40d80 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -48,6 +48,7 @@ if(WITH_GTESTS)
   set(TEST_SRC
 tests/asset_catalog_path_test.cc
 tests/asset_catalog_test.cc
+tests/asset_catalog_tree_test.cc
 tests/asset_library_service_test.cc
 tests/asset_library_test.cc
 
diff --git a/source/blender/asset_system/tests/asset_catalog_test.cc 
b/source/blender/asset_system/tests/asset_catalog_test.cc
index 144912d62a1..87819f3683b 100644
--- a/source/blender/asset_system/tests/asset_catalog_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_test.cc
@@ -80,77 +80,6 @@ class TestableAssetCatalogService : public 
AssetCatalogService {
 
 class AssetCatalogTest : public AssetLibraryTestBase {
  protected:
-  void assert_expected_item(const AssetCatalogPath _path,
-const AssetCatalogTreeItem _item)
-  {
-if (expected_path != actual_item.catalog_path().str()) {
-  /* This will fail, but with a nicer error message than just calling 
FAIL(). */
-  EXPECT_EQ(expected_path, actual_item.catalog_path());
-  return;
-}
-
-/* Is the catalog name as expected? "character", "Ellie", ... */
-EXPECT_EQ(expected_path.name(), actual_item.get_name());
-
-/* Does the computed number of parents match? */
-const std::string expected_path_str = expected_path.str();
-const size_t expected_parent_count = std::count(
-expected_path_str.begin(), expected_path_str.end(), 
AssetCatalogPath::SEPARATOR);
-EXPECT_EQ(expected_parent_count, actual_item.count_parents());
-  }
-
-  /**
-   * Recursively iterate over all tree items using 
#AssetCatalogTree::foreach_item() and check if
-   * the items map exactly to \a expected_paths.
-   */
-  void assert_expected_tree_items(AssetCatalogTree *tree,
-  const std::vector 
_paths)
-  {
-int i = 0;
-tree->foreach_item([&](const AssetCatalogTreeItem _item) {
-  ASSERT_LT(i, expected_paths.size())
-  << "More catalogs in tree than expected; did not expect " << 
actual_item.catalog_path();
-  assert_expected_item(expected_paths[i], actual_item);
-  i++;
-});
-  }
-
-  /**
-   * Iterate over the root items of \a tree and check if the items map exactly 
to \a
-   * expected_paths. Similar to #assert_expected_tree_items() but calls
-   * #AssetCatalogTree::foreach_root_item() instead of 
#AssetCatalogTree::foreach_item().
-   */
-  void assert_expected_tree_root_items(AssetCatalogTree *tree,
-   const std::vector 
_paths)
-  {
-int i = 0;
-tree->foreach_root_item([&](const AssetCatalogTreeItem _item) {
-  ASSERT_LT(i, expected_paths.size())
-  << "More catalogs in tree root than expected; did not expect "
-  << actual_item.catalog_path();
-  assert_expected_item(expected_paths[i], actual_item);
-  i++;
-});
-  }
-
-  /**
-   * Iterate over the child items of \a parent_item and check if the items map 
exactly to \a
-   * expected_paths. Similar to #assert_expected_tree_items() but calls
-   * #AssetCatalogTreeItem::foreach_child() instead of 
#AssetCatalogTree::foreach_item().
-   */
-  void assert_expected_tree_item_child_items(AssetCatalogTreeItem *parent_item,
- const 
std::vector _paths)
-  {
-int i = 0;
-parent_item->foreach_child([&](const AssetCatalogTreeItem _item) {
-  ASSERT_LT(i, expected_paths.size())
-  << "More catalogs in tree item than expected; did not expect "
-  << actual_item.catalog_path();
-  assert_expected_item(expected_paths[i], actual_item);
-  i++;
-});
-  }
-
   /* Used by on_blendfile_save__from_memory_into_existing_asset_lib* test 
functions. */
   void save_from_memory_into_existing_asset_lib(const bool 
should_top_level_cdf_exist)
   {
@@ -307,149 +236,6 @@ TEST_F(A

[Bf-blender-cvs] [dbd3822329f] master: Cleanup: Extract asset test class into own header

2022-12-12 Thread Julian Eisel
Commit: dbd3822329f16b24d46ac1336a792cb4f6b8a92e
Author: Julian Eisel
Date:   Mon Dec 12 16:06:23 2022 +0100
Branches: master
https://developer.blender.org/rBdbd3822329f16b24d46ac1336a792cb4f6b8a92e

Cleanup: Extract asset test class into own header

This manages setting up asset library directories for testing, which is
useful for testing multiple asset library related compontents. So move
it to a common header. No reason to squeeze everything into one file
then.

===

M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/tests/asset_catalog_test.cc
A   source/blender/asset_system/tests/asset_library_test_common.hh

===

diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index de1f41667d5..6f4e058e78d 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -46,10 +46,12 @@ 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_catalog_test.cc
 tests/asset_library_service_test.cc
 tests/asset_library_test.cc
+
+tests/asset_library_test_common.hh
   )
   set(TEST_LIB
 bf_asset_system
diff --git a/source/blender/asset_system/tests/asset_catalog_test.cc 
b/source/blender/asset_system/tests/asset_catalog_test.cc
index 0a051bfd51f..144912d62a1 100644
--- a/source/blender/asset_system/tests/asset_catalog_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_test.cc
@@ -17,6 +17,8 @@
 
 #include "testing/testing.h"
 
+#include "asset_library_test_common.hh"
+
 namespace blender::asset_system::tests {
 
 /* UUIDs from lib/tests/asset_library/blender_assets.cats.txt */
@@ -76,59 +78,8 @@ class TestableAssetCatalogService : public 
AssetCatalogService {
   }
 };
 
-class AssetCatalogTest : public testing::Test {
+class AssetCatalogTest : public AssetLibraryTestBase {
  protected:
-  CatalogFilePath asset_library_root_;
-  CatalogFilePath temp_library_path_;
-
-  static void SetUpTestSuite()
-  {
-testing::Test::SetUpTestSuite();
-CLG_init();
-  }
-
-  static void TearDownTestSuite()
-  {
-CLG_exit();
-testing::Test::TearDownTestSuite();
-  }
-
-  void SetUp() override
-  {
-const std::string test_files_dir = blender::tests::flags_test_asset_dir();
-if (test_files_dir.empty()) {
-  FAIL();
-}
-
-asset_library_root_ = test_files_dir + SEP_STR + "asset_library";
-temp_library_path_ = "";
-  }
-
-  void TearDown() override
-  {
-if (!temp_library_path_.empty()) {
-  BLI_delete(temp_library_path_.c_str(), true, true);
-  temp_library_path_ = "";
-}
-  }
-
-  /* Register a temporary path, which will be removed at the end of the test.
-   * The returned path ends in a slash. */
-  CatalogFilePath use_temp_path()
-  {
-BKE_tempdir_init("");
-const CatalogFilePath tempdir = BKE_tempdir_session();
-temp_library_path_ = tempdir + "test-temporary-path" + SEP_STR;
-return temp_library_path_;
-  }
-
-  CatalogFilePath create_temp_path()
-  {
-CatalogFilePath path = use_temp_path();
-BLI_dir_create_recursive(path.c_str());
-return path;
-  }
-
   void assert_expected_item(const AssetCatalogPath _path,
 const AssetCatalogTreeItem _item)
   {
diff --git a/source/blender/asset_system/tests/asset_library_test_common.hh 
b/source/blender/asset_system/tests/asset_library_test_common.hh
new file mode 100644
index 000..d8a8966487f
--- /dev/null
+++ b/source/blender/asset_system/tests/asset_library_test_common.hh
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#pragma once
+
+#include 
+
+#include "BKE_appdir.h"
+
+#include "BLI_fileops.h"
+#include "BLI_path_util.h"
+
+#include "CLG_log.h"
+
+#include "testing/testing.h"
+
+namespace blender::asset_system::tests {
+
+/**
+ * Functionality to setup and access directories on disk within which asset 
library related testing
+ * can be done.
+ */
+class AssetLibraryTestBase : public testing::Test {
+ protected:
+  std::string asset_library_root_;
+  std::string temp_library_path_;
+
+  static void SetUpTestSuite()
+  {
+testing::Test::SetUpTestSuite();
+CLG_init();
+  }
+
+  static void TearDownTestSuite()
+  {
+CLG_exit();
+testing::Test::TearDownTestSuite();
+  }
+
+  void SetUp() override
+  {
+const std::string test_files_dir = blender::tests::flags_test_asset_dir();
+if (test_files_dir.empty()) {
+  FAIL();
+}
+
+asset_library_root_ = test_files_dir + SEP_STR + "asset_library";
+temp_library_path_ 

[Bf-blender-cvs] [a683d5f9349] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-12-12 Thread Julian Eisel
Commit: a683d5f934951b8862e98546bd70b40526f04217
Author: Julian Eisel
Date:   Mon Dec 12 15:35:48 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBa683d5f934951b8862e98546bd70b40526f04217

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3cd93ace247] temp-asset-library-all: Simple progress reporting for all library

2022-12-07 Thread Julian Eisel
Commit: 3cd93ace247fefff8dec69879bb61ed074d55495
Author: Julian Eisel
Date:   Wed Dec 7 18:29:38 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB3cd93ace247fefff8dec69879bb61ed074d55495

Simple progress reporting for all library

Progress bar display the file reading (and other operations) is actually
broken in master for a while, so this won't actually be reported. Still
calculate it for once it's fixed.

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 234c550d829..44f846f8595 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3900,10 +3900,14 @@ static void 
filelist_readjob_all_asset_library(FileListReadJob *job_params,
   if (job_params->only_main_data) {
 return;
   }
-  /* TODO propertly update progress? */
+
+  /* Count how many asset libraries need to be loaded, for progress reporting. 
Not very precise. */
+  int library_count = 0;
+  asset_system::AssetLibrary::foreach_loaded([_count](auto &) { 
library_count++; }, false);
 
   BLI_assert(filelist->asset_library != nullptr);
 
+  int libraries_done_count = 0;
   /* The "All" asset library was loaded, which means all other asset libraries 
are also loaded.
* Load their assets from disk into the "All" library. */
   asset_system::AssetLibrary::foreach_loaded(
@@ -3917,7 +3921,12 @@ static void 
filelist_readjob_all_asset_library(FileListReadJob *job_params,
 job_params->load_asset_library = _library;
 BLI_strncpy(filelist->filelist.root, root_path.c_str(), 
sizeof(filelist->filelist.root));
 
-filelist_readjob_recursive_dir_add_items(true, job_params, stop, 
do_update, progress);
+float progress_this = 0.0f;
+filelist_readjob_recursive_dir_add_items(
+true, job_params, stop, do_update, _this);
+
+libraries_done_count++;
+*progress = float(libraries_done_count) / library_count;
   },
   false);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e8575bfd4a3] temp-asset-library-all: General cleanup (comments, remove outdated TODO marks, naming)

2022-12-07 Thread Julian Eisel
Commit: e8575bfd4a3a27e9ad636f682ff198907472bec5
Author: Julian Eisel
Date:   Wed Dec 7 18:19:15 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBe8575bfd4a3a27e9ad636f682ff198907472bec5

General cleanup (comments, remove outdated TODO marks, naming)

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_storage.hh
M   source/blender/editors/asset/ED_asset_catalog.h
M   source/blender/editors/asset/ED_asset_catalog.hh
M   source/blender/editors/asset/ED_asset_library.h
M   source/blender/editors/asset/intern/asset_library_reference_enum.cc
M   source/blender/editors/space_file/file_draw.c
M   source/blender/editors/space_file/filelist.cc
M   source/blender/makesdna/DNA_space_types.h

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 6526e3e8382..14d356c703e 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -109,7 +109,6 @@ class AssetLibrary {
   /** Remove an asset from the library that was added using 
#add_external_asset() or
* #add_local_id_asset(). Can usually be expected to be constant time 
complexity (worst case may
* differ).
-   *
* \note This is save to call if \a asset is freed (dangling reference), 
will not perform any
*   change then.
* \return True on success, false if the asset couldn't be found inside the 
library (also the
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 02c5c0dc4f3..f5377734b12 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -257,7 +257,6 @@ StringRefNull AssetLibrary::root_path() const
   return *root_path_;
 }
 
-/* TODO get rid of this. */
 Vector all_valid_asset_library_refs()
 {
   Vector result;
diff --git a/source/blender/asset_system/intern/asset_storage.hh 
b/source/blender/asset_system/intern/asset_storage.hh
index b4866fa9382..2b4614abca5 100644
--- a/source/blender/asset_system/intern/asset_storage.hh
+++ b/source/blender/asset_system/intern/asset_storage.hh
@@ -31,8 +31,6 @@ class AssetStorage {
* faster lookups. Not possible until each asset is only represented once in 
the storage. */
   StorageT local_id_assets_;
 
-  friend class AssetLibrary;
-
  public:
   /** See #AssetLibrary::add_external_asset(). */
   AssetRepresentation _external_asset(AssetIdentifier &,
diff --git a/source/blender/editors/asset/ED_asset_catalog.h 
b/source/blender/editors/asset/ED_asset_catalog.h
index 04df381bec9..9f6850b7266 100644
--- a/source/blender/editors/asset/ED_asset_catalog.h
+++ b/source/blender/editors/asset/ED_asset_catalog.h
@@ -19,6 +19,8 @@ struct Main;
 
 void ED_asset_catalogs_save_from_main_path(struct AssetLibrary *library, const 
struct Main *bmain);
 
+/** Saving catalog edits when the file is saved is a global option shared for 
each asset library,
+ * and as such ignores the per asset library #ED_asset_catalogs_read_only(). */
 void ED_asset_catalogs_set_save_catalogs_when_file_is_saved(bool should_save);
 bool ED_asset_catalogs_get_save_catalogs_when_file_is_saved(void);
 
diff --git a/source/blender/editors/asset/ED_asset_catalog.hh 
b/source/blender/editors/asset/ED_asset_catalog.hh
index d236bdec37f..a423ad6f8ad 100644
--- a/source/blender/editors/asset/ED_asset_catalog.hh
+++ b/source/blender/editors/asset/ED_asset_catalog.hh
@@ -22,6 +22,10 @@
 
 struct AssetLibrary;
 
+/**
+ * Returns if the catalogs of \a library are allowed to be editable, or if the 
UI should forbid
+ * edits.
+ */
 [[nodiscard]] bool ED_asset_catalogs_read_only(const AssetLibrary );
 
 blender::asset_system::AssetCatalog *ED_asset_catalog_add(
diff --git a/source/blender/editors/asset/ED_asset_library.h 
b/source/blender/editors/asset/ED_asset_library.h
index cc0d97054b6..c4baadc23c8 100644
--- a/source/blender/editors/asset/ED_asset_library.h
+++ b/source/blender/editors/asset/ED_asset_library.h
@@ -29,10 +29,13 @@ AssetLibraryReference 
ED_asset_library_reference_from_enum_value(int value);
  * 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 de

[Bf-blender-cvs] [747a9ea263a] temp-asset-library-all: Make catalogs from "All" library read-only

2022-12-06 Thread Julian Eisel
Commit: 747a9ea263ad97a78878705f020e3587f50734ff
Author: Julian Eisel
Date:   Tue Dec 6 17:02:05 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB747a9ea263ad97a78878705f020e3587f50734ff

Make catalogs from "All" library read-only

Loading the asset library will create a read-only catalog service. The
read-only nature is not dealt with much in the asset catalog code, the
using code (e.g. the UI) is responsible for respecting it.

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/intern/asset_catalog.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/asset/ED_asset_catalog.hh
M   source/blender/editors/asset/intern/asset_catalog.cc
M   source/blender/editors/asset/intern/asset_ops.cc
M   source/blender/editors/space_file/asset_catalog_tree_view.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index a7829778fdf..1d5401f0b0e 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -45,11 +45,17 @@ class AssetCatalogService {
   Vector> undo_snapshots_;
   Vector> redo_snapshots_;
 
+  const bool is_read_only_ = false;
+
  public:
   static const CatalogFilePath DEFAULT_CATALOG_FILENAME;
 
+  struct read_only_tag {
+  };
+
  public:
   AssetCatalogService();
+  explicit AssetCatalogService(read_only_tag);
   explicit AssetCatalogService(const CatalogFilePath _library_root);
 
   /**
@@ -62,6 +68,13 @@ class AssetCatalogService {
   void tag_has_unsaved_changes(AssetCatalog *edited_catalog);
   bool has_unsaved_changes() const;
 
+  /**
+   * Check if this is a read-only service meaning the user shouldn't be able 
to do edits. This is
+   * not enforced by internal catalog code, the catalog service user is 
responsible for it. For
+   * example the UI should disallow edits.
+   */
+  bool is_read_only() const;
+
   /** Load asset catalog definitions from the files found in the asset 
library. */
   void load_from_disk();
   /** Load asset catalog definitions from the given file or directory. */
diff --git a/source/blender/asset_system/intern/asset_catalog.cc 
b/source/blender/asset_system/intern/asset_catalog.cc
index 7924ceb862c..6256b6ee503 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -44,6 +44,11 @@ AssetCatalogService::AssetCatalogService()
 {
 }
 
+AssetCatalogService::AssetCatalogService(read_only_tag) : AssetCatalogService()
+{
+  const_cast(is_read_only_) = true;
+}
+
 AssetCatalogService::AssetCatalogService(const CatalogFilePath 
_library_root)
 : AssetCatalogService()
 {
@@ -52,6 +57,8 @@ AssetCatalogService::AssetCatalogService(const 
CatalogFilePath _library_ro
 
 void AssetCatalogService::tag_has_unsaved_changes(AssetCatalog *edited_catalog)
 {
+  BLI_assert(!is_read_only_);
+
   if (edited_catalog) {
 edited_catalog->flags.has_unsaved_changes = true;
   }
@@ -86,6 +93,11 @@ bool AssetCatalogService::has_unsaved_changes() const
   return catalog_collection_->has_unsaved_changes_;
 }
 
+bool AssetCatalogService::is_read_only() const
+{
+  return is_read_only_;
+}
+
 void AssetCatalogService::tag_all_catalogs_as_unsaved_changes()
 {
   for (auto  : catalog_collection_->catalogs_.values()) {
@@ -458,6 +470,8 @@ bool 
AssetCatalogService::is_catalog_known_with_unsaved_changes(const CatalogID
 
 bool AssetCatalogService::write_to_disk(const CatalogFilePath _file_path)
 {
+  BLI_assert(!is_read_only_);
+
   if (!write_to_disk_ex(blend_file_path)) {
 return false;
   }
@@ -631,6 +645,7 @@ void AssetCatalogService::undo()
 
 void AssetCatalogService::redo()
 {
+  BLI_assert(!is_read_only_);
   BLI_assert_msg(is_redo_possbile(), "Redo stack is empty");
 
   undo_snapshots_.append(std::move(catalog_collection_));
@@ -640,6 +655,7 @@ void AssetCatalogService::redo()
 
 void AssetCatalogService::undo_push()
 {
+  BLI_assert(!is_read_only_);
   std::unique_ptr snapshot = 
catalog_collection_->deep_copy();
   undo_snapshots_.append(std::move(snapshot));
   redo_snapshots_.clear();
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index fbcda02025c..80356214e40 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -157,7 +157,8 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_all(const Main *bmain)
   AssetLibrary _library = *all_library_;
   auto build_catalogs_fn = [_library](const bool is_first_load) {
 /* Start with empty catalog storage. */
-all_library.catalog_service = std::make_unique();

[Bf-blender-cvs] [af0c1d72a2b] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-12-06 Thread Julian Eisel
Commit: af0c1d72a2b519b6234abded2c942767c97fc15c
Author: Julian Eisel
Date:   Tue Dec 6 11:57:01 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBaf0c1d72a2b519b6234abded2c942767c97fc15c

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ecc25bc62ec] temp-asset-library-all: Use "All" library for node add menu building

2022-12-02 Thread Julian Eisel
Commit: ecc25bc62ec517420ce0aef47d9a6af761643f22
Author: Julian Eisel
Date:   Fri Dec 2 20:23:54 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBecc25bc62ec517420ce0aef47d9a6af761643f22

Use "All" library for node add menu building

Code was manually building the add menu from all asset libraries, this
should be simpler now.

===

M   source/blender/editors/asset/ED_asset_list.hh
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/editors/asset/ED_asset_list.hh 
b/source/blender/editors/asset/ED_asset_list.hh
index 541fa315f77..f60c6752d5f 100644
--- a/source/blender/editors/asset/ED_asset_list.hh
+++ b/source/blender/editors/asset/ED_asset_list.hh
@@ -15,6 +15,18 @@ struct AssetLibraryReference;
 struct FileDirEntry;
 struct bContext;
 
+namespace blender::asset_system {
+class AssetLibrary;
+}
+
+/**
+ * Get the asset library being read into an asset-list and identified using \a 
library_reference.
+ * \note The asset library may be loaded asynchronously, so this may return 
null until it becomes
+ *   available.
+ */
+blender::asset_system::AssetLibrary *ED_assetlist_library_get(
+const AssetLibraryReference _reference);
+
 /* Can return false to stop iterating. */
 using AssetListIterFn = blender::FunctionRef;
 void ED_assetlist_iterate(const AssetLibraryReference _reference, 
AssetListIterFn fn);
diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index 64636693a58..e086e5702d1 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -114,6 +114,7 @@ class AssetList : NonCopyable {
   void clear(bContext *C);
 
   bool needsRefetch() const;
+  asset_system::AssetLibrary *asset_library() const;
   void iterate(AssetListIterFn fn) const;
   bool listen(const wmNotifier ) const;
   int size() const;
@@ -180,6 +181,11 @@ bool AssetList::needsRefetch() const
   return filelist_needs_force_reset(filelist_) || 
filelist_needs_reading(filelist_);
 }
 
+asset_system::AssetLibrary *AssetList::asset_library() const
+{
+  return reinterpret_cast(filelist_asset_library(filelist_));
+}
+
 void AssetList::iterate(AssetListIterFn fn) const
 {
   FileList *files = filelist_;
@@ -399,6 +405,7 @@ AssetListStorage::AssetListMap 
::global_storage()
 /** \name C-API
  * \{ */
 
+using namespace blender;
 using namespace blender::ed::asset;
 
 void ED_assetlist_storage_fetch(const AssetLibraryReference 
*library_reference, const bContext *C)
@@ -449,6 +456,16 @@ void ED_assetlist_iterate(const AssetLibraryReference 
_reference, AssetL
   }
 }
 
+asset_system::AssetLibrary *ED_assetlist_library_get(
+const AssetLibraryReference _reference)
+{
+  const AssetList *list = AssetListStorage::lookup_list(library_reference);
+  if (!list) {
+return nullptr;
+  }
+  return list->asset_library();
+}
+
 ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle)
 {
   ImBuf *imbuf = filelist_file_getimage(asset_handle->file_data);
diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index bb5f33f8cf0..2296922e040 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -49,13 +49,6 @@ struct LibraryAsset {
   AssetHandle handle;
 };
 
-struct LibraryCatalog {
-  asset_system::AssetLibrary *library;
-  /* Catalog pointers are not save to store. Use the catalog ID instead and 
lookup the catalog when
-   * needed. */
-  const asset_system::CatalogID catalog_id;
-};
-
 struct AssetItemTree {
   asset_system::AssetCatalogTree catalogs;
   MultiValueMap assets_per_path;
@@ -63,14 +56,18 @@ struct AssetItemTree {
   full_catalog_per_tree_item;
 };
 
+static AssetLibraryReference all_library_reference()
+{
+  AssetLibraryReference all_library_ref{};
+  all_library_ref.custom_library_index = -1;
+  all_library_ref.type = ASSET_LIBRARY_ALL;
+  return all_library_ref;
+}
+
 static bool all_loading_finished()
 {
-  for (const AssetLibraryReference  : 
asset_system::all_valid_asset_library_refs()) {
-if (!ED_assetlist_is_loaded()) {
-  return false;
-}
-  }
-  return true;
+  AssetLibraryReference all_library_ref = all_library_reference();
+  return ED_assetlist_is_loaded(_library_ref);
 }
 
 static AssetItemTree build_catalog_tree(const bContext , const bNodeTree 
*node_tree)
@@ -78,68 +75,52 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
   if (!node_tree) {
 return {};
   }
-  const Main  = *CTX_data_main();
-  const Vector all_libraries = 
asset_system::all_valid_asset_library_refs();
-
-  /* Merge catalogs from all librarie

[Bf-blender-cvs] [11abc1be394] temp-asset-library-all: Use "All" library for node search menu building

2022-12-02 Thread Julian Eisel
Commit: 11abc1be394ccb148c5cda3ecde6dbe0d5eb4f27
Author: Julian Eisel
Date:   Fri Dec 2 20:28:33 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB11abc1be394ccb148c5cda3ecde6dbe0d5eb4f27

Use "All" library for node search menu building

Code was manually building the search menu items from all asset
libraries, this is simpler now.

===

M   source/blender/editors/space_node/add_node_search.cc

===

diff --git a/source/blender/editors/space_node/add_node_search.cc 
b/source/blender/editors/space_node/add_node_search.cc
index ba060ab3925..85c79d5e57d 100644
--- a/source/blender/editors/space_node/add_node_search.cc
+++ b/source/blender/editors/space_node/add_node_search.cc
@@ -93,12 +93,15 @@ static void search_items_for_asset_metadata(const bNodeTree 
_tree,
   search_items.append(std::move(item));
 }
 
-static void gather_search_items_for_asset_library(const bContext ,
-  const bNodeTree _tree,
-  const AssetLibraryReference 
_ref,
-  Set 
_added_assets,
-  Vector 
_items)
+static void gather_search_items_for_all_assets(const bContext ,
+   const bNodeTree _tree,
+   Set 
_added_assets,
+   Vector 
_items)
 {
+  AssetLibraryReference library_ref{};
+  library_ref.custom_library_index = -1;
+  library_ref.type = ASSET_LIBRARY_ALL;
+
   AssetFilterSettings filter_settings{};
   filter_settings.id_types = FILTER_ID_NT;
 
@@ -117,26 +120,6 @@ static void gather_search_items_for_asset_library(const 
bContext ,
   });
 }
 
-static void gather_search_items_for_all_assets(const bContext ,
-   const bNodeTree _tree,
-   Set 
_added_assets,
-   Vector 
_items)
-{
-  int i;
-  LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, 
_libraries, i) {
-AssetLibraryReference library_ref{};
-library_ref.custom_library_index = i;
-library_ref.type = ASSET_LIBRARY_CUSTOM;
-/* Skip local assets to avoid duplicates when the asset is part of the 
local file library. */
-gather_search_items_for_asset_library(C, node_tree, library_ref, 
r_added_assets, search_items);
-  }
-
-  AssetLibraryReference library_ref{};
-  library_ref.custom_library_index = -1;
-  library_ref.type = ASSET_LIBRARY_LOCAL;
-  gather_search_items_for_asset_library(C, node_tree, library_ref, 
r_added_assets, search_items);
-}
-
 static void gather_search_items_for_node_groups(const bContext ,
 const bNodeTree _tree,
 const Set 
_assets,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a07a2e2369d] temp-asset-library-all: Avoid redundant loading of catalogs and "All" library processing

2022-12-02 Thread Julian Eisel
Commit: a07a2e2369d0290d08e124aa53d56cfd4600e341
Author: Julian Eisel
Date:   Fri Dec 2 19:32:46 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBa07a2e2369d0290d08e124aa53d56cfd4600e341

Avoid redundant loading of catalogs and "All" library processing

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 3f2562aa987..6526e3e8382 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -84,8 +84,7 @@ class AssetLibrary {
*  library. This is just a combination of the other 
ones, so usually
*  iterating over it is redundant.
*/
-  static void foreach_loaded(FunctionRef fn,
- bool include_all_library = true);
+  static void foreach_loaded(FunctionRef fn, bool 
include_all_library);
 
   void load_catalogs();
 
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 430de903db7..fbcda02025c 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -155,20 +155,25 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_all(const Main *bmain)
   all_library_ = std::make_unique();
 
   AssetLibrary _library = *all_library_;
-  auto build_catalogs_fn = [_library]() {
+  auto build_catalogs_fn = [_library](const bool is_first_load) {
 /* Start with empty catalog storage. */
 all_library.catalog_service = std::make_unique();
 
 /* (Re-)load catalogs on refresh. */
-AssetLibrary::foreach_loaded([_library](AssetLibrary ) {
-  nested.catalog_service->reload_catalogs();
-  all_library.catalog_service->add_from_existing(*nested.catalog_service);
-});
+AssetLibrary::foreach_loaded(
+[&](AssetLibrary ) {
+  /* On first load the catalogs were read just above, no need to 
reload. */
+  if (!is_first_load) {
+nested.catalog_service->reload_catalogs();
+  }
+  
all_library.catalog_service->add_from_existing(*nested.catalog_service);
+},
+false);
 all_library.catalog_service->rebuild_tree();
   };
 
-  build_catalogs_fn();
-  all_library.on_refresh_ = build_catalogs_fn;
+  build_catalogs_fn(true);
+  all_library.on_refresh_ = [build_catalogs_fn]() { build_catalogs_fn(false); 
};
 
   return _library;
 }
diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 60c34ceda5f..2bf91efc610 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3907,18 +3907,20 @@ static void 
filelist_readjob_all_asset_library(FileListReadJob *job_params,
 
   /* The "All" asset library was loaded, which means all other asset libraries 
are also loaded.
* Load their assets from disk into the "All" library. */
-  asset_system::AssetLibrary::foreach_loaded([&](asset_system::AssetLibrary 
_library) {
-StringRefNull root_path = nested_library.root_path();
-if (root_path.is_empty()) {
-  return;
-}
+  asset_system::AssetLibrary::foreach_loaded(
+  [&](asset_system::AssetLibrary _library) {
+StringRefNull root_path = nested_library.root_path();
+if (root_path.is_empty()) {
+  return;
+}
 
-/* Override library info to read this library. */
-job_params->load_asset_library = _library;
-BLI_strncpy(filelist->filelist.root, root_path.c_str(), 
sizeof(filelist->filelist.root));
+/* Override library info to read this library. */
+job_params->load_asset_library = _library;
+BLI_strncpy(filelist->filelist.root, root_path.c_str(), 
sizeof(filelist->filelist.root));
 
-filelist_readjob_recursive_dir_add_items(true, job_params, stop, 
do_update, progress);
-  });
+filelist_readjob_recursive_dir_add_items(true, job_params, stop, 
do_update, progress);
+  },
+  false);
 }
 
 /**

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [af5d2256538] temp-asset-library-all: Load catalogs for "All" asset library

2022-12-02 Thread Julian Eisel
Commit: af5d225653889bde783f165726ce95786928839a
Author: Julian Eisel
Date:   Fri Dec 2 19:19:08 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBaf5d225653889bde783f165726ce95786928839a

Load catalogs for "All" asset library

Merges the catalog definitions from all asset libraries in to the
storage of the "All" one, builds the catalog tree and refreshes data as
needed. This doesn't allow writing changes back to the catalog
definition files, so the UI probably shouldn't allow edits.

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_catalog.cc
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 87b9425c8c6..a7829778fdf 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -67,6 +67,12 @@ class AssetCatalogService {
   /** Load asset catalog definitions from the given file or directory. */
   void load_from_disk(const CatalogFilePath _or_directory_path);
 
+  /**
+   * Duplicate the catalogs from \a other_service into this one. Does not 
rebuild the tree, this
+   * needs to be done by the caller (call #rebuild_tree()!).
+   */
+  void add_from_existing(const AssetCatalogService _service);
+
   /**
* Write the catalog definitions to disk.
*
@@ -105,6 +111,15 @@ class AssetCatalogService {
*/
   void reload_catalogs();
 
+  /**
+   * Make sure the tree is updated to the latest collection of catalogs stored 
in this service.
+   * Does not depend on a CDF file being available so this can be called on a 
service that stores
+   * catalogs that are not stored in a CDF.
+   * Most API functions that modify catalog data will trigger this, unless 
otherwise specified (for
+   * batch operations).
+   */
+  void rebuild_tree();
+
   /** Return catalog with the given ID. Return nullptr if not found. */
   AssetCatalog *find_catalog(CatalogID catalog_id) const;
 
@@ -222,7 +237,6 @@ class AssetCatalogService {
   const CatalogFilePath _file_path);
 
   std::unique_ptr read_into_tree();
-  void rebuild_tree();
 
   /**
* For every catalog, ensure that its parent path also has a known catalog.
@@ -270,6 +284,11 @@ class AssetCatalogCollection {
   AssetCatalogCollection(AssetCatalogCollection &) noexcept = default;
 
   std::unique_ptr deep_copy() const;
+  /**
+   * Copy the catalogs from \a other and append them to this collection. 
Copies no other data
+   * otherwise (but marks as having unsaved changes).
+   */
+  void add_catalogs_from_existing(const AssetCatalogCollection );
 
  protected:
   static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap 
);
diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index d377f2334b8..3f2562aa987 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -56,6 +56,8 @@ class AssetLibrary {
*/
   std::unique_ptr asset_storage_;
 
+  std::function on_refresh_;
+
   bCallbackFuncStore on_save_callback_store_{};
 
  public:
diff --git a/source/blender/asset_system/intern/asset_catalog.cc 
b/source/blender/asset_system/intern/asset_catalog.cc
index 9b47aca1209..7924ceb862c 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -323,6 +323,11 @@ void AssetCatalogService::load_from_disk(const 
CatalogFilePath _or_director
   rebuild_tree();
 }
 
+void AssetCatalogService::add_from_existing(const AssetCatalogService 
_service)
+{
+  
catalog_collection_->add_catalogs_from_existing(*other_service.catalog_collection_);
+}
+
 void AssetCatalogService::load_directory_recursive(const CatalogFilePath 
_path)
 {
   /* TODO(@sybren): implement proper multi-file support. For now, just load
@@ -658,15 +663,25 @@ std::unique_ptr 
AssetCatalogCollection::deep_copy() cons
   return copy;
 }
 
-OwningAssetCatalogMap AssetCatalogCollection::copy_catalog_map(const 
OwningAssetCatalogMap )
+static void copy_catalog_map_into_existing(const OwningAssetCatalogMap ,
+   OwningAssetCatalogMap )
 {
-  OwningAssetCatalogMap copy;
-
-  for (const auto _catalog_uptr : orig.values()) {
+  for (const auto _catalog_uptr : source.values()) {
 auto copy_catalog_uptr = 
std::make_unique(*orig_catalog_uptr);
-copy.add_new(copy_catalog_uptr->catalog_id, std::move(copy_catalog_uptr));
+dest.add_new(copy_catalog_uptr->catalog_id, std::move(copy_catalog_uptr));
   }

[Bf-blender-cvs] [fb2303fb739] temp-asset-library-all: Avoid ugly nested library storage

2022-12-02 Thread Julian Eisel
Commit: fb2303fb739e72e263289d9aeee10031b10a3ec6
Author: Julian Eisel
Date:   Fri Dec 2 16:58:47 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBfb2303fb739e72e263289d9aeee10031b10a3ec6

Avoid ugly nested library storage

We actually don't have to do this, since we can just iterate over all
loaded libraries after calling the loading for the "All" asset library.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh
M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index a9ed5ff0594..d377f2334b8 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -56,10 +56,6 @@ class AssetLibrary {
*/
   std::unique_ptr asset_storage_;
 
-  /** In some cases an asset library is a combination of multiple other ones, 
these are then
-   * referenced here. "All" asset library only currently. */
-  Vector nested_libs_; /* Non-owning pointers. */
-
   bCallbackFuncStore on_save_callback_store_{};
 
  public:
@@ -78,6 +74,17 @@ class AssetLibrary {
   AssetLibrary(StringRef root_path = "");
   ~AssetLibrary();
 
+  /**
+   * Execute \a fn for every asset library that is loaded. The asset library 
is passed to the
+   * \a fn call.
+   *
+   * \param skip_all_library: When true, the \a fn will also be executed for 
the "All" asset
+   *  library. This is just a combination of the other 
ones, so usually
+   *  iterating over it is redundant.
+   */
+  static void foreach_loaded(FunctionRef fn,
+ bool include_all_library = true);
+
   void load_catalogs();
 
   /** Load catalogs that have changed on disk. */
@@ -101,8 +108,6 @@ class AssetLibrary {
   /** Remove an asset from the library that was added using 
#add_external_asset() or
* #add_local_id_asset(). Can usually be expected to be constant time 
complexity (worst case may
* differ).
-   * Can also be called when this asset library is just a merged library 
containing multiple nested
-   * ones ("All" library). Will then check if it exists in a nested library 
and remove it.
*
* \note This is save to call if \a asset is freed (dangling reference), 
will not perform any
*   change then.
@@ -110,11 +115,6 @@ class AssetLibrary {
* case when the reference is dangling). */
   bool remove_asset(AssetRepresentation );
 
-  /** In some cases an asset library is a combination of multiple other ones 
("All" asset library
-   * only currently). Iterate over the contained asset libraries, executing \a 
fn for each of them.
-   */
-  void foreach_nested(FunctionRef fn);
-
   /**
* Remap ID pointers for local ID assets, see #BKE_lib_remap.h. When an ID 
pointer would be
* mapped to null (typically when an ID gets removed), the asset is removed, 
because we don't
@@ -142,9 +142,6 @@ class AssetLibrary {
   AssetIdentifier asset_identifier_from_library(StringRef relative_asset_path);
 
   StringRefNull root_path() const;
-
- private:
-  std::optional find_asset_index(const AssetRepresentation );
 };
 
 Vector all_valid_asset_library_refs();
@@ -152,6 +149,13 @@ Vector 
all_valid_asset_library_refs();
 }  // namespace blender::asset_system
 
 /**
+ * Load the data for an asset library, but not the asset representations 
themselves (loading these
+ * is currently not done in the asset system).
+ *
+ * For the "All" asset library (#ASSET_LIBRARY_ALL), every other known asset 
library will be
+ * loaded as well. So a call to #AssetLibrary::foreach_loaded() can be 
expected to iterate over all
+ * libraries.
+ *
  * \warning Catalogs are reloaded, invalidating catalog pointers. Do not store 
catalog pointers,
  *  store CatalogIDs instead and lookup the catalog where needed.
  */
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 1fe477707a1..b763822c1ac 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -121,9 +121,11 @@ void AS_asset_library_refresh_catalog_simplename(struct 
::AssetLibrary *asset_li
 void AS_asset_library_remap_ids(const IDRemapper *mappings)
 {
   AssetLibraryService *service = AssetLibraryService::get();
-  service->foreach_loaded_asset_library([mappings](asset_system::AssetLibrary 
) {
-library.remap_ids_and_remove_invalid(*mappings);
-  });
+  service-&g

[Bf-blender-cvs] [1dc8305213a] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-12-02 Thread Julian Eisel
Commit: 1dc8305213a838b2e87e3a480576570b95cdc0d1
Author: Julian Eisel
Date:   Fri Dec 2 19:18:18 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB1dc8305213a838b2e87e3a480576570b95cdc0d1

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [71071a25a04] master: Fix crash on File > Link or Append

2022-12-02 Thread Julian Eisel
Commit: 71071a25a046c90f17ae3a6c4bde2a21470a0e4e
Author: Julian Eisel
Date:   Fri Dec 2 19:07:42 2022 +0100
Branches: master
https://developer.blender.org/rB71071a25a046c90f17ae3a6c4bde2a21470a0e4e

Fix crash on File > Link or Append

Would attempt to destruct memory of a null pointer. Use `MEM_delete()`
instead of manual destruction, which allows this case (NOP then).

===

M   source/blender/blenkernel/intern/asset.cc

===

diff --git a/source/blender/blenkernel/intern/asset.cc 
b/source/blender/blenkernel/intern/asset.cc
index 74605af815d..8fa5fc5842b 100644
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@ -33,8 +33,8 @@ AssetMetaData *BKE_asset_metadata_create()
 
 void BKE_asset_metadata_free(AssetMetaData **asset_data)
 {
-  (*asset_data)->~AssetMetaData();
-  MEM_SAFE_FREE(*asset_data);
+  MEM_delete(*asset_data);
+  *asset_data = nullptr;
 }
 
 AssetMetaData::~AssetMetaData()

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5186c9c9c65] temp-asset-library-all: Merge remote-tracking branch 'origin/master' into temp-asset-library-all

2022-12-02 Thread Julian Eisel
Commit: 5186c9c9c65c8b78b6c395442d3d53c9539b66b4
Author: Julian Eisel
Date:   Fri Dec 2 16:20:28 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB5186c9c9c65c8b78b6c395442d3d53c9539b66b4

Merge remote-tracking branch 'origin/master' into temp-asset-library-all

===



===

diff --cc source/blender/editors/space_file/filelist.cc
index 9d1191ad80e,bf0f9c865a8..ca83ff6d51b
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@@ -3125,13 -3104,17 +3125,17 @@@ static void filelist_readjob_list_lib_a
  if (datablock_info->asset_data) {
entry->typeflag |= FILE_TYPE_ASSET;
  
-   if (job_params->load_asset_library) {
- /** XXX Moving out the asset metadata like this isn't great. */
- std::unique_ptr metadata = BKE_asset_metadata_move_to_unique_ptr(
- datablock_info->asset_data);
- BKE_asset_metadata_free(_info->asset_data);
 -  if (filelist->asset_library) {
++  if (job_params->asset_library) {
+ /* Take ownership over the asset data (shallow copies into unique_ptr 
managed memory) to
+  * pass it on to the asset system. */
+ std::unique_ptr metadata = 
std::make_unique(*datablock_info->asset_data);
+ MEM_freeN(datablock_info->asset_data);
+ /* Give back a non-owning pointer, because the data-block info is 
still needed (e.g. to
+  * update the asset index). */
+ datablock_info->asset_data = metadata.get();
+ datablock_info->free_asset_data = false;
  
 -entry->asset = >asset_library->add_external_asset(
 +entry->asset = _params->load_asset_library->add_external_asset(
  entry->relpath, datablock_info->name, std::move(metadata));
}
  }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6a7917162c5] master: Fix asset index only generating empty entries since 1efc94bb2f7b

2022-12-02 Thread Julian Eisel
Commit: 6a7917162c560eef9c5db188bc0a4d608aff21ad
Author: Julian Eisel
Date:   Thu Dec 1 15:48:54 2022 +0100
Branches: master
https://developer.blender.org/rB6a7917162c560eef9c5db188bc0a4d608aff21ad

Fix asset index only generating empty entries since 1efc94bb2f7b

Steps to reproduce were:
- Open a .blend file that is located inside of an asset library and
  contains assets.
- Save and close the file.
- Open a new file (Ctrl+N -> General).
- Open asset browser and load the asset library from above.
- If the assets from the file above still show up, press refresh button.
- -> Assets from the file above don't appear.

Likely fixes the underlying issue for T102610. A followup will be needed
to correct the empty asset index files written because of this bug.

We're in the process of moving responsibilities from the file/asset
browser backend to the asset system. 1efc94bb2f7b introduces a new
representation for asset, which would own the asset metadata now instead
of the file data.

Since the file-list code still does the loading of asset libraries,
ownership of the asset metadata has to be transferred to the asset
system. However, the asset indexing still requires it to be available,
so it can update the index with latest data. So transfer the ownership,
but still keep a non-owning pointer set.

Differential Revision: https://developer.blender.org/D16665

Reviewed by: Bastien Montagne

===

M   source/blender/blenkernel/BKE_asset.h
M   source/blender/blenkernel/intern/asset.cc
M   source/blender/blenloader/BLO_readfile.h
M   source/blender/blenloader/intern/readblenentry.cc
M   source/blender/editors/asset/intern/asset_indexer.cc
M   source/blender/editors/space_file/file_indexer.cc
M   source/blender/editors/space_file/filelist.cc
M   source/blender/makesdna/DNA_asset_types.h

===

diff --git a/source/blender/blenkernel/BKE_asset.h 
b/source/blender/blenkernel/BKE_asset.h
index 81a132a8f91..81b520a1db0 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -71,12 +71,3 @@ void BKE_asset_metadata_read(struct BlendDataReader *reader, 
struct AssetMetaDat
 #ifdef __cplusplus
 }
 #endif
-
-#ifdef __cplusplus
-
-#  include 
-
-[[nodiscard]] std::unique_ptr 
BKE_asset_metadata_move_to_unique_ptr(
-AssetMetaData *asset_data);
-
-#endif
diff --git a/source/blender/blenkernel/intern/asset.cc 
b/source/blender/blenkernel/intern/asset.cc
index 7103e017847..74605af815d 100644
--- a/source/blender/blenkernel/intern/asset.cc
+++ b/source/blender/blenkernel/intern/asset.cc
@@ -47,13 +47,6 @@ AssetMetaData::~AssetMetaData()
   BLI_freelistN();
 }
 
-std::unique_ptr 
BKE_asset_metadata_move_to_unique_ptr(AssetMetaData *asset_data)
-{
-  std::unique_ptr unique_asset_data = 
std::make_unique(*asset_data);
-  *asset_data = *DNA_struct_default_get(AssetMetaData);
-  return unique_asset_data;
-}
-
 static AssetTag *asset_metadata_tag_add(AssetMetaData *asset_data, const char 
*const name)
 {
   AssetTag *tag = (AssetTag *)MEM_callocN(sizeof(*tag), __func__);
diff --git a/source/blender/blenloader/BLO_readfile.h 
b/source/blender/blenloader/BLO_readfile.h
index 75a1956ce12..4c34b628a6d 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -182,6 +182,7 @@ void BLO_blendfiledata_free(BlendFileData *bfd);
 typedef struct BLODataBlockInfo {
   char name[64]; /* MAX_NAME */
   struct AssetMetaData *asset_data;
+  bool free_asset_data;
   /* Optimization: Tag data-blocks for which we know there is no preview.
* Knowing this can be used to skip the (potentially expensive) preview 
loading process. If this
* is set to true it means we looked for a preview and couldn't find one. 
False may mean that
@@ -189,6 +190,15 @@ typedef struct BLODataBlockInfo {
   bool no_preview_found;
 } BLODataBlockInfo;
 
+/**
+ * Frees contained data, not \a datablock_info itself.
+ */
+void BLO_datablock_info_free(BLODataBlockInfo *datablock_info);
+/**
+ * Can be used to free the list returned by 
#BLO_blendhandle_get_datablock_info().
+ */
+void BLO_datablock_info_linklist_free(struct LinkNode * /*BLODataBlockInfo*/ 
datablock_infos);
+
 /**
  * Open a blendhandle from a file path.
  *
@@ -231,8 +241,11 @@ struct LinkNode 
*BLO_blendhandle_get_datablock_names(BlendHandle *bh,
  * \param ofblocktype: The type of names to get.
  * \param use_assets_only: Limit the result to assets only.
  * \param r_tot_info_items: The length of the returned list.
+ *
  * \return A BLI_linklist of `BLODataBlockInfo *`.
- * The links and #BLODataBlockInfo.asset_data should be freed with MEM_freeN.
+ *
+ * \note The links should be freed using #BLO_datablock_info_free() or the 
entire list using
+ *   #BLO_datablock_info_linklist_free().
  */
 struct LinkNode * /*BLODataBlo

[Bf-blender-cvs] [5c580ff4574] master: Fix asset-only loading optimizatoin not working as intended

2022-12-01 Thread Julian Eisel
Commit: 5c580ff45746fa79057788562a74b25e40ca7ec4
Author: Julian Eisel
Date:   Wed Nov 30 21:05:19 2022 +0100
Branches: master
https://developer.blender.org/rB5c580ff45746fa79057788562a74b25e40ca7ec4

Fix asset-only loading optimizatoin not working as intended

Introduced in fc7beac8d6f4, but I think this never worked because the
`asset_library_ref` of the temporary file-list used for reading in a
background thread is nulled. Now there's a different pointer that we can
use that works properly.

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index beb1387b26e..3374da082d8 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3614,7 +3614,7 @@ static void 
filelist_readjob_recursive_dir_add_items(const bool do_lib,
   }
   /* Only load assets when browsing an asset library. For normal file 
browsing we return all
* entries. `FLF_ASSETS_ONLY` filter can be enabled/disabled by the 
user. */
-  if (filelist->asset_library_ref) {
+  if (filelist->asset_library) {
 list_lib_options |= LIST_LIB_ASSETS_ONLY;
   }
   std::optional lib_entries_num = filelist_readjob_list_lib(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1a2e2dcddc5] master: Cleanup: Improve function name for asset identifier creation

2022-12-01 Thread Julian Eisel
Commit: 1a2e2dcddc5d2d798ffb24b9656cfb12ec4ed04d
Author: Julian Eisel
Date:   Thu Dec 1 11:41:04 2022 +0100
Branches: master
https://developer.blender.org/rB1a2e2dcddc5d2d798ffb24b9656cfb12ec4ed04d

Cleanup: Improve function name for asset identifier creation

I find this a bit more explanatory/clear.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 9f9b1b80343..f272ed6ff51 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -125,7 +125,7 @@ class AssetLibrary {
* Create an asset identifier from the root path of this asset library and 
the given relative
* asset path (relative to the asset library root directory).
*/
-  AssetIdentifier derive_asset_identifier(StringRef relative_asset_path);
+  AssetIdentifier asset_identifier_from_library(StringRef relative_asset_path);
 
   StringRefNull root_path() const;
 
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 2f3b56d226a..73f81a50e46 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -152,13 +152,13 @@ AssetRepresentation 
::add_external_asset(StringRef relative_asset_p
   StringRef name,
   
std::unique_ptr metadata)
 {
-  AssetIdentifier identifier = derive_asset_identifier(relative_asset_path);
+  AssetIdentifier identifier = 
asset_identifier_from_library(relative_asset_path);
   return asset_storage_->add_external_asset(std::move(identifier), name, 
std::move(metadata));
 }
 
 AssetRepresentation ::add_local_id_asset(StringRef 
relative_asset_path, ID )
 {
-  AssetIdentifier identifier = derive_asset_identifier(relative_asset_path);
+  AssetIdentifier identifier = 
asset_identifier_from_library(relative_asset_path);
   return asset_storage_->add_local_id_asset(std::move(identifier), id);
 }
 
@@ -215,7 +215,7 @@ void AssetLibrary::on_blend_save_post(struct Main *main,
   }
 }
 
-AssetIdentifier AssetLibrary::derive_asset_identifier(StringRef 
relative_asset_path)
+AssetIdentifier AssetLibrary::asset_identifier_from_library(StringRef 
relative_asset_path)
 {
   return AssetIdentifier(root_path_, relative_asset_path);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [126136baaba] temp-asset-library-all: Fix missing asset previews and broken drag & drop in "All" library

2022-11-30 Thread Julian Eisel
Commit: 126136baabac679e95d578267d2b4f042dc5f9bd
Author: Julian Eisel
Date:   Wed Nov 30 20:15:04 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB126136baabac679e95d578267d2b4f042dc5f9bd

Fix missing asset previews and broken drag & drop in "All" library

Together with the changes made in master, all this does is making sure
the assets are loaded and removed using the correct asset library nested
within the "All" library. Now full paths for the assets can be built
correctly from the asset identifier, which fixes preview loading and
drag & drop.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index cb75a2540ff..561452d3ac8 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -101,6 +101,9 @@ class AssetLibrary {
   /** Remove an asset from the library that was added using 
#add_external_asset() or
* #add_local_id_asset(). Can usually be expected to be constant time 
complexity (worst case may
* differ).
+   * Can also be called when this asset library is just a merged library 
containing multiple nested
+   * ones ("All" library). Will then check if it exists in a nested library 
and remove it.
+   *
* \note This is save to call if \a asset is freed (dangling reference), 
will not perform any
*   change then.
* \return True on success, false if the asset couldn't be found inside the 
library (also the
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 043d1a45ef2..944e91bcf4d 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -170,7 +170,24 @@ AssetRepresentation 
::add_local_id_asset(StringRef relative_asset_p
 
 bool AssetLibrary::remove_asset(AssetRepresentation )
 {
-  return asset_storage_->remove_asset(asset);
+  /* Usual case, only the "All" library differs and uses nested libraries (see 
below). */
+  if (asset_storage_->remove_asset(asset)) {
+return true;
+  }
+
+  /* If asset is not stored in this library, check nested ones (for "All" 
library). */
+  for (AssetLibrary *library : nested_libs_) {
+if (!library) {
+  BLI_assert_unreachable();
+  continue;
+}
+
+if (asset_storage_->remove_asset(asset)) {
+  return true;
+}
+  }
+
+  return false;
 }
 
 void AssetLibrary::foreach_nested(FunctionRef fn)
diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 5039fcdce5a..9d1191ad80e 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -2928,6 +2928,11 @@ struct FileListReadJob {
* `Materials/Material.001`). */
   char cur_relbase[FILE_MAX_LIBEXTRA];
 
+  /** The current asset library to load. Usually the same as 
#FileList.asset_library, however
+   * sometimes the #FileList one is a combination of multiple other ones 
("All" asset library),
+   * which need to be loaded individually. Then this can be set to override 
the #FileList library.
+   * Use this in all loading code. */
+  asset_system::AssetLibrary *load_asset_library;
   /** Set to request a partial read that only adds files representing #Main 
data (IDs). Used when
* #Main may have received changes of interest (e.g. asset removed or 
renamed). */
   bool only_main_data;
@@ -3105,7 +3110,6 @@ static void 
filelist_readjob_list_lib_add_datablock(FileListReadJob *job_params,
 const int idcode,
 const char *group_name)
 {
-  FileList *filelist = job_params->tmp_filelist; /* Use the thread-safe 
filelist queue. */
   FileListInternEntry *entry = MEM_cnew(__func__);
   if (prefix_relpath_with_group_name) {
 std::string datablock_path = StringRef(group_name) + "/" + 
datablock_info->name;
@@ -3121,13 +3125,13 @@ static void 
filelist_readjob_list_lib_add_datablock(FileListReadJob *job_params,
 if (datablock_info->asset_data) {
   entry->typeflag |= FILE_TYPE_ASSET;
 
-  if (filelist->asset_library) {
+  if (job_params->load_asset_library) {
 /** XXX Moving out the asset metadata like this isn't great. */
 std::unique_ptr metadata = BKE_asset_metadata_move_to_unique_ptr(
 datablock_info->asset_data);
 BKE_asset_metadata_free(_info->asset_data);
 
-entry->asset = >asset_library->

[Bf-blender-cvs] [3f1e4f6f56d] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-11-30 Thread Julian Eisel
Commit: 3f1e4f6f56d3c4bba24a0d70ea7779918d9565a4
Author: Julian Eisel
Date:   Wed Nov 30 20:02:29 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB3f1e4f6f56d3c4bba24a0d70ea7779918d9565a4

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [03bd4371702] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-11-30 Thread Julian Eisel
Commit: 03bd43717027ef4318c30edf611e4f32d94f1a95
Author: Julian Eisel
Date:   Wed Nov 30 19:49:29 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB03bd43717027ef4318c30edf611e4f32d94f1a95

Merge branch 'master' into temp-asset-library-all

===



===

diff --cc source/blender/asset_system/intern/asset_library.cc
index 79c3c55029c,2f3b56d226a..043d1a45ef2
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@@ -249,7 -235,11 +253,12 @@@ void AssetLibrary::refresh_catalog_simp
STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
  }
  
+ StringRefNull AssetLibrary::root_path() const
+ {
+   return *root_path_;
+ }
+ 
 +/* TODO get rid of this. */
  Vector all_valid_asset_library_refs()
  {
Vector result;
diff --cc source/blender/asset_system/intern/asset_storage.hh
index 0814c258442,2b4614abca5..b4866fa9382
--- a/source/blender/asset_system/intern/asset_storage.hh
+++ b/source/blender/asset_system/intern/asset_storage.hh
@@@ -30,13 -31,13 +31,15 @@@ class AssetStorage 
 * faster lookups. Not possible until each asset is only represented once 
in the storage. */
StorageT local_id_assets_;
  
 +  friend class AssetLibrary;
 +
   public:
/** See #AssetLibrary::add_external_asset(). */
-   AssetRepresentation _external_asset(StringRef name, 
std::unique_ptr metadata);
+   AssetRepresentation _external_asset(AssetIdentifier &,
+   StringRef name,
+   std::unique_ptr 
metadata);
/** See #AssetLibrary::add_external_asset(). */
-   AssetRepresentation _local_id_asset(ID );
+   AssetRepresentation _local_id_asset(AssetIdentifier &, ID 
);
  
/** See #AssetLibrary::remove_asset(). */
bool remove_asset(AssetRepresentation );

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2c2515d4657] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-11-30 Thread Julian Eisel
Commit: 2c2515d46573c0c407e134253782d917883edb08
Author: Julian Eisel
Date:   Tue Nov 29 11:14:41 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB2c2515d46573c0c407e134253782d917883edb08

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b582028b127] master: Correct previously missed case of manual path building in file browser

2022-11-30 Thread Julian Eisel
Commit: b582028b127aab86028f422c8f30a5e697714c60
Author: Julian Eisel
Date:   Wed Nov 30 19:59:26 2022 +0100
Branches: master
https://developer.blender.org/rBb582028b127aab86028f422c8f30a5e697714c60

Correct previously missed case of manual path building in file browser

Missed in 39c9164ea183. Also adds a comments to point at the function
that should be used instead.

===

M   source/blender/editors/space_file/file_draw.c
M   source/blender/editors/space_file/filelist.h
M   source/blender/makesdna/DNA_space_types.h

===

diff --git a/source/blender/editors/space_file/file_draw.c 
b/source/blender/editors/space_file/file_draw.c
index ed0132c6990..e85a6cbc0d4 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -907,7 +907,6 @@ void file_draw_list(const bContext *C, ARegion *region)
   View2D *v2d = >v2d;
   struct FileList *files = sfile->files;
   struct FileDirEntry *file;
-  const char *root = filelist_dir(files);
   ImBuf *imb;
   uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
   int numfiles;
@@ -988,7 +987,6 @@ void file_draw_list(const bContext *C, ARegion *region)
 
   for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) {
 uint file_selflag;
-char path[FILE_MAX_LIBEXTRA];
 const int padx = 0.1f * UI_UNIT_X;
 int icon_ofs = 0;
 
@@ -997,7 +995,8 @@ void file_draw_list(const bContext *C, ARegion *region)
 file = filelist_file(files, i);
 file_selflag = filelist_entry_select_get(sfile->files, file, CHECK_ALL);
 
-BLI_path_join(path, sizeof(path), root, file->relpath);
+char path[FILE_MAX_LIBEXTRA];
+filelist_file_get_full_path(files, file, path);
 
 if (!(file_selflag & FILE_SEL_EDITING)) {
   if ((params->highlight_file == i) || (file_selflag & 
FILE_SEL_HIGHLIGHTED) ||
diff --git a/source/blender/editors/space_file/filelist.h 
b/source/blender/editors/space_file/filelist.h
index e81a8926eaf..e96ced3fa63 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -94,6 +94,10 @@ void filelist_clear_ex(struct FileList *filelist,
 void filelist_clear_from_reset_tag(struct FileList *filelist);
 void filelist_free(struct FileList *filelist);
 
+/**
+ * Get the root path of the file list. To get the full path for a file, use
+ * #filelist_file_get_full_path().
+ */
 const char *filelist_dir(const struct FileList *filelist);
 bool filelist_is_dir(struct FileList *filelist, const char *path);
 /**
diff --git a/source/blender/makesdna/DNA_space_types.h 
b/source/blender/makesdna/DNA_space_types.h
index 36c15b6e106..72e39647093 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1123,7 +1123,8 @@ typedef struct FileDirEntry {
   /** ID type, in case typeflag has FILE_TYPE_BLENDERLIB set. */
   int blentype;
 
-  /* Path to item that is relative to current folder root. */
+  /* Path to item that is relative to current folder root. To get the full 
path, use
+   * #filelist_file_get_full_path() */
   char *relpath;
   /** Optional argument for shortcuts, aliases etc. */
   char *redirection_path;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [39c9164ea18] master: File/Asset Browser: Get full asset path from asset representation

2022-11-30 Thread Julian Eisel
Commit: 39c9164ea1839decfa4f6b8930237864e5be6509
Author: Julian Eisel
Date:   Wed Nov 30 19:34:11 2022 +0100
Branches: master
https://developer.blender.org/rB39c9164ea1839decfa4f6b8930237864e5be6509

File/Asset Browser: Get full asset path from asset representation

No user visible changes expected.

Add a function to query the full path for a file, so that asset files
can get the path via the asset representation and its new asset
identifier. This is designed to be a reliable way to locate an asset,
and using it is yet another step to rely less on the problematic file
browser code.
Also, previous code would build the full path manually in a few places,
which is good to deduplicate anyway.

===

M   source/blender/editors/space_file/file_ops.c
M   source/blender/editors/space_file/filelist.cc
M   source/blender/editors/space_file/filelist.h

===

diff --git a/source/blender/editors/space_file/file_ops.c 
b/source/blender/editors/space_file/file_ops.c
index 6d7365fa136..e9a7080ff35 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2859,12 +2859,12 @@ static bool file_delete_poll(bContext *C)
   return false;
 }
 
-static bool file_delete_single(const FileSelectParams *params,
+static bool file_delete_single(const struct FileList *files,
FileDirEntry *file,
const char **r_error_message)
 {
-  char str[FILE_MAX];
-  BLI_path_join(str, sizeof(str), params->dir, file->relpath);
+  char str[FILE_MAX_LIBEXTRA];
+  filelist_file_get_full_path(files, file, str);
   if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) {
 return false;
   }
@@ -2876,7 +2876,6 @@ static int file_delete_exec(bContext *C, wmOperator *op)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
   SpaceFile *sfile = CTX_wm_space_file(C);
-  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   int numfiles = filelist_files_ensure(sfile->files);
 
   const char *error_message = NULL;
@@ -2885,7 +2884,7 @@ static int file_delete_exec(bContext *C, wmOperator *op)
   for (int i = 0; i < numfiles; i++) {
 if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) {
   FileDirEntry *file = filelist_file(sfile->files, i);
-  if (!file_delete_single(params, file, _message)) {
+  if (!file_delete_single(sfile->files, file, _message)) {
 report_error = true;
   }
 }
diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index b97f1e27a1a..beb1387b26e 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -1132,6 +1132,18 @@ void filelist_free_icons(void)
   }
 }
 
+void filelist_file_get_full_path(const FileList *filelist, const FileDirEntry 
*file, char *r_path)
+{
+  if (file->asset) {
+const std::string asset_path = 
AS_asset_representation_full_path_get(file->asset);
+BLI_strncpy(r_path, asset_path.c_str(), FILE_MAX_LIBEXTRA);
+return;
+  }
+
+  const char *root = filelist_dir(filelist);
+  BLI_path_join(r_path, FILE_MAX_LIBEXTRA, root, file->relpath);
+}
+
 static FileDirEntry *filelist_geticon_get_file(struct FileList *filelist, 
const int index)
 {
   BLI_assert(G.background == false);
@@ -1176,8 +1188,8 @@ ImBuf *filelist_geticon_image(struct FileList *filelist, 
const int index)
   return filelist_geticon_image_ex(file);
 }
 
-static int filelist_geticon_ex(const FileDirEntry *file,
-   const char *root,
+static int filelist_geticon_ex(const FileList *filelist,
+   const FileDirEntry *file,
const bool is_main,
const bool ignore_libdir)
 {
@@ -1215,8 +1227,8 @@ static int filelist_geticon_ex(const FileDirEntry *file,
   if (file->redirection_path) {
 target = file->redirection_path;
   }
-  else if (root) {
-BLI_path_join(fullpath, sizeof(fullpath), root, file->relpath);
+  else if (filelist) {
+filelist_file_get_full_path(filelist, file, fullpath);
 BLI_path_slash_ensure(fullpath, sizeof(fullpath));
   }
   for (; tfsm; tfsm = tfsm->next) {
@@ -1296,13 +1308,13 @@ int filelist_geticon(struct FileList *filelist, const 
int index, const bool is_m
 {
   FileDirEntry *file = filelist_geticon_get_file(filelist, index);
 
-  return filelist_geticon_ex(file, filelist->filelist.root, is_main, false);
+  return filelist_geticon_ex(filelist, file, is_main, false);
 }
 
 int ED_file_icon(const FileDirEntry *file)
 {
   return file->preview_icon_id ? file->preview_icon_id :
- filelist_geticon_ex(file, nullptr, false, 
false);
+  

[Bf-blender-cvs] [f68da703a5d] master: Asset system: Initial asset identifier type

2022-11-30 Thread Julian Eisel
Commit: f68da703a5d2731231e0faa5d33eef87d65eedf1
Author: Julian Eisel
Date:   Wed Nov 30 18:12:42 2022 +0100
Branches: master
https://developer.blender.org/rBf68da703a5d2731231e0faa5d33eef87d65eedf1

Asset system: Initial asset identifier type

No user visible changes expected.

`AssetIdentifier` holds information to uniquely identify and locate an
asset. More information:
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Identifier

For the start this is tied quite a bit to file paths, so that external
assets are assumed to be in the file system.

This is needed to support an "All" asset library (see T102879), which
would contain assets from different locations. Currently the location of
an asset is queried via the file browser backend, which however requires
a common root location. It also moves us further away from the file
browser towards the asset system (see T87235) and allows us to remove
some hacks (see following commit).

===

A   source/blender/asset_system/AS_asset_identifier.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/AS_asset_representation.hh
M   source/blender/asset_system/CMakeLists.txt
A   source/blender/asset_system/intern/asset_identifier.cc
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_representation.cc
M   source/blender/asset_system/intern/asset_storage.cc
M   source/blender/asset_system/intern/asset_storage.hh
M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/asset_system/AS_asset_identifier.hh 
b/source/blender/asset_system/AS_asset_identifier.hh
new file mode 100644
index 000..33b7f71becc
--- /dev/null
+++ b/source/blender/asset_system/AS_asset_identifier.hh
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ *
+ * \brief Information to uniquely identify and locate an asset.
+ *
+ * 
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Identifier
+ */
+
+#pragma once
+
+#include 
+#include 
+
+namespace blender::asset_system {
+
+class AssetIdentifier {
+  std::shared_ptr library_root_path_;
+  std::string relative_asset_path_;
+
+ public:
+  AssetIdentifier(std::shared_ptr library_root_path, std::string 
relative_asset_path);
+  AssetIdentifier(AssetIdentifier &&) = default;
+  AssetIdentifier(const AssetIdentifier &) = default;
+
+  std::string full_path() const;
+};
+
+}  // namespace blender::asset_system
diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 7df6e6d9f51..9f9b1b80343 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -24,6 +24,7 @@ struct Main;
 
 namespace blender::asset_system {
 
+class AssetIdentifier;
 class AssetRepresentation;
 class AssetStorage;
 
@@ -35,8 +36,10 @@ class AssetStorage;
  */
 class AssetLibrary {
   /** If this is an asset library on disk, the top-level directory path. 
Normalized using
-   * #normalize_directory_path().*/
-  std::string root_path_;
+   * #normalize_directory_path(). Shared pointer so assets can safely point to 
it, and don't have
+   * to hold a copy (which is the size of `std::string` + the allocated 
buffer, if no short string
+   * optimization is used). With thousands of assets this might make a 
reasonable difference. */
+  std::shared_ptr root_path_;
 
   /** Storage for assets (better said their representations) that are 
considered to be part of this
* library. Assets are not automatically loaded into this when loading an 
asset library. Assets
@@ -79,10 +82,16 @@ class AssetLibrary {
* representation is not needed anymore, it must be freed using 
#remove_asset(), or there will be
* leaking that's only cleared when the library storage is destructed 
(typically on exit or
* loading a different file).
+   *
+   * \param relative_asset_path: The path of the asset relative to the asset 
library root. With
+   * this the asset must be uniquely identifiable 
within the asset
+   * library.
*/
-  AssetRepresentation _external_asset(StringRef name, 
std::unique_ptr metadata);
+  AssetRepresentation _external_asset(StringRef relative_asset_path,
+  StringRef name,
+  std::unique_ptr 
metadata);
   /** See #AssetLibrary::add_external_asset(). */
-  AssetRepresentation _local_id_asset(ID );
+  AssetRepresentation _local_id_asset(StringRef relative_asset_path, ID 
);
   /** Remove an asset from the library that was added using 
#add_external_asset() or
* #add_local_id_asset(). Can usually be expect

[Bf-blender-cvs] [ccc9eef1b92] master: Assets: Get asset path via new identifier (not via file browser hacks)

2022-11-30 Thread Julian Eisel
Commit: ccc9eef1b9278ec2e8b57feddbf44cdfcda9d0a9
Author: Julian Eisel
Date:   Wed Nov 30 19:24:24 2022 +0100
Branches: master
https://developer.blender.org/rBccc9eef1b9278ec2e8b57feddbf44cdfcda9d0a9

Assets: Get asset path via new identifier (not via file browser hacks)

With the asset identifier introduced in the previous commit, we can now
locate an asset just from its `AssetRepresentation`, without requiring
information from the asset library and the file browser storage. With
this we can remove some hacks and function parameters. A RNA/BPY
function is also affected, but I didn't remove the paramter to keep
compatibility. It's simply ignored and not required anymore, noted this
in the parameter description (noted for T102877).

===

M   release/scripts/startup/bl_operators/assets.py
M   release/scripts/startup/bl_ui/space_filebrowser.py
M   source/blender/editors/armature/pose_lib_2.c
M   source/blender/editors/asset/ED_asset_handle.h
M   source/blender/editors/asset/ED_asset_list.h
M   source/blender/editors/asset/ED_asset_list.hh
M   source/blender/editors/asset/ED_asset_temp_id_consumer.h
M   source/blender/editors/asset/intern/asset_handle.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/asset/intern/asset_temp_id_consumer.cc
M   source/blender/editors/interface/interface_template_asset_view.cc
M   source/blender/editors/space_node/add_node_search.cc
M   source/blender/editors/space_node/link_drag_search.cc
M   source/blender/editors/space_node/node_add.cc
M   source/blender/makesrna/intern/rna_asset.c
M   source/blender/windowmanager/WM_api.h
M   source/blender/windowmanager/intern/wm_dragdrop.cc

===

diff --git a/release/scripts/startup/bl_operators/assets.py 
b/release/scripts/startup/bl_operators/assets.py
index 1911a98f930..b794ede10a2 100644
--- a/release/scripts/startup/bl_operators/assets.py
+++ b/release/scripts/startup/bl_operators/assets.py
@@ -97,13 +97,12 @@ class ASSET_OT_open_containing_blend_file(Operator):
 
 def execute(self, context):
 asset_file_handle = context.asset_file_handle
-asset_library_ref = context.asset_library_ref
 
 if asset_file_handle.local_id:
 self.report({'WARNING'}, "This asset is stored in the current 
blend file")
 return {'CANCELLED'}
 
-asset_lib_path = 
bpy.types.AssetHandle.get_full_library_path(asset_file_handle, 
asset_library_ref)
+asset_lib_path = 
bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
 self.open_in_new_blender(asset_lib_path)
 
 wm = context.window_manager
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py 
b/release/scripts/startup/bl_ui/space_filebrowser.py
index 1e7faf68b3f..614f350533b 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -862,8 +862,7 @@ def asset_path_str_get(_self):
 if asset_file_handle.local_id:
 return "Current File"
 
-asset_library_ref = bpy.context.asset_library_ref
-return bpy.types.AssetHandle.get_full_library_path(asset_file_handle, 
asset_library_ref)
+return bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
 
 
 def register_props():
diff --git a/source/blender/editors/armature/pose_lib_2.c 
b/source/blender/editors/armature/pose_lib_2.c
index e3189eacdd5..1e69d9d0fc2 100644
--- a/source/blender/editors/armature/pose_lib_2.c
+++ b/source/blender/editors/armature/pose_lib_2.c
@@ -249,16 +249,15 @@ static void poselib_tempload_exit(PoseBlendData *pbd)
 static bAction *poselib_blend_init_get_action(bContext *C, wmOperator *op)
 {
   bool asset_handle_valid;
-  const AssetLibraryReference *asset_library_ref = CTX_wm_asset_library_ref(C);
   const AssetHandle asset_handle = CTX_wm_asset_handle(C, _handle_valid);
   /* Poll callback should check. */
-  BLI_assert((asset_library_ref != NULL) && asset_handle_valid);
+  BLI_assert(asset_handle_valid);
 
   PoseBlendData *pbd = op->customdata;
 
   pbd->temp_id_consumer = ED_asset_temp_id_consumer_create(_handle);
   return (bAction *)ED_asset_temp_id_consumer_ensure_local_id(
-  pbd->temp_id_consumer, C, asset_library_ref, ID_AC, CTX_data_main(C), 
op->reports);
+  pbd->temp_id_consumer, ID_AC, CTX_data_main(C), op->reports);
 }
 
 static bAction *flip_pose(bContext *C, Object *ob, bAction *action)
@@ -508,11 +507,9 @@ static bool poselib_asset_in_context(bContext *C)
 {
   bool asset_handle_valid;
   /* Check whether the context provides the asset data needed to add a pose. */
-  const AssetLibraryReference *asset_library_ref = CTX_wm_asset_library_ref(C);
-  AssetHandle asset_handle = CTX_wm_asset_handle(C, _handle_valid);
+  const AssetHandle asset_handle = CTX_

[Bf-blender-cvs] [2165136740f] master: File/Asset Browser: Refactor how recursive paths are set

2022-11-30 Thread Julian Eisel
Commit: 2165136740f88fe92ebe4e548ef587adb6a3dfdd
Author: Julian Eisel
Date:   Wed Nov 30 18:54:42 2022 +0100
Branches: master
https://developer.blender.org/rB2165136740f88fe92ebe4e548ef587adb6a3dfdd

File/Asset Browser: Refactor how recursive paths are set

When reading directories recursively, the code would first only set the
file name as the relative path and then later iterate over the read files
and prepend the recursed into path, to get the complete path relative to
the recursed into directory. This isn't clear and confused me quite a
bit. And it is not compatible with what we need for creating asset
identifiers, which are introduced in the 2nd following commit.

Instead properly determine the complete relative path when initially
adding the file, and don't change it after. The asset identifier can the
be constructed properly at the time needed.

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index dc59bb1286d..4a27893e985 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -2888,7 +2888,65 @@ struct TodoDir {
   char *dir;
 };
 
-static int filelist_readjob_list_dir(const char *root,
+struct FileListReadJob {
+  ThreadMutex lock;
+  char main_name[FILE_MAX];
+  Main *current_main;
+  FileList *filelist;
+
+  /** The path currently being read, relative to the filelist root directory. 
Needed for recursive
+   * reading. The full file path is then composed like: `//.
+   * (whereby the file name may also be a library path within a .blend, e.g.
+   * `Materials/Material.001`). */
+  char cur_relbase[FILE_MAX_LIBEXTRA];
+
+  /** Set to request a partial read that only adds files representing #Main 
data (IDs). Used when
+   * #Main may have received changes of interest (e.g. asset removed or 
renamed). */
+  bool only_main_data;
+
+  /** Shallow copy of #filelist for thread-safe access.
+   *
+   * The job system calls #filelist_readjob_update which moves any read file 
from #tmp_filelist
+   * into #filelist in a thread-safe way.
+   *
+   * #tmp_filelist also keeps an `AssetLibrary *` so that it can be loaded in 
the same thread,
+   * and moved to #filelist once all categories are loaded.
+   *
+   * NOTE: #tmp_filelist is freed in #filelist_readjob_free, so any copied 
pointers need to be
+   * set to nullptr to avoid double-freeing them. */
+  FileList *tmp_filelist;
+};
+
+/**
+ * Append \a filename (or even a path inside of a .blend, like 
`Material/Material.001`), to the
+ * current relative path being read within the filelist root. The returned 
string needs freeing
+ * with #MEM_freeN().
+ */
+static char *current_relpath_append(const FileListReadJob *job_params, const 
char *filename)
+{
+  const char *relbase = job_params->cur_relbase;
+
+  /* Early exit, nothing to join. */
+  if (!relbase[0]) {
+return BLI_strdup(filename);
+  }
+
+  BLI_assert(relbase[strlen(relbase) - 1] == SEP);
+  BLI_assert(BLI_path_is_rel(relbase));
+
+  char relpath[FILE_MAX_LIBEXTRA];
+  /* Using #BLI_path_join works but isn't needed as `rel_subdir` has a 
trailing slash. */
+  BLI_string_join(relpath,
+  sizeof(relpath),
+  /* + 2 to remove "//" relative path prefix. */
+  relbase + 2,
+  filename);
+
+  return BLI_strdup(relpath);
+}
+
+static int filelist_readjob_list_dir(FileListReadJob *job_params,
+ const char *root,
  ListBase *entries,
  const char *filter_glob,
  const bool do_lib,
@@ -2911,7 +2969,7 @@ static int filelist_readjob_list_dir(const char *root,
   }
 
   entry = MEM_cnew(__func__);
-  entry->relpath = static_cast(MEM_dupallocN(files[i].relname));
+  entry->relpath = current_relpath_append(job_params, files[i].relname);
   entry->st = files[i].s;
 
   BLI_path_join(full_path, FILE_MAX, root, entry->relpath);
@@ -2998,11 +3056,11 @@ enum ListLibOptions {
 };
 ENUM_OPERATORS(ListLibOptions, LIST_LIB_ADD_PARENT);
 
-static FileListInternEntry *filelist_readjob_list_lib_group_create(const int 
idcode,
-   const char 
*group_name)
+static FileListInternEntry *filelist_readjob_list_lib_group_create(
+const FileListReadJob *job_params, const int idcode, const char 
*group_name)
 {
   FileListInternEntry *entry = MEM_cnew(__func__);
-  entry->relpath = BLI_strdup(group_name);
+  entry->relpath = current_relpath_append(job_params, group_name);
   entry->typeflag |= FILE_TYPE_BLENDERLIB | FILE_TYPE_DIR;
   entry->blentype = idcode;
   return 

[Bf-blender-cvs] [cfaca0d9ab2] master: Asset System: Store root path in asset library data

2022-11-30 Thread Julian Eisel
Commit: cfaca0d9ab2fa102379c09b6db693e41ceddb2e8
Author: Julian Eisel
Date:   Wed Nov 30 17:15:31 2022 +0100
Branches: master
https://developer.blender.org/rBcfaca0d9ab2fa102379c09b6db693e41ceddb2e8

Asset System: Store root path in asset library data

No user visible changes expected.

If an asset library is located on disk, store the path to it in the
asset library data. This is called the "root path" now.
With this we can construct an asset identifier, which is introduced in
the following commit.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh
A   source/blender/asset_system/intern/utils.cc
A   source/blender/asset_system/intern/utils.hh

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 1a558c4e322..7df6e6d9f51 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -34,7 +34,9 @@ class AssetStorage;
  * to also include asset indexes and more.
  */
 class AssetLibrary {
-  bCallbackFuncStore on_save_callback_store_{};
+  /** If this is an asset library on disk, the top-level directory path. 
Normalized using
+   * #normalize_directory_path().*/
+  std::string root_path_;
 
   /** Storage for assets (better said their representations) that are 
considered to be part of this
* library. Assets are not automatically loaded into this when loading an 
asset library. Assets
@@ -51,6 +53,8 @@ class AssetLibrary {
*/
   std::unique_ptr asset_storage_;
 
+  bCallbackFuncStore on_save_callback_store_{};
+
  public:
   /* Controlled by #ED_asset_catalogs_set_save_catalogs_when_file_is_saved,
* for managing the "Save Catalog Changes" in the quit-confirmation dialog 
box. */
@@ -59,10 +63,13 @@ class AssetLibrary {
   std::unique_ptr catalog_service;
 
  public:
-  AssetLibrary();
+  /**
+   * \param root_path: If this is an asset library on disk, the top-level 
directory path.
+   */
+  AssetLibrary(StringRef root_path = "");
   ~AssetLibrary();
 
-  void load_catalogs(StringRefNull library_root_directory);
+  void load_catalogs();
 
   /** Load catalogs that have changed on disk. */
   void refresh();
@@ -105,6 +112,8 @@ class AssetLibrary {
 
   void on_blend_save_post(Main *bmain, PointerRNA **pointers, int 
num_pointers);
 
+  StringRefNull root_path() const;
+
  private:
   std::optional find_asset_index(const AssetRepresentation );
 };
diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index d00c3c72e3b..c9ef11d33f4 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -21,6 +21,7 @@ set(SRC
   intern/asset_library_service.cc
   intern/asset_representation.cc
   intern/asset_storage.cc
+  intern/utils.cc
 
   AS_asset_catalog.hh
   AS_asset_catalog_path.hh
@@ -29,6 +30,7 @@ set(SRC
   AS_asset_representation.hh
   intern/asset_library_service.hh
   intern/asset_storage.hh
+  intern/utils.hh
 
   AS_asset_library.h
   AS_asset_representation.h
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 45196a218aa..7bdffe9abad 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -22,6 +22,7 @@
 
 #include "asset_library_service.hh"
 #include "asset_storage.hh"
+#include "utils.hh"
 
 using namespace blender;
 using namespace blender::asset_system;
@@ -120,8 +121,9 @@ void AS_asset_library_remap_ids(const IDRemapper *mappings)
 
 namespace blender::asset_system {
 
-AssetLibrary::AssetLibrary()
-: asset_storage_(std::make_unique()),
+AssetLibrary::AssetLibrary(StringRef root_path)
+: root_path_(utils::normalize_directory_path(root_path)),
+  asset_storage_(std::make_unique()),
   catalog_service(std::make_unique())
 {
 }
@@ -133,9 +135,9 @@ AssetLibrary::~AssetLibrary()
   }
 }
 
-void AssetLibrary::load_catalogs(StringRefNull library_root_directory)
+void AssetLibrary::load_catalogs()
 {
-  auto catalog_service = 
std::make_unique(library_root_directory);
+  auto catalog_service = std::make_unique(root_path());
   catalog_service->load_from_disk();
   this->catalog_service = std::move(catalog_service);
 }
@@ -224,6 +226,11 @@ void AssetLibrary::refresh_catalog_simplename(struct 
AssetMetaData *asset_data)
   STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
 }
 
+StringRefNull AssetLibrary::root_path() const
+{
+  return roo

[Bf-blender-cvs] [d51212c4f05] temp-asset-library-all: Integrate "All" library better with the asset system

2022-11-28 Thread Julian Eisel
Commit: d51212c4f05e38851580f7e9e75d174695dc1b82
Author: Julian Eisel
Date:   Mon Nov 28 19:37:00 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBd51212c4f05e38851580f7e9e75d174695dc1b82

Integrate "All" library better with the asset system

Now it actually loads data from all asset libraries when this is
selected. The asset representations still need to be loaded by the file
browser backend, this won't change for now.

This adds the concept of nested asset libraries, which I'd prefer to
keep as implementation detail and not expose in the API. But for now
it's needed (for the asset representation loading by the file browser
backend).

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh
A   source/blender/asset_system/intern/utils.cc
A   source/blender/asset_system/intern/utils.hh
M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index ece3426731c..3bbed9603a5 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -34,7 +34,9 @@ class AssetStorage;
  * to also include asset indexes and more.
  */
 class AssetLibrary {
-  bCallbackFuncStore on_save_callback_store_{};
+  /** If this is an asset library on disk, the top-level directory path. 
Normalized using
+   * #normalize_directory_path().*/
+  std::string root_path_;
 
   /** Storage for assets (better said their representations) that are 
considered to be part of this
* library. Assets are not automatically loaded into this when loading an 
asset library. Assets
@@ -51,6 +53,12 @@ class AssetLibrary {
*/
   std::unique_ptr asset_storage_;
 
+  /** In some cases an asset library is a combination of multiple other ones, 
these are then
+   * referenced here. "All" asset library only currently. */
+  Vector nested_libs_; /* Non-owning pointers. */
+
+  bCallbackFuncStore on_save_callback_store_{};
+
  public:
   /* Controlled by #ED_asset_catalogs_set_save_catalogs_when_file_is_saved,
* for managing the "Save Catalog Changes" in the quit-confirmation dialog 
box. */
@@ -58,11 +66,16 @@ class AssetLibrary {
 
   std::unique_ptr catalog_service;
 
+  friend class AssetLibraryService;
+
  public:
-  AssetLibrary();
+  /**
+   * \param root_path: If this is an asset library on disk, the top-level 
directory path.
+   */
+  AssetLibrary(StringRef root_path = "");
   ~AssetLibrary();
 
-  void load_catalogs(StringRefNull library_root_directory);
+  void load_catalogs();
 
   /** Load catalogs that have changed on disk. */
   void refresh();
@@ -85,6 +98,11 @@ class AssetLibrary {
* case when the reference is dangling). */
   bool remove_asset(AssetRepresentation );
 
+  /** In some cases an asset library is a combination of multiple other ones 
("All" asset library
+   * only currently). Iterate over the contained asset libraries, executing \a 
fn for each of them.
+   */
+  void foreach_nested(FunctionRef fn);
+
   /**
* Remap ID pointers for local ID assets, see #BKE_lib_remap.h. When an ID 
pointer would be
* mapped to null (typically when an ID gets removed), the asset is removed, 
because we don't
@@ -105,6 +123,8 @@ class AssetLibrary {
 
   void on_blend_save_post(Main *bmain, PointerRNA **pointers, int 
num_pointers);
 
+  StringRefNull root_path() const;
+
  private:
   std::optional find_asset_index(const AssetRepresentation );
 };
diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index d00c3c72e3b..c9ef11d33f4 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -21,6 +21,7 @@ set(SRC
   intern/asset_library_service.cc
   intern/asset_representation.cc
   intern/asset_storage.cc
+  intern/utils.cc
 
   AS_asset_catalog.hh
   AS_asset_catalog_path.hh
@@ -29,6 +30,7 @@ set(SRC
   AS_asset_representation.hh
   intern/asset_library_service.hh
   intern/asset_storage.hh
+  intern/utils.hh
 
   AS_asset_library.h
   AS_asset_representation.h
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index eebbc8db837..79c3c55029c 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -22,6 +22,7 @@
 
 #include "asset_library_service.hh"
 #include "asset_storage.hh"
+#include "utils.hh"
 
 using nam

[Bf-blender-cvs] [ca8fa2f7d61] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-11-28 Thread Julian Eisel
Commit: ca8fa2f7d61890ec2a7beac144010816e3735cec
Author: Julian Eisel
Date:   Thu Nov 24 16:25:39 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rBca8fa2f7d61890ec2a7beac144010816e3735cec

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [86b9b1df227] temp-asset-library-all: Merge branch 'master' into temp-asset-library-all

2022-11-28 Thread Julian Eisel
Commit: 86b9b1df227639f8d906d49e4896be4862b24256
Author: Julian Eisel
Date:   Mon Nov 28 15:44:59 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB86b9b1df227639f8d906d49e4896be4862b24256

Merge branch 'master' into temp-asset-library-all

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [19a13a8b8b8] blender-v3.3-release: Fix T85870: ColorRamp Keyframes crash Blender

2022-11-28 Thread Julian Eisel
Commit: 19a13a8b8b80a458322e7895672658f453e72c4f
Author: Julian Eisel
Date:   Tue Nov 8 12:14:31 2022 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rB19a13a8b8b80a458322e7895672658f453e72c4f

Fix T85870: ColorRamp Keyframes crash Blender

The color-band needs to do some special, rather awkward updating of the
UI state when certain values are changed. As @lichtwerk noted in the
report, this was done to the wrong buttons. Now lookup the proper
buttons, and don't assume that `uiItemR()` only adds a single button
(which often isn't the case).

===

M   source/blender/editors/interface/interface_templates.c

===

diff --git a/source/blender/editors/interface/interface_templates.c 
b/source/blender/editors/interface/interface_templates.c
index f051e9004ca..89713a7eabd 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -3673,13 +3673,9 @@ static void colorband_buttons_layout(uiLayout *layout,
 
   row = uiLayoutRow(split, false);
   uiItemR(row, , "position", 0, IFACE_("Pos"), ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_func_set(bt, colorband_update_cb, bt, coba);
 
   row = uiLayoutRow(layout, false);
   uiItemR(row, , "color", 0, "", ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
 }
 else {
   split = uiLayoutSplit(layout, 0.5f, false);
@@ -3704,13 +3700,28 @@ static void colorband_buttons_layout(uiLayout *layout,
 
   row = uiLayoutRow(subsplit, false);
   uiItemR(row, , "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), 
ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_func_set(bt, colorband_update_cb, bt, coba);
 
   row = uiLayoutRow(split, false);
   uiItemR(row, , "color", 0, "", ICON_NONE);
-  bt = block->buttons.last;
-  UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL);
+}
+
+/* Some special (rather awkward) treatment to update UI state on certain 
property changes. */
+LISTBASE_FOREACH_BACKWARD (uiBut *, but, >buttons) {
+  if (but->rnapoin.data != ptr.data) {
+continue;
+  }
+  if (!but->rnaprop) {
+continue;
+  }
+
+  const char *prop_identifier = RNA_property_identifier(but->rnaprop);
+  if (STREQ(prop_identifier, "position")) {
+UI_but_func_set(but, colorband_update_cb, but, coba);
+  }
+
+  if (STREQ(prop_identifier, "color")) {
+UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), NULL);
+  }
 }
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6396d297796] master: Merge branch 'blender-v3.4-release'

2022-11-23 Thread Julian Eisel
Commit: 6396d2977968cb9376ab9edcfbfab4a6dcbdc044
Author: Julian Eisel
Date:   Wed Nov 23 13:25:12 2022 +0100
Branches: master
https://developer.blender.org/rB6396d2977968cb9376ab9edcfbfab4a6dcbdc044

Merge branch 'blender-v3.4-release'

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ff9606ddc4e] blender-v3.4-release: Fix use-after-free of asset catalog data in node add menu

2022-11-23 Thread Julian Eisel
Commit: ff9606ddc4e2681903e484afd7c16e8f20a8ebc2
Author: Julian Eisel
Date:   Fri Nov 18 17:20:07 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rBff9606ddc4e2681903e484afd7c16e8f20a8ebc2

Fix use-after-free of asset catalog data in node add menu

(Probably requires ASan for a reliable crash.)

Steps to reproduce were:
* Enter Geometry Nodes Workspace
* Press "New" button in the geometry nodes editor header
* Right-click the data-block selector -> "Mark as Asset"
* Change 3D View to Asset Browser
* Create a catalog
* Drag new Geometry Nodes asset into the catalog
* Save the file
* Press Shift+A in the geometry nodes editor

There was a general issue here with keeping catalog pointers around
during the add menu building. The way it does things, catalogs may be
reloaded in between.
Since the Current File asset library isn't loaded in a separate thread,
the use-after-free would always happen in between. For other libraries
it could still happen, but apparently didn't by chance.

===

M   source/blender/blenkernel/BKE_asset_catalog.hh
M   source/blender/blenkernel/BKE_asset_library.hh
M   source/blender/editors/asset/ED_asset_list.h
M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh 
b/source/blender/blenkernel/BKE_asset_catalog.hh
index 73c2e00c4c4..3e1a73c23c4 100644
--- a/source/blender/blenkernel/BKE_asset_catalog.hh
+++ b/source/blender/blenkernel/BKE_asset_catalog.hh
@@ -424,8 +424,14 @@ class AssetCatalogDefinitionFile {
   bool ensure_directory_exists(const CatalogFilePath directory_path) const;
 };
 
-/** Asset Catalog definition, containing a symbolic ID and a path that points 
to a node in the
- * catalog hierarchy. */
+/**
+ * Asset Catalog definition, containing a symbolic ID and a path that points 
to a node in the
+ * catalog hierarchy.
+ *
+ * \warning The asset system may reload catalogs, invalidating pointers. Thus 
it's not recommended
+ *  to store pointers to asset catalogs. Store the #CatalogID instead 
and do a lookup when
+ *  needed.
+ */
 class AssetCatalog {
  public:
   AssetCatalog() = default;
diff --git a/source/blender/blenkernel/BKE_asset_library.hh 
b/source/blender/blenkernel/BKE_asset_library.hh
index 2058df71f6a..243c8218509 100644
--- a/source/blender/blenkernel/BKE_asset_library.hh
+++ b/source/blender/blenkernel/BKE_asset_library.hh
@@ -61,6 +61,10 @@ Vector all_valid_asset_library_refs();
 
 }  // namespace blender::bke
 
+/**
+ * \warning Catalogs are reloaded, invalidating catalog pointers. Do not store 
catalog pointers,
+ *  store CatalogIDs instead and lookup the catalog where needed.
+ */
 blender::bke::AssetLibrary *BKE_asset_library_load(const Main *bmain,
const AssetLibraryReference 
_reference);
 
diff --git a/source/blender/editors/asset/ED_asset_list.h 
b/source/blender/editors/asset/ED_asset_list.h
index 3d2aaa3bda1..bcd5dbca8d4 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -20,6 +20,9 @@ struct wmNotifier;
 /**
  * Invoke asset list reading, potentially in a parallel job. Won't wait until 
the job is done,
  * and may return earlier.
+ *
+ * \warning: Asset list reading involves an #AS_asset_library_load() call 
which may reload asset
+ *   library data like catalogs (invalidating pointers). Refer to its 
warning for details.
  */
 void ED_assetlist_storage_fetch(const struct AssetLibraryReference 
*library_reference,
 const struct bContext *C);
diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index 5458a25d74a..f361f70c265 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -49,7 +49,9 @@ struct LibraryAsset {
 
 struct LibraryCatalog {
   bke::AssetLibrary *library;
-  const bke::AssetCatalog *catalog;
+  /* Catalog pointers are not save to store. Use the catalog ID instead and 
lookup the catalog when
+   * needed. */
+  const bke::CatalogID catalog_id;
 };
 
 struct AssetItemTree {
@@ -88,7 +90,7 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
   const bke::CatalogID  = item.get_catalog_id();
   bke::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});
+  id_to_catalog_map.add(item.get_catalog_id(), LibraryCatalog{library, 
id});
 });
   }
 }
@@ -118,7 +120,9 @@ static AssetItemTree build_catalog_tree(const bCon

[Bf-blender-cvs] [80249ce6e4f] master: Asset Browser: Allow changing active catalog from Python

2022-11-23 Thread Julian Eisel
Commit: 80249ce6e4f9a031277f1b12af923c23128165a7
Author: Julian Eisel
Date:   Wed Nov 23 11:44:18 2022 +0100
Branches: master
https://developer.blender.org/rB80249ce6e4f9a031277f1b12af923c23128165a7

Asset Browser: Allow changing active catalog from Python

The active catalog ID (UUID) was a read only property. From a studio I
got the request to make this editable, so their pipeline tooling can
make certain assets visible.

Differential Revision: https://developer.blender.org/D16356

Reviewed by: Sybren Stüvel

===

M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 20ef064af39..e0341e76667 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3325,6 +3325,26 @@ static int 
rna_FileAssetSelectParams_catalog_id_length(PointerRNA *UNUSED(ptr))
   return UUID_STRING_LEN - 1;
 }
 
+static void rna_FileAssetSelectParams_catalog_id_set(PointerRNA *ptr, const 
char *value)
+{
+  FileAssetSelectParams *params = ptr->data;
+
+  if (value[0] == '\0') {
+params->catalog_id = BLI_uuid_nil();
+params->asset_catalog_visibility = FILE_SHOW_ASSETS_ALL_CATALOGS;
+return;
+  }
+
+  bUUID new_uuid;
+  if (!BLI_uuid_parse_string(_uuid, value)) {
+printf("UUID %s not formatted correctly, ignoring new value\n", value);
+return;
+  }
+
+  params->catalog_id = new_uuid;
+  params->asset_catalog_visibility = FILE_SHOW_ASSETS_FROM_CATALOG;
+}
+
 #else
 
 static const EnumPropertyItem dt_uv_items[] = {
@@ -6870,9 +6890,9 @@ static void rna_def_fileselect_asset_params(BlenderRNA 
*brna)
   RNA_def_property_string_funcs(prop,
 "rna_FileAssetSelectParams_catalog_id_get",
 "rna_FileAssetSelectParams_catalog_id_length",
-NULL);
-  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+"rna_FileAssetSelectParams_catalog_id_set");
   RNA_def_property_ui_text(prop, "Catalog UUID", "The UUID of the catalog 
shown in the browser");
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
 
   prop = RNA_def_property(srna, "filter_asset_id", PROP_POINTER, PROP_NONE);
   RNA_def_property_flag(prop, PROP_NEVER_NULL);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [571f373155c] master: UI: Don't render missing linked material previews, avoids UI freezing

2022-11-23 Thread Julian Eisel
Commit: 571f373155cb34d6b27f454e6a6fe28d80134593
Author: Julian Eisel
Date:   Wed Nov 23 11:37:02 2022 +0100
Branches: master
https://developer.blender.org/rB571f373155cb34d6b27f454e6a6fe28d80134593

UI: Don't render missing linked material previews, avoids UI freezing

Opening the material selector after reloading files could cause long UI
freezes, because some linked in materials don't have the preview stored
in the source file. So Blender would keep rerendering it after every
file load, which may involve compiling OpenGL shaders, which again
freezes the UI typically. This was reported as quite an issue for the
Heist Production by the Blender Studio.

Don't render these missing material previews from linked data-blocks
anymore.

Differential Revision: https://developer.blender.org/D16538

Reviewed by: Brecht Van Lommel, Jeroen Bakker

===

M   source/blender/editors/render/render_preview.cc

===

diff --git a/source/blender/editors/render/render_preview.cc 
b/source/blender/editors/render/render_preview.cc
index 09394ea33be..ecc29c56836 100644
--- a/source/blender/editors/render/render_preview.cc
+++ b/source/blender/editors/render/render_preview.cc
@@ -1605,6 +1605,14 @@ static void icon_preview_startjob_all_sizes(void 
*customdata,
   continue;
 }
 
+/* Workaround: Skip preview renders for linked IDs. Preview rendering can 
be slow and even
+ * freeze the UI (e.g. on Eevee shader compilation). And since the result 
will never be stored
+ * in a file, it's done every time the file is reloaded, so this becomes a 
frequent annoyance.
+ */
+if (!use_solid_render_mode && ip->id && ID_IS_LINKED(ip->id)) {
+  continue;
+}
+
 #ifndef NDEBUG
 {
   int size_index = icon_previewimg_size_index_get(cur_size, prv);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [33bcc4f4309] temp-asset-library-all: Initial "All" asset library loading support

2022-11-22 Thread Julian Eisel
Commit: 33bcc4f43092c10d37d4120c860c3a222c05d9f7
Author: Julian Eisel
Date:   Tue Nov 22 17:56:36 2022 +0100
Branches: temp-asset-library-all
https://developer.blender.org/rB33bcc4f43092c10d37d4120c860c3a222c05d9f7

Initial "All" asset library loading support

An "All" asset library can be selected in the Asset Browser and asset
view templates now, and that will load all assets from all asset
libraries. Preview loading, drag & drop and asset catalogs don't work
yet.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh
M   source/blender/asset_system/intern/asset_storage.hh
M   source/blender/editors/asset/intern/asset_library_reference_enum.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/space_file/file_draw.c
M   source/blender/editors/space_file/filelist.cc
M   source/blender/editors/space_file/filesel.c
M   source/blender/makesdna/DNA_asset_defaults.h
M   source/blender/makesdna/DNA_asset_types.h
M   source/blender/makesdna/DNA_space_types.h

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 1a558c4e322..ece3426731c 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -120,6 +120,9 @@ Vector 
all_valid_asset_library_refs();
 blender::asset_system::AssetLibrary *AS_asset_library_load(
 const Main *bmain, const AssetLibraryReference _reference);
 
+std::string AS_asset_library_root_path_from_library_ref(
+const AssetLibraryReference _reference);
+
 /**
  * Try to find an appropriate location for an asset library root from a file 
or directory path.
  * Does not check if \a input_path exists.
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 45196a218aa..eebbc8db837 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -64,6 +64,12 @@ bool AS_asset_library_has_any_unsaved_catalogs()
   return service->has_any_unsaved_catalogs();
 }
 
+std::string AS_asset_library_root_path_from_library_ref(
+const AssetLibraryReference _reference)
+{
+  return AssetLibraryService::root_path_from_library_ref(library_reference);
+}
+
 std::string AS_asset_library_find_suitable_root_path_from_path(
 const blender::StringRefNull input_path)
 {
@@ -224,6 +230,7 @@ void AssetLibrary::refresh_catalog_simplename(struct 
AssetMetaData *asset_data)
   STRNCPY(asset_data->catalog_simple_name, catalog->simple_name.c_str());
 }
 
+/* TODO get rid of this. */
 Vector all_valid_asset_library_refs()
 {
   Vector result;
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 9bd2eecd468..c40e6059f66 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -68,12 +68,17 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 
 return get_asset_library_on_disk(root_path);
   }
+
+  /* TODO */
+  if (library_reference.type == ASSET_LIBRARY_ALL) {
+return get_asset_library_current_file();
+  }
+
   if (library_reference.type == ASSET_LIBRARY_CUSTOM) {
-bUserAssetLibrary *user_library = 
BKE_preferences_asset_library_find_from_index(
-, library_reference.custom_library_index);
+std::string root_path = root_path_from_library_ref(library_reference);
 
-if (user_library) {
-  return get_asset_library_on_disk(user_library->path);
+if (!root_path.empty()) {
+  return get_asset_library_on_disk(root_path);
 }
   }
 
@@ -133,6 +138,31 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_current_file()
   return lib;
 }
 
+std::string AssetLibraryService::root_path_from_library_ref(
+const AssetLibraryReference _reference)
+{
+  if (ELEM(library_reference.type, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL)) {
+return "";
+  }
+
+  const char *top_level_directory = nullptr;
+
+  BLI_assert(library_reference.type == ASSET_LIBRARY_CUSTOM);
+  BLI_assert(library_reference.custom_library_index >= 0);
+
+  bUserAssetLibrary *user_library = 
BKE_preferences_asset_library_find_from_index(
+  , library_reference.custom_library_index);
+  if (user_library) {
+top_level_directory = user_library->path;
+  }
+
+  if (!top_level_directory) {
+return "";
+  }
+
+  return normalize_directory_path(top_level_directory);
+}
+
 void AssetLibraryService::allocate_service_instance()
 {

[Bf-blender-cvs] [2910be8f19c] master: Cleanup: Correct semantics for .blend listing in file/asset browser

2022-11-21 Thread Julian Eisel
Commit: 2910be8f19cf87dd57bdc3a81ce5b26fed2a8beb
Author: Julian Eisel
Date:   Mon Nov 21 12:16:30 2022 +0100
Branches: master
https://developer.blender.org/rB2910be8f19cf87dd57bdc3a81ce5b26fed2a8beb

Cleanup: Correct semantics for .blend listing in file/asset browser

When attempting to load contents of a .blend, the code would just assume
if the number of added items is 0, that means it's not a .blend (but a
directory, although the previous commit fixed that part already).
However there may be situations where a .blend file simply doesn't
contain anything of interest to be added (e.g. when listing assets
only), so have a proper "none" value for this.

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 46211a72a82..dc59bb1286d 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef WIN32
@@ -3116,11 +3117,15 @@ static int 
filelist_readjob_list_lib_populate_from_index(FileList *filelist,
   return read_from_index + navigate_to_parent_len;
 }
 
-static int filelist_readjob_list_lib(FileList *filelist,
- const char *root,
- ListBase *entries,
- const ListLibOptions options,
- FileIndexer *indexer_runtime)
+/**
+ * \return The number of entries found if the \a root path points to a valid 
library file.
+ * Otherwise returns no value (#std::nullopt).
+ */
+static std::optional filelist_readjob_list_lib(FileList *filelist,
+const char *root,
+ListBase *entries,
+const ListLibOptions 
options,
+FileIndexer 
*indexer_runtime)
 {
   BLI_assert(indexer_runtime);
 
@@ -3135,7 +3140,7 @@ static int filelist_readjob_list_lib(FileList *filelist,
* call it directly from `filelist_readjob_do` to increase readability. */
   const bool is_lib = BLO_library_path_explode(root, dir, , nullptr);
   if (!is_lib) {
-return 0;
+return std::nullopt;
   }
 
   const bool group_came_from_path = group != nullptr;
@@ -3166,7 +3171,7 @@ static int filelist_readjob_list_lib(FileList *filelist,
   BlendFileReadReport bf_reports{};
   libfiledata = BLO_blendhandle_from_file(dir, _reports);
   if (libfiledata == nullptr) {
-return 0;
+return std::nullopt;
   }
 
   /* Add current parent when requested. */
@@ -3557,10 +3562,11 @@ static void 
filelist_readjob_recursive_dir_add_items(const bool do_lib,
   if (filelist->asset_library_ref) {
 list_lib_options |= LIST_LIB_ASSETS_ONLY;
   }
-  entries_num = filelist_readjob_list_lib(
+  std::optional lib_entries_num = filelist_readjob_list_lib(
   filelist, subdir, , list_lib_options, _runtime);
-  if (entries_num > 0) {
+  if (lib_entries_num) {
 is_lib = true;
+entries_num += *lib_entries_num;
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c58e7da43e0] master: Asset Browser: Avoid non-existent directory prints

2022-11-21 Thread Julian Eisel
Commit: c58e7da43e03d6b24408305654b63c37007e7227
Author: Julian Eisel
Date:   Mon Nov 21 12:11:52 2022 +0100
Branches: master
https://developer.blender.org/rBc58e7da43e03d6b24408305654b63c37007e7227

Asset Browser: Avoid non-existent directory prints

When loading asset libraries, there would be a bunch of "non-existent
directory" prints because we were calling a function to list directory
contents on .blend file paths. Make sure the path actually points to a
directory.

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 22c94065234..46211a72a82 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -3564,7 +3564,7 @@ static void 
filelist_readjob_recursive_dir_add_items(const bool do_lib,
   }
 }
 
-if (!is_lib) {
+if (!is_lib && BLI_is_dir(subdir)) {
   entries_num = filelist_readjob_list_dir(
   subdir, , filter_glob, do_lib, job_params->main_name, 
skip_currpar);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c6e4953719a] master: Fix use-after-free of asset catalog data in node add menu

2022-11-18 Thread Julian Eisel
Commit: c6e4953719ad1f9d5917c108a8d8fe712103a274
Author: Julian Eisel
Date:   Fri Nov 18 17:20:07 2022 +0100
Branches: master
https://developer.blender.org/rBc6e4953719ad1f9d5917c108a8d8fe712103a274

Fix use-after-free of asset catalog data in node add menu

(Probably requires ASan for a reliable crash.)

Steps to reproduce were:
* Enter Geometry Nodes Workspace
* Press "New" button in the geometry nodes editor header
* Right-click the data-block selector -> "Mark as Asset"
* Change 3D View to Asset Browser
* Create a catalog
* Drag new Geometry Nodes asset into the catalog
* Save the file
* Press Shift+A in the geometry nodes editor

There was a general issue here with keeping catalog pointers around
during the add menu building. The way it does things, catalogs may be
reloaded in between.
Since the Current File asset library isn't loaded in a separate thread,
the use-after-free would always happen in between. For other libraries
it could still happen, but apparently didn't by chance.

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/editors/asset/ED_asset_list.h
M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 6c4fdeedaad..87b9425c8c6 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -341,8 +341,14 @@ class AssetCatalogDefinitionFile {
   bool ensure_directory_exists(const CatalogFilePath directory_path) const;
 };
 
-/** Asset Catalog definition, containing a symbolic ID and a path that points 
to a node in the
- * catalog hierarchy. */
+/**
+ * Asset Catalog definition, containing a symbolic ID and a path that points 
to a node in the
+ * catalog hierarchy.
+ *
+ * \warning The asset system may reload catalogs, invalidating pointers. Thus 
it's not recommended
+ *  to store pointers to asset catalogs. Store the #CatalogID instead 
and do a lookup when
+ *  needed.
+ */
 class AssetCatalog {
  public:
   CatalogID catalog_id;
diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 47a45b7056f..1a558c4e322 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -113,6 +113,10 @@ Vector 
all_valid_asset_library_refs();
 
 }  // namespace blender::asset_system
 
+/**
+ * \warning Catalogs are reloaded, invalidating catalog pointers. Do not store 
catalog pointers,
+ *  store CatalogIDs instead and lookup the catalog where needed.
+ */
 blender::asset_system::AssetLibrary *AS_asset_library_load(
 const Main *bmain, const AssetLibraryReference _reference);
 
diff --git a/source/blender/editors/asset/ED_asset_list.h 
b/source/blender/editors/asset/ED_asset_list.h
index 3d2aaa3bda1..bcd5dbca8d4 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -20,6 +20,9 @@ struct wmNotifier;
 /**
  * Invoke asset list reading, potentially in a parallel job. Won't wait until 
the job is done,
  * and may return earlier.
+ *
+ * \warning: Asset list reading involves an #AS_asset_library_load() call 
which may reload asset
+ *   library data like catalogs (invalidating pointers). Refer to its 
warning for details.
  */
 void ED_assetlist_storage_fetch(const struct AssetLibraryReference 
*library_reference,
 const struct bContext *C);
diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index 536ec6742e2..bb5f33f8cf0 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -51,7 +51,9 @@ struct LibraryAsset {
 
 struct LibraryCatalog {
   asset_system::AssetLibrary *library;
-  const asset_system::AssetCatalog *catalog;
+  /* Catalog pointers are not save to store. Use the catalog ID instead and 
lookup the catalog when
+   * needed. */
+  const asset_system::CatalogID catalog_id;
 };
 
 struct AssetItemTree {
@@ -91,7 +93,7 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
   const asset_system::CatalogID  = 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});
+  id_to_catalog_map.add(item.get_catalog_id(), LibraryCatalog{library, 
id});
 });
   }
 }
@@ -121,7 +123,9 @@ static AssetItemTree build_catalog_tree(const bCon

[Bf-blender-cvs] [0151d846e8b] master: Fix MSVC warnings from recent asset system changes

2022-11-18 Thread Julian Eisel
Commit: 0151d846e8b057f92d749de51ec53fcb8cb2890b
Author: Julian Eisel
Date:   Fri Nov 18 15:12:45 2022 +0100
Branches: master
https://developer.blender.org/rB0151d846e8b057f92d749de51ec53fcb8cb2890b

Fix MSVC warnings from recent asset system changes

* Mismatching class vs struct forward declaration (one forward
  declaration wasn't needed anymore)
* Unused member warning (`on_load_callback_store_`)

===

M   source/blender/asset_system/AS_asset_representation.hh
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/space_file/file_intern.h

===

diff --git a/source/blender/asset_system/AS_asset_representation.hh 
b/source/blender/asset_system/AS_asset_representation.hh
index b53d85119a6..853222c8dc7 100644
--- a/source/blender/asset_system/AS_asset_representation.hh
+++ b/source/blender/asset_system/AS_asset_representation.hh
@@ -36,7 +36,6 @@ class AssetRepresentation {
 ID *local_asset_id_ = nullptr; /* Non-owning. */
   };
 
-  friend struct AssetLibrary;
   friend class AssetStorage;
 
  public:
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 44c7f27af80..9bd2eecd468 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -146,19 +146,18 @@ void AssetLibraryService::allocate_service_instance()
   }
 }
 
-#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
 static void on_blendfile_load(struct Main * /*bMain*/,
   struct PointerRNA ** /*pointers*/,
   const int /*num_pointers*/,
   void * /*arg*/)
 {
+#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
   AssetLibraryService::destroy();
-}
 #endif
+}
 
 void AssetLibraryService::app_handler_register()
 {
-#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
   /* The callback system doesn't own `on_load_callback_store_`. */
   on_load_callback_store_.alloc = false;
 
@@ -166,16 +165,13 @@ void AssetLibraryService::app_handler_register()
   on_load_callback_store_.arg = this;
 
   BKE_callback_add(_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
-#endif
 }
 
 void AssetLibraryService::app_handler_unregister()
 {
-#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
   BKE_callback_remove(_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
   on_load_callback_store_.func = nullptr;
   on_load_callback_store_.arg = nullptr;
-#endif
 }
 
 bool AssetLibraryService::has_any_unsaved_catalogs() const
diff --git a/source/blender/editors/space_file/file_intern.h 
b/source/blender/editors/space_file/file_intern.h
index f4577b960d3..ec9c8be42e3 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -226,7 +226,7 @@ void file_create_asset_catalog_tree_view_in_layout(struct 
AssetLibrary *asset_li
 #ifdef __cplusplus
 
 namespace blender::asset_system {
-struct AssetLibrary;
+class AssetLibrary;
 }
 
 FileAssetCatalogFilterSettingsHandle 
*file_create_asset_catalog_filter_settings(void);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [61d0f778109] master: Cleanup: Better follow class layout style guide in asset headers

2022-11-18 Thread Julian Eisel
Commit: 61d0f778109c95fecd8883fd43059d27357a0dd6
Author: Julian Eisel
Date:   Fri Nov 18 12:34:47 2022 +0100
Branches: master
https://developer.blender.org/rB61d0f778109c95fecd8883fd43059d27357a0dd6

Cleanup: Better follow class layout style guide in asset headers

Move "using" declarations and member variables to the top of the class.
See https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Class_Layout.

Changes access specifiers of some variables from public/protected to
private, there was no point in not having them private.

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/AS_asset_catalog_path.hh
M   source/blender/asset_system/AS_asset_catalog_tree.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/AS_asset_representation.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.hh

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 5cf7c0e3188..d11717736af 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -38,6 +38,13 @@ using OwningAssetCatalogMap = Map>;
 /* Manages the asset catalogs of a single asset library (i.e. of catalogs 
defined in a single
  * directory hierarchy). */
 class AssetCatalogService {
+  std::unique_ptr catalog_collection_;
+  std::unique_ptr catalog_tree_;
+  CatalogFilePath asset_library_root_;
+
+  Vector> undo_snapshots_;
+  Vector> redo_snapshots_;
+
  public:
   static const CatalogFilePath DEFAULT_CATALOG_FILENAME;
 
@@ -164,13 +171,6 @@ class AssetCatalogService {
   bool is_redo_possbile() const;
 
  protected:
-  std::unique_ptr catalog_collection_;
-  std::unique_ptr catalog_tree_;
-  CatalogFilePath asset_library_root_;
-
-  Vector> undo_snapshots_;
-  Vector> redo_snapshots_;
-
   void load_directory_recursive(const CatalogFilePath _path);
   void load_single_file(const CatalogFilePath _definition_file_path);
 
@@ -246,15 +246,6 @@ class AssetCatalogService {
  * struct.
  */
 class AssetCatalogCollection {
-  friend AssetCatalogService;
-
- public:
-  AssetCatalogCollection() = default;
-  AssetCatalogCollection(const AssetCatalogCollection ) = delete;
-  AssetCatalogCollection(AssetCatalogCollection &) noexcept = default;
-
-  std::unique_ptr deep_copy() const;
-
  protected:
   /** All catalogs known, except the known-but-deleted ones. */
   OwningAssetCatalogMap catalogs_;
@@ -271,6 +262,16 @@ class AssetCatalogCollection {
   /** Whether any of the catalogs have unsaved changes. */
   bool has_unsaved_changes_ = false;
 
+  friend AssetCatalogService;
+
+ public:
+  AssetCatalogCollection() = default;
+  AssetCatalogCollection(const AssetCatalogCollection ) = delete;
+  AssetCatalogCollection(AssetCatalogCollection &) noexcept = default;
+
+  std::unique_ptr deep_copy() const;
+
+ protected:
   static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap 
);
 };
 
@@ -278,6 +279,11 @@ class AssetCatalogCollection {
  * Only contains non-owning pointers to the #AssetCatalog instances, so ensure 
the lifetime of this
  * class is shorter than that of the #`AssetCatalog`s themselves. */
 class AssetCatalogDefinitionFile {
+ protected:
+  /* Catalogs stored in this file. They are mapped by ID to make it possible 
to query whether a
+   * catalog is already known, without having to find the corresponding 
`AssetCatalog*`. */
+  Map catalogs_;
+
  public:
   /* For now this is the only version of the catalog definition files that is 
supported.
* Later versioning code may be added to handle older files. */
@@ -290,6 +296,7 @@ class AssetCatalogDefinitionFile {
 
   CatalogFilePath file_path;
 
+ public:
   AssetCatalogDefinitionFile() = default;
 
   /**
@@ -323,10 +330,6 @@ class AssetCatalogDefinitionFile {
   const OwningAssetCatalogMap , const OwningAssetCatalogMap 
_catalogs) const;
 
  protected:
-  /* Catalogs stored in this file. They are mapped by ID to make it possible 
to query whether a
-   * catalog is already known, without having to find the corresponding 
`AssetCatalog*`. */
-  Map catalogs_;
-
   bool parse_version_line(StringRef line);
   std::unique_ptr parse_catalog_line(StringRef line);
 
@@ -342,9 +345,6 @@ class AssetCatalogDefinitionFile {
  * catalog hierarchy. */
 class AssetCatalog {
  public:
-  AssetCatalog() = default;
-  AssetCatalog(CatalogID catalog_id, const AssetCatalogPath , const 
std::string _name);
-
   CatalogID catalog_id;
   AssetCatalogPath path;
   /**
@@ -376,6 +376,10 @@ class AssetCatalog {
 bool has_unsaved_changes = false;
   } flags;
 
+ public:
+  AssetCatalog() = default;
+  AssetCatalog(CatalogID catalog_id, const AssetCatal

[Bf-blender-cvs] [754f6749773] master: Cleanup: Missing trailing underscore in private asset system member vars

2022-11-18 Thread Julian Eisel
Commit: 754f67497731ee760852348ce0d3779ca8ae2d05
Author: Julian Eisel
Date:   Fri Nov 18 12:43:33 2022 +0100
Branches: master
https://developer.blender.org/rB754f67497731ee760852348ce0d3779ca8ae2d05

Cleanup: Missing trailing underscore in private asset system member vars

See style guide:
https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Class_data_member_names

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/intern/asset_catalog.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index d11717736af..6c4fdeedaad 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -424,8 +424,8 @@ using MutableAssetCatalogOrderedSet = std::set matching_catalog_ids;
-  const Set known_catalog_ids;
+  const Set matching_catalog_ids_;
+  const Set known_catalog_ids_;
 
   friend AssetCatalogService;
 
diff --git a/source/blender/asset_system/intern/asset_catalog.cc 
b/source/blender/asset_system/intern/asset_catalog.cc
index 67663503213..9b47aca1209 100644
--- a/source/blender/asset_system/intern/asset_catalog.cc
+++ b/source/blender/asset_system/intern/asset_catalog.cc
@@ -960,14 +960,14 @@ std::string 
AssetCatalog::sensible_simple_name_for_path(const AssetCatalogPath &
 
 AssetCatalogFilter::AssetCatalogFilter(Set &_catalog_ids,
Set &_catalog_ids)
-: matching_catalog_ids(std::move(matching_catalog_ids)),
-  known_catalog_ids(std::move(known_catalog_ids))
+: matching_catalog_ids_(std::move(matching_catalog_ids)),
+  known_catalog_ids_(std::move(known_catalog_ids))
 {
 }
 
 bool AssetCatalogFilter::contains(const CatalogID asset_catalog_id) const
 {
-  return matching_catalog_ids.contains(asset_catalog_id);
+  return matching_catalog_ids_.contains(asset_catalog_id);
 }
 
 bool AssetCatalogFilter::is_known(const CatalogID asset_catalog_id) const
@@ -975,7 +975,7 @@ bool AssetCatalogFilter::is_known(const CatalogID 
asset_catalog_id) const
   if (BLI_uuid_is_nil(asset_catalog_id)) {
 return false;
   }
-  return known_catalog_ids.contains(asset_catalog_id);
+  return known_catalog_ids_.contains(asset_catalog_id);
 }
 
 }  // namespace blender::asset_system

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d5c8d3e6618] master: Cleanup: Avoid unnecessary/annoying type alias in asset system

2022-11-18 Thread Julian Eisel
Commit: d5c8d3e6618e249baf0307069c8a7292705a503c
Author: Julian Eisel
Date:   Fri Nov 18 12:37:27 2022 +0100
Branches: master
https://developer.blender.org/rBd5c8d3e6618e249baf0307069c8a7292705a503c

Cleanup: Avoid unnecessary/annoying type alias in asset system

A `using FooPtr = std::unique_ptr` isn't that useful usually, just
saves a few character stokes. It obfuscates the underlying type, which
is usually relevant information. Plus, `Ptr` for a unique pointer is
misleading (should be `UPtr` or similar).

===

M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/asset_system/intern/asset_library_service.hh

===

diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index 51d8e5fcee6..44c7f27af80 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -98,7 +98,8 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_on_disk(StringRefNull top_l
 
   std::string top_dir_trailing_slash = 
normalize_directory_path(top_level_directory);
 
-  AssetLibraryPtr *lib_uptr_ptr = 
on_disk_libraries_.lookup_ptr(top_dir_trailing_slash);
+  std::unique_ptr *lib_uptr_ptr = on_disk_libraries_.lookup_ptr(
+  top_dir_trailing_slash);
   if (lib_uptr_ptr != nullptr) {
 CLOG_INFO(, 2, "get \"%s\" (cached)", top_dir_trailing_slash.c_str());
 AssetLibrary *lib = lib_uptr_ptr->get();
@@ -106,7 +107,7 @@ AssetLibrary 
*AssetLibraryService::get_asset_library_on_disk(StringRefNull top_l
 return lib;
   }
 
-  AssetLibraryPtr lib_uptr = std::make_unique();
+  std::unique_ptr lib_uptr = std::make_unique();
   AssetLibrary *lib = lib_uptr.get();
 
   lib->on_blend_save_handler_register();
diff --git a/source/blender/asset_system/intern/asset_library_service.hh 
b/source/blender/asset_system/intern/asset_library_service.hh
index 85c08da1f0c..6045060e91e 100644
--- a/source/blender/asset_system/intern/asset_library_service.hh
+++ b/source/blender/asset_system/intern/asset_library_service.hh
@@ -31,16 +31,14 @@ namespace blender::asset_system {
  *   loaded from a file on disk).
  */
 class AssetLibraryService {
-  using AssetLibraryPtr = std::unique_ptr;
-
   static std::unique_ptr instance_;
 
   /* Mapping absolute path of the library's top-level directory to the 
AssetLibrary instance. */
-  Map on_disk_libraries_;
+  Map> on_disk_libraries_;
   /** Library without a known path, i.e. the "Current File" library if the 
file isn't saved yet. If
* the file was saved, a valid path for the library can be determined and 
#on_disk_libraries_
* above should be used. */
-  AssetLibraryPtr current_file_library_;
+  std::unique_ptr current_file_library_;
 
   /* Handlers for managing the life cycle of the AssetLibraryService instance. 
*/
   bCallbackFuncStore on_load_callback_store_;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7c0cecfd009] master: Asset system: Move catalog tree code to own files

2022-11-18 Thread Julian Eisel
Commit: 7c0cecfd00978e5d55dfcc30644d5963709e0e89
Author: Julian Eisel
Date:   Fri Nov 18 11:46:12 2022 +0100
Branches: master
https://developer.blender.org/rB7c0cecfd00978e5d55dfcc30644d5963709e0e89

Asset system: Move catalog tree code to own files

The catalog code is already quite complex, I rather keep the tree stuff
separate in a more focused unit.

===

M   source/blender/asset_system/AS_asset_catalog.hh
A   source/blender/asset_system/AS_asset_catalog_tree.hh
M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/intern/asset_catalog.cc
A   source/blender/asset_system/intern/asset_catalog_tree.cc
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/tests/asset_catalog_test.cc
M   source/blender/editors/space_file/asset_catalog_tree_view.cc
M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 8160676603d..71d53f25261 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -165,7 +165,7 @@ class AssetCatalogService {
 
  protected:
   std::unique_ptr catalog_collection_;
-  std::unique_ptr catalog_tree_ = 
std::make_unique();
+  std::unique_ptr catalog_tree_;
   CatalogFilePath asset_library_root_;
 
   Vector> undo_snapshots_;
@@ -274,88 +274,6 @@ class AssetCatalogCollection {
   static OwningAssetCatalogMap copy_catalog_map(const OwningAssetCatalogMap 
);
 };
 
-/**
- * Representation of a catalog path in the #AssetCatalogTree.
- */
-class AssetCatalogTreeItem {
-  friend class AssetCatalogTree;
-
- public:
-  /** Container for child items. Uses a #std::map to keep items ordered by 
their name (i.e. their
-   * last catalog component). */
-  using ChildMap = std::map;
-  using ItemIterFn = FunctionRef;
-
-  AssetCatalogTreeItem(StringRef name,
-   CatalogID catalog_id,
-   StringRef simple_name,
-   const AssetCatalogTreeItem *parent = nullptr);
-
-  CatalogID get_catalog_id() const;
-  StringRefNull get_simple_name() const;
-  StringRefNull get_name() const;
-  bool has_unsaved_changes() const;
-  /** Return the full catalog path, defined as the name of this catalog 
prefixed by the full
-   * catalog path of its parent and a separator. */
-  AssetCatalogPath catalog_path() const;
-  int count_parents() const;
-  bool has_children() const;
-
-  /** Iterate over children calling \a callback for each of them, but do not 
recurse into their
-   * children. */
-  void foreach_child(ItemIterFn callback);
-
- protected:
-  /** Child tree items, ordered by their names. */
-  ChildMap children_;
-  /** The user visible name of this component. */
-  CatalogPathComponent name_;
-  CatalogID catalog_id_;
-  /** Copy of #AssetCatalog::simple_name. */
-  std::string simple_name_;
-  /** Copy of #AssetCatalog::flags.has_unsaved_changes. */
-  bool has_unsaved_changes_ = false;
-
-  /** Pointer back to the parent item. Used to reconstruct the hierarchy from 
an item (e.g. to
-   * build a path). */
-  const AssetCatalogTreeItem *parent_ = nullptr;
-
- private:
-  static void foreach_item_recursive(ChildMap _, ItemIterFn callback);
-};
-
-/**
- * A representation of the catalog paths as tree structure. Each component of 
the catalog tree is
- * represented by an #AssetCatalogTreeItem. The last path component of an item 
is used as its name,
- * which may also be shown to the user.
- * An item can not have multiple children with the same name. That means the 
name uniquely
- * identifies an item within its parent.
- *
- * There is no single root tree element, the #AssetCatalogTree instance itself 
represents the root.
- */
-class AssetCatalogTree {
-  using ChildMap = AssetCatalogTreeItem::ChildMap;
-  using ItemIterFn = AssetCatalogTreeItem::ItemIterFn;
-
- public:
-  /** Ensure an item representing \a path is in the tree, adding it if 
necessary. */
-  void insert_item(const AssetCatalog );
-
-  void foreach_item(ItemIterFn callback);
-  /** Iterate over root items calling \a callback for each of them, but do not 
recurse into their
-   * children. */
-  void foreach_root_item(ItemIterFn callback);
-
-  bool is_empty() const;
-
-  AssetCatalogTreeItem *find_item(const AssetCatalogPath );
-  AssetCatalogTreeItem *find_root_item(const AssetCatalogPath );
-
- protected:
-  /** Child tree items, ordered by their names. */
-  ChildMap root_items_;
-};
-
 /** Keeps track of which catalogs are defined in a certain file on disk.
  * Only contains non-owning pointers to the #AssetCatalog instances, so ensure 
the lifetime of this
  * class is shorter than that of the #`AssetCatalog`s themselves. */
diff --git a/source/blender/asset_sys

[Bf-blender-cvs] [e31f282917e] master: Cleanup: Minor cleanups in asset system headers

2022-11-18 Thread Julian Eisel
Commit: e31f282917ed239abb56c1c3077c864139ada0de
Author: Julian Eisel
Date:   Fri Nov 18 12:07:00 2022 +0100
Branches: master
https://developer.blender.org/rBe31f282917ed239abb56c1c3077c864139ada0de

Cleanup: Minor cleanups in asset system headers

- Move main comment on class to header comment where it's more visible.
- Improve comment.
- Move stdlib includes first, like we do it usually
- Separate includes my code module
- Remove unnecessary forward declarations

===

M   source/blender/asset_system/AS_asset_catalog.hh
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/AS_asset_representation.hh

===

diff --git a/source/blender/asset_system/AS_asset_catalog.hh 
b/source/blender/asset_system/AS_asset_catalog.hh
index 71d53f25261..5cf7c0e3188 100644
--- a/source/blender/asset_system/AS_asset_catalog.hh
+++ b/source/blender/asset_system/AS_asset_catalog.hh
@@ -6,6 +6,11 @@
 
 #pragma once
 
+#include 
+#include 
+#include 
+#include 
+
 #include "BLI_function_ref.hh"
 #include "BLI_map.hh"
 #include "BLI_set.hh"
@@ -15,11 +20,6 @@
 
 #include "AS_asset_catalog_path.hh"
 
-#include 
-#include 
-#include 
-#include 
-
 namespace blender::asset_system {
 
 class AssetCatalog;
diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 4bd5ee3446d..97db15dd640 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -6,20 +6,19 @@
 
 #pragma once
 
+#include 
+
+#include "AS_asset_catalog.hh"
+
 #include "DNA_asset_types.h"
 
 #include "BLI_set.hh"
 #include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
 
-#include "AS_asset_catalog.hh"
 #include "BKE_callbacks.h"
 
-#include 
-
 struct AssetLibrary;
-struct AssetLibraryReference;
-struct AssetMetaData;
 struct IDRemapper;
 struct Main;
 
diff --git a/source/blender/asset_system/AS_asset_representation.hh 
b/source/blender/asset_system/AS_asset_representation.hh
index 15e10d6c98f..6a4a41f08f3 100644
--- a/source/blender/asset_system/AS_asset_representation.hh
+++ b/source/blender/asset_system/AS_asset_representation.hh
@@ -2,6 +2,11 @@
 
 /** \file
  * \ingroup asset_system
+ *
+ * \brief Main runtime representation of an asset.
+ *
+ * Abstraction to reference an asset, with necessary data for display & 
interaction.
+ * 
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation
  */
 
 #pragma once
@@ -16,11 +21,6 @@ struct ID;
 
 namespace blender::asset_system {
 
-/**
- * \brief Abstraction to reference an asset, with necessary data for display & 
interaction.
- *
- * 
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation
- */
 class AssetRepresentation {
   friend struct AssetLibrary;
   friend class AssetStorage;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6bf13d07341] master: Fix crash when loading different file with asset browser open

2022-11-17 Thread Julian Eisel
Commit: 6bf13d07341b15e2f2a302e306da6303cb6c0b39
Author: Julian Eisel
Date:   Thu Nov 17 15:50:08 2022 +0100
Branches: master
https://developer.blender.org/rB6bf13d07341b15e2f2a302e306da6303cb6c0b39

Fix crash when loading different file with asset browser open

Steps to reproduce were:
- Open an asset browser
- Open an asset library with assets in it
- Load a different file (e.g. File -> New -> General)

Didn't see a nice way to fix this with the current pre file load handler
callback we use for freeing asset libraries. Using this is cleaner, but
for now, the relationship between UI and asset system is too close
still, so better do explicit freeing at the right point in time.

===

M   source/blender/asset_system/AS_asset_library.h
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/windowmanager/intern/wm_files.c

===

diff --git a/source/blender/asset_system/AS_asset_library.h 
b/source/blender/asset_system/AS_asset_library.h
index 83ee8cebcdf..0a67df2ecbf 100644
--- a/source/blender/asset_system/AS_asset_library.h
+++ b/source/blender/asset_system/AS_asset_library.h
@@ -16,6 +16,14 @@ extern "C" {
 /** Forward declaration, defined in intern/asset_library.hh */
 typedef struct AssetLibrary AssetLibrary;
 
+/**
+ * Force clearing of all asset library data. After calling this, new asset 
libraries can be loaded
+ * just as usual using #AS_asset_library_load(), no init or other setup is 
needed.
+ *
+ * Does not need to be called on exit, this is handled internally.
+ */
+void AS_asset_libraries_exit(void);
+
 /**
  * Return the #AssetLibrary rooted at the given directory path.
  *
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 90d83d369d6..5beab18cba6 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -27,6 +27,12 @@ using namespace blender::asset_system;
 
 bool asset_system::AssetLibrary::save_catalogs_when_file_is_saved = true;
 
+/* Can probably removed once #WITH_DESTROY_VIA_LOAD_HANDLER gets enabled by 
default. */
+void AS_asset_libraries_exit()
+{
+  AssetLibraryService::destroy();
+}
+
 asset_system::AssetLibrary *AS_asset_library_load(const Main *bmain,
   const AssetLibraryReference 
_reference)
 {
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index e46557e1b29..51d8e5fcee6 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -19,6 +19,17 @@
 
 #include "CLG_log.h"
 
+/* When enabled, use a pre file load handler (#BKE_CB_EVT_LOAD_PRE) callback 
to destroy the asset
+ * library service. Without this an explicit call from the file loading code 
is needed to do this,
+ * which is not as nice.
+ *
+ * TODO Currently disabled because UI data depends on asset library data, so 
we have to make sure
+ * it's freed in the right order (UI first). Pre-load handlers don't give us 
this order.
+ * Should be addressed with a proper ownership model for the asset system:
+ * 
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Ownership_Model
+ */
+//#define WITH_DESTROY_VIA_LOAD_HANDLER
+
 static CLG_LogRef LOG = {"asset_system.asset_library_service"};
 
 namespace blender::asset_system {
@@ -134,6 +145,7 @@ void AssetLibraryService::allocate_service_instance()
   }
 }
 
+#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
 static void on_blendfile_load(struct Main * /*bMain*/,
   struct PointerRNA ** /*pointers*/,
   const int /*num_pointers*/,
@@ -141,9 +153,11 @@ static void on_blendfile_load(struct Main * /*bMain*/,
 {
   AssetLibraryService::destroy();
 }
+#endif
 
 void AssetLibraryService::app_handler_register()
 {
+#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
   /* The callback system doesn't own `on_load_callback_store_`. */
   on_load_callback_store_.alloc = false;
 
@@ -151,13 +165,16 @@ void AssetLibraryService::app_handler_register()
   on_load_callback_store_.arg = this;
 
   BKE_callback_add(_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
+#endif
 }
 
 void AssetLibraryService::app_handler_unregister()
 {
+#ifdef WITH_DESTROY_VIA_LOAD_HANDLER
   BKE_callback_remove(_load_callback_store_, BKE_CB_EVT_LOAD_PRE);
   on_load_callback_store_.func = nullptr;
   on_load_callback_store_.arg = nullptr;
+#endif
 }
 
 bool AssetLibraryService::has_any_unsaved_catalogs() const
diff --git a/source/blender/windowmanager/intern/wm_files.c 
b/source/blender/windowmanager/intern/wm_files.c
index cfeaedaa2b1..dd3f6db6297 10064

[Bf-blender-cvs] [59f8061a346] master: Assets: Refactor asset representation storage

2022-11-17 Thread Julian Eisel
Commit: 59f8061a346cdea268307c3d4b07024b4db35d02
Author: Julian Eisel
Date:   Wed Nov 16 15:43:43 2022 +0100
Branches: master
https://developer.blender.org/rB59f8061a346cdea268307c3d4b07024b4db35d02

Assets: Refactor asset representation storage

- Move code to manage storage to own class in own file, separates
  concerns and different levels of abstraction better.
- Store local ID assets separately in the storage class for more
  efficient lookups (e.g. for ID remapping).
- Make API function names and comments more complete.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/AS_asset_representation.hh
M   source/blender/asset_system/CMakeLists.txt
M   source/blender/asset_system/intern/asset_library.cc
A   source/blender/asset_system/intern/asset_storage.cc
A   source/blender/asset_system/intern/asset_storage.hh

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index c4d9706a9c1..4bd5ee3446d 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -20,11 +20,13 @@
 struct AssetLibrary;
 struct AssetLibraryReference;
 struct AssetMetaData;
+struct IDRemapper;
 struct Main;
 
 namespace blender::asset_system {
 
 class AssetRepresentation;
+class AssetStorage;
 
 /**
  * AssetLibrary provides access to an asset library's data.
@@ -54,12 +56,24 @@ struct AssetLibrary {
* loading a different file).
*/
   AssetRepresentation _external_asset(StringRef name, 
std::unique_ptr metadata);
+  /** See #AssetLibrary::add_external_asset(). */
   AssetRepresentation _local_id_asset(ID );
   /** Remove an asset from the library that was added using 
#add_external_asset() or
-   * #add_local_id_asset().
-   * \return True on success, false if the asset couldn't be found inside the 
library. */
+   * #add_local_id_asset(). Can usually be expected to be constant time 
complexity (worst case may
+   * differ).
+   * \note This is save to call if \a asset is freed (dangling reference), 
will not perform any
+   *   change then.
+   * \return True on success, false if the asset couldn't be found inside the 
library (also the
+   * case when the reference is dangling). */
   bool remove_asset(AssetRepresentation );
 
+  /**
+   * Remap ID pointers for local ID assets, see #BKE_lib_remap.h. When an ID 
pointer would be
+   * mapped to null (typically when an ID gets removed), the asset is removed, 
because we don't
+   * support such empty/null assets.
+   */
+  void remap_ids_and_remove_invalid(const IDRemapper );
+
   /**
* Update `catalog_simple_name` by looking up the asset's catalog by its ID.
*
@@ -73,8 +87,6 @@ struct AssetLibrary {
 
   void on_blend_save_post(Main *bmain, PointerRNA **pointers, int 
num_pointers);
 
-  void remap_ids(const struct IDRemapper );
-
  private:
   bCallbackFuncStore on_save_callback_store_{};
 
@@ -91,7 +103,7 @@ struct AssetLibrary {
* already in memory and which not. Neither do we keep track of how many 
parts of Blender are
* using an asset or an asset library, which is needed to know when assets 
can be freed.
*/
-  Set> asset_storage_;
+  std::unique_ptr asset_storage_;
 
   std::optional find_asset_index(const AssetRepresentation );
 };
diff --git a/source/blender/asset_system/AS_asset_representation.hh 
b/source/blender/asset_system/AS_asset_representation.hh
index 66c49c445dc..15e10d6c98f 100644
--- a/source/blender/asset_system/AS_asset_representation.hh
+++ b/source/blender/asset_system/AS_asset_representation.hh
@@ -23,6 +23,7 @@ namespace blender::asset_system {
  */
 class AssetRepresentation {
   friend struct AssetLibrary;
+  friend class AssetStorage;
 
   struct ExternalAsset {
 std::string name;
diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index 8bf7a135155..05f03c2bfc5 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -19,12 +19,14 @@ set(SRC
   intern/asset_library.cc
   intern/asset_library_service.cc
   intern/asset_representation.cc
+  intern/asset_storage.cc
 
   AS_asset_catalog.hh
   AS_asset_catalog_path.hh
   AS_asset_library.hh
   AS_asset_representation.hh
   intern/asset_library_service.hh
+  intern/asset_storage.hh
 
   AS_asset_library.h
   AS_asset_representation.h
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index a7add445c99..90d83d369d6 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -10,7 +10,6 @@
 #include "AS_asset_library.hh"
 #include "AS_asset_representation.hh"
 
-#include "BKE_lib_remap.h"

[Bf-blender-cvs] [67869432f2e] master: Asset system: Remap local asset ID pointers as part of UI remapping

2022-11-17 Thread Julian Eisel
Commit: 67869432f2ea659e2c7ca4f244ecec6eb750fe27
Author: Julian Eisel
Date:   Tue Nov 15 18:26:46 2022 +0100
Branches: master
https://developer.blender.org/rB67869432f2ea659e2c7ca4f244ecec6eb750fe27

Asset system: Remap local asset ID pointers as part of UI remapping

After checking with @mont29, this is much prefered over calling this in
BKE directly.

===

M   source/blender/asset_system/AS_asset_library.h
M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/blenkernel/intern/lib_id_delete.c
M   source/blender/windowmanager/intern/wm_event_system.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.h 
b/source/blender/asset_system/AS_asset_library.h
index 8c5c4633c4e..83ee8cebcdf 100644
--- a/source/blender/asset_system/AS_asset_library.h
+++ b/source/blender/asset_system/AS_asset_library.h
@@ -34,7 +34,7 @@ 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 AS_asset_library_remap_ids(struct IDRemapper *mappings);
+void AS_asset_library_remap_ids(const struct IDRemapper *mappings);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 8bc9927c198..c4d9706a9c1 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -73,7 +73,7 @@ struct AssetLibrary {
 
   void on_blend_save_post(Main *bmain, PointerRNA **pointers, int 
num_pointers);
 
-  void remap_ids(struct IDRemapper );
+  void remap_ids(const struct IDRemapper );
 
  private:
   bCallbackFuncStore on_save_callback_store_{};
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 74b39fa7b0f..a7add445c99 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -104,7 +104,7 @@ void AS_asset_library_refresh_catalog_simplename(struct 
::AssetLibrary *asset_li
   lib->refresh_catalog_simplename(asset_data);
 }
 
-void AS_asset_library_remap_ids(IDRemapper *mappings)
+void AS_asset_library_remap_ids(const IDRemapper *mappings)
 {
   AssetLibraryService *service = AssetLibraryService::get();
   service->foreach_loaded_asset_library(
@@ -203,7 +203,7 @@ void AssetLibrary::on_blend_save_post(struct Main *main,
   }
 }
 
-void AssetLibrary::remap_ids(IDRemapper )
+void AssetLibrary::remap_ids(const IDRemapper )
 {
   Set removed_id_assets;
 
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c 
b/source/blender/blenkernel/intern/lib_id_delete.c
index 45787a5e3a0..c7643c56212 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -19,8 +19,6 @@
 #include "BLI_linklist.h"
 #include "BLI_listbase.h"
 
-#include "AS_asset_library.h"
-
 #include "BKE_anim_data.h"
 #include "BKE_asset.h"
 #include "BKE_idprop.h"
@@ -139,16 +137,16 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, 
const bool use_flag_from_i
 BKE_main_lock(bmain);
   }
 
-  struct IDRemapper *remapper = BKE_id_remapper_create();
-  BKE_id_remapper_add(remapper, id, NULL);
-
   if ((flag & LIB_ID_FREE_NO_UI_USER) == 0) {
 if (free_notifier_reference_cb) {
   free_notifier_reference_cb(id);
 }
 
 if (remap_editor_id_reference_cb) {
+  struct IDRemapper *remapper = BKE_id_remapper_create();
+  BKE_id_remapper_add(remapper, id, NULL);
   remap_editor_id_reference_cb(remapper);
+  BKE_id_remapper_free(remapper);
 }
   }
 
@@ -160,9 +158,6 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const 
bool use_flag_from_i
 }
   }
 
-  AS_asset_library_remap_ids(remapper);
-  BKE_id_remapper_free(remapper);
-
   BKE_libblock_free_data(id, (flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0);
 
   if ((flag & LIB_ID_FREE_NO_MAIN) == 0) {
diff --git a/source/blender/windowmanager/intern/wm_event_system.cc 
b/source/blender/windowmanager/intern/wm_event_system.cc
index 48806754433..90f162ac76a 100644
--- a/source/blender/windowmanager/intern/wm_event_system.cc
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+#include "AS_asset_library.h"
+
 #include "DNA_listBase.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -393,6 +395,8 @@ void WM_main_remap_editor_id_reference(const IDRemapper 
*mappings)
   if (wm && wm->message_bus) {
 BKE_id_remapper_iter(mappings, wm_main_remap_msgbu

[Bf-blender-cvs] [50b257715f8] master: Assets: Avoid quadratic complexity when freeing asset libraries

2022-11-15 Thread Julian Eisel
Commit: 50b257715f8733233dacd92476b3cbdf65ce2dad
Author: Julian Eisel
Date:   Tue Nov 15 17:34:06 2022 +0100
Branches: master
https://developer.blender.org/rB50b257715f8733233dacd92476b3cbdf65ce2dad

Assets: Avoid quadratic complexity when freeing asset libraries

Using a vector to store assets means we have to lookup the position of
the asset to be able to remove/free it. Use a `blender::Set` instead for
(nearly?) constant time removal.

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index a0f1214ad39..8bc9927c198 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -8,6 +8,7 @@
 
 #include "DNA_asset_types.h"
 
+#include "BLI_set.hh"
 #include "BLI_string_ref.hh"
 #include "BLI_vector.hh"
 
@@ -90,7 +91,7 @@ struct AssetLibrary {
* already in memory and which not. Neither do we keep track of how many 
parts of Blender are
* using an asset or an asset library, which is needed to know when assets 
can be freed.
*/
-  Vector> asset_storage_;
+  Set> asset_storage_;
 
   std::optional find_asset_index(const AssetRepresentation );
 };
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index b52594fa20c..74b39fa7b0f 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -139,39 +139,25 @@ void AssetLibrary::refresh()
 AssetRepresentation ::add_external_asset(StringRef name,
   
std::unique_ptr metadata)
 {
-  asset_storage_.append(std::make_unique(name, 
std::move(metadata)));
-  return *asset_storage_.last();
+  return *asset_storage_.lookup_key_or_add(
+  std::make_unique(name, std::move(metadata)));
 }
 
 AssetRepresentation ::add_local_id_asset(ID )
 {
-  asset_storage_.append(std::make_unique(id));
-  return *asset_storage_.last();
-}
-
-std::optional AssetLibrary::find_asset_index(const AssetRepresentation 
)
-{
-  int index = 0;
-  /* Find index of asset. */
-  for (auto _uptr : asset_storage_) {
-if ( == asset_uptr.get()) {
-  return index;
-}
-index++;
-  }
-
-  return {};
+  return 
*asset_storage_.lookup_key_or_add(std::make_unique(id));
 }
 
 bool AssetLibrary::remove_asset(AssetRepresentation )
 {
-  std::optional asset_index = find_asset_index(asset);
-  if (!asset_index) {
-return false;
-  }
-
-  asset_storage_.remove_and_reorder(*asset_index);
-  return true;
+  /* Create a "fake" unique_ptr to figure out the hash for the pointed to 
asset representation. The
+   * standard requires that this is the same for all unique_ptr's wrapping the 
same address. */
+  std::unique_ptr fake_asset_ptr{};
+
+  const bool was_removed = asset_storage_.remove_as(fake_asset_ptr);
+  /* Make sure the contained storage is not destructed. */
+  fake_asset_ptr.release();
+  return was_removed;
 }
 
 namespace {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4fb02d7f8e9] master: Fix T102482: Crash loading geometry nodes assets after file load

2022-11-15 Thread Julian Eisel
Commit: 4fb02d7f8e90e195f9b559035639d983d688c2d7
Author: Julian Eisel
Date:   Tue Nov 15 16:15:57 2022 +0100
Branches: master
https://developer.blender.org/rB4fb02d7f8e90e195f9b559035639d983d688c2d7

Fix T102482: Crash loading geometry nodes assets after file load

Asset library data is destructed on file load. Asset lists (weak and
hopefully temporary design) contain pointers into it that would dangle
then. Make sure the asset lists are destructed before the asset library
data.

===

M   source/blender/windowmanager/intern/wm_files.c

===

diff --git a/source/blender/windowmanager/intern/wm_files.c 
b/source/blender/windowmanager/intern/wm_files.c
index bdac91e990c..cfeaedaa2b1 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -606,6 +606,12 @@ void wm_file_read_report(bContext *C, Main *bmain)
 static void wm_file_read_pre(bContext *C, bool use_data, bool 
UNUSED(use_userdef))
 {
   if (use_data) {
+/* XXX Do before executing the callbacks below, otherwise the asset list 
refers to storage in
+ * the asset library that's destructed through a callback below.
+ * Asset list is weak design and mixes asset representation lifetime 
management with UI
+ * lifetime. The asset system needs a better defined ownership model. */
+ED_assetlist_storage_exit();
+
 BKE_callback_exec_null(CTX_data_main(C), BKE_CB_EVT_LOAD_PRE);
 BLI_timer_on_file_load();
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea2dda306c7] master: Asset system: New asset system code module (with files from BKE)

2022-11-14 Thread Julian Eisel
Commit: ea2dda306c7d017618042a1b311caaae202ab1ca
Author: Julian Eisel
Date:   Mon Nov 14 12:41:55 2022 +0100
Branches: master
https://developer.blender.org/rBea2dda306c7d017618042a1b311caaae202ab1ca

Asset system: New asset system code module (with files from BKE)

Adds a new `source/blender/asset_system` directory and moves asset
related files from BKE to it. More asset related code can follow
(e.g. asset indexing, ED_assetlist stuff) but needs further work to
untangle it. I also kept `BKE_asset.h` and `asset.cc` as is, since they
deal with asset DNA data mostly, thus make sense in BKE.

Motivation:
- Makes the asset system design more present (term wasn't even used in
  code before).
- An `asset_system` directory is quite descriptive (trivial to identify
  core asset system features) and makes it easy to find asset code.
- Asset system is mostly runtime data, with little relation to other
  `Main`/BKE/DNA types.
- There's a lot of stuff in BKE already. It shouldn't be just a dump for
  all stuff that seems core enough.
- Being its own directly helps us be more mindful about encapsulating
  the module well, and avoiding dependencies on other modules.
- We can be more free with splitting files here than in BKE.
- In future there might be an asset system BPY module, which would then
  map quite nicely to the `asset_system` directory.

Checked with some other core devs, consensus seems that this makes
sense.

===

M   source/blender/CMakeLists.txt
R098source/blender/blenkernel/BKE_asset_catalog.hh  
source/blender/asset_system/AS_asset_catalog.hh
R097source/blender/blenkernel/BKE_asset_catalog_path.hh 
source/blender/asset_system/AS_asset_catalog_path.hh
R069source/blender/blenkernel/BKE_asset_library.h   
source/blender/asset_system/AS_asset_library.h
R085source/blender/blenkernel/BKE_asset_library.hh  
source/blender/asset_system/AS_asset_library.hh
A   source/blender/asset_system/AS_asset_representation.h
R095source/blender/blenkernel/BKE_asset_representation.hh   
source/blender/asset_system/AS_asset_representation.hh
A   source/blender/asset_system/CMakeLists.txt
R099source/blender/blenkernel/intern/asset_catalog.cc   
source/blender/asset_system/intern/asset_catalog.cc
R097source/blender/blenkernel/intern/asset_catalog_path.cc  
source/blender/asset_system/intern/asset_catalog_path.cc
R075source/blender/blenkernel/intern/asset_library.cc   
source/blender/asset_system/intern/asset_library.cc
R094source/blender/blenkernel/intern/asset_library_service.cc   
source/blender/asset_system/intern/asset_library_service.cc
R094source/blender/blenkernel/intern/asset_library_service.hh   
source/blender/asset_system/intern/asset_library_service.hh
R065source/blender/blenkernel/intern/asset_representation.cc
source/blender/asset_system/intern/asset_representation.cc
R098source/blender/blenkernel/intern/asset_catalog_path_test.cc 
source/blender/asset_system/tests/asset_catalog_path_test.cc
R099source/blender/blenkernel/intern/asset_catalog_test.cc  
source/blender/asset_system/tests/asset_catalog_test.cc
R098source/blender/blenkernel/intern/asset_library_service_test.cc  
source/blender/asset_system/tests/asset_library_service_test.cc
R078source/blender/blenkernel/intern/asset_library_test.cc  
source/blender/asset_system/tests/asset_library_test.cc
M   source/blender/blenkernel/BKE_asset.h
M   source/blender/blenkernel/CMakeLists.txt
R100source/blender/blenkernel/intern/asset_test.cc  
source/blender/blenkernel/intern/asset_metadata_test.cc
M   source/blender/blenkernel/intern/lib_id_delete.c
M   source/blender/editors/asset/CMakeLists.txt
M   source/blender/editors/asset/ED_asset_catalog.hh
M   source/blender/editors/asset/intern/asset_catalog.cc
M   source/blender/editors/asset/intern/asset_handle.cc
M   source/blender/editors/asset/intern/asset_indexer.cc
M   source/blender/editors/asset/intern/asset_ops.cc
M   source/blender/editors/interface/CMakeLists.txt
M   source/blender/editors/space_file/CMakeLists.txt
M   source/blender/editors/space_file/asset_catalog_tree_view.cc
M   source/blender/editors/space_file/file_intern.h
M   source/blender/editors/space_file/filelist.cc
M   source/blender/editors/space_node/CMakeLists.txt
M   source/blender/editors/space_node/add_menu_assets.cc
M   source/blender/editors/space_node/add_node_search.cc
M   source/blender/editors/util/CMakeLists.txt
M   source/blender/makesrna/intern/CMakeLists.txt
M   source/blender/makesrna/intern/rna_asset.c
M   source/blender/makesrna/intern/rna_space.c
M   source/blender/windowmanager/CMakeLists.txt
M   source/blender/windowmanager/intern/wm_files.c

===

diff --git a/source/blender/CMakeLists.txt b/source/blender

[Bf-blender-cvs] [7246c387435] asset-browser-grid-view: Merge branch 'master' into asset-browser-grid-view

2022-11-10 Thread Julian Eisel
Commit: 7246c387435769a169ac24c91434c615df6434b4
Author: Julian Eisel
Date:   Thu Nov 10 13:17:42 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rB7246c387435769a169ac24c91434c615df6434b4

Merge branch 'master' into asset-browser-grid-view

===



===

diff --cc source/blender/blenkernel/intern/screen.c
index c8bdf91b45e,2c896788b20..ab7a1bcaa35
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@@ -1208,151 -1152,10 +1152,14 @@@ static void write_area(BlendWriter *wri
write_region(writer, region, sl->spacetype);
  }
  
- if (sl->spacetype == SPACE_VIEW3D) {
-   View3D *v3d = (View3D *)sl;
-   BLO_write_struct(writer, View3D, v3d);
- 
-   if (v3d->localvd) {
- BLO_write_struct(writer, View3D, v3d->localvd);
-   }
- 
-   BKE_screen_view3d_shading_blend_write(writer, >shading);
- }
- else if (sl->spacetype == SPACE_GRAPH) {
-   SpaceGraph *sipo = (SpaceGraph *)sl;
-   ListBase tmpGhosts = sipo->runtime.ghost_curves;
- 
-   /* temporarily disable ghost curves when saving */
-   BLI_listbase_clear(>runtime.ghost_curves);
- 
-   BLO_write_struct(writer, SpaceGraph, sl);
-   if (sipo->ads) {
- BLO_write_struct(writer, bDopeSheet, sipo->ads);
-   }
- 
-   /* reenable ghost curves */
-   sipo->runtime.ghost_curves = tmpGhosts;
- }
- else if (sl->spacetype == SPACE_PROPERTIES) {
-   BLO_write_struct(writer, SpaceProperties, sl);
- }
- else if (sl->spacetype == SPACE_FILE) {
-   SpaceFile *sfile = (SpaceFile *)sl;
- 
-   BLO_write_struct(writer, SpaceFile, sl);
-   if (sfile->params) {
- BLO_write_struct(writer, FileSelectParams, sfile->params);
-   }
-   if (sfile->asset_params) {
- BLO_write_struct(writer, FileAssetSelectParams, sfile->asset_params);
-   }
- }
- else if (sl->spacetype == SPACE_SEQ) {
-   BLO_write_struct(writer, SpaceSeq, sl);
- }
- else if (sl->spacetype == SPACE_OUTLINER) {
-   SpaceOutliner *space_outliner = (SpaceOutliner *)sl;
-   write_space_outliner(writer, space_outliner);
- }
- else if (sl->spacetype == SPACE_IMAGE) {
-   BLO_write_struct(writer, SpaceImage, sl);
- }
- else if (sl->spacetype == SPACE_TEXT) {
-   BLO_write_struct(writer, SpaceText, sl);
- }
- else if (sl->spacetype == SPACE_SCRIPT) {
-   SpaceScript *scr = (SpaceScript *)sl;
-   scr->but_refs = NULL;
-   BLO_write_struct(writer, SpaceScript, sl);
- }
- else if (sl->spacetype == SPACE_ACTION) {
-   BLO_write_struct(writer, SpaceAction, sl);
- }
- else if (sl->spacetype == SPACE_NLA) {
-   SpaceNla *snla = (SpaceNla *)sl;
- 
-   BLO_write_struct(writer, SpaceNla, snla);
-   if (snla->ads) {
- BLO_write_struct(writer, bDopeSheet, snla->ads);
-   }
- }
- else if (sl->spacetype == SPACE_NODE) {
-   SpaceNode *snode = (SpaceNode *)sl;
-   BLO_write_struct(writer, SpaceNode, snode);
- 
-   LISTBASE_FOREACH (bNodeTreePath *, path, >treepath) {
- BLO_write_struct(writer, bNodeTreePath, path);
-   }
- }
- else if (sl->spacetype == SPACE_CONSOLE) {
-   SpaceConsole *con = (SpaceConsole *)sl;
- 
-   LISTBASE_FOREACH (ConsoleLine *, cl, >history) {
- /* 'len_alloc' is invalid on write, set from 'len' on read */
- BLO_write_struct(writer, ConsoleLine, cl);
- BLO_write_raw(writer, (size_t)cl->len + 1, cl->line);
-   }
-   BLO_write_struct(writer, SpaceConsole, sl);
- }
- else if (sl->spacetype == SPACE_TOPBAR) {
-   BLO_write_struct(writer, SpaceTopBar, sl);
- }
- else if (sl->spacetype == SPACE_STATUSBAR) {
-   BLO_write_struct(writer, SpaceStatusBar, sl);
- }
- else if (sl->spacetype == SPACE_USERPREF) {
-   BLO_write_struct(writer, SpaceUserPref, sl);
- }
- else if (sl->spacetype == SPACE_CLIP) {
-   BLO_write_struct(writer, SpaceClip, sl);
- }
- else if (sl->spacetype == SPACE_INFO) {
-   BLO_write_struct(writer, SpaceInfo, sl);
- }
- else if (sl->spacetype == SPACE_SPREADSHEET) {
-   BLO_write_struct(writer, SpaceSpreadsheet, sl);
-   SpaceSpreadsheet *sspreadsheet = (SpaceSpreadsheet *)sl;
- 
-   LISTBASE_FOREACH (SpreadsheetRowFilter *, row_filter, 
>row_filters) {
- BLO_write_struct(writer, SpreadsheetRowFilter, row_filter);
- BLO_write_string(writer, row_filter->value_string);
-   }
- 
-   LISTBASE_FOREACH (SpreadsheetColumn *, column, >columns) {
- BLO_write_struct(writer, SpreadsheetColumn, column);
- BLO_write_struct(writer, SpreadsheetC

[Bf-blender-cvs] [8311bfe45cd] temp-asset-module: Minor cleanups

2022-11-10 Thread Julian Eisel
Commit: 8311bfe45cd268e81901073be6aa2cf9e89647fd
Author: Julian Eisel
Date:   Thu Nov 10 12:17:51 2022 +0100
Branches: temp-asset-module
https://developer.blender.org/rB8311bfe45cd268e81901073be6aa2cf9e89647fd

Minor cleanups

===

M   source/blender/asset_system/AS_asset_library.hh
M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/editors/space_node/add_menu_assets.cc
M   source/blender/editors/space_node/add_node_search.cc

===

diff --git a/source/blender/asset_system/AS_asset_library.hh 
b/source/blender/asset_system/AS_asset_library.hh
index 9b3b7d5e59a..a0f1214ad39 100644
--- a/source/blender/asset_system/AS_asset_library.hh
+++ b/source/blender/asset_system/AS_asset_library.hh
@@ -18,6 +18,7 @@
 
 struct AssetLibrary;
 struct AssetLibraryReference;
+struct AssetMetaData;
 struct Main;
 
 namespace blender::asset_system {
diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index ad16f9f1c42..b52594fa20c 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -9,7 +9,6 @@
 #include "AS_asset_library.h"
 #include "AS_asset_library.hh"
 #include "AS_asset_representation.hh"
-#include "asset_library_service.hh"
 
 #include "BKE_lib_remap.h"
 #include "BKE_main.h"
@@ -22,6 +21,8 @@
 #include "DNA_asset_types.h"
 #include "DNA_userdef_types.h"
 
+#include "asset_library_service.hh"
+
 using namespace blender;
 using namespace blender::asset_system;
 
diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index 19a59f64466..c4cd5819d60 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
+#include "AS_asset_catalog.hh"
 #include "AS_asset_library.hh"
 
 #include "BLI_multi_value_map.hh"
@@ -7,7 +8,6 @@
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 
-#include "AS_asset_catalog.hh"
 #include "BKE_asset.h"
 #include "BKE_idprop.h"
 #include "BKE_screen.h"
diff --git a/source/blender/editors/space_node/add_node_search.cc 
b/source/blender/editors/space_node/add_node_search.cc
index a7463be0af0..adeddfd115d 100644
--- a/source/blender/editors/space_node/add_node_search.cc
+++ b/source/blender/editors/space_node/add_node_search.cc
@@ -2,6 +2,7 @@
 
 #include 
 
+#include "AS_asset_catalog.hh"
 #include "AS_asset_library.hh"
 
 #include "BLI_listbase.h"
@@ -10,7 +11,6 @@
 #include "DNA_space_types.h"
 
 #include "BKE_asset.h"
-#include "AS_asset_catalog.hh"
 #include "BKE_context.h"
 #include "BKE_idprop.h"
 #include "BKE_lib_id.h"

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a15525b4ee9] temp-asset-module: Merge branch 'master' into temp-asset-module

2022-11-10 Thread Julian Eisel
Commit: a15525b4ee9acd4c9b91446eae67c9e5152a0f23
Author: Julian Eisel
Date:   Thu Nov 10 11:10:26 2022 +0100
Branches: temp-asset-module
https://developer.blender.org/rBa15525b4ee9acd4c9b91446eae67c9e5152a0f23

Merge branch 'master' into temp-asset-module

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


  1   2   3   4   5   6   7   8   9   10   >