[Bf-blender-cvs] [e03ebc88ca4] greasepencil-object: GPencil: Add new parameters to merge materials

Antonio Vazquez noreply at git.blender.org
Thu Nov 14 16:16:37 CET 2019


Commit: e03ebc88ca48b055e62a9a7ee233bd844cbefbe3
Author: Antonio Vazquez
Date:   Thu Nov 14 16:16:29 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe03ebc88ca48b055e62a9a7ee233bd844cbefbe3

GPencil: Add new parameters to merge materials

Now the user can control de Hue, Saturation and Value range.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_merge.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 4c1ea3a761e..20ff038ea03 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -125,7 +125,9 @@ void BKE_gpencil_material_remap(struct bGPdata *gpd,
                                 const unsigned int *remap,
                                 unsigned int remap_len);
 bool BKE_gpencil_merge_materials_table_get(struct Object *ob,
-                                           float threshold,
+                                           const float hue_threshold,
+                                           const float sat_threshold,
+                                           const float val_threshold,
                                            struct GHash *r_mat_table);
 
 /* statistics functions */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 7f5c9d3aabc..1c8faaec227 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2120,7 +2120,11 @@ void BKE_gpencil_material_remap(struct bGPdata *gpd,
 }
 
 /* Load a table with material conversion index for merged materials. */
-bool BKE_gpencil_merge_materials_table_get(Object *ob, float threshold, GHash *r_mat_table)
+bool BKE_gpencil_merge_materials_table_get(Object *ob,
+                                           const float hue_threshold,
+                                           const float sat_threshold,
+                                           const float val_threshold,
+                                           GHash *r_mat_table)
 {
   bool changed = false;
 
@@ -2178,15 +2182,26 @@ bool BKE_gpencil_merge_materials_table_get(Object *ob, float threshold, GHash *r
         continue;
       }
 
-      float stroke_a[4], stroke_b[4], fill_a[4], fill_b[4];
-      copy_v4_v4(stroke_a, gp_style_primary->stroke_rgba);
-      copy_v4_v4(stroke_b, gp_style_secondary->stroke_rgba);
-      copy_v4_v4(fill_a, gp_style_primary->fill_rgba);
-      copy_v4_v4(fill_b, gp_style_secondary->fill_rgba);
-
-      /* Check stroke and fill color. */
-      if ((!compare_v4v4(stroke_a, stroke_b, threshold)) ||
-          (!compare_v4v4(fill_a, fill_b, threshold))) {
+      float s_hsv_a[3], s_hsv_b[3], f_hsv_a[3], f_hsv_b[3], col[3];
+      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);
+      rgb_to_hsv_compat_v(col, s_hsv_b);
+
+      copy_v3_v3(col, gp_style_primary->fill_rgba);
+      rgb_to_hsv_compat_v(col, f_hsv_a);
+      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). */
+      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(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))) {
         continue;
       }
 
diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c
index cbba50c2984..3fd273a78a8 100644
--- a/source/blender/editors/gpencil/gpencil_merge.c
+++ b/source/blender/editors/gpencil/gpencil_merge.c
@@ -592,7 +592,9 @@ static int gp_stroke_merge_material_exec(bContext *C, wmOperator *op)
 {
   Object *ob = CTX_data_active_object(C);
   bGPdata *gpd = (bGPdata *)ob->data;
-  const float threshold = RNA_float_get(op->ptr, "threshold");
+  const float hue_threshold = RNA_float_get(op->ptr, "hue_threshold");
+  const float sat_threshold = RNA_float_get(op->ptr, "sat_threshold");
+  const float val_threshold = RNA_float_get(op->ptr, "val_threshold");
 
   /* Review materials. */
   GHash *mat_table = BLI_ghash_int_new(__func__);
@@ -602,7 +604,8 @@ static int gp_stroke_merge_material_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  bool changed = BKE_gpencil_merge_materials_table_get(ob, threshold, mat_table);
+  bool changed = BKE_gpencil_merge_materials_table_get(
+      ob, hue_threshold, sat_threshold, val_threshold, mat_table);
 
   int removed = BLI_ghash_len(mat_table);
 
@@ -648,7 +651,7 @@ void GPENCIL_OT_stroke_merge_material(wmOperatorType *ot)
   PropertyRNA *prop;
 
   /* identifiers */
-  ot->name = "Merge Stroke Materials";
+  ot->name = "Merge Grease Pencil Materials";
   ot->idname = "GPENCIL_OT_stroke_merge_material";
   ot->description = "Replace materials in strokes merging similar";
 
@@ -660,7 +663,12 @@ void GPENCIL_OT_stroke_merge_material(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
   /* properties */
-  prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f);
+  prop = RNA_def_float(
+      ot->srna, "hue_threshold", 0.001f, 0.0f, 1.0f, "Hue Threshold", "", 0.0f, 1.0f);
+  prop = RNA_def_float(
+      ot->srna, "sat_threshold", 0.001f, 0.0f, 1.0f, "Saturation Threshold", "", 0.0f, 1.0f);
+  prop = RNA_def_float(
+      ot->srna, "val_threshold", 0.001f, 0.0f, 1.0f, "Value Threshold", "", 0.0f, 1.0f);
   /* avoid re-using last var */
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }



More information about the Bf-blender-cvs mailing list