diff options
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 60 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 3 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 3 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_old.c | 8 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 4 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_primitive.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_utils.c | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_uv.c | 7 |
12 files changed, 63 insertions, 46 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index ebfe47c2f99..aca734ae709 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -62,7 +62,6 @@ void BKE_brush_sculpt_reset(struct Brush *brush); void BKE_brush_gpencil_presets(struct bContext *C); void BKE_brush_update_material(struct Main *bmain, struct Material *ma, struct Brush *exclude_brush); struct Brush *BKE_brush_getactive_gpencil(struct ToolSettings *ts); -struct Paint *BKE_brush_get_gpencil_paint(struct ToolSettings *ts); /* image icon function */ struct ImBuf *get_brush_icon(struct Brush *brush); diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 652b794f937..06e4aad68ec 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -61,6 +61,7 @@ struct Tex; struct ImagePool; struct UnifiedPaintSettings; struct Depsgraph; +struct ToolSettings; enum eOverlayFlags; @@ -124,6 +125,7 @@ void BKE_paint_curve_copy_data( struct PaintCurve *BKE_paint_curve_copy(struct Main *bmain, const struct PaintCurve *pc); void BKE_paint_curve_make_local(struct Main *bmain, struct PaintCurve *pc, const bool lib_local); +bool BKE_paint_ensure(const struct ToolSettings *ts, struct Paint **r_paint); void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3]); void BKE_paint_free(struct Paint *p); void BKE_paint_copy(struct Paint *src, struct Paint *tar, const int flag); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 94ff7f3f2e5..286ba5f7902 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -193,7 +193,7 @@ void BKE_brush_init_gpencil_settings(Brush *brush) Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name) { Brush *brush; - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; brush = BKE_brush_add(bmain, name, OB_MODE_GPENCIL_PAINT); BKE_paint_brush_set(paint, brush); @@ -208,16 +208,6 @@ Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name) return brush; } -Paint *BKE_brush_get_gpencil_paint(ToolSettings *ts) -{ - /* alloc paint session */ - if (ts->gp_paint == NULL) { - ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint"); - } - - return &ts->gp_paint->paint; -} - /* grease pencil cumapping->preset */ typedef enum eGPCurveMappingPreset { GPCURVE_PRESET_PENCIL = 0, @@ -273,7 +263,7 @@ void BKE_brush_gpencil_presets(bContext *C) #define SMOOTH_STROKE_FACTOR 0.9f ToolSettings *ts = CTX_data_tool_settings(C); - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; Main *bmain = CTX_data_main(C); Brush *brush, *deft; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 7838fb69f1a..e6ef18efcc9 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -570,6 +570,53 @@ eObjectMode BKE_paint_object_mode_from_paint_mode(ePaintMode mode) } } +/** + * Call when entering each respective paint mode. + */ +bool BKE_paint_ensure(const ToolSettings *ts, struct Paint **r_paint) +{ + Paint *paint = NULL; + if (*r_paint) { + /* Note: 'ts->imapaint' is ignored, it's not allocated. */ + BLI_assert( + ELEM(*r_paint, + &ts->gp_paint->paint, + &ts->sculpt->paint, + &ts->vpaint->paint, + &ts->wpaint->paint, + &ts->uvsculpt->paint)); + return true; + } + + if (ELEM(*r_paint, &ts->vpaint->paint, &ts->wpaint->paint)) { + VPaint *data = MEM_callocN(sizeof(*data), __func__); + paint = &data->paint; + } + else if (*r_paint == &ts->sculpt->paint) { + Sculpt *data = MEM_callocN(sizeof(*data), __func__); + paint = &data->paint; + + /* Turn on X plane mirror symmetry by default */ + paint->symmetry_flags |= PAINT_SYMM_X; + + /* Make sure at least dyntopo subdivision is enabled */ + data->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE; + } + else if (*r_paint == &ts->gp_paint->paint) { + GpPaint *data = MEM_callocN(sizeof(*data), __func__); + paint = &data->paint; + } + else if (*r_paint == &ts->uvsculpt->paint) { + UvSculpt *data = MEM_callocN(sizeof(*data), __func__); + paint = &data->paint; + } + + paint->flags |= PAINT_SHOW_BRUSH; + + *r_paint = paint; + return false; +} + void BKE_paint_init(Main *bmain, Scene *sce, ePaintMode mode, const char col[3]) { UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings; @@ -1144,18 +1191,9 @@ int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd) void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene) { - Sculpt *sd = scene->toolsettings->sculpt; - if (sd == NULL) { - sd = scene->toolsettings->sculpt = MEM_callocN(sizeof(Sculpt), __func__); - - /* Turn on X plane mirror symmetry by default */ - sd->paint.symmetry_flags |= PAINT_SYMM_X; - sd->paint.flags |= PAINT_SHOW_BRUSH; - - /* Make sure at least dyntopo subdivision is enabled */ - sd->flags |= SCULPT_DYNTOPO_SUBDIVIDE | SCULPT_DYNTOPO_COLLAPSE; - } + BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->sculpt); + Sculpt *sd = scene->toolsettings->sculpt; if (!sd->detail_size) { sd->detail_size = 12; } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index a01495eb064..af27103b07e 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -688,9 +688,6 @@ void BKE_scene_init(Scene *sce) sce->toolsettings->imapaint.normal_angle = 80; sce->toolsettings->imapaint.seam_bleed = 2; - /* alloc grease pencil drawing brushes */ - sce->toolsettings->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint"); - /* grease pencil multiframe falloff curve */ sce->toolsettings->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *gp_falloff_curve = sce->toolsettings->gp_sculpt.cur_falloff; diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 4dcb3420bd6..8c7068c0a7c 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -1561,7 +1561,7 @@ static int gp_brush_select_exec(bContext *C, wmOperator *op) const int index = RNA_int_get(op->ptr, "index"); - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; int i = 0; for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) { diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 12dc3451902..fc50fa7359f 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -319,7 +319,8 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op) if (mode == OB_MODE_GPENCIL_PAINT) { /* be sure we have brushes */ - Paint *paint = BKE_brush_get_gpencil_paint(ts); + BKE_paint_ensure(ts, (Paint **)&ts->gp_paint); + Paint *paint = &ts->gp_paint->paint; /* if not exist, create a new one */ if (paint->brush == NULL) { BKE_brush_gpencil_presets(C); diff --git a/source/blender/editors/gpencil/gpencil_old.c b/source/blender/editors/gpencil/gpencil_old.c index 1474e948920..a2012be223d 100644 --- a/source/blender/editors/gpencil/gpencil_old.c +++ b/source/blender/editors/gpencil/gpencil_old.c @@ -105,7 +105,6 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - ToolSettings *ts = CTX_data_tool_settings(C); ViewLayer *view_layer = CTX_data_view_layer(C); /* Convert grease pencil scene datablock to GP object */ @@ -114,13 +113,6 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op)) ob = BKE_object_add_for_data(bmain, view_layer, OB_GPENCIL, "GP_Scene", &scene->gpd->id, false); zero_v3(ob->loc); - Paint *paint = BKE_brush_get_gpencil_paint(ts); - /* if not exist, create a new one */ - if (paint->brush == NULL) { - /* create new brushes */ - BKE_brush_gpencil_presets(C); - } - /* convert grease pencil palettes (version >= 2.78) to materials and weights */ bGPdata *gpd = scene->gpd; for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) { diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index afd91d50e1f..a0cc149fd90 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1641,7 +1641,7 @@ static void gp_session_validatebuffer(tGPsdata *p) static Brush *gp_get_default_eraser(Main *bmain, ToolSettings *ts) { Brush *brush_dft = NULL; - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; Brush *brush_old = paint->brush; for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { if ((brush->ob_mode == OB_MODE_GPENCIL_PAINT) && @@ -1685,7 +1685,7 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p) Scene *scene = CTX_data_scene(C); ToolSettings *ts = CTX_data_tool_settings(C); - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; /* if not exist, create a new one */ if (paint->brush == NULL) { diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 338fb7f5c6a..5f50c2f7a82 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -144,7 +144,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi) Brush *brush; /* if brush doesn't exist, create a new one */ - Paint *paint = BKE_brush_get_gpencil_paint(ts); + Paint *paint = &ts->gp_paint->paint; /* if not exist, create a new one */ if (paint->brush == NULL) { /* create new brushes */ diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 5b8c11ac38c..41ea3a2138d 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -1201,7 +1201,8 @@ void ED_gpencil_add_defaults(bContext *C) /* ensure color exist */ BKE_gpencil_material_ensure(bmain, ob); - Paint *paint = BKE_brush_get_gpencil_paint(ts); + BKE_paint_ensure(ts, (Paint **)&ts->gp_paint); + Paint *paint = &ts->gp_paint->paint; /* if not exist, create a new one */ if (paint->brush == NULL) { /* create new brushes */ diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 897539bddd7..c5cebed0b8b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -236,15 +236,12 @@ void ED_space_image_uv_sculpt_update(Main *bmain, wmWindowManager *wm, Scene *sc { ToolSettings *settings = scene->toolsettings; if (settings->use_uv_sculpt) { - if (!settings->uvsculpt) { - settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint"); + if (settings->uvsculpt == NULL) { settings->uv_sculpt_tool = UV_SCULPT_TOOL_GRAB; settings->uv_sculpt_settings = UV_SCULPT_LOCK_BORDERS | UV_SCULPT_ALL_ISLANDS; settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN; - /* Uv sculpting does not include explicit brush view control yet, always enable */ - settings->uvsculpt->paint.flags |= PAINT_SHOW_BRUSH; } - + BKE_paint_ensure(settings, (Paint **)&settings->uvsculpt); BKE_paint_init(bmain, scene, ePaintSculptUV, PAINT_CURSOR_SCULPT); settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate( |