[Bf-blender-cvs] [028f97ed324] greasepencil-edit-curve: Merge branch 'master' into greasepencil-edit-curve

Antonio Vazquez noreply at git.blender.org
Fri Jun 19 23:04:47 CEST 2020


Commit: 028f97ed324be9a031c74c67516a68bf177ff09c
Author: Antonio Vazquez
Date:   Fri Jun 19 23:04:41 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB028f97ed324be9a031c74c67516a68bf177ff09c

Merge branch 'master' into greasepencil-edit-curve

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



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

diff --cc source/blender/blenkernel/intern/gpencil_modifier.c
index e6323ddc747,6496b219be1..29f25d24a6a
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@@ -53,8 -53,218 +53,11 @@@
  
  #include "MOD_gpencil_modifiertypes.h"
  
+ #include "CLG_log.h"
+ 
+ static CLG_LogRef LOG = {"bke.gpencil_modifier"};
  static GpencilModifierTypeInfo *modifier_gpencil_types[NUM_GREASEPENCIL_MODIFIER_TYPES] = {NULL};
  
 -/* *************************************************** */
 -/* Geometry Utilities */
 -
 -/* calculate stroke normal using some points */
 -void BKE_gpencil_stroke_normal(const bGPDstroke *gps, float r_normal[3])
 -{
 -  if (gps->totpoints < 3) {
 -    zero_v3(r_normal);
 -    return;
 -  }
 -
 -  bGPDspoint *points = gps->points;
 -  int totpoints = gps->totpoints;
 -
 -  const bGPDspoint *pt0 = &points[0];
 -  const bGPDspoint *pt1 = &points[1];
 -  const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
 -
 -  float vec1[3];
 -  float vec2[3];
 -
 -  /* initial vector (p0 -> p1) */
 -  sub_v3_v3v3(vec1, &pt1->x, &pt0->x);
 -
 -  /* point vector at 3/4 */
 -  sub_v3_v3v3(vec2, &pt3->x, &pt0->x);
 -
 -  /* vector orthogonal to polygon plane */
 -  cross_v3_v3v3(r_normal, vec1, vec2);
 -
 -  /* Normalize vector */
 -  normalize_v3(r_normal);
 -}
 -
 -/* Stroke Simplify ------------------------------------- */
 -
 -/* Reduce a series of points to a simplified version, but
 - * maintains the general shape of the series
 - *
 - * Ramer - Douglas - Peucker algorithm
 - * by http ://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
 - */
 -void BKE_gpencil_stroke_simplify_adaptive(bGPDstroke *gps, float epsilon)
 -{
 -  bGPDspoint *old_points = MEM_dupallocN(gps->points);
 -  int totpoints = gps->totpoints;
 -  char *marked = NULL;
 -  char work;
 -
 -  int start = 0;
 -  int end = gps->totpoints - 1;
 -
 -  marked = MEM_callocN(totpoints, "GP marked array");
 -  marked[start] = 1;
 -  marked[end] = 1;
 -
 -  work = 1;
 -  int totmarked = 0;
 -  /* while still reducing */
 -  while (work) {
 -    int ls, le;
 -    work = 0;
 -
 -    ls = start;
 -    le = start + 1;
 -
 -    /* while not over interval */
 -    while (ls < end) {
 -      int max_i = 0;
 -      /* divided to get more control */
 -      float max_dist = epsilon / 10.0f;
 -
 -      /* find the next marked point */
 -      while (marked[le] == 0) {
 -        le++;
 -      }
 -
 -      for (int i = ls + 1; i < le; i++) {
 -        float point_on_line[3];
 -        float dist;
 -
 -        closest_to_line_segment_v3(
 -            point_on_line, &old_points[i].x, &old_points[ls].x, &old_points[le].x);
 -
 -        dist = len_v3v3(point_on_line, &old_points[i].x);
 -
 -        if (dist > max_dist) {
 -          max_dist = dist;
 -          max_i = i;
 -        }
 -      }
 -
 -      if (max_i != 0) {
 -        work = 1;
 -        marked[max_i] = 1;
 -        totmarked++;
 -      }
 -
 -      ls = le;
 -      le = ls + 1;
 -    }
 -  }
 -
 -  /* adding points marked */
 -  MDeformVert *old_dvert = NULL;
 -  MDeformVert *dvert_src = NULL;
 -
 -  if (gps->dvert != NULL) {
 -    old_dvert = MEM_dupallocN(gps->dvert);
 -  }
 -  /* resize gps */
 -  int j = 0;
 -  for (int i = 0; i < totpoints; i++) {
 -    bGPDspoint *pt_src = &old_points[i];
 -    bGPDspoint *pt = &gps->points[j];
 -
 -    if ((marked[i]) || (i == 0) || (i == totpoints - 1)) {
 -      memcpy(pt, pt_src, sizeof(bGPDspoint));
 -      if (gps->dvert != NULL) {
 -        dvert_src = &old_dvert[i];
 -        MDeformVert *dvert = &gps->dvert[j];
 -        memcpy(dvert, dvert_src, sizeof(MDeformVert));
 -        if (dvert_src->dw) {
 -          memcpy(dvert->dw, dvert_src->dw, sizeof(MDeformWeight));
 -        }
 -      }
 -      j++;
 -    }
 -    else {
 -      if (gps->dvert != NULL) {
 -        dvert_src = &old_dvert[i];
 -        BKE_gpencil_free_point_weights(dvert_src);
 -      }
 -    }
 -  }
 -
 -  gps->totpoints = j;
 -
 -  /* Calc geometry data. */
 -  BKE_gpencil_stroke_geometry_update(gps);
 -
 -  MEM_SAFE_FREE(old_points);
 -  MEM_SAFE_FREE(old_dvert);
 -  MEM_SAFE_FREE(marked);
 -}
 -
 -/* Simplify alternate vertex of stroke except extremes */
 -void BKE_gpencil_stroke_simplify_fixed(bGPDstroke *gps)
 -{
 -  if (gps->totpoints < 5) {
 -    return;
 -  }
 -
 -  /* save points */
 -  bGPDspoint *old_points = MEM_dupallocN(gps->points);
 -  MDeformVert *old_dvert = NULL;
 -  MDeformVert *dvert_src = NULL;
 -
 -  if (gps->dvert != NULL) {
 -    old_dvert = MEM_dupallocN(gps->dvert);
 -  }
 -
 -  /* resize gps */
 -  int newtot = (gps->totpoints - 2) / 2;
 -  if (((gps->totpoints - 2) % 2) > 0) {
 -    newtot++;
 -  }
 -  newtot += 2;
 -
 -  gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
 -  if (gps->dvert != NULL) {
 -    gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
 -  }
 -
 -  int j = 0;
 -  for (int i = 0; i < gps->totpoints; i++) {
 -    bGPDspoint *pt_src = &old_points[i];
 -    bGPDspoint *pt = &gps->points[j];
 -
 -    if ((i == 0) || (i == gps->totpoints - 1) || ((i % 2) > 0.0)) {
 -      memcpy(pt, pt_src, sizeof(bGPDspoint));
 -      if (gps->dvert != NULL) {
 -        dvert_src = &old_dvert[i];
 -        MDeformVert *dvert = &gps->dvert[j];
 -        memcpy(dvert, dvert_src, sizeof(MDeformVert));
 -        if (dvert_src->dw) {
 -          memcpy(dvert->dw, dvert_src->dw, sizeof(MDeformWeight));
 -        }
 -      }
 -      j++;
 -    }
 -    else {
 -      if (gps->dvert != NULL) {
 -        dvert_src = &old_dvert[i];
 -        BKE_gpencil_free_point_weights(dvert_src);
 -      }
 -    }
 -  }
 -
 -  gps->totpoints = j;
 -  /* Calc geometry data. */
 -  BKE_gpencil_stroke_geometry_update(gps);
 -
 -  MEM_SAFE_FREE(old_points);
 -  MEM_SAFE_FREE(old_dvert);
 -}
 -
  /* *************************************************** */
  /* Modifier Utilities */



More information about the Bf-blender-cvs mailing list