WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 351 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
15 changed files with 154 additions and 64 deletions
Showing only changes of commit f2086022ee - Show all commits

View File

@ -8934,7 +8934,7 @@ class VIEW3D_PT_viewport_debug(Panel):
class BrushAssetShelf:
bl_space_type = "VIEW_3D"
bl_options = {'DEFAULT_VISIBLE', 'NO_ASSET_DRAG'}
bl_options = {'DEFAULT_VISIBLE', 'NO_ASSET_DRAG', 'STORE_ENABLED_CATALOGS_IN_PREFERENCES'}
bl_activate_operator = "BRUSH_OT_asset_select"
bl_default_preview_size = 48

View File

@ -80,3 +80,13 @@ void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data)
void BKE_asset_weak_reference_write(BlendWriter *writer, const AssetWeakReference *weak_ref);
void BKE_asset_weak_reference_read(BlendDataReader *reader, AssetWeakReference *weak_ref);
void BKE_asset_catalog_path_list_free(ListBase &catalog_path_list);
ListBase BKE_asset_catalog_path_list_duplicate(const ListBase &catalog_path_list);
void BKE_asset_catalog_path_list_blend_write(BlendWriter *writer,
const ListBase &catalog_path_list);
void BKE_asset_catalog_path_list_blend_read_data(BlendDataReader *reader,
ListBase &catalog_path_list);
bool BKE_asset_catalog_path_list_has_path(const ListBase &catalog_path_list,
const char *catalog_path);
void BKE_asset_catalog_path_list_add_path(ListBase &catalog_path_list, const char *catalog_path);

View File

@ -147,8 +147,3 @@ bool BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(UserDef *u
#ifdef __cplusplus
}
#endif
void BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(const UserDef *userdef,
const char *shelf_idname);
void BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(
bUserAssetShelfSettings *settings);

View File

@ -523,6 +523,7 @@ enum AssetShelfTypeFlag {
* keymap items then. */
ASSET_SHELF_TYPE_FLAG_NO_ASSET_DRAG = (1 << 0),
ASSET_SHELF_TYPE_FLAG_DEFAULT_VISIBLE = (1 << 1),
ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS = (1 << 2),
ASSET_SHELF_TYPE_FLAG_MAX
};

View File

@ -129,3 +129,58 @@ void BKE_asset_weak_reference_read(BlendDataReader *reader, AssetWeakReference *
BLO_read_data_address(reader, &weak_ref->asset_library_identifier);
BLO_read_data_address(reader, &weak_ref->relative_asset_identifier);
}
void BKE_asset_catalog_path_list_free(ListBase &catalog_path_list)
{
LISTBASE_FOREACH_MUTABLE (AssetCatalogPathLink *, catalog_path, &catalog_path_list) {
MEM_delete(catalog_path->path);
BLI_freelinkN(&catalog_path_list, catalog_path);
}
BLI_assert(BLI_listbase_is_empty(&catalog_path_list));
}
ListBase BKE_asset_catalog_path_list_duplicate(const ListBase &catalog_path_list)
{
ListBase duplicated_list = {nullptr};
LISTBASE_FOREACH (AssetCatalogPathLink *, catalog_path, &catalog_path_list) {
AssetCatalogPathLink *copied_path = MEM_cnew<AssetCatalogPathLink>(__func__);
copied_path->path = BLI_strdup(catalog_path->path);
BLI_addtail(&duplicated_list, copied_path);
}
return duplicated_list;
}
void BKE_asset_catalog_path_list_blend_write(BlendWriter *writer,
const ListBase &catalog_path_list)
{
LISTBASE_FOREACH (const AssetCatalogPathLink *, catalog_path, &catalog_path_list) {
BLO_write_struct(writer, AssetCatalogPathLink, catalog_path);
BLO_write_string(writer, catalog_path->path);
}
}
void BKE_asset_catalog_path_list_blend_read_data(BlendDataReader *reader,
ListBase &catalog_path_list)
{
BLO_read_list(reader, &catalog_path_list);
LISTBASE_FOREACH (AssetCatalogPathLink *, catalog_path, &catalog_path_list) {
BLO_read_data_address(reader, &catalog_path->path);
}
}
bool BKE_asset_catalog_path_list_has_path(const ListBase &catalog_path_list,
const char *catalog_path)
{
return BLI_findstring_ptr(
&catalog_path_list, catalog_path, offsetof(AssetCatalogPathLink, path)) != nullptr;
}
void BKE_asset_catalog_path_list_add_path(ListBase &catalog_path_list, const char *catalog_path)
{
AssetCatalogPathLink *new_path = MEM_cnew<AssetCatalogPathLink>(__func__);
new_path->path = BLI_strdup(catalog_path);
BLI_addtail(&catalog_path_list, new_path);
}

