[Bf-blender-cvs] [053cd1f] soc-2014-nurbs: Interior trims are now preserved by re-knot-ing. For some reason exterior trims aren't...
Jonathan deWerd
noreply at git.blender.org
Thu Jul 31 02:03:12 CEST 2014
Commit: 053cd1f2894098d94b429fa3f907cc0d63e67bec
Author: Jonathan deWerd
Date: Wed Jul 30 20:02:59 2014 -0400
Branches: soc-2014-nurbs
https://developer.blender.org/rB053cd1f2894098d94b429fa3f907cc0d63e67bec
Interior trims are now preserved by re-knot-ing. For some reason exterior trims aren't...
===================================================================
M source/blender/blenkernel/intern/curve.cpp
M source/blender/editors/io/io_rhino_import.cpp
===================================================================
diff --git a/source/blender/blenkernel/intern/curve.cpp b/source/blender/blenkernel/intern/curve.cpp
index 582140d..dad428c 100644
--- a/source/blender/blenkernel/intern/curve.cpp
+++ b/source/blender/blenkernel/intern/curve.cpp
@@ -655,21 +655,21 @@ int BKE_nurbTrim_tess(struct NurbTrim *nt, int resolution, float (**uv_out)[2])
float (*uv)[2] = (float(*)[2])MEM_mallocN(sizeof(*uv)*tot_tess_pts, "BKE_nurbTrim_tess");
*uv_out = uv;
for (Nurb* nu = (Nurb*)nt->nurb_list.first; nu; nu=nu->next) {
+ int tess_pts = nu->pntsu * resolution + 1;
float *U = nu->knotsu;
int pntsu = nu->pntsu;
BPoint *bp = nu->bp;
int orderu = nu->orderu;
- int tess_pts = nu->pntsu * resolution + 1;
float umin, umax;
BKE_nurb_domain(nu, &umin, &umax, NULL, NULL);
float du = (umax-umin)/(tess_pts-1);
- for (int i=0; i<=tess_pts; i++) {
+ for (int i=0; i<tess_pts; i++) {
BPoint pt;
- float u = (i<tess_pts)? umin+i*du : umax;
+ float u = (i!=tess_pts-1)? umin+i*du : umax;
BKE_nurbs_curve_eval(u, U, pntsu, orderu, bp, 1, 0, &pt);
uv[i][0] = pt.vec[0];
uv[i][1] = pt.vec[1];
- printf("uv: %f %f\n",pt.vec[0],pt.vec[1]);
+ printf("uv(%i/%i): %f %f\n",int(uv+i-*uv_out),tot_tess_pts,pt.vec[0],pt.vec[1]);
}
uv += tess_pts;
}
diff --git a/source/blender/editors/io/io_rhino_import.cpp b/source/blender/editors/io/io_rhino_import.cpp
index f383a24..14b884a 100644
--- a/source/blender/editors/io/io_rhino_import.cpp
+++ b/source/blender/editors/io/io_rhino_import.cpp
@@ -195,14 +195,20 @@ static void normalize_knots(Nurb *nu, char uv) {
int uv_idx = (uv=='u')? 0 : 1;
for (NurbTrim *nt = (NurbTrim*)nu->trims.first; nt; nt=nt->next) {
for (Nurb *trim_nurb = (Nurb*)nt->nurb_list.first; trim_nurb; trim_nurb=trim_nurb->next) {
+ float umin=std::numeric_limits<float>::infinity();
+ float umax=-std::numeric_limits<float>::infinity();
int ptsu = std::max(trim_nurb->pntsu,1);
int ptsv = std::max(trim_nurb->pntsv,1);
int bp_count = ptsu*ptsv;
BPoint *bp = trim_nurb->bp; // Control points
for (int bpnum=0; bpnum<bp_count; bpnum++) {
double old = bp[bpnum].vec[uv_idx];
- bp[bpnum].vec[uv_idx] = (old-lowest)*denominator;
+ double new_uv = (old-lowest)*denominator;
+ bp[bpnum].vec[uv_idx] = new_uv;
+ umin = std::min(umin,(float)new_uv);
+ umax = std::max(umax,(float)new_uv);
}
+ printf("[Knot (Trim Boudns) Bounds]: [%f (%f,%f) %f]\n",knots[0],umin,umax,knots[num_knots-1]);
}
}
BKE_nurb_clear_cached_UV_mesh(nu,true);
@@ -603,12 +609,19 @@ static void rhino_import_nurbs_surf_end(bContext *C) {
printf("nurbssurf done\n");
}
+static void nurb_normalize_knots(Nurb *nu) {
+ normalize_knots(nu, 'u');
+ normalize_knots(nu, 'v');
+ BKE_nurb_knot_calc_u(nu);
+ BKE_nurb_knot_calc_v(nu);
+}
static Nurb* rhino_import_nurbs_surf(bContext *C,
- ON_Surface *raw_surf,
- ON_Object *obj,
- ON_3dmObjectAttributes *attrs,
- bool newobj) {
+ ON_Surface *raw_surf,
+ ON_Object *obj,
+ ON_3dmObjectAttributes *attrs,
+ bool newobj,
+ bool normalize_knots=true) {
ON_NurbsSurface *surf = ON_NurbsSurface::Cast(raw_surf);
bool surf_needs_delete = false;
if (!surf) {
@@ -662,13 +675,8 @@ static Nurb* rhino_import_nurbs_surf(bContext *C,
}
nu->knotsv[i] = nu->knotsv[i-1];
nu->flagu = analyze_knots(nu->knotsu, nu->pntsu+nu->orderu, nu->orderu, surf->IsPeriodic(0));
- normalize_knots(nu, 'u');
nu->flagv = analyze_knots(nu->knotsv, nu->pntsv+nu->orderv, nu->orderv, surf->IsPeriodic(1));
- normalize_knots(nu, 'v');
- // If trim curves are deformed on import, check for knot agreement between
- // this point, after executing the next two calls
- BKE_nurb_knot_calc_u(nu);
- BKE_nurb_knot_calc_v(nu);
+ if (normalize_knots) nurb_normalize_knots(nu);
ListBase *editnurb = object_editcurve_get(obedit);
BLI_addtail(editnurb, nu);
@@ -725,7 +733,7 @@ static void rhino_import_brep_face(bContext *C,
}
should_destroy_ns = true;
}
- Nurb *nu = rhino_import_nurbs_surf(C, ns, parentObj, parentAttrs, false);
+ Nurb *nu = rhino_import_nurbs_surf(C, ns, parentObj, parentAttrs, false, false);
/* Add the trim curves */
ON_BrepLoop *outer_loop = face->OuterLoop();
@@ -747,6 +755,8 @@ static void rhino_import_brep_face(bContext *C,
}
BLI_addtail(&nu->trims, trim);
}
+
+ nurb_normalize_knots(nu);
if (should_destroy_ns) delete ns;
}
More information about the Bf-blender-cvs
mailing list