basic bevel modifier working again in bmesh, closely matches the edge split modifier since it calls out to the bevel operator.

- edge angles are ok
- width is interpreted as percent

added BMESH_TODO comments with details about what needs working on.
This commit is contained in:
Campbell Barton
2011-11-28 04:19:44 +00:00
parent 9776f56a39
commit 52558fbe2e
2 changed files with 97 additions and 20 deletions

View File

@@ -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,15 +88,91 @@ 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),
int UNUSED(isFinalCalc))
{
#if 1 /*BMESH_TODO*/
(void)md;
return CDDM_copy(derivedData, 0);
#else
DerivedMesh *result;
BME_Mesh *bm;
@@ -116,9 +195,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
BME_free_mesh(bm);
CDDM_calc_normals(result);
#endif
return result;
}
#endif
static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
struct BMEditMesh *UNUSED(editData),
DerivedMesh *derivedData)

View File

@@ -36,29 +36,24 @@
/* EdgeSplit modifier: Splits edges in the mesh according to sharpness flag
* or edge angle (can be used to achieve autosmoothing) */
#include "DNA_meshdata_types.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_memarena.h"
#include "BLI_edgehash.h"
#include "BLI_math.h"
#include "BLI_array.h"
#include "BLI_smallhash.h"
#include "BLI_linklist.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "BKE_tessmesh.h"
#include "BKE_mesh.h"
#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
/* EdgeSplit */
/* EdgeSplit modifier: Splits edges in the mesh according to sharpness flag
* or edge angle (can be used to achieve autosmoothing)
*/
*
* note: this code is very close to MOD_bevel.c
*/
#define EDGE_MARK 1