[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43190] branches/bmesh/blender/source/ blender: rename normal calc functions.

Campbell Barton ideasman42 at gmail.com
Fri Jan 6 01:08:44 CET 2012


Revision: 43190
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43190
Author:   campbellbarton
Date:     2012-01-06 00:08:37 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
rename normal calc functions.

comparing bmesh to trunk, mesh_calc_normals() in bmesh is a much more comprehensive function, calculating mpoly,mface normals, where trunk only calculated vertex normals.

renamed:
* mesh_calc_normals() --> mesh_calc_normals_mapping_ex
* mesh_calc_tessface_normals --> mesh_calc_normals_tessface() - only calculates normals from tessface
* added mesh_calc_normals() - only calculates normals from poltys

this way we can have mesh_calc_normals() remain fast for parts of the code which only need vertex normals to be updated.

only refactor, no func changes- didnt replace mesh_calc_normals_mapping_ex() with mesh_calc_normals() anywhere yet.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
    branches/bmesh/blender/source/blender/blenlib/intern/pbvh.c
    branches/bmesh/blender/source/blender/blenloader/intern/readfile.c
    branches/bmesh/blender/source/blender/collada/MeshImporter.cpp
    branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c
    branches/bmesh/blender/source/blender/editors/object/object_transform.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/sculpt.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/sculpt_undo.c

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h	2012-01-05 23:49:57 UTC (rev 43189)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h	2012-01-06 00:08:37 UTC (rev 43190)
@@ -123,7 +123,7 @@
 void mesh_delete_material_index(struct Mesh *me, short index);
 void mesh_set_smooth_flag(struct Object *meshOb, int enableSmooth);
 void convert_mfaces_to_mpolys(struct Mesh *mesh);
-void mesh_calc_tessface_normals(struct MVert *mverts, int numVerts,struct  MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
+void mesh_calc_normals_tessface(struct MVert *mverts, int numVerts,struct  MFace *mfaces, int numFaces, float (*faceNors_r)[3]);
 
 /*used for unit testing; compares two meshes, checking only
   differences we care about.  should be usable with leaf's
@@ -143,15 +143,21 @@
 	/* Calculate vertex and face normals, face normals are returned in *faceNors_r if non-NULL
 	 * and vertex normals are stored in actual mverts.
 	 */
-void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MLoop *mloop, 
-	struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
-	struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
+void mesh_calc_normals_mapping(
+        struct MVert *mverts, int numVerts,
+        struct MLoop *mloop, struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+        struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3]);
 	/* extended version of 'mesh_calc_normals' with option not to calc vertex normals */
-void mesh_calc_normals_ex(struct MVert *mverts, int numVerts, struct MLoop *mloop,
-	struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
-	struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
-	const short only_face_normals);
+void mesh_calc_normals_mapping_ex(
+        struct MVert *mverts, int numVerts, struct MLoop *mloop,
+        struct MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+        struct MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
+        const short only_face_normals);
 
+void mesh_calc_normals(
+        struct MVert *mverts, int numVerts, struct MLoop *mloop,
+        struct MPoly *mpolys, int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3]);
+
 	/* Return a newly MEM_malloc'd array of all the mesh vertex locations
 	 * (_numVerts_r_ may be NULL) */
 float (*mesh_getVertexCos(struct Mesh *me, int *numVerts_r))[3];

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-05 23:49:57 UTC (rev 43189)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-06 00:08:37 UTC (rev 43190)
@@ -2258,7 +2258,7 @@
 	face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors");
 	
 	/* calculate face normals */
-	mesh_calc_normals_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
+	mesh_calc_normals_mapping_ex(cddm->mvert, dm->numVertData, CDDM_get_loops(dm), CDDM_get_polys(dm),
 	                     dm->numLoopData, dm->numPolyData, NULL, cddm->mface, dm->numTessFaceData,
 	                     CustomData_get_layer(&dm->faceData, CD_POLYINDEX), face_nors,
 	                     only_face_normals);

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-05 23:49:57 UTC (rev 43189)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-06 00:08:37 UTC (rev 43190)
@@ -1392,7 +1392,7 @@
 		me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
 		me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
 
-		mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
+		mesh_calc_normals_mapping(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL, NULL, 0, NULL, NULL);
 	} else {
 		me= add_mesh("Mesh");
 		DM_to_mesh(dm, me, ob);
@@ -1663,24 +1663,25 @@
 	}
 }
 
-void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
-		int numLoops, int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
-		int *origIndexFace, float (*faceNors_r)[3])
+void mesh_calc_normals_mapping(MVert *mverts, int numVerts,
+                                MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
+                                MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3])
 {
-	mesh_calc_normals_ex(mverts, numVerts, mloop, mpolys,
-	                  numLoops, numPolys, polyNors_r, mfaces, numFaces,
-	                  origIndexFace, faceNors_r, TRUE);
+	mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
+	                              numLoops, numPolys, polyNors_r, mfaces, numFaces,
+	                              origIndexFace, faceNors_r, TRUE);
 }
