WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 357 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.
4 changed files with 20 additions and 30 deletions
Showing only changes of commit 525e85bd30 - Show all commits

View File

@ -76,6 +76,5 @@ PreviewImage *BKE_asset_metadata_preview_get_from_id(const AssetMetaData *asset_
void BKE_asset_metadata_write(BlendWriter *writer, AssetMetaData *asset_data);
void BKE_asset_metadata_read(BlendDataReader *reader, AssetMetaData *asset_data);
AssetWeakReference *BKE_asset_weak_reference_copy(const AssetWeakReference *weak_ref);
void BKE_asset_weak_reference_write(BlendWriter *writer, const AssetWeakReference *weak_ref);
void BKE_asset_weak_reference_read(BlendDataReader *reader, AssetWeakReference *weak_ref);

View File

@ -84,20 +84,6 @@ bool AssetWeakReference::operator!=(const AssetWeakReference &other) const
return !(*this == other);
}
AssetWeakReference *BKE_asset_weak_reference_copy(const AssetWeakReference *weak_ref)
{
if (weak_ref == nullptr) {
return nullptr;
}
AssetWeakReference *weak_ref_copy = MEM_new<AssetWeakReference>(__func__);
weak_ref_copy->asset_library_type = weak_ref->asset_library_type;
weak_ref_copy->asset_library_identifier = BLI_strdup_null(weak_ref->asset_library_identifier);
weak_ref_copy->relative_asset_identifier = BLI_strdup_null(weak_ref->relative_asset_identifier);
return weak_ref_copy;
}
AssetWeakReference AssetWeakReference::make_reference(
const asset_system::AssetLibrary &library,
const asset_system::AssetIdentifier &asset_identifier)

View File

@ -1290,20 +1290,23 @@ void BKE_paint_free(Paint *paint)
MEM_delete(paint->brush_asset_reference);
}
void BKE_paint_copy(const Paint *src, Paint *tar, const int flag)
void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
{
tar->brush = src->brush;
tar->cavity_curve = BKE_curvemapping_copy(src->cavity_curve);
tar->tool_slots = static_cast<PaintToolSlot *>(MEM_dupallocN(src->tool_slots));
dst->brush = src->brush;
dst->cavity_curve = BKE_curvemapping_copy(src->cavity_curve);
dst->tool_slots = static_cast<PaintToolSlot *>(MEM_dupallocN(src->tool_slots));
tar->brush_asset_reference = BKE_asset_weak_reference_copy(src->brush_asset_reference);
if (src->brush_asset_reference) {
dst->brush_asset_reference = MEM_new<AssetWeakReference>(__func__,
*src->brush_asset_reference);
}
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)tar->brush);
id_us_plus((ID *)tar->palette);
id_us_plus((ID *)dst->brush);
id_us_plus((ID *)dst->palette);
if (src->tool_slots != nullptr) {
for (int i = 0; i < tar->tool_slots_len; i++) {
id_us_plus((ID *)tar->tool_slots[i].brush);
for (int i = 0; i < dst->tool_slots_len; i++) {
id_us_plus((ID *)dst->tool_slots[i].brush);
}
}
}

View File

@ -40,7 +40,7 @@ namespace blender::ed::asset::shelf {
class AssetView : public ui::AbstractGridView {
const AssetLibraryReference library_ref_;
const AssetShelf &shelf_;
AssetWeakReference *active_asset_ = nullptr;
std::optional<AssetWeakReference> active_asset_;
/** Copy of the filter string from #AssetShelfSettings, with extra '*' added to the beginning and
* end of the string, for `fnmatch()` to work. */
char search_string[sizeof(AssetShelfSettings::search_string) + 2] = "";
@ -96,14 +96,16 @@ AssetView::AssetView(const AssetLibraryReference &library_ref, const AssetShelf
search_string, shelf.settings.search_string, '*', sizeof(search_string));
}
if (shelf.type->get_active_asset) {
active_asset_ = BKE_asset_weak_reference_copy(shelf.type->get_active_asset(shelf.type));
if (const AssetWeakReference *weak_ref = shelf.type->get_active_asset(shelf.type)) {
active_asset_ = *weak_ref;
}
else {
active_asset_.reset();
}
}
}
AssetView::~AssetView()
{
MEM_delete(active_asset_);
}
AssetView::~AssetView() {}
void AssetView::build_items()
{