changing the number of subdivisions for nurbs curves.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 23 Sep 2008 06:26:48 +0000 (06:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 23 Sep 2008 06:26:48 +0000 (06:26 +0000)
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.

source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/intern/anim.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/src/editcurve.c

index 45d8193b16fd9d21b56a21c079b3f87b657e6400..006e3ac1e79631aa5020ea89efcae363be4803e8 100644 (file)
@@ -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);
index ceb0e132ff98aca90ed00240920df81be04c4ba8..731c2a18c55cfde25e4175e3196d7b3570a8f1b5 100644 (file)
@@ -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");
 
index c5ad9e58a4c309fb13bf2b3ea7a0306e1ae66eb5..49d25b0652d26d9a59d0469285ffcb30fbc4e495 100644 (file)
@@ -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;
index 69c8f3406a2fcaf7bf777c99867f8492feb5b118..e55006b6c1cfd3cfee1455a45475ec5c7ad0ffaf 100644 (file)
@@ -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");
index f15ffcdcb58c852a6b225ba03d5041cc9f180625..1dee0837445d3a24d086fce4f099e1bf3e03a1ac 100644 (file)
@@ -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;