svn merge ^/trunk/blender -r43420:43436
[blender.git] / source / blender / blenkernel / intern / dynamicpaint.c
index 50f423280437a36eb05b44c6e7a548dbc53a252c..944de316eb153c521270347b3c3d76bee8b7a565 100644 (file)
@@ -1260,9 +1260,9 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, int for
 
                /* 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++) {
@@ -1348,8 +1348,8 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
        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[MAX_CUSTOMDATA_LAYER_NAME];
 
                if (!tex) return;
@@ -1423,8 +1423,8 @@ void dynamicPaint_setInitialColor(DynamicPaintSurface *surface)
 
                /* 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++) {
@@ -1567,7 +1567,7 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                                                        Object *ob,
                                                        DerivedMesh *dm)
 {      
-       DerivedMesh *result = CDDM_copy(dm);
+       DerivedMesh *result = CDDM_copy(dm, 0);
 
        if(pmd->canvas && !(pmd->canvas->flags & MOD_DPAINT_BAKING)) {
 
@@ -1588,11 +1588,11 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                                        /* vertex color paint */
                                        if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
 
-                                               MFace *mface = result->getFaceArray(result);
-                                               int numOfFaces = result->getNumFaces(result);
                                                int i;
                                                PaintPoint* pPoint = (PaintPoint*)sData->type_data;
-                                               MCol *col;
+                                               MLoopCol *col = NULL;
+                                               MLoop *mloop = CDDM_get_loops(result);
+                                               int totloop = result->numLoopData;
 
                                                /* paint is stored on dry and wet layers, so mix final color first */
                                                float *fcolor = MEM_callocN(sizeof(float)*sData->total_points*4, "Temp paint color");
@@ -1604,27 +1604,31 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                                                }
 
                                                /* viewport preview */
