svn merge ^/trunk/blender -r41226:41227 .
[blender.git] / source / blender / modifiers / intern / MOD_decimate.c
index aba68dc..f533e20 100644 (file)
@@ -82,9 +82,9 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
        int a, numTris;
 
        mvert = dm->getVertArray(dm);
-       mface = dm->getFaceArray(dm);
+       mface = dm->getTessFaceArray(dm);
        totvert = dm->getNumVerts(dm);
-       totface = dm->getNumFaces(dm);
+       totface = dm->getNumTessFaces(dm);
 
        numTris = 0;
        for (a=0; a<totface; a++) {
@@ -96,7 +96,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
        if(numTris<3) {
                modifier_setError(md,
                        "Modifier requires more than 3 input faces (triangles).");
-               goto exit;
+               dm = CDDM_copy(dm, 0);
+               return dm;
        }
 
        lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*totvert, "vertices");
@@ -140,11 +141,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
                        }
 
                        if(lod.vertex_num>2) {
-                               result = CDDM_new(lod.vertex_num, 0, lod.face_num);
+                               result = CDDM_new(lod.vertex_num, 0, lod.face_num, 0, 0);
                                dmd->faceCount = lod.face_num;
                        }
                        else
-                               result = CDDM_new(lod.vertex_num, 0, 0);
+                               result = CDDM_new(lod.vertex_num, 0, 0, 0, 0);
 
                        mvert = CDDM_get_verts(result);
                        for(a=0; a<lod.vertex_num; a++) {
@@ -155,7 +156,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
                        }
 
                        if(lod.vertex_num>2) {
-                               mface = CDDM_get_faces(result);
+                               mface = CDDM_get_tessfaces(result);
                                for(a=0; a<lod.face_num; a++) {
                                        MFace *mf = &mface[a];
                                        int *tri = &lod.triangle_index_buffer[a*3];
@@ -167,7 +168,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
                        }
 
                        CDDM_calc_edges(result);
-                       CDDM_calc_normals(result);
                }
                else
                        modifier_setError(md, "Out of memory.");
@@ -181,8 +181,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
        MEM_freeN(lod.vertex_normal_buffer);
        MEM_freeN(lod.triangle_index_buffer);
 
-exit:
-               return result;
+       dm = CDDM_copy(result, 1); /*builds ngon faces from tess (mface) faces*/
+       CDDM_calc_normals(dm);
+       result->needsFree = 1;
+       result->release(result);
+
+       return dm;
 }
 #else // WITH_MOD_DECIMATE
 static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),