From 94dfa6eaacac69723d5832181201b5b65c32260d Mon Sep 17 00:00:00 2001 From: Antonioya Date: Tue, 25 Dec 2018 11:10:05 +0100 Subject: GP: Remove duplicate code moving to single function --- source/blender/blenkernel/BKE_gpencil.h | 3 ++ source/blender/blenkernel/intern/gpencil.c | 45 +++++++++++++++++++++ .../draw/engines/gpencil/gpencil_draw_utils.c | 46 +--------------------- source/blender/editors/gpencil/drawgpencil.c | 46 +--------------------- 4 files changed, 50 insertions(+), 90 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 34c61083872..989bec1957b 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -168,6 +168,9 @@ void BKE_gpencil_simplify_stroke(struct bGPDstroke *gps, float factor); void BKE_gpencil_simplify_fixed(struct bGPDstroke *gps); void BKE_gpencil_subdivide(struct bGPDstroke *gps, int level, int flag); +void BKE_gpencil_stroke_2d_flat( + const struct bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction); + void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]); bool BKE_gpencil_smooth_stroke(struct bGPDstroke *gps, int i, float inf); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 5f444541890..f8dfa82e2a2 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1559,3 +1559,48 @@ int BKE_gpencil_get_material_index(Object *ob, Material *ma) return 0; } + +/* Get points of stroke always flat to view not affected by camera view or view position */ +void BKE_gpencil_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) +{ + const bGPDspoint *pt0 = &points[0]; + const bGPDspoint *pt1 = &points[1]; + const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; + + float locx[3]; + float locy[3]; + float loc3[3]; + float normal[3]; + + /* local X axis (p0 -> p1) */ + sub_v3_v3v3(locx, &pt1->x, &pt0->x); + + /* point vector at 3/4 */ + sub_v3_v3v3(loc3, &pt3->x, &pt0->x); + + /* vector orthogonal to polygon plane */ + cross_v3_v3v3(normal, locx, loc3); + + /* local Y axis (cross to normal/x axis) */ + cross_v3_v3v3(locy, normal, locx); + + /* Normalize vectors */ + normalize_v3(locx); + normalize_v3(locy); + + /* Get all points in local space */ + for (int i = 0; i < totpoints; i++) { + const bGPDspoint *pt = &points[i]; + float loc[3]; + + /* Get local space using first point as origin */ + sub_v3_v3v3(loc, &pt->x, &pt0->x); + + points2d[i][0] = dot_v3v3(loc, locx); + points2d[i][1] = dot_v3v3(loc, locy); + } + + /* Concave (-1), Convex (1), or Autodetect (0)? */ + *r_direction = (int)locy[2]; +} + diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 273a8f216a4..6c3577c2794 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -214,50 +214,6 @@ static void gpencil_calc_stroke_fill_uv( } } -/* Get points of stroke always flat to view not affected by camera view or view position */ -static void gpencil_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) -{ - const bGPDspoint *pt0 = &points[0]; - const bGPDspoint *pt1 = &points[1]; - const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; - - float locx[3]; - float locy[3]; - float loc3[3]; - float normal[3]; - - /* local X axis (p0 -> p1) */ - sub_v3_v3v3(locx, &pt1->x, &pt0->x); - - /* point vector at 3/4 */ - sub_v3_v3v3(loc3, &pt3->x, &pt0->x); - - /* vector orthogonal to polygon plane */ - cross_v3_v3v3(normal, locx, loc3); - - /* local Y axis (cross to normal/x axis) */ - cross_v3_v3v3(locy, normal, locx); - - /* Normalize vectors */ - normalize_v3(locx); - normalize_v3(locy); - - /* Get all points in local space */ - for (int i = 0; i < totpoints; i++) { - const bGPDspoint *pt = &points[i]; - float loc[3]; - - /* Get local space using first point as origin */ - sub_v3_v3v3(loc, &pt->x, &pt0->x); - - points2d[i][0] = dot_v3v3(loc, locx); - points2d[i][1] = dot_v3v3(loc, locy); - } - - /* Concave (-1), Convex (1), or Autodetect (0)? */ - *r_direction = (int)locy[2]; -} - /* recalc the internal geometry caches for fill and uvs */ static void DRW_gpencil_recalc_geometry_caches( Object *ob, bGPDlayer *gpl, MaterialGPencilStyle *gp_style, bGPDstroke *gps) @@ -1114,7 +1070,7 @@ void DRW_gpencil_triangulate_stroke_fill(Object *ob, bGPDstroke *gps) int direction = 0; /* convert to 2d and triangulate */ - gpencil_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); + BKE_gpencil_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); BLI_polyfill_calc(points2d, (uint)gps->totpoints, direction, tmp_triangles); /* calc texture coordinates automatically */ diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index c16ea84ec81..1ad71f55ba4 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -459,50 +459,6 @@ static void gp_calc_stroke_text_coordinates(const float(*points2d)[2], int totpo } } -/* Get points of stroke always flat to view not affected by camera view or view position */ -static void gp_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction) -{ - const bGPDspoint *pt0 = &points[0]; - const bGPDspoint *pt1 = &points[1]; - const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)]; - - float locx[3]; - float locy[3]; - float loc3[3]; - float normal[3]; - - /* local X axis (p0 -> p1) */ - sub_v3_v3v3(locx, &pt1->x, &pt0->x); - - /* point vector at 3/4 */ - sub_v3_v3v3(loc3, &pt3->x, &pt0->x); - - /* vector orthogonal to polygon plane */ - cross_v3_v3v3(normal, locx, loc3); - - /* local Y axis (cross to normal/x axis) */ - cross_v3_v3v3(locy, normal, locx); - - /* Normalize vectors */ - normalize_v3(locx); - normalize_v3(locy); - - /* Get all points in local space */ - for (int i = 0; i < totpoints; i++) { - const bGPDspoint *pt = &points[i]; - float loc[3]; - - /* Get local space using first point as origin */ - sub_v3_v3v3(loc, &pt->x, &pt0->x); - - points2d[i][0] = dot_v3v3(loc, locx); - points2d[i][1] = dot_v3v3(loc, locy); - } - - /* Concave (-1), Convex (1), or Autodetect (0)? */ - *r_direction = (int)locy[2]; -} - /* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */ static void gp_triangulate_stroke_fill(bGPDstroke *gps) { @@ -517,7 +473,7 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps) int direction = 0; /* convert to 2d and triangulate */ - gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); + BKE_gpencil_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); BLI_polyfill_calc(points2d, (uint)gps->totpoints, direction, tmp_triangles); /* calc texture coordinates automatically */ -- cgit v1.2.3