svn merge ^/trunk/blender -r42290:42292
authorCampbell Barton <ideasman42@gmail.com>
Wed, 30 Nov 2011 10:07:04 +0000 (10:07 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 30 Nov 2011 10:07:04 +0000 (10:07 +0000)
1  2 
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/dynamicpaint.c

index 6947bf05890e558b74d713890282b6b72e00b72e,1f09d98d697c359d92ed4641a5bcd6371c03095a..49ca4e139cc8770d14c8ad10aa34aef3d8170b00
@@@ -45,9 -45,6 +45,9 @@@
  #include "BLI_utildefines.h"
  
  
 +#include "BLI_cellalloc.h"
 +
 +
  void defgroup_copy_list(ListBase *outbase, ListBase *inbase)
  {
        bDeformGroup *defgroup, *defgroupn;
@@@ -86,10 -83,10 +86,10 @@@ void defvert_copy(MDeformVert *dvert_ds
        }
        else {
                if (dvert_dst->dw)
 -                      MEM_freeN(dvert_dst->dw);
 +                      BLI_cellalloc_free(dvert_dst->dw);
  
                if (dvert_src->totweight)
 -                      dvert_dst->dw= MEM_dupallocN(dvert_src->dw);
 +                      dvert_dst->dw= BLI_cellalloc_dupalloc(dvert_src->dw);
                else
                        dvert_dst->dw= NULL;
  
@@@ -561,10 -558,10 +561,10 @@@ MDeformWeight *defvert_verify_index(MDe
        if (dw_new)
                return dw_new;
  
-       dw_new= BLI_cellalloc_calloc(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight");
 -      dw_new= MEM_callocN(sizeof(MDeformWeight)*(dvert->totweight+1), "deformWeight");
++      dw_new= BLI_cellalloc_calloc(sizeof(MDeformWeight)*(dvert->totweight+1), "deformWeight");
        if (dvert->dw) {
                memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*dvert->totweight);
 -              MEM_freeN(dvert->dw);
 +              BLI_cellalloc_free(dvert->dw);
        }
        dvert->dw= dw_new;
        dw_new += dvert->totweight;
@@@ -606,17 -603,17 +606,17 @@@ void defvert_remove_index(MDeformVert *
         * this deform weight, and reshuffle the others.
         */
        if (dvert->totweight) {
 -              dw_new = MEM_mallocN(sizeof(MDeformWeight)*(dvert->totweight), __func__);
 +              dw_new = BLI_cellalloc_malloc(sizeof(MDeformWeight)*(dvert->totweight), __func__);
                if (dvert->dw){
                        memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*i);
                        memcpy(dw_new+i, dvert->dw+i+1, sizeof(MDeformWeight)*(dvert->totweight-i));
 -                      MEM_freeN(dvert->dw);
 +                      BLI_cellalloc_free(dvert->dw);
                }
                dvert->dw = dw_new;
        }
        else {
                /* If there are no other deform weights left then just remove this one. */
 -              MEM_freeN(dvert->dw);
 +              BLI_cellalloc_free(dvert->dw);
                dvert->dw = NULL;
        }
  }
index 75b6cb10e7e8226f61be001c9c34771a612bfb4f,9a5bbf8e6b87806a721f12172279b734ba002c48..08e5f65f380c3b4f9359906441a586e4e0af8499
@@@ -1213,9 -1213,9 +1213,9 @@@ static void dynamicPaint_initAdjacencyD
  
                /* For vertex format, count every vertex that is connected by an edge */
                int numOfEdges = surface->canvas->dm->getNumEdges(surface->canvas->dm);
 -              int numOfFaces = surface->canvas->dm->getNumFaces(surface->canvas->dm);
 +              int numOfFaces = surface->canvas->dm->getNumTessFaces(surface->canvas->dm);
                struct MEdge *edge =  surface->canvas->dm->getEdgeArray(surface->canvas->dm);
 -              struct MFace *face =  surface->canvas->dm->getFaceArray(surface->canvas->dm);
 +              struct MFace *face =  surface->canvas->dm->getTessFaceArray(surface->canvas->dm);
  
                /* count number of edges per vertex */
                for (i=0; i<numOfEdges; i++) {
@@@ -1301,8 -1301,8 +1301,8 @@@ void dynamicPaint_setInitialColor(Dynam
        else if (surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) {
                Tex *tex = surface->init_texture;
                MTFace *tface;
 -              MFace *mface = dm->getFaceArray(dm);
 -              int numOfFaces = dm->getNumFaces(dm);
 +              MFace *mface = dm->getTessFaceArray(dm);
 +              int numOfFaces = dm->getNumTessFaces(dm);
                char uvname[40];
  
                if (!tex) return;
  
                /* for vertex surface, just copy colors from mcol */
                if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
 -                      MFace *mface = dm->getFaceArray(dm);
 -                      int numOfFaces = dm->getNumFaces(dm);
 +                      MFace *mface = dm->getTessFaceArray(dm);
 +                      int numOfFaces = dm->getNumTessFaces(dm);
  
                        #pragma omp parallel for schedule(static)
                        for (i=0; i<numOfFaces; i++) {
@@@ -1524,7 -1524,7 +1524,7 @@@ static struct DerivedMesh *dynamicPaint
                                                         Object *ob,
                                                         DerivedMesh *dm)
  {     
 -      DerivedMesh *result = CDDM_copy(dm);
 +      DerivedMesh *result = CDDM_copy(dm, 0); /* BMESH_TODO second argument untested, may be incorrect - campbell */
  
        if(pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
  
                                        /* vertex color paint */
                                        if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
  
 -                                              MFace *mface = result->getFaceArray(result);
 -                                              int numOfFaces = result->getNumFaces(result);
 +                                              MFace *mface = result->getTessFaceArray(result);
 +                                              int numOfFaces = result->getNumTessFaces(result);
                                                int i;
                                                PaintPoint* pPoint = (PaintPoint*)sData->type_data;
                                                MCol *col;
                                                if (surface->flags & MOD_DPAINT_PREVIEW) {
                                                        /* Save preview results to weight layer, to be
                                                        *   able to share same drawing methods */
 -                                                      col = result->getFaceDataArray(result, CD_WEIGHT_MCOL);
 +                                                      col = result->getTessFaceDataArray(result, CD_WEIGHT_MCOL);
                                                        if (!col) col = CustomData_add_layer(&result->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numOfFaces);
  
                                                        if (col) {
                                                if (surface->flags & MOD_DPAINT_PREVIEW) {
                                                        /* Save preview results to weight layer, to be
                                                        *   able to share same drawing methods */
 -                                                      MFace *mface = result->getFaceArray(result);
 -                                                      int numOfFaces = result->getNumFaces(result);
 +                                                      MFace *mface = result->getTessFaceArray(result);
 +                                                      int numOfFaces = result->getNumPolys(result);
                                                        int i;
 -                                                      MCol *col = result->getFaceDataArray(result, CD_WEIGHT_MCOL);
 +                                                      MCol *col = result->getTessFaceDataArray(result, CD_WEIGHT_MCOL);
                                                        if (!col) col = CustomData_add_layer(&result->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numOfFaces);
  
                                                        if (col) {
                                                                MDeformWeight *def_weight = defvert_find_index(dv, defgrp_index);
  
                                                                /* skip if weight value is 0 and no existing weight is found */
-                                                               if (!def_weight && !weight[i])
-                                                                       continue;
-                                                               /* if not found, add a weight for it */
-                                                               if (!def_weight) {
-                                                                       MDeformWeight *newdw = MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), 
-                                                                                                                "deformWeight");
-                                                                       if(dv->dw){
-                                                                               memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight);
-                                                                               MEM_freeN(dv->dw);
+                                                               if ((def_weight != NULL) || (weight[i] != 0.0f)) {
+                                                                       /* if not found, add a weight for it */
+                                                                       if (def_weight == NULL) {
+                                                                               def_weight= defvert_verify_index(dv, defgrp_index);
                                                                        }
-                                                                       dv->dw=newdw;
-                                                                       dv->dw[dv->totweight].def_nr=defgrp_index;
-                                                                       def_weight = &dv->dw[dv->totweight];
-                                                                       dv->totweight++;
-                                                               }
  
-                                                               /* set weight value */
-                                                               def_weight->weight = weight[i];
+                                                                       /* set weight value */
+                                                                       def_weight->weight = weight[i];
+                                                               }
                                                        }
                                                }
                                        }
                                                for (i=0; i<sData->total_points; i++) {
                                                        float normal[3];
                                                        normal_short_to_float_v3(normal, mvert[i].no);
-                                                       normalize_v3(normal);
-                                                       mvert[i].co[0] += normal[0]*wPoint[i].height;
-                                                       mvert[i].co[1] += normal[1]*wPoint[i].height;
-                                                       mvert[i].co[2] += normal[2]*wPoint[i].height;
+                                                       madd_v3_v3fl(mvert[i].co, normal, wPoint[i].height);
                                                }
                                                CDDM_calc_normals(result);
                                        }
        /* make a copy of dm to use as brush data */
        if (pmd->brush) {
                if (pmd->brush->dm) pmd->brush->dm->release(pmd->brush->dm);
 -              pmd->brush->dm = CDDM_copy(result);
 +              pmd->brush->dm = CDDM_copy(result, 0); /* BMESH_TODO untested second argument - campbell */
        }
  
        return result;
@@@ -1771,7 -1758,7 +1758,7 @@@ void dynamicPaint_cacheUpdateFrames(Dyn
  void canvas_copyDerivedMesh(DynamicPaintCanvasSettings *canvas, DerivedMesh *dm)
  {
        if (canvas->dm) canvas->dm->release(canvas->dm);
 -      canvas->dm = CDDM_copy(dm);
 +      canvas->dm = CDDM_copy(dm, 0); /* BMESH_TODO second argument untested, may be incorrect - campbell */
  }
  
  /*
@@@ -1924,9 -1911,9 +1911,9 @@@ static int dynamicPaint_findNeighbourPi
        *       TODO: Implement something more accurate / optimized?
        */
        {
 -              int numOfFaces = dm->getNumFaces(dm);
 -              MFace *mface = dm->getFaceArray(dm);
 -              MTFace *tface =  CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
 +              int numOfFaces = dm->getNumTessFaces(dm);
 +              MFace *mface = dm->getTessFaceArray(dm);
 +              MTFace *tface =  CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); /* BMESH_TODO, is this data valid?, possibly need loop uv's */
  
                /* Get closest edge to that subpixel on UV map  */
                {
@@@ -2091,8 -2078,8 +2078,8 @@@ int dynamicPaint_createUVSurface(Dynami
        if (!dm) return setError(canvas, "Canvas mesh not updated.");
        if (surface->format != MOD_DPAINT_SURFACE_F_IMAGESEQ) return setError(canvas, "Can't bake non-\"image sequence\" formats.");
  
 -      numOfFaces = dm->getNumFaces(dm);
 -      mface = dm->getFaceArray(dm);
 +      numOfFaces = dm->getNumPolys(dm);
 +      mface = dm->getTessFaceArray(dm);
  
        /* get uv map */
        CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, surface->uvlayer_name, uvname);
@@@ -2693,7 -2680,7 +2680,7 @@@ static void dynamicPaint_freeBrushMater
  void dynamicPaint_doMaterialTex(BrushMaterials *bMats, float color[3], float *alpha, Object *brushOb, const float volume_co[3], const float surface_co[3], int faceIndex, short isQuad, DerivedMesh *orcoDm)
  {
        Material *mat = bMats->mat;
 -      MFace *mface = orcoDm->getFaceArray(orcoDm);
 +      MFace *mface = orcoDm->getTessFaceArray(orcoDm);
  
        /* If no material defined, use the one assigned to the mesh face */
        if (mat == NULL) {
@@@ -3019,7 -3006,7 +3006,7 @@@ static void dynamicPaint_brushMeshCalcu
        scene->r.subframe = prev_sfra;
  
        subframe_updateObject(scene, ob, UPDATE_EVERYTHING, BKE_curframe(scene));
 -      dm_p = CDDM_copy(brush->dm);
 +      dm_p = CDDM_copy(brush->dm, 0); /* BMESH_TODO second argument untested, may be incorrect - campbell */
        numOfVerts_p = dm_p->getNumVerts(dm_p);
        mvert_p = dm_p->getVertArray(dm_p);
        copy_m4_m4(prev_obmat, ob->obmat);
@@@ -3123,9 -3110,9 +3110,9 @@@ static int dynamicPaint_paintMesh(Dynam
                Bounds3D mesh_bb = {0};
                VolumeGrid *grid = bData->grid;
  
 -              dm = CDDM_copy(brush->dm);
 +              dm = CDDM_copy(brush->dm, 0); /* BMESH_TODO second argument untested, may be incorrect - campbell */
                mvert = dm->getVertArray(dm);
 -              mface = dm->getFaceArray(dm);
 +              mface = dm->getTessFaceArray(dm);
                numOfVerts = dm->getNumVerts(dm);
  
                /*      Transform collider vertices to global space