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
This commit is contained in:
Pablo Dobarro 2020-03-09 20:10:56 +01:00
parent 0dfb4ac1ff
commit 18e3615a68
Notes: blender-bot 2023-02-14 04:56:36 +01:00
Referenced by issue #74613, Sculpting base color is green
10 changed files with 30 additions and 10 deletions

View File

@ -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 */

View File

@ -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;
}
/**

View File

@ -137,6 +137,7 @@ struct PBVH {
CustomData *pdata;
int face_sets_color_seed;
int face_sets_color_default;
/* Grid Data */
CCGKey gridkey;

View File

@ -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;
}
}
}

View File

@ -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++) {

View File

@ -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);

View File

@ -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;

View File

@ -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, \
}

View File

@ -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;

View File

@ -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 | \