View File

@ -22,6 +22,7 @@
#include "IMB_moviecache.hh"
#include "BKE_addon.h"
#include "BKE_asset.hh"
#include "BKE_asset_edit.hh"
#include "BKE_blender.hh" /* own include */
#include "BKE_blender_user_menu.hh" /* own include */
@ -349,7 +350,7 @@ void BKE_blender_userdef_data_free(UserDef *userdef, bool clear_fonts)
BLI_freelistN(&userdef->extension_repos);
LISTBASE_FOREACH_MUTABLE (bUserAssetShelfSettings *, settings, &userdef->asset_shelves_settings)
{
BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(settings);
BKE_asset_catalog_path_list_free(settings->enabled_catalog_paths);
MEM_freeN(settings);
}
BLI_listbase_clear(&userdef->asset_shelves_settings);

View File

@ -20,10 +20,12 @@
#include "BLI_string_utils.hh"
#include "BKE_appdir.hh"
#include "BKE_asset.hh"
#include "BKE_preferences.h"
#include "BLT_translation.hh"
#include "DNA_asset_types.h"
#include "DNA_defaults.h"
#include "DNA_userdef_types.h"
@ -435,13 +437,6 @@ bUserAssetShelfSettings *BKE_preferences_asset_shelf_settings_get(const UserDef
offsetof(bUserAssetShelfSettings, shelf_idname)));
}
static bool asset_shelf_settings_is_catalog_path_enabled(const bUserAssetShelfSettings *settings,
const char *catalog_path)
{
return BLI_findstring_ptr(
&settings->enabled_catalog_paths, catalog_path, offsetof(LinkData, data)) != nullptr;
}
bool BKE_preferences_asset_shelf_settings_is_catalog_path_enabled(const UserDef *userdef,
const char *shelf_idname,
const char *catalog_path)
@ -451,7 +446,7 @@ bool BKE_preferences_asset_shelf_settings_is_catalog_path_enabled(const UserDef
if (!settings) {
return false;
}
return asset_shelf_settings_is_catalog_path_enabled(settings, catalog_path);
return BKE_asset_catalog_path_list_has_path(settings->enabled_catalog_paths, catalog_path);
}
bool BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(UserDef *userdef,
@ -465,31 +460,8 @@ bool BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(UserDef *u
}
bUserAssetShelfSettings *settings = asset_shelf_settings_ensure(userdef, shelf_idname);
char *path_copy = BLI_strdup(catalog_path);
BLI_addtail(&settings->enabled_catalog_paths, BLI_genericNodeN(path_copy));
BKE_asset_catalog_path_list_add_path(settings->enabled_catalog_paths, catalog_path);
return true;
}
void BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(
bUserAssetShelfSettings *settings)
{
LISTBASE_FOREACH_MUTABLE (LinkData *, path_link, &settings->enabled_catalog_paths) {
MEM_freeN(path_link->data);
BLI_freelinkN(&settings->enabled_catalog_paths, path_link);
}
BLI_assert(BLI_listbase_is_empty(&settings->enabled_catalog_paths));
}
void BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(const UserDef *userdef,
const char *shelf_idname)
{
bUserAssetShelfSettings *settings = BKE_preferences_asset_shelf_settings_get(userdef,
shelf_idname);
if (!settings) {
return;
}
BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(settings);
}
/** \} */

View File

@ -3433,10 +3433,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
}
LISTBASE_FOREACH (bUserAssetShelfSettings *, shelf_settings, &user->asset_shelves_settings) {
BLO_read_list(reader, &shelf_settings->enabled_catalog_paths);
LISTBASE_FOREACH (LinkData *, path_link, &shelf_settings->enabled_catalog_paths) {
BLO_read_data_address(reader, &path_link->data);
}
BKE_asset_catalog_path_list_blend_read_data(reader, shelf_settings->enabled_catalog_paths);
}
/* XXX */

