GPencil: New BKE function to set stroke start point
This function allows to set the start point for cyclic strokes. The function is required by a new modifier and operator that are currently under development.
This commit is contained in:
@@ -406,7 +406,13 @@ void BKE_gpencil_stroke_join(struct bGPDstroke *gps_a,
|
||||
struct bGPDstroke *gps_b,
|
||||
bool leave_gaps,
|
||||
bool fit_thickness,
|
||||
bool smooth);
|
||||
bool smooth,
|
||||
bool auto_flip);
|
||||
/**
|
||||
* Set stroke start point in the selected index. Only works for Cyclic strokes.
|
||||
* \param start_idx: Index of the point to be the start point.
|
||||
*/
|
||||
void BKE_gpencil_stroke_start_set(struct bGPdata *gpd, struct bGPDstroke *gps, int start_idx);
|
||||
/**
|
||||
* Copy the stroke of the frame to all frames selected (except current).
|
||||
*/
|
||||
|
@@ -3415,7 +3415,8 @@ void BKE_gpencil_stroke_join(bGPDstroke *gps_a,
|
||||
bGPDstroke *gps_b,
|
||||
const bool leave_gaps,
|
||||
const bool fit_thickness,
|
||||
const bool smooth)
|
||||
const bool smooth,
|
||||
bool auto_flip)
|
||||
{
|
||||
bGPDspoint point;
|
||||
bGPDspoint *pt;
|
||||
@@ -3432,52 +3433,54 @@ void BKE_gpencil_stroke_join(bGPDstroke *gps_a,
|
||||
return;
|
||||
}
|
||||
|
||||
/* define start and end points of each stroke */
|
||||
float start_a[3], start_b[3], end_a[3], end_b[3];
|
||||
pt = &gps_a->points[0];
|
||||
copy_v3_v3(start_a, &pt->x);
|
||||
if (auto_flip) {
|
||||
/* define start and end points of each stroke */
|
||||
float start_a[3], start_b[3], end_a[3], end_b[3];
|
||||
pt = &gps_a->points[0];
|
||||
copy_v3_v3(start_a, &pt->x);
|
||||
|
||||
pt = &gps_a->points[gps_a->totpoints - 1];
|
||||
copy_v3_v3(end_a, &pt->x);
|
||||
pt = &gps_a->points[gps_a->totpoints - 1];
|
||||
copy_v3_v3(end_a, &pt->x);
|
||||
|
||||
pt = &gps_b->points[0];
|
||||
copy_v3_v3(start_b, &pt->x);
|
||||
pt = &gps_b->points[0];
|
||||
copy_v3_v3(start_b, &pt->x);
|
||||
|
||||
pt = &gps_b->points[gps_b->totpoints - 1];
|
||||
copy_v3_v3(end_b, &pt->x);
|
||||
pt = &gps_b->points[gps_b->totpoints - 1];
|
||||
copy_v3_v3(end_b, &pt->x);
|
||||
|
||||
/* Check if need flip strokes. */
|
||||
float dist = len_squared_v3v3(end_a, start_b);
|
||||
bool flip_a = false;
|
||||
bool flip_b = false;
|
||||
float lowest = dist;
|
||||
/* Check if need flip strokes. */
|
||||
float dist = len_squared_v3v3(end_a, start_b);
|
||||
bool flip_a = false;
|
||||
bool flip_b = false;
|
||||
float lowest = dist;
|
||||
|
||||
dist = len_squared_v3v3(end_a, end_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = false;
|
||||
flip_b = true;
|
||||
}
|
||||
dist = len_squared_v3v3(end_a, end_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = false;
|
||||
flip_b = true;
|
||||
}
|
||||
|
||||
dist = len_squared_v3v3(start_a, start_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = true;
|
||||
flip_b = false;
|
||||
}
|
||||
dist = len_squared_v3v3(start_a, start_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = true;
|
||||
flip_b = false;
|
||||
}
|
||||
|
||||
dist = len_squared_v3v3(start_a, end_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = true;
|
||||
flip_b = true;
|
||||
}
|
||||
dist = len_squared_v3v3(start_a, end_b);
|
||||
if (dist < lowest) {
|
||||
lowest = dist;
|
||||
flip_a = true;
|
||||
flip_b = true;
|
||||
}
|
||||
|
||||
if (flip_a) {
|
||||
BKE_gpencil_stroke_flip(gps_a);
|
||||
}
|
||||
if (flip_b) {
|
||||
BKE_gpencil_stroke_flip(gps_b);
|
||||
if (flip_a) {
|
||||
BKE_gpencil_stroke_flip(gps_a);
|
||||
}
|
||||
if (flip_b) {
|
||||
BKE_gpencil_stroke_flip(gps_b);
|
||||
}
|
||||
}
|
||||
|
||||
/* don't visibly link the first and last points? */
|
||||
@@ -3540,6 +3543,29 @@ void BKE_gpencil_stroke_join(bGPDstroke *gps_a,
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_gpencil_stroke_start_set(bGPdata *gpd, bGPDstroke *gps, int start_idx)
|
||||
{
|
||||
if ((start_idx < 1) || (start_idx >= gps->totpoints)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Only cyclic strokes. */
|
||||
if ((gps->flag & GP_STROKE_CYCLIC) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bGPDstroke *gps_b = BKE_gpencil_stroke_duplicate(gps, true, false);
|
||||
BKE_gpencil_stroke_trim_points(gps_b, 0, start_idx - 0);
|
||||
BKE_gpencil_stroke_trim_points(gps, start_idx, gps->totpoints - 1);
|
||||
|
||||
/* Join both strokes. */
|
||||
BKE_gpencil_stroke_join(gps, gps_b, false, false, false, false);
|
||||
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
BKE_gpencil_free_stroke(gps_b);
|
||||
}
|
||||
|
||||
void BKE_gpencil_stroke_copy_to_keyframes(
|
||||
bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps, const bool tail)
|
||||
{
|
||||
|
@@ -3650,7 +3650,7 @@ static int gpencil_stroke_join_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
elem = &strokes_list[i];
|
||||
/* Join new_stroke and stroke B. */
|
||||
BKE_gpencil_stroke_join(gps_new, elem->gps, leave_gaps, true, false);
|
||||
BKE_gpencil_stroke_join(gps_new, elem->gps, leave_gaps, true, false, true);
|
||||
elem->used = true;
|
||||
}
|
||||
|
||||
|
@@ -3189,7 +3189,7 @@ bGPDstroke *ED_gpencil_stroke_join_and_trim(
|
||||
|
||||
/* Join both strokes. */
|
||||
int totpoint = gps_final->totpoints;
|
||||
BKE_gpencil_stroke_join(gps_final, gps, false, true, true);
|
||||
BKE_gpencil_stroke_join(gps_final, gps, false, true, true, true);
|
||||
|
||||
/* Select the join points and merge if the distance is very small. */
|
||||
pt = &gps_final->points[totpoint - 1];
|
||||
|
Reference in New Issue
Block a user