With the commit last week to have curve bevels nice circular (when no
authorTon Roosendaal <ton@blender.org>
Sat, 11 Mar 2006 12:34:50 +0000 (12:34 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 11 Mar 2006 12:34:50 +0000 (12:34 +0000)
front/back is selected), the UV coordinates for curves should also be
corrected.
This commit re-uses the same code as for Nurbs, to make sure UV coordinates
wrap around nicely.

BUT! I've noticed that Daniel's commit of august in this code actually
broke this UV correction... in his craze to cleanup old code, he missed
the actual functionality. Meaning that in 2.40 and 2.41, "UV orco" texture
coordinates wrap around ugly in Nurbs Surfaces, something that was fixed
in NaN days.

Got no time for tracker now... but I'm sure it's in there! :)

source/blender/blenkernel/intern/curve.c
source/blender/render/intern/source/convertblender.c
source/blender/src/drawview.c

index 315a1981354cbc1b32d6f2dbaf70695b20a115fb..0ae3249d4350d1398daef5206404b324f134940a 100644 (file)
@@ -913,30 +913,47 @@ void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int i
 
 float *make_orco_surf(Object *ob)
 {
-       Curve *cu = ob->data;
+       Curve *cu= ob->data;
        Nurb *nu;
        int a, b, tot=0;
-       int sizeu, sizev;// ###
-       float *data;
-       float *orco;
-
-               /* first calculate the size of the datablock */
-       for (nu=cu->nurb.first; nu; nu=nu->next) {
-               sizeu = nu->resolu; sizev = nu->resolv;
-               if(nu->pntsv>1) tot+= sizeu * sizev;
+       int sizeu, sizev;
+       float *data, *orco;
+       
+       /* first calculate the size of the datablock */
+       nu= cu->nurb.first;
+       while(nu) {
+               /* as we want to avoid the seam in a cyclic nurbs
+               texture wrapping, reserve extra orco data space to save these extra needed
+               vertex based UV coordinates for the meridian vertices.
+               Vertices on the 0/2pi boundary are not duplicated inside the displist but later in
+               the renderface/vert construction.
+               
+               See also convertblender.c: init_render_surf()
+               */
+               
+               sizeu = nu->resolu; 
+               sizev = nu->resolv;
+               if (nu->flagu & CU_CYCLIC) sizeu++;
+               if (nu->flagv & CU_CYCLIC) sizev++;
+               if(nu->pntsv>1) tot+= sizeu * sizev;
+               
+               nu= nu->next;
        }
-                               /* makeNurbfaces wants zeros */
+       /* makeNurbfaces wants zeros */
        data= orco= MEM_callocN(3*sizeof(float)*tot, "make_orco");
-
-       for (nu=cu->nurb.first; nu; nu=nu->next) {
+       
+       nu= cu->nurb.first;
+       while(nu) {
                if(nu->pntsv>1) {
                        sizeu = nu->resolu;
                        sizev = nu->resolv;
+                       if (nu->flagu & CU_CYCLIC) sizeu++;
+                       if (nu->flagv & CU_CYCLIC) sizev++;
                        
                        if(cu->flag & CU_UV_ORCO) {
                                for(b=0; b< sizeu; b++) {
                                        for(a=0; a< sizev; a++) {
-                                       
+                                               
                                                if(sizev <2) data[0]= 0.0f;
                                                else data[0]= -1.0f + 2.0f*((float)a)/(sizev - 1);
                                                
@@ -944,14 +961,14 @@ float *make_orco_surf(Object *ob)
                                                else data[1]= -1.0f + 2.0f*((float)b)/(sizeu - 1);
                                                
                                                data[2]= 0.0;
-               
+                                               
                                                data+= 3;
                                        }
                                }
                        }
                        else {
                                makeNurbfaces(nu, data, sizeof(*data)*sizev*3);
-
+                               
                                for(b=0; b<sizeu; b++) {
                                        for(a=0; a<sizev; a++) {
                                                data = orco + 3 * (b * sizev + a);
@@ -962,8 +979,9 @@ float *make_orco_surf(Object *ob)
                                }
                        }
                }
+               nu= nu->next;
        }
-
+       
        return orco;
 }
 
@@ -993,6 +1011,8 @@ float *make_orco_curve(Object *ob)
                        numVerts += dl->nr;
                } else if (dl->type==DL_SURF) {
                        numVerts += dl->parts*dl->nr;
+                       if (dl->flag & DL_CYCL_U)
+                               numVerts+= dl->parts;
                }
        }
 
@@ -1000,8 +1020,8 @@ float *make_orco_curve(Object *ob)
 
        for (dl=cu->disp.first; dl; dl=dl->next) {
                if (dl->type==DL_INDEX3) {
-                       for (u=0; u<dl->nr; u++,fp+=3) {
-                               if (cu->flag&CU_UV_ORCO) {
+                       for (u=0; u<dl->nr; u++, fp+=3) {
+                               if (cu->flag & CU_UV_ORCO) {
                                        fp[0]= 2.0f*u/(dl->nr-1) - 1.0f;
                                        fp[1]= 0.0;
                                        fp[2]= 0.0;
@@ -1014,14 +1034,21 @@ float *make_orco_curve(Object *ob)
                                }
                        }
                } else if (dl->type==DL_SURF) {
+                       int sizeu= dl->nr;
+                       
+                       if (dl->flag & DL_CYCL_U)
+                               sizeu++;
+                               
                        for (u=0; u<dl->parts; u++) {
-                               for (v=0; v<dl->nr; v++,fp+=3) {
-                                       if (cu->flag&CU_UV_ORCO) {
+                               for (v=0; v<sizeu; v++,fp+=3) {
+                                       if (cu->flag & CU_UV_ORCO) {
                                                fp[0]= 2.0f*u/(dl->parts-1) - 1.0f;
                                                fp[1]= 2.0f*v/(dl->nr-1) - 1.0f;
                                                fp[2]= 0.0;
                                        } else {
-                                               VECCOPY(fp, &dl->verts[(dl->nr*u + v)*3]);
+                                               int realv= v % dl->nr;
+
+                                               VECCOPY(fp, &dl->verts[(dl->nr*u + realv)*3]);
 
                                                fp[0]= (fp[0]-cu->loc[0])/cu->size[0];
                                                fp[1]= (fp[1]-cu->loc[1])/cu->size[1];
index 30b30a1d0bb8af059c9cead24a2f48abb0f64496..756a12ccbda433953a233d44c76f037764c6a63b 100644 (file)
@@ -2142,6 +2142,173 @@ static void add_render_lamp(Render *re, Object *ob, int actual_render)
 }
 
 /* ------------------------------------------------------------------------- */
+
+/* returns amount of vertices added for orco */
+static int dl_surf_to_renderdata(Render *re, Object *ob, DispList *dl, Material **matar, float *orco, float mat[4][4])
+{
+       VertRen *v1, *v2, *v3, *v4, *ver;
+       VlakRen *vlr, *vlr1, *vlr2, *vlr3;
+       Curve *cu= ob->data;
+       float *data, n1[3], *orcobase= orco, flen;
+       int u, v, orcoret= 0;
+       int p1, p2, p3, p4, a;
+       int sizeu, nsizeu, sizev, nsizev;
+       int startvert, startvlak;
+       
+       startvert= re->totvert;
+       nsizeu = sizeu = dl->parts; nsizev = sizev = dl->nr; 
+       
+       data= dl->verts;
+       for (u = 0; u < sizeu; u++) {
+               v1 = RE_findOrAddVert(re, re->totvert++); /* save this for possible V wrapping */
+               VECCOPY(v1->co, data); data += 3;
+               if(orco) {
+                       v1->orco= orco; orco+= 3; orcoret++;
+               }       
+               MTC_Mat4MulVecfl(mat, v1->co);
+               
+               for (v = 1; v < sizev; v++) {
+                       ver= RE_findOrAddVert(re, re->totvert++);
+                       VECCOPY(ver->co, data); data += 3;
+                       if(orco) {
+                               ver->orco= orco; orco+= 3; orcoret++;
+                       }       
+                       MTC_Mat4MulVecfl(mat, ver->co);
+               }
+               /* if V-cyclic, add extra vertices at end of the row */
+               if (dl->flag & DL_CYCL_U) {
+                       ver= RE_findOrAddVert(re, re->totvert++);
+                       VECCOPY(ver->co, v1->co);
+                       if(orco) {
+                               ver->orco= orco; orco+=3; orcoret++; //orcobase + 3*(u*sizev + 0);
+                       }
+               }       
+       }       
+       
+       /* Done before next loop to get corner vert */
+       if (dl->flag & DL_CYCL_U) nsizev++;
+       if (dl->flag & DL_CYCL_V) nsizeu++;
+       
+       /* if U cyclic, add extra row at end of column */
+       if (dl->flag & DL_CYCL_V) {
+               for (v = 0; v < nsizev; v++) {
+                       v1= RE_findOrAddVert(re, startvert + v);
+                       ver= RE_findOrAddVert(re, re->totvert++);
+                       VECCOPY(ver->co, v1->co);
+                       if(orco) {
+                               ver->orco= orco; orco+=3; orcoret++; //ver->orco= orcobase + 3*(0*sizev + v);
+                       }
+               }
+       }
+       
+       sizeu = nsizeu;
+       sizev = nsizev;
+       
+       startvlak= re->totvlak;
+       
+       for(u = 0; u < sizeu - 1; u++) {
+               p1 = startvert + u * sizev; /* walk through face list */
+               p2 = p1 + 1;
+               p3 = p2 + sizev;
+               p4 = p3 - 1;
+               
+               for(v = 0; v < sizev - 1; v++) {
+                       v1= RE_findOrAddVert(re, p1);
+                       v2= RE_findOrAddVert(re, p2);
+                       v3= RE_findOrAddVert(re, p3);
+                       v4= RE_findOrAddVert(re, p4);
+                       
+                       vlr= RE_findOrAddVlak(re, re->totvlak++);
+                       vlr->ob= ob;
+                       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);
+                       VECCOPY(vlr->n, n1);
+                       
+                       vlr->lay= ob->lay;
+                       vlr->mat= matar[ dl->col];
+                       vlr->ec= ME_V1V2+ME_V2V3;
+                       vlr->flag= dl->rt;
+                       if( (cu->flag & CU_NOPUNOFLIP) ) {
+                               vlr->flag |= R_NOPUNOFLIP;
+                       }
+                       
+                       VecAddf(v1->n, v1->n, n1);
+                       VecAddf(v2->n, v2->n, n1);
+                       VecAddf(v3->n, v3->n, n1);
+                       VecAddf(v4->n, v4->n, n1);
+                       
+                       p1++; p2++; p3++; p4++;
+               }
+       }       
+       /* fix normals for U resp. V cyclic faces */
+       sizeu--; sizev--;  /* dec size for face array */
+       if (dl->flag & DL_CYCL_V) {
+               
+               for (v = 0; v < sizev; v++)
+               {
+                       /* optimize! :*/
+                       vlr= RE_findOrAddVlak(re, UVTOINDEX(sizeu - 1, v));
+                       vlr1= RE_findOrAddVlak(re, UVTOINDEX(0, v));
+                       VecAddf(vlr1->v1->n, vlr1->v1->n, vlr->n);
+                       VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n);
+                       VecAddf(vlr->v3->n, vlr->v3->n, vlr1->n);
+                       VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n);
+               }
+       }
+       if (dl->flag & DL_CYCL_U) {
+               
+               for (u = 0; u < sizeu; u++)
+               {
+                       /* optimize! :*/
+                       vlr= RE_findOrAddVlak(re, UVTOINDEX(u, 0));
+                       vlr1= RE_findOrAddVlak(re, UVTOINDEX(u, sizev-1));
+                       VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n);
+                       VecAddf(vlr1->v3->n, vlr1->v3->n, vlr->n);
+                       VecAddf(vlr->v1->n, vlr->v1->n, vlr1->n);
+                       VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n);
+               }
+       }
+       /* last vertex is an extra case: 
+               
+               ^       ()----()----()----()
+               |       |     |     ||     |
+               u       |     |(0,n)||(0,0)|
+               |     |     ||     |
+               ()====()====[]====()
+               |     |     ||     |
+               |     |(m,n)||(m,0)|
+               |     |     ||     |
+               ()----()----()----()
+               v ->
+               
+               vertex [] is no longer shared, therefore distribute
+               normals of the surrounding faces to all of the duplicates of []
+               */
+       
+       if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U))
+       {
+               vlr= RE_findOrAddVlak(re, UVTOINDEX(sizeu - 1, sizev - 1)); /* (m,n) */
+               vlr1= RE_findOrAddVlak(re, UVTOINDEX(0,0));  /* (0,0) */
+               VecAddf(n1, vlr->n, vlr1->n);
+               vlr2= RE_findOrAddVlak(re, UVTOINDEX(0, sizev-1)); /* (0,n) */
+               VecAddf(n1, n1, vlr2->n);
+               vlr3= RE_findOrAddVlak(re, UVTOINDEX(sizeu-1, 0)); /* (m,0) */
+               VecAddf(n1, n1, vlr3->n);
+               VECCOPY(vlr->v3->n, n1);
+               VECCOPY(vlr1->v1->n, n1);
+               VECCOPY(vlr2->v2->n, n1);
+               VECCOPY(vlr3->v4->n, n1);
+       }
+       for(a = startvert; a < re->totvert; a++) {
+               ver= RE_findOrAddVert(re, a);
+               Normalise(ver->n);
+       }
+       
+       
+       return orcoret;
+}
+
 static void init_render_surf(Render *re, Object *ob)
 {
        extern Material defmaterial;    // initrender.c
@@ -2149,15 +2316,9 @@ static void init_render_surf(Render *re, Object *ob)
        Curve *cu;
        ListBase displist;
        DispList *dl;
-       VertRen *ver, *v1, *v2, *v3, *v4;
-       VlakRen *vlr;
        Material *matar[32];
-       float *data, *orco=NULL, *orcobase=NULL, n1[3], flen, mat[4][4];
-       int a, need_orco=0, startvlak, startvert, p1, p2, p3, p4;
-       int u, v;
-       int sizeu, sizev;
-       VlakRen *vlr1, *vlr2, *vlr3;
-       float  vn[3]; // n2[3],
+       float *orco=NULL, *orcobase=NULL, mat[4][4];
+       int a, need_orco=0;
 
        cu= ob->data;
        nu= cu->nurb.first;
@@ -2188,159 +2349,7 @@ static void init_render_surf(Render *re, Object *ob)
        while(dl) {
                        /* watch out: u ^= y, v ^= x !! */
                if(dl->type==DL_SURF) {
-                       int nsizeu, nsizev;
-
-                       startvert= re->totvert;
-                       nsizeu = sizeu = dl->parts; nsizev = sizev = dl->nr; 
-
-                       data= dl->verts;
-                       for (u = 0; u < sizeu; u++) {
-                               v1 = RE_findOrAddVert(re, re->totvert++); /* save this for possible V wrapping */
-                               VECCOPY(v1->co, data); data += 3;
-                               if(orco) {
-                                       v1->orco= orco; orco+= 3;
-                               }       
-                               MTC_Mat4MulVecfl(mat, v1->co);
-
-                               for (v = 1; v < sizev; v++) {
-                                       ver= RE_findOrAddVert(re, re->totvert++);
-                                       VECCOPY(ver->co, data); data += 3;
-                                       if(orco) {
-                                               ver->orco= orco; orco+= 3;
-                                       }       
-                                       MTC_Mat4MulVecfl(mat, ver->co);
-                               }
-                               /* if V-cyclic, add extra vertices at end of the row */
-                               if (dl->flag & DL_CYCL_U) {
-                                       ver= RE_findOrAddVert(re, re->totvert++);
-                                       VECCOPY(ver->co, v1->co);
-                                       if(orco) {
-                                               ver->orco= orcobase + 3*(u*sizev + 0);
-                                       }
-                               }       
-                       }       
-
-                               /* Done before next loop to get corner vert */
-                       if (dl->flag & DL_CYCL_U) nsizev++;
-                       if (dl->flag & DL_CYCL_V) nsizeu++;
-
-                       /* if U cyclic, add extra row at end of column */
-                       if (dl->flag & DL_CYCL_V) {
-                               for (v = 0; v < nsizev; v++) {
-                                       v1= RE_findOrAddVert(re, startvert + v);
-                                       ver= RE_findOrAddVert(re, re->totvert++);
-                                       VECCOPY(ver->co, v1->co);
-                                       if(orco) {
-                                               ver->orco= orcobase + 3*(0*sizev + v);
-                                       }
-                               }
-                       }
-                       
-                       sizeu = nsizeu;
-                       sizev = nsizev;
-
-                       startvlak= re->totvlak;
-
-                       for(u = 0; u < sizeu - 1; u++) {
-                               p1 = startvert + u * sizev; /* walk through face list */
-                               p2 = p1 + 1;
-                               p3 = p2 + sizev;
-                               p4 = p3 - 1;
-
-                               for(v = 0; v < sizev - 1; v++) {
-                                       v1= RE_findOrAddVert(re, p1);
-                                       v2= RE_findOrAddVert(re, p2);
-                                       v3= RE_findOrAddVert(re, p3);
-                                       v4= RE_findOrAddVert(re, p4);
-
-                                       vlr= RE_findOrAddVlak(re, re->totvlak++);
-                                       vlr->ob= ob;
-                                       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);
-                                       VECCOPY(vlr->n, n1);
-                                       
-                                       vlr->lay= ob->lay;
-                                       vlr->mat= matar[ dl->col];
-                                       vlr->ec= ME_V1V2+ME_V2V3;
-                                       vlr->flag= dl->rt;
-                                       if( (cu->flag & CU_NOPUNOFLIP) ) {
-                                               vlr->flag |= R_NOPUNOFLIP;
-                                       }
-
-                                       VecAddf(v1->n, v1->n, n1);
-                                       VecAddf(v2->n, v2->n, n1);
-                                       VecAddf(v3->n, v3->n, n1);
-                                       VecAddf(v4->n, v4->n, n1);
-
-                                       p1++; p2++; p3++; p4++;
-                               }
-                       }       
-                       /* fix normals for U resp. V cyclic faces */
-                       sizeu--; sizev--;  /* dec size for face array */
-                       if (dl->flag & DL_CYCL_V) {
-
-                               for (v = 0; v < sizev; v++)
-                               {
-                                       /* optimize! :*/
-                                       vlr= RE_findOrAddVlak(re, UVTOINDEX(sizeu - 1, v));
-                                       vlr1= RE_findOrAddVlak(re, UVTOINDEX(0, v));
-                                       VecAddf(vlr1->v1->n, vlr1->v1->n, vlr->n);
-                                       VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n);
-                                       VecAddf(vlr->v3->n, vlr->v3->n, vlr1->n);
-                                       VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n);
-                               }
-                       }
-                       if (dl->flag & DL_CYCL_U) {
-
-                               for (u = 0; u < sizeu; u++)
-                               {
-                                       /* optimize! :*/
-                                       vlr= RE_findOrAddVlak(re, UVTOINDEX(u, 0));
-                                       vlr1= RE_findOrAddVlak(re, UVTOINDEX(u, sizev-1));
-                                       VecAddf(vlr1->v2->n, vlr1->v2->n, vlr->n);
-                                       VecAddf(vlr1->v3->n, vlr1->v3->n, vlr->n);
-                                       VecAddf(vlr->v1->n, vlr->v1->n, vlr1->n);
-                                       VecAddf(vlr->v4->n, vlr->v4->n, vlr1->n);
-                               }
-                       }
-                       /* last vertex is an extra case: 
-
-                       ^       ()----()----()----()
-                       |       |     |     ||     |
-                       u       |     |(0,n)||(0,0)|
-                               |     |     ||     |
-                               ()====()====[]====()
-                               |     |     ||     |
-                               |     |(m,n)||(m,0)|
-                               |     |     ||     |
-                               ()----()----()----()
-                                      v ->
-
-                       vertex [] is no longer shared, therefore distribute
-                       normals of the surrounding faces to all of the duplicates of []
-                       */
-
-                       if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U))
-                       {
-                               vlr= RE_findOrAddVlak(re, UVTOINDEX(sizeu - 1, sizev - 1)); /* (m,n) */
-                               vlr1= RE_findOrAddVlak(re, UVTOINDEX(0,0));  /* (0,0) */
-                               VecAddf(vn, vlr->n, vlr1->n);
-                               vlr2= RE_findOrAddVlak(re, UVTOINDEX(0, sizev-1)); /* (0,n) */
-                               VecAddf(vn, vn, vlr2->n);
-                               vlr3= RE_findOrAddVlak(re, UVTOINDEX(sizeu-1, 0)); /* (m,0) */
-                               VecAddf(vn, vn, vlr3->n);
-                               VECCOPY(vlr->v3->n, vn);
-                               VECCOPY(vlr1->v1->n, vn);
-                               VECCOPY(vlr2->v2->n, vn);
-                               VECCOPY(vlr3->v4->n, vn);
-                       }
-                       for(a = startvert; a < re->totvert; a++) {
-                               ver= RE_findOrAddVert(re, a);
-                               Normalise(ver->n);
-                       }
-
-
+                       orco+= 3*dl_surf_to_renderdata(re, ob, dl, matar, orco, mat);
                }
 
                dl= dl->next;
