temp-sculpt-colors: implement patch review items

This commit is contained in:
Joseph Eagar 2021-11-03 15:06:27 -07:00
parent 3efad90211
commit a8fa8bf364
10 changed files with 66 additions and 124 deletions

View File

@ -467,7 +467,6 @@ typedef struct SculptSession {
struct KeyBlock *shapekey_active;
struct MPropCol *vcol;
float (*f3col)[3];
struct MLoopCol *mcol;
int vcol_domain;

View File

@ -1680,15 +1680,11 @@ static void sculpt_update_object(Depsgraph *depsgraph,
ss->vcol = NULL;
ss->mcol = NULL;
ss->f3col = NULL;
if (BKE_pbvh_get_color_layer(me, &cl, &domain)) {
if (cl->type == CD_PROP_COLOR) {
ss->vcol = cl->data;
}
else if (cl->type == CD_PROP_FLOAT3) {
ss->f3col = cl->data;
}
else {
ss->mcol = cl->data;
}
@ -1824,7 +1820,7 @@ void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
{
Mesh *orig_me = BKE_object_get_original_mesh(object);
int types[] = {CD_PROP_COLOR, CD_PROP_FLOAT3, CD_MLOOPCOL};
int types[] = {CD_PROP_COLOR, CD_MLOOPCOL};
bool has_color = false;
for (int i = 0; i < 3; i++) {
@ -1840,7 +1836,7 @@ void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
CustomDataLayer *cl;
if (has_color) {
cl = BKE_id_attributes_active_get(&orig_me->id);
if (!ELEM(cl->type, CD_PROP_COLOR, CD_MLOOPCOL, CD_PROP_FLOAT3)) {
if (!ELEM(cl->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
cl = NULL;
/* find a color layer */
@ -1848,7 +1844,7 @@ void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
CustomData *cdata = step ? &orig_me->ldata : &orig_me->vdata;
for (int i = 0; i < cdata->totlayer; i++) {
if (ELEM(cdata->layers[i].type, CD_PROP_COLOR, CD_MLOOPCOL, CD_PROP_FLOAT3)) {
if (ELEM(cdata->layers[i].type, CD_PROP_COLOR, CD_MLOOPCOL)) {
cl = cdata->layers + i;
break;
}

View File

@ -1264,7 +1264,7 @@ bool BKE_pbvh_get_color_layer(const Mesh *me, CustomDataLayer **r_cl, AttributeD
CustomDataLayer *cl = BKE_id_attributes_active_get((ID *)me);
AttributeDomain domain;
if (!cl || !ELEM(cl->type, CD_PROP_FLOAT3, CD_PROP_COLOR, CD_MLOOPCOL)) {
if (!cl || !ELEM(cl->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
return false;
}

View File

@ -468,7 +468,7 @@ static bool mesh_cd_calc_active_vcol_layer(Mesh *me, DRW_MeshAttributes *attrs_u
int type, idx = -1;
AttributeDomain domain;
if (layer && ELEM(layer->type, CD_PROP_FLOAT3, CD_PROP_COLOR, CD_MLOOPCOL)) {
if (layer && ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
domain = BKE_id_attribute_domain((ID *)me, layer);
type = layer->type;
@ -661,11 +661,11 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
cd_used.orco = 1;
break;
}
case CD_PROP_FLOAT3:
case CD_PROP_COLOR:
cd_used.vcol = 1;
/* fallthrough */
case CD_PROP_FLOAT3:
case CD_PROP_BOOL:
case CD_PROP_INT32:
case CD_PROP_FLOAT:

View File

@ -95,18 +95,6 @@ template<> struct attribute_type_converter<MPropCol, gpuMeshCol> {
}
};
template<> struct attribute_type_converter<MLoopCol, gpuMeshCol> {
static gpuMeshCol convert_value(MLoopCol value)
{
gpuMeshCol result;
result.r = value.r * 257;
result.g = value.g * 257;
result.b = value.b * 257;
result.a = value.a * 257;
return result;
}
};
/* Return the number of component for the attribute's value type, or 0 if is it unsupported. */
static uint gpu_component_size_for_attribute_type(CustomDataType type)
{
@ -340,10 +328,6 @@ static void extract_attr_init(const MeshRenderData *mr,
extract_attr_generic<MPropCol, gpuMeshCol>(mr, vbo, request);
break;
}
case CD_MLOOPCOL: {
extract_attr_generic<MLoopCol, gpuMeshCol>(mr, vbo, request);
break;
}
default: {
BLI_assert(false);
}

View File

@ -77,7 +77,7 @@ static void extract_vcol_init(const MeshRenderData *mr,
note that there are three color attribute types that operate over two domains
(verts and face corners)
*/
int vcol_types[3] = {CD_MLOOPCOL, CD_PROP_COLOR, CD_PROP_FLOAT3};
int vcol_types[2] = {CD_MLOOPCOL, CD_PROP_COLOR};
CustomDataLayer *actlayer = BKE_id_attributes_active_get((ID *)mr->me);
AttributeDomain actdomain = actlayer ? BKE_id_attribute_domain((ID *)mr->me, actlayer) :
@ -89,7 +89,7 @@ static void extract_vcol_init(const MeshRenderData *mr,
actn = actlayer - (cdata->layers + cdata->typemap[actlayer->type]);
}
for (int i = 0; i < 3; i++) {
for (int i = 0; i < ARRAY_SIZE(vcol_types); i++) {
int type = vcol_types[i];
for (int step = 0; step < 2; step++) {
@ -159,28 +159,27 @@ static void extract_vcol_init(const MeshRenderData *mr,
BMElem *elem = step ? (BMElem *)l_iter : (BMElem *)l_iter->v;
switch (type) {
case CD_PROP_FLOAT3:
case CD_PROP_COLOR: {
float *color = (float *)BM_ELEM_CD_GET_VOID_P(elem, cd_vcol);
vcol_data->r = unit_float_to_ushort_clamp(color[0]);
vcol_data->g = unit_float_to_ushort_clamp(color[1]);
vcol_data->b = unit_float_to_ushort_clamp(color[2]);
vcol_data->a = unit_float_to_ushort_clamp(type == CD_PROP_COLOR ? color[3] :
1.0f);
vcol_data->a = unit_float_to_ushort_clamp(color[3]);
break;
}
case CD_MLOOPCOL: {
MLoopCol *mloopcol = (MLoopCol *)BM_ELEM_CD_GET_VOID_P(elem, cd_vcol);
float temp[4];
vcol_data->r = unit_float_to_ushort_clamp(
BLI_color_from_srgb_table[mloopcol->r]);
vcol_data->g = unit_float_to_ushort_clamp(
BLI_color_from_srgb_table[mloopcol->r]);
vcol_data->b = unit_float_to_ushort_clamp(
BLI_color_from_srgb_table[mloopcol->r]);
vcol_data->a = unit_float_to_ushort_clamp(mloopcol->a * (1.0f / 255.0f));
MLoopCol *mloopcol = (MLoopCol *)BM_ELEM_CD_GET_VOID_P(elem, cd_vcol);
rgba_float_to_uchar((unsigned char *)mloopcol, temp);
linearrgb_to_srgb_v3_v3(temp, temp);
vcol_data->r = unit_float_to_ushort_clamp(temp[0]);
vcol_data->g = unit_float_to_ushort_clamp(temp[1]);
vcol_data->b = unit_float_to_ushort_clamp(temp[2]);
vcol_data->a = unit_float_to_ushort_clamp(temp[3]);
break;
}
}
@ -195,31 +194,6 @@ static void extract_vcol_init(const MeshRenderData *mr,
};
switch (type) {
case CD_PROP_FLOAT3: {
MPropCol3 *colors = (MPropCol3 *)cdata->layers[idx].data;
if (step) {
for (int k = 0; k < mr->loop_len; k++, vcol_data++, colors++) {
vcol_data->r = unit_float_to_ushort_clamp(colors->color[0]);
vcol_data->g = unit_float_to_ushort_clamp(colors->color[1]);
vcol_data->b = unit_float_to_ushort_clamp(colors->color[2]);
unit_float_to_ushort_clamp(1.0f);
}
}
else {
const MLoop *ml = mr->mloop;
for (int k = 0; k < mr->loop_len; k++, vcol_data++, ml++) {
MPropCol3 *color = colors + ml->v;
vcol_data->r = unit_float_to_ushort_clamp(color->color[0]);
vcol_data->g = unit_float_to_ushort_clamp(color->color[1]);
vcol_data->b = unit_float_to_ushort_clamp(color->color[2]);
vcol_data->a = unit_float_to_ushort_clamp(1.0f);
}
}
break;
}
case CD_PROP_COLOR: {
MPropCol *colors = (MPropCol *)cdata->layers[idx].data;
@ -250,10 +224,14 @@ static void extract_vcol_init(const MeshRenderData *mr,
if (step) {
for (int k = 0; k < mr->loop_len; k++, vcol_data++, colors++) {
vcol_data->r = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[colors->r]);
vcol_data->g = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[colors->g]);
vcol_data->b = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[colors->b]);
vcol_data->a = unit_float_to_ushort_clamp((float)colors->a * (1.0f / 255.0f));
float temp[4];
rgba_float_to_uchar((unsigned char *)colors, temp);
linearrgb_to_srgb_v3_v3(temp, temp);
vcol_data->r = unit_float_to_ushort_clamp(temp[0]);
vcol_data->g = unit_float_to_ushort_clamp(temp[1]);
vcol_data->b = unit_float_to_ushort_clamp(temp[2]);
vcol_data->a = unit_float_to_ushort_clamp(temp[3]);
}
}
else {
@ -261,11 +239,15 @@ static void extract_vcol_init(const MeshRenderData *mr,
for (int k = 0; k < mr->loop_len; k++, vcol_data++, ml++) {
MLoopCol *color = colors + ml->v;
float temp[4];
vcol_data->r = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[color->r]);
vcol_data->g = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[color->g]);
vcol_data->b = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[color->b]);
vcol_data->a = unit_float_to_ushort_clamp((float)color->a * (1.0f / 255.0f));
rgba_float_to_uchar((unsigned char *)color, temp);
linearrgb_to_srgb_v3_v3(temp, temp);
vcol_data->r = unit_float_to_ushort_clamp(temp[0]);
vcol_data->g = unit_float_to_ushort_clamp(temp[1]);
vcol_data->b = unit_float_to_ushort_clamp(temp[2]);
vcol_data->a = unit_float_to_ushort_clamp(temp[3]);
}
}
break;

View File

@ -158,14 +158,14 @@ const float *SCULPT_vertex_co_get(SculptSession *ss, int index)
bool SCULPT_has_colors(const SculptSession *ss)
{
return ss->vcol || ss->mcol || ss->f3col;
return ss->vcol || ss->mcol;
}
bool SCULPT_vertex_color_get(SculptSession *ss, int index, float out[4])
{
switch (BKE_pbvh_type(ss->pbvh)) {
case PBVH_FACES:
if (!(ss->vcol || ss->mcol || ss->f3col)) {
if (!(ss->vcol || ss->mcol)) {
zero_v4(out);
return false;
}
@ -187,16 +187,14 @@ bool SCULPT_vertex_color_get(SculptSession *ss, int index, float out[4])
if (ss->vcol_type == CD_MLOOPCOL) {
MLoopCol *col = ss->mcol + li;
float tmp[4];
float temp[4];
rgba_uchar_to_float(tmp, (const char *)col);
add_v4_v4(out, tmp);
rgba_uchar_to_float(temp, (const char *)col);
srgb_to_linearrgb_v3_v3(temp, temp);
add_v4_v4(out, temp);
}
else if (ss->vcol_type == CD_PROP_FLOAT3) {
add_v3_v3(out, ss->f3col[li]);
out[3] += 1.0f;
}
else {
else if (ss->vcol_type == CD_PROP_COLOR) {
add_v4_v4(out, ss->vcol[li].color);
}
}
@ -210,20 +208,18 @@ bool SCULPT_vertex_color_get(SculptSession *ss, int index, float out[4])
if (ss->vcol_type == CD_MLOOPCOL) {
MLoopCol *col = ss->mcol + index;
float tmp[4];
rgba_uchar_to_float(tmp, (const char *)col);
copy_v4_v4(out, tmp);
float temp[4];
rgba_uchar_to_float(temp, (const char *)col);
srgb_to_linearrgb_v3_v3(temp, temp);
copy_v4_v4(out, temp);
}
else if (ss->vcol_type == CD_PROP_FLOAT3) {
copy_v3_v3(out, ss->f3col[index]);
out[3] = 1.0f;
}
else {
if (ss->vcol_type == CD_PROP_COLOR) {
copy_v4_v4(out, ss->vcol[index].color);
}
}
return ss->vcol || ss->mcol || ss->f3col;
return ss->vcol || ss->mcol;
case PBVH_BMESH:
case PBVH_GRIDS:
break;
@ -236,7 +232,7 @@ void SCULPT_vertex_color_set(SculptSession *ss, int index, float color[4])
{
switch (BKE_pbvh_type(ss->pbvh)) {
case PBVH_FACES:
if (!(ss->vcol || ss->mcol || ss->f3col)) {
if (!(ss->vcol || ss->mcol)) {
return;
}
@ -253,17 +249,16 @@ void SCULPT_vertex_color_set(SculptSession *ss, int index, float color[4])
}
if (ss->vcol_type == CD_MLOOPCOL) {
float temp[4];
MLoopCol *col = ss->mcol + li;
col->r = (unsigned char)(color[0] * 255.0f);
col->g = (unsigned char)(color[1] * 255.0f);
col->b = (unsigned char)(color[2] * 255.0f);
col->a = (unsigned char)(color[3] * 255.0f);
linearrgb_to_srgb_v3_v3(temp, color);
temp[4] = color[4];
rgba_float_to_uchar((char *)col, temp);
}
else if (ss->vcol_type == CD_PROP_FLOAT3) {
copy_v3_v3(ss->f3col[li], color);
}
else {
else if (ss->vcol_type == CD_PROP_COLOR) {
copy_v4_v4(ss->vcol[li].color, color);
}
}
@ -272,16 +267,14 @@ void SCULPT_vertex_color_set(SculptSession *ss, int index, float color[4])
else {
if (ss->vcol_type == CD_MLOOPCOL) {
MLoopCol *col = ss->mcol + index;
float temp[4];
col->r = (unsigned char)(color[0] * 255.0f);
col->g = (unsigned char)(color[1] * 255.0f);
col->b = (unsigned char)(color[2] * 255.0f);
col->a = (unsigned char)(color[3] * 255.0f);
linearrgb_to_srgb_v3_v3(temp, color);
temp[4] = color[4];
rgba_float_to_uchar((char *)col, temp);
}
else if (ss->vcol_type == CD_PROP_FLOAT3) {
copy_v3_v3(ss->f3col[index], color);
}
else {
if (ss->vcol_type == CD_PROP_COLOR) {
copy_v4_v4(ss->vcol[index].color, color);
}
}

View File

@ -1570,16 +1570,12 @@ static void sculpt_undosys_step_decode_undo_impl(struct bContext *C,
BLI_assert(us->step.is_applied == true);
sculpt_undo_restore_list(C, depsgraph, &us->data.nodes);
us->step.is_applied = false;
// sculpt_undo_load_vcol_layer(C, us);
}
static void sculpt_undosys_step_decode_redo_impl(struct bContext *C,
Depsgraph *depsgraph,
SculptUndoStep *us)
{
// sculpt_undo_load_vcol_layer(C, us);
BLI_assert(us->step.is_applied == false);
sculpt_undo_restore_list(C, depsgraph, &us->data.nodes);
us->step.is_applied = true;
@ -1635,9 +1631,6 @@ static void sculpt_undosys_step_decode_redo(struct bContext *C,
if (us_iter == us) {
sculpt_undo_set_active_layer(C, &((SculptUndoStep *)us_iter)->active_attr_end);
// if (us_iter->step.next && us_iter->step.next->type == BKE_UNDOSYS_TYPE_SCULPT) {
// sculpt_undo_load_vcol_layer(C, (SculptUndoStep *)us_iter->step.next);
//}
break;
}
us_iter = (SculptUndoStep *)us_iter->step.next;

View File

@ -456,7 +456,7 @@ static void panelRegister(ARegionType *region_type)
region_type, "vertex_vgroup", "Vertex Groups", NULL, vertex_vgroup_panel_draw, vertex_panel);
modifier_subpanel_register(
region_type, "vert_propcol", "Sculpt Colors", NULL, vert_propcol_panel_draw, vertex_panel);
region_type, "vert_propcol", "Colors", NULL, vert_propcol_panel_draw, vertex_panel);
modifier_subpanel_register(
region_type, "edge", "", edge_panel_draw_header, edge_panel_draw, panel_type);
@ -469,7 +469,7 @@ static void panelRegister(ARegionType *region_type)
panel_type);
modifier_subpanel_register(region_type,
"face_corner_vcol",
"Vertex Colors",
"Colors",
NULL,
face_corner_vcol_panel_draw,
face_corner_panel);

View File

@ -213,11 +213,6 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
else {
brush = BKE_brush_add(bmain, items[i].name, paint->runtime.ob_mode);
if (paint->runtime.ob_mode == OB_MODE_SCULPT) {
brush->sculpt_tool = slot_index;
BKE_brush_sculpt_reset(brush);
}
BKE_brush_tool_set(brush, paint, slot_index);
}
BKE_paint_brush_set(paint, brush);