[Bf-blender-cvs] [4a7653005b9] soc-2017-normal-tools: Now invalidates all loops in an lnor space

Rohan Rathi noreply at git.blender.org
Mon Jul 10 13:31:01 CEST 2017


Commit: 4a7653005b99d3f0f186f9c9f80ca979fb15d7e6
Author: Rohan Rathi
Date:   Mon Jul 10 17:00:22 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rB4a7653005b99d3f0f186f9c9f80ca979fb15d7e6

Now invalidates all loops in an lnor space

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

M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/transform/transform.c

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

diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 2e750837fb6..49b2cec754c 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -814,12 +814,7 @@ static void bm_mesh_loops_calc_normals(
 
 					if (r_lnors_spacearr) {
 						/* Assign current lnor space to current 'vertex' loop. */
-
-						/* weak fix, need to look out if breaks something. Without this 'if', wrongly builds the lnor spaces
-						   if loops are merged. */
-						if (!rebuild || !BM_elem_flag_test(lfan_pivot->v, BM_ELEM_TAG) || (bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL)) {
-							BKE_lnor_space_add_loop(r_lnors_spacearr, lnor_space, lfan_pivot_index, true);
-						}
+						BKE_lnor_space_add_loop(r_lnors_spacearr, lnor_space, lfan_pivot_index, true);
 						if (e_next != e_org) {
 							/* We store here all edges-normalized vectors processed. */
 							BLI_stack_push(edge_vectors, vec_next);
@@ -1020,28 +1015,44 @@ void BM_lnorspace_invalidate(BMesh *bm, bool inval_all)
 		bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
 		return;
 	}
+	BMFace *f;
 	BMVert *v;
+	BMLoop *l;
 	BMIter viter, fiter, liter;
 	BLI_bitmap *faces = BLI_BITMAP_NEW(bm->totface, __func__);
+	BLI_bitmap *loops_marked = BLI_BITMAP_NEW(bm->totloop, __func__);
 
 	BM_mesh_elem_index_ensure(bm, (BM_FACE | BM_LOOP));
 
 	BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
 		if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
-
-			BMFace *f;
 			BM_ITER_ELEM(f, &fiter, v, BM_FACES_OF_VERT) {
-				if (!BLI_BITMAP_TEST(faces, BM_elem_index_get(f))) {
 
-					BMLoop *l;
+				if (!BLI_BITMAP_TEST(faces, BM_elem_index_get(f))) {
 					BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
-						BM_elem_flag_enable(l, BM_ELEM_LNORSPACE);
+
+						BLI_BITMAP_ENABLE(loops_marked, BM_elem_index_get(l));		/* enable bitmaps of all loops in the spaces */
+						LinkNode *loops = bm->lnor_spacearr ? bm->lnor_spacearr->lspacearr[BM_elem_index_get(l)]->loops : NULL;
+						while (loops) {
+							const int loop_index = GET_INT_FROM_POINTER(loops->link);
+							BLI_BITMAP_ENABLE(loops_marked, loop_index);
+							loops = loops->next;
+						}
 					}
-					BLI_BITMAP_ENABLE(faces, BM_elem_index_get(f));
+					BLI_BITMAP_ENABLE(faces, BM_elem_index_get(f));		/* enable bitmap of face to not iterate through it again */
 				}
 			}
 		}
 	}
+	BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
+		BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
+			if (BLI_BITMAP_TEST(loops_marked, BM_elem_index_get(l))) {
+				BM_elem_flag_enable(l, BM_ELEM_LNORSPACE);				/* flag all loops marked */
+			}
+		}
+	}
+
+	MEM_freeN(loops_marked);
 	MEM_freeN(faces);
 	bm->spacearr_dirty |= BM_SPACEARR_DIRTY;
 }
