diff options
author | Christian Hubert <christian.hubert@dstribe.com> | 2018-05-11 11:55:26 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-05-11 12:12:28 +0300 |
commit | e0a41fd0ced5182bb212caf356357b75adf38336 (patch) | |
tree | 460ce282b32bcb85befdeb6982d6d7f550adba7f /source/blender/modifiers/intern/MOD_decimate.c | |
parent | 9d0d7c375e3f7675d05e412c226db8bacf270dbf (diff) |
Modifiers: ported Decimate DerivedMesh → Mesh
Two things to indicate (which als apply before the DM → M port):
- Face count in the UI is not updated and stays at 0
- When planar mode is used, the result is inverted (mirrored along X)
compared to 2.79
Reviewers: sybren
Differential Revision: https://developer.blender.org/D3303
Diffstat (limited to 'source/blender/modifiers/intern/MOD_decimate.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_decimate.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 3a7ccc44f74..b004da7df6a 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -33,15 +33,17 @@ */ #include "DNA_object_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "BLI_math.h" #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" -#include "BKE_modifier.h" #include "BKE_deform.h" -#include "BKE_cdderivedmesh.h" +#include "BKE_mesh.h" +#include "BKE_library.h" #include "bmesh.h" #include "bmesh_tools.h" @@ -77,11 +79,11 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, - DerivedMesh *derivedData) +static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, + Mesh *meshData) { DecimateModifierData *dmd = (DecimateModifierData *) md; - DerivedMesh *dm = derivedData, *result = NULL; + Mesh *mesh = meshData, *result = NULL; BMesh *bm; bool calc_face_normal; float *vweights = NULL; @@ -91,34 +93,34 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c #endif /* set up front so we dont show invalid info in the UI */ - dmd->face_count = dm->getNumPolys(dm); + dmd->face_count = mesh->totpoly; switch (dmd->mode) { case MOD_DECIM_MODE_COLLAPSE: if (dmd->percent == 1.0f) { - return dm; + return mesh; } calc_face_normal = true; break; case MOD_DECIM_MODE_UNSUBDIV: if (dmd->iter == 0) { - return dm; + return mesh; } calc_face_normal = false; break; case MOD_DECIM_MODE_DISSOLVE: if (dmd->angle == 0.0f) { - return dm; + return mesh; } calc_face_normal = true; break; default: - return dm; + return mesh; } if (dmd->face_count <= 3) { modifier_setError(md, "Modifier requires more than 3 input faces"); - return dm; + return mesh; } if (dmd->mode == MOD_DECIM_MODE_COLLAPSE) { @@ -126,10 +128,10 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c MDeformVert *dvert; int defgrp_index; - modifier_get_vgroup(ctx->object, dm, dmd->defgrp_name, &dvert, &defgrp_index); + modifier_get_vgroup_mesh(ctx->object, mesh, dmd->defgrp_name, &dvert, &defgrp_index); if (dvert) { - const unsigned int vert_tot = dm->getNumVerts(dm); + const unsigned int vert_tot = mesh->totvert; unsigned int i; vweights = MEM_malloc_arrayN(vert_tot, sizeof(float), __func__); @@ -148,7 +150,10 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c } } - bm = DM_to_bmesh(dm, calc_face_normal); + bm = BKE_mesh_to_bmesh_ex( + mesh, + &((struct BMeshCreateParams){0}), + &((struct BMeshFromMeshParams){.calc_face_normal = calc_face_normal,})); switch (dmd->mode) { case MOD_DECIM_MODE_COLLAPSE: @@ -180,7 +185,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c /* update for display only */ dmd->face_count = bm->totface; - result = CDDM_from_bmesh(bm, false); + result = BKE_bmesh_to_mesh_nomain(bm, &((struct BMeshToMeshParams){0})); BLI_assert(bm->vtoolflagpool == NULL && bm->etoolflagpool == NULL && bm->ftoolflagpool == NULL); /* make sure we never alloc'd these */ @@ -194,7 +199,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *c TIMEIT_END(decim); #endif - result->dirty = DM_DIRTY_NORMALS; + result->runtime.cd_dirty_vert |= CD_MASK_NORMAL; return result; } @@ -213,14 +218,14 @@ ModifierTypeInfo modifierType_Decimate = { /* deformMatrices_DM */ NULL, /* deformVertsEM_DM */ NULL, /* deformMatricesEM_DM*/NULL, - /* applyModifier_DM */ applyModifier, + /* applyModifier_DM */ NULL, /* applyModifierEM_DM */NULL, /* deformVerts */ NULL, /* deformMatrices */ NULL, /* deformVertsEM */ NULL, /* deformMatricesEM */ NULL, - /* applyModifier */ NULL, + /* applyModifier */ applyModifier, /* applyModifierEM */ NULL, /* initData */ initData, |