[Bf-blender-cvs] [a232686] temp_custom_loop_normals: Fix various little issues and some corner-cases bugs...

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


Commit: a232686bcffdd6d2cd00d05dcaaf0d72071792f6
Author: Bastien Montagne
Date:   Sun Jul 27 20:48:40 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rBa232686bcffdd6d2cd00d05dcaaf0d72071792f6

Fix various little issues and some corner-cases bugs...

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

M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/makesrna/intern/rna_mesh_api.c

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

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 633cae6..475cd83 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1195,7 +1195,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	/* 40: CD_TESSLOOPNORMAL */
 	{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
 	/* 41: CD_CUSTOMLOOPNORMAL */
-	{sizeof(float[2]), "vec3f", 1, NULL, NULL, NULL, layerInterp_clnor, NULL, NULL},
+	{sizeof(float[2]), "vec2f", 1, NULL, NULL, NULL, layerInterp_clnor, NULL, NULL},
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index e85e137..39d7f5f 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -398,10 +398,6 @@ void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3],
 void BKE_lnor_space_add_loop(MLoopsNorSpaces *lnors_spaces, MLoopNorSpace *lnor_space, const int ml_index,
                              const bool add_to_list)
 {
-	if (lnor_space == NULL) {
-		return;
-	}
-
 	lnors_spaces->lspaces[ml_index] = lnor_space;
 	if (add_to_list) {
 		BLI_linklist_prepend_arena(&lnor_space->loops, SET_INT_IN_POINTER(ml_index), lnors_spaces->mem);
@@ -456,7 +452,7 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float
 		r_clnor_data[0] = saacosf(cos_alpha) / lnor_space->ref_alpha;
 
 		/* Project custom lnor on (vec_ref, vec_ortho) plane. */
-		mul_v4_v4fl(vec, lnor_space->vec_lnor, -cos_alpha);
+		mul_v3_v3fl(vec, lnor_space->vec_lnor, -cos_alpha);
 		add_v3_v3(vec, custom_lnor);
 		normalize_v3(vec);
 
@@ -513,7 +509,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
 
 	MPoly *mp;
 	int mp_index, me_index;
-	const bool check_angle = (split_angle < (float)M_PI);
+	bool check_angle = (split_angle < (float)M_PI);
 
 	bool *sharp_verts = NULL;  /* Maybe we could use a BLI_bitmap here? */
 	MLoopsNorSpaces _lnors_spaces = {NULL};
@@ -528,7 +524,13 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
 #endif
 
 	if (check_angle) {
-		split_angle = cosf(split_angle);
+		/* When using custom loop normals, disable the angle feature! */
+		if (clnors_data) {
+			check_angle = false;
+		}
+		else {
+			split_angle = cosf(split_angle);
+		}
 	}
 
 	if (!r_lnors_spaces && clnors_data) {
@@ -596,8 +598,10 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
 	}
 
 	if (r_lnors_spaces) {
-		/* Tag vertices that have at least one sharp edge as 'sharp' (used for the lnor spaces computation). */
-		/* XXX This third loop over edges is *very* disappointing, could not find any other way yet. */
+		/* Tag vertices that have at least one sharp edge as 'sharp' (used for the lnor spaces computation).
+		/* XXX This third loop over edges is a bit disappointing, could not find any other way yet.
+		 *     Not really performance-critical anyway.
+		 */
 		for (me_index = 0; me_index < numEdges; me_index++) {
 			const int *e2l = edge_to_loops[me_index];
 			const MEdge *me = &medges[me_index];
@@ -914,10 +918,10 @@ void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *
 	 * are not (enough) equal, add sharp edges as needed.
 	 * This way, next time we run BKE_mesh_normals_loop_split(), we'll get lnor spaces/smooth fans matching
 	 * given custom lnors.
-	 * Note this code *will never* unsharpen edges!
+	 * Note this code *will never* unsharp edges!
 	 */
 	for (i = 0; i < numLoops; i++) {
-		if (!BLI_BITMAP_TEST_BOOL(done_loops, i)) {
+		if (!BLI_BITMAP_TEST_BOOL(done_loops, i) && lnors_spaces.lspaces[i]) {
 			/* Notes:
 			 *     * In case of mono-loop smooth fan, loops is NULL, so everything is fine (we have nothing to do).
 			 *     * Loops in this linklist are ordered (in reversed order compared to how they were discovered by
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 4031c7e..dd3678d 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -817,8 +817,9 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const
 void BM_mesh_loop_normals_update(BMesh *bm, const float split_angle, float (*r_lnos)[3],
                                  MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset)
 {
-	/* Tag smooth edges and set lnos from vnos when they might be completely smooth... */
-	bm_mesh_edges_sharp_tag(bm, NULL, NULL, split_angle, r_lnos);
+	/* Tag smooth edges and set lnos from vnos when they might be completely smooth...
+	 * When using custom loop normals, disable the angle feature! */
+	bm_mesh_edges_sharp_tag(bm, NULL, NULL, (cd_loop_clnors_offset == -1) ? split_angle : (float)M_PI, r_lnos);
 
 	/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
 	bm_mesh_loops_calc_normals(bm, NULL, NULL, r_lnos, r_lnors_spaces, cd_loop_clnors_offset);
@@ -835,8 +836,9 @@ void BM_loops_calc_normal_vcos(BMesh *bm, const float (*vcos)[3], const float (*
                                const float split_angle, float (*r_lnos)[3],
                                MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset)
 {
-	/* Tag smooth edges and set lnos from vnos when they might be completely smooth... */
-	bm_mesh_edges_sharp_tag(bm, vnos, fnos, split_angle, r_lnos);
+	/* Tag smooth edges and set lnos from vnos when they might be completely smooth...
+	 * When using custom loop normals, disable the angle feature! */
+	bm_mesh_edges_sharp_tag(bm, vnos, fnos, (cd_loop_clnors_offset == -1) ? split_angle : (float)M_PI, r_lnos);
 
 	/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
 	bm_mesh_loops_calc_normals(bm, vcos, fnos, r_lnos, r_lnors_spaces, cd_loop_clnors_offset);
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index d0e6ba6..2d09e54 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -170,7 +170,7 @@ static void rna_Mesh_define_normals_split_custom(Mesh *mesh, ReportList *reports
 
 	if (CustomData_has_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL)) {
 		clnors = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL);
-		memset(clnors, 0, sizeof(float[2]) * numloops);
+		memset(clnors, 0, sizeof(*clnors) * numloops);
 	}
 	else {
 		clnors = CustomData_add_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL, CD_DEFAULT, NULL, numloops);




More information about the Bf-blender-cvs mailing list