[Bf-blender-cvs] [4fdab28f776] greasepencil-object: GPencil: Fix errors with strokes with Stroke and Fill

Antonio Vazquez noreply at git.blender.org
Sun Jul 26 16:54:38 CEST 2020


Commit: 4fdab28f77684dae2aa1ff6878bb83bf88956172
Author: Antonio Vazquez
Date:   Sun Jul 26 16:54:31 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4fdab28f77684dae2aa1ff6878bb83bf88956172

GPencil: Fix errors with strokes with Stroke and Fill

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

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

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

diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 5b73e6ecc26..e6a2c132120 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -78,7 +78,8 @@ bool GpencilExporter::gpencil_3d_point_to_screen_space(struct ARegion *region,
   float parent_co[3];
   mul_v3_m4v3(parent_co, diff_mat, co);
   float screen_co[2];
-  eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
+  //  eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
+  eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_OK);
   if (ED_view3d_project_float_global(region, parent_co, screen_co, test) == V3D_PROJ_RET_OK) {
     if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
       copy_v2_v2(r_co, screen_co);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index d497aefdb48..2f65ba2d639 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -115,6 +115,52 @@ void GpencilExporterSVG::create_document_header(void)
   main_node.append_attribute("viewBox").set_value(viewbox.c_str());
 }
 
+/**
+ * Create Styles (materials) list.
+ */
+void GpencilExporterSVG::export_style_list(void)
+{
+  Object *ob = this->params.ob;
+  int mat_len = max_ii(1, ob->totcol);
+  main_node.append_child(pugi::node_comment).set_value("List of materials");
+  pugi::xml_node style_node = main_node.append_child("style");
+  style_node.append_attribute("type").set_value("text/css");
+
+  std::string txt;
+  float col[3];
+
+  for (int i = 0; i < mat_len; i++) {
+    MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
+
+    bool is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
+                      (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+    bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
+                    (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
+
+    if (is_stroke) {
+      txt.append("\n\t.style_stroke_");
+      txt.append(std::to_string(i + 1).c_str());
+      linearrgb_to_srgb_v3_v3(col, gp_style->stroke_rgba);
+      txt.append("{");
+      txt.append("stroke:" + rgb_to_hex(col) + ";");
+      txt.append("fill:" + rgb_to_hex(col) + ";");
+      txt.append("}");
+    }
+
+    if (is_fill) {
+      txt.append("\n\t.style_fill_");
+      txt.append(std::to_string(i + 1).c_str());
+      linearrgb_to_srgb_v3_v3(col, gp_style->fill_rgba);
+      txt.append("{");
+      txt.append("stroke:" + rgb_to_hex(col) + ";");
+      txt.append("fill:" + rgb_to_hex(col) + ";");
+      txt.append("}");
+    }
+  }
+  txt.append("\n\t");
+  style_node.text().set(txt.c_str());
+}
+
 /* Main layer loop. */
 void GpencilExporterSVG::export_layers(void)
 {
@@ -156,7 +202,7 @@ void GpencilExporterSVG::export_layers(void)
 
       /* Fill. */
       if (is_fill) {
-        export_stroke(gpl_node, gps, diff_mat);
+        export_stroke(gpl_node, gps, diff_mat, true);
       }
 
       /* Stroke. */
@@ -170,7 +216,7 @@ void GpencilExporterSVG::export_layers(void)
         // ED_gpencil_project_stroke_to_view(params.C, gpl, gps_perimeter);
         BKE_gpencil_stroke_sample(gps_perimeter, 0.03f, false);
 
-        export_stroke(gpl_node, gps_perimeter, diff_mat);
+        export_stroke(gpl_node, gps_perimeter, diff_mat, false);
 
         BKE_gpencil_free_stroke(gps_perimeter);
         BKE_gpencil_free_stroke(gps_tmp);
@@ -188,14 +234,16 @@ void GpencilExporterSVG::export_layers(void)
  */
 void GpencilExporterSVG::export_stroke(pugi::xml_node gpl_node,
                                        struct bGPDstroke *gps,
-                                       float diff_mat[4][4])
+                                       float diff_mat[4][4],
+                                       const bool is_fill)
 {
   pugi::xml_node gps_node = gpl_node.append_child("path");
   // gps_node.append_attribute("fill").set_value("#000000");
   // gps_node.append_attribute("stroke").set_value("#000000");
 
+  std::string style_type = (is_fill) ? "_fill_" : "_stroke_";
   gps_node.append_attribute("class").set_value(
-      ("style" + std::to_string(gps->mat_nr + 1)).c_str());
+      ("style" + style_type + std::to_string(gps->mat_nr + 1)).c_str());
 
   gps_node.append_attribute("stroke-width").set_value("1.0");
 
@@ -219,55 +267,6 @@ void GpencilExporterSVG::export_stroke(pugi::xml_node gpl_node,
   gps_node.append_attribute("d").set_value(txt.c_str());
 }
 
-/**
- * Create Style (materials) list.
- */
-void GpencilExporterSVG::export_style_list(void)
-{
-  Object *ob = this->params.ob;
-  int mat_len = max_ii(1, ob->totcol);
-  main_node.append_child(pugi::node_comment).set_value("List of materials");
-  pugi::xml_node style_node = main_node.append_child("style");
-  style_node.append_attribute("type").set_value("text/css");
-
-  std::string txt;
-  float col[3];
-
-  for (int i = 0; i < mat_len; i++) {
-    MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, i + 1);
-
-    bool is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) &&
-                      (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
-    bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) &&
-                    (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
-
-    txt.append("\n\t.style");
-    txt.append(std::to_string(i + 1).c_str());
-
-    txt.append("{");
-    if (is_fill) {
-      linearrgb_to_srgb_v3_v3(col, gp_style->fill_rgba);
-
-      txt.append("fill:" + rgb_to_hex(col) + ";");
-      if (!is_stroke) {
-        txt.append("stroke:" + rgb_to_hex(col) + ";");
-      }
-    }
-
-    if (is_stroke) {
-      linearrgb_to_srgb_v3_v3(col, gp_style->stroke_rgba);
-
-      txt.append("stroke:" + rgb_to_hex(col) + ";");
-      if (!is_fill) {
-        txt.append("fill:" + rgb_to_hex(col) + ";");
-      }
-    }
-    txt.append("}");
-  }
-  txt.append("\n\t");
-  style_node.text().set(txt.c_str());
-}
-
 }  // namespace gpencil
 }  // namespace io
 }  // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.h b/source/blender/io/gpencil/intern/gpencil_io_svg.h
index bce64053d81..a9e34bb997e 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.h
@@ -51,7 +51,10 @@ class GpencilExporterSVG : public GpencilExporter {
   void create_document_header(void);
   void export_layers(void);
   void export_style_list(void);
-  void export_stroke(pugi::xml_node gpl_node, struct bGPDstroke *gps, float diff_mat[4][4]);
+  void export_stroke(pugi::xml_node gpl_node,
+                     struct bGPDstroke *gps,
+                     float diff_mat[4][4],
+                     const bool is_fill);
 };
 
 }  // namespace gpencil



More information about the Bf-blender-cvs mailing list