=bmesh= merge from trunk at r36529
[blender.git] / source / blender / blenkernel / intern / displist.c
index a6957d6ead137bbbdb4f701f6ef31cae559cd39d..48192546b0f58013802f9d044efdcccd4a2410fe 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/blenkernel/intern/displist.c
+ *  \ingroup bke
+ */
+
+
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
 
 #include "MEM_guardedalloc.h"
 
-
 #include "DNA_curve_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
@@ -46,6 +50,7 @@
 #include "BLI_math.h"
 #include "BLI_editVert.h"
 #include "BLI_scanfill.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_global.h"
 #include "BKE_displist.h"
@@ -121,7 +126,7 @@ DispList *find_displist(ListBase *lb, int type)
                dl= dl->next;
        }
 
-       return 0;
+       return NULL;
 }
 
 int displist_has_faces(ListBase *lb)
@@ -138,7 +143,7 @@ void copy_displist(ListBase *lbn, ListBase *lb)
 {
        DispList *dln, *dl;
        
-       lbn->first= lbn->last= 0;
+       freedisplist(lbn);
        
        dl= lb->first;
        while(dl) {
@@ -150,7 +155,10 @@ void copy_displist(ListBase *lbn, ListBase *lb)
                dln->index= MEM_dupallocN(dl->index);
                dln->col1= MEM_dupallocN(dl->col1);
                dln->col2= MEM_dupallocN(dl->col2);
-               
+
+               if(dl->bevelSplitFlag)
+                       dln->bevelSplitFlag= MEM_dupallocN(dl->bevelSplitFlag);
+
                dl= dl->next;
        }
 }
@@ -170,8 +178,8 @@ void addnormalsDispList(ListBase *lb)
                if(dl->type==DL_INDEX3) {
                        if(dl->nors==NULL) {
                                dl->nors= MEM_callocN(sizeof(float)*3, "dlnors");
-                               if(dl->verts[2]<0.0) dl->nors[2]= -1.0;
-                               else dl->nors[2]= 1.0;
+                               if(dl->verts[2] < 0.0f) dl->nors[2]= -1.0f;
+                               else dl->nors[2]= 1.0f;
                        }
                }
                else if(dl->type==DL_SURF) {
@@ -405,10 +413,10 @@ static void fastshade(float *co, float *nor, float *orco, Material *ma, char *co
                        VECCOPY(shi.orn, shi.vn);
                }
                if(ma->texco & TEXCO_REFL) {
-                       float inp= 2.0*(shi.vn[2]);
+                       float inp= 2.0f * (shi.vn[2]);
                        shi.ref[0]= (inp*shi.vn[0]);
                        shi.ref[1]= (inp*shi.vn[1]);
-                       shi.ref[2]= (-1.0+inp*shi.vn[2]);
+                       shi.ref[2]= (-1.0f + inp*shi.vn[2]);
                }
        }
        
