[Bf-blender-cvs] [b580fdf0fef] greasepencil-object: GPencil: remove code from Polygon mode from Freehand operator

Antonio Vazquez noreply at git.blender.org
Thu Oct 17 17:29:50 CEST 2019


Commit: b580fdf0fef9aa6ffc31ff98325b2d2add7d6ddd
Author: Antonio Vazquez
Date:   Thu Oct 17 17:29:27 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBb580fdf0fef9aa6ffc31ff98325b2d2add7d6ddd

GPencil: remove code from Polygon mode from Freehand operator

This section of the code was from 2.7x and it's was not working and it will be replaced by a new primitive polyline tool.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_gpencil_types.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 9554e9c0275..b46b092edac 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -473,20 +473,19 @@ void GPENCIL_cache_init(void *vedata)
       stl->storage->is_xray = 0;
     }
 
-    /* save pixsize */
+    /* Save pixsize. */
     stl->storage->pixsize = DRW_viewport_pixelsize_get();
     if ((!DRW_state_is_opengl_render()) && (stl->storage->is_render)) {
       stl->storage->pixsize = &stl->storage->render_pixsize;
     }
 
-    /* detect if painting session */
+    /* Detect if painting session. */
     if ((obact_gpd) && (obact_gpd->flag & GP_DATA_STROKE_PAINTMODE) &&
         (stl->storage->is_playing == false)) {
-      /* need the original to avoid cow overhead while drawing */
+      /* Need the original to avoid cow overhead while drawing. */
       bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&obact_gpd->id);
       if (((gpd_orig->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) &&
-          (gpd_orig->runtime.sbuffer_used > 0) &&
-          ((gpd_orig->flag & GP_DATA_STROKE_POLYGON) == 0) && !DRW_state_is_depth() &&
+          (gpd_orig->runtime.sbuffer_used > 0) && (!DRW_state_is_depth()) &&
           (stl->storage->background_ready == true)) {
         stl->g_data->session_flag |= GP_DRW_PAINT_PAINTING;
       }
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 686a3edc434..1eb1c2b13b1 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -713,14 +713,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
   bGPdata *gpd = p->gpd;
   Brush *brush = p->brush;
   tGPspoint *pt;
-  ToolSettings *ts = p->scene->toolsettings;
   Object *obact = (Object *)p->ownerPtr.data;
-  Depsgraph *depsgraph = p->depsgraph;
   RegionView3D *rv3d = p->ar->regiondata;
-  View3D *v3d = p->sa->spacedata.first;
   MaterialGPencilStyle *gp_style = p->material->gp_style;
-  const int def_nr = obact->actdef - 1;
-  const bool have_weight = (bool)BLI_findlink(&obact->defbase, def_nr);
 
   /* check painting mode */
   if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -896,96 +891,6 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
 
     return GP_STROKEADD_NORMAL;
   }
-  else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
-
-    /* enable special flag for drawing engine */
-    gpd->flag |= GP_DATA_STROKE_POLYGON;
-
-    bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
-    /* get pointer to destination point */
-    pt = (tGPspoint *)(gpd->runtime.sbuffer);
-
-    /* store settings */
-    copy_v2_v2(&pt->x, mval);
-    /* T44932 - Pressure vals are unreliable, so ignore for now */
-    pt->pressure = 1.0f;
-    pt->strength = 1.0f;
-    pt->time = (float)(curtime - p->inittime);
-
-    /* if there's stroke for this poly line session add (or replace last) point
-     * to stroke. This allows to draw lines more interactively (see new segment
-     * during mouse slide, e.g.)
-     */
-    if (gp_stroke_added_check(p)) {
-      bGPDstroke *gps = p->gpf->strokes.last;
-      bGPDspoint *pts;
-      MDeformVert *dvert = NULL;
-
-      /* First time point is adding to temporary buffer (need to allocate new point in stroke) */
-      if (gpd->runtime.sbuffer_used == 0) {
-        gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
-        if (gps->dvert != NULL) {
-          gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1));
-        }
-        gps->totpoints++;
-      }
-
-      pts = &gps->points[gps->totpoints - 1];
-      if (gps->dvert != NULL) {
-        dvert = &gps->dvert[gps->totpoints - 1];
-      }
-      /* special case for poly lines: normally,
-       * depth is needed only when creating new stroke from buffer,
-       * but poly lines are converting to stroke instantly,
-       * so initialize depth buffer before converting coordinates
-       */
-      if (gpencil_project_check(p)) {
-        view3d_region_operator_needs_opengl(p->win, p->ar);
-        ED_view3d_autodist_init(
-            p->depsgraph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0);
-      }
-
-      /* convert screen-coordinates to appropriate coordinates (and store them) */
-      gp_stroke_convertcoords(p, &pt->x, &pts->x, NULL);
-      /* reproject to plane (only in 3d space) */
-      gp_reproject_toplane(p, gps);
-      /* if parented change position relative to parent object */
-      gp_apply_parent_point(depsgraph, obact, gpd, gpl, pts);
-      /* copy pressure and time */
-      pts->pressure = pt->pressure;
-      pts->strength = pt->strength;
-      pts->time = pt->time;
-      pts->uv_fac = pt->uv_fac;
-      pts->uv_rot = pt->uv_rot;
-
-      if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
-        BKE_gpencil_dvert_ensure(gps);
-        MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
-        if (dw) {
-          dw->weight = ts->vgroup_weight;
-        }
-      }
-      else {
-        if (dvert != NULL) {
-          dvert->totweight = 0;
-          dvert->dw = NULL;
-        }
-      }
-
-      /* force fill recalc */
-      gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-      /* drawing batch cache is dirty now */
-      gp_update_cache(p->gpd);
-    }
-
-    /* increment counters */
-    if (gpd->runtime.sbuffer_used == 0) {
-      gpd->runtime.sbuffer_used++;
-    }
-
-    return GP_STROKEADD_NORMAL;
-  }
-
   /* return invalid state for now... */
   return GP_STROKEADD_INVALID;
 }
