From ca7414c4cb4c85a337dbe3effb76b9a5b1ad7d83 Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Tue, 18 Aug 2020 12:19:39 +0200 Subject: Fix Mask Slice deleting the Face Sets This was a TODO in the code. Previously the Face Set datalayer was deleted and recreated with a constant ID of 0. Now the datalayer is preserved and set to the SculptSession after slicing the mask and a new ID is calculated for the new faces that the slicing operation produced, so they can be easily isolated for further tweaking. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8583 --- .../blender/editors/sculpt_paint/sculpt_face_set.c | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.c b/source/blender/editors/sculpt_paint/sculpt_face_set.c index 2afa3556dd9..cd0720bbe1c 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.c +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.c @@ -71,6 +71,37 @@ #include #include +/* Utils. */ +int ED_sculpt_face_sets_find_next_available_id(struct Mesh *mesh) +{ + int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS); + if (!face_sets) { + return SCULPT_FACE_SET_NONE; + } + + int next_face_set_id = 0; + for (int i = 0; i < mesh->totpoly; i++) { + next_face_set_id = max_ii(next_face_set_id, abs(face_sets[i])); + } + next_face_set_id++; + + return next_face_set_id; +} + +void ED_sculpt_face_sets_initialize_none_to_id(struct Mesh *mesh, const int new_id) +{ + int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS); + if (!face_sets) { + return; + } + + for (int i = 0; i < mesh->totpoly; i++) { + if (face_sets[i] == SCULPT_FACE_SET_NONE) { + face_sets[i] = new_id; + } + } +} + /* Draw Face Sets Brush. */ static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata, -- cgit v1.2.3