[Bf-blender-cvs] [ebf5657733f] greasepencil-object: GPencil: Reformat code and cleanup parameter list

Antonio Vazquez noreply at git.blender.org
Tue Jul 28 23:14:44 CEST 2020


Commit: ebf5657733faa905d069a7c6fe5535ce6f490c7a
Author: Antonio Vazquez
Date:   Tue Jul 28 23:14:12 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rBebf5657733faa905d069a7c6fe5535ce6f490c7a

GPencil: Reformat code and cleanup parameter list

Also added round caps.

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

M	source/blender/blenkernel/BKE_gpencil_geom.h
M	source/blender/blenkernel/intern/gpencil_geom.c
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
M	source/blender/io/gpencil/intern/gpencil_io_svg.h

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

diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index 87fa55c201d..06dbb695b44 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -28,6 +28,7 @@
 extern "C" {
 #endif
 
+struct ARegion;
 struct bContext;
 struct BoundBox;
 struct Depsgraph;
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 3505a77e52f..7b317e445d4 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -54,8 +54,8 @@
 #include "BKE_material.h"
 #include "BKE_object.h"
 
-#include "UI_view2d.h"
-#include "ED_view3d.h"
+//#include "UI_view2d.h"
+//#include "ED_view3d.h"
 
 #include "DEG_depsgraph_query.h"
 
@@ -3116,6 +3116,7 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d,
   return perimeter_stroke;
 }
 
+#if 0
 /**
  * Calculates the perimeter of a stroke projected from the view and
  * returns it as a flat 2D stroke.
@@ -3196,4 +3197,5 @@ bGPDstroke *BKE_gpencil_stroke_perimeter_from_view_2d(struct ARegion *region,
 
   return perimeter_stroke;
 }
+#endif
 /** \} */
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index 2dbd62fea12..d1777ff6104 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -72,21 +72,22 @@ void GpencilExporter::set_out_filename(char *filename)
 
 /* Convert to screen space.
  * TODO: Cleanup using a more generic BKE function. */