@@ -1051,19 +956,6 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
     return;
   }
 
-  /* special case for poly line -- for already added stroke during session
-   * coordinates are getting added to stroke immediately to allow more
-   * interactive behavior
-   */
-  if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
-    /* be sure to hide any lazy cursor */
-    ED_gpencil_toggle_brush_cursor(p->C, true, NULL);
-
-    if (gp_stroke_added_check(p)) {
-      return;
-    }
-  }
-
   /* allocate memory for a new stroke */
   gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
 
@@ -1169,40 +1061,6 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
       ED_gpencil_project_stroke_to_view(p->C, p->gpl, gps);
     }
   }
-  else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) {
-    /* first point */
-    ptc = gpd->runtime.sbuffer;
-
-    /* convert screen-coordinates to appropriate coordinates (and store them) */
-    gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
-    /* reproject to plane (only in 3d space) */
-    gp_reproject_toplane(p, gps);
-    /* if parented change position relative to parent object */
-    gp_apply_parent_point(depsgraph, obact, gpd, gpl, pt);
-    /* if camera view, reproject flat to view to avoid perspective effect */
-    if (is_camera) {
-      ED_gpencil_project_stroke_to_view(p->C, p->gpl, gps);
-    }
-    /* copy pressure and time */
-    pt->pressure = ptc->pressure;
-    pt->strength = ptc->strength;
-    CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
-    pt->time = ptc->time;
-
-    if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) {
-      BKE_gpencil_dvert_ensure(gps);
-      MDeformWeight *dw = defvert_verify_index(dvert, def_nr);
-      if (dw) {
-        dw->weight = ts->vgroup_weight;
-      }
-    }
-    else {
-      if (dvert != NULL) {
-        dvert->totweight = 0;
-        dvert->dw = NULL;
-      }
-    }
-  }
   else {
     float *depth_arr = NULL;
 
@@ -1376,8 +1234,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
    * is added on listbase head because the drawing order is inverse and the head stroke is the
    * first to draw. This is very useful for artist when drawing the background.
    */
-  if ((ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) &&
-      (p->paintmode != GP_PAINTMODE_DRAW_POLY)) {
+  if (ts->gpencil_flags & GP_TOOL_FLAG_PAINT_ONBACK) {
     BLI_addhead(&p->gpf->strokes, gps);
   }
   else {
@@ -2177,7 +2034,6 @@ static void gp_session_cleanup(tGPsdata *p)
 
   /* free stroke buffer */
   if (gpd->runtime.sbuffer) {
-    /* printf("\t\tGP - free sbuffer\n"); */
     MEM_SAFE_FREE(gpd->runtime.sbuffer);
     gpd->runtime.sbuffer = NULL;
   }
@@ -2499,10 +2355,7 @@ static void gpencil_draw_exit(bContext *C, wmOperator *op)
     else {
       /* drawing batch cache is dirty now */
       bGPdata *gpd = CTX_data_gpencil_data(C);
-      if (gpd) {
-        gpd->flag &= ~GP_DATA_STROKE_POLYGON;
-        gp_update_cache(gpd);
-      }
+      gp_update_cache(gpd);
     }
 
     /* clear undo stack */
@@ -2632,13 +2485,6 @@ static void gpencil_draw_status_indicators(bContext *C, tGPsdata *p)
           }
           break;
         }
-        case GP_PAINTMODE_DRAW_POLY: {
-          ED_workspace_status_text(
-              C,
-              TIP_("Grease Pencil Poly Session: LMB click to place next stroke vertex | "
-                   "Release Shift/ESC/Enter to end (or click outside this area)"));
-          break;
-        }
         default: /* unhandled future cases */
         {
           ED_workspace_status_text(
@@ -3119,28 +2965,21 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
   tGPsdata *p = NULL;
   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
 
-  /* printf("GPencil - Starting Re-Drawing\n"); */
-
   /* try to initialize context data needed while drawing */
   if (!gpencil_draw_init(C, op, NULL)) {
     MEM_SAFE_FREE(op->customdata);
-    /* printf("\tGP - no valid data\n"); */
     return OPERATOR_CANCELLED;
   }
   else {
     p = op->customdata;
   }
 
-  /* printf("\tGP - Start redrawing stroke\n"); */
-
   /* loop over the stroke RNA elements recorded (i.e. progress of mouse movement),
    * setting the relevant values in context at each step, then applying
    */
   RNA_BEGIN (op->ptr, itemptr, "stroke") {
     float mousef[2];
 
-    /* printf("\t\tGP - stroke elem\n"); */
-
     /* get relevant data for this point from 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list