diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_decimate.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_decimate.c | 152 |
1 files changed, 1 insertions, 151 deletions
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 54c31148405..7bcf56a1bfc 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -32,7 +32,6 @@ * \ingroup modifiers */ - #include "DNA_meshdata_types.h" #include "BLI_math.h" @@ -48,19 +47,12 @@ #include "BKE_cdderivedmesh.h" #include "BKE_tessmesh.h" +#include "bmesh.h" -// #define USE_TIMEIT - -/* testing only! - Campbell */ -#define USE_DECIMATE_BMESH #ifdef USE_TIMEIT # include "PIL_time.h" #endif -#ifdef WITH_MOD_DECIMATE -#include "LOD_decimation.h" -#endif - #include "MOD_util.h" static void initData(ModifierData *md) @@ -78,11 +70,6 @@ static void copyData(ModifierData *md, ModifierData *target) tdmd->percent = dmd->percent; } -#ifdef WITH_MOD_DECIMATE -#ifdef USE_DECIMATE_BMESH - -#include "bmesh.h" - static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), DerivedMesh *derivedData, ModifierApplyFlag UNUSED(flag)) @@ -123,143 +110,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), return result; } -#else -static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), - DerivedMesh *derivedData, - ModifierApplyFlag UNUSED(flag)) -{ - DecimateModifierData *dmd = (DecimateModifierData *) md; - DerivedMesh *dm = derivedData, *result = NULL; - MVert *mvert; - MFace *mface; - LOD_Decimation_Info lod; - int totvert, totface; - int a, numTris; - - // TIMEIT_START(decim); - - DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */ - - mvert = dm->getVertArray(dm); - mface = dm->getTessFaceArray(dm); - totvert = dm->getNumVerts(dm); - totface = dm->getNumTessFaces(dm); - - numTris = 0; - for (a = 0; a < totface; a++) { - MFace *mf = &mface[a]; - numTris++; - if (mf->v4) numTris++; - } - - if (numTris < 3) { - modifier_setError(md, "%s", TIP_("Modifier requires more than 3 input faces (triangles)")); - dm = CDDM_copy(dm); - return dm; - } - - lod.vertex_buffer = MEM_mallocN(3 * sizeof(float) * totvert, "vertices"); - lod.vertex_normal_buffer = MEM_mallocN(3 * sizeof(float) * totvert, "normals"); - lod.triangle_index_buffer = MEM_mallocN(3 * sizeof(int) * numTris, "trias"); - lod.vertex_num = totvert; - lod.face_num = numTris; - - for (a = 0; a < totvert; a++) { - MVert *mv = &mvert[a]; - float *vbCo = &lod.vertex_buffer[a * 3]; - float *vbNo = &lod.vertex_normal_buffer[a * 3]; - - copy_v3_v3(vbCo, mv->co); - normal_short_to_float_v3(vbNo, mv->no); - } - - numTris = 0; - for (a = 0; a < totface; a++) { - MFace *mf = &mface[a]; - int *tri = &lod.triangle_index_buffer[3 * numTris++]; - tri[0] = mf->v1; - tri[1] = mf->v2; - tri[2] = mf->v3; - - if (mf->v4) { - tri = &lod.triangle_index_buffer[3 * numTris++]; - tri[0] = mf->v1; - tri[1] = mf->v3; - tri[2] = mf->v4; - } - } - - dmd->faceCount = 0; - if (LOD_LoadMesh(&lod) ) { - if (LOD_PreprocessMesh(&lod) ) { - /* we assume the decim_faces tells how much to reduce */ - - while (lod.face_num > numTris * dmd->percent) { - if (LOD_CollapseEdge(&lod) == 0) break; - } - - if (lod.vertex_num > 2) { - 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, 0, 0); - - mvert = CDDM_get_verts(result); - for (a = 0; a < lod.vertex_num; a++) { - MVert *mv = &mvert[a]; - float *vbCo = &lod.vertex_buffer[a * 3]; - - copy_v3_v3(mv->co, vbCo); - } - - if (lod.vertex_num > 2) { - 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]; - mf->v1 = tri[0]; - mf->v2 = tri[1]; - mf->v3 = tri[2]; - test_index_face(mf, NULL, 0, 3); - } - } - - CDDM_calc_edges_tessface(result); - } - else - modifier_setError(md, "%s", TIP_("Out of memory")); - - LOD_FreeDecimationData(&lod); - } - else - modifier_setError(md, "%s", TIP_("Non-manifold mesh as input")); - - MEM_freeN(lod.vertex_buffer); - MEM_freeN(lod.vertex_normal_buffer); - MEM_freeN(lod.triangle_index_buffer); - - // TIMEIT_END(decim); - - if (result) { - CDDM_tessfaces_to_faces(result); /*builds ngon faces from tess (mface) faces*/ - - return result; - } - else { - return dm; - } -} -#endif // USE_DECIMATE_BMESH -#else // WITH_MOD_DECIMATE -static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob), - DerivedMesh *derivedData, - ModifierApplyFlag UNUSED(flag)) -{ - return derivedData; -} -#endif // WITH_MOD_DECIMATE - ModifierTypeInfo modifierType_Decimate = { /* name */ "Decimate", /* structName */ "DecimateModifierData", |