Fix: Missing updates for multires sculpting

Caused by ee23f0f3fb, which removed the update tag when entering
sculpt mode, and by b5f7af31d6, which made these layers lazily
created, so they weren't always available at the start of a stroke. Now
update the evaluated mesh/multires CCG as necessary. Some updates
could potentially avoided when switching modes in the future, but for
now do it all the time.

Fixes T101116
Also fixes a crash when painting multires mask for the first time
This commit is contained in:
Hans Goudey 2022-09-16 14:29:37 -05:00
parent 02575bcbd0
commit 8fdaf2bddc
Notes: blender-bot 2023-02-14 01:11:05 +01:00
Referenced by issue #101116, Regression: Multires levels not visible when entering sculpt mode
3 changed files with 16 additions and 9 deletions

View File

@ -2042,6 +2042,8 @@ int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
}
}
}
/* The evaluated multires CCG must be updated to contain the new data. */
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
ret |= SCULPT_MASK_LAYER_CALC_LOOP;
}
@ -2049,6 +2051,8 @@ int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
/* Create vertex paint mask layer if there isn't one already. */
if (!paint_mask) {
CustomData_add_layer(&me->vdata, CD_PAINT_MASK, CD_SET_DEFAULT, nullptr, me->totvert);
/* The evaluated mesh must be updated to contain the new data. */
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
ret |= SCULPT_MASK_LAYER_CALC_VERT;
}

View File

@ -3301,15 +3301,6 @@ static void do_brush_action(Sculpt *sd,
BKE_pbvh_ensure_node_loops(ss->pbvh);
}
if (SCULPT_tool_is_mask(brush->sculpt_tool)) {
MultiresModifierData *mmd = BKE_sculpt_multires_active(ss->scene, ob);
BKE_sculpt_mask_layers_ensure(ob, mmd);
}
if (SCULPT_tool_is_face_sets(brush->sculpt_tool)) {
Mesh *mesh = BKE_object_get_original_mesh(ob);
ss->face_sets = BKE_sculpt_face_sets_ensure(mesh);
}
/* Build a list of all nodes that are potentially within the brush's area of influence */
if (SCULPT_tool_needs_all_pbvh_nodes(brush)) {
@ -5582,11 +5573,20 @@ static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Brush *brush = BKE_paint_brush(&sd->paint);
SculptSession *ss = ob->sculpt;
if (SCULPT_tool_is_paint(brush->sculpt_tool) &&
!SCULPT_handles_colors_report(ob->sculpt, op->reports)) {
return OPERATOR_CANCELLED;
}
if (SCULPT_tool_is_mask(brush->sculpt_tool)) {
MultiresModifierData *mmd = BKE_sculpt_multires_active(ss->scene, ob);
BKE_sculpt_mask_layers_ensure(ob, mmd);
}
if (SCULPT_tool_is_face_sets(brush->sculpt_tool)) {
Mesh *mesh = BKE_object_get_original_mesh(ob);
ss->face_sets = BKE_sculpt_face_sets_ensure(mesh);
}
stroke = paint_stroke_new(C,
op,

View File

@ -309,6 +309,9 @@ static void sculpt_init_session(Main *bmain, Depsgraph *depsgraph, Scene *scene,
ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
ob->sculpt->mode_type = OB_MODE_SCULPT;
/* Necessary to make multires displacement immediately visible. */
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
/* This function expects a fully evaluated depsgraph. */