diff options
author | Antonioya <blendergit@gmail.com> | 2018-08-26 17:39:01 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2018-08-26 17:40:06 +0300 |
commit | 1948681440c011ae3008cd5d2a575eb6d45dc7ec (patch) | |
tree | c1ae82fe27da01caf3efdeab5d99a6b6e30950d8 /source/blender/blenkernel/intern/gpencil_modifier.c | |
parent | 85aafba04c18a849eda08fe3f7d46a515ba455d6 (diff) |
GP: Reduce weight paint data memory footprint
Before, the weight data array was created always, but now only is added when a weight value is assigned.
This change was suggested by algorithm, and both agreed it was good idea.
Diffstat (limited to 'source/blender/blenkernel/intern/gpencil_modifier.c')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil_modifier.c | 54 |
1 files changed, 32 insertions, 22 deletions
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); + } } } |