[Bf-blender-cvs] [18e3615a681] master: Face Sets: Use white color for a default Face Set to enable the overlay

Pablo Dobarro noreply at git.blender.org
Mon Mar 9 20:12:11 CET 2020


Commit: 18e3615a68191c9f35303139d109972744499565
Author: Pablo Dobarro
Date:   Mon Mar 9 20:10:56 2020 +0100
Branches: master
https://developer.blender.org/rB18e3615a68191c9f35303139d109972744499565

Face Sets: Use white color for a default Face Set to enable the overlay

This introduces a variable to store a face set ID which is going to be
rendered white. When initializing a mesh or randomizing the colors, this
variable gets updated to always render a white face set. This way the
face set overlay can be enabled without adding colors to the mesh if
face sets are not in use. After creating the first face set, new colors
are generated randomly like usual.

The face set stored as default does not have any special meaning for
tools or brushes, it just affects the rendering color.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7035

===================================================================

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_mesh_defaults.h
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesdna/DNA_view3d_defaults.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 6097fab814f..16a7e4d38d0 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -299,7 +299,7 @@ void BKE_pbvh_grids_update(PBVH *bvh,
                            struct DMFlagMat *flagmats,
                            unsigned int **grid_hidden);
 
-void BKE_pbvh_face_sets_color_seed_set(PBVH *bvh, int seed);
+void BKE_pbvh_face_sets_color_set(PBVH *bvh, int seed, int color_default);
 
 /* Layer displacement */
 
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 61caccccf90..ae20e5d023d 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -565,6 +565,7 @@ void BKE_pbvh_build_mesh(PBVH *bvh,
   bvh->pdata = pdata;
 
   bvh->face_sets_color_seed = mesh->face_sets_color_seed;
+  bvh->face_sets_color_default = mesh->face_sets_color_default;
 
   BB_reset(&cb);
 
@@ -1304,6 +1305,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
                                      CustomData_get_layer(bvh->ldata, CD_MLOOPCOL),
                                      CustomData_get_layer(bvh->pdata, CD_SCULPT_FACE_SETS),
                                      bvh->face_sets_color_seed,
+                                     bvh->face_sets_color_default,
                                      node->face_vert_indices,
                                      update_flags);
         break;
@@ -2615,9 +2617,10 @@ void BKE_pbvh_update_normals(PBVH *bvh, struct SubdivCCG *subdiv_ccg)
   MEM_SAFE_FREE(nodes);
 }
 