@@ -2455,97 +2464,103 @@ static void init_render_curve(Render *re, Object *ob, int only_verts)
                        }
                }
                else if (dl->type==DL_SURF) {
-                       int p1,p2,p3,p4;
+                       
+                       if (dl->flag & DL_CYCL_U) {
+                               orco+= 3*dl_surf_to_renderdata(re, ob, dl, matar, orco, mat);
+                       }
+                       else {
+                               int p1,p2,p3,p4;
 
-                       fp= dl->verts;
-                       startvert= re->totvert;
-                       nr= dl->nr*dl->parts;
+                               fp= dl->verts;
+                               startvert= re->totvert;
+                               nr= dl->nr*dl->parts;
 
-                       while(nr--) {
-                               ver= RE_findOrAddVert(re, re->totvert++);
-                                       
-                               VECCOPY(ver->co, fp);
-                               MTC_Mat4MulVecfl(mat, ver->co);
-                               fp+= 3;
+                               while(nr--) {
+                                       ver= RE_findOrAddVert(re, re->totvert++);
+                                               
+                                       VECCOPY(ver->co, fp);
+                                       MTC_Mat4MulVecfl(mat, ver->co);
+                                       fp+= 3;
 
-                               if (orco) {
-                                       ver->orco = orco;
-                                       orco += 3;
+                                       if (orco) {
+                                               ver->orco = orco;
+                                               orco += 3;
+                                       }
                                }
-                       }
 
-                       if(dl->bevelSplitFlag || only_verts==0) {
-                               startvlak= re->totvlak;
+                               if(dl->bevelSplitFlag || only_verts==0) {
+                                       startvlak= re->totvlak;
 
-                               for(a=0; a<dl->parts; a++) {
+                                       for(a=0; a<dl->parts; a++) {
 
-                                       frontside= (a >= dl->nr/2);
+                                               frontside= (a >= dl->nr/2);
 
-                                       DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
-                                       p1+= startvert;
-                                       p2+= startvert;
-                                       p3+= startvert;
-                                       p4+= startvert;
+                                               DL_SURFINDEX(dl->flag & DL_CYCL_U, dl->flag & DL_CYCL_V, dl->nr, dl->parts);
+                                               p1+= startvert;
+                                               p2+= startvert;
+                                               p3+= startvert;
+                                               p4+= startvert;
 
-                                       for(; b<dl->nr; b++) {
-                                               vlr= RE_findOrAddVlak(re, re->totvlak++);
-                                               vlr->ob= ob;
-                                               vlr->v1= RE_findOrAddVert(re, p2);
-                                               vlr->v2= RE_findOrAddVert(re, p1);
-                                               vlr->v3= RE_findOrAddVert(re, p3);
-                                               vlr->v4= RE_findOrAddVert(re, p4);
-                                               vlr->ec= ME_V2V3+ME_V3V4;
-                                               if(a==0) vlr->ec+= ME_V1V2;
-
-                                               vlr->flag= dl->rt;
-                                               vlr->lay= ob->lay;
+                                               for(; b<dl->nr; b++) {
+                                                       vlr= RE_findOrAddVlak(re, re->totvlak++);
+                                                       vlr->ob= ob;
+                                                       vlr->v1= RE_findOrAddVert(re, p2);
+                                                       vlr->v2= RE_findOrAddVert(re, p1);
+                                                       vlr->v3= RE_findOrAddVert(re, p3);
+                                                       vlr->v4= RE_findOrAddVert(re, p4);
+                                                       vlr->ec= ME_V2V3+ME_V3V4;
+                                                       if(a==0) vlr->ec+= ME_V1V2;
+
+                                                       vlr->flag= dl->rt;
+                                                       vlr->lay= ob->lay;
 
-                                               /* this is not really scientific: the vertices
-                                                       * 2, 3 en 4 seem to give better vertexnormals than 1 2 3:
-                                                       * front and backside treated different!!
-                                                       */
+                                                       /* this is not really scientific: the vertices
+                                                               * 2, 3 en 4 seem to give better vertexnormals than 1 2 3:
+                                                               * front and backside treated different!!
+                                                               */
 
-                                               if(frontside)
-                                                       CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, vlr->n);
-                                               else 
-                                                       CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->n);
+                                                       if(frontside)
+                                                               CalcNormFloat(vlr->v2->co, vlr->v3->co, vlr->v4->co, vlr->n);
+                                                       else 
+                                                               CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->n);
 
-                                               vlr->mat= matar[ dl->col ];
+                                                       vlr->mat= matar[ dl->col ];
 
-                                               p4= p3;
-                                               p3++;
-                                               p2= p1;
-                                               p1++;
+                                                       p4= p3;
+                                                       p3++;
+                                                       p2= p1;
+                                                       p1++;
+                                               }
                                        }
-                               }
 
-                               if (dl->bevelSplitFlag) {
-                                       for(a=0; a<dl->parts-1+!!(dl->flag&DL_CYCL_V); a++)
-                                               if(dl->bevelSplitFlag[a>>5]&(1<<(a&0x1F)))
-                                                       split_v_renderfaces(re, startvlak, startvert, dl->parts, dl->nr, a, dl->flag&DL_CYCL_V, dl->flag&DL_CYCL_U);
-                               }
+                                       if (dl->bevelSplitFlag) {
+                                               for(a=0; a<dl->parts-1+!!(dl->flag&DL_CYCL_V); a++)
+                                                       if(dl->bevelSplitFlag[a>>5]&(1<<(a&0x1F)))
+                                                               split_v_renderfaces(re, startvlak, startvert, dl->parts, dl->nr, a, dl->flag&DL_CYCL_V, dl->flag&DL_CYCL_U);
+                                       }
 
-                               /* vertex normals */
-                               for(a= startvlak; a<re->totvlak; a++) {
-                                       vlr= RE_findOrAddVlak(re, a);
+                                       /* vertex normals */
+                                       for(a= startvlak; a<re->totvlak; a++) {
+                                               vlr= RE_findOrAddVlak(re, a);
 
-                                       VecAddf(vlr->v1->n, vlr->v1->n, vlr->n);
-                                       VecAddf(vlr->v3->n, vlr->v3->n, vlr->n);
-                                       VecAddf(vlr->v2->n, vlr->v2->n, vlr->n);
-                                       VecAddf(vlr->v4->n, vlr->v4->n, vlr->n);
-                               }
-                               for(a=startvert; a<re->totvert; a++) {
-                                       ver= RE_findOrAddVert(re, a);
-                                       len= Normalise(ver->n);
-                                       if(len==0.0) ver->flag= 1;      /* flag use, its only used in zbuf now  */
-                                       else ver->flag= 0;
-                               }
-                               for(a= startvlak; a<re->totvlak; a++) {
-                                       vlr= RE_findOrAddVlak(re, a);
-                                       if(vlr->v1->flag) VECCOPY(vlr->v1->n, vlr->n);
-                                       if(vlr->v2->flag) VECCOPY(vlr->v2->n, vlr->n);
-                                       if(vlr->v3->flag) VECCOPY(vlr->v3->n, vlr->n);
-                                       if(vlr->v4->flag) VECCOPY(vlr->v4->n, vlr->n);
+                                               VecAddf(vlr->v1->n, vlr->v1->n, vlr->n);
+                                               VecAddf(vlr->v3->n, vlr->v3->n, vlr->n);
+                                               VecAddf(vlr->v2->n, vlr->v2->n, vlr->n);
+                                               VecAddf(vlr->v4->n, vlr->v4->n, vlr->n);
+                                       }
+                                       for(a=startvert; a<re->totvert; a++) {
+                                               ver= RE_findOrAddVert(re, a);
+                                               len= Normalise(ver->n);
+                                               if(len==0.0) ver->flag= 1;      /* flag use, its only used in zbuf now  */
+                                               else ver->flag= 0;
+                                       }
+                                       for(a= startvlak; a<re->totvlak; a++) {
+                                               vlr= RE_findOrAddVlak(re, a);
+                                               if(vlr->v1->flag) VECCOPY(vlr->v1->n, vlr->n);
+                                               if(vlr->v2->flag) VECCOPY(vlr->v2->n, vlr->n);
+                                               if(vlr->v3->flag) VECCOPY(vlr->v3->n, vlr->n);
+                                               if(vlr->v4->flag) VECCOPY(vlr->v4->n, vlr->n);
+                                       }
                                }
                        }
                }
index ab7e8c2b4553b9106f32adbff67153b1690391dc..ac97acbd87dd539100f45b85473ad8ce253feb6a 100644 (file)
@@ -1358,9 +1358,11 @@ static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim)
                        
                        for (i=0; i<evedef->totweight; i++){
                                dg = BLI_findlink (&ob->defbase, evedef->dw[i].def_nr);
-                               max+= sprintf(str, "%s %%x%d|", dg->name, evedef->dw[i].def_nr); 
-                               if(max<320) strcat(defstr, str);
-                               
+                               if(dg) {
+                                       max+= sprintf(str, "%s %%x%d|", dg->name, evedef->dw[i].def_nr); 
+                                       if(max<320) strcat(defstr, str);
+                               }
+                               else printf("oh no!\n");
                                if(curdef==evedef->dw[i].def_nr) {
                                        init= 0;
                                        defweightp= &evedef->dw[i].weight;