-                                               if (surface->flags & MOD_DPAINT_PREVIEW) {
-                                                       /* Save preview results to weight layer, to be
+                                               if (0 && surface->flags & MOD_DPAINT_PREVIEW) {
+                                                       MPoly *mp = CDDM_get_polys(result);
+                                                       int totpoly = result->numPolyData;
+
+                                                       /* Save preview results to weight layer to be
                                                        *   able to share same drawing methods */
-                                                       col = result->getFaceDataArray(result, CD_WEIGHT_MCOL);
-                                                       if (!col) col = CustomData_add_layer(&result->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numOfFaces);
+                                                       col = CustomData_get_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL);
+                                                       if (!col) col = CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_CALLOC, NULL, totloop);
 
                                                        if (col) {
                                                                #pragma omp parallel for schedule(static)
-                                                               for (i=0; i<numOfFaces; i++) {
+                                                               for (i=0; i<totpoly; i++) {
                                                                        int j=0;
-                                                                       Material *material = give_current_material(ob, mface[i].mat_nr+1);
+                                                                       Material *material = give_current_material(ob, mp[i].mat_nr+1);
 
-                                                                       for (; j<((mface[i].v4)?4:3); j++) {
-                                                                               int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
+                                                                       for (; j<mp[i].totloop; j++) {
+                                                                               int l_index = mp[i].loopstart + j;
+                                                                               int v_index = mloop[l_index].v;
 
                                                                                if (surface->preview_id == MOD_DPAINT_SURFACE_PREV_PAINT) {
                                                                                        float c[3];
-                                                                                       index *= 4;
+                                                                                       v_index *= 4;
 
                                                                                        /* Apply material color as base vertex color for preview */
-                                                                                       col[i*4+j].a = 255;
+                                                                                       col[l_index].a = 255;
                                                                                        if (material) {
                                                                                                c[0] = material->r;
                                                                                                c[1] = material->g;
@@ -1636,17 +1640,17 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                                                                                                c[2] = 0.65f;
                                                                                        }
                                                                                        /* mix surface color */
-                                                                                       interp_v3_v3v3(c, c, &fcolor[index], fcolor[index+3]);
+                                                                                       interp_v3_v3v3(c, c, &fcolor[v_index], fcolor[v_index+3]);
 
-                                                                                       col[i*4+j].r = FTOCHAR(c[2]);
-                                                                                       col[i*4+j].g = FTOCHAR(c[1]);
-                                                                                       col[i*4+j].b = FTOCHAR(c[0]);
+                                                                                       col[l_index].r = FTOCHAR(c[2]);
+                                                                                       col[l_index].g = FTOCHAR(c[1]);
+                                                                                       col[l_index].b = FTOCHAR(c[0]);
                                                                                }
                                                                                else {
-                                                                                       col[i*4+j].a = 255;
-                                                                                       col[i*4+j].r =
-                                                                                       col[i*4+j].g =
-                                                                                       col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
+                                                                                       col[l_index].a = 255;
+                                                                                       col[l_index].r =
+                                                                                       col[l_index].g =
+                                                                                       col[l_index].b = FTOCHAR(pPoint[v_index].wetness);
                                                                                }
                                                                        }
                                                                }
@@ -1658,79 +1662,69 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                                                /* save layer data to output layer */
 
                                                /* paint layer */
-                                               col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name);
+                                               col = CustomData_get_layer_named(&result->loopData, CD_MLOOPCOL, surface->output_name);
                                                /* if output layer is lost from a constructive modifier, re-add it */
                                                if (!col && dynamicPaint_outputLayerExists(surface, ob, 0))
-                                                       col = CustomData_add_layer_named(&result->faceData, CD_MCOL, CD_CALLOC, NULL, numOfFaces, surface->output_name);
+                                                       col = CustomData_add_layer_named(&result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name);
                                                /* apply color */
                                                if (col) {
                                                        #pragma omp parallel for schedule(static)
-                                                       for (i=0; i<numOfFaces; i++) {
-                                                               int j=0;
-                                                               for (; j<((mface[i].v4)?4:3); j++) {
-                                                                       int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
-                                                                       index *= 4;
-
-                                                                       col[i*4+j].a = FTOCHAR(fcolor[index+3]);
-                                                                       col[i*4+j].r = FTOCHAR(fcolor[index+2]);
-                                                                       col[i*4+j].g = FTOCHAR(fcolor[index+1]);
-                                                                       col[i*4+j].b = FTOCHAR(fcolor[index]);
-                                                               }
+                                                       for (i=0; i<totloop; i++) {
+                                                               int index = mloop[i].v*4;
+                                                               col[i].a = FTOCHAR(fcolor[index+3]);
+                                                               col[i].r = FTOCHAR(fcolor[index+2]);
+                                                               col[i].g = FTOCHAR(fcolor[index+1]);
+                                                               col[i].b = FTOCHAR(fcolor[index]);
                                                        }
                                                }
                                                
                                                MEM_freeN(fcolor);
 
                                                /* wet layer */
-                                               col = CustomData_get_layer_named(&result->faceData, CD_MCOL, surface->output_name2);
+                                               col = CustomData_get_layer_named(&result->loopData, CD_MLOOPCOL, surface->output_name2);
                                                /* if output layer is lost from a constructive modifier, re-add it */
                                                if (!col && dynamicPaint_outputLayerExists(surface, ob, 1))
-                                                       col = CustomData_add_layer_named(&result->faceData, CD_MCOL, CD_CALLOC, NULL, numOfFaces, surface->output_name2);
+                                                       col = CustomData_add_layer_named(&result->loopData, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name2);
                                                /* apply color */
                                                if (col) {
                                                        #pragma omp parallel for schedule(static)
-                                                       for (i=0; i<numOfFaces; i++) {
-                                                               int j=0;
-
-                                                               for (; j<((mface[i].v4)?4:3); j++) {
-                                                                       int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
-                                                                       col[i*4+j].a = 255;
-                                                                       col[i*4+j].r =
-                                                                       col[i*4+j].g =
-                                                                       col[i*4+j].b = FTOCHAR(pPoint[index].wetness);
-                                                               }
+                                                       for (i=0; i<totloop; i++) {
+                                                               int index = mloop[i].v;
+                                                               col[i].a = 255;
+                                                               col[i].r =
+                                                               col[i].g =
+                                                               col[i].b = FTOCHAR(pPoint[index].wetness);
                                                        }
                                                }
                                        }
                                        /* vertex group paint */
                                        else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
+                                               MLoop *mloop = CDDM_get_loops(result);
+                                               int totloop = result->numLoopData;
+
                                                int defgrp_index = defgroup_name_index(ob, surface->output_name);
                                                MDeformVert *dvert = result->getVertDataArray(result, CD_MDEFORMVERT);
                                                float *weight = (float*)sData->type_data;
+
                                                /* viewport preview */
-                                               if (surface->flags & MOD_DPAINT_PREVIEW) {
-                                                       /* Save preview results to weight layer, to be
+                                               if (0 && 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);
                                                        int i;
-                                                       MCol *col = result->getFaceDataArray(result, CD_WEIGHT_MCOL);
-                                                       if (!col) col = CustomData_add_layer(&result->faceData, CD_WEIGHT_MCOL, CD_CALLOC, NULL, numOfFaces);
+                                                       MLoopCol *col = CustomData_get_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL);
+                                                       if (!col) col = CustomData_add_layer(&dm->loopData, CD_WEIGHT_MLOOPCOL, CD_CALLOC, NULL, totloop);
 
                                                        if (col) {
+                                                               printf("doint weight preview\n");
                                                                #pragma omp parallel for schedule(static)
-                                                               for (i=0; i<numOfFaces; i++) {
+                                                               for (i=0; i<totloop; i++) {
                                                                        float temp_color[3];
-                                                                       int j=0;
-                                                                       for (; j<((mface[i].v4)?4:3); j++) {
-                                                                               int index = (j==0)?mface[i].v1: (j==1)?mface[i].v2: (j==2)?mface[i].v3: mface[i].v4;
-
-                                                                               weight_to_rgb(temp_color, weight[index]);
-                                                                               col[i*4+j].r = FTOCHAR(temp_color[2]);
-                                                                               col[i*4+j].g = FTOCHAR(temp_color[1]);
-                                                                               col[i*4+j].b = FTOCHAR(temp_color[0]);
-                                                                               col[i*4+j].a = 255;
-                                                                       }
+                                                                       weight_to_rgb(temp_color, weight[mloop[i].v]);
+
+                                                                       col[i].a = 255;
+                                                                       col[i].r = FTOCHAR(temp_color[2]);
+                                                                       col[i].g = FTOCHAR(temp_color[1]);
+                                                                       col[i].b = FTOCHAR(temp_color[0]);
                                                                }
                                                                pmd->canvas->flags |= MOD_DPAINT_PREVIEW_READY;
                                                        }
@@ -1785,12 +1779,12 @@ static struct DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData
                }
 
                if (update_normals)
-                       CDDM_calc_normals(result);
+                       CDDM_calc_normals_mapping(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);
        }
 
        return result;
@@ -1808,7 +1802,7 @@ void dynamicPaint_cacheUpdateFrames(DynamicPaintSurface *surface)
 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);
 }
 
 /*
@@ -1962,8 +1956,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
        *       TODO: Implement something more accurate / optimized?
        */
        {
-               int numOfFaces = dm->getNumFaces(dm);
-               MFace *mface = dm->getFaceArray(dm);
+               int numOfFaces = dm->getNumTessFaces(dm);
+               MFace *mface = dm->getTessFaceArray(dm);
                MTFace *tface =  CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
 
                /* Get closest edge to that subpixel on UV map  */
@@ -2129,8 +2123,8 @@ int dynamicPaint_createUVSurface(DynamicPaintSurface *surface)
        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);
@@ -2722,7 +2716,7 @@ static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats)
 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) {
@@ -3054,7 +3048,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Scene *scene, Object *ob, Dy
        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);
        numOfVerts_p = dm_p->getNumVerts(dm_p);
        mvert_p = dm_p->getVertArray(dm_p);
        copy_m4_m4(prev_obmat, ob->obmat);
@@ -3159,9 +3153,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
                Bounds3D mesh_bb = {0};
                VolumeGrid *grid = bData->grid;
 
-               dm = CDDM_copy(brush->dm);
+               dm = CDDM_copy(brush->dm, 0);
                mvert = dm->getVertArray(dm);
-               mface = dm->getFaceArray(dm);
+               mface = dm->getTessFaceArray(dm);
                numOfVerts = dm->getNumVerts(dm);
 
                /*      Transform collider vertices to global space