forked from bartvdbraak/blender
Code Cleanup - Style tweaks
This commit is contained in:
parent
bfbbc8ec40
commit
00cfbeef11
@ -126,6 +126,23 @@ extern ListBase gp_strokes_copypastebuf;
|
|||||||
|
|
||||||
void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags);
|
void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply smooth to stroke
|
||||||
|
*
|
||||||
|
* \param gps Stroke to smooth
|
||||||
|
* \param i Point index
|
||||||
|
* \param inf Smooth factor
|
||||||
|
*/
|
||||||
|
bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subdivide a stroke
|
||||||
|
* \param gps Stroke data
|
||||||
|
* \param new_totpoints Total number of points
|
||||||
|
*/
|
||||||
|
void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
|
||||||
|
|
||||||
/* Layers Enums -------------------------------------- */
|
/* Layers Enums -------------------------------------- */
|
||||||
|
|
||||||
struct EnumPropertyItem *ED_gpencil_layers_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
|
struct EnumPropertyItem *ED_gpencil_layers_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
|
||||||
@ -208,21 +225,6 @@ void gpencil_undo_init(struct bGPdata *gpd);
|
|||||||
void gpencil_undo_push(struct bGPdata *gpd);
|
void gpencil_undo_push(struct bGPdata *gpd);
|
||||||
void gpencil_undo_finish(void);
|
void gpencil_undo_finish(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply smooth to stroke
|
|
||||||
*
|
|
||||||
* gps Stroke to smooth
|
|
||||||
* i Point index
|
|
||||||
* inf Smooth factor
|
|
||||||
*/
|
|
||||||
bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf);
|
|
||||||
|
|
||||||
/* subdivide a stroke
|
|
||||||
* gps Stroke data
|
|
||||||
* new_totpoints Total number of points
|
|
||||||
*/
|
|
||||||
void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
|
|
||||||
|
|
||||||
/******************************************************* */
|
/******************************************************* */
|
||||||
/* FILTERED ACTION DATA - TYPES ---> XXX DEPRECEATED OLD ANIM SYSTEM CODE! */
|
/* FILTERED ACTION DATA - TYPES ---> XXX DEPRECEATED OLD ANIM SYSTEM CODE! */
|
||||||
|
|
||||||
|
@ -568,10 +568,10 @@ static void gp_stroke_simplify(tGPsdata *p)
|
|||||||
static void gp_stroke_newfrombuffer(tGPsdata *p)
|
static void gp_stroke_newfrombuffer(tGPsdata *p)
|
||||||
{
|
{
|
||||||
bGPdata *gpd = p->gpd;
|
bGPdata *gpd = p->gpd;
|
||||||
|
bGPDlayer *gpl = p->gpl;
|
||||||
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 */
|
||||||
@ -612,14 +612,13 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
|
|||||||
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 */
|
||||||
int sublevel = layer->sublevel;
|
int sublevel = gpl->sublevel;
|
||||||
int new_totpoints = gps->totpoints;
|
int new_totpoints = gps->totpoints;
|
||||||
for (i = 0; i < sublevel; ++i)
|
for (i = 0; i < sublevel; i++) {
|
||||||
{
|
/* Avoid error if subdivide is too big (assume totpoints is right) */
|
||||||
// Avoid error if subdivide is too big (assume totpoints is right)
|
if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX) {
|
||||||
if (new_totpoints + (new_totpoints - 1) > GP_STROKE_BUFFER_MAX)
|
/* Reduce sublevel to avoid too-dense strokes */
|
||||||
{
|
sublevel = i;
|
||||||
sublevel = i; // reduce sublevel
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
new_totpoints += new_totpoints - 1;
|
new_totpoints += new_totpoints - 1;
|
||||||
@ -745,21 +744,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* subdivide the stroke */
|
/* subdivide the stroke */
|
||||||
if (sublevel > 0)
|
if (sublevel > 0) {
|
||||||
{
|
|
||||||
int sub = gps->totpoints;
|
int sub = gps->totpoints;
|
||||||
for (i = 0; i < sublevel; ++i)
|
for (i = 0; i < sublevel; i++) {
|
||||||
{
|
|
||||||
sub += sub - 1;
|
sub += sub - 1;
|
||||||
gp_subdivide_stroke(gps, sub);
|
gp_subdivide_stroke(gps, sub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* smooth stroke */
|
/* smooth stroke - only if there's somethign to do */
|
||||||
if (layer->smooth_drawfac > 0.0f) // only if something to do
|
if (gpl->smooth_drawfac > 0.0f) {
|
||||||
{
|
for (i = 0; i < gps->totpoints; i++) {
|
||||||
for (i = 0; i < gps->totpoints; i++)
|
gp_smooth_stroke(gps, i, gpl->smooth_drawfac);
|
||||||
{
|
|
||||||
gp_smooth_stroke(gps, i, layer->smooth_drawfac);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,28 +533,29 @@ bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, Scene *scene, const float screen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply smooth to stroke point
|
/**
|
||||||
* gps Stroke to smooth
|
* Apply smooth to stroke point
|
||||||
* i Point index
|
* \param gps Stroke to smooth
|
||||||
* inf Smooth factor
|
* \param i Point index
|
||||||
|
* \param inf Smooth factor
|
||||||
*/
|
*/
|
||||||
bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
|
bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
|
||||||
{
|
{
|
||||||
bGPDspoint *pt = &gps->points[i];
|
bGPDspoint *pt = &gps->points[i];
|
||||||
float sco[3] = { 0.0f };
|
float sco[3] = {0.0f};
|
||||||
|
|
||||||
/* Do nothing if not enough points to smooth out */
|
/* Do nothing if not enough points to smooth out */
|
||||||
if (gps->totpoints <= 2) {
|
if (gps->totpoints <= 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only affect endpoints by a fraction of the normal strength,
|
/* Only affect endpoints by a fraction of the normal strength,
|
||||||
* to prevent the stroke from shrinking too much
|
* to prevent the stroke from shrinking too much
|
||||||
*/
|
*/
|
||||||
if ((i == 0) || (i == gps->totpoints - 1)) {
|
if ((i == 0) || (i == gps->totpoints - 1)) {
|
||||||
inf *= 0.1f;
|
inf *= 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute smoothed coordinate by taking the ones nearby */
|
/* Compute smoothed coordinate by taking the ones nearby */
|
||||||
/* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */
|
/* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */
|
||||||
{
|
{
|
||||||
@ -562,10 +563,10 @@ bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
|
|||||||
const int steps = 2;
|
const int steps = 2;
|
||||||
const float average_fac = 1.0f / (float)(steps * 2 + 1);
|
const float average_fac = 1.0f / (float)(steps * 2 + 1);
|
||||||
int step;
|
int step;
|
||||||
|
|
||||||
/* add the point itself */
|
/* add the point itself */
|
||||||
madd_v3_v3fl(sco, &pt->x, average_fac);
|
madd_v3_v3fl(sco, &pt->x, average_fac);
|
||||||
|
|
||||||
/* n-steps before/after current point */
|
/* n-steps before/after current point */
|
||||||
// XXX: review how the endpoints are treated by this algorithm
|
// XXX: review how the endpoints are treated by this algorithm
|
||||||
// XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight
|
// XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight
|
||||||
@ -573,62 +574,61 @@ bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf)
|
|||||||
bGPDspoint *pt1, *pt2;
|
bGPDspoint *pt1, *pt2;
|
||||||
int before = i - step;
|
int before = i - step;
|
||||||
int after = i + step;
|
int after = i + step;
|
||||||
|
|
||||||
CLAMP_MIN(before, 0);
|
CLAMP_MIN(before, 0);
|
||||||
CLAMP_MAX(after, gps->totpoints - 1);
|
CLAMP_MAX(after, gps->totpoints - 1);
|
||||||
|
|
||||||
pt1 = &gps->points[before];
|
pt1 = &gps->points[before];
|
||||||
pt2 = &gps->points[after];
|
pt2 = &gps->points[after];
|
||||||
|
|
||||||
/* add both these points to the average-sum (s += p[i]/n) */
|
/* add both these points to the average-sum (s += p[i]/n) */
|
||||||
madd_v3_v3fl(sco, &pt1->x, average_fac);
|
madd_v3_v3fl(sco, &pt1->x, average_fac);
|
||||||
madd_v3_v3fl(sco, &pt2->x, average_fac);
|
madd_v3_v3fl(sco, &pt2->x, average_fac);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Based on influence factor, blend between original and optimal smoothed coordinate */
|
/* Based on influence factor, blend between original and optimal smoothed coordinate */
|
||||||
interp_v3_v3v3(&pt->x, &pt->x, sco, inf);
|
interp_v3_v3v3(&pt->x, &pt->x, sco, inf);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* subdivide a stroke
|
/**
|
||||||
* gps Stroke data
|
* Subdivide a stroke
|
||||||
* new_totpoints Total number of points
|
* \param gps Stroke data
|
||||||
*/
|
* \param new_totpoints Total number of points
|
||||||
|
*/
|
||||||
void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints)
|
void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
// Subdivide stroke adding a point half way existing points
|
/* Subdivide stroke adding a point half way existing points */
|
||||||
bGPDspoint *pt_a;
|
bGPDspoint *pt_a;
|
||||||
bGPDspoint *pt_b;
|
bGPDspoint *pt_b;
|
||||||
bGPDspoint *pt_n;
|
bGPDspoint *pt_n;
|
||||||
|
|
||||||
/* Move points to insert subdivision */
|
/* Move points to insert subdivision */
|
||||||
int y = 1;
|
int y = 1;
|
||||||
for (i = gps->totpoints - 1; i > 0; --i)
|
for (i = gps->totpoints - 1; i > 0; i--) {
|
||||||
{
|
|
||||||
pt_n = &gps->points[i];
|
pt_n = &gps->points[i];
|
||||||
gps->points[new_totpoints - y] = *pt_n;
|
gps->points[new_totpoints - y] = *pt_n;
|
||||||
y = y + 2;
|
y = y + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create interpolated points */
|
/* Create interpolated points */
|
||||||
for (i = 0; i < new_totpoints - 1; ++i)
|
for (i = 0; i < new_totpoints - 1; i++) {
|
||||||
{
|
|
||||||
pt_a = &gps->points[i];
|
pt_a = &gps->points[i];
|
||||||
pt_n = &gps->points[i + 1];
|
pt_n = &gps->points[i + 1];
|
||||||
pt_b = &gps->points[i + 2];
|
pt_b = &gps->points[i + 2];
|
||||||
// Interpolate all values
|
/* Interpolate all values */
|
||||||
interp_v3_v3v3(&pt_n->x, &pt_a->x, &pt_b->x, 0.5f);
|
interp_v3_v3v3(&pt_n->x, &pt_a->x, &pt_b->x, 0.5f);
|
||||||
pt_n->pressure = interpf(pt_a->pressure, pt_b->pressure, 0.5f);
|
pt_n->pressure = interpf(pt_a->pressure, pt_b->pressure, 0.5f);
|
||||||
pt_n->time = interpf(pt_a->time, pt_b->time, 0.5f);
|
pt_n->time = interpf(pt_a->time, pt_b->time, 0.5f);
|
||||||
|
|
||||||
++i; // add to loop to jump next pair
|
i++; /* add to loop to jump next pair */
|
||||||
}
|
}
|
||||||
|
|
||||||
gps->totpoints = new_totpoints; // Increase number of points
|
gps->totpoints = new_totpoints; /* Increase number of points */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ******************************************************** */
|
/* ******************************************************** */
|
||||||
|
Loading…
Reference in New Issue
Block a user