@@ -1157,11 +1168,11 @@ static void BM_lnorspace_err(BMesh *bm)
 
 	for (int i = 0; i < bm->totloop; i++) {
 		int j = 0;
-		j += compare_ff(temp->lspacearr[i]->ref_alpha, bm->lnor_spacearr->lspacearr[i]->ref_alpha, 1.0f - 1e-4f);
-		j += compare_ff(temp->lspacearr[i]->ref_beta, bm->lnor_spacearr->lspacearr[i]->ref_beta, 1.0f - 1e-4f);
-		j += compare_v3v3(temp->lspacearr[i]->vec_lnor, bm->lnor_spacearr->lspacearr[i]->vec_lnor, 1.0f - 1e-4f);
-		j += compare_v3v3(temp->lspacearr[i]->vec_ortho, bm->lnor_spacearr->lspacearr[i]->vec_ortho, 1.0f - 1e-4f);
-		j += compare_v3v3(temp->lspacearr[i]->vec_ref, bm->lnor_spacearr->lspacearr[i]->vec_ref, 1.0f - 1e-4f);
+		j += compare_ff(temp->lspacearr[i]->ref_alpha, bm->lnor_spacearr->lspacearr[i]->ref_alpha, 1e-4f);
+		j += compare_ff(temp->lspacearr[i]->ref_beta, bm->lnor_spacearr->lspacearr[i]->ref_beta, 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_lnor, bm->lnor_spacearr->lspacearr[i]->vec_lnor, 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_ortho, bm->lnor_spacearr->lspacearr[i]->vec_ortho, 1e-4f);
+		j += compare_v3v3(temp->lspacearr[i]->vec_ref, bm->lnor_spacearr->lspacearr[i]->vec_ref, 1e-4f);
 
 		if (j != 5) {
 			clear = false;
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index e85c3703adf..d1685f2fe73 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -6372,15 +6372,18 @@ static bool merge_loop_average(bContext *C, wmOperator *op, LoopNormalData *ld)
 	BMesh *bm = em->bm;
 
 	TransDataLoopNormal *tld = ld->normal;
+	BLI_SMALLSTACK_DECLARE(clnors, short *);
 
 	for (int i = 0; i < ld->totloop; i++, tld++) {
+		if (tld->loop_index == -1)
+			continue;
+
 		MLoopNorSpace *lnor_space = bm->lnor_spacearr->lspacearr[tld->loop_index];
 
 		if (lnor_space->loops) {
 
 			LinkNode *loops = lnor_space->loops;
 			float avg_normal[3] = { 0, 0, 0 };
-			BLI_SMALLSTACK_DECLARE(clnors, short *);
 			short *clnors_data;
 
 			while (loops) {
@@ -6390,7 +6393,8 @@ static bool merge_loop_average(bContext *C, wmOperator *op, LoopNormalData *ld)
 				for (int j = 0; j < ld->totloop; j++, temp++) {
 					if (loop_index == temp->loop_index) {
 						add_v3_v3(avg_normal, temp->nloc);
-						BLI_SMALLSTACK_PUSH(clnors, tld->clnors_data);
+						BLI_SMALLSTACK_PUSH(clnors, temp->clnors_data);
+						temp->loop_index == -1;
 					}
 				}
 				loops = loops->next;
@@ -6404,7 +6408,6 @@ static bool merge_loop_average(bContext *C, wmOperator *op, LoopNormalData *ld)
 				normalize_v3(avg_normal);					/* else set all clnors to this avg */
 				while ((clnors_data = BLI_SMALLSTACK_POP(clnors))) {
 					BKE_lnor_space_custom_normal_to_data(lnor_space, avg_normal, clnors_data);
-					printf("hi");
 				}
 			}
 		}
@@ -6439,7 +6442,6 @@ static bool split_loop(bContext *C, wmOperator *op, LoopNormalData *ld)
 		}
 		else if (type == SPLIT_LOOP_KEEP) {						/* else set to transdata normal computed */
 			BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[tld->loop_index], tld->nloc, tld->clnors_data);
-			printf("hi");
 		}
 	}
 	return true;
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 8242823c0fe..0088ca51338 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2409,14 +2409,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 				RNA_boolean_set(op->ptr, "preserve_clnor", false);
 			}
 			if (!all_select) {
-				if (em->bm->lnor_spacearr) {
-					BM_lnorspace_invalidate(em->bm, false);
-
-					const bool preserve_clnor = RNA_boolean_get(op->ptr, "preserve_clnor");
-					if (preserve_clnor) {
-						t->flag |= T_CLNOR_REBUILD;
-					}
+				const bool preserve_clnor = RNA_boolean_get(op->ptr, "preserve_clnor");
+				if (preserve_clnor) {
+					BM_lnorspace_update(em->bm);
+					t->flag |= T_CLNOR_REBUILD;
 				}
+				BM_lnorspace_invalidate(em->bm, false);
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list