[Bf-blender-cvs] [b6b185691f0] soc-2018-bevel: Code cleanup and fixes

Rohan Rathi noreply at git.blender.org
Sat Jul 21 16:02:07 CEST 2018


Commit: b6b185691f018f6b175ffb58c65418991cda75f2
Author: Rohan Rathi
Date:   Thu Jul 19 19:27:45 2018 +0530
Branches: soc-2018-bevel
https://developer.blender.org/rBb6b185691f018f6b175ffb58c65418991cda75f2

Code cleanup and fixes

===================================================================

M	source/blender/bmesh/tools/bmesh_bevel.c
M	source/blender/editors/mesh/editmesh_bevel.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/modifiers/intern/MOD_bevel.c

===================================================================

diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c
index 8a72ffc775f..bcf44ad4384 100644
--- a/source/blender/bmesh/tools/bmesh_bevel.c
+++ b/source/blender/bmesh/tools/bmesh_bevel.c
@@ -152,7 +152,7 @@ typedef struct BoundVert {
 	Profile profile;    /* edge profile between this and next BoundVert */
 	bool any_seam;      /* are any of the edges attached here seams? */
 	bool visited;       /* used during delta adjust pass */
-	int add_seam;
+	int seam_len;
 	int sharp_len;
 //	int _pad;
 } BoundVert;
@@ -1532,18 +1532,18 @@ static void snap_to_superellipsoid(float co[3], const float super_r, bool midlin
 	co[2] = z;
 }
 
-#define EDGE_DATA_CHECK(eh, flag) (BM_elem_flag_test(eh->e, flag))
+#define BEV_EXTEND_EDGE_DATA_CHECK(eh, flag) (BM_elem_flag_test(eh->e, flag))
 
 static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag, bool neg)
 {
 	EdgeHalf *e = &bv->edges[0], *efirst = &bv->edges[0];
 
-	while ((!neg && !EDGE_DATA_CHECK(e, flag) || (neg && EDGE_DATA_CHECK(e, flag)))) {
+	while ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(e, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(e, flag)))) {
 		e = e->next;
 		if (e == efirst)
 			break;
 	}
-	if ((!neg && !EDGE_DATA_CHECK(e, flag) || (neg && EDGE_DATA_CHECK(e, flag))))
+	if ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(e, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(e, flag))))
 		return;
 
 	efirst = e;
@@ -1551,17 +1551,17 @@ static void check_edge_data_seam_sharp_edges(BevVert *bv, int flag, bool neg)
 		int flag_count = 0;
 		EdgeHalf *ne = e->next;
 		
