GPencil: Fix unreported performance issue with relative onion mode

When the relative mode was used, the calculation of the total number of vertices was not done and it was using the total number of vertices in the datablock. This worked for small files, but with complex files the time to allocate all the data was too long and the performance was very bad.

Now, for relative mode the real number of vertex is calculated.

Also fixed the same problem when onion and multiedit is enabled.
This commit is contained in:
Antonio Vazquez
2019-10-16 21:55:47 +02:00
parent 7e78fbf2de
commit 812b30daf5

View File

@@ -169,6 +169,34 @@ static void gpencil_calc_vertex(GPENCIL_StorageList *stl,
continue;
}
/* Relative onion mode needs to find the frame range before. */
int frame_from = -9999;
int frame_to = 9999;
if ((is_onion) && (mode == GP_ONION_MODE_RELATIVE)) {
/* 1) Found first Frame. */
int step = gpd->gstep;
int idx = 0;
if (gpl->actframe) {
for (bGPDframe *gf = gpl->actframe->prev; gf; gf = gf->prev) {
idx++;
frame_from = gf->framenum;
if (idx >= step) {
break;
}
}
/* 2) Found last Frame. */
step = gpd->gstep_next;
idx = 0;
for (bGPDframe *gf = gpl->actframe->next; gf; gf = gf->next) {
idx++;
frame_to = gf->framenum;
if (idx >= step) {
break;
}
}
}
}
/* If multiedit or onion skin need to count all frames of the layer. */
if ((is_multiedit) || (is_onion)) {
init_gpf = gpl->frames.first;
@@ -191,21 +219,32 @@ static void gpencil_calc_vertex(GPENCIL_StorageList *stl,
}
}
else {
/* Only selected frames. */
if ((mode == GP_ONION_MODE_SELECTED) && ((gpf->flag & GP_FRAME_SELECT) == 0)) {
continue;
}
/* Verify keyframe type. */
if ((onion_keytype > -1) && (gpf->key_type != onion_keytype)) {
continue;
}
/* Absolute range. */
if (mode == GP_ONION_MODE_ABSOLUTE) {
if ((gpl->actframe) && (abs(gpl->actframe->framenum - gpf->framenum) > step)) {
bool select = ((is_multiedit) &&
((gpf == gpl->actframe) || (gpf->flag & GP_FRAME_SELECT)));
if (!select) {
/* Only selected frames. */
if ((mode == GP_ONION_MODE_SELECTED) && ((gpf->flag & GP_FRAME_SELECT) == 0)) {
continue;
}
/* Verify keyframe type. */
if ((onion_keytype > -1) && (gpf->key_type != onion_keytype)) {
continue;
}
/* Absolute range. */
if (mode == GP_ONION_MODE_ABSOLUTE) {
if ((gpl->actframe) && (abs(gpl->actframe->framenum - gpf->framenum) > step)) {
continue;
}
}
/* Relative range. */
if (mode == GP_ONION_MODE_RELATIVE) {
if ((gpf->framenum < frame_from) || (gpf->framenum > frame_to)) {
continue;
}
}
}
/* For relative range it takes too much time compute, so use all frames. */
cache_ob->tot_vertex += gps->totpoints + 3;
cache_ob->tot_triangles += gps->totpoints - 1;
}