Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoward Trickey <howard.trickey@gmail.com>2019-01-03 21:39:52 +0300
committerHoward Trickey <howard.trickey@gmail.com>2019-01-03 21:39:52 +0300
commitaef01c47e6334b214520f14c72b01de99387f122 (patch)
treef8edbb1bc5cce8c3ea5a2faaffd7462f14a69fa9 /source/blender/bmesh
parentbdfc10e482c4c6724a45259c4b2f2d7cde7d26d0 (diff)
Fix T58113 Multiple problems with bevel harden normals.
Move the bevel hardening code all into bmesh_bevel.c. Based on user feedback, rewrote the bevel hardening algorithm to be more what users want. Based on user feedback, changed the UI, removing some not-useful options. Now hardening normals while beveling is enabled by a simple checkbox. Now setting face strength gives options for which faces get their face strength set.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r--source/blender/bmesh/intern/bmesh_opdefines.c16
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.h9
-rw-r--r--source/blender/bmesh/operators/bmo_bevel.c5
-rw-r--r--source/blender/bmesh/tools/bmesh_bevel.c406
-rw-r--r--source/blender/bmesh/tools/bmesh_bevel.h2
5 files changed, 240 insertions, 198 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index 519ffa5ed59..7a6cb814cc9 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1734,11 +1734,11 @@ static BMO_FlagSet bmo_enum_bevel_offset_type[] = {
{0, NULL},
};
-static BMO_FlagSet bmo_enum_bevel_harden_normal_type[] = {
- {BEVEL_HN_NONE, "NONE"},
- {BEVEL_HN_FACE, "FACE"},
- {BEVEL_HN_ADJ, "ADJACENT"},
- {BEVEL_HN_FIX_SHA, "FIXED_NORMAL_SHADING"},
+static BMO_FlagSet bmo_enum_bevel_face_strength_type[] = {
+ {BEVEL_FACE_STRENGTH_NONE, "NONE"},
+ {BEVEL_FACE_STRENGTH_NEW, "NEW"},
+ {BEVEL_FACE_STRENGTH_AFFECTED, "AFFECTED"},
+ {BEVEL_FACE_STRENGTH_ALL, "ALL"},
{0, NULL},
};
@@ -1761,15 +1761,15 @@ static BMOpDefine bmo_bevel_def = {
{"loop_slide", BMO_OP_SLOT_BOOL}, /* prefer to slide along edges to having even widths */
{"mark_seam", BMO_OP_SLOT_BOOL}, /* extend edge data to allow seams to run across bevels */
{"mark_sharp", BMO_OP_SLOT_BOOL}, /* extend edge data to allow sharp edges to run across bevels */
- {"strength", BMO_OP_SLOT_FLT}, /* strength of calculated normal in range (0, 1) for custom clnors */
- {"hnmode", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_bevel_harden_normal_type}, /* harden normals mode used in bevel, if enabled */
+ {"harden_normals", BMO_OP_SLOT_BOOL}, /* harden normals */
+ {"face_strength_mode", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM},
+ bmo_enum_bevel_face_strength_type}, /* whether to set face strength, and which faces to set if so */
{{'\0'}},
},
/* slots_out */
{{"faces.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}}, /* output faces */
{"edges.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* output edges */
{"verts.out", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}}, /* output verts */
- {"normals.out", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL}}, /* output normals per vertex for beveled edges */
{{'\0'}},
},
diff --git a/source/blender/bmesh/intern/bmesh_operators.h b/source/blender/bmesh/intern/bmesh_operators.h
index 21b356155ed..365b5eb4681 100644
--- a/source/blender/bmesh/intern/bmesh_operators.h
+++ b/source/blender/bmesh/intern/bmesh_operators.h
@@ -117,11 +117,12 @@ enum {
BEVEL_AMT_PERCENT
};
+/* Bevel face_strength_mode values: should match face_str mode enum in DNA_modifer_types.h */
enum {
- BEVEL_HN_NONE, /* Disable harden normals */
- BEVEL_HN_FACE, /* harden normals according to face area */
- BEVEL_HN_ADJ, /* harden normals according to adjacent 'beveled' faces */
- BEVEL_HN_FIX_SHA, /* Special mode to fix normal shading continuity */
+ BEVEL_FACE_STRENGTH_NONE,
+ BEVEL_FACE_STRENGTH_NEW,
+ BEVEL_FACE_STRENGTH_AFFECTED,
+ BEVEL_FACE_STRENGTH_ALL,
};
extern const BMOpDefine *bmo_opdefines[];
diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c
index 656a446d5ab..1ef8531397f 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -45,7 +45,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
const bool loop_slide = BMO_slot_bool_get(op->slots_in, "loop_slide");
const bool mark_seam = BMO_slot_bool_get(op->slots_in, "mark_seam");
const bool mark_sharp = BMO_slot_bool_get(op->slots_in, "mark_sharp");
- const int hnmode = BMO_slot_int_get(op->slots_in, "hnmode");
+ const bool harden_normals = BMO_slot_bool_get(op->slots_in, "harden_normals");
+ const int face_strength_mode = BMO_slot_int_get(op->slots_in, "face_strength_mode");
if (offset > 0) {
BMOIter siter;
@@ -71,7 +72,7 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
BM_mesh_bevel(
bm, offset, offset_type, seg, profile, vonly, false, clamp_overlap, NULL, -1, material,
- loop_slide, mark_seam, mark_sharp, hnmode, op);
+ loop_slide, mark_seam, mark_sharp, harden_normals, face_strength_mode);
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index e48616ea231..7149df7dc4e 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -34,12 +34,15 @@
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
+#include "DNA_scene_types.h"
#include "BLI_array.h"
#include "BLI_alloca.h"
#include "BLI_gsqueue.h"
+#include "BLI_linklist_stack.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
+#include "BLI_utildefines.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
@@ -167,7 +170,6 @@ typedef struct VMesh {
M_POLY, /* a simple polygon */
M_ADJ, /* "adjacent edges" mesh pattern */
M_TRI_FAN, /* a simple polygon - fan filled */
- M_QUAD_STRIP, /* a simple polygon - cut into parallel strips */
} mesh_kind;
// int _pad;
} VMesh;
@@ -186,13 +188,21 @@ typedef struct BevVert {
VMesh *vmesh; /* mesh structure for replacing vertex */
} BevVert;
+/* face classification: note depend on F_RECON > F_EDGE > F_VERT */
+typedef enum {
+ F_NONE, /* used when there is no face at all */
+ F_ORIG, /* original face, not touched */
+ F_VERT, /* face for construction aroun a vert */
+ F_EDGE, /* face for a beveled edge */
+ F_RECON, /* reconstructed original face with some new verts */
+} FKind;
+
+// static const char* fkind_names[] = {"F_NONE", "F_ORIG", "F_VERT", "F_EDGE", "F_RECON"}; /* DEBUG */
+
/* Bevel parameters and state */
typedef struct BevelParams {
- /* hash of BevVert for each vertex involved in bevel
- * GHash: (key=(BMVert *), value=(BevVert *)) */
- GHash *vert_hash;
- /* Hash set used to store resultant beveled faces for VMesh when poly is ring */
- GHash *faceHash;
+ GHash *vert_hash; /* records BevVerts made: key BMVert*, value BevVert* */
+ GHash *face_hash; /* records new faces: key BMFace*, value one of {VERT/EDGE/RECON}_POLY */
MemArena *mem_arena; /* use for all allocs while bevel runs, if we need to free we can switch to mempool */
ProfileSpacing pro_spacing; /* parameter values for evenly spaced profiles */
@@ -205,12 +215,13 @@ typedef struct BevelParams {
bool loop_slide; /* should bevel prefer to slide along edges rather than keep widths spec? */
bool limit_offset; /* should offsets be limited by collisions? */
bool offset_adjust; /* should offsets be adjusted to try to get even widths? */
- bool mark_seam;
- bool mark_sharp;
+ bool mark_seam; /* should we propagate seam edge markings? */
+ bool mark_sharp; /* should we propagate sharp edge markings? */
+ bool harden_normals; /* should we harden normals? */
const struct MDeformVert *dvert; /* vertex group array, maybe set if vertex_only */
int vertex_group; /* vertex group index, maybe set if vertex_only */
int mat_nr; /* if >= 0, material number for bevel; else material comes from adjacent faces */
- int hnmode;
+ int face_strength_mode; /* setting face strength if > 0 */
} BevelParams;
// #pragma GCC diagnostic ignored "-Wpadded"
@@ -223,8 +234,10 @@ static int bev_debug_flags = 0;
#define DEBUG_OLD_PROJ_TO_PERP_PLANE (bev_debug_flags & 2)
#define DEBUG_OLD_FLAT_MID (bev_debug_flags & 4)
+/* use the unused _BM_ELEM_TAG_ALT flag to flag the 'long' loops (parallel to beveled edge) of edge-polygons */
+#define BM_ELEM_LONG_TAG (1<<6)
-/* this flag values will get set on geom we want to return in 'out' slots for edges and verts */
+/* these flag values will get set on geom we want to return in 'out' slots for edges and verts */
#define EDGE_OUT 4
#define VERT_OUT 8
@@ -247,6 +260,18 @@ static void disable_flag_out_edge(BMesh *bm, BMEdge *bme)
BMO_edge_flag_disable(bm, bme, EDGE_OUT);
}
+static void record_face_kind(BevelParams *bp, BMFace *f, FKind fkind)
+{
+ if (bp->face_hash)
+ BLI_ghash_insert(bp->face_hash, f, POINTER_FROM_INT(fkind));
+}
+
+static FKind get_face_kind(BevelParams *bp, BMFace *f)
+{
+ void *val = BLI_ghash_lookup(bp->face_hash, f);
+ return val ? (FKind)POINTER_AS_INT(val) : F_ORIG;
+}
+
/* Are d1 and d2 parallel or nearly so? */
static bool nearly_parallel(const float d1[3], const float d2[3])
{
@@ -1678,76 +1703,166 @@ static void bevel_extend_edge_data(BevVert *bv)
} while (bcur != start);
}
-static void bevel_harden_normals_mode(BevelParams *bp, BevVert *bv, BMOperator *op)
+/*
+ * Harden normals for bevel.
+ * The desired effect is that the newly created F_EDGE and F_VERT faces appear smoothly shaded
+ * with the the normals at the boundaries with F_RECON faces matching those recon faces.
+ * And at boundaries between F_EDGE and F_VERT faces, the normals should match the F_EDGE ones.
+ * Assumes custom loop normals are in use.
+ */
+static void bevel_harden_normals(BMesh *bm, BevelParams *bp)
{
- if (bp->hnmode == BEVEL_HN_NONE)
+ BMIter liter, fiter;
+ BMFace *f;
+ BMLoop *l, *lnext, *lprev, *lprevprev, *lnextnext;
+ BMEdge *estep;
+ FKind fkind, fprevkind, fnextkind, fprevprevkind, fnextnextkind;
+ int cd_clnors_offset, l_index;
+ short *clnors;
+ float *pnorm, norm[3];
+
+ if (bp->offset == 0.0 || !bp->harden_normals)
return;
- VMesh *vm = bv->vmesh;
- BoundVert *bcur = vm->boundstart, *bstart = bcur;
-
- BMEdge *e;
- BMIter eiter;
-
- BMOpSlot *nslot = BMO_slot_get(op->slots_out, "normals.out");
- float n_final[3] = { 0.0f, 0.0f, 0.0f };
-
- if (bp->hnmode == BEVEL_HN_FACE) {
- GHash *tempfaceHash = BLI_ghash_int_new(__func__);
-
- /* Iterate through all faces of current BMVert and add their normal*face_area to n_final */
- BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) {
- if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+ /* recalculate all face and vertex normals; side effect: ensures vertex, edge, face indices */
+ BM_mesh_normals_update(bm);
- BMFace *f_a, *f_b;
- BM_edge_face_pair(e, &f_a, &f_b);
+ /* ensure that bm->lnor_spacearr has properly stored loop normals; side effect: ensures loop indices */
+ BM_lnorspace_update(bm);
+ cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
- if (f_a && !BLI_ghash_haskey(tempfaceHash, POINTER_FROM_UINT(BM_elem_index_get(f_a)))) {
- int f_area = BM_face_calc_area(f_a);
- float f_no[3];
- copy_v3_v3(f_no, f_a->no);
- mul_v3_fl(f_no, f_area);
- add_v3_v3(n_final, f_no);
- BLI_ghash_insert(tempfaceHash, POINTER_FROM_UINT(BM_elem_index_get(f_a)), NULL);
+ BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
+ fkind = get_face_kind(bp, f);
+ if (fkind == F_ORIG || fkind == F_RECON)
+ continue;
+ BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
+ estep = l->prev->e; /* causes CW walk around l->v fan */
+ lprev = BM_vert_step_fan_loop(l, &estep);
+ estep = l->e; /* causes CCW walk around l->v fan */
+ lnext = BM_vert_step_fan_loop(l, &estep);
+ fprevkind = lprev ? get_face_kind(bp, lprev->f) : F_NONE;
+ fnextkind = lnext ? get_face_kind(bp, lnext->f) : F_NONE;
+ pnorm = NULL;
+ if (fkind == F_EDGE) {
+ if (fprevkind == F_EDGE && BM_elem_flag_test(l, BM_ELEM_LONG_TAG)) {
+ add_v3_v3v3(norm, f->no, lprev->f->no);
+ pnorm = norm;
+ }
+ else if (fnextkind == F_EDGE && BM_elem_flag_test(lnext, BM_ELEM_LONG_TAG)) {
+ add_v3_v3v3(norm, f->no, lnext->f->no);
+ pnorm = norm;
+ }
+ else if (fprevkind == F_RECON && BM_elem_flag_test(l, BM_ELEM_LONG_TAG)) {
+ pnorm = lprev->f->no;
}
- if (f_b && !BLI_ghash_haskey(tempfaceHash, POINTER_FROM_UINT(BM_elem_index_get(f_b)))) {
- int f_area = BM_face_calc_area(f_b);
- float f_no[3];
- copy_v3_v3(f_no, f_b->no);
- mul_v3_fl(f_no, f_area);
- add_v3_v3(n_final, f_no);
- BLI_ghash_insert(tempfaceHash, POINTER_FROM_UINT(BM_elem_index_get(f_b)), NULL);
+ else if (fnextkind == F_RECON && BM_elem_flag_test(l->prev, BM_ELEM_LONG_TAG)) {
+ pnorm = lnext->f->no;
+ }
+ else {
+ /* printf("unexpected harden case (edge)\n"); */
}
}
- }
- BLI_ghash_free(tempfaceHash, NULL, NULL);
- normalize_v3(n_final);
- }
- else if (bp->hnmode == BEVEL_HN_ADJ) {
- BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) {
- if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
- if (e->v1 == bv->v) {
- add_v3_v3(n_final, e->v2->no);
+ else if (fkind == F_VERT) {
+ if (fprevkind == F_VERT && fnextkind == F_VERT) {
+ pnorm = l->v->no;
+ }
+ else if (fprevkind == F_RECON) {
+ pnorm = lprev->f->no;
+ }
+ else if (fnextkind == F_RECON) {
+ pnorm = lnext->f->no;
}
else {
- add_v3_v3(n_final, e->v1->no);
+ if (lprev) {
+ estep = lprev->prev->e;
+ lprevprev = BM_vert_step_fan_loop(lprev, &estep);
+ }
+ else {
+ lprevprev = NULL;
+ }
+ if (lnext) {
+ estep = lnext->e;
+ lnextnext = BM_vert_step_fan_loop(lnext, &estep);
+ }
+ else {
+ lnextnext = NULL;
+ }
+ fprevprevkind = lprevprev ? get_face_kind(bp, lprevprev->f) : F_NONE;
+ fnextnextkind = lnextnext ? get_face_kind(bp, lnextnext->f) : F_NONE;
+ if (fprevkind == F_EDGE && fprevprevkind == F_RECON) {
+ pnorm = lprevprev->f->no;
+ }
+ else if (fprevkind == F_EDGE && fnextkind == F_VERT && fprevprevkind == F_EDGE) {
+ add_v3_v3v3(norm, lprev->f->no, lprevprev->f->no);
+ pnorm = norm;
+ }
+ else if (fnextkind == F_EDGE && fprevkind == F_VERT && fnextnextkind == F_EDGE) {
+ add_v3_v3v3(norm, lnext->f->no, lnextnext->f->no);
+ pnorm = norm;
+ }
+ else {
+ /* printf("unexpected harden case (vert)\n"); */
+ }
}
}
+ if (pnorm) {
+ if (pnorm == norm)
+ normalize_v3(norm);
+ l_index = BM_elem_index_get(l);
+ clnors = BM_ELEM_CD_GET_VOID_P(l, cd_clnors_offset);
+ BKE_lnor_space_custom_normal_to_data(
+ bm->lnor_spacearr->lspacearr[l_index], pnorm, clnors);
+ }
}
- normalize_v3(n_final);
}
+}
- do {
- /* Set normals.out for vertices as computed earlier */
- if (BMO_slot_map_contains(nslot, bcur->nv.v) != true) {
-
- float *vert_normal = MEM_mallocN(sizeof(*vert_normal) * 3, __func__);
- normalize_v3_v3(vert_normal, n_final);
-
- BMO_slot_map_insert(op, nslot, bcur->nv.v, vert_normal);
+static void bevel_set_weighted_normal_face_strength(BMesh *bm, BevelParams *bp)
+{
+ BMFace *f;
+ BMIter fiter;
+ FKind fkind;
+ int strength;
+ int mode = bp->face_strength_mode;
+ bool do_set_strength;
+ const char *wn_layer_id = MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID;
+ int cd_prop_int_idx = CustomData_get_named_layer_index(&bm->pdata, CD_PROP_INT, wn_layer_id);
+
+ if (cd_prop_int_idx == -1) {
+ BM_data_layer_add_named(bm, &bm->pdata, CD_PROP_INT, wn_layer_id);
+ cd_prop_int_idx = CustomData_get_named_layer_index(&bm->pdata, CD_PROP_INT, wn_layer_id);
+ }
+ cd_prop_int_idx -= CustomData_get_layer_index(&bm->pdata, CD_PROP_INT);
+ const int cd_prop_int_offset = CustomData_get_n_offset(&bm->pdata, CD_PROP_INT, cd_prop_int_idx);
+
+ BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
+ fkind = get_face_kind(bp, f);
+ do_set_strength = true;
+ switch (fkind) {
+ case F_VERT:
+ strength = FACE_STRENGTH_WEAK;
+ do_set_strength = (mode >= BEVEL_FACE_STRENGTH_NEW);
+ break;
+ case F_EDGE:
+ strength = FACE_STRENGTH_MEDIUM;
+ do_set_strength = (mode >= BEVEL_FACE_STRENGTH_NEW);
+ break;
+ case F_RECON:
+ strength = FACE_STRENGTH_STRONG;
+ do_set_strength = (mode >= BEVEL_FACE_STRENGTH_AFFECTED);
+ break;
+ case F_ORIG:
+ strength = FACE_STRENGTH_STRONG;
+ do_set_strength = (mode == BEVEL_FACE_STRENGTH_ALL);
+ break;
+ default:
+ do_set_strength = false;
}
- bcur = bcur->next;
- } while (bcur != bstart);
+ if (do_set_strength) {
+ int *strength_ptr = BM_ELEM_CD_GET_VOID_P(f, cd_prop_int_offset);
+ *strength_ptr = strength;
+ }
+ }
}
/* Set the any_seam property for a BevVert and all its BoundVerts */
@@ -1972,22 +2087,6 @@ static void build_boundary_terminal_edge(BevelParams *bp, BevVert *bv, EdgeHalf
}
}
-#if 0
-/* Return a value that is v if v is within BEVEL_MAX_ADJUST_PCT of the spec (assumed positive),
- * else clamp to make it at most that far away from spec */
-static float clamp_adjust(float v, float spec)
-{
- float allowed_delta = spec * (BEVEL_MAX_ADJUST_PCT / 100.0f);
-
- if (v - spec > allowed_delta)
- return spec + allowed_delta;
- else if (spec - v > allowed_delta)
- return spec - allowed_delta;
- else
- return v;
-}
-#endif
-
/* Make a circular list of BoundVerts for bv, each of which has the coordinates
* of a vertex on the boundary of the beveled vertex bv->v.
* This may adjust some EdgeHalf widths, and there might have to be
@@ -3419,12 +3518,12 @@ static float snap_face_dist_squared(float *co, BMFace *f, BMEdge **r_snap_e, flo
return beste_d2;
}
-static void build_center_ngon(BMesh *bm, BevVert *bv, int mat_nr)
+static void build_center_ngon(BevelParams *bp, BMesh *bm, BevVert *bv, int mat_nr)
{
VMesh *vm = bv->vmesh;
BoundVert *v;
int i, ns2;
- BMFace *frep;
+ BMFace *frep, *f;
BMEdge *frep_e1, *frep_e2, *frep_e;
BMVert **vv = NULL;
BMFace **vf = NULL;
@@ -3456,7 +3555,8 @@ static void build_center_ngon(BMesh *bm, BevVert *bv, int mat_nr)
BLI_array_append(ve, NULL);
}
} while ((v = v->next) != vm->boundstart);
- bev_create_ngon(bm, vv, BLI_array_len(vv), vf, frep, ve, mat_nr, true);
+ f = bev_create_ngon(bm, vv, BLI_array_len(vv), vf, frep, ve, mat_nr, true);
+ record_face_kind(bp, f, F_VERT);
BLI_array_free(vv);
BLI_array_free(vf);
@@ -3496,7 +3596,7 @@ static void build_square_in_vmesh(BevelParams *bp, BMesh *bm, BevVert *bv, VMesh
for (i = 0; i < n; i++) {
mesh_vert(vm, i, ns2, ns2)->v = mesh_vert(vm, i, 0, ns2)->v;
}
- build_center_ngon(bm, bv, bp->mat_nr);
+ build_center_ngon(bp, bm, bv, bp->mat_nr);
}
}
@@ -3722,8 +3822,6 @@ static void bevel_build_rings(BevelParams *bp, BMesh *bm, BevVert *bv)
vm1 = adj_vmesh(bp, bv);
}
- bool do_fix_shading_bv = bp->faceHash != NULL;
-
/* copy final vmesh into bv->vmesh, make BMVerts and BMFaces */
vm = bv->vmesh;
for (i = 0; i < n; i++) {
@@ -3810,8 +3908,7 @@ static void bevel_build_rings(BevelParams *bp, BMesh *bm, BevVert *bv)
NULL, bme1, bme2, bme3, mat_nr);
}
}
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, r_f, NULL);
+ record_face_kind(bp, r_f, F_VERT);
}
}
} while ((v = v->next) != vm->boundstart);
@@ -3837,7 +3934,7 @@ static void bevel_build_rings(BevelParams *bp, BMesh *bm, BevVert *bv)
/* center ngon */
if (odd) {
- build_center_ngon(bm, bv, mat_nr);
+ build_center_ngon(bp, bm, bv, mat_nr);
}
}
@@ -3884,8 +3981,6 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv)
BLI_array_staticdeclare(vf, BM_DEFAULT_NGON_STACK_SIZE);
BLI_array_staticdeclare(ve, BM_DEFAULT_NGON_STACK_SIZE);
- bool do_fix_shading_bv = bp->faceHash != NULL;
-
if (bv->any_seam) {
frep = boundvert_rep_face(vm->boundstart, &frep2);
if (frep2 && frep && is_bad_uv_poly(bv, frep)) {
@@ -3931,8 +4026,7 @@ static BMFace *bevel_build_poly(BevelParams *bp, BMesh *bm, BevVert *bv)
} while ((v = v->next) != vm->boundstart);
if (n > 2) {
f = bev_create_ngon(bm, vv, n, vf, frep, ve, bp->mat_nr, true);
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, f, NULL);
+ record_face_kind(bp, f, F_VERT);
}
else {
f = NULL;
@@ -3947,7 +4041,6 @@ static void bevel_build_trifan(BevelParams *bp, BMesh *bm, BevVert *bv)
{
BMFace *f;
BLI_assert(next_bev(bv, NULL)->seg == 1 || bv->selcount == 1);
- bool do_fix_shading_bv = bp->faceHash != NULL;
f = bevel_build_poly(bp, bm, bv);
@@ -3956,11 +4049,6 @@ static void bevel_build_trifan(BevelParams *bp, BMesh *bm, BevVert *bv)
BMLoop *l_fan = BM_FACE_FIRST_LOOP(f)->prev;
BMVert *v_fan = l_fan->v;
- if (f->len == 3) {
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, f, NULL);
- }
-
while (f->len > 3) {
BMLoop *l_new;
BMFace *f_new;
@@ -3981,56 +4069,7 @@ static void bevel_build_trifan(BevelParams *bp, BMesh *bm, BevVert *bv)
else if (l_fan->prev->v == v_fan) { l_fan = l_fan->prev; }
else { BLI_assert(0); }
}
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, f_new, NULL);
- }
- }
-}
-
-static void bevel_build_quadstrip(BevelParams *bp, BMesh *bm, BevVert *bv)
-{
- BMFace *f;
- BLI_assert(bv->selcount == 2);
- bool do_fix_shading_bv = bp->faceHash != NULL;
-
- f = bevel_build_poly(bp, bm, bv);
-
- if (f) {
- /* we have a polygon which we know starts at this vertex, make it into strips */
- EdgeHalf *eh_a = bv->vmesh->boundstart->elast;
- EdgeHalf *eh_b = next_bev(bv, eh_a->next); /* since (selcount == 2) we know this is valid */
- BMLoop *l_a = BM_face_vert_share_loop(f, eh_a->rightv->nv.v);
- BMLoop *l_b = BM_face_vert_share_loop(f, eh_b->leftv->nv.v);
- int split_count = bv->vmesh->seg + 1; /* ensure we don't walk past the segments */
-
- if (f->len == 4) {
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, f, NULL);
- }
-
- while (f->len > 4 && split_count > 0) {
- BMLoop *l_new;
- BLI_assert(l_a->f == f);
- BLI_assert(l_b->f == f);
-
- if (l_a-> v == l_b->v || l_a->next == l_b) {
- /* l_a->v and l_b->v can be the same or such that we'd make a 2-vertex poly */
- l_a = l_a->prev;
- l_b = l_b->next;
- }
- else {
- BM_face_split(bm, f, l_a, l_b, &l_new, NULL, false);
- f = l_new->f;
- flag_out_edge(bm, l_new->e);
-
- /* walk around the new face to get the next verts to split */
- l_a = l_new->prev;
- l_b = l_new->next->next;
-
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, f, NULL);
- }
- split_count--;
+ record_face_kind(bp, f_new, F_VERT);
}
}
}
@@ -4091,13 +4130,6 @@ static void bevel_vert_two_edges(BevelParams *bp, BMesh *bm, BevVert *bv)
flag_out_edge(bm, bme);
}
}
- else if (bp->faceHash) {
- BMFace *f;
- BMIter fiter;
- BM_ITER_ELEM(f, &fiter, bv->v, BM_FACES_OF_VERT) {
- BLI_ghash_insert(bp->faceHash, f, NULL);
- }
- }
}
/* Given that the boundary is built, now make the actual BMVerts
@@ -4200,9 +4232,6 @@ static void build_vmesh(BevelParams *bp, BMesh *bm, BevVert *bv)
case M_TRI_FAN:
bevel_build_trifan(bp, bm, bv);
break;
- case M_QUAD_STRIP:
- bevel_build_quadstrip(bp, bm, bv);
- break;
}
}
@@ -4827,6 +4856,7 @@ static bool bev_rebuild_polygon(BMesh *bm, BevelParams *bp, BMFace *f)
/* don't select newly or return created boundary faces... */
if (f_new) {
+ record_face_kind(bp, f_new, F_RECON);
BM_elem_flag_disable(f_new, BM_ELEM_TAG);
/* Also don't want new edges that aren't part of a new bevel face */
BM_ITER_ELEM(bme, &eiter, f_new, BM_EDGES_OF_FACE) {
@@ -5016,11 +5046,11 @@ static void bevel_build_edge_polygons(BMesh *bm, BevelParams *bp, BMEdge *bme)
BMVert *verts[4];
BMFace *faces[4];
BMEdge *edges[4];
+ BMLoop *l;
+ BMIter iter;
int k, nseg, i1, i2, odd, mid;
int mat_nr = bp->mat_nr;
- bool do_fix_shading_bv = bp->faceHash != NULL;
-
if (!BM_edge_is_manifold(bme))
return;
@@ -5102,8 +5132,12 @@ static void bevel_build_edge_polygons(BMesh *bm, BevelParams *bp, BMEdge *bme)
f = (k <= mid) ? f1 : f2;
r_f = bev_create_ngon(bm, verts, 4, NULL, f, NULL, mat_nr, true);
}
- if (do_fix_shading_bv)
- BLI_ghash_insert(bp->faceHash, r_f, NULL);
+ record_face_kind(bp, r_f, F_EDGE);
+ /* tag the long edges: those out of verts[0] and verts[2] */
+ BM_ITER_ELEM(l, &iter, r_f, BM_LOOPS_OF_FACE) {
+ if (l->v == verts[0] || l->v == verts[2])
+ BM_elem_flag_enable(l, BM_ELEM_LONG_TAG);
+ }
verts[0] = verts[3];
verts[1] = verts[2];
}
@@ -5137,7 +5171,6 @@ static void bevel_build_edge_polygons(BMesh *bm, BevelParams *bp, BMEdge *bme)
}
}
-
/* Find xnew > x0 so that distance((x0,y0), (xnew, ynew)) = dtarget.
* False position Illinois method used because the function is somewhat linear
* -> linear interpolation converges fast.
@@ -5644,18 +5677,17 @@ void BM_mesh_bevel(
const bool vertex_only, const bool use_weights, const bool limit_offset,
const struct MDeformVert *dvert, const int vertex_group, const int mat,
const bool loop_slide, const bool mark_seam, const bool mark_sharp,
- const int hnmode, void *mod_bmop_customdata)
+ const bool harden_normals, const int face_strength_mode)
{
- BMIter iter;
+ BMIter iter, liter;
BMVert *v, *v_next;
BMEdge *e;
+ BMFace *f;
+ BMLoop *l;
BevVert *bv;
BevelParams bp = {NULL};
GHashIterator giter;
- BMOperator *op = NULL;
- BevelModNorEditData *clnordata;
-
bp.offset = offset;
bp.offset_type = offset_type;
bp.seg = segments;
@@ -5670,8 +5702,9 @@ void BM_mesh_bevel(
bp.mat_nr = mat;
bp.mark_seam = mark_seam;
bp.mark_sharp = mark_sharp;
- bp.hnmode = hnmode;
- bp.faceHash = NULL;
+ bp.harden_normals = harden_normals;
+ bp.face_strength_mode = face_strength_mode;
+ bp.face_hash = NULL;
if (profile >= 0.950f) { /* r ~ 692, so PRO_SQUARE_R is 1e4 */
bp.pro_super_r = PRO_SQUARE_R;
@@ -5684,15 +5717,8 @@ void BM_mesh_bevel(
BLI_memarena_use_calloc(bp.mem_arena);
set_profile_spacing(&bp);
- /* Stores BMOp if executed through tool else stores BevelModNorEditData */
- if (bm->use_toolflags)
- op = mod_bmop_customdata;
- else {
- clnordata = mod_bmop_customdata;
- clnordata->faceHash = BLI_ghash_ptr_new(__func__);
- BLI_ghash_flag_set(clnordata->faceHash, GHASH_FLAG_ALLOW_DUPES);
- bp.faceHash = clnordata->faceHash;
- }
+ bp.face_hash = BLI_ghash_ptr_new(__func__);
+ BLI_ghash_flag_set(bp.face_hash, GHASH_FLAG_ALLOW_DUPES);
/* Analyze input vertices, sorting edges and assigning initial new vertex positions */
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -5742,9 +5768,6 @@ void BM_mesh_bevel(
GHASH_ITER(giter, bp.vert_hash) {
bv = BLI_ghashIterator_getValue(&giter);
bevel_extend_edge_data(bv);
- if (bm->use_toolflags) {
- bevel_harden_normals_mode(&bp, bv, op);
- }
}
/* Rebuild face polygons around affected vertices */
@@ -5762,6 +5785,13 @@ void BM_mesh_bevel(
}
}
+ if (bp.harden_normals) {
+ bevel_harden_normals(bm, &bp);
+ }
+ if (bp.face_strength_mode != BEVEL_FACE_STRENGTH_NONE) {
+ bevel_set_weighted_normal_face_strength(bm, &bp);
+ }
+
/* When called from operator (as opposed to modifier), bm->use_toolflags
* will be set, and we to transfer the oflags to BM_ELEM_TAGs */
if (bm->use_toolflags) {
@@ -5776,8 +5806,18 @@ void BM_mesh_bevel(
}
}
+ /* clear the BM_ELEM_LONG_TAG tags, which were only set on some edges in F_EDGE faces */
+ BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) {
+ if (get_face_kind(&bp, f) != F_EDGE)
+ continue;
+ BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
+ BM_elem_flag_disable(l, BM_ELEM_LONG_TAG);
+ }
+ }
+
/* primary free */
BLI_ghash_free(bp.vert_hash, NULL, NULL);
+ BLI_ghash_free(bp.face_hash, NULL, NULL);
BLI_memarena_free(bp.mem_arena);
}
}
diff --git a/source/blender/bmesh/tools/bmesh_bevel.h b/source/blender/bmesh/tools/bmesh_bevel.h
index f8a77d431cc..2bfa2be8f1c 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.h
+++ b/source/blender/bmesh/tools/bmesh_bevel.h
@@ -34,6 +34,6 @@ void BM_mesh_bevel(
const float profile, const bool vertex_only, const bool use_weights,
const bool limit_offset, const struct MDeformVert *dvert, const int vertex_group,
const int mat, const bool loop_slide, const bool mark_seam, const bool mark_sharp,
- const int hnmode, void *mod_bmop_customdata);
+ const bool harden_normals, const int face_strength_mode);
#endif /* __BMESH_BEVEL_H__ */