GPencil: Fix unreported problem in merge similar materials

When two similar colors were adjacent, the colors were not merged.
This commit is contained in:
Antonio Vazquez 2020-08-12 19:18:59 +02:00
parent b126e38f6b
commit 01636ed159
2 changed files with 26 additions and 16 deletions

View File

@ -1879,6 +1879,7 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
Material *ma_secondary = NULL;
MaterialGPencilStyle *gp_style_primary = NULL;
MaterialGPencilStyle *gp_style_secondary = NULL;
GHash *mat_used = BLI_ghash_int_new(__func__);
short *totcol = BKE_object_material_len_p(ob);
if (totcol == 0) {
@ -1891,12 +1892,14 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
if (ma_primary == NULL) {
continue;
}
for (int idx_secondary = 0; idx_secondary < *totcol; idx_secondary++) {
if ((idx_secondary == idx_primary) ||
BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) {
continue;
}
if (BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_secondary))) {
continue;
}
/* Read secondary material to compare with primary material. */
ma_secondary = BKE_gpencil_material(ob, idx_secondary + 1);
@ -1950,32 +1953,35 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob,
copy_v3_v3(col, gp_style_secondary->fill_rgba);
rgb_to_hsv_compat_v(col, f_hsv_b);
/* Check stroke and fill color (only Hue and Saturation). */
/* Check stroke and fill color. */
if ((!compare_ff(s_hsv_a[0], s_hsv_b[0], hue_threshold)) ||
(!compare_ff(s_hsv_a[1], s_hsv_b[1], sat_threshold)) ||
(!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) ||
(!compare_ff(f_hsv_a[0], f_hsv_b[0], hue_threshold)) ||
(!compare_ff(f_hsv_a[1], f_hsv_b[1], sat_threshold)) ||
(!compare_ff(f_hsv_a[2], f_hsv_b[2], val_threshold))) {
(!compare_ff(f_hsv_a[2], f_hsv_b[2], val_threshold)) ||
(!compare_ff(gp_style_primary->stroke_rgba[3],
gp_style_secondary->stroke_rgba[3],
val_threshold)) ||
(!compare_ff(
gp_style_primary->fill_rgba[3], gp_style_secondary->fill_rgba[3], val_threshold))) {
continue;
}
gp_style_secondary->stroke_rgba[0] = 0.0f;
gp_style_secondary->stroke_rgba[1] = 1.0f;
gp_style_secondary->stroke_rgba[2] = 0.0f;
gp_style_secondary->stroke_rgba[3] = 1.0f;
gp_style_secondary->fill_rgba[0] = 1.0f;
gp_style_secondary->fill_rgba[1] = 0.0f;
gp_style_secondary->fill_rgba[2] = 0.0f;
gp_style_secondary->fill_rgba[3] = 1.0f;
/* Save conversion indexes. */
BLI_ghash_insert(
r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary));
changed = true;
if (!BLI_ghash_haskey(r_mat_table, POINTER_FROM_INT(idx_secondary))) {
BLI_ghash_insert(
r_mat_table, POINTER_FROM_INT(idx_secondary), POINTER_FROM_INT(idx_primary));
changed = true;
if (!BLI_ghash_haskey(mat_used, POINTER_FROM_INT(idx_primary))) {
BLI_ghash_insert(mat_used, POINTER_FROM_INT(idx_primary), POINTER_FROM_INT(idx_primary));
}
}
}
}
/* Free hash memory. */
BLI_ghash_free(mat_used, NULL, NULL);
return changed;
}

View File

@ -64,10 +64,12 @@ static int gpencil_check_same_material_color(Object *ob_gp,
float hsv_stroke[4], hsv_fill[4];
copy_v4_v4(color_cu, color_stroke);
zero_v3(hsv_stroke);
rgb_to_hsv_v(color_cu, hsv_stroke);
hsv_stroke[3] = color_stroke[3];
copy_v4_v4(color_cu, color_fill);
zero_v3(hsv_fill);
rgb_to_hsv_v(color_cu, hsv_fill);
hsv_fill[3] = color_fill[3];
@ -91,6 +93,7 @@ static int gpencil_check_same_material_color(Object *ob_gp,
/* Check color with small tolerance (better result in HSV). */
float hsv2[4];
if (do_fill) {
zero_v3(hsv2);
rgb_to_hsv_v(gp_style->fill_rgba, hsv2);
hsv2[3] = gp_style->fill_rgba[3];
if (compare_v4v4(hsv_fill, hsv2, 0.01f)) {
@ -104,6 +107,7 @@ static int gpencil_check_same_material_color(Object *ob_gp,
}
if (do_stroke) {
zero_v3(hsv2);
rgb_to_hsv_v(gp_style->stroke_rgba, hsv2);
hsv2[3] = gp_style->stroke_rgba[3];
if (compare_v4v4(hsv_stroke, hsv2, 0.01f)) {