Fix T80771: Avoid changing the visibility of loose geometry when entering Sculpt Mode

When entering scultp mode the visibility from the Face Sets is copied to
the base mesh. This steps was considering that if a vertex belongs to a
face with a visibible Face Set ID, it should be visible. As loose
geometry may not have any faces, those vertex were set to hidden.

Now this function check if a vertex visibility should be modified by the
face sets (by checking the loops), avoiding modifying the visibility of
loose geometry unintentionally.

Reviewed By: sergey

Maniphest Tasks: T80771

Differential Revision: https://developer.blender.org/D8899
This commit is contained in:
Pablo Dobarro 2020-09-17 23:51:01 +02:00
parent adfbb77b20
commit cacd57b67a
Notes: blender-bot 2023-02-13 23:17:13 +01:00
Referenced by issue #82709, Faces with no vertex bug.
Referenced by issue #80771, Mode switching hides vertices in Edit mode (Weight paint / Sculpt mode --> Edit mode)
Referenced by issue #80396, Potential candidates for corrective releases
Referenced by issue #80274, Visibility not correctly synced between Sculpt & Edit Mode
1 changed files with 20 additions and 7 deletions

View File

@ -1885,18 +1885,31 @@ static void sculpt_sync_face_sets_visibility_to_base_mesh(Mesh *mesh)
return;
}
for (int i = 0; i < mesh->totvert; i++) {
mesh->mvert[i].flag |= ME_HIDE;
}
/* Enabled if the vertex should be visible according to the Face Sets. */
BLI_bitmap *visibile_vertex = BLI_BITMAP_NEW(mesh->totvert, "visible vertices");
/* Enabled if the visibility of this vertex can be affected by the Face Sets to avoid modifying
* disconnected geometry. */
BLI_bitmap *modified_vertex = BLI_BITMAP_NEW(mesh->totvert, "modified vertices");
for (int i = 0; i < mesh->totpoly; i++) {
if (face_sets[i] >= 0) {
for (int l = 0; l < mesh->mpoly[i].totloop; l++) {
MLoop *loop = &mesh->mloop[mesh->mpoly[i].loopstart + l];
mesh->mvert[loop->v].flag &= ~ME_HIDE;
const bool is_face_set_visible = face_sets[i] >= 0;
for (int l = 0; l < mesh->mpoly[i].totloop; l++) {
MLoop *loop = &mesh->mloop[mesh->mpoly[i].loopstart + l];
if (is_face_set_visible) {
BLI_BITMAP_ENABLE(visibile_vertex, loop->v);
}
BLI_BITMAP_ENABLE(modified_vertex, loop->v);
}
}
for (int i = 0; i < mesh->totvert; i++) {
if (BLI_BITMAP_TEST(modified_vertex, i) && !BLI_BITMAP_TEST(visibile_vertex, i)) {
mesh->mvert[i].flag |= ME_HIDE;
}
}
MEM_SAFE_FREE(visibile_vertex);
MEM_SAFE_FREE(modified_vertex);
}
static void sculpt_sync_face_sets_visibility_to_grids(Mesh *mesh, SubdivCCG *subdiv_ccg)