[Bf-blender-cvs] [47ba69079b2] greasepencil-object: GPencil: Handle Stroke opacity in SVG export

Antonio Vazquez noreply at git.blender.org
Fri Jul 31 17:24:15 CEST 2020


Commit: 47ba69079b2153454dd89003b13b690deda9975a
Author: Antonio Vazquez
Date:   Fri Jul 31 17:23:25 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB47ba69079b2153454dd89003b13b690deda9975a

GPencil: Handle Stroke opacity in SVG export

Also removed stroke for filled areas is the stroke is disabled

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

M	source/blender/io/gpencil/intern/gpencil_io_base.cc
M	source/blender/io/gpencil/intern/gpencil_io_base.h
M	source/blender/io/gpencil/intern/gpencil_io_svg.cc

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

diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 2b46cc96b70..762e8546b02 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -294,19 +294,26 @@ void GpencilExporter::gps_current_set(struct Object *ob,
   gps_cur = gps;
   if (set_colors) {
     gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
-    gp_style_current_set(gp_style);
+
+    is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
+                 (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+    is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
+               (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
 
     /* Stroke color. */
     copy_v4_v4(stroke_color, gp_style->stroke_rgba);
+    avg_opacity = 0;
     /* Get average vertex color and apply. */
     float avg_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
     for (int i = 0; i < gps->totpoints; i++) {
       bGPDspoint *pt = &gps->points[i];
       add_v4_v4(avg_color, pt->vert_color);
+      avg_opacity += pt->strength;
     }
 
     mul_v4_v4fl(avg_color, avg_color, 1.0f / (float)gps->totpoints);
     interp_v3_v3v3(stroke_color, stroke_color, avg_color, avg_color[3]);
+    avg_opacity /= (float)gps->totpoints;
 
     /* Fill color. */
     copy_v4_v4(fill_color, gp_style->fill_rgba);
@@ -315,15 +322,6 @@ void GpencilExporter::gps_current_set(struct Object *ob,
   }
 }
 
-void GpencilExporter::gp_style_current_set(MaterialGPencilStyle *igp_style)
-{
-  gp_style = igp_style;
-  is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
-               (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
-  is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
-             (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
-}
-
 struct MaterialGPencilStyle *GpencilExporter::gp_style_current_get(void)
 {
   return gp_style;
@@ -339,6 +337,11 @@ bool GpencilExporter::gp_style_is_fill(void)
   return is_fill;
 }
 
+float GpencilExporter::stroke_average_opacity(void)
+{
+  return avg_opacity;
+}
+
 }  // namespace gpencil
 }  // namespace io
 }  // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 7da6ce5c811..d0139548d87 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -81,11 +81,11 @@ class GpencilExporter {
   struct MaterialGPencilStyle *gp_style_current_get(void);
   bool gp_style_is_stroke(void);
   bool gp_style_is_fill(void);
+  float stroke_average_opacity(void);
 
   void gpl_current_set(struct bGPDlayer *gpl);
   void gpf_current_set(struct bGPDframe *gpf);
   void gps_current_set(struct Object *ob, struct bGPDstroke *gps, const bool set_colors);
-  void gp_style_current_set(MaterialGPencilStyle *gp_style);
 
  private:
   struct bGPDlayer *gpl_cur;
@@ -94,6 +94,7 @@ class GpencilExporter {
   struct MaterialGPencilStyle *gp_style;
   bool is_stroke;
   bool is_fill;
+  float avg_opacity;
 
   void set_out_filename(char *filename);
 };
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index f7ff22075e2..49d47e6e41e 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -249,7 +249,12 @@ void GpencilExporterSVG::export_stroke_path(pugi::xml_node gpl_node, const bool
   float col[3];
   std::string stroke_hex;
   if (is_fill) {
-    gps_node.append_attribute("stroke-opacity").set_value(fill_color[3] * gpl->opacity);
+    if (gp_style_is_stroke()) {
+      gps_node.append_attribute("stroke-opacity").set_value(fill_color[3] * gpl->opacity);
+    }
+    else {
+      gps_node.append_attribute("stroke-opacity").set_value("none");
+    }
     gps_node.append_attribute("fill-opacity").set_value(fill_color[3] * gpl->opacity);
 
     interp_v3_v3v3(col, fill_color, gpl->tintcolor, gpl->tintcolor[3]);
@@ -257,8 +262,10 @@ void GpencilExporterSVG::export_stroke_path(pugi::xml_node gpl_node, const bool
     stroke_hex = rgb_to_hex(col);
   }
   else {
-    gps_node.append_attribute("stroke-opacity").set_value(stroke_color[3] * gpl->opacity);
-    gps_node.append_attribute("fill-opacity").set_value(stroke_color[3] * gpl->opacity);
+    gps_node.append_attribute("stroke-opacity")
+        .set_value(stroke_color[3] * stroke_average_opacity() * gpl->opacity);
+    gps_node.append_attribute("fill-opacity")
+        .set_value(stroke_color[3] * stroke_average_opacity() * gpl->opacity);
 
     interp_v3_v3v3(col, stroke_color, gpl->tintcolor, gpl->tintcolor[3]);
     linearrgb_to_srgb_v3_v3(col, col);
@@ -371,7 +378,8 @@ void GpencilExporterSVG::color_string_set(pugi::xml_node gps_node, const bool is
       gps_node.append_attribute("fill").set_value(stroke_hex.c_str());
     }
   }
-  gps_node.append_attribute("stroke-opacity").set_value(stroke_color[3] * gpl->opacity);
+  gps_node.append_attribute("stroke-opacity")
+      .set_value(stroke_color[3] * stroke_average_opacity() * gpl->opacity);
   gps_node.append_attribute("fill-opacity").set_value(fill_color[3] * gpl->opacity);
 }



More information about the Bf-blender-cvs mailing list