[Bf-blender-cvs] [46b187f4a8d] temp-gpencil-io: Second round of code cleanup after review
Antonio Vazquez
noreply at git.blender.org
Wed Mar 3 13:16:12 CET 2021
Commit: 46b187f4a8daa07d26bd2496f0bae5ab5b7ce527
Author: Antonio Vazquez
Date: Wed Mar 3 13:16:03 2021 +0100
Branches: temp-gpencil-io
https://developer.blender.org/rB46b187f4a8daa07d26bd2496f0bae5ab5b7ce527
Second round of code cleanup after review
===================================================================
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_export_pdf.cc
M source/blender/io/gpencil/intern/gpencil_io_export_pdf.h
M source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
M source/blender/io/gpencil/intern/gpencil_io_export_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 b08c169a9b1..ec3d2e3cfa9 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -148,10 +148,6 @@ GpencilIO::GpencilIO(const struct GpencilIOParams *iparams)
offset_[0] = boundbox.xmin;
offset_[1] = boundbox.ymin;
}
-
- gpl_cur_ = nullptr;
- gpf_cur_ = nullptr;
- gps_cur_ = nullptr;
}
/** Create a list of selected objects sorted from back to front */
@@ -327,9 +323,8 @@ bool GpencilIO::is_stroke_thickness_constant(struct bGPDstroke *gps)
}
/** Get radius of point. */
-float GpencilIO::stroke_point_radius_get(struct bGPDstroke *gps)
+float GpencilIO::stroke_point_radius_get(bGPDlayer *gpl, struct bGPDstroke *gps)
{
- const bGPDlayer *gpl = gpl_current_get();
bGPDspoint *pt = nullptr;
float v1[2], screen_co[2], screen_ex[2];
@@ -364,7 +359,7 @@ std::string GpencilIO::rgb_to_hexstr(float color[3])
return hexstr;
}
-/** Convert a color to gray scale. */
+/** Convert a color to grayscale. */
void GpencilIO::rgb_to_grayscale(float color[3])
{
float grayscale = ((0.3f * color[0]) + (0.59f * color[1]) + (0.11f * color[2]));
@@ -373,37 +368,12 @@ void GpencilIO::rgb_to_grayscale(float color[3])
color[2] = grayscale;
}
-struct bGPDlayer *GpencilIO::gpl_current_get(void)
-{
- return gpl_cur_;
-}
-
-void GpencilIO::gpl_current_set(struct bGPDlayer *gpl)
+void GpencilIO::gpl_matrix_set(struct bGPDlayer *gpl)
{
- gpl_cur_ = gpl;
BKE_gpencil_layer_transform_matrix_get(depsgraph_, params_.ob, gpl, diff_mat_);
mul_m4_m4m4(diff_mat_, diff_mat_, gpl->layer_invmat);
}
-struct bGPDframe *GpencilIO::gpf_current_get(void)
-{
- return gpf_cur_;
-}
-
-void GpencilIO::gpf_current_set(struct bGPDframe *gpf)
-{
- gpf_cur_ = gpf;
-}
-struct bGPDstroke *GpencilIO::gps_current_get(void)
-{
- return gps_cur_;
-}
-
-void GpencilIO::gps_current_set(struct bGPDstroke *gps)
-{
- gps_cur_ = gps;
-}
-
void GpencilIO::gps_current_color_set(struct Object *ob, struct bGPDstroke *gps)
{
gp_style_ = BKE_gpencil_material_settings(ob, gps->mat_nr + 1);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 8121d0c6f78..bfb969c2e45 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -93,7 +93,7 @@ class GpencilIO {
void gpencil_3d_point_to_render_space(const float co[3], float r_co[2]);
void gpencil_3d_point_to_2D(const float co[3], float r_co[2]);
- float stroke_point_radius_get(struct bGPDstroke *gps);
+ float stroke_point_radius_get(struct bGPDlayer *gpl, struct bGPDstroke *gps);
void create_object_list(void);
struct MaterialGPencilStyle *gp_style_current_get(void);
@@ -104,12 +104,7 @@ class GpencilIO {
float stroke_average_opacity_get(void);
- struct bGPDlayer *gpl_current_get(void);
- struct bGPDframe *gpf_current_get(void);
- struct bGPDstroke *gps_current_get(void);
- void gpl_current_set(struct bGPDlayer *gpl);
- void gpf_current_set(struct bGPDframe *gpf);
- void gps_current_set(struct bGPDstroke *gps);
+ void gpl_matrix_set(struct bGPDlayer *gpl);
void gps_current_color_set(struct Object *ob, struct bGPDstroke *gps);
void selected_objects_boundbox_set(void);
@@ -117,9 +112,6 @@ class GpencilIO {
void filename_set(const char *filename);
private:
- struct bGPDlayer *gpl_cur_;
- struct bGPDframe *gpf_cur_;
- struct bGPDstroke *gps_cur_;
struct MaterialGPencilStyle *gp_style_;
bool is_stroke_;
bool is_fill_;
diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
index 26c08e51cbe..a3dcf0e857d 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
@@ -166,13 +166,12 @@ void GpencilExporterPDF::export_gpencil_layers(void)
if (gpl->flag & GP_LAYER_HIDE) {
continue;
}
- gpl_current_set(gpl);
+ gpl_matrix_set(gpl);
bGPDframe *gpf = gpl->actframe;
if ((gpf == nullptr) || (gpf->strokes.first == nullptr)) {
continue;
}
- gpf_current_set(gpf);
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
if (gps->totpoints == 0) {
@@ -183,8 +182,6 @@ void GpencilExporterPDF::export_gpencil_layers(void)
}
/* Duplicate the stroke to apply any layer thickness change. */
bGPDstroke *gps_duplicate = BKE_gpencil_stroke_duplicate(gps, true, false);
-
- gps_current_set(gps_duplicate);
gps_current_color_set(ob, gps_duplicate);
/* Apply layer thickness change. */
@@ -193,32 +190,30 @@ void GpencilExporterPDF::export_gpencil_layers(void)
gps_duplicate->thickness *= mat4_to_scale(ob->obmat);
CLAMP_MIN(gps_duplicate->thickness, 1.0f);
if (gps_duplicate->totpoints == 1) {
- export_stroke_to_point();
+ export_stroke_to_point(gpl, gps_duplicate);
}
else {
/* Fill. */
if ((material_is_fill()) && (params_.flag & GP_EXPORT_FILL)) {
/* Fill is exported as polygon for fill and stroke in a different shape. */
- export_stroke_to_polyline(true, false);
+ export_stroke_to_polyline(gpl, gps_duplicate, true, false);
}
/* Stroke. */
if (material_is_stroke()) {
if (is_normalized) {
- export_stroke_to_polyline(false, true);
+ export_stroke_to_polyline(gpl, gps_duplicate, false, true);
}
else {
bGPDstroke *gps_perimeter = BKE_gpencil_stroke_perimeter_from_view(
rv3d_, gpd_, gpl, gps_duplicate, 3, diff_mat_);
- gps_current_set(gps_perimeter);
-
/* Sample stroke. */
if (params_.stroke_sample > 0.0f) {
BKE_gpencil_stroke_sample(gpd_eval, gps_perimeter, params_.stroke_sample, false);
}
- export_stroke_to_polyline(false, false);
+ export_stroke_to_polyline(gpl, gps_perimeter, false, false);
BKE_gpencil_free_stroke(gps_perimeter);
}
@@ -233,17 +228,15 @@ void GpencilExporterPDF::export_gpencil_layers(void)
/**
* Export a point
*/
-void GpencilExporterPDF::export_stroke_to_point(void)
+void GpencilExporterPDF::export_stroke_to_point(bGPDlayer *gpl, bGPDstroke *gps)
{
- bGPDstroke *gps = gps_current_get();
-
BLI_assert(gps->totpoints == 1);
float screen_co[2];
bGPDspoint *pt = &gps->points[0];
gpencil_3d_point_to_2D(&pt->x, screen_co);
/* Radius. */
- float radius = stroke_point_radius_get(gps);
+ float radius = stroke_point_radius_get(gpl, gps);
HPDF_Page_Circle(page_, screen_co[0], screen_co[1], radius);
HPDF_Page_ClosePathFillStroke(page_);
@@ -253,11 +246,11 @@ void GpencilExporterPDF::export_stroke_to_point(void)
* Export a stroke using polyline or polygon
* \param do_fill: True if the stroke is only fill
*/
-void GpencilExporterPDF::export_stroke_to_polyline(const bool do_fill, const bool normalize)
+void GpencilExporterPDF::export_stroke_to_polyline(bGPDlayer *gpl,
+ bGPDstroke *gps,
+ const bool do_fill,
+ const bool normalize)
{
- bGPDlayer *gpl = gpl_current_get();
- bGPDstroke *gps = gps_current_get();
-
const bool is_thickness_const = is_stroke_thickness_constant(gps);
const bool cyclic = ((gps->flag & GP_STROKE_CYCLIC) != 0);
@@ -276,11 +269,11 @@ void GpencilExporterPDF::export_stroke_to_polyline(const bool do_fill, const boo
copy_v3_v3(&pt_dst->x, &pt_src->x);
pt_dst->pressure = avg_pressure;
- float radius = stroke_point_radius_get(gps_temp);
+ float radius = stroke_point_radius_get(gpl, gps_temp);
BKE_gpencil_free_stroke(gps_temp);
- color_set(do_fill);
+ color_set(gpl, do_fill);
if (material_is_stroke() && !do_fill) {
HPDF_Page_SetLineJoin(page_, HPDF_ROUND_JOIN);
@@ -319,10 +312,8 @@ void GpencilExporterPDF::export_stroke_to_polyline(const bool do_fill, const boo
* Set color
* @param do_fill: True if the stroke is only fill
*/
-void GpencilExporterPDF::color_set(const bool do_fill)
+void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill)
{
- bGPDlayer *gpl = gpl_current_get();
-
const float fill_opacity = fill_color_[3] * gpl->opacity;
const float stroke_opacity = stroke_color_[3] * stroke_average_opacity_get() * gpl->opacity;
diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.h b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.h
index 38470c8dd80..4789df52539 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.h
@@ -29,6 +29,8 @@
#include "hpdf.h"
struct GpencilIOParams;
+struct bGPDlayer;
+struct bGPDstroke;
#define PDF_EXPORTER_NAME "PDF Exporter for Grease Pencil"
#define PDF_EXPORTER_VERSION "v1.0"
@@ -57,9 +59,12 @@ class GpencilExporterPDF : public GpencilExporter {
bool add_page(void);
void export_gpencil_layers(void);
- void export_stroke_to_point(void);
- void export_stroke_to_polyline(const bool is_fill, const bool normalize);
- void color_set(const bool do_fill);
+ void export_stroke_to_point(bGPDlayer *gpl, bGPDstroke *gps);
+ void export_stroke_to_polyline(bGPDlayer *gpl,
+ bGPDstroke *gps,
+ const bool is_fill,
+ const bool normalize);
+ void color_set(bGPDlayer *gpl, const bool do_fill);
};
} // namespace blender::io::gpencil
diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
index c77c113c058..63a56f15ee4 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_export_svg.cc
+++ b/source/blender/io/gpencil/intern/g
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list