[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43094] branches/bmesh/blender/source/ blender: minor changes for mirror modifier, bigger changes coming.

Campbell Barton ideasman42 at gmail.com
Tue Jan 3 10:38:07 CET 2012


Revision: 43094
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43094
Author:   campbellbarton
Date:     2012-01-03 09:37:57 +0000 (Tue, 03 Jan 2012)
Log Message:
-----------
minor changes for mirror modifier, bigger changes coming.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h
    branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c

Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h	2012-01-03 07:33:11 UTC (rev 43093)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_cdderivedmesh.h	2012-01-03 09:37:57 UTC (rev 43094)
@@ -60,7 +60,7 @@
 DerivedMesh *CDDM_from_BMEditMesh(struct BMEditMesh *em, struct Mesh *me, int use_mdisps);
 
 /* merge verts  */
-DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, int *vtargetmap);
+DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap);
 
 /* creates a CDDerivedMesh from the given curve object */
 struct DerivedMesh *CDDM_from_curve(struct Object *ob);

Modified: branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-03 07:33:11 UTC (rev 43093)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c	2012-01-03 09:37:57 UTC (rev 43094)
@@ -2279,7 +2279,7 @@
  *
  * note, CDDM_recalc_tesselation has to run on the returned DM if you want to access tessfaces.
  */
-DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, int *vtargetmap)
+DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap)
 {
 	CDDerivedMesh *cddm = (CDDerivedMesh*)dm;
 	CDDerivedMesh *cddm2 = NULL;
@@ -2336,7 +2336,7 @@
 	c = 0;
 	for (i=0; i<dm->numEdgeData; i++, med++) {
 		
-		if (med->v1 != med->v2) {
+		if (LIKELY(med->v1 != med->v2)) {
 			const unsigned int v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1;
 			const unsigned int v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2;
 			void **eh_p= BLI_edgehash_lookup_p(ehash, v1, v2);
@@ -2366,16 +2366,17 @@
 		c = 0;
 		for (j=0; j<mp->totloop; j++, ml++) {
 			med = cddm->medge + ml->e;
-			if (med->v1 != med->v2) {
+			if (LIKELY(med->v1 != med->v2)) {
+				newl[j+mp->loopstart] = BLI_array_count(mloop);
 				BLI_array_append(oldl, j+mp->loopstart);
 				BLI_array_append(mloop, *ml);
-				newl[j+mp->loopstart] = BLI_array_count(mloop)-1;
 				c++;
 			}
 		}
-		
-		if (!c)
+
+		if (UNLIKELY(c == 0)) {
 			continue;
+		}
 		
 		mp2 = BLI_array_append_r(mpoly, *mp);
 		mp2->totloop = c;

Modified: branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c
===================================================================
--- branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c	2012-01-03 07:33:11 UTC (rev 43093)
+++ branches/bmesh/blender/source/blender/modifiers/intern/MOD_mirror.c	2012-01-03 09:37:57 UTC (rev 43094)
@@ -99,7 +99,7 @@
                                    int axis)
 {
 	float tolerance_sq;
-	DerivedMesh *cddm, *origdm;
+	DerivedMesh *result, *origdm;
 	MVert *mv, *ov;
 	MEdge *me;
 	MLoop *ml;
@@ -139,18 +139,18 @@
 		mult_m4_m4m4(mtx, itmp, mtx);
 	}
 	
-	cddm = CDDM_from_template(dm, dm->numVertData*2, dm->numEdgeData*2, 0, dm->numLoopData*2, dm->numPolyData*2);
+	result = CDDM_from_template(dm, dm->numVertData*2, dm->numEdgeData*2, 0, dm->numLoopData*2, dm->numPolyData*2);
 	
 	/*copy customdata to original geometry*/
-	CustomData_copy_data(&dm->vertData, &cddm->vertData, 0, 0, dm->numVertData);
-	CustomData_copy_data(&dm->edgeData, &cddm->edgeData, 0, 0, dm->numEdgeData);
-	CustomData_copy_data(&dm->loopData, &cddm->loopData, 0, 0, dm->numLoopData);
-	CustomData_copy_data(&dm->polyData, &cddm->polyData, 0, 0, dm->numPolyData);
+	CustomData_copy_data(&dm->vertData, &result->vertData, 0, 0, dm->numVertData);
+	CustomData_copy_data(&dm->edgeData, &result->edgeData, 0, 0, dm->numEdgeData);
+	CustomData_copy_data(&dm->loopData, &result->loopData, 0, 0, dm->numLoopData);
+	CustomData_copy_data(&dm->polyData, &result->polyData, 0, 0, dm->numPolyData);
 
 	/*copy customdata to new geometry*/
-	CustomData_copy_data(&dm->vertData, &cddm->vertData, 0, dm->numVertData, dm->numVertData);
-	CustomData_copy_data(&dm->edgeData, &cddm->edgeData, 0, dm->numEdgeData, dm->numEdgeData);
-	CustomData_copy_data(&dm->polyData, &cddm->polyData, 0, dm->numPolyData, dm->numPolyData);
+	CustomData_copy_data(&dm->vertData, &result->vertData, 0, dm->numVertData, dm->numVertData);
+	CustomData_copy_data(&dm->edgeData, &result->edgeData, 0, dm->numEdgeData, dm->numEdgeData);
+	CustomData_copy_data(&dm->polyData, &result->polyData, 0, dm->numPolyData, dm->numPolyData);
 
 	if (do_vtargetmap) {
 		/* second half is filled with -1 */
@@ -161,7 +161,7 @@
 	}
 
 	/*mirror vertex coordinates*/
-	ov = CDDM_get_verts(cddm);
+	ov = CDDM_get_verts(result);
 	mv = ov + dm->numVertData;
 	for (i=0; i<dm->numVertData; i++, mv++, ov++) {
 		mul_m4_v3(mtx, mv->co);
@@ -178,30 +178,30 @@
 	}
 	
 	/*handle shape keys*/
-	totshape = CustomData_number_of_layers(&cddm->vertData, CD_SHAPEKEY);
+	totshape = CustomData_number_of_layers(&result->vertData, CD_SHAPEKEY);
 	for (a=0; a<totshape; a++) {
-		float (*cos)[3] = CustomData_get_layer_n(&cddm->vertData, CD_SHAPEKEY, a);
-		for (i=dm->numVertData; i<cddm->numVertData; i++) {
+		float (*cos)[3] = CustomData_get_layer_n(&result->vertData, CD_SHAPEKEY, a);
+		for (i=dm->numVertData; i<result->numVertData; i++) {
 			mul_m4_v3(mtx, cos[i]);
 		}
 	}
 	
 	/*adjust mirrored edge vertex indices*/
-	me = CDDM_get_edges(cddm) + dm->numEdgeData;
+	me = CDDM_get_edges(result) + dm->numEdgeData;
 	for (i=0; i<dm->numEdgeData; i++, me++) {
 		me->v1 += dm->numVertData;
 		me->v2 += dm->numVertData;
 	}
 	
 	/*adjust mirrored poly loopstart indices, and reverse loop order (normals)*/	
-	mp = CDDM_get_polys(cddm) + dm->numPolyData;
-	ml = CDDM_get_loops(cddm);
+	mp = CDDM_get_polys(result) + dm->numPolyData;
+	ml = CDDM_get_loops(result);
 	for (i=0; i<dm->numPolyData; i++, mp++) {
 		MLoop *ml2;
 		int e;
 		
 		for (j=0; j<mp->totloop; j++) {
-			CustomData_copy_data(&dm->loopData, &cddm->loopData, mp->loopstart+j,
+			CustomData_copy_data(&dm->loopData, &result->loopData, mp->loopstart+j,
 								 mp->loopstart+dm->numLoopData+mp->totloop-j-1, 1);
 		}
 		
@@ -216,7 +216,7 @@
 	}
 
 	/*adjust mirrored loop vertex and edge indices*/	
-	ml = CDDM_get_loops(cddm) + dm->numLoopData;
+	ml = CDDM_get_loops(result) + dm->numLoopData;
 	for (i=0; i<dm->numLoopData; i++, ml++) {
 		ml->v += dm->numVertData;
 		ml->e += dm->numEdgeData;
@@ -228,10 +228,10 @@
 		const int do_mirr_u= (mmd->flag & MOD_MIR_MIRROR_U) != 0;
 		const int do_mirr_v= (mmd->flag & MOD_MIR_MIRROR_V) != 0;
 
-		const int totuv = CustomData_number_of_layers(&cddm->loopData, CD_MLOOPUV);
+		const int totuv = CustomData_number_of_layers(&result->loopData, CD_MLOOPUV);
 
 		for (a=0; a<totuv; a++) {
-			MLoopUV *dmloopuv = CustomData_get_layer_n(&cddm->loopData, CD_MLOOPUV, a);
+			MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, a);
 			int j = dm->numLoopData;
 			dmloopuv += j; /* second set of loops only */
 			for ( ; i-- > 0; dmloopuv++) {
@@ -242,8 +242,8 @@
 	}
 
 	/*handle vgroup stuff*/
-	if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&cddm->vertData, CD_MDEFORMVERT)) {
-		MDeformVert *dvert = CustomData_get_layer(&cddm->vertData, CD_MDEFORMVERT);
+	if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vertData, CD_MDEFORMVERT)) {
+		MDeformVert *dvert = CustomData_get_layer(&result->vertData, CD_MDEFORMVERT);
 		int *flip_map= NULL, flip_map_len= 0;
 
 		flip_map= defgroup_flip_map(ob, &flip_map_len, FALSE);
@@ -255,18 +255,18 @@
 
 	if (do_vtargetmap) {
 		/* this calls CDDM_recalc_tesselation, so dont do twice */
-		cddm = CDDM_merge_verts(cddm, vtargetmap);
+		result = CDDM_merge_verts(result, vtargetmap);
 		MEM_freeN(vtargetmap);
 	}
 
-	CDDM_recalc_tesselation(cddm);
+	CDDM_recalc_tesselation(result);
 	
 	if (dm != origdm) {
 		dm->needsFree = 1;
 		dm->release(dm);
 	}
 	
-	return cddm;
+	return result;
 }
 
 static DerivedMesh *mirrorModifier__doMirror(MirrorModifierData *mmd,



More information about the Bf-blender-cvs mailing list