[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43534] branches/bmesh/blender/source/ blender: argument to mesh_recalcTesselation to skip copying normals from polygons.

Campbell Barton ideasman42 at gmail.com
Thu Jan 19 18:52:00 CET 2012


Revision: 43534
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43534
Author:   campbellbarton
Date:     2012-01-19 17:51:52 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
argument to mesh_recalcTesselation to skip copying normals from polygons.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
    branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
    branches/bmesh/blender/source/blender/blenloader/intern/readfile.c
    branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
    branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c
    branches/bmesh/blender/source/blender/editors/object/object_add.c

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h	2012-01-19 17:51:52 UTC (rev 43534)
@@ -76,9 +76,10 @@
  * if both of the above are 0, it'll use the indices of the mpolys of the MPoly
  * data in pdata, and ignore the origindex layer altogether.
  */
-int mesh_recalcTesselation(struct CustomData *fdata, struct CustomData *ldata, 
-	struct CustomData *pdata, struct MVert *mvert, int totface, 
-	int totloop, int totpoly);
+int mesh_recalcTesselation(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata,
+                           struct MVert *mvert,
+                           int totface, int totloop, int totpoly,
+                           const int do_face_normals);
 
 /* for forwards compat only quad->tri polys to mface, skip ngons.
  */

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/DerivedMesh.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -448,7 +448,10 @@
 	/* yes, must be before _and_ after tesselate */
 	mesh_update_customdata_pointers(&tmp, TRUE);
 
-	tmp.totface = mesh_recalcTesselation(&tmp.fdata, &tmp.ldata, &tmp.pdata, tmp.mvert, tmp.totface, tmp.totloop, tmp.totpoly);
+	tmp.totface = mesh_recalcTesselation(&tmp.fdata, &tmp.ldata, &tmp.pdata,
+	                                     tmp.mvert,
+	                                     tmp.totface, tmp.totloop, tmp.totpoly,
+	                                     TRUE);
 
 	mesh_update_customdata_pointers(&tmp, TRUE);
 

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -1582,9 +1582,10 @@
 {
 	CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
 
-	dm->numTessFaceData = mesh_recalcTesselation(&dm->faceData, &dm->loopData, 
-		&dm->polyData, cddm->mvert, dm->numTessFaceData, dm->numLoopData, 
-		dm->numPolyData);
+	dm->numTessFaceData = mesh_recalcTesselation(&dm->faceData, &dm->loopData, &dm->polyData,
+	                                             cddm->mvert,
+	                                             dm->numTessFaceData, dm->numLoopData, dm->numPolyData,
+	                                             TRUE);
 
 	if (!CustomData_get_layer(&dm->faceData, CD_ORIGINDEX)) {
 		int *polyIndex = CustomData_get_layer(&dm->faceData, CD_POLYINDEX);
@@ -2255,6 +2256,7 @@
 	cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData);
 #endif
 
+
 	if (dm->numTessFaceData == 0) {
 		/* No tesselation on this mesh yet, need to calculate one */
 		CDDM_recalc_tesselation(dm);
@@ -2265,6 +2267,7 @@
 		CustomData_free_layers(&dm->faceData, CD_NORMAL, dm->numTessFaceData);
 	}
 
+
 	face_nors = MEM_mallocN(sizeof(float)*3*dm->numTessFaceData, "face_nors");
 	
 	/* calculate face normals */
@@ -2274,7 +2277,9 @@
 	                             only_face_normals);
 	
 	CustomData_add_layer(&dm->faceData, CD_NORMAL, CD_ASSIGN, 
-		face_nors, dm->numTessFaceData);
+	                     face_nors, dm->numTessFaceData);
+
+
 }
 
 /* bmesh note: this matches what we have in trunk */

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -1105,12 +1105,16 @@
 			index+= 4;
 		}
 
+		/* BMESH_TODO - why is this converting from MFaces to MPoly's then tesselating?
+		 * should just make mpolys */
+
 		make_edges(me, 0);	// all edges
 		convert_mfaces_to_mpolys(me);
 
-		me->totface = mesh_recalcTesselation(
-			&me->fdata, &me->ldata, &me->pdata,
-			me->mvert, me->totface, me->totloop, me->totpoly);
+		me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
+		                                     me->mvert,
+		                                     me->totface, me->totloop, me->totpoly,
+		                                     TRUE);
 
 		mesh_update_customdata_pointers(me, TRUE);
 	}
@@ -2212,10 +2216,13 @@
   this function recreates a tesselation.
   returns number of tesselation faces.
  */
