[Bf-blender-cvs] [1c626f8] master: Complete fix for T45618

Antony Riakiotakis noreply at git.blender.org
Fri Jul 31 22:52:51 CEST 2015


Commit: 1c626f823db0136317ee867dde0c778ab785070c
Author: Antony Riakiotakis
Date:   Fri Jul 31 22:52:37 2015 +0200
Branches: master
https://developer.blender.org/rB1c626f823db0136317ee867dde0c778ab785070c

Complete fix for T45618

Two issues here, normal update was not happening due to own sillyness in
viewport refactor, also normal update code still used triangles.
Now reused Campbell's poly normal recalculation code.

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

M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/pbvh.c

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

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index dde0410..19c4e66 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -450,6 +450,8 @@ static void cdDM_drawFacesSolid(
 		if (BKE_pbvh_has_faces(cddm->pbvh)) {
 			float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL);
 
+			cdDM_update_normals_from_pbvh(dm);
+
 			BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
 			              setMaterial, false, false);
 			glShadeModel(GL_FLAT);
@@ -505,6 +507,7 @@ static void cdDM_drawFacesTex_common(
 	 */
 	if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) {
 		if (BKE_pbvh_has_faces(cddm->pbvh)) {
+			cdDM_update_normals_from_pbvh(dm);
 			GPU_set_tpage(NULL, false, false);
 			BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
 		}
@@ -523,8 +526,6 @@ static void cdDM_drawFacesTex_common(
 		mloopcol = dm->getLoopDataArray(dm, colType);
 	}
 
-	cdDM_update_normals_from_pbvh(dm);
-	
 	GPU_vertex_setup(dm);
 	GPU_normal_setup(dm);
 	GPU_triangle_setup(dm);
@@ -700,8 +701,6 @@ static void cdDM_drawMappedFaces(
 		}
 	}
 	else {
-		cdDM_update_normals_from_pbvh(dm);
-
 		GPU_normal_setup(dm);
 
 		if (useColors) {
@@ -880,6 +879,7 @@ static void cdDM_drawMappedFacesGLSL(
 	 */
 	if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) {
 		if (BKE_pbvh_has_faces(cddm->pbvh)) {
+			cdDM_update_normals_from_pbvh(dm);
 			setMaterial(1, &gattribs);
 			BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
 		}
@@ -887,8 +887,6 @@ static void cdDM_drawMappedFacesGLSL(
 		return;
 	}
 
-	cdDM_update_normals_from_pbvh(dm);
-
 	matnr = -1;
 	do_draw = false;
 
@@ -1149,10 +1147,9 @@ static void cdDM_drawMappedFacesMat(
 	 *       works fine for matcap
 	 */
 
-	cdDM_update_normals_from_pbvh(dm);
-
 	if (cddm->pbvh && cddm->pbvh_draw && BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH) {
 		if (BKE_pbvh_has_faces(cddm->pbvh)) {
+			cdDM_update_normals_from_pbvh(dm);
 			setMaterial(userData, 1, &gattribs);
 			BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
 		}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index e6579a3..311e928 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -44,6 +44,8 @@
 
 #include "pbvh_intern.h"
 
+#include <limits.h>
+
 #define LEAF_LIMIT 10000
 
 //#define PERFCNTRS
@@ -986,6 +988,8 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes,
 
 		if ((node->flag & PBVH_UpdateNormals)) {
 			int i, j, totface, *faces;
+			unsigned int mpoly_prev = UINT_MAX;
+			float fn[3];
 
 			faces = node->prim_indices;
 			totface = node->totprim;
@@ -997,14 +1001,18 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes,
 				    bvh->mloop[lt->tri[1]].v,
 				    bvh->mloop[lt->tri[2]].v,
 				};
-				float fn[3];
 				const int sides = 3;
 
-				normal_tri_v3(
-				        fn,
-				        bvh->verts[vtri[0]].co,
-				        bvh->verts[vtri[1]].co,
-				        bvh->verts[vtri[2]].co);
+				/* Face normal and mask */
+				if (lt->poly != mpoly_prev) {
+					const MPoly *mp = &bvh->mpoly[lt->poly];
+					BKE_mesh_calc_poly_normal(mp, &bvh->mloop[mp->loopstart], bvh->verts, fn);
+					mpoly_prev = lt->poly;
+
+					if (face_nors) {
+						copy_v3_v3(face_nors[lt->poly], fn);
+					}
+				}
 
 				for (j = 0; j < sides; ++j) {
 					int v = vtri[j];
@@ -1020,10 +1028,6 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes,
 						vnor[v][2] += fn[2];
 					}
 				}
-
-				if (face_nors) {
-					copy_v3_v3(face_nors[lt->poly], fn);
-				}
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list