[Bf-blender-cvs] [f630ed8] soc-2014-nurbs: Progress commit: adding support for import+tessellate trim curves (mem mgt bugs).
Jonathan deWerd
noreply at git.blender.org
Sun Jul 27 11:54:01 CEST 2014
Commit: f630ed83d6a256d2e85a6909dee3fa7a29e0ce88
Author: Jonathan deWerd
Date: Sat Jul 26 22:53:25 2014 -0400
Branches: soc-2014-nurbs
https://developer.blender.org/rBf630ed83d6a256d2e85a6909dee3fa7a29e0ce88
Progress commit: adding support for import+tessellate trim curves (mem mgt bugs).
===================================================================
M source/blender/blenkernel/BKE_curve.h
M source/blender/blenkernel/intern/curve.cpp
M source/blender/blenkernel/intern/curve_eval.cpp
M source/blender/blenkernel/intern/mesh.c
M source/blender/editors/io/io_rhino_import.cpp
M source/blender/makesdna/DNA_curve_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index f689175..e8d27715 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -210,8 +210,8 @@ void BKE_nurb_handles_autocalc(struct Nurb *nu, int flag);
void BKE_nurb_bezt_handle_test(struct BezTriple *bezt, const bool use_handle);
void BKE_nurb_handles_test(struct Nurb *nu, const bool use_handles);
-/* Does not traverse nu's linked list. Fills dl with a mesh corresponding to
- * the single surface nu, performing trim if necessary.
+/* Does not traverse nurb's linked list. Fills dl with a mesh corresponding to
+ * the single surface nurb, performing trim if necessary.
*/
void BKE_nurb_make_displist(struct Nurb *nurb, struct DispList *dl);
diff --git a/source/blender/blenkernel/intern/curve.cpp b/source/blender/blenkernel/intern/curve.cpp
index 57bece1..c3854d5 100644
--- a/source/blender/blenkernel/intern/curve.cpp
+++ b/source/blender/blenkernel/intern/curve.cpp
@@ -194,7 +194,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
copy_v3_fl(cu->size, 1.0f);
cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
cu->pathlen = 100;
- cu->resolu = cu->resolv = (type == OB_SURF) ? 4 : 12;
+ cu->resolu = cu->resolv = (type == OB_SURF) ? 8 : 12;
cu->width = 1.0;
cu->wordspace = 1.0;
cu->spacing = cu->linedist = 1.0;
@@ -542,10 +542,28 @@ void BKE_nurb_free(Nurb *nu)
if (nu->knotsv)
MEM_freeN(nu->knotsv);
nu->knotsv = NULL;
- /* if (nu->trim.first) freeNurblist(&(nu->trim)); */
+ Nurb *outertrim = (Nurb*)nu->outer_trim.first;
+ while (outertrim) {
+ Nurb *tofree = outertrim;
+ outertrim = outertrim->next;
+ MEM_freeN(tofree);
+ }
+ LinkData *innertrim = (LinkData*)nu->inner_trim.first;
+ while (innertrim) {
+ if (innertrim->data) {
+ Nurb *it_nurb = (Nurb*)innertrim->data;
+ while (it_nurb) {
+ Nurb *tofree = it_nurb;
+ it_nurb = it_nurb->next;
+ MEM_freeN(tofree);
+ }
+ }
+ LinkData *tofree = innertrim;
+ innertrim = innertrim->next;
+ MEM_freeN(tofree);
+ }
MEM_freeN(nu);
-
}
@@ -564,6 +582,10 @@ void BKE_nurbList_free(ListBase *lb)
BLI_listbase_clear(lb);
}
+void BKE_nurbList_duplicate(ListBase *lb) {
+ Nurb *nu;
+}
+
Nurb *BKE_nurb_duplicate(Nurb *nu)
{
Nurb *newnu;
@@ -601,6 +623,7 @@ Nurb *BKE_nurb_duplicate(Nurb *nu)
}
}
}
+ BKE_nurbList_
return newnu;
}
@@ -3981,6 +4004,23 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *t
r_rect->ymin = r_rect->ymax - tb->h;
}
+void BKE_nurb_domain(struct Nurb *nu, float *umin, float *umax, float *vmin, float *vmax) {
+ *umin = nu->knotsu[nu->orderu - 1];
+ if (nu->flagu & CU_NURB_CYCLIC)
+ *umax = nu->knotsu[nu->pntsu + nu->orderu - 1];
+ else
+ *umax = nu->knotsu[nu->pntsu];
+ *vmin = nu->knotsv[nu->orderv - 1];
+ if (nu->flagv & CU_NURB_CYCLIC)
+ *vmax = nu->knotsv[nu->pntsv + nu->orderv - 1];
+ else
+ *vmax = nu->knotsv[nu->pntsv];
+ *umin = std::min(nu->knotsu[0], *umin);
+ *umax = std::max(nu->knotsu[nu->pntsu+nu->orderu-1], *umax);
+ *vmin = std::min(nu->knotsv[0], *umin);
+ *vmax = std::max(nu->knotsv[nu->pntsv+nu->orderv-1], *umax);
+}
+
float subj0[] = {0.512000,0.938000, 0.374000,0.950000, 0.248000,0.908000, 0.170000,0.866000, 0.092000,0.740000, 0.092000,0.602000, 0.092000,0.440000, 0.116000,0.260000, 0.254000,0.110000, 0.476000,0.074000, 0.746000,0.092000, 0.836000,0.206000, 0.848000,0.422000, 0.812000,0.644000, 0.716000,0.686000, 0.614000,0.734000, 0.488000,0.728000, 0.386000,0.710000, 0.260000,0.626000, 0.272000,0.476000, 0.350000,0.338000, 0.482000,0.278000, 0.632000,0.308000, 0.644000,0.404000, 0.638000,0.494000, [...]
void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl) {
bool remap_coords = true; // Remove trimmed verts (only useful for meshgen)
@@ -3990,18 +4030,8 @@ void BKE_nurb_make_displist(struct Nurb *nu, struct DispList *dl) {
// Figure out the domain
int totu=(nu->pntsu-nu->orderu+1)*nu->resolu, totv=(nu->pntsv-nu->orderv+1)*nu->resolv;
- float ustart = nu->knotsu[nu->orderu - 1];
- float uend;
- if (nu->flagu & CU_NURB_CYCLIC)
- uend = nu->knotsu[nu->pntsu + nu->orderu - 1];
- else
- uend = nu->knotsu[nu->pntsu];
- float vstart = nu->knotsv[nu->orderv - 1];
- float vend;
- if (nu->flagv & CU_NURB_CYCLIC)
- vend = nu->knotsv[nu->pntsv + nu->orderv - 1];
- else
- vend = nu->knotsv[nu->pntsv];
+ float ustart,uend,vstart,vend;
+ BKE_nurb_domain(nu,&ustart,&uend,&vstart,&vend);
// Trim the uniform grid in 2D UV space
GridMesh *gm = new GridMesh();
diff --git a/source/blender/blenkernel/intern/curve_eval.cpp b/source/blender/blenkernel/intern/curve_eval.cpp
index 781974a..7e6afc5 100644
--- a/source/blender/blenkernel/intern/curve_eval.cpp
+++ b/source/blender/blenkernel/intern/curve_eval.cpp
@@ -76,12 +76,15 @@ void BKE_bspline_knot_calc(int flags, int pnts, int order, float knots[])
int num_knots = pnts + order;
if (flags & CU_NURB_CYCLIC) num_knots += order-1;
if (flags & CU_NURB_BEZIER) {
- /* Previous versions of blender supported "Bezier" knot vectors. These
- * are useless to the user. *All* NURBS surfaces can be transformed into
- * Bezier quilts (grids of connected Bezier surfaces). The "Bezier" knot
- * vector is only an intermediate mathematical step in this process.
- * Bezier quilts may be exposed to the user but there is no point in having
- * the option to use Bezier-style knot vectors without Bezier-style controls.
+ /* On a NURBS curve, points between knots have infinitely many continuous
+ * derivatives. Points *at* knots have p-n continuous derivatives, where
+ * p is the degree of the curve and n is the multiplicity of the knot.
+ * p-n==-1 corresponds to a discontinuity in the curve itself. By ensuring
+ * that n==p (each knot has a multiplicity equal to the degree of a curve)
+ * we ensure that at each knot the curve is
+ * 1. continuous
+ * 2. has a (pontentially) discontinuous 1st derivative
+ * this gives the curve behavior equivalent to that of a Bezier curve.
* |------------------ pnts+order -------------|
* |--ord--||-ord-1-||-ord-1-||-ord-1-||--ord--|
* Bezier: { 0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 4 }
@@ -89,13 +92,14 @@ void BKE_bspline_knot_calc(int flags, int pnts, int order, float knots[])
int v=0;
for (int i=0; i<order; i++)
knots[i] = v;
- for (int i=order,reps=0; i<pnts; i++) {
+ for (int i=order,reps=0; i<pnts; i++,reps--) {
if (reps==0) {
v += 1;
reps = order-1;
}
knots[i] = v;
}
+ v++;
for (int i=pnts; i<pnts+order; i++)
knots[i] = v;
} else if (flags & CU_NURB_ENDPOINT) {
@@ -225,7 +229,7 @@ void BKE_bspline_basis_eval(float u, int i, float *U, int num_pts, int order, in
fprintf(stderr, "NURBS tess error: curve argument out of bounds\n");
return;
}
- if (!(p<=i && i<=num_knots-p-1 && i<=10)) {
+ if (!(p<=i && i<=num_knots-p-1)) {
fprintf(stderr, "NURBS tess error: knot index i out of bounds\n");
return;
}
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 7197d56..d6059fa 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1304,9 +1304,14 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
startvert = vertcount;
a = dl->nr;
data = dl->verts;
+ float *nors = dl->nors;
while (a--) {
copy_v3_v3(mvert->co, data);
data += 3;
+ if (nors) {
+ copy_v3_v3(mvert->no, nors);
+ nors += 3;
+ }
vertcount++;
mvert++;
}
diff --git a/source/blender/editors/io/io_rhino_import.cpp b/source/blender/editors/io/io_rhino_import.cpp
index e865e80..d1d6383 100644
--- a/source/blender/editors/io/io_rhino_import.cpp
+++ b/source/blender/editors/io/io_rhino_import.cpp
@@ -87,6 +87,7 @@ static void import_ON_str(char *dest, ON_wString& onstr, size_t n) {
// #define CU_NURB_ENDPOINT 2
// #define CU_NURB_BEZIER 4
static int analyze_knots(float *knots, int num_knots, int order, bool periodic, float tol=.001) {
+ printf("knots{"); for (int i=0; i<num_knots; i++) printf("%f,",knots[i]); printf("}->");
float first = knots[1];
float last = knots[num_knots-2];
@@ -102,7 +103,7 @@ static int analyze_knots(float *knots, int num_knots, int order, bool periodic,
bool unif_bezier = bezier;
if (bezier) {
float jump = knots[order]-knots[order-1];
- for (int i=order; i<num_knots-order; i+=2) {
+ for (int i=order; i<num_knots-order; i+=order-1) {
if (abs(knots[i]-knots[i+1])>tol) {
bezier = false;
unif_bezier = false;
@@ -136,16 +137,18 @@ static int analyze_knots(float *knots, int num_knots, int order, bool periodic,
if (bezier) {
BLI_assert(unif_bezier);
+ printf("bez\n");
return CU_NURB_BEZIER;
}
if (unif) {
+ printf("unif/cyc\n");
return periodic? CU_NURB_CYCLIC : 0;
}
if (unif_clamped) {
+ printf("endpt\n");
return CU_NURB_ENDPOINT;
}
- BLI_assert(false /* Can't tell curve type from knots */ );
- return 0;
+ return CU_NURB_CUSTOMKNOT;
}
static void normalize_knots(float *knots, int num_knots) {
@@ -164,12 +167,13 @@ static void normalize_knots(float *knots, int num_knots) {
/****************************** Curve Import *********************************/
static float null_loc[] = {0,0,0};
static float null_rot[] = {0,0,0};
-static void rhino_import_curve(bContext *C,
+static Nurb* rhino_import_curve(bContext *C,
ON_Curve *curve,
ON_Object *Object,
ON_3dmObjectAttributes *Attributes,
bool newobj=true,
- bool cast_lines_to_nurbs=false);
+ bool cast_lines_to
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list