Sculpt: avoid adding ".sculpt_mask" attributes in certain cases

Mask layers were added (unnecessarily) in these cases:
- calling `Mask Slice` without having a mask even (now return
`OPERATOR_CANCELLED` early)
- calling `Mask Extract` without having a mask even (now return
`OPERATOR_CANCELLED` early)
- `Extract Face Set` was also adding a mask layer (only because both
extracts used `geometry_extract_apply`), moved mask specific stuff into
`paint_mask_extract_exec` (see above also)

Came up in !123888

Pull Request: https://projects.blender.org/blender/blender/pulls/133435
This commit is contained in:
Philipp Oeser
2025-01-22 15:25:25 +01:00
committed by Philipp Oeser
parent 549c724f78
commit c0e881cebf

View File

@@ -87,8 +87,6 @@ static int geometry_extract_apply(bContext *C,
blender::ed::sculpt_paint::object_sculpt_mode_exit(C, depsgraph);
BKE_sculpt_mask_layers_ensure(&depsgraph, bmain, ob, nullptr);
/* Ensures that deformation from sculpt mode is taken into account before duplicating the mesh to
* extract the geometry. */
CTX_data_ensure_evaluated_depsgraph(C);
@@ -279,6 +277,12 @@ static void geometry_extract_tag_face_set(BMesh *bm, GeometryExtractParams *para
static int paint_mask_extract_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
Mesh *mesh = static_cast<Mesh *>(ob->data);
if (!mesh->attributes().contains(".sculpt_mask")) {
return OPERATOR_CANCELLED;
}
GeometryExtractParams params;
params.mask_threshold = RNA_float_get(op->ptr, "mask_threshold");
params.num_smooth_iterations = RNA_int_get(op->ptr, "smooth_iterations");
@@ -462,14 +466,16 @@ static int paint_mask_slice_exec(bContext *C, wmOperator *op)
Main &bmain = *CTX_data_main(C);
Object &ob = *CTX_data_active_object(C);
View3D *v3d = CTX_wm_view3d(C);
Mesh *mesh = static_cast<Mesh *>(ob.data);
BKE_sculpt_mask_layers_ensure(nullptr, nullptr, &ob, nullptr);
if (!mesh->attributes().contains(".sculpt_mask")) {
return OPERATOR_CANCELLED;
}
bool create_new_object = RNA_boolean_get(op->ptr, "new_object");
bool fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
float mask_threshold = RNA_float_get(op->ptr, "mask_threshold");
Mesh *mesh = static_cast<Mesh *>(ob.data);
Mesh *new_mesh = (Mesh *)BKE_id_copy(&bmain, &mesh->id);
/* Undo crashes when new object is created in the middle of a sculpt, see #87243. */