changing the number of subdivisions for nurbs curves.

this way each edge/segment gets the same number of points matching the resolution value.
before, a nurbs curve would have the same number of points no matter if it was cyclic or not.

This will make slight changes to objects on an animated path, but only noticable if the path has a low resolution.

bug [#11744] NurbCurve Radius incorrect - now dosnt show bad results with order 4 on non-cyclic curve.
This commit is contained in:
Campbell Barton 2008-09-23 06:26:48 +00:00
parent d2d56e3058
commit bcba8003c0
5 changed files with 16 additions and 11 deletions

@ -39,9 +39,12 @@ struct ListBase;
struct BezTriple;
struct BevList;
#define KNOTSU(nu) ( (nu)->orderu+ (nu)->pntsu+ (nu->orderu-1)*((nu)->flagu & CU_CYCLIC) )
#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (nu->orderv-1)*((nu)->flagv & CU_CYCLIC) )
#define KNOTSU(nu) ( (nu)->orderu+ (nu)->pntsu+ (((nu)->flagu & CU_CYCLIC) ? (nu->orderu-1) : 0) )
#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (((nu)->flagv & CU_CYCLIC) ? (nu->orderv-1) : 0) )
/* Non cyclic nurbs have 1 less segment */
#define SEGMENTSU(nu) ( ((nu)->flagu & CU_CYCLIC) ? (nu)->pntsu : (nu)->pntsu-1 )
#define SEGMENTSV(nu) ( ((nu)->flagv & CU_CYCLIC) ? (nu)->pntsv : (nu)->pntsv-1 )
void unlink_curve( struct Curve *cu);
void free_curve( struct Curve *cu);

@ -52,6 +52,7 @@
#include "DNA_vfont_types.h"
#include "BKE_anim.h"
#include "BKE_curve.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_effect.h"
@ -118,7 +119,7 @@ void calc_curvepath(Object *ob)
path->len= tot+1;
/* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */
if(path->len<nu->resolu*nu->pntsu) path->len= nu->resolu*nu->pntsu;
if(path->len<nu->resolu*SEGMENTSU(nu)) path->len= nu->resolu*SEGMENTSU(nu);
dist= (float *)MEM_mallocN((tot+1)*4, "calcpathdist");

@ -825,8 +825,8 @@ void makeNurbcurve(Nurb *nu, float *data, int resolu, int dim)
len= nu->pntsu;
if(len==0) return;
sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1");
resolu*= nu->pntsu;
resolu= (resolu*SEGMENTSU(nu))+1;
if(resolu==0) {
MEM_freeN(sum);
return;
@ -836,7 +836,7 @@ void makeNurbcurve(Nurb *nu, float *data, int resolu, int dim)
ustart= fp[nu->orderu-1];
if(nu->flagu & CU_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
else uend= fp[nu->pntsu];
ustep= (uend-ustart)/(resolu-1+(nu->flagu & CU_CYCLIC));
ustep= (uend-ustart)/(resolu-1);
basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3");
if(nu->flagu & CU_CYCLIC) cycl= nu->orderu-1;
@ -1620,7 +1620,7 @@ void makeBevelList(Object *ob)
}
else if((nu->type & 7)==CU_NURBS) {
if(nu->pntsv==1) {
len= resolu*nu->pntsu;
len= (resolu*SEGMENTSU(nu))+1;
bl= MEM_mallocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3");
BLI_addtail(&(cu->bev), bl);
bl->nr= len;

@ -858,7 +858,8 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
}
}
else if((nu->type & 7)==CU_NURBS) {
len= nu->pntsu*resolu;
len= (resolu*SEGMENTSU(nu))+1;
dl= MEM_callocN(sizeof(DispList), "makeDispListsurf");
dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");
BLI_addtail(dispbase, dl);
@ -1322,7 +1323,7 @@ void makeDispListSurf(Object *ob, ListBase *dispbase, int forRender)
for (nu=nubase->first; nu; nu=nu->next) {
if(forRender || nu->hide==0) {
if(nu->pntsv==1) {
len= nu->pntsu*nu->resolu;
len= nu->resolu*SEGMENTSU(nu)+1;
dl= MEM_callocN(sizeof(DispList), "makeDispListsurf");
dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");

@ -1727,7 +1727,7 @@ void subdivideNurb()
*/
/* count */
if(nu->flagu & CU_CYCLIC) {
a= nu->pntsu*nu->pntsv;
a= nu->pntsu;
bp= nu->bp;
prevbp= bp+(a-1);
}
@ -2145,7 +2145,7 @@ int convertspline(short type, Nurb *nu)
nu->type |= 1;
calchandlesNurb(nu);
}
else if(type==4) { /* to Nurb */
else if(type==CU_NURBS) {
nu->type &= ~7;
nu->type+= 4;
nu->orderu= 4;