[Bf-blender-cvs] [96ffed6] gsoc2016-improved_extrusion: Curves: Extend curve operator
João Araújo
noreply at git.blender.org
Tue Jun 14 12:31:35 CEST 2016
Commit: 96ffed6b2bb69572180ff95836fd55b8a6b6f993
Author: João Araújo
Date: Tue Jun 14 11:29:31 2016 +0100
Branches: gsoc2016-improved_extrusion
https://developer.blender.org/rB96ffed6b2bb69572180ff95836fd55b8a6b6f993
Curves: Extend curve operator
Implements the "get_intersections" function, which calculates intersections between straigth lines and Bezier curves.
===================================================================
M release/datafiles/locale
M release/scripts/addons
M release/scripts/addons_contrib
M source/blender/editors/curve/editcurve.c
===================================================================
diff --git a/release/datafiles/locale b/release/datafiles/locale
index fff5b57..95f26f9 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit fff5b57dfbe2b69fb85f69715bb92acd3b3f68a2
+Subproject commit 95f26f93f441a6c26c476b7d5c386f4f78c64fb7
diff --git a/release/scripts/addons b/release/scripts/addons
index 16edba6..c4a7943 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 16edba689ed3295d738fb70247b50b54872a47fa
+Subproject commit c4a79435e45610d50dadfacf2ed2c09ce595f70f
diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib
index 8519564..980b8a6 160000
--- a/release/scripts/addons_contrib
+++ b/release/scripts/addons_contrib
@@ -1 +1 @@
-Subproject commit 8519564c212910db4ccb0a93742f75fec36c3952
+Subproject commit 980b8a64339ea72c45bc6efb642e1b1f52d0a333
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 4e76873..8050305 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -6454,14 +6454,15 @@ static ListBase *interpolate_all_segments(Nurb *nu)
int i = 0, dims = 3;
float *coord_array;
ListBase pl = {NULL,NULL};
- LinkData link;
+ LinkData *link;
/* number of BezTriples */
int bezier_points = nu->pntsu;
while (i < bezier_points-1+nu->flagu) {
coord_array = MEM_callocN(dims * (nu->resolu) * sizeof(float), "interpolate_bezier2");
- link.data = coord_array;
+ link = MEM_callocN(sizeof(LinkData), "interpolate_bezier3");
+ link->data = coord_array;
for (int j = 0; j < dims; j++) {
BKE_curve_forward_diff_bezier(nu->bezt[i%bezier_points].vec[1][j],
nu->bezt[i%bezier_points].vec[2][j],
@@ -6469,48 +6470,61 @@ static ListBase *interpolate_all_segments(Nurb *nu)
nu->bezt[(i+1)%bezier_points].vec[1][j],
coord_array + j, nu->resolu - 1, sizeof(float) * dims);
}
- BLI_addtail(&pl, &link);
+ BLI_addtail(&pl, link);
i++;
}
return &pl;
}
-/*
-def interpolate_all_segments(spline_ob):
-'''
-> spline_ob: bezier spline object
-< returns interpolated splinepoints
-'''
-point_range = len(spline_ob.bezier_points)
-pl = []
-
-for i in range (0, point_range-1+spline_ob.use_cyclic_u):
-if len(pl) > 0:
-pl.pop()
-seg = (interpolate_bezier(spline_ob.bezier_points[i%point_range].co,
- spline_ob.bezier_points[i%point_range].handle_right,
- spline_ob.bezier_points[(i+1)%point_range].handle_left,
- spline_ob.bezier_points[(i+1)%point_range].co,
- spline_ob.resolution_u+1))
-pl += seg
-return pl */
-
static ListBase *linear_spline_list(ListBase *nubase)
{
/* return a list with all the points of a curve object */
ListBase spline_list = {NULL, NULL};
- LinkData link;
+ LinkData *link;
Nurb *nu;
for (nu=nubase->first; nu; nu=nu->next) {
- link.data = interpolate_all_segments(nu);
- BLI_addtail(&spline_list, &link);
+ link = MEM_callocN(sizeof(LinkData), "linearspllist1");
+ link->data = interpolate_all_segments(nu);
+ BLI_addtail(&spline_list, link);
}
return &spline_list;
}
+static ListBase *get_intersections(float *p1, float *p2, ListBase *nubase)
+{
+ /* return a list with all the intersection points of the segment p1p2 with the curve object */
+ ListBase il = {NULL, NULL}, *spline_list, *points_list;
+ LinkData *intersection, *link, *spl;
+ float *coord_array, vi[2], p3[2], p4[2];
+ Nurb *nu = nubase->first;
+ int dims = 3, result;
+ const float PRECISION = 1e-05;
+
+ spline_list = linear_spline_list(nubase); /* all the points in a curve object */
+ for (spl=spline_list->first; spl; spl=spl->next) { /* selecting the points of a given spline */
+ points_list = spl->data; /* output of interpolate_all_segments */
+ for (link = points_list->first; link; link=link->next) {
+ coord_array = (float *)link->data;
+ for (int i = 0; i < nu->resolu - 1; i++) {
+ p3[0] = coord_array[i * dims];
+ p3[1] = coord_array[i * dims + 1];
+ p4[0] = coord_array[(i + 1) * dims];
+ p4[1] = coord_array[(i + 1) * dims + 1];
+ result = isect_seg_seg_v2_point(p2, p1, p3, p4, vi);
+ if (result == 1 && len_v2v2(vi, p1) > PRECISION) {
+ intersection = MEM_callocN(sizeof(LinkData), "getintersections1");
+ intersection->data = vi;
+ BLI_addtail(&il, intersection);
+ }
+ }
+ }
+ }
+ return &il;
+}
+
static int extend_curve_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
@@ -6551,6 +6565,8 @@ static int extend_curve_exec(bContext *C, wmOperator *op)
}
get_nurb_shape_bounds(obedit, bound_box);
get_max_extent_2d(p1, p1_handle, bound_box, p1_extend);
+ intersections_list = get_intersections(p1, p1_extend, nubase);
+ /* nearest_point(p1, get_intersections(p1, p1_extend, nubase), 0, p2); */
}
}
More information about the Bf-blender-cvs
mailing list