-void BKE_pbvh_face_sets_color_seed_set(PBVH *bvh, int seed)
+void BKE_pbvh_face_sets_color_set(PBVH *bvh, int seed, int color_default)
 {
   bvh->face_sets_color_seed = seed;
+  bvh->face_sets_color_default = color_default;
 }
 
 /**
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 51342eb1faa..af92f11e219 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -137,6 +137,7 @@ struct PBVH {
   CustomData *pdata;
 
   int face_sets_color_seed;
+  int face_sets_color_default;
 
   /* Grid Data */
   CCGKey gridkey;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 28f59b6ab07..68f0abe9b3e 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -4796,7 +4796,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
           for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
             if (sl->spacetype == SPACE_VIEW3D) {
               View3D *v3d = (View3D *)sl;
-              v3d->overlay.sculpt_mode_face_sets_opacity = 0.0f;
+              v3d->overlay.sculpt_mode_face_sets_opacity = 1.0f;
             }
           }
         }
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index bb6ac097132..e14e7004bb1 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -10974,7 +10974,10 @@ static int sculpt_face_sets_randomize_colors_invoke(bContext *C,
 
   int new_seed = BLI_hash_int(PIL_check_seconds_timer_i() & UINT_MAX);
   mesh->face_sets_color_seed = new_seed;
-  BKE_pbvh_face_sets_color_seed_set(pbvh, new_seed);
+  if (ss->face_sets) {
+    mesh->face_sets_color_default = ss->face_sets[0];
+  }
+  BKE_pbvh_face_sets_color_set(pbvh, new_seed, mesh->face_sets_color_default);
 
   BKE_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
   for (int i = 0; i < totnode; i++) {
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index f5f7f9ee07c..9d17b199722 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -83,6 +83,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                   const struct MLoopCol *vcol,
                                   const int *sculpt_face_sets,
                                   const int face_sets_color_seed,
+                                  const int face_sets_color_default,
                                   const int (*face_vert_indices)[3],
                                   const int update_flags);
 
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 6671296db2a..5eae86e50f0 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -213,6 +213,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
                                   const MLoopCol *vcol,
                                   const int *sculpt_face_sets,
                                   const int face_sets_color_seed,
+                                  const int face_sets_color_default,
                                   const int (*face_vert_indices)[3],
                                   const int update_flags)
 {
@@ -267,8 +268,12 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
         for (uint i = 0; i < buffers->face_indices_len; i++) {
           if (show_face_sets) {
             const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
-            face_set_overlay_color_get(
-                sculpt_face_sets[lt->poly], face_sets_color_seed, face_set_color);
+            const int fset = abs(sculpt_face_sets[lt->poly]);
+
+            /* Skip for the default color Face Set to render it white. */
+            if (fset != face_sets_color_default) {
+              face_set_overlay_color_get(fset, face_sets_color_seed, face_set_color);
+            }
           }
           for (int j = 0; j < 3; j++) {
             const int vidx = face_vert_indices[i][j];
@@ -325,8 +330,11 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
 
           uchar face_set_color[4] = {UCHAR_MAX, UCHAR_MAX, UCHAR_MAX, UCHAR_MAX};
           if (show_face_sets) {
-            face_set_overlay_color_get(
-                sculpt_face_sets[lt->poly], face_sets_color_seed, face_set_color);
+            const int fset = abs(sculpt_face_sets[lt->poly]);
+            /* Skip for the default color Face Set to render it white. */
+            if (fset != face_sets_color_default) {
+              face_set_overlay_color_get(fset, face_sets_color_seed, face_set_color);
+            }
           }
 
           float fmask = 0.0f;
diff --git a/source/blender/makesdna/DNA_mesh_defaults.h b/source/blender/makesdna/DNA_mesh_defaults.h
index 275bcc64562..abcdf8bf57b 100644
--- a/source/blender/makesdna/DNA_mesh_defaults.h
+++ b/source/blender/makesdna/DNA_mesh_defaults.h
@@ -36,6 +36,7 @@
     .remesh_voxel_size = 0.1f, \
     .remesh_voxel_adaptivity = 0.0f, \
     .face_sets_color_seed = 0, \
+    .face_sets_color_default = 1, \
     .flag = ME_REMESH_FIX_POLES | ME_REMESH_REPROJECT_VOLUME, \
   }
 
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index c0c7c0465bb..5f915d4516b 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -197,9 +197,12 @@ typedef struct Mesh {
   float remesh_voxel_adaptivity;
   char remesh_mode;
 
-  char _pad1[7];
+  char _pad1[3];
 
   int face_sets_color_seed;
+  /* Stores the initial Face Set to be rendered white. This way the overlay can be enabled by
+   * default and Face Sets can be used without affecting the color of the mesh. */
+  int face_sets_color_default;
 
   /** Deprecated multiresolution modeling data, only keep for loading old files. */
   struct Multires *mr DNA_DEPRECATED;
diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h
index c139d4dc0d1..afade37d0c8 100644
--- a/source/blender/makesdna/DNA_view3d_defaults.h
+++ b/source/blender/makesdna/DNA_view3d_defaults.h
@@ -59,7 +59,7 @@
     /* Intentionally different to vertex/paint mode, \
      * we typically want to see shading too. */ \
     .sculpt_mode_mask_opacity = 0.75f, \
-    .sculpt_mode_face_sets_opacity = 0.0f, \
+    .sculpt_mode_face_sets_opacity = 1.0f, \
  \
     .edit_flag = V3D_OVERLAY_EDIT_FACES | V3D_OVERLAY_EDIT_SEAMS | \
                              V3D_OVERLAY_EDIT_SHARP | V3D_OVERLAY_EDIT_FREESTYLE_EDGE | \



More information about the Bf-blender-cvs mailing list