diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-08-12 17:45:07 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-08-12 23:48:00 +0300 |
commit | b126e38f6bcdd6deace59fe89a3200f004814018 (patch) | |
tree | dac6b7ea40a6dc6f03033b41e7eb1a09d8a9998d /source/blender/blenkernel | |
parent | 3d247abb782b23316ff3c5deed0826ad6d14ddc1 (diff) |
GPencil: Fix unreported error in merge similar materials
When the color was black, the original value was not initialized and get a NaN value with unexpected results.
Also cleanup code.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index c64f1b86eab..3039879799d 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1892,7 +1892,12 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, continue; } - for (int idx_secondary = idx_primary + 1; idx_secondary < *totcol; idx_secondary++) { + 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; + } + /* Read secondary material to compare with primary material. */ ma_secondary = BKE_gpencil_material(ob, idx_secondary + 1); if ((ma_secondary == NULL) || @@ -1930,6 +1935,11 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, } float s_hsv_a[3], s_hsv_b[3], f_hsv_a[3], f_hsv_b[3], col[3]; + zero_v3(s_hsv_a); + zero_v3(s_hsv_b); + zero_v3(f_hsv_a); + zero_v3(f_hsv_b); + copy_v3_v3(col, gp_style_primary->stroke_rgba); rgb_to_hsv_compat_v(col, s_hsv_a); copy_v3_v3(col, gp_style_secondary->stroke_rgba); @@ -1943,15 +1953,23 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, /* Check stroke and fill color (only Hue and Saturation). */ 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(s_hsv_a[2], s_hsv_b[2], val_threshold)) || - (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) || - (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold)) || - (!compare_ff(s_hsv_a[2], s_hsv_b[2], val_threshold))) { + (!compare_ff(f_hsv_a[2], f_hsv_b[2], 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)); |