mask point slide now accounts for scaled bezier weights,
This commit is contained in:
@@ -98,6 +98,7 @@ float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *sp
|
||||
void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]);
|
||||
void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point,
|
||||
float u, float n[2]);
|
||||
float BKE_mask_point_weight_scalar(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u);
|
||||
float BKE_mask_point_weight(struct MaskSpline *spline, struct MaskSplinePoint *point, float u);
|
||||
struct MaskSplinePointUW *BKE_mask_point_sort_uw(struct MaskSplinePoint *point, struct MaskSplinePointUW *uw);
|
||||
void BKE_mask_point_add_uw(struct MaskSplinePoint *point, float u, float w);
|
||||
|
||||
@@ -782,7 +782,28 @@ static float mask_point_interp_weight(BezTriple *bezt, BezTriple *bezt_next, con
|
||||
return (bezt->weight * (1.0f - u)) + (bezt_next->weight * u);
|
||||
}
|
||||
|
||||
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, float u)
|
||||
float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, const float u)
|
||||
{
|
||||
MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
|
||||
BezTriple *bezt = &point->bezt, *bezt_next;
|
||||
|
||||
bezt_next = mask_spline_point_next_bezt(spline, points_array, point);
|
||||
|
||||
if (!bezt_next) {
|
||||
return bezt->weight;
|
||||
}
|
||||
else if (u <= 0.0) {
|
||||
return bezt->weight;
|
||||
}
|
||||
else if (u >= 1.0f) {
|
||||
return bezt_next->weight;
|
||||
}
|
||||
else {
|
||||
return mask_point_interp_weight(bezt, bezt_next, u);
|
||||
}
|
||||
}
|
||||
|
||||
float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const float u)
|
||||
{
|
||||
MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point);
|
||||
BezTriple *bezt = &point->bezt, *bezt_next;
|
||||
|
||||
@@ -654,6 +654,11 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op)
|
||||
if (find_nearest_diff_point(C, mask, co, threshold, TRUE, &masklay, &spline, &point, &u, NULL)) {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
float w = BKE_mask_point_weight(spline, point, u);
|
||||
float weight_scalar = BKE_mask_point_weight_scalar(spline, point, u);
|
||||
|
||||
if (weight_scalar != 0.0f) {
|
||||
w = w / weight_scalar;
|
||||
}
|
||||
|
||||
BKE_mask_point_add_uw(point, u, w);
|
||||
|
||||
|
||||
@@ -387,15 +387,18 @@ static int slide_point_check_initial_feather(MaskSpline *spline)
|
||||
|
||||
for (i = 0; i < spline->tot_point; i++) {
|
||||
MaskSplinePoint *point = &spline->points[i];
|
||||
int j;
|
||||
|
||||
if (point->bezt.weight != 0.0f)
|
||||
return FALSE;
|
||||
|
||||
/* comment for now. if all bezt weights are zero - this is as good-as initial */
|
||||
#if 0
|
||||
int j;
|
||||
for (j = 0; j < point->tot_uw; j++) {
|
||||
if (point->uw[j].w != 0.0f)
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -454,25 +457,21 @@ static void *slide_point_customdata(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
if (uw) {
|
||||
float co[2];
|
||||
|
||||
customdata->weight = point->bezt.weight;
|
||||
float weight_scalar = BKE_mask_point_weight_scalar(spline, point, uw->u);
|
||||
|
||||
customdata->weight = uw->w;
|
||||
BKE_mask_point_segment_co(spline, point, uw->u, co);
|
||||
BKE_mask_point_normal(spline, point, uw->u, customdata->no);
|
||||
|
||||
customdata->feather[0] = co[0] + customdata->no[0] * uw->w;
|
||||
customdata->feather[1] = co[1] + customdata->no[1] * uw->w;
|
||||
madd_v2_v2v2fl(customdata->feather, co, customdata->no, uw->w * weight_scalar);
|
||||
}
|
||||
else {
|
||||
BezTriple *bezt = &point->bezt;
|
||||
|
||||
customdata->weight = bezt->weight;
|
||||
BKE_mask_point_normal(spline, point, 0.0f, customdata->no);
|
||||
|
||||
customdata->feather[0] = bezt->vec[1][0] + customdata->no[0] * bezt->weight;
|
||||
customdata->feather[1] = bezt->vec[1][1] + customdata->no[1] * bezt->weight;
|
||||
|
||||
customdata->weight = bezt->weight;
|
||||
madd_v2_v2v2fl(customdata->feather, bezt->vec[1], customdata->no, bezt->weight);
|
||||
}
|
||||
|
||||
if (customdata->action == SLIDE_ACTION_FEATHER)
|
||||
@@ -533,17 +532,20 @@ static void slide_point_delta_all_feather(SlidePointData *data, float delta)
|
||||
for (i = 0; i < data->spline->tot_point; i++) {
|
||||
MaskSplinePoint *point = &data->spline->points[i];
|
||||
MaskSplinePoint *orig_point = &data->orig_spline->points[i];
|
||||
int j;
|
||||
|
||||
point->bezt.weight = orig_point->bezt.weight + delta;
|
||||
if (point->bezt.weight < 0.0f)
|
||||
point->bezt.weight = 0.0f;
|
||||
|
||||
/* not needed anymore */
|
||||
#if 0
|
||||
int j;
|
||||
for (j = 0; j < point->tot_uw; j++) {
|
||||
point->uw[j].w = orig_point->uw[j].w + delta;
|
||||
if (point->uw[j].w < 0.0f)
|
||||
point->uw[j].w = 0.0f;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,6 +647,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
else if (data->action == SLIDE_ACTION_FEATHER) {
|
||||
float vec[2], no[2], p[2], c[2], w, offco[2];
|
||||
float *weight = NULL;
|
||||
float weight_scalar = 1.0f;
|
||||
int overall_feather = data->overall_feather || data->initial_feather;
|
||||
|
||||
add_v2_v2v2(offco, data->feather, dco);
|
||||
@@ -679,12 +682,18 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
data->uw = BKE_mask_point_sort_uw(data->point, data->uw);
|
||||
weight = &data->uw->w;
|
||||
weight_scalar = BKE_mask_point_weight_scalar(data->spline, data->point, u);
|
||||
if (weight_scalar != 0.0f) {
|
||||
weight_scalar = 1.0f / weight_scalar;
|
||||
}
|
||||
|
||||
BKE_mask_point_normal(data->spline, data->point, data->uw->u, no);
|
||||
BKE_mask_point_segment_co(data->spline, data->point, data->uw->u, p);
|
||||
}
|
||||
}
|
||||
else {
|
||||
weight = &bezt->weight;
|
||||
/* weight_scalar = 1.0f; keep as is */
|
||||
copy_v2_v2(no, data->no);
|
||||
copy_v2_v2(p, bezt->vec[1]);
|
||||
}
|
||||
@@ -707,7 +716,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
/* restore weight for currently sliding point, so orig_spline would be created
|
||||
* with original weights used
|
||||
*/
|
||||
*weight = data->weight;
|
||||
*weight = data->weight * weight_scalar;
|
||||
|
||||
data->orig_spline = BKE_mask_spline_copy(data->spline);
|
||||
}
|
||||
@@ -726,7 +735,9 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
data->orig_spline = NULL;
|
||||
}
|
||||
|
||||
*weight = w;
|
||||
if (weight_scalar != 0.0f) {
|
||||
*weight = w * weight_scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user