[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47385] branches/soc-2011-tomato/source/ blender: - adding subdivided points now interpolates weights along the spline.
Campbell Barton
ideasman42 at gmail.com
Sun Jun 3 21:39:27 CEST 2012
Revision: 47385
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47385
Author: campbellbarton
Date: 2012-06-03 19:39:19 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
- adding subdivided points now interpolates weights along the spline.
- the handle lengths are now interpolated based on the new points projected location along the spline.
Modified Paths:
--------------
branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c
Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h 2012-06-03 19:10:19 UTC (rev 47384)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_mask.h 2012-06-03 19:39:19 UTC (rev 47385)
@@ -110,7 +110,8 @@
void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime, const int do_newframe);
void BKE_mask_update_scene(struct Main *bmain, struct Scene *scene, const int do_newframe);
void BKE_mask_parent_init(struct MaskParent *parent);
-void BKE_mask_calc_handle_adjacent_length(struct Mask *mask, struct MaskSpline *spline, struct MaskSplinePoint *point);
+void BKE_mask_calc_handle_adjacent_interp(struct Mask *mask, struct MaskSpline *spline, struct MaskSplinePoint *point,
+ const float u);
void BKE_mask_calc_tangent_polyline(struct Mask *mask, struct MaskSpline *spline, struct MaskSplinePoint *point, float t[2]);
void BKE_mask_calc_handle_point(struct Mask *mask, struct MaskSpline *spline, struct MaskSplinePoint *point);
void BKE_mask_calc_handle_point_auto(struct Mask *mask, struct MaskSpline *spline, struct MaskSplinePoint *point,
Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c 2012-06-03 19:10:19 UTC (rev 47384)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/mask.c 2012-06-03 19:39:19 UTC (rev 47385)
@@ -1077,31 +1077,50 @@
}
}
-void BKE_mask_calc_handle_adjacent_length(Mask *mask, MaskSpline *spline, MaskSplinePoint *point)
+void BKE_mask_calc_handle_adjacent_interp(Mask *mask, MaskSpline *spline, MaskSplinePoint *point, const float u)
{
/* TODO! - make this interpolate between siblings - not always midpoint! */
int length_tot = 0;
float length_average = 0.0f;
+ float weight_average = 0.0f;
+
MaskSplinePoint *prev_point, *next_point;
+
+ BLI_assert(u >= 0.0f && u <= 1.0f);
+
BKE_mask_get_handle_point_adjacent(mask, spline, point,
&prev_point, &next_point);
- if (prev_point) {
- length_average += len_v2v2(prev_point->bezt.vec[0], prev_point->bezt.vec[1]);
- length_tot++;
+ if (prev_point && next_point) {
+ length_average = ((len_v2v2(prev_point->bezt.vec[0], prev_point->bezt.vec[1]) * (1.0f - u)) +
+ (len_v2v2(next_point->bezt.vec[2], next_point->bezt.vec[1]) * u));
+
+ weight_average = (prev_point->bezt.weight * (1.0f - u) +
+ next_point->bezt.weight * u);
+ length_tot = 1;
}
+ else {
+ if (prev_point) {
+ length_average += len_v2v2(prev_point->bezt.vec[0], prev_point->bezt.vec[1]);
+ weight_average += prev_point->bezt.weight;
+ length_tot++;
+ }
- if (next_point) {
- length_average += len_v2v2(next_point->bezt.vec[2], next_point->bezt.vec[1]);
- length_tot++;
+ if (next_point) {
+ length_average += len_v2v2(next_point->bezt.vec[2], next_point->bezt.vec[1]);
+ weight_average += next_point->bezt.weight;
+ length_tot++;
+ }
}
if (length_tot) {
length_average /= (float)length_tot;
+ weight_average /= (float)length_tot;
enforce_dist_v2_v2fl(point->bezt.vec[0], point->bezt.vec[1], length_average);
enforce_dist_v2_v2fl(point->bezt.vec[2], point->bezt.vec[1], length_average);
+ point->bezt.weight = weight_average;
}
}
Modified: branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c 2012-06-03 19:10:19 UTC (rev 47384)
+++ branches/soc-2011-tomato/source/blender/editors/mask/mask_ops.c 2012-06-03 19:39:19 UTC (rev 47385)
@@ -946,7 +946,7 @@
/******************** add vertex *********************/
static void setup_vertex_point(bContext *C, Mask *mask, MaskSpline *spline, MaskSplinePoint *new_point,
- const float point_co[2], const float tangent[2],
+ const float point_co[2], const float tangent[2], const float u,
MaskSplinePoint *reference_point, const short reference_adjacent)
{
MaskSplinePoint *prev_point = NULL;
@@ -1008,7 +1008,7 @@
add_v2_v2(bezt->vec[2], vec);
if (reference_adjacent) {
- BKE_mask_calc_handle_adjacent_length(mask, spline, new_point);
+ BKE_mask_calc_handle_adjacent_interp(mask, spline, new_point, u);
}
}
else {
@@ -1061,7 +1061,7 @@
sub_v2_v2(bezt->vec[2], vec);
#else
BKE_mask_calc_handle_point_auto(mask, spline, new_point, TRUE);
- BKE_mask_calc_handle_adjacent_length(mask, spline, new_point);
+ BKE_mask_calc_handle_adjacent_interp(mask, spline, new_point, u);
#endif
}
@@ -1097,8 +1097,9 @@
MaskSplinePoint *point = NULL;
const float threshold = 9;
float tangent[2];
+ float u;
- if (find_nearest_diff_point(C, mask, co, threshold, FALSE, &masklay, &spline, &point, NULL, tangent)) {
+ if (find_nearest_diff_point(C, mask, co, threshold, FALSE, &masklay, &spline, &point, &u, tangent)) {
MaskSplinePoint *new_point;
int point_index = point - spline->points;
@@ -1108,7 +1109,7 @@
new_point = &spline->points[point_index + 1];
- setup_vertex_point(C, mask, spline, new_point, co, tangent, NULL, TRUE);
+ setup_vertex_point(C, mask, spline, new_point, co, tangent, u, NULL, TRUE);
/* TODO - we could pass the spline! */
BKE_mask_layer_shape_changed_add(masklay, BKE_mask_layer_shape_spline_to_index(masklay, spline) + point_index + 1, TRUE, TRUE);
@@ -1249,7 +1250,7 @@
masklay->act_point = new_point;
- setup_vertex_point(C, mask, spline, new_point, co, NULL, ref_point, FALSE);
+ setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE);
if (masklay->splines_shapes.first) {
point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
@@ -1295,7 +1296,7 @@
masklay->act_point = new_point;
- setup_vertex_point(C, mask, spline, new_point, co, NULL, ref_point, FALSE);
+ setup_vertex_point(C, mask, spline, new_point, co, NULL, 0.5f, ref_point, FALSE);
{
int point_index = (((int)(new_point - spline->points) + 0) % spline->tot_point);
More information about the Bf-blender-cvs
mailing list