[Bf-blender-cvs] [02312cc] temp_custom_loop_normals: Fix `BKE_mesh_has_custom_loop_normals` in Edit mode, get rid of some debug prints, various minor tweaks.

Bastien Montagne noreply at git.blender.org
Wed Aug 6 21:36:49 CEST 2014


Commit: 02312cc6973cec3ec8fcb7b026ee0514e8ac4c9f
Author: Bastien Montagne
Date:   Thu Jul 31 17:10:29 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rB02312cc6973cec3ec8fcb7b026ee0514e8ac4c9f

Fix `BKE_mesh_has_custom_loop_normals` in Edit mode, get rid of some debug prints, various minor tweaks.

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/editderivedmesh.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/editors/mesh/mesh_data.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 85e8aa5..7fff22b 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -37,6 +37,7 @@ struct DispList;
 struct EdgeHash;
 struct ListBase;
 struct LinkNode;
+struct BLI_Stack;
 struct MemArena;
 struct BMEditMesh;
 struct BMesh;
@@ -182,10 +183,9 @@ void BKE_mesh_loop_tangents_ex(
 void BKE_mesh_loop_tangents(
         struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
 
-/* XXX This is ugly! */
+/* XXX This is ugly! But other solution is to include those in each file using BKE_mesh.h :/ */
 #include "BLI_linklist.h"
 #include "BLI_memarena.h"
-#include "BLI_stack.h"
 
 typedef struct MLoopNorSpace {
 	float vec_lnor[3];   /* Automatically computed loop normal. */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 87383ca..ffa04be 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -2511,6 +2511,8 @@ void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
 	CDDM_calc_loop_normals_spaces(dm, split_angle, NULL);
 }
 
+//#define DEBUG_CLNORS
+
 void CDDM_calc_loop_normals_spaces(DerivedMesh *dm, const float split_angle, MLoopsNorSpaces *r_lnors_spaces)
 {
 	MVert *mverts = dm->getVertArray(dm);
@@ -2554,7 +2556,7 @@ void CDDM_calc_loop_normals_spaces(DerivedMesh *dm, const float split_angle, MLo
 		BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
 		                            mpolys, (const float (*)[3])pnors, numPolys, split_angle,
 		                            r_lnors_spaces, clnor_data, NULL);
-#if 0
+#ifdef DEBUG_CLNORS
 		if (r_lnors_spaces) {
 			int i;
 			for (i = 0; i < numLoops; i++) {
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 65aee87..fb8bd22 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -206,33 +206,12 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
 		float (*clnors_data)[2] = dm->getLoopDataArray(dm, CD_CUSTOMLOOPNORMAL);
 		const int cd_loop_clnors_offset = clnors_data ? -1 : CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
 
-#ifdef DEBUG_CLNORS
-		const int numLoops = dm->getNumLoops(dm);
-		float (*clnor_data)[2] = NULL;
-		/* XXX All this is really dirty!!! */
-		if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
-			float (*clnor)[2] = clnor_data = MEM_mallocN(sizeof(float[2]) * (size_t)numLoops, __func__);
-			BMIter iter;
-			BMFace *efa;
-
-			BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
-				BMLoop *l_iter, *l_first;
-				l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
-				do {
-					copy_v2_v2(*clnor, CustomData_bmesh_get(ldata, l_iter->head.data, CD_CUSTOMLOOPNORMAL));
-					++clnor;
-				} while ((l_iter = l_iter->next) != l_first);
-			}
-		}
-#endif
-
 		BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos,
 		                          r_lnors_spaces, clnors_data, cd_loop_clnors_offset);
 #ifdef DEBUG_CLNORS
 		if (r_lnors_spaces) {
 			int i;
 			for (i = 0; i < numLoops; i++) {
-				//if (i != 1) continue;
 				if (r_lnors_spaces->lspaces[i]->ref_alpha != 0.0f) {
 					LinkNode *loops = r_lnors_spaces->lspaces[i]->loops;
 					printf("Loop %d uses lnor space %p:\n", i, r_lnors_spaces->lspaces[i]);
@@ -253,8 +232,6 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
 				}
 			}
 		}
-
-		MEM_SAFE_FREE(clnor_data);
 #endif
 	}
 }
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 7842002..213f7c4 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -416,7 +416,12 @@ void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
 
 bool BKE_mesh_has_custom_loop_normals(Mesh *me)
 {
-	return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
+	if (me->edit_btmesh) {
+		return CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_CUSTOMLOOPNORMAL);
+	}
+	else {
+		return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
+	}
 }
 
 /* Note: unlinking is called when me->id.us is 0, question remains how
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 04fe85b..0e5c69a 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -46,6 +46,7 @@
 #include "BLI_linklist.h"
 #include "BLI_linklist_stack.h"
 #include "BLI_alloca.h"
+#include "BLI_stack.h"
 
 #include "BKE_customdata.h"
 #include "BKE_mesh.h"
@@ -336,7 +337,7 @@ MLoopNorSpace *BKE_lnor_space_create(MLoopsNorSpaces *lnors_spaces)
 
 /* Should only be called once.
  * Beware, this modifies ref_vec and other_vec in place!
- * Might set *lnor_space to NULL in case no valid space can be generated.
+ * In case no valid space can be generated, ref_alpha and ref_beta are set to zero (which means 'use auto lnors').
  */
 void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3],
                            float vec_ref[3], float vec_other[3], BLI_Stack *edge_vectors)