-void mesh_calc_normals_ex(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
-		int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3], MFace *mfaces, int numFaces,
-		int *origIndexFace, float (*faceNors_r)[3],
-		const short only_face_normals)
+
+void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts,
+                                   MLoop *mloop, MPoly *mpolys,
+                                   int numLoops, int numPolys, float (*polyNors_r)[3],
+                                   MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
+                                   const short only_face_normals)
 {
 	float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r;
-	int i, j;
+	int i;
 	MFace *mf;
 	MPoly *mp;
-	MLoop *ml;
 
 	if (numPolys == 0) {
 		return;
@@ -1699,51 +1700,7 @@
 	if (only_face_normals == FALSE) {
 		/* vertex normals are optional, they require some extra calculations,
 		 * so make them optional */
-
-		float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
-		float **vertcos = NULL, **vertnos = NULL;
-		BLI_array_declare(vertcos);
-		BLI_array_declare(vertnos);
-		BLI_array_declare(edgevecbuf);
-
-		/*first go through and calculate normals for all the polys*/
-		tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
-
-		mp = mpolys;
-		for (i=0; i<numPolys; i++, mp++) {
-			mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
-			ml = mloop + mp->loopstart;
-
-			BLI_array_empty(vertcos);
-			BLI_array_empty(vertnos);
-			for (j=0; j<mp->totloop; j++) {
-				int vindex = ml[j].v;
-				BLI_array_append(vertcos, mverts[vindex].co);
-				BLI_array_append(vertnos, tnorms[vindex]);
-			}
-
-			BLI_array_empty(edgevecbuf);
-			BLI_array_growitems(edgevecbuf, mp->totloop);
-
-			accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
-		}
-
-		BLI_array_free(vertcos);
-		BLI_array_free(vertnos);
-		BLI_array_free(edgevecbuf);
-
-		/* following Mesh convention; we use vertex coordinate itself for normal in this case */
-		for(i=0; i<numVerts; i++) {
-			MVert *mv= &mverts[i];
-			float *no= tnorms[i];
-
-			if(normalize_v3(no) == 0.0f)
-				normalize_v3_v3(no, mv->co);
-
-			normal_float_to_short_v3(mv->no, no);
-		}
-
-		MEM_freeN(tnorms);
+		mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, polyNors_r);
 	}
 	else {
 		/* only calc poly normals */
@@ -1776,8 +1733,67 @@
 	
 }
 
-void mesh_calc_tessface_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3]) 
+void mesh_calc_normals(MVert *mverts, int numVerts, MLoop *mloop, MPoly *mpolys,
+                       int UNUSED(numLoops), int numPolys, float (*polyNors_r)[3])
 {
+	float (*pnors)[3] = polyNors_r;
+
+	float (*tnorms)[3], (*edgevecbuf)[3]= NULL;
+	float **vertcos = NULL, **vertnos = NULL;
+	BLI_array_declare(vertcos);
+	BLI_array_declare(vertnos);
+	BLI_array_declare(edgevecbuf);
+
+	int i, j;
+	MPoly *mp;
+	MLoop *ml;
+
+	if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c");
+
+	/*first go through and calculate normals for all the polys*/
+	tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
+
+	mp = mpolys;
+	for (i=0; i<numPolys; i++, mp++) {
+		mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
+		ml = mloop + mp->loopstart;
+
+		BLI_array_empty(vertcos);
+		BLI_array_empty(vertnos);
+		for (j=0; j<mp->totloop; j++) {
+			int vindex = ml[j].v;
+			BLI_array_append(vertcos, mverts[vindex].co);
+			BLI_array_append(vertnos, tnorms[vindex]);
+		}
+
+		BLI_array_empty(edgevecbuf);
+		BLI_array_growitems(edgevecbuf, mp->totloop);
+
+		accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
+	}
+
+	BLI_array_free(vertcos);
+	BLI_array_free(vertnos);
+	BLI_array_free(edgevecbuf);
+
+	/* following Mesh convention; we use vertex coordinate itself for normal in this case */
+	for(i=0; i<numVerts; i++) {
+		MVert *mv= &mverts[i];
+		float *no= tnorms[i];
+
+		if(normalize_v3(no) == 0.0f)
+			normalize_v3_v3(no, mv->co);
+
+		normal_float_to_short_v3(mv->no, no);
+	}
+
+	MEM_freeN(tnorms);
+
+	if (pnors != polyNors_r) MEM_freeN(pnors);
+}
+
+void mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
+{
 	float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
 	float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
 	int i;
@@ -2602,15 +2618,15 @@
                                          const float (*vertex_coords)[3], float normal[3])
 {
 
-	float *v1, *v2, *v3;
+	const float *v1, *v2, *v3;
 	double u[3], v[3], w[3];
 	double n[3] = {0.0, 0.0, 0.0}, l;
 	int i;
 
 	for(i = 0; i < mpoly->totloop; i++){
-		v1 = vertex_coords + loopstart[i].v;
-		v2 = vertex_coords + loopstart[(i+1)%mpoly->totloop].v;
-		v3 = vertex_coords + loopstart[(i+2)%mpoly->totloop].v;
+		v1 = (const float *)(vertex_coords + loopstart[i].v);
+		v2 = (const float *)(vertex_coords + loopstart[(i+1)%mpoly->totloop].v);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list