[Bf-blender-cvs] [96a256f757f] greasepencil-object: GPencil: Change to style instead of material name

Antonio Vazquez noreply at git.blender.org
Sun Jul 26 13:09:01 CEST 2020


Commit: 96a256f757fdff71f1b4cf52296115df6f0fec06
Author: Antonio Vazquez
Date:   Sun Jul 26 13:08:48 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB96a256f757fdff71f1b4cf52296115df6f0fec06

GPencil: Change to style instead of material name

Also added support for default material

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

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 d0bab5c4d5f..5b73e6ecc26 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -127,7 +127,6 @@ std::string GpencilExporter::to_lower_string(char *input_text)
 
   return text;
 }
-
 }  // namespace gpencil
 }  // namespace io
 }  // namespace blender
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index f422ef61e14..d497aefdb48 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -148,8 +148,7 @@ void GpencilExporterSVG::export_layers(void)
     BKE_gpencil_parent_matrix_get(depsgraph, ob, gpl, diff_mat);
 
     LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-      Material *ma = BKE_object_material_get(ob, gps->mat_nr + 1);
-      MaterialGPencilStyle *gp_style = ma->gp_style;
+      MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 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) &&
@@ -157,7 +156,7 @@ void GpencilExporterSVG::export_layers(void)
 
       /* Fill. */
       if (is_fill) {
-        export_stroke(gpl_node, gps, ma, diff_mat);
+        export_stroke(gpl_node, gps, diff_mat);
       }
 
       /* Stroke. */
@@ -171,7 +170,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, ma, diff_mat);
+        export_stroke(gpl_node, gps_perimeter, diff_mat);
 
         BKE_gpencil_free_stroke(gps_perimeter);
         BKE_gpencil_free_stroke(gps_tmp);
@@ -189,7 +188,6 @@ void GpencilExporterSVG::export_layers(void)
  */
 void GpencilExporterSVG::export_stroke(pugi::xml_node gpl_node,
                                        struct bGPDstroke *gps,
-                                       struct Material *ma,
                                        float diff_mat[4][4])
 {
   pugi::xml_node gps_node = gpl_node.append_child("path");
@@ -197,7 +195,7 @@ void GpencilExporterSVG::export_stroke(pugi::xml_node gpl_node,
   // gps_node.append_attribute("stroke").set_value("#000000");
 
   gps_node.append_attribute("class").set_value(
-      (GP_EXP_SVG_STYLE_PREFIX + to_lower_string(ma->id.name + 2)).c_str());
+      ("style" + std::to_string(gps->mat_nr + 1)).c_str());
 
   gps_node.append_attribute("stroke-width").set_value("1.0");
 
@@ -228,6 +226,7 @@ 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");
 
@@ -235,16 +234,15 @@ void GpencilExporterSVG::export_style_list(void)
   float col[3];
 
   for (int i = 0; i < mat_len; i++) {
-    Material *ma = BKE_object_material_get(ob, i + 1);
-    MaterialGPencilStyle *gp_style = ma->gp_style;
+    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.");
-    txt.append((GP_EXP_SVG_STYLE_PREFIX + to_lower_string(ma->id.name + 2)).c_str());
+    txt.append("\n\t.style");
+    txt.append(std::to_string(i + 1).c_str());
 
     txt.append("{");
     if (is_fill) {
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.h b/source/blender/io/gpencil/intern/gpencil_io_svg.h
index 1c1e333adc7..bce64053d81 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.h
@@ -32,8 +32,6 @@ struct ARegion;
 
 struct bGPDstroke;
 
-#define GP_EXP_SVG_STYLE_PREFIX "m_"
-
 namespace blender {
 namespace io {
 namespace gpencil {
@@ -53,10 +51,7 @@ 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,
-                     struct Material *ma,
-                     float diff_mat[4][4]);
+  void export_stroke(pugi::xml_node gpl_node, struct bGPDstroke *gps, float diff_mat[4][4]);
 };
 
 }  // namespace gpencil



More information about the Bf-blender-cvs mailing list