@@ -507,10 +515,10 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
                dm = mesh_get_derived_final(RE_GetScene(re), ob, dataMask);
        
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
-       nors = dm->getFaceDataArray(dm, CD_NORMAL);
+       mface = dm->getTessFaceArray(dm);
+       nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
        totvert = dm->getNumVerts(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
        orco= dm->getVertDataArray(dm, CD_ORCO);
 
        if (onlyForMesh) {
@@ -581,9 +589,7 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
 
                        mul_v3_m4v3(vec, mat, mv->co);
 
-                       vec[0]+= 0.001*vn[0];
-                       vec[1]+= 0.001*vn[1];
-                       vec[2]+= 0.001*vn[2];
+                       mul_v3_v3fl(vec, vn, 0.001f);
 
                        fastshade_customdata(&dm->faceData, i, j, ma);
                        fastshade(vec, vn, orco?&orco[vidx[j]*3]:mv->co, ma, col1, col2);
@@ -622,7 +628,6 @@ void shadeDispList(Scene *scene, Base *base)
        Object *ob= base->object;
        DispList *dl, *dlob;
        Material *ma = NULL;
-       Curve *cu;
        Render *re;
        float imat[3][3], mat[4][4], vec[3];
        float *fp, *nor, n1[3];
@@ -656,8 +661,7 @@ void shadeDispList(Scene *scene, Base *base)
                if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
                
                        /* now we need the normals */
-                       cu= ob->data;
-                       dl= cu->disp.first;
+                       dl= ob->disp.first;
                        
                        while(dl) {
                                extern Material defmaterial;    /* material.c */
@@ -929,19 +933,21 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal)
 {
        EditVert *eve, *v1, *vlast;
        EditFace *efa;
-       DispList *dlnew=0, *dl;
+       DispList *dlnew=NULL, *dl;
        float *f1;
        int colnr=0, charidx=0, cont=1, tot, a, *index, nextcol= 0;
        intptr_t totvert;
        
-       if(dispbase==0) return;
-       if(dispbase->first==0) return;
+       if(dispbase==NULL) return;
+       if(dispbase->first==NULL) return;
 
        while(cont) {
                cont= 0;
                totvert= 0;
                nextcol= 0;
                
+               BLI_begin_edgefill();
+               
                dl= dispbase->first;
                while(dl) {
        
@@ -952,7 +958,7 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal)
                                                /* make editverts and edges */
                                                f1= dl->verts;
                                                a= dl->nr;
-                                               eve= v1= 0;
+                                               eve= v1= NULL;
                                                
                                                while(a--) {
                                                        vlast= eve;
@@ -960,14 +966,14 @@ void filldisplist(ListBase *dispbase, ListBase *to, int flipnormal)
                                                        eve= BLI_addfillvert(f1);
                                                        totvert++;
 
-                                                       if(vlast==0) v1= eve;
+                                                       if(vlast==NULL) v1= eve;
                                                        else {
                                                                BLI_addfilledge(vlast, eve);
                                                        }
                                                        f1+=3;
                                                }
 
-                                               if(eve!=0 && v1!=0) {
+                                               if(eve!=NULL && v1!=NULL) {
                                                        BLI_addfilledge(eve, v1);
                                                }
                                        } else if (colnr<dl->col) {
@@ -1057,7 +1063,7 @@ static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
        float *fp, *fp1;
        int a, dpoly;
        
-       front.first= front.last= back.first= back.last= 0;
+       front.first= front.last= back.first= back.last= NULL;
        
        dl= dispbase->first;
        while(dl) {
@@ -1137,16 +1143,14 @@ static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dis
 */
 float calc_taper(Scene *scene, Object *taperobj, int cur, int tot)
 {
-       Curve *cu;
        DispList *dl;
        
        if(taperobj==NULL || taperobj->type!=OB_CURVE) return 1.0;
        
-       cu= taperobj->data;
-       dl= cu->disp.first;
+       dl= taperobj->disp.first;
        if(dl==NULL) {
                makeDispListCurveTypes(scene, taperobj, 0);
-               dl= cu->disp.first;
+               dl= taperobj->disp.first;
        }
        if(dl) {
                float fac= ((float)cur)/(float)(tot-1);
@@ -1156,7 +1160,7 @@ float calc_taper(Scene *scene, Object *taperobj, int cur, int tot)
                /* horizontal size */
                minx= dl->verts[0];
                dx= dl->verts[3*(dl->nr-1)] - minx;
-               if(dx>0.0) {
+               if(dx > 0.0f) {
                
                        fp= dl->verts;
                        for(a=0; a<dl->nr; a++, fp+=3) {
@@ -1221,10 +1225,20 @@ static ModifierData *curve_get_tesselate_point(Scene *scene, Object *ob, int for
 
        preTesselatePoint = NULL;
        for (; md; md=md->next) {
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
                if (!modifier_isEnabled(scene, md, required_mode)) continue;
+               if (mti->type == eModifierTypeType_Constructive) return preTesselatePoint;
 
                if (ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) {
-                       preTesselatePoint  = md;
+                       preTesselatePoint = md;
+
+                       /* this modifiers are moving point of tesselation automatically
+                          (some of them even can't be applied on tesselated curve), set flag
+                          for incformation button in modifier's header */
+                       md->mode |= eModifierMode_ApplyOnSpline;
+               } else if(md->mode&eModifierMode_ApplyOnSpline) {
+                       preTesselatePoint = md;
                }
        }
 
@@ -1395,7 +1409,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba
 
                        if (dm) {
                                if (vertCos) {
-                                       DerivedMesh *tdm = CDDM_copy(dm);
+                                       DerivedMesh *tdm = CDDM_copy(dm, 0);
                                        dm->release(dm);
                                        dm = tdm;
 
@@ -1436,7 +1450,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba
 
        if (vertCos) {
                if (dm) {
-                       DerivedMesh *tdm = CDDM_copy(dm);
+                       DerivedMesh *tdm = CDDM_copy(dm, 0);
                        dm->release(dm);
                        dm = tdm;
 
@@ -1675,6 +1689,11 @@ void makeDispListSurf(Scene *scene, Object *ob, ListBase *dispbase,
                }
        }
 
+       /* make copy of 'undeformed" displist for texture space calculation
+          actually, it's not totally undeformed -- pre-tesselation modifiers are
+          already applied, thats how it worked for years, so keep for compatibility (sergey) */
+       copy_displist(&cu->disp, dispbase);
+
        if (!forRender) {
                tex_space_curve(cu);
        }
@@ -1722,7 +1741,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                if (!dlbev.first && cu->width==1.0f) {
                        curve_to_displist(cu, nubase, dispbase, forRender);
                } else {
-                       float widfac= cu->width-1.0;
+                       float widfac= cu->width - 1.0f;
                        BevList *bl= cu->bev.first;
                        Nurb *nu= nubase->first;
 
@@ -1790,8 +1809,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                                                        /* CU_2D conflicts with R_NOPUNOFLIP */
                                                        dl->rt= nu->flag & ~CU_2D;
 
-                                                       dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((bl->nr+0x1F)>>5), "col2");
-                                                       bevp= (BevPoint *)(bl+1);
+                                                       dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((bl->nr+0x1F)>>5), "bevelSplitFlag");
        
                                                        /* for each point of poly make a bevel piece */
                                                        bevp= (BevPoint *)(bl+1);
@@ -1848,9 +1866,14 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
 
                if(cu->flag & CU_PATH) calc_curvepath(ob);
 
-                if (!forRender) {
-                        tex_space_curve(cu);
-                }
+               /* make copy of 'undeformed" displist for texture space calculation
+                  actually, it's not totally undeformed -- pre-tesselation modifiers are
+                  already applied, thats how it worked for years, so keep for compatibility (sergey) */
+               copy_displist(&cu->disp, dispbase);
+
+               if (!forRender) {
+                       tex_space_curve(cu);
+               }
 
                if(!forOrco) curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, forRender, originalVerts, deformedVerts);
 
@@ -1862,13 +1885,16 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
 
 void makeDispListCurveTypes(Scene *scene, Object *ob, int forOrco)
 {
-       Curve *cu = ob->data;
+       Curve *cu= ob->data;
        ListBase *dispbase;
 
        freedisplist(&(ob->disp));
-       dispbase= &(cu->disp);
+       dispbase= &(ob->disp);
        freedisplist(dispbase);
 
+       /* free displist used for textspace */
+       freedisplist(&cu->disp);
+
        do_makeDispListCurveTypes(scene, ob, dispbase, &ob->derivedFinal, 0, forOrco);
 
        if (ob->derivedFinal) {
@@ -1915,15 +1941,10 @@ float *makeOrcoDispList(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int
        return orco;
 }
 
-void imagestodisplist(void)
-{
-       /* removed */
-}
-
 /* this is confusing, there's also min_max_object, appplying the obmat... */
 static void boundbox_displist(Object *ob)
 {
-       BoundBox *bb=0;
+       BoundBox *bb=NULL;
        float min[3], max[3];
        DispList *dl;
        float *vert;
@@ -1935,10 +1956,10 @@ static void boundbox_displist(Object *ob)
                Curve *cu= ob->data;
                int doit= 0;
 
-               if(cu->bb==0) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
+               if(cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
                bb= cu->bb;
                
-               dl= cu->disp.first;
+               dl= ob->disp.first;
 
                while (dl) {
                        if(dl->type==DL_INDEX3) tot= dl->nr;