diff options
Diffstat (limited to 'source/blender/blenkernel/intern/brush.c')
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index a816e4354b8..1b77989c2b8 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -50,7 +50,7 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "RE_render_ext.h" /* RE_texture_evaluate */ +#include "RE_texture.h" /* RE_texture_evaluate */ #include "BLO_read_write.h" @@ -170,7 +170,7 @@ static void brush_make_local(Main *bmain, ID *id, const int flags) id_fake_user_set(&brush->id); } else { - Brush *brush_new = BKE_brush_copy(bmain, brush); /* Ensures FAKE_USER is set */ + Brush *brush_new = (Brush *)BKE_id_copy(bmain, &brush->id); /* Ensures FAKE_USER is set */ brush_new->id.us = 0; @@ -250,7 +250,7 @@ static void brush_blend_read_data(BlendDataReader *reader, ID *id) { Brush *brush = (Brush *)id; - /* fallof curve */ + /* Falloff curve. */ BLO_read_data_address(reader, &brush->curve); BLO_read_data_address(reader, &brush->gradient); @@ -355,6 +355,37 @@ static void brush_blend_read_expand(BlendExpander *expander, ID *id) } } +static int brush_undo_preserve_cb(LibraryIDLinkCallbackData *cb_data) +{ + BlendLibReader *reader = cb_data->user_data; + ID *id_old = *cb_data->id_pointer; + /* Old data has not been remapped to new values of the pointers, if we want to keep the old + * pointer here we need its new address. */ + ID *id_old_new = id_old != NULL ? BLO_read_get_new_id_address(reader, id_old->lib, id_old) : + NULL; + BLI_assert(id_old_new == NULL || ELEM(id_old, id_old_new, id_old_new->orig_id)); + if (cb_data->cb_flag & IDWALK_CB_USER) { + id_us_plus_no_lib(id_old_new); + id_us_min(id_old); + } + *cb_data->id_pointer = id_old_new; + return IDWALK_RET_NOP; +} + +static void brush_undo_preserve(BlendLibReader *reader, ID *id_new, ID *id_old) +{ + /* Whole Brush is preserved accross undo's. */ + BKE_lib_id_swap(NULL, id_new, id_old); + + /* `id_new` now has content from `id_old`, we need to ensure those old ID pointers are valid. + * Note: Since we want to re-use all old pointers here, code is much simpler than for Scene. */ + BKE_library_foreach_ID_link(NULL, id_new, brush_undo_preserve_cb, reader, IDWALK_NOP); + + /* Note: We do not swap IDProperties, as dealing with potential ID pointers in those would be + * fairly delicate. */ + SWAP(IDProperty *, id_new->properties, id_old->properties); +} + IDTypeInfo IDType_ID_BR = { .id_code = ID_BR, .id_filter = FILTER_ID_BR, @@ -363,7 +394,7 @@ IDTypeInfo IDType_ID_BR = { .name = "Brush", .name_plural = "brushes", .translation_context = BLT_I18NCONTEXT_ID_BRUSH, - .flags = 0, + .flags = IDTYPE_FLAGS_NO_ANIMDATA, .init_data = brush_init_data, .copy_data = brush_copy_data, @@ -376,6 +407,8 @@ IDTypeInfo IDType_ID_BR = { .blend_read_data = brush_blend_read_data, .blend_read_lib = brush_blend_read_lib, .blend_read_expand = brush_blend_read_expand, + + .blend_read_undo_preserve = brush_undo_preserve, }; static RNG *brush_rng; @@ -455,9 +488,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode) { Brush *brush; - brush = BKE_libblock_alloc(bmain, ID_BR, name, 0); - - brush_init_data(&brush->id); + brush = BKE_id_new(bmain, ID_BR, name); brush->ob_mode = ob_mode; @@ -1531,13 +1562,6 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mo return NULL; } -Brush *BKE_brush_copy(Main *bmain, const Brush *brush) -{ - Brush *brush_copy; - BKE_id_copy(bmain, &brush->id, (ID **)&brush_copy); - return brush_copy; -} - void BKE_brush_debug_print_state(Brush *br) { /* create a fake brush and set it to the defaults */ @@ -1545,20 +1569,28 @@ void BKE_brush_debug_print_state(Brush *br) brush_defaults(&def); #define BR_TEST(field, t) \ - if (br->field != def.field) \ - printf("br->" #field " = %" #t ";\n", br->field) + if (br->field != def.field) { \ + printf("br->" #field " = %" #t ";\n", br->field); \ + } \ + ((void)0) #define BR_TEST_FLAG(_f) \ - if ((br->flag & _f) && !(def.flag & _f)) \ + if ((br->flag & _f) && !(def.flag & _f)) { \ printf("br->flag |= " #_f ";\n"); \ - else if (!(br->flag & _f) && (def.flag & _f)) \ - printf("br->flag &= ~" #_f ";\n") + } \ + else if (!(br->flag & _f) && (def.flag & _f)) { \ + printf("br->flag &= ~" #_f ";\n"); \ + } \ + ((void)0) #define BR_TEST_FLAG_OVERLAY(_f) \ - if ((br->overlay_flags & _f) && !(def.overlay_flags & _f)) \ + if ((br->overlay_flags & _f) && !(def.overlay_flags & _f)) { \ printf("br->overlay_flags |= " #_f ";\n"); \ - else if (!(br->overlay_flags & _f) && (def.overlay_flags & _f)) \ - printf("br->overlay_flags &= ~" #_f ";\n") + } \ + else if (!(br->overlay_flags & _f) && (def.overlay_flags & _f)) { \ + printf("br->overlay_flags &= ~" #_f ";\n"); \ + } \ + ((void)0) /* print out any non-default brush state */ BR_TEST(normal_weight, f); @@ -1708,11 +1740,10 @@ void BKE_brush_sculpt_reset(Brush *br) case SCULPT_TOOL_SCRAPE: case SCULPT_TOOL_FILL: br->alpha = 0.7f; - br->area_radius_factor = 1.0f; + br->area_radius_factor = 0.5f; br->spacing = 7; br->flag |= BRUSH_ACCUMULATE; br->flag |= BRUSH_INVERT_TO_SCRAPE_FILL; - br->flag2 |= BRUSH_AREA_RADIUS_PRESSURE; break; case SCULPT_TOOL_ROTATE: br->alpha = 1.0; |