Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h1
-rw-r--r--source/blender/blenkernel/intern/gpencil.c17
-rw-r--r--source/blender/blenkernel/intern/gpencil_modifier.c54
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c23
-rw-r--r--source/blender/editors/gpencil/editaction_gpencil.c6
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c9
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c28
-rw-r--r--source/blender/editors/gpencil/gpencil_fill.c10
-rw-r--r--source/blender/editors/gpencil/gpencil_interpolate.c32
-rw-r--r--source/blender/editors/gpencil/gpencil_old.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c45
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c13
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c35
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_ruler.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c2
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c31
-rw-r--r--source/blender/makesrna/intern/rna_gpencil.c4
17 files changed, 203 insertions, 113 deletions
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 19535f23cf2..9c352da15a0 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -151,6 +151,7 @@ struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
void BKE_gpencil_centroid_3D(struct bGPdata *gpd, float r_centroid[3]);
/* vertex groups */
+void BKE_gpencil_dvert_ensure(struct bGPDstroke *gps);
float BKE_gpencil_vgroup_use_index(struct MDeformVert *dvert, int index);
void BKE_gpencil_vgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
struct MDeformWeight *BKE_gpencil_vgroup_add_point_weight(struct MDeformVert *dvert, int index, float weight);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 57494397f40..51731cb3e8e 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -519,7 +519,6 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
gps->totpoints = totpoints;
gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
/* initialize triangle memory to dummy data */
gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation");
@@ -573,8 +572,13 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src)
gps_dst->points = MEM_dupallocN(gps_src->points);
- gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ if (gps_src->dvert != NULL) {
+ gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ }
+ else {
+ gps_dst->dvert = NULL;
+ }
/* Don't clear triangles, so that modifier evaluation can just use
* this without extra work first. Most places that need to force
@@ -1253,6 +1257,13 @@ void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
BLI_freelinkN(&ob->defbase, defgroup);
}
+
+void BKE_gpencil_dvert_ensure(bGPDstroke *gps)
+{
+ if (gps->dvert == NULL) {
+ gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+ }
+}
/* add a new weight */
MDeformWeight *BKE_gpencil_vgroup_add_point_weight(MDeformVert *dvert, int index, float weight)
{
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index 3b0c86a1832..fd1170c1a9c 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -220,8 +220,12 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
/* adding points marked */
bGPDspoint *old_points = MEM_dupallocN(gps->points);
- MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
+ MDeformVert *old_dvert = NULL;
+ MDeformVert *dvert_src = NULL;
+ if (gps->dvert != NULL) {
+ old_dvert = MEM_dupallocN(gps->dvert);
+ }
/* resize gps */
gps->flag |= GP_STROKE_RECALC_CACHES;
gps->tot_triangles = 0;
@@ -231,16 +235,20 @@ static void gpencil_rdp_stroke(bGPDstroke *gps, vec2f *points2d, float epsilon)
bGPDspoint *pt_src = &old_points[i];
bGPDspoint *pt = &gps->points[j];
- MDeformVert *dvert_src = &old_dvert[i];
- MDeformVert *dvert = &gps->dvert[j];
-
if ((marked[i]) || (i == 0) || (i == totpoints - 1)) {
memcpy(pt, pt_src, sizeof(bGPDspoint));
- memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ MDeformVert *dvert = &gps->dvert[j];
+ memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ }
j++;
}
else {
- BKE_gpencil_free_point_weights(dvert_src);
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ BKE_gpencil_free_point_weights(dvert_src);
+ }
}
}
@@ -257,11 +265,6 @@ void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float factor)
/* first create temp data and convert points to 2D */
vec2f *points2d = MEM_mallocN(sizeof(vec2f) * gps->totpoints, "GP Stroke temp 2d points");
- /* for some old files, the weights array could not be initializated */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
gpencil_stroke_project_2d(gps->points, gps->totpoints, points2d);
gpencil_rdp_stroke(gps, points2d, factor);
@@ -276,14 +279,14 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
return;
}
- /* for some old files, the weights array could not be initializated */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
/* save points */
bGPDspoint *old_points = MEM_dupallocN(gps->points);
- MDeformVert *old_dvert = MEM_dupallocN(gps->dvert);
+ 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;
@@ -293,7 +296,9 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
newtot += 2;
gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * newtot);
- gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * newtot);
+ }
gps->flag |= GP_STROKE_RECALC_CACHES;
gps->tot_triangles = 0;
@@ -302,16 +307,21 @@ void BKE_gpencil_simplify_fixed(bGPDstroke *gps)
bGPDspoint *pt_src = &old_points[i];
bGPDspoint *pt = &gps->points[j];
- MDeformVert *dvert_src = &old_dvert[i];
- MDeformVert *dvert = &gps->dvert[j];
if ((i == 0) || (i == gps->totpoints - 1) || ((i % 2) > 0.0)) {
memcpy(pt, pt_src, sizeof(bGPDspoint));
- memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ MDeformVert *dvert = &gps->dvert[j];
+ memcpy(dvert, dvert_src, sizeof(MDeformVert));
+ }
j++;
}
else {
- BKE_gpencil_free_point_weights(dvert_src);
+ if (gps->dvert != NULL) {
+ dvert_src = &old_dvert[i];
+ BKE_gpencil_free_point_weights(dvert_src);
+ }
}
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 2102f255f75..3f185c4fbfc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -499,10 +499,10 @@ GPUBatch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
int idx = 0;
float fcolor[4];
float fsize = 0;
- for (int i = 0; i < gps->totpoints; i++, pt++, dvert++) {
+ for (int i = 0; i < gps->totpoints; i++, pt++) {
/* weight paint */
if (is_weight_paint) {
- float weight = BKE_gpencil_vgroup_use_index(dvert, vgindex);
+ float weight = gps->dvert!= NULL ? BKE_gpencil_vgroup_use_index(dvert, vgindex) : 0;
CLAMP(weight, 0.0f, 1.0f);
float hue = 2.0f * (1.0f - weight) / 3.0f;
hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
@@ -535,6 +535,9 @@ GPUBatch *DRW_gpencil_get_edit_geom(bGPDstroke *gps, float alpha, short dflag)
GPU_vertbuf_attr_set(vbo, size_id, idx, &fsize);
GPU_vertbuf_attr_set(vbo, pos_id, idx, &pt->x);
idx++;
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
return GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO);
@@ -571,22 +574,14 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
/* Draw all the stroke lines (selected or not) */
bGPDspoint *pt = gps->points;
-
- /* GPXX: for some converted files, this struct could be null
- * maybe we can remove this and move to versioning code after
- * merge */
- if (gps->dvert == NULL) {
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
- }
-
MDeformVert *dvert = gps->dvert;
int idx = 0;
float fcolor[4];
- for (int i = 0; i < gps->totpoints; i++, pt++, dvert++) {
+ for (int i = 0; i < gps->totpoints; i++, pt++) {
/* weight paint */
if (is_weight_paint) {
- float weight = BKE_gpencil_vgroup_use_index(dvert, vgindex);
+ float weight = gps->dvert != NULL ? BKE_gpencil_vgroup_use_index(dvert, vgindex) : 0;
CLAMP(weight, 0.0f, 1.0f);
float hue = 2.0f * (1.0f - weight) / 3.0f;
hsv_to_rgb(hue, 1.0f, 1.0f, &selectColor[0], &selectColor[1], &selectColor[2]);
@@ -605,6 +600,10 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
GPU_vertbuf_attr_set(vbo, color_id, idx, fcolor);
GPU_vertbuf_attr_set(vbo, pos_id, idx, &pt->x);
idx++;
+
+ if (gps->dvert != NULL) {
+ dvert++;
+ }
}
return GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c
index 88f935eb8bf..2c3159692bf 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -492,8 +492,10 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode)
/* make a copy of stroke, then of its points array */
gpsn = MEM_dupallocN(gps);
gpsn->points = MEM_dupallocN(gps->points);
- gpsn->dvert = MEM_dupallocN(gps->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps, gpsn);
+ if (gps->dvert != NULL) {
+ gpsn->dvert = MEM_dupallocN(gps->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps, gpsn);
+ }
/* duplicate triangle information */
gpsn->triangles = MEM_dupallocN(gps->triangles);
/* append stroke to frame */
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index ddce148a3a3..4ab344c7861 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -876,6 +876,9 @@ static bool gp_brush_weight_apply(
tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index,
const int radius, const int co[2])
{
+ /* create dvert */
+ BKE_gpencil_dvert_ensure(gps);
+
bGPDspoint *pt = gps->points + pt_index;
MDeformVert *dvert = gps->dvert + pt_index;
float inf;
@@ -1055,8 +1058,10 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
new_stroke = MEM_dupallocN(gps);
new_stroke->points = MEM_dupallocN(gps->points);
- new_stroke->dvert = MEM_dupallocN(gps->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps, new_stroke);
+ if (gps->dvert != NULL) {
+ new_stroke->dvert = MEM_dupallocN(gps->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps, new_stroke);
+ }
new_stroke->triangles = MEM_dupallocN(gps->triangles);
new_stroke->next = new_stroke->prev = NULL;
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 81a5fbdf069..d8fb5bed5af 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2921,6 +2921,8 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
bGPdata *gpd = ED_gpencil_data_get_active(C);
bGPDspoint *temp_points;
const int cuts = RNA_int_get(op->ptr, "number_cuts");
+ MDeformVert *temp_dvert = NULL;
+ MDeformVert *dvert_final = NULL;
int totnewpoints, oldtotpoints;
int i2;
@@ -2942,7 +2944,9 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
/* duplicate points in a temp area */
temp_points = MEM_dupallocN(gps->points);
oldtotpoints = gps->totpoints;
-
+ if (gps->dvert != NULL) {
+ temp_dvert = MEM_dupallocN(gps->dvert);
+ }
/* resize the points arrys */
gps->totpoints += totnewpoints;
gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * gps->totpoints);
@@ -2957,7 +2961,10 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
bGPDspoint *pt = &temp_points[i];
bGPDspoint *pt_final = &gps->points[i2];
- MDeformVert *dvert_final = &gps->dvert[i2];
+ MDeformVert *dvert = NULL;
+ if (gps->dvert != NULL) {
+ dvert = &temp_dvert[i];
+ }
/* copy current point */
copy_v3_v3(&pt_final->x, &pt->x);
@@ -2966,8 +2973,11 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
pt_final->time = pt->time;
pt_final->flag = pt->flag;
- dvert_final->totweight = 0;
- dvert_final->dw = NULL;
+ if (gps->dvert != NULL) {
+ dvert_final = &gps->dvert[i2];
+ dvert_final->totweight = dvert->totweight;
+ dvert_final->dw = dvert->dw;
+ }
i2++;
/* if next point is selected add a half way point */
@@ -2987,16 +2997,18 @@ static int gp_stroke_subdivide_exec(bContext *C, wmOperator *op)
pt_final->time = interpf(pt->time, next->time, 0.5f);
pt_final->flag |= GP_SPOINT_SELECT;
- dvert_final->totweight = 0;
- dvert_final->dw = NULL;
-
+ if (gps->dvert != NULL) {
+ dvert_final->totweight = 0;
+ dvert_final->dw = NULL;
+ }
i2++;
}
}
}
}
/* free temp memory */
- MEM_freeN(temp_points);
+ MEM_SAFE_FREE(temp_points);
+ MEM_SAFE_FREE(temp_dvert);
}
}
}
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index c6df07ae83e..d3132d78aa4 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -846,7 +846,6 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
/* allocate memory for storage points */
gps->totpoints = tgpf->sbuffer_size;
gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_size, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * tgpf->sbuffer_size, "gp_stroke_weights");
/* initialize triangle memory to dummy data */
gps->tot_triangles = 0;
@@ -865,7 +864,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
pt = gps->points;
dvert = gps->dvert;
point2D = (tGPspoint *)tgpf->sbuffer;
- for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, pt++, dvert++) {
+ for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, pt++) {
/* convert screen-coordinates to 3D coordinates */
gp_stroke_convertcoords_tpoint(
tgpf->scene, tgpf->ar, tgpf->v3d, tgpf->ob,
@@ -877,8 +876,11 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf)
pt->strength = 1.0f;;
pt->time = 0.0f;
- dvert->totweight = 0;
- dvert->dw = NULL;
+ if (gps->dvert != NULL) {
+ dvert->totweight = 0;
+ dvert->dw = NULL;
+ dvert++;
+ }
}
/* smooth stroke */
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 6541e9f012a..ccf600a2584 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -1,4 +1,4 @@
-/*
+/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@@ -119,7 +119,6 @@ static void gp_interpolate_update_points(bGPDstroke *gps_from, bGPDstroke *gps_t
for (int i = 0; i < new_stroke->totpoints; i++) {
prev = &gps_from->points[i];
pt = &new_stroke->points[i];
- dvert = &new_stroke->dvert[i];
next = &gps_to->points[i];
/* Interpolate all values */
@@ -128,8 +127,10 @@ static void gp_interpolate_update_points(bGPDstroke *gps_from, bGPDstroke *gps_t
pt->strength = interpf(prev->strength, next->strength, 1.0f - factor);
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
- dvert->totweight = 0;
- dvert->dw = NULL;
+ /* GPXX interpolate dverts */
+ //dvert = &new_stroke->dvert[i];
+ //dvert->totweight = 0;
+ //dvert->dw = NULL;
}
}
@@ -301,7 +302,9 @@ static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
/* if destination stroke is smaller, resize new_stroke to size of gps_to stroke */
if (gps_from->totpoints > gps_to->totpoints) {
new_stroke->points = MEM_recallocN(new_stroke->points, sizeof(*new_stroke->points) * gps_to->totpoints);
- new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert) * gps_to->totpoints);
+ if (new_stroke->dvert != NULL) {
+ new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert) * gps_to->totpoints);
+ }
new_stroke->totpoints = gps_to->totpoints;
new_stroke->tot_triangles = 0;
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
@@ -313,7 +316,9 @@ static void gp_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
/* need an empty stroke to keep index correct for lookup, but resize to smallest size */
new_stroke->totpoints = 0;
new_stroke->points = MEM_recallocN(new_stroke->points, sizeof(*new_stroke->points));
- new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert));
+ if (new_stroke->dvert != NULL) {
+ new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert));
+ }
new_stroke->tot_triangles = 0;
new_stroke->triangles = MEM_recallocN(new_stroke->triangles, sizeof(*new_stroke->triangles));
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
@@ -587,8 +592,10 @@ static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent
/* make copy of source stroke, then adjust pointer to points too */
gps_dst = MEM_dupallocN(gps_src);
gps_dst->points = MEM_dupallocN(gps_src->points);
- gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
- BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ if (gps_src->dvert != NULL) {
+ gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
+ BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+ }
gps_dst->triangles = MEM_dupallocN(gps_src->triangles);
gps_dst->flag |= GP_STROKE_RECALC_CACHES;
BLI_addtail(&gpf_dst->strokes, gps_dst);
@@ -1016,10 +1023,15 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
/* if destination stroke is smaller, resize new_stroke to size of gps_to stroke */
if (gps_from->totpoints > gps_to->totpoints) {
/* free weights of removed points */
- BKE_defvert_array_free_elems(gps_from->dvert + gps_to->totpoints, gps_from->totpoints - gps_to->totpoints);
+ if (gps_from->dvert != NULL) {
+ BKE_defvert_array_free_elems(gps_from->dvert + gps_to->totpoints, gps_from->totpoints - gps_to->totpoints);
+ }
new_stroke->points = MEM_recallocN(new_stroke->points, sizeof(*new_stroke->points) * gps_to->totpoints);
- new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert) * gps_to->totpoints);
+
+ if (new_stroke->dvert != NULL) {
+ new_stroke->dvert = MEM_recallocN(new_stroke->dvert, sizeof(*new_stroke->dvert) * gps_to->totpoints);
+ }
new_stroke->totpoints = gps_to->totpoints;
new_stroke->tot_triangles = 0;
new_stroke->flag |= GP_STROKE_RECALC_CACHES;
diff --git a/source/blender/editors/gpencil/gpencil_old.c b/source/blender/editors/gpencil/gpencil_old.c
index a384d6d7ae8..5c01de55885 100644
--- a/source/blender/editors/gpencil/gpencil_old.c
+++ b/source/blender/editors/gpencil/gpencil_old.c
@@ -146,8 +146,8 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
{
gps->mat_nr = ob->totcol - 1;
gps->colorname[0] = '\0';
- /* create weights array */
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+ /* weights array */
+ gps->dvert = NULL;
}
}
}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index b50624d07d2..aa163e02cfe 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -758,13 +758,16 @@ static short gp_stroke_addpoint(
/* first time point is adding to temporary buffer -- need to allocate new point in stroke */
if (gpd->runtime.sbuffer_size == 0) {
gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
- gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (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];
- dvert = &gps->dvert[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,
@@ -789,8 +792,10 @@ static short gp_stroke_addpoint(
pts->uv_fac = pt->uv_fac;
pts->uv_rot = pt->uv_rot;
- dvert->totweight = 0;
- dvert->dw = NULL;
+ if (gps->dvert != NULL) {
+ dvert->totweight = 0;
+ dvert->dw = NULL;
+ }
/* force fill recalc */
gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -895,7 +900,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
bGPDstroke *gps;
bGPDspoint *pt;
tGPspoint *ptc;
- MDeformVert *dvert;
+ MDeformVert *dvert = NULL;
Brush *brush = p->brush;
ToolSettings *ts = p->scene->toolsettings;
Depsgraph *depsgraph = p->depsgraph;
@@ -949,7 +954,6 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
const int subdivide = brush->gpencil_settings->draw_subdivide;
gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
/* initialize triangle memory to dummy data */
gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation");
@@ -959,7 +963,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
gp_update_cache(p->gpd);
/* set pointer to first non-initialized point */
pt = gps->points + (gps->totpoints - totelem);
- dvert = gps->dvert + (gps->totpoints - totelem);
+ if (gps->dvert != NULL) {
+ dvert = gps->dvert + (gps->totpoints - totelem);
+ }
/* copy points from the buffer to the stroke */
if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) {
@@ -975,12 +981,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
pt->strength = ptc->strength;
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
pt->time = ptc->time;
+ pt++;
- dvert->totweight = 0;
- dvert->dw = NULL;
+ if (dvert != NULL) {
+ dvert->totweight = 0;
+ dvert->dw = NULL;
- pt++;
- dvert++;
+ dvert++;
+ }
}
if (totelem == 2) {
@@ -995,8 +1003,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
pt->time = ptc->time;
- dvert->totweight = 0;
- dvert->dw = NULL;
+ if (dvert != NULL) {
+ dvert->totweight = 0;
+ dvert->dw = NULL;
+ }
}
/* reproject to plane (only in 3d space) */
@@ -1023,9 +1033,10 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
pt->time = ptc->time;
- dvert->totweight = 0;
- dvert->dw = NULL;
-
+ if (dvert != NULL) {
+ dvert->totweight = 0;
+ dvert->dw = NULL;
+ }
}
else {
float *depth_arr = NULL;
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 2dfdeeba0b6..6fa7d0b7a81 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -182,7 +182,6 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
/* allocate memory for storage points, but keep empty */
gps->totpoints = 0;
gps->points = MEM_callocN(sizeof(bGPDspoint), "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert), "gp_stroke_weights");
/* initialize triangle memory to dummy data */
gps->tot_triangles = 0;
gps->triangles = NULL;
@@ -322,7 +321,9 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* realloc points to new size */
/* TODO: only do this if the size has changed? */
gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * tgpi->tot_edges);
- gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * tgpi->tot_edges);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * tgpi->tot_edges);
+ }
gps->totpoints = tgpi->tot_edges;
/* compute screen-space coordinates for points */
@@ -344,7 +345,6 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* convert screen-coordinates to 3D coordinates */
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
- MDeformVert *dvert = &gps->dvert[i];
tGPspoint *p2d = &points2D[i];
@@ -355,8 +355,11 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
pt->strength = tgpi->brush->gpencil_settings->draw_strength;
pt->time = 0.0f;
- dvert->totweight = 0;
- dvert->dw = NULL;
+ if (gps->dvert != NULL) {
+ MDeformVert *dvert = &gps->dvert[i];
+ dvert->totweight = 0;
+ dvert->dw = NULL;
+ }
}
/* if axis locked, reproject to plane locked */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index cd352579b4a..3e05dcc3004 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -946,7 +946,9 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int subdivide)
/* resize the points arrys */
gps->totpoints += totnewpoints;
gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * gps->totpoints);
- gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints);
+ if (gps->dvert != NULL) {
+ gps->dvert = MEM_recallocN(gps->dvert, sizeof(*gps->dvert) * gps->totpoints);
+ }
gps->flag |= GP_STROKE_RECALC_CACHES;
/* move points from last to first to new place */
@@ -954,8 +956,6 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int subdivide)
for (int i = oldtotpoints - 1; i > 0; i--) {
bGPDspoint *pt = &temp_points[i];
bGPDspoint *pt_final = &gps->points[i2];
- MDeformVert *dvert = &gps->dvert[i];
- MDeformVert *dvert_final = &gps->dvert[i2];
copy_v3_v3(&pt_final->x, &pt->x);
pt_final->pressure = pt->pressure;
@@ -965,8 +965,13 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int subdivide)
pt_final->uv_fac = pt->uv_fac;
pt_final->uv_rot = pt->uv_rot;
- dvert_final->totweight = dvert->totweight;
- dvert_final->dw = dvert->dw;
+ if (gps->dvert != NULL) {
+ MDeformVert *dvert = &gps->dvert[i];
+ MDeformVert *dvert_final = &gps->dvert[i2];
+
+ dvert_final->totweight = dvert->totweight;
+ dvert_final->dw = dvert->dw;
+ }
i2 -= 2;
}
@@ -976,7 +981,6 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int subdivide)
bGPDspoint *pt = &temp_points[i];
bGPDspoint *next = &temp_points[i + 1];
bGPDspoint *pt_final = &gps->points[i2];
- MDeformVert *dvert_final = &gps->dvert[i2];
/* add a half way point */
interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f);
@@ -987,8 +991,11 @@ void gp_subdivide_stroke(bGPDstroke *gps, const int subdivide)
pt_final->uv_fac = interpf(pt->uv_fac, next->uv_fac, 0.5f);
pt_final->uv_rot = interpf(pt->uv_rot, next->uv_rot, 0.5f);
- dvert_final->totweight = 0;
- dvert_final->dw = NULL;
+ if (gps->dvert != NULL) {
+ MDeformVert *dvert_final = &gps->dvert[i2];
+ dvert_final->totweight = 0;
+ dvert_final->dw = NULL;
+ }
i2 += 2;
}
@@ -1211,6 +1218,9 @@ void ED_gpencil_vgroup_assign(bContext *C, Object *ob, float weight)
CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
{
if (gps->flag & GP_STROKE_SELECT) {
+ /* verify the weight array is created */
+ BKE_gpencil_dvert_ensure(gps);
+
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
MDeformVert *dvert = &gps->dvert[i];
@@ -1234,6 +1244,9 @@ void ED_gpencil_vgroup_remove(bContext *C, Object *ob)
{
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
+ if (gps->dvert == NULL) {
+ continue;
+ }
MDeformVert *dvert = &gps->dvert[i];
if ((pt->flag & GP_SPOINT_SELECT) && (dvert->totweight > 0)) {
@@ -1255,6 +1268,9 @@ void ED_gpencil_vgroup_select(bContext *C, Object *ob)
{
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
+ if (gps->dvert == NULL) {
+ continue;
+ }
MDeformVert *dvert = &gps->dvert[i];
if (BKE_gpencil_vgroup_use_index(dvert, def_nr) > -1.0f) {
@@ -1277,6 +1293,9 @@ void ED_gpencil_vgroup_deselect(bContext *C, Object *ob)
{
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
+ if (gps->dvert == NULL) {
+ continue;
+ }
MDeformVert *dvert = &gps->dvert[i];
if (BKE_gpencil_vgroup_use_index(dvert, def_nr) > -1.0f) {
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 5853fa6e3b3..938b4c45181 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -422,7 +422,6 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
if (ruler_item->flag & RULERITEM_USE_ANGLE) {
gps->totpoints = 3;
pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
for (j = 0; j < 3; j++) {
copy_v3_v3(&pt->x, ruler_item->co[j]);
pt->pressure = 1.0f;
@@ -433,7 +432,6 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
else {
gps->totpoints = 2;
pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
for (j = 0; j < 3; j += 2) {
copy_v3_v3(&pt->x, ruler_item->co[j]);
pt->pressure = 1.0f;
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c
index 0475159712b..df8d65449e9 100644
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_ruler.c
@@ -338,7 +338,6 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
if (ruler_item->flag & RULERITEM_USE_ANGLE) {
gps->totpoints = 3;
pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
for (j = 0; j < 3; j++) {
copy_v3_v3(&pt->x, ruler_item->co[j]);
pt->pressure = 1.0f;
@@ -349,7 +348,6 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
else {
gps->totpoints = 2;
pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
- gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
for (j = 0; j < 3; j += 2) {
copy_v3_v3(&pt->x, ruler_item->co[j]);
pt->pressure = 1.0f;
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
index 945afec002d..6435ca1ce70 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
@@ -118,7 +118,10 @@ static void gpf_clear_all_strokes(bGPDframe *gpf)
static void reduce_stroke_points(bGPDstroke *gps, const int num_points, const eBuildGpencil_Transition transition)
{
bGPDspoint *new_points = MEM_callocN(sizeof(bGPDspoint) * num_points, __func__);
- MDeformVert *new_dvert = MEM_callocN(sizeof(MDeformVert) * num_points, __func__);
+ MDeformVert *new_dvert = NULL;
+ if (gps->dvert != NULL) {
+ new_dvert = MEM_callocN(sizeof(MDeformVert) * num_points, __func__);
+ }
/* Which end should points be removed from */
// TODO: free stroke weights
@@ -128,14 +131,15 @@ static void reduce_stroke_points(bGPDstroke *gps, const int num_points, const eB
{
/* copy over point data */
memcpy(new_points, gps->points, sizeof(bGPDspoint) * num_points);
- memcpy(new_dvert, gps->dvert, sizeof(MDeformVert) * num_points);
+ if (gps->dvert != NULL) {
+ memcpy(new_dvert, gps->dvert, sizeof(MDeformVert) * num_points);
- /* free unused point weights */
- for (int i = num_points; i < gps->totpoints; i++) {
- MDeformVert *dvert = &gps->dvert[i];
- BKE_gpencil_free_point_weights(dvert);
+ /* free unused point weights */
+ for (int i = num_points; i < gps->totpoints; i++) {
+ MDeformVert *dvert = &gps->dvert[i];
+ BKE_gpencil_free_point_weights(dvert);
+ }
}
-
break;
}
@@ -149,14 +153,15 @@ static void reduce_stroke_points(bGPDstroke *gps, const int num_points, const eB
/* copy over point data */
memcpy(new_points, gps->points + offset, sizeof(bGPDspoint) * num_points);
- memcpy(new_dvert, gps->dvert + offset, sizeof(MDeformVert) * num_points);
+ if (gps->dvert != NULL) {
+ memcpy(new_dvert, gps->dvert + offset, sizeof(MDeformVert) * num_points);
- /* free unused weights */
- for (int i = 0; i < offset; i++) {
- MDeformVert *dvert = &gps->dvert[i];
- BKE_gpencil_free_point_weights(dvert);
+ /* free unused weights */
+ for (int i = 0; i < offset; i++) {
+ MDeformVert *dvert = &gps->dvert[i];
+ BKE_gpencil_free_point_weights(dvert);
+ }
}
-
break;
}
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 6beb8c5313e..6bb93e9e313 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -494,7 +494,9 @@ static void rna_GPencil_stroke_point_pop(bGPDstroke *stroke, ReportList *reports
stroke->totpoints--;
stroke->points = MEM_callocN(sizeof(bGPDspoint) * stroke->totpoints, "gp_stroke_points");
- stroke->dvert = MEM_callocN(sizeof(MDeformVert) * stroke->totpoints, "gp_stroke_weights");
+ if (pt_dvert != NULL) {
+ stroke->dvert = MEM_callocN(sizeof(MDeformVert) * stroke->totpoints, "gp_stroke_weights");
+ }
if (index > 0) {
memcpy(stroke->points, pt_tmp, sizeof(bGPDspoint) * index);