Fix #134895: Cancelling sculpt mode elastic transforms deforms mesh

Since the transform system uses previous positions to update to
"original" positions upon cancel, the elastic transforms are not working
well with this (due to their `TransformDisplacementMode::Incremental`
nature).

To resolve, rely on restoring positions from undo (as done elsewhere in
sculpt).

Pull Request: https://projects.blender.org/blender/blender/pulls/134919
This commit is contained in:
Philipp Oeser
2025-02-26 15:38:29 +01:00
committed by Philipp Oeser
parent 7ac3de70fd
commit bc3c6c4e7c
3 changed files with 18 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ void keymap_sculpt(wmKeyConfig *keyconf);
/* `sculpt_transform.cc` */
void update_modal_transform(bContext *C, Object &ob);
void cancel_modal_transform(bContext *C, Object &ob);
void init_transform(bContext *C, Object &ob, const float mval_fl[2], const char *undo_name);
void end_transform(bContext *C, Object &ob);

View File

@@ -576,6 +576,16 @@ void update_modal_transform(bContext *C, Object &ob)
flush_update_step(C, UpdateType::Position);
}
void cancel_modal_transform(bContext *C, Object &ob)
{
/* Cancelling "Elastic" transforms (due to its TransformDisplacementMode::Incremental nature),
* requires restoring positions from undo. For "All Vertices" there is no benefit in using the
* transform system to update to original positions either. */
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
undo::restore_position_from_undo_step(*depsgraph, ob);
}
void end_transform(bContext *C, Object &ob)
{
SculptSession &ss = *ob.sculpt;

View File

@@ -110,7 +110,13 @@ static void recalcData_sculpt(TransInfo *t)
using namespace blender::ed;
BKE_view_layer_synced_ensure(t->scene, t->view_layer);
Object *ob = BKE_view_layer_active_object_get(t->view_layer);
sculpt_paint::update_modal_transform(t->context, *ob);
if (t->state == TRANS_CANCEL) {
sculpt_paint::cancel_modal_transform(t->context, *ob);
}
else {
sculpt_paint::update_modal_transform(t->context, *ob);
}
}
static void special_aftertrans_update__sculpt(bContext *C, TransInfo *t)