fix for own bugs in curves.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 6 Oct 2008 06:10:14 +0000 (06:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 6 Oct 2008 06:10:14 +0000 (06:10 +0000)
- the number of segments was always 1 too many on cyclic curves.
- [#17739] - normals were not being calculated when rendering curves.

Replaced macro DL_SURFINDEX with a function. it that assumes variable names and could break from the loop that called it.

source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/exotic.c
source/blender/python/api2_2x/NMesh.c
source/blender/render/intern/source/convertblender.c

index d6b438a3010dc25f9cd59ace7192dc3379aa6b9f..a534dcc3669a15b15fc5462cfdd618727c804df1 100644 (file)
 #define DL_FRONT_CURVE 4
 #define DL_BACK_CURVE  8
 
-#define DL_SURFINDEX(cyclu, cyclv, sizeu, sizev)           \
-\
-if( (cyclv)==0 && a==(sizev)-1) break;             \
-if(cyclu) {                                                \
-       p1= sizeu*a;                                        \
-               p2= p1+ sizeu-1;                                    \
-                       p3= p1+ sizeu;                                      \
-                               p4= p2+ sizeu;                                      \
-                                       b= 0;                                               \
-}                                                          \
-else {                                             \
-       p2= sizeu*a;                                        \
-               p1= p2+1;                                           \
-                       p4= p2+ sizeu;                                      \
-                               p3= p1+ sizeu;                                      \
-                                       b= 1;                                               \
-}                                                          \
-if( (cyclv) && a==sizev-1) {                       \
-       p3-= sizeu*sizev;                                   \
-               p4-= sizeu*sizev;                                   \
-}
-
 
 /* prototypes */
 
@@ -114,6 +92,7 @@ extern void makeDispListMBall(struct Object *ob);
 extern void shadeDispList(struct Base *base);
 extern void shadeMeshMCol(struct Object *ob, struct Mesh *me);
 
+int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4);
 void imagestodisplist(void);
 void reshadeall_displist(void);
 void filldisplist(struct ListBase *dispbase, struct ListBase *to);
index c29a92558d644a21eeac5c57efd317efa8e1a799..b090ac2b538466081caa7dc58f167af137fbe179 100644 (file)
@@ -832,7 +832,9 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
        if(len==0) return;
        sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1");
        
-       resolu= (resolu*SEGMENTSU(nu))+1;
+       resolu= (resolu*SEGMENTSU(nu));
+       if((nu->flagu & CU_CYCLIC)==0) resolu++;
+       
        if(resolu==0) {
                MEM_freeN(sum);
                return;
@@ -842,7 +844,8 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
        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);
+       ustep= (uend-ustart)/(resolu - ((nu->flagu & CU_CYCLIC) ? 0 : 1));
+       
        basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3");
 
        if(nu->flagu & CU_CYCLIC) cycl= nu->orderu-1; 
@@ -1678,7 +1681,9 @@ void makeBevelList(Object *ob)
                        }
                        else if((nu->type & 7)==CU_NURBS) {
                                if(nu->pntsv==1) {
-                                       len= (resolu*SEGMENTSU(nu))+1;
+                                       len= (resolu*SEGMENTSU(nu));
+                                       if((nu->flagu & CU_CYCLIC)==0) len++;
+                                       
                                        bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3");
                                        BLI_addtail(&(cu->bev), bl);
                                        bl->nr= len;
index 8d97b82f2f5c8638cbb7de859b2dbb85d3cad630..bf17f0cecbc4c7c92f033e97e8c5bd2c7b0c5f42 100644 (file)
@@ -206,8 +206,9 @@ void addnormalsDispList(Object *ob, ListBase *lb)
                                ndata= dl->nors;
                                
                                for(a=0; a<dl->parts; a++) {
-       
-                                       DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+                                       
+                                       if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
+                                               break;
        
                                        v1= vdata+ 3*p1; 
                                        n1= ndata+ 3*p1;
@@ -271,6 +272,33 @@ void count_displist(ListBase *lb, int *totvert, int *totface)
        }
 }
 
+int surfindex_displist(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4)
+{
+       if((dl->flag & DL_CYCL_V)==0 && a==(dl->parts)-1) {
+               return 0;
+       }
+       
+       if(dl->flag & DL_CYCL_U) {
+               (*p1)= dl->nr*a;
+               (*p2)= (*p1)+ dl->nr-1;
+               (*p3)= (*p1)+ dl->nr;
+               (*p4)= (*p2)+ dl->nr;
+               (*b)= 0;
+       } else {
+               (*p2)= dl->nr*a;
+               (*p1)= (*p2)+1;
+               (*p4)= (*p2)+ dl->nr;
+               (*p3)= (*p1)+ dl->nr;
+               (*b)= 1;
+       }
+       
+       if( (dl->flag & DL_CYCL_U) && a==dl->parts-1) {                     \
+               (*p3)-= dl->nr*dl->parts;                                   \
+               (*p4)-= dl->nr*dl->parts;                                   \
+       }
+       
+       return 1;
+}
 
 /* ***************************** shade displist. note colors now are in rgb(a) order ******************** */
 
@@ -858,12 +886,14 @@ static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase)
                                }
                        }
                        else if((nu->type & 7)==CU_NURBS) {
-                               len= (resolu*SEGMENTSU(nu))+1;
+                               len= (resolu*SEGMENTSU(nu));
+                               if((nu->flagu & CU_CYCLIC)==0) len++;
                                
                                dl= MEM_callocN(sizeof(DispList), "makeDispListsurf");
                                dl->verts= MEM_callocN(len*3*sizeof(float), "dlverts");
                                BLI_addtail(dispbase, dl);
                                dl->parts= 1;
+                               
                                dl->nr= len;
                                dl->col= nu->mat_nr;
                                dl->charidx = nu->charidx;
@@ -1308,7 +1338,8 @@ static void displist_surf_indices(DispList *dl)
        
        for(a=0; a<dl->parts; a++) {
                
-               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+               if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
+                       break;
                
                for(; b<dl->nr; b++, index+=4) {        
                        index[0]= p1;
index 479be2ee6446b9a07b4ad4b560a83f66f9bfdde8..561b564ac39657a9009225773bc2476d9704bd47 100644 (file)
@@ -2097,8 +2097,10 @@ static void displist_to_mesh(DispList *dlfirst)
                        }
 
                        for(a=0; a<dl->parts; a++) {
-
-                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+                               
+                               if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
+                                       break;
+                               
                                p1+= startve; 
                                p2+= startve; 
                                p3+= startve; 
index 28407f174dac5a17b0e9c7a54913b07a667594f1..2e82c55155f6de287c5da6190cb070587171c040 100644 (file)
@@ -2158,8 +2158,8 @@ static PyObject *new_NMesh_displist(ListBase *lb, Object *ob)
 
                        for(a=0; a<dl->parts; a++) {
                                
-                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
-                               
+                               if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
+                                       break;
                                
                                for(; b<dl->nr; b++) {
                                        vidx[0] = p2 + ioffset;
index 05e2d0a521afc8dc1020f9b427a31dde7943b147..2d229cb33878568cdbbaf1646121e06d4b08d595 100644 (file)
@@ -2443,7 +2443,6 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
        VlakRen *vlr, *vlr1, *vlr2, *vlr3;
        Curve *cu= ob->data;
        float *data, n1[3];
-       /*float flen; - as yet unused */
        int u, v, orcoret= 0;
        int p1, p2, p3, p4, a;
        int sizeu, nsizeu, sizev, nsizev;
@@ -2515,7 +2514,8 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
                        vlr= RE_findOrAddVlak(obr, obr->totvlak++);
                        vlr->v1= v1; vlr->v2= v2; vlr->v3= v3; vlr->v4= v4;
                        
-                       /* flen= CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, n1); - as yet unused */
+                       CalcNormFloat4(vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co, n1);
+                       
                        VECCOPY(vlr->n, n1);
                        
                        vlr->mat= matar[ dl->col];
@@ -2787,8 +2787,10 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
                                        for(a=0; a<dl->parts; a++) {
 
                                                frontside= (a >= dl->nr/2);
-
-                                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+                                               
+                                               if (surfindex_displist(dl, a, &b, &p1, &p2, &p3, &p4)==0)
+                                                       break;
+                                               
                                                p1+= startvert;
                                                p2+= startvert;
                                                p3+= startvert;