-		while ((!neg && !EDGE_DATA_CHECK(ne, flag) || (neg && EDGE_DATA_CHECK(ne, flag))) && ne != efirst) {
+		while ((!neg && !BEV_EXTEND_EDGE_DATA_CHECK(ne, flag) || (neg && BEV_EXTEND_EDGE_DATA_CHECK(ne, flag))) && ne != efirst) {
 			if (ne->is_bev)
 				flag_count++;
 			ne = ne->next;
 		}
-		if (ne == e || (ne == efirst && (!neg && !EDGE_DATA_CHECK(efirst, flag) ||
-										(neg && EDGE_DATA_CHECK(efirst, flag))))) {
+		if (ne == e || (ne == efirst && (!neg && !BEV_EXTEND_EDGE_DATA_CHECK(efirst, flag) ||
+										(neg && BEV_EXTEND_EDGE_DATA_CHECK(efirst, flag))))) {
 			break;
 		}
  		if (flag == BM_ELEM_SEAM)
-			e->rightv->add_seam = flag_count;
+			e->rightv->seam_len = flag_count;
 		else if (flag == BM_ELEM_SMOOTH)
 			e->rightv->sharp_len = flag_count;
 		e = ne;
@@ -1576,11 +1576,11 @@ static void bevel_extend_edge_data(BevVert *bv)
 	BoundVert *bcur = bv->vmesh->boundstart, *start = bcur;
 
 	do {
-		if (bcur->add_seam) {
-			if (!bv->vmesh->boundstart->add_seam && start == bv->vmesh->boundstart)
+		if (bcur->seam_len) {
+			if (!bv->vmesh->boundstart->seam_len && start == bv->vmesh->boundstart)
 				start = bcur;
 
-			int idxlen = bcur->index + bcur->add_seam;
+			int idxlen = bcur->index + bcur->seam_len;
 			for (int i = bcur->index; i < idxlen; i++) {
 				BMVert *v1 = mesh_vert(vm, i % vm->count, 0, 0)->v, *v2;
 				BMEdge *e;
@@ -1659,7 +1659,6 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B
 {
 	if (bp->hnmode == BEVEL_HN_NONE)
 		return;
-	int mode = 1;
 
 	VMesh *vm = bv->vmesh;
 	BoundVert *bcur = vm->boundstart, *bstart = bcur;
@@ -1672,7 +1671,7 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B
 	float n_final[3] = { 0.0f, 0.0f, 0.0f };
 
 	if (bp->hnmode == BEVEL_HN_FACE) {
-		GHash *faceHash = BLI_ghash_int_new(__func__);
+		GHash *tempfaceHash = BLI_ghash_int_new(__func__);
 
 		BM_ITER_ELEM(e, &eiter, bv->v, BM_EDGES_OF_VERT) {
 			if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
@@ -1680,25 +1679,25 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B
 				BMFace *f_a, *f_b;
 				BM_edge_face_pair(e, &f_a, &f_b);
 
-				if(f_a && !BLI_ghash_haskey(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)))) {
+				if(f_a && !BLI_ghash_haskey(tempfaceHash, SET_UINT_IN_POINTER(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(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)), NULL);
+					BLI_ghash_insert(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_a)), NULL);
 				}
-				if(f_b && !BLI_ghash_haskey(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)))) {
+				if(f_b && !BLI_ghash_haskey(tempfaceHash, SET_UINT_IN_POINTER(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(faceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)), NULL);
+					BLI_ghash_insert(tempfaceHash, SET_UINT_IN_POINTER(BM_elem_index_get(f_b)), NULL);
 				}
 			}
 		}
-		BLI_ghash_free(faceHash, NULL, NULL);
+		BLI_ghash_free(tempfaceHash, NULL, NULL);
 		normalize_v3(n_final);
 	}
 	else if (bp->hnmode == BEVEL_HN_ADJ) {
@@ -1718,11 +1717,11 @@ static void bevel_harden_normals_mode(BMesh *bm, BevelParams *bp, BevVert *bv, B
 	do {
 		if (BMO_slot_map_contains(nslot, bcur->nv.v) != true) {
 
-			float(*custom_normal) = MEM_callocN(sizeof(*custom_normal) * 3, __func__);
-			add_v3_v3(custom_normal, n_final);
-			normalize_v3(custom_normal);
+			float(*vert_normal) = MEM_callocN(sizeof(*vert_normal) * 3, __func__);
+			add_v3_v3(vert_normal, n_final);
+			normalize_v3(vert_normal);
 
-			BMO_slot_map_insert(op, nslot, bcur->nv.v, custom_normal);
+			BMO_slot_map_insert(op, nslot, bcur->nv.v, vert_normal);
 		}
 		bcur = bcur->next;
 	} while (bcur != bstart);
@@ -5662,6 +5661,7 @@ 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 {
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index f6b69beac71..83da84357dc 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -140,7 +140,7 @@ static void bevel_harden_normals(BMEditMesh *em, BMOperator *bmop, float face_st
 {
 	BKE_editmesh_lnorspace_update(em);
 	BM_normals_loops_edges_tag(em->bm, true);
-	int cd_clnors_offset = CustomData_get_offset(&em->bm->ldata, CD_CUSTOMLOOPNORMAL);
+	const int cd_clnors_offset = CustomData_get_offset(&em->bm->ldata, CD_CUSTOMLOOPNORMAL);
 
 	BMesh *bm = em->bm;
 	BMFace *f;
@@ -181,10 +181,12 @@ static void bevel_harden_normals(BMEditMesh *em, BMOperator *bmop, float face_st
 						else {
 							e_next = (lfan_pivot->e == e_next) ? lfan_pivot->prev->e : lfan_pivot->e;
 						}
+
 						BLI_SMALLSTACK_PUSH(loops, lfan_pivot);
 						float cur[3];
 						mul_v3_v3fl(cur, lfan_pivot->f->no, BM_face_calc_area(lfan_pivot->f));
 						add_v3_v3(cn_wght, cur);
+
 						if(BM_elem_flag_test(lfan_pivot->f, BM_ELEM_SELECT))
 							add_v3_v3(cn_unwght, cur);
 
@@ -310,7 +312,7 @@ static bool edbm_bevel_calc(wmOperator *op)
 	const bool loop_slide = RNA_boolean_get(op->ptr, "loop_slide");
 	const bool mark_seam = RNA_boolean_get(op->ptr, "mark_seam");
 	const bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
-	const float strength = RNA_float_get(op->ptr, "strength");
+	const float hn_strength = RNA_float_get(op->ptr, "strength");
 	const int hnmode = RNA_enum_get(op->ptr, "hnmode");
 
 
@@ -330,7 +332,7 @@ static bool edbm_bevel_calc(wmOperator *op)
 			"bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f clamp_overlap=%b "
 			"material=%i loop_slide=%b mark_seam=%b mark_sharp=%b strength=%f hnmode=%i",
 			BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, profile,
-			clamp_overlap, material, loop_slide, mark_seam, mark_sharp, strength, hnmode);
+			clamp_overlap, material, loop_slide, mark_seam, mark_sharp, hn_strength, hnmode);
 
 		BMO_op_exec(em->bm, &bmop);
 
@@ -342,7 +344,7 @@ static bool edbm_bevel_calc(wmOperator *op)
 		}
 
 		if(hnmode != BEVEL_HN_NONE)
-			bevel_harden_normals(em, &bmop, strength, hnmode);
+			bevel_harden_normals(em, &bmop, hn_strength, hnmode);
 
 		/* no need to de-select existing geometry */
 		if (!EDBM_op_finish(em, &bmop, op, true)) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 5e8ead09d91..fec73c267ce 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -318,7 +318,6 @@ enum {
 
 typedef struct BevelModNorEditData {
 	struct GHash *faceHash;
-	struct GHash *vert_hash;
 } BevelModNorEditData;
 
 typedef struct BevelModifierData {
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index 06c4f8c57fd..1ada8b215c5 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -108,9 +108,9 @@ static void bevel_set_weighted_normal_face_strength(BMesh *bm, Scene *scene)
 	}
 }
 
-static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn_strength, int hnmode, MDeformVert *dvert, int vgroup)
+static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, const float hn_strength, const int hnmode, MDeformVert *dvert, int vgroup)
 {
-	if (bmd->res > 20)
+	if (bmd->res > 20 || bmd->value == 0)
 		return;
 
 	BM_mesh_normals_update(bm);
@@ -118,8 +118,8 @@ static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn
 	BM_normals_loops_edges_tag(bm, true);
 
 	const bool vertex_only = (bmd->flags & MOD_BEVEL_VERT) != 0;
-	int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
-	bool do_normal_to_recon = (hn_strength == 1.0f);
+	const int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
+	const bool do_normal_to_recon = (hn_strength == 1.0f);
 
 	BMFace *f;
 	BMLoop *l, *l_cur, *l_first;
@@ -127,9 +127,7 @@ static void bevel_mod_harden_normals(BevelModifierData *bmd, BMesh *bm, float hn
 	GHash *faceHash = bmd->clnordata.faceHash;
 
 	BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
-		if (!BLI_ghash_haskey(faceHash, f)) {
-			BM_elem_fla

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list