Brush Assets: Store assets outside Main #117730

Manually merged
Brecht Van Lommel merged 18 commits from brecht/blender:brush-separate-main into brush-assets-project 2024-02-27 14:53:03 +01:00
3 changed files with 23 additions and 14 deletions
Showing only changes of commit a93300fe20 - Show all commits

View File

@ -232,7 +232,7 @@ ID *BKE_asset_weak_reference_ensure(Main *global_main, const AssetWeakReference
BKE_main_id_tag_all(asset_main, LIB_TAG_ASSET_MAIN, true);
/* Verify that the name matches. It must for referencing the same asset again to work. */
BLI_asset(local_asset == nullptr || STREQ(local_asset->name + 2, asset_name));
BLI_assert(local_asset == nullptr || STREQ(local_asset->name + 2, asset_name));
return local_asset;
}

View File

@ -35,6 +35,7 @@
#include "BKE_anim_data.h"
#include "BKE_animsys.h"
#include "BKE_appdir.hh"
#include "BKE_asset.hh"
#include "BKE_blender_copybuffer.hh"
#include "BKE_brush.hh"
#include "BKE_context.hh"
@ -821,22 +822,26 @@ void MATERIAL_OT_new(wmOperatorType *ot)
static int new_texture_exec(bContext *C, wmOperator * /*op*/)
{
Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data);
Main *bmain = CTX_data_main(C);
PointerRNA ptr;
PropertyRNA *prop;
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
Main *id_main = CTX_data_main(C);
if (ptr.owner_id) {
id_main = BKE_asset_weak_reference_main(id_main, ptr.owner_id);
}
/* add or copy texture */
Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data);
if (tex) {
tex = (Tex *)BKE_id_copy(bmain, &tex->id);
tex = (Tex *)BKE_id_copy(id_main, &tex->id);
}
else {
tex = BKE_texture_add(bmain, DATA_("Texture"));
tex = BKE_texture_add(id_main, DATA_("Texture"));
}
/* hook into UI */
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
if (prop) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer use also increases user, so this compensates it */

View File

@ -34,6 +34,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BKE_asset.hh"
#include "BKE_colortools.hh"
#include "BKE_context.hh"
#include "BKE_global.h"
@ -2537,7 +2538,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
{
SpaceImage *sima;
Image *ima;
Main *bmain;
Main *id_main;
PropertyRNA *prop;
char name_buffer[MAX_ID_NAME - 2];
const char *name;
@ -2545,9 +2546,14 @@ static int image_new_exec(bContext *C, wmOperator *op)
int width, height, floatbuf, gen_type, alpha;
int stereo3d;
ImageNewData *data = image_new_init(C, op);
/* retrieve state */
sima = CTX_wm_space_image(C);
bmain = CTX_data_main(C);
id_main = CTX_data_main(C);
if (data->pprop.ptr.owner_id) {
id_main = BKE_asset_weak_reference_main(id_main, data->pprop.ptr.owner_id);
}
prop = RNA_struct_find_property(op->ptr, "name");
RNA_property_string_get(op->ptr, prop, name_buffer);
@ -2571,7 +2577,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
color[3] = 1.0f;
}
ima = BKE_image_add_generated(bmain,
ima = BKE_image_add_generated(id_main,
width,
height,
name,
@ -2589,8 +2595,6 @@ static int image_new_exec(bContext *C, wmOperator *op)
}
/* hook into UI */
ImageNewData *data = image_new_init(C, op);
if (data->pprop.prop) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer use also increases user, so this compensates it */
@ -2601,7 +2605,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
RNA_property_update(C, &data->pprop.ptr, data->pprop.prop);
}
else if (sima) {
ED_space_image_set(bmain, sima, ima, false);
ED_space_image_set(id_main, sima, ima, false);
}
else {
/* #BKE_image_add_generated creates one user by default, remove it if image is not linked to
@ -2609,7 +2613,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
id_us_min(&ima->id);
}
BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : nullptr, IMA_SIGNAL_USER_NEW_IMAGE);
BKE_image_signal(id_main, ima, (sima) ? &sima->iuser : nullptr, IMA_SIGNAL_USER_NEW_IMAGE);
WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);