View File

@ -100,6 +100,7 @@
#include "MEM_guardedalloc.h" /* MEM_freeN */
#include "BKE_asset.hh"
#include "BKE_blender_version.h"
#include "BKE_bpath.hh"
#include "BKE_global.hh" /* For #Global `G`. */
@ -938,10 +939,7 @@ static void write_userdef(BlendWriter *writer, const UserDef *userdef)
const bUserAssetShelfSettings *, shelf_settings, &userdef->asset_shelves_settings)
{
BLO_write_struct(writer, bUserAssetShelfSettings, shelf_settings);
LISTBASE_FOREACH (const LinkData *, path_link, &shelf_settings->enabled_catalog_paths) {
BLO_write_struct(writer, LinkData, path_link);
BLO_write_string(writer, (const char *)path_link->data);
}
BKE_asset_catalog_path_list_blend_write(writer, shelf_settings->enabled_catalog_paths);
}
LISTBASE_FOREACH (const uiStyle *, style, &userdef->uistyles) {

View File

@ -58,10 +58,14 @@ void settings_set_all_catalog_active(AssetShelfSettings &settings);
bool settings_is_active_catalog(const AssetShelfSettings &settings,
const asset_system::AssetCatalogPath &path);
bool settings_is_all_catalog_active(const AssetShelfSettings &settings);
void settings_clear_enabled_catalogs(const AssetShelf &shelf);
/**
* Clears the list of enabled catalogs in either the Preferences (if any) or the asset shelf
* settings (if any), depending on the #ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS flag.
*/
void settings_clear_enabled_catalogs(AssetShelf &shelf);
bool settings_is_catalog_path_enabled(const AssetShelf &shelf,
const asset_system::AssetCatalogPath &path);
void settings_set_catalog_path_enabled(const AssetShelf &shelf,
void settings_set_catalog_path_enabled(AssetShelf &shelf,
const asset_system::AssetCatalogPath &path);
void settings_foreach_enabled_catalog_path(

View File

@ -20,7 +20,9 @@
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BKE_asset.hh"
#include "BKE_preferences.h"
#include "BKE_screen.hh"
#include "asset_shelf.hh"
@ -47,11 +49,15 @@ AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &othe
if (active_catalog_path) {
active_catalog_path = BLI_strdup(other.active_catalog_path);
}
BKE_asset_catalog_path_list_free(enabled_catalog_paths);
enabled_catalog_paths = BKE_asset_catalog_path_list_duplicate(other.enabled_catalog_paths);
return *this;
}
AssetShelfSettings::~AssetShelfSettings()
{
BKE_asset_catalog_path_list_free(enabled_catalog_paths);
MEM_delete(active_catalog_path);
}
@ -60,11 +66,14 @@ namespace blender::ed::asset::shelf {
void settings_blend_write(BlendWriter *writer, const AssetShelfSettings &settings)
{
BLO_write_struct(writer, AssetShelfSettings, &settings);
BKE_asset_catalog_path_list_blend_write(writer, settings.enabled_catalog_paths);
BLO_write_string(writer, settings.active_catalog_path);
}
void settings_blend_read_data(BlendDataReader *reader, AssetShelfSettings &settings)
{
BKE_asset_catalog_path_list_blend_read_data(reader, settings.enabled_catalog_paths);
BLO_read_data_address(reader, &settings.active_catalog_path);
}
@ -92,25 +101,62 @@ bool settings_is_all_catalog_active(const AssetShelfSettings &settings)
return !settings.active_catalog_path || !settings.active_catalog_path[0];
}
void settings_clear_enabled_catalogs(const AssetShelf &shelf)
static bool use_enabled_catalogs_from_prefs(const AssetShelf &shelf)
{
BKE_preferences_asset_shelf_settings_clear_enabled_catalog_paths(&U, shelf.idname);
return shelf.type && (shelf.type->flag & ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS);
}
static const ListBase *get_enabled_catalog_path_list(const AssetShelf &shelf)
{
if (use_enabled_catalogs_from_prefs(shelf)) {
bUserAssetShelfSettings *pref_settings = BKE_preferences_asset_shelf_settings_get(
&U, shelf.idname);
return pref_settings ? &pref_settings->enabled_catalog_paths : nullptr;
}
return &shelf.settings.enabled_catalog_paths;
}
static ListBase *get_enabled_catalog_path_list(AssetShelf &shelf)
{
return const_cast<ListBase *>(
get_enabled_catalog_path_list(const_cast<const AssetShelf &>(shelf)));
}
void settings_clear_enabled_catalogs(AssetShelf &shelf)
{
ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
if (enabled_catalog_paths) {
BKE_asset_catalog_path_list_free(*enabled_catalog_paths);
BLI_assert(BLI_listbase_is_empty(enabled_catalog_paths));
}
}
bool settings_is_catalog_path_enabled(const AssetShelf &shelf,
const asset_system::AssetCatalogPath &path)
{
return BKE_preferences_asset_shelf_settings_is_catalog_path_enabled(
&U, shelf.idname, path.c_str());
const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
if (!enabled_catalog_paths) {
return false;
}
return BKE_asset_catalog_path_list_has_path(*enabled_catalog_paths, path.c_str());
}
void settings_set_catalog_path_enabled(const AssetShelf &shelf,
void settings_set_catalog_path_enabled(AssetShelf &shelf,
const asset_system::AssetCatalogPath &path)
{
if (BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(
&U, shelf.idname, path.c_str()))
{
U.runtime.is_dirty = true;
if (use_enabled_catalogs_from_prefs(shelf)) {
if (BKE_preferences_asset_shelf_settings_ensure_catalog_path_enabled(
&U, shelf.idname, path.c_str()))
{
U.runtime.is_dirty = true;
}
}
else {
if (!BKE_asset_catalog_path_list_has_path(shelf.settings.enabled_catalog_paths, path.c_str()))
{
BKE_asset_catalog_path_list_add_path(shelf.settings.enabled_catalog_paths, path.c_str());
}
}
}
@ -118,14 +164,13 @@ void settings_foreach_enabled_catalog_path(
const AssetShelf &shelf,
FunctionRef<void(const asset_system::AssetCatalogPath &catalog_path)> fn)
{
const bUserAssetShelfSettings *pref_settings = BKE_preferences_asset_shelf_settings_get(
&U, shelf.idname);
if (!pref_settings) {
const ListBase *enabled_catalog_paths = get_enabled_catalog_path_list(shelf);
if (!enabled_catalog_paths) {
return;
}
LISTBASE_FOREACH (LinkData *, path_link, &pref_settings->enabled_catalog_paths) {
fn(asset_system::AssetCatalogPath((char *)path_link->data));
LISTBASE_FOREACH (const AssetCatalogPathLink *, path_link, enabled_catalog_paths) {
fn(asset_system::AssetCatalogPath(path_link->path));
}
}

View File

@ -205,3 +205,8 @@ typedef struct AssetWeakReference {
typedef struct AssetHandle {
const struct FileDirEntry *file_data;
} AssetHandle;
struct AssetCatalogPathLink {
struct AssetCatalogPathLink *next, *prev;
char *path;
};

View File

@ -799,6 +799,7 @@ typedef struct AssetShelfSettings {
AssetLibraryReference asset_library_reference;
ListBase enabled_catalog_paths; /* #AssetCatalogPathLink */
/** If not set (null or empty string), all assets will be displayed ("All" catalog behavior). */
const char *active_catalog_path;

View File

@ -765,7 +765,7 @@ typedef struct bUserAssetShelfSettings {
/** Identifier that matches the #AssetShelfType.idname of the shelf these settings apply to. */
char shelf_idname[64]; /* MAX_NAME */
ListBase enabled_catalog_paths; /* #LinkData */
ListBase enabled_catalog_paths; /* #AssetCatalogPathLink */
} bUserAssetShelfSettings;
/**

View File

@ -2309,6 +2309,12 @@ static void rna_def_asset_shelf(BlenderRNA *brna)
"Visible by Default",
"Unhide the asset shelf when it's available for the first time, otherwise it will be "
"hidden"},
{ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS,
"STORE_ENABLED_CATALOGS_IN_PREFERENCES",
0,
"Store Enabled Catalogs in Preferences",
"Store the shelf's enabled catalogs in the preferences rather than the local asset shelf "
"settings"},
{0, nullptr, 0, nullptr, nullptr},
};