diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_bevel.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_bevel.c | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index c746b10755e..239b479472b 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -32,17 +32,20 @@ * \ingroup modifiers */ -#include "MEM_guardedalloc.h" - #include "BLI_utildefines.h" +#include "BLI_math.h" #include "BLI_string.h" -#include "BKE_bmesh.h" #include "BKE_cdderivedmesh.h" #include "BKE_modifier.h" -#include "BKE_particle.h" +#include "BKE_tessmesh.h" +#include "BKE_mesh.h" -#include "MOD_util.h" +#include "BKE_bmesh.h" /* only for defines */ + +#include "DNA_object_types.h" + +#include "MEM_guardedalloc.h" static void initData(ModifierData *md) @@ -85,6 +88,86 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } +#define EDGE_MARK 1 + + +/* BMESH_TODO + * + * this bevel calls the operator which is missing many of the options + * which the bevel modifier in trunk has. + * - width is interpreted as percent (not distance) + * - no vertex bevel + * - no weight bevel + * + * These will need to be added to the bmesh operator. + * - campbell + * + * note: this code is very close to MOD_edgesplit.c. + * note: if 0'd code from trunk included below. + */ +static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob, + DerivedMesh *dm, + int UNUSED(useRenderParams), + int UNUSED(isFinalCalc)) +{ + BMesh *bm; + BMEditMesh *em; + DerivedMesh *cddm; + BMIter iter; + BMEdge *e; + BevelModifierData *bmd = (BevelModifierData*) md; + /* int allocsize[] = {512, 512, 2048, 512}; */ /* UNUSED */ + float threshold = cos((bmd->bevel_angle + 0.00001) * M_PI / 180.0); + + if (!CDDM_Check(dm)) { + cddm = CDDM_copy(dm, 0); + } else cddm = dm; + + em = CDDM_To_BMesh(ob, dm, NULL); + bm = em->bm; + + BM_Compute_Normals(bm); + BMO_push(bm, NULL); + + if (bmd->lim_flags & BME_BEVEL_ANGLE) { + BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { + /* check for 1 edge having 2 face users */ + BMLoop *l1, *l2; + if ( (l1= e->l) && + (l2= e->l->radial_next) != l1) + { + if (dot_v3v3(l1->f->no, l2->f->no) < threshold) { + BMO_SetFlag(bm, e, EDGE_MARK); + } + } + } + } + else { + /* crummy, is there a way just to operator on all? - campbell */ + BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { + BMO_SetFlag(bm, e, EDGE_MARK); + } + } + + BMO_CallOpf(bm, "bevel geom=%fe percent=%f", EDGE_MARK, bmd->value); + BMO_pop(bm); + BMEdit_RecalcTesselation(em); + + if (cddm != dm) { + cddm->needsFree = 1; + cddm->release(cddm); + } + + cddm = CDDM_from_BMEditMesh(em, NULL, 1); + BMEdit_Free(em); + MEM_freeN(em); + + return cddm; +} + + +#if 0 /* from trunk, see note above */ + static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), DerivedMesh *derivedData, int UNUSED(useRenderParams), @@ -116,8 +199,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), return result; } +#endif + static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, - EditMesh *UNUSED(editData), + struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData) { return applyModifier(md, ob, derivedData, 0, 1); |