@@ -364,7 +365,7 @@ void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3],
 		while (!BLI_stack_is_empty(edge_vectors)) {
 			BLI_stack_pop(edge_vectors, vec);
 			alpha += saacosf(dot_v3v3(vec, lnor));
-			++nbr;
+			nbr++;
 		}
 		lnor_space->ref_alpha = alpha / (float)nbr;
 	}
@@ -434,13 +435,9 @@ void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, float r_cus
 
 void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], float r_clnor_data[2])
 {
-	print_v3("auto lnor", lnor_space->vec_lnor);
-	print_v3("custom lnor", custom_lnor);
-
 	/* We use null vector as NOP custom normal (can be simpler than giving autocomputed lnor...). */
 	if (is_zero_v3(custom_lnor) || equals_v3v3(lnor_space->vec_lnor, custom_lnor)) {
 		zero_v2(r_clnor_data);
-		printf("same nors\n");
 		return;
 	}
 
@@ -475,7 +472,6 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float
 			}
 		}
 	}
-	print_v2("encoded clnor", r_clnor_data);
 }
 
 /**
@@ -950,8 +946,6 @@ static void mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdg
 
 	BLI_SMALLSTACK_DECLARE(clnors_data, float *);
 
-	printf("%s\n", __func__);
-
 	/* Compute current lnor spaces. */
 	BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
 	                            mpolys, polynors, numPolys, split_angle, &lnors_spaces, NULL, loop_to_poly);
@@ -991,7 +985,7 @@ static void mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdg
 
 				if (fac != 1.0f) {
 					/* Note: inplace modification to get final custom lnor! */
-					interp_v3_v3v3_slerp(nor, lnors_spaces.lspaces[i]->vec_lnor, nor, fac);
+					interp_v3_v3v3_slerp_safe(nor, lnors_spaces.lspaces[i]->vec_lnor, nor, fac);
 				}
 				BLI_BITMAP_ENABLE(done_loops, i);
 			}
@@ -1005,7 +999,7 @@ static void mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdg
 
 				if (fac != 1.0f) {
 					/* Note: inplace modification to get final custom lnor! */
-					interp_v3_v3v3_slerp(nor, lnors_spaces.lspaces[lidx]->vec_lnor, nor, fac);
+					interp_v3_v3v3_slerp_safe(nor, lnors_spaces.lspaces[lidx]->vec_lnor, nor, fac);
 				}
 
 				if (!org_nor) {
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 81d2d99..a85d40d 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -34,6 +34,7 @@
 #include "BLI_linklist_stack.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_stack.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_cdderivedmesh.h"
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index ac224f5..2dce796 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -844,7 +844,6 @@ static int mesh_customdata_add_clear_custom_splitnormals_exec(bContext *C, wmOpe
 
 		if (me->edit_btmesh) {
 			BM_data_layer_add(me->edit_btmesh->bm, data, CD_CUSTOMLOOPNORMAL);
-			
 		}
 		else {
 			CustomData_add_layer(data, CD_CUSTOMLOOPNORMAL, CD_DEFAULT, NULL, me->totloop);




More information about the Bf-blender-cvs mailing list