-bool GpencilExporter::gpencil_3d_point_to_screen_space(struct ARegion *region,
-                                                       const float diff_mat[4][4],
-                                                       const float co[3],
-                                                       const bool invert,
-                                                       float r_co[2])
+bool GpencilExporter::gpencil_3d_point_to_screen_space(const float co[3], float r_co[2])
 {
   float parent_co[3];
   mul_v3_m4v3(parent_co, diff_mat, co);
   float screen_co[2];
   eV3DProjTest test = (eV3DProjTest)(V3D_PROJ_RET_OK);
-  if (ED_view3d_project_float_global(region, parent_co, screen_co, test) == V3D_PROJ_RET_OK) {
+  if (ED_view3d_project_float_global(params.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);
+      /* Invert X axis. */
+      if (invert_axis[0]) {
+        r_co[0] = params.region->winx - r_co[0];
+      }
       /* Invert Y axis. */
-      if (invert) {
+      if (invert_axis[1]) {
         r_co[1] = params.region->winy - r_co[1];
       }
 
@@ -96,8 +97,12 @@ bool GpencilExporter::gpencil_3d_point_to_screen_space(struct ARegion *region,
   r_co[0] = V2D_IS_CLIPPED;
   r_co[1] = V2D_IS_CLIPPED;
 
+  /* Invert X axis. */
+  if (invert_axis[0]) {
+    r_co[0] = params.region->winx - r_co[0];
+  }
   /* Invert Y axis. */
-  if (invert) {
+  if (invert_axis[1]) {
     r_co[1] = params.region->winy - r_co[1];
   }
 
@@ -151,23 +156,22 @@ bool GpencilExporter::is_stroke_thickness_constant(struct bGPDstroke *gps)
   return true;
 }
 
-float GpencilExporter::stroke_point_radius_get(const struct bGPDlayer *gpl,
-                                               struct bGPDstroke *gps,
-                                               float diff_mat[4][4])
+float GpencilExporter::stroke_point_radius_get(struct bGPDstroke *gps)
 {
+  const bGPDlayer *gpl = gpl_current_get();
   RegionView3D *rv3d = (RegionView3D *)params.region->regiondata;
   bGPDspoint *pt = NULL;
   float v1[2], screen_co[2], screen_ex[2];
 
   pt = &gps->points[0];
-  gpencil_3d_point_to_screen_space(params.region, diff_mat, &pt->x, true, screen_co);
+  gpencil_3d_point_to_screen_space(&pt->x, screen_co);
 
   /* Radius. */
   bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
       rv3d, gpd, gpl, gps, 3, diff_mat);
 
   pt = &gps_perimeter->points[0];
-  gpencil_3d_point_to_screen_space(params.region, diff_mat, &pt->x, true, screen_ex);
+  gpencil_3d_point_to_screen_space(&pt->x, screen_ex);
 
   sub_v2_v2v2(v1, screen_co, screen_ex);
   float radius = len_v2(v1);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 400232cd778..de44337ab63 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -24,6 +24,8 @@
 
 #include "BLI_path_util.h"
 
+#include "BKE_gpencil.h"
+
 #include "DNA_defs.h"
 
 #include "gpencil_io_exporter.h"
@@ -33,6 +35,7 @@ struct Main;
 struct ARegion;
 
 struct bGPDlayer;
+struct bGPDframe;
 struct bGPDstroke;
 
 namespace blender {
@@ -46,28 +49,56 @@ class GpencilExporter {
   void set_out_filename(char *filename);
 
   /* Geometry functions. */
-  bool gpencil_3d_point_to_screen_space(struct ARegion *region,
-                                        const float diff_mat[4][4],
-                                        const float co[3],
-                                        const bool invert,
-                                        float r_co[2]);
+  bool gpencil_3d_point_to_screen_space(const float co[3], float r_co[2]);
 
   bool is_stroke_thickness_constant(struct bGPDstroke *gps);
   float stroke_average_pressure_get(struct bGPDstroke *gps);
-  float stroke_point_radius_get(const struct bGPDlayer *gpl,
-                                struct bGPDstroke *gps,
-                                float diff_mat[4][4]);
+  float stroke_point_radius_get(struct bGPDstroke *gps);
 
   std::string rgb_to_hex(float color[3]);
   std::string to_lower_string(char *input_text);
 
  protected:
+  bool invert_axis[2];
+  float diff_mat[4][4];
+
   GpencilExportParams params;
   char out_filename[FILE_MAX];
   /* Data for easy access. */
   struct Depsgraph *depsgraph;
   struct bGPdata *gpd;
   struct Main *bmain;
+
+  struct bGPDlayer *gpl_current_get(void)
+  {
+    return gpl_cur;
+  }
+  void gpl_current_set(struct bGPDlayer *gpl)
+  {
+    gpl_cur = gpl;
+    BKE_gpencil_parent_matrix_get(depsgraph, params.ob, gpl, diff_mat);
+  }
+  struct bGPDframe *gpf_current_get(void)
+  {
+    return gpf_cur;
+  }
+  void gpf_current_set(struct bGPDframe *gpf)
+  {
+    gpf_cur = gpf;
+  }
+  struct bGPDstroke *gps_current_get(void)
+  {
+    return gps_cur;
+  }
+  void gps_current_set(struct bGPDstroke *gps)
+  {
+    gps_cur = gps;
+  }
+
+ private:
+  struct bGPDlayer *gpl_cur;
+  struct bGPDframe *gpf_cur;
+  struct bGPDstroke *gps_cur;
 };
 
 }  // namespace gpencil
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 57b110aae2e..8feef6e70d1 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -76,6 +76,9 @@ GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *params)
   this->depsgraph = CTX_data_depsgraph_pointer(params->C);
   this->gpd = (bGPdata *)params->ob->data;
 
+  this->invert_axis[0] = false;
+  this->invert_axis[1] = true;
+
   /* Prepare output filename with full path. */
   set_out_filename(params->filename);
 }
@@ -204,6 +207,7 @@ void GpencilExporterSVG::export_layers(void)
     if (gpl->flag & GP_LAYER_HIDE) {
       continue;
     }
+    gpl_current_set(gpl);
 
     /* Layer node. */
     std::string txt = "Layer: ";
@@ -216,6 +220,7 @@ void GpencilExporterSVG::export_layers(void)
     if (gpf == NULL) {
       continue;
     }
+    gpf_current_set(gpf);
 
     float diff_mat[4][4];
     BKE_gpencil_parent_matrix_get(depsgraph, ob, gpl, diff_mat);
@@ -232,35 +237,40 @@ void GpencilExporterSVG::export_layers(void)
                       (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH));
 
       if (gps->totpoints == 1) {
-        export_point(gpl_node, gpl, gps, diff_mat);
+        gps_current_set(gps);
+
+        export_point(gpl_node);
       }
       else {
         bool is_normalized = ((params.flag & GP_EXPORT_NORM_THICKNESS) != 0);
+        gps_current_set(gps);
 
         /* Fill. */
         if ((is_fill) && (params.flag & GP_EXPORT_FILL)) {
           if (is_normalized) {
-            export_stroke_polyline(gpl_node, gpl, gps, gp_style, diff_mat, true);
+            export_stroke_polyline(gpl_node, gp_style, true);
           }
           else {
-            export_stroke_path(gpl_node, gps, diff_mat, true);
+            export_stroke_path(gpl_node, true);
           }
         }
 
         /* Stroke. */
         if (is_stroke) {
           if (is_normalized) {
-            export_stroke_polyline(gpl_node, gpl, gps, gp_style, diff_mat, false);
+            export_stroke_polyline(gpl_node, gp_style, false);
           }
           else {
             bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
                 rv3d, gpd, gpl, gps, 3, diff_mat);
 
+            gps_current_set(gps_perimeter);
+
             /* Reproject and sample stroke. */
             // ED_gpencil_project_stroke_to_view(params.C, gpl, gps_perimeter);
             BKE_gpencil_stroke_sample(gps_perimeter, 0.03f, false);
 
-            export_stroke_path(gpl_node, gps_perimeter, diff_mat, false);
+            export_stroke_path(gpl_node, false);
 
             BKE_gpencil_free_stroke(gps_perimeter);
           }
@@ -276,11 +286,10 @@ void GpencilExporterSVG::export_layers(void)
  * \param gps: Stroke to export.
  * \param diff_mat: Transformation matrix.
  */
-void GpencilExporterSVG::export_point(pugi::xml_node gpl_node,
-                                      struct bGPDlayer *gpl,
-                                      struct bGPDstroke *gps,
-                                      float diff_mat[4][4])
+void GpencilExporterSVG::export_point(pugi::xml_node gpl_node)
 {
+  bGPDstroke *gps = gps_current_get();
+
   BLI_assert(gps->totpoints == 1);
   float screen_co[2];
 
@@ -290,13 +299,13 @@ void GpencilExporterSVG::export_point(pugi::xml_node gpl_node,
       ("stylestroke" + std::to_st

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list