-int mesh_recalcTesselation(CustomData *fdata, 
+int mesh_recalcTesselation(CustomData *fdata,
                            CustomData *ldata, CustomData *pdata,
                            MVert *mvert, int totface, int UNUSED(totloop),
-                           int totpoly)
+                           int totpoly,
+                           /* when teseelating to recalcilate normals after
+                            * we can skip copying here */
+                           const int do_face_nor_cpy)
 {
 
 	/* use this to avoid locking pthread for _every_ polygon
@@ -2350,13 +2357,15 @@
 
 	CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
 
-	/* If polys have a normals layer, copying that to faces can help
-	 * avoid the need to recalculate normals later */
-	if (CustomData_has_layer(pdata, CD_NORMAL)) {
-		float *pnors = CustomData_get_layer(pdata, CD_NORMAL);
-		float *fnors = CustomData_add_layer(fdata, CD_NORMAL, CD_CALLOC, NULL, totface);
-		for (i=0; i<totface; i++, fnors++) {
-			copy_v3_v3(fnors, &pnors[polyIndex[i]]);
+	if (do_face_nor_cpy) {
+		/* If polys have a normals layer, copying that to faces can help
+		 * avoid the need to recalculate normals later */
+		if (CustomData_has_layer(pdata, CD_NORMAL)) {
+			float *pnors = CustomData_get_layer(pdata, CD_NORMAL);
+			float *fnors = CustomData_add_layer(fdata, CD_NORMAL, CD_CALLOC, NULL, totface);
+			for (i=0; i<totface; i++, fnors++) {
+				copy_v3_v3(fnors, &pnors[polyIndex[i]]);
+			}
 		}
 	}
 

Modified: branches/bmesh/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/bmesh/blender/source/blender/blenloader/intern/readfile.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/blenloader/intern/readfile.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -3704,9 +3704,10 @@
 			 *    waiting until edit mode has been entered/exited, making it easier
 			 *    to recognize problems that would otherwise only show up after edits).
 			 */
-			me->totface = mesh_recalcTesselation(
-				&me->fdata, &me->ldata, &me->pdata,
-				me->mvert, me->totface, me->totloop, me->totpoly);
+			me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
+			                                     me->mvert,
+			                                     me->totface, me->totloop, me->totpoly,
+			                                     TRUE);
 
 			mesh_update_customdata_pointers(me, TRUE);
 

Modified: branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -614,9 +614,11 @@
 	}
 
 	if (dotess) {
-		me->totface= mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
-		                                    me->mvert,
-		                                    me->totface, me->totloop, me->totpoly);
+		me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata,
+		                                     me->mvert,
+		                                     me->totface, me->totloop, me->totpoly,
+		                                     /* possibly can set to FALSE here, but defaults to true */
+		                                     TRUE);
 	}
 
 	mesh_update_customdata_pointers(me, dotess);

Modified: branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -758,14 +758,11 @@
 	if(calc_edges || (mesh->totpoly && mesh->totedge == 0))
 		BKE_mesh_calc_edges(mesh, calc_edges);
 
-	mesh->totface = mesh_recalcTesselation(
-		&mesh->fdata,
-		&mesh->ldata,
-		&mesh->pdata,
-		mesh->mvert,
-		mesh->totface,
-		mesh->totloop,
-		mesh->totpoly);
+	mesh->totface = mesh_recalcTesselation(&mesh->fdata, &mesh->ldata, &mesh->pdata,
+	                                       mesh->mvert,
+	                                       mesh->totface, mesh->totloop, mesh->totpoly,
+	                                       /* calc normals right after, dont copy from polys here */
+	                                       FALSE);
 
 	mesh_update_customdata_pointers(mesh, TRUE);
 

Modified: branches/bmesh/blender/source/blender/editors/object/object_add.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/object/object_add.c	2012-01-19 17:30:29 UTC (rev 43533)
+++ branches/bmesh/blender/source/blender/editors/object/object_add.c	2012-01-19 17:51:52 UTC (rev 43534)
@@ -1371,9 +1371,7 @@
 
 			DM_to_mesh(dm, newob->data, newob);
 
-			/* re-tesselation doesn't happen automatic, calling like this is  */
-			me= newob->data;
-			me->totface = mesh_recalcTesselation(&me->fdata, &me->ldata, &me->pdata, me->mvert, me->totface, me->totloop, me->totpoly);
+			/* re-tesselation is called by DM_to_mesh */
 
 			dm->release(dm);
 			object_free_modifiers(newob);	/* after derivedmesh calls! */




More information about the Bf-blender-cvs mailing list