From 04adf3ae1552132d2d0d915265509a566528d3af Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 30 Sep 2010 05:26:36 +0000 Subject: [PATCH] cleanup of nurb spin function, was very confusing. no functional changes. --- source/blender/editors/curve/editcurve.c | 106 +++++++++-------------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index bd63862a73e..b0684171614 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1280,13 +1280,9 @@ static void rotateflagNurb(ListBase *editnurb, short flag, float *cent, float ro while(a--) { if(bp->f1 & flag) { - bp->vec[0]-=cent[0]; - bp->vec[1]-=cent[1]; - bp->vec[2]-=cent[2]; + sub_v3_v3(bp->vec, cent); mul_m3_v3(rotmat, bp->vec); - bp->vec[0]+=cent[0]; - bp->vec[1]+=cent[1]; - bp->vec[2]+=cent[2]; + add_v3_v3(bp->vec, cent); } bp++; } @@ -1326,7 +1322,7 @@ static void translateflagNurb(ListBase *editnurb, short flag, float *vec) } } -static void weightflagNurb(ListBase *editnurb, short flag, float w, int mode) /* mode==0: replace, mode==1: multiply */ +static void weightflagNurb(ListBase *editnurb, short flag, float w) { Nurb *nu; BPoint *bp; @@ -1338,8 +1334,8 @@ static void weightflagNurb(ListBase *editnurb, short flag, float w, int mode) /* bp= nu->bp; while(a--) { if(bp->f1 & flag) { - if(mode==1) bp->vec[3]*= w; - else bp->vec[3]= w; + /* a mode used to exist for replace/multiple but is was unused */ + bp->vec[3]*= w; } bp++; } @@ -3969,14 +3965,9 @@ int mouse_nurb(bContext *C, short mval[2], int extend) /******************** spin operator ***********************/ -/* from what I can gather, the mode==0 magic number spins and bridges the nurbs based on the - * orientation of the global 3d view (yuck yuck!) mode==1 does the same, but doesn't bridge up - * up the new geometry, mode==2 now does the same as 0, but aligned to world axes, not the view. -*/ - /* 'cent' is in object space and 'dvec' in worldspace. */ -static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cent, short mode) +static int spin_nurb(float viewmat[][4], Object *obedit, float *axis, float *cent) { Curve *cu= (Curve*)obedit->data; ListBase *editnurb= curve_get_editcurve(obedit); @@ -3986,26 +3977,14 @@ static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cen float persmat[3][3], persinv[3][3]; short a,ok, changed= 0; - if (mode != 2) copy_m3_m4(persmat, rv3d->viewmat); - else unit_m3(persmat); + copy_m3_m4(persmat, viewmat); invert_m3_m3(persinv, persmat); /* imat and center and size */ copy_m3_m4(bmat, obedit->obmat); invert_m3_m3(imat, bmat); - - if(dvec || mode==2) { - if(dvec) { - normalize_v3_v3(n, dvec); - } - else { - n[0]=n[1]= 0.0; - n[2]= 1.0; - } - } - else { - normalize_v3_v3(n, rv3d->viewinv[2]); - } + + normalize_v3_v3(n, axis); phi= M_PI/8.0; q[0]= cos(phi); @@ -4018,8 +3997,8 @@ static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cen mul_m3_m3m3(rotmat, imat, tmat); unit_m3(scalemat1); - scalemat1[0][0]= sqrt(2.0); - scalemat1[1][1]= sqrt(2.0); + scalemat1[0][0]= M_SQRT2; + scalemat1[1][1]= M_SQRT2; mul_m3_m3m3(tmat,persmat,bmat); mul_m3_m3m3(cmat,scalemat1,tmat); @@ -4027,8 +4006,8 @@ static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cen mul_m3_m3m3(scalemat1,imat,tmat); unit_m3(scalemat2); - scalemat2[0][0]/= sqrt(2.0); - scalemat2[1][1]/= sqrt(2.0); + scalemat2[0][0]/= M_SQRT2; + scalemat2[1][1]/= M_SQRT2; mul_m3_m3m3(tmat,persmat,bmat); mul_m3_m3m3(cmat,scalemat2,tmat); @@ -4038,25 +4017,22 @@ static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cen ok= 1; for(a=0;a<7;a++) { - if(mode==0 || mode==2) ok= extrudeflagNurb(cu->editnurb, 1); - else adduplicateflagNurb(obedit, 1); + ok= extrudeflagNurb(cu->editnurb, 1); if(ok==0) return changed; changed= 1; - rotateflagNurb(editnurb, 1,cent,rotmat); + rotateflagNurb(editnurb, SELECT, cent, rotmat); - if(mode==0 || mode==2) { - if( (a & 1)==0 ) { - rotateflagNurb(editnurb, 1,cent,scalemat1); - weightflagNurb(editnurb, 1, 0.25*sqrt(2.0), 1); - } - else { - rotateflagNurb(editnurb, 1,cent,scalemat2); - weightflagNurb(editnurb, 1, 4.0/sqrt(2.0), 1); - } + if( (a & SELECT)==0 ) { + rotateflagNurb(editnurb, SELECT, cent, scalemat1); + weightflagNurb(editnurb, SELECT, 0.25*M_SQRT2); + } + else { + rotateflagNurb(editnurb, SELECT, cent, scalemat2); + weightflagNurb(editnurb, SELECT, 4.0/M_SQRT2); } } @@ -4075,7 +4051,6 @@ static int spin_nurb(RegionView3D *rv3d, Object *obedit, float *dvec, float *cen static int spin_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); float cent[3], axis[3]; @@ -4085,7 +4060,7 @@ static int spin_exec(bContext *C, wmOperator *op) invert_m4_m4(obedit->imat, obedit->obmat); mul_m4_v3(obedit->imat, cent); - if(!spin_nurb(ED_view3d_context_rv3d(C), obedit, axis, cent, 0)) { + if(!spin_nurb(ED_view3d_context_rv3d(C)->viewmat, obedit, axis, cent)) { BKE_report(op->reports, RPT_ERROR, "Can't spin"); return OPERATOR_CANCELLED; } @@ -5638,10 +5613,10 @@ int join_curve_exec(bContext *C, wmOperator *op) Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) { static int xzproj= 0; /* this function calls itself... */ - Scene *scene= CTX_data_scene(C); Object *obedit= CTX_data_edit_object(C); ListBase *editnurb= curve_get_editcurve(obedit); View3D *v3d= CTX_wm_view3d(C); + RegionView3D *rv3d= ED_view3d_context_rv3d(C); Nurb *nu = NULL; BezTriple *bezt; BPoint *bp; @@ -5649,7 +5624,10 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) float fac, grid; int a, b, cutype, stype; int force_3d = ((Curve *)obedit->data)->flag & CU_3D; /* could be adding to an existing 3D curve */ - + + float umat[4][4]; + unit_m4(umat); + cutype= type & CU_TYPE; // poly, bezier, nurbs, etc stype= type & CU_PRIMITIVE; @@ -5834,7 +5812,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) bp->vec[0]+= 0.25*nurbcircle[a][0]*grid-.75*grid; bp->vec[2]+= 0.25*nurbcircle[a][1]*grid; } - if(a & 1) bp->vec[3]= 0.25*sqrt(2.0); + if(a & 1) bp->vec[3]= 0.25*M_SQRT2; else bp->vec[3]= 1.0; mul_m4_v3(mat,bp->vec); bp->radius = bp->weight = 1.0; @@ -5925,7 +5903,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) case CU_PRIM_SPHERE: /* sphere */ if( cutype==CU_NURBS ) { float tmp_cent[3] = {0.f, 0.f, 0.f}; - float tmp_vec[3] = {0.f, 0.f, 0.f}; + float tmp_vec[3] = {0.f, 0.f, 1.f}; if(newname) { rename_id((ID *)obedit, "SurfSphere"); @@ -5946,7 +5924,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) bp->f1= SELECT; bp->vec[0]+= nurbcircle[a][0]*grid; bp->vec[2]+= nurbcircle[a][1]*grid; - if(a & 1) bp->vec[3]= 0.5*sqrt(2.0); + if(a & 1) bp->vec[3]= 0.5*M_SQRT2; else bp->vec[3]= 1.0; mul_m4_v3(mat,bp->vec); bp++; @@ -5955,10 +5933,10 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) makeknots(nu, 1); BLI_addtail(editnurb, nu); /* temporal for spin */ - if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) - spin_nurb(ED_view3d_context_rv3d(C), obedit, NULL, tmp_cent, 2); - else - spin_nurb(ED_view3d_context_rv3d(C), obedit, NULL, mat[3], (U.flag & USER_ADD_VIEWALIGNED) ? 0 : 2); + + if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) spin_nurb(umat, obedit, tmp_vec, tmp_cent); + else if ((U.flag & USER_ADD_VIEWALIGNED)) spin_nurb(rv3d->viewmat, obedit, rv3d->viewinv[2], mat[3]); + else spin_nurb(umat, obedit, tmp_vec, mat[3]); makeknots(nu, 2); @@ -5974,7 +5952,7 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) case CU_PRIM_DONUT: /* torus */ if( cutype==CU_NURBS ) { float tmp_cent[3] = {0.f, 0.f, 0.f}; - float tmp_vec[3] = {0.f, 0.f, 0.f}; + float tmp_vec[3] = {0.f, 0.f, 1.f}; if(newname) { rename_id((ID *)obedit, "SurfTorus"); @@ -5987,11 +5965,13 @@ Nurb *add_nurbs_primitive(bContext *C, float mat[4][4], int type, int newname) nu->resolu= 4; nu->resolv= 4; nu->flag= CU_SMOOTH; - BLI_addtail(editnurb, nu); /* temporal for extrude and translate */ - if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) - spin_nurb(ED_view3d_context_rv3d(C), obedit, NULL, tmp_cent, 2); - else - spin_nurb(ED_view3d_context_rv3d(C), obedit, NULL, mat[3], (U.flag & USER_ADD_VIEWALIGNED) ? 0 : 2); + BLI_addtail(editnurb, nu); /* temporal for spin */ + + /* same as above */ + if(newname && (U.flag & USER_ADD_VIEWALIGNED) == 0) spin_nurb(umat, obedit, tmp_vec, tmp_cent); + else if ((U.flag & USER_ADD_VIEWALIGNED)) spin_nurb(rv3d->viewmat, obedit, rv3d->viewinv[2], mat[3]); + else spin_nurb(umat, obedit, tmp_vec, mat[3]); + BLI_remlink(editnurb, nu);