Code Cleanup: Just a bit more tidying up comments/whitespace/etc.
There is still some instability in how the triangulations are happening, where the triangle count of the resulting triangulation fluctuates resulting in weird artifacts sometimes. To reproduce, try drawing some U-shapes, and keep reloading the file.
This commit is contained in:
@@ -341,7 +341,7 @@ static void gp_stroke_2d_flat(bGPDspoint *points, int totpoints, float(*points2d
|
||||
float loc3[3];
|
||||
float normal[3];
|
||||
|
||||
/* local X axis (p0-p1) */
|
||||
/* local X axis (p0 -> p1) */
|
||||
sub_v3_v3v3(locx, &pt1->x, &pt0->x);
|
||||
|
||||
/* point vector at 3/4 */
|
||||
@@ -369,6 +369,7 @@ static void gp_stroke_2d_flat(bGPDspoint *points, int totpoints, float(*points2d
|
||||
points2d[i][1] = dot_v3v3(loc, locy);
|
||||
}
|
||||
|
||||
/* Concave (-1), Convex (1), or Autodetect (0)? */
|
||||
*r_direction = (int)locy[2];
|
||||
}
|
||||
|
||||
@@ -382,7 +383,7 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps)
|
||||
unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->totpoints, "GP Stroke temp triangulation");
|
||||
float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points");
|
||||
|
||||
int direction;
|
||||
int direction = 0;
|
||||
|
||||
/* convert to 2d and triangulate */
|
||||
gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction);
|
||||
@@ -392,20 +393,21 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps)
|
||||
gps->tot_triangles = 0;
|
||||
for (int i = 0; i < gps->totpoints; i++) {
|
||||
if ((tmp_triangles[i][0] >= 0) && (tmp_triangles[i][0] < gps->totpoints) &&
|
||||
(tmp_triangles[i][1] >= 0) && (tmp_triangles[i][1] < gps->totpoints) &&
|
||||
(tmp_triangles[i][2] >= 0) && (tmp_triangles[i][2] < gps->totpoints))
|
||||
(tmp_triangles[i][1] >= 0) && (tmp_triangles[i][1] < gps->totpoints) &&
|
||||
(tmp_triangles[i][2] >= 0) && (tmp_triangles[i][2] < gps->totpoints))
|
||||
{
|
||||
gps->tot_triangles++;
|
||||
}
|
||||
}
|
||||
//printf("tot triangles: %d / %d - direction = %d\n", gps->tot_triangles, gps->totpoints, direction);
|
||||
|
||||
/* save triangulation data in stroke cache */
|
||||
if (gps->tot_triangles > 0) {
|
||||
if (gps->triangles == NULL) {
|
||||
gps->triangles = MEM_callocN(sizeof(bGPDtriangle) * gps->tot_triangles, "GP Stroke triangulation");
|
||||
gps->triangles = MEM_callocN(sizeof(*gps->triangles) * gps->tot_triangles, "GP Stroke triangulation");
|
||||
}
|
||||
else {
|
||||
gps->triangles = MEM_recallocN(gps->triangles, sizeof(bGPDtriangle) * gps->tot_triangles);
|
||||
gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles);
|
||||
}
|
||||
|
||||
int triangle_index = 0;
|
||||
|
@@ -766,10 +766,9 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
|
||||
new_stroke = MEM_dupallocN(gps);
|
||||
|
||||
new_stroke->points = MEM_dupallocN(gps->points);
|
||||
/* duplicate triangle information */
|
||||
new_stroke->triangles = MEM_dupallocN(gps->triangles);
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
BLI_addtail(&gpf->strokes, new_stroke);
|
||||
|
||||
/* Adjust all the stroke's points, so that the strokes
|
||||
@@ -1286,6 +1285,7 @@ static bool gpsculpt_brush_apply_standard(bContext *C, tGP_BrushEditData *gso)
|
||||
printf("ERROR: Unknown type of GPencil Sculpt brush - %u\n", gso->brush_type);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Triangulation must be calculated if changed */
|
||||
if (changed) {
|
||||
gps->flag |= GP_STROKE_RECALC_CACHES;
|
||||
|
@@ -169,10 +169,12 @@ static void gp_duplicate_points(const bGPDstroke *gps, ListBase *new_strokes)
|
||||
|
||||
/* make a stupid copy first of the entire stroke (to get the flags too) */
|
||||
gpsd = MEM_dupallocN(gps);
|
||||
/* initialize triangle memory */
|
||||
|
||||
/* initialize triangle memory - will be calculated on next redraw */
|
||||
gpsd->triangles = NULL;
|
||||
gpsd->flag |= GP_STROKE_RECALC_CACHES;
|
||||
gpsd->tot_triangles = 0;
|
||||
|
||||
/* now, make a new points array, and copy of the relevant parts */
|
||||
gpsd->points = MEM_callocN(sizeof(bGPDspoint) * len, "gps stroke points copy");
|
||||
memcpy(gpsd->points, gps->points + start_idx, sizeof(bGPDspoint) * len);
|
||||
@@ -225,10 +227,11 @@ static int gp_duplicate_exec(bContext *C, wmOperator *op)
|
||||
/* make direct copies of the stroke and its points */
|
||||
gpsd = MEM_dupallocN(gps);
|
||||
gpsd->points = MEM_dupallocN(gps->points);
|
||||
/* triangle information */
|
||||
gpsd->triangles = MEM_dupallocN(gps->triangles);
|
||||
|
||||
/* triangle information - will be calculated on next redraw */
|
||||
gpsd->flag |= GP_STROKE_RECALC_CACHES;
|
||||
|
||||
gpsd->triangles = NULL;
|
||||
|
||||
/* add to temp buffer */
|
||||
gpsd->next = gpsd->prev = NULL;
|
||||
BLI_addtail(&new_strokes, gpsd);
|
||||
@@ -342,10 +345,12 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op)
|
||||
/* make direct copies of the stroke and its points */
|
||||
gpsd = MEM_dupallocN(gps);
|
||||
gpsd->points = MEM_dupallocN(gps->points);
|
||||
/* duplicate triangle information */
|
||||
gpsd->triangles = MEM_dupallocN(gps->triangles);
|
||||
|
||||
/* triangles cache - will be recalculated on next redraw */
|
||||
gpsd->flag |= GP_STROKE_RECALC_CACHES;
|
||||
gpsd->tot_triangles = 0;
|
||||
gpsd->triangles = NULL;
|
||||
|
||||
/* add to temp buffer */
|
||||
gpsd->next = gpsd->prev = NULL;
|
||||
BLI_addtail(&gp_strokes_copypastebuf, gpsd);
|
||||
@@ -460,11 +465,11 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
|
||||
bGPDstroke *new_stroke = MEM_dupallocN(gps);
|
||||
|
||||
new_stroke->points = MEM_dupallocN(gps->points);
|
||||
/* triangle information */
|
||||
new_stroke->triangles = MEM_dupallocN(gps->triangles);
|
||||
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
|
||||
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
|
||||
new_stroke->triangles = NULL;
|
||||
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
BLI_addtail(&gpf->strokes, new_stroke);
|
||||
}
|
||||
}
|
||||
@@ -769,9 +774,11 @@ static int gp_dissolve_selected_points(bContext *C)
|
||||
/* save the new buffer */
|
||||
gps->points = new_points;
|
||||
gps->totpoints = tot;
|
||||
/* recalculate cache */
|
||||
|
||||
/* triangles cache needs to be recalculated */
|
||||
gps->flag |= GP_STROKE_RECALC_CACHES;
|
||||
gps->tot_triangles = 0;
|
||||
|
||||
/* deselect the stroke, since none of its selected points will still be selected */
|
||||
gps->flag &= ~GP_STROKE_SELECT;
|
||||
}
|
||||
@@ -861,7 +868,7 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke
|
||||
tGPDeleteIsland *island = &islands[idx];
|
||||
bGPDstroke *new_stroke = MEM_dupallocN(gps);
|
||||
|
||||
/* initialize triangle memory */
|
||||
/* initialize triangle memory - to be calculated on next redraw */
|
||||
new_stroke->triangles = NULL;
|
||||
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
|
||||
new_stroke->tot_triangles = 0;
|
||||
|
Reference in New Issue
Block a user