Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_paint.c
| Context not available. | |||||
| bGPDstroke *gps; | bGPDstroke *gps; | ||||
| bGPDspoint *pt; | bGPDspoint *pt; | ||||
| tGPspoint *ptc; | tGPspoint *ptc; | ||||
| bGPDlayer *layer = gpencil_layer_getactive(p->gpd); | |||||
| int i, totelem; | int i, totelem; | ||||
| /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ | /* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */ | ||||
| int depth_margin = (p->gpd->flag & GP_DATA_DEPTH_STROKE) ? 4 : 0; | int depth_margin = (p->gpd->flag & GP_DATA_DEPTH_STROKE) ? 4 : 0; | ||||
| Context not available. | |||||
| gps->inittime = p->inittime; | gps->inittime = p->inittime; | ||||
| /* allocate enough memory for a continuous array for storage points */ | /* allocate enough memory for a continuous array for storage points */ | ||||
| gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); | int sublevel = layer->sublevel; | ||||
| int new_totpoints = gps->totpoints; | |||||
| for (i = 0; i < sublevel; ++i) | |||||
| { | |||||
| // Avoid error if subdivide is too big (assume totpoints is right) | |||||
| if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX) | |||||
| { | |||||
| sublevel = i; // reduce sublevel | |||||
| break; | |||||
aligorith: "subpoints" is not really that descriptive. It was only upon re-reading the code that I… | |||||
| } | |||||
| new_totpoints += new_totpoints - 1; | |||||
| } | |||||
| gps->points = MEM_callocN(sizeof(bGPDspoint) * new_totpoints, "gp_stroke_points"); | |||||
Not Done Inline ActionsIs there any reason why you need to have these on the stack, and thus end up copying the data back and forth? It would probably be more efficient to just do: bGPDspoint *pt_a; bGPDspoint *pt_b; bGPDspoint *pt_new; then: pt_a = &gps->points[i]; pt_b = &gps->points[i]; pt_n = &gps->points[i + 1]; /* Interpolate all values */ interp_v3_v3(&pt_n->x, &pt_a->x, &pt_b->x, 0.5f); interpf(&pt_n->pressure, pt_a->pressure, pt_b->pressure); // ... Also note, the use of the interp functions from BLI_math instead of inlining the math here :) AFAICT, there isn't really any reason why we need to make copies of everything first. It doesn't look like the ranges will overlap... aligorith: Is there any reason why you need to have these on the stack, and thus end up copying the data… | |||||
| /* set pointer to first non-initialized point */ | /* set pointer to first non-initialized point */ | ||||
| pt = gps->points + (gps->totpoints - totelem); | pt = gps->points + (gps->totpoints - totelem); | ||||
| Context not available. | |||||
| pt->time = ptc->time; | pt->time = ptc->time; | ||||
| } | } | ||||
| /* subdivide the stroke */ | |||||
| if (sublevel > 0) | |||||
| { | |||||
| int sub = gps->totpoints; | |||||
| for (i = 0; i < sublevel; ++i) | |||||
| { | |||||
| sub += sub - 1; | |||||
| gp_subdivide_stroke(gps, sub); | |||||
| } | |||||
| } | |||||
| /* smooth stroke */ | |||||
| if (layer->smooth_drawfac > 0.0f) // only if something to do | |||||
| { | |||||
| for (i = 0; i < gps->totpoints; i++) | |||||
| { | |||||
| gp_smooth_stroke(gps, i, layer->smooth_drawfac); | |||||
| } | |||||
| } | |||||
| if (depth_arr) | if (depth_arr) | ||||
| MEM_freeN(depth_arr); | MEM_freeN(depth_arr); | ||||
| } | } | ||||
| /* add stroke to frame */ | /* add stroke to frame */ | ||||
| BLI_addtail(&p->gpf->strokes, gps); | BLI_addtail(&p->gpf->strokes, gps); | ||||
| gp_stroke_added_enable(p); | gp_stroke_added_enable(p); | ||||
| Context not available. | |||||
"subpoints" is not really that descriptive. It was only upon re-reading the code that I realised that this is the new total number of points in the subdivided stroke. Maybe something like "new_totpoints" or something like that instead?