From 751189e9d6828368614fe3f517a80ddb95f8c547 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Jun 2018 08:35:41 +0200 Subject: Vertex Paint: set sculpt object mode immediately SculptSession.mode_type wasn't initialized until painting, making it unreliable for checks in other parts of the code. Also remove unnecessary initialization, matching sculpt mode more closely. --- source/blender/editors/sculpt_paint/paint_vertex.c | 25 +++++++++++++--------- source/blender/editors/sculpt_paint/sculpt.c | 10 +++------ 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 93c8b1c8fea..095ba088e0c 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -938,15 +938,20 @@ static void do_weight_paint_vertex( /* Toggle operator for turning vertex paint mode on or off (copied from sculpt.c) */ -static void vertex_paint_init_session(Scene *scene, Object *ob) +static void vertex_paint_init_session(Scene *scene, Object *ob, eObjectMode object_mode) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); - if (ob->sculpt == NULL) { - ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); - BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, false, false); - } + BLI_assert(ob->sculpt == NULL); + ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); + ob->sculpt->mode_type = object_mode; + BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, false, false); +} + +static void vertex_paint_init_stroke(Scene *scene, Object *ob) +{ + BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, false, false); } static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) @@ -957,12 +962,12 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob) if (ob->mode == OB_MODE_VERTEX_PAINT) { gmap = &ob->sculpt->mode.vpaint.gmap; brush = BKE_paint_brush(&ts->vpaint->paint); - ob->sculpt->mode_type = OB_MODE_VERTEX_PAINT; + BLI_assert(ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT); } else if (ob->mode == OB_MODE_WEIGHT_PAINT) { gmap = &ob->sculpt->mode.wpaint.gmap; brush = BKE_paint_brush(&ts->wpaint->paint); - ob->sculpt->mode_type = OB_MODE_WEIGHT_PAINT; + BLI_assert(ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT); } else { ob->sculpt->mode_type = 0; @@ -1080,7 +1085,7 @@ static void ed_vwpaintmode_enter_generic( BKE_sculptsession_free(ob); } - vertex_paint_init_session(scene, ob); + vertex_paint_init_session(scene, ob, mode_flag); } void ED_object_vpaintmode_enter_ex( @@ -1505,7 +1510,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo } /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(scene, ob); + vertex_paint_init_stroke(scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); vertex_paint_init_session_data(ts, ob); @@ -2482,7 +2487,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f } /* If not previously created, create vertex/weight paint mode session data */ - vertex_paint_init_session(scene, ob); + vertex_paint_init_stroke(scene, ob); vwpaint_update_cache_invariants(C, vp, ss, op, mouse); vertex_paint_init_session_data(ts, ob); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index bef705a29b1..280e22084cc 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -4804,7 +4804,7 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession sculpt_update_tex(scene, sd, ss); } -static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) +static void sculpt_brush_stroke_init(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -4824,8 +4824,6 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) is_smooth = sculpt_any_smooth_mode(brush, NULL, mode); BKE_sculpt_update_mesh_elements(scene, sd, ob, is_smooth, need_mask); - - return 1; } static void sculpt_restore_mesh(Sculpt *sd, Object *ob) @@ -5069,8 +5067,7 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent int ignore_background_click; int retval; - if (!sculpt_brush_stroke_init(C, op)) - return OPERATOR_CANCELLED; + sculpt_brush_stroke_init(C, op); stroke = paint_stroke_new(C, op, sculpt_stroke_get_location, sculpt_stroke_test_start, @@ -5102,8 +5099,7 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) { - if (!sculpt_brush_stroke_init(C, op)) - return OPERATOR_CANCELLED; + sculpt_brush_stroke_init(C, op); op->customdata = paint_stroke_new(C, op, sculpt_stroke_get_location, sculpt_stroke_test_start, sculpt_stroke_update_step, NULL, sculpt_stroke_done, 0); -- cgit v1.2.3