[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15754] branches/soc-2008-nicholasbishop/ source/blender/blenkernel/intern/multires.c: More speed/ memory improvements to multires update.

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 25 07:39:49 CEST 2008


Revision: 15754
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15754
Author:   nicholasbishop
Date:     2008-07-25 07:39:48 +0200 (Fri, 25 Jul 2008)

Log Message:
-----------
More speed/memory improvements to multires update.

Modified Paths:
--------------
    branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-25 03:34:05 UTC (rev 15753)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-25 05:39:48 UTC (rev 15754)
@@ -948,9 +948,16 @@
 	return final;
 }
 
-void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, int lvl, int totlvl,
-		      int totsubvert, int totsubedge, int totsubface, MVert *addverts)
+void VecAddUf(float a[3], float b[3])
 {
+	a[0] += b[0];
+	a[1] += b[1];
+	a[2] += b[2];
+}
+
+static void multires_subdisp(DerivedMesh *orig, Mesh *me, DerivedMesh *final, int lvl, int totlvl,
+			     int totsubvert, int totsubedge, int totsubface, int addverts)
+{
 	DerivedMesh *mrdm;
 	MultiresModifierData mmd_sub;
 	MVert *mvs = CDDM_get_verts(final);
@@ -971,9 +978,16 @@
 	/* Need to map from ccg to mrdm */
 	totvert = mrdm->getNumVerts(mrdm);
 
+	if(!addverts) {
+		for(i = 0; i < totvert; ++i) {
+			float z[3] = {0,0,0};
+			VecCopyf(mvd[i].co, z);
+		}
+	}
+
 	/* Load base verts */
 	for(i = 0; i < me->totvert; ++i)
-		VecCopyf(mvd[totvert - me->totvert + i].co, mvs[totvert - me->totvert + i].co);
+		VecAddUf(mvd[totvert - me->totvert + i].co, mvs[totvert - me->totvert + i].co);
 
 	mvd_f1 = mvd;
 	mvs_f1 = mvs;
@@ -994,7 +1008,7 @@
 			for(y = 0; y < sll; ++y) {
 				for(x = 0; x < sll; ++x) {
 					/* Face center */
-					VecCopyf(mvd_f1->co, mvs_f1->co);
+					VecAddUf(mvd_f1->co, mvs_f1->co);
 					mvs_f1 += 1;
 
 					/* Now we hold the center of the subface at mvd_f1
@@ -1008,7 +1022,7 @@
 						else if(k == 3) mov = -(slo2 - 2);
 
 						for(x2 = 1; x2 < skip/2; ++x2) {
-							VecCopyf((mvd_f1 + mov * x2)->co, mvs_f1->co);
+							VecAddUf((mvd_f1 + mov * x2)->co, mvs_f1->co);
 							++mvs_f1;
 						}
 					}
@@ -1024,7 +1038,7 @@
 
 						for(y2 = 1; y2 < skip/2; ++y2) {
 							for(x2 = 1; x2 < skip/2; ++x2) {
-								VecCopyf((mvd_f1 + movy * y2 + movx * x2)->co, mvs_f1->co);
+								VecAddUf((mvd_f1 + movy * y2 + movx * x2)->co, mvs_f1->co);
 								++mvs_f1;
 							}
 						}
@@ -1039,7 +1053,7 @@
 		}
 
 		/* update face center verts */
-		VecCopyf(mvd_f2->co, mvs_f2->co);
+		VecAddUf(mvd_f2->co, mvs_f2->co);
 
 		mvd_f2 += 1;
 		mvs_f2 += 1;
@@ -1050,17 +1064,17 @@
 
 			/* Super-face edge cross */
 			for(k = 0; k < skip-1; ++k) {
-				VecCopyf(mvd_f2->co, mvs_e1->co);
+				VecAddUf(mvd_f2->co, mvs_e1->co);
 				mvd_f2++;
 				mvs_e1++;
 			}
 			for(x = 1; x < sll; ++x) {
-				VecCopyf(mvd_f2->co, mvs_f2->co);
+				VecAddUf(mvd_f2->co, mvs_f2->co);
 				mvd_f2++;
 				mvs_f2++;
 
 				for(k = 0; k < skip-1; ++k) {
-					VecCopyf(mvd_f2->co, mvs_e1->co);
+					VecAddUf(mvd_f2->co, mvs_e1->co);
 					mvd_f2++;
 					mvs_e1++;
 				}
@@ -1070,7 +1084,7 @@
 			for(y = 0; y < sll - 1; ++y) {
 				for(x = 0; x < sll; ++x) {
 					for(k = 0; k < skip - 1; ++k) {
-						VecCopyf(mvd_f3[(skip-1)+(y*skip) + (x*skip+k)*(slo2-2)].co,
+						VecAddUf(mvd_f3[(skip-1)+(y*skip) + (x*skip+k)*(slo2-2)].co,
 							 mvs_e1->co);
 						++mvs_e1;
 					}
@@ -1082,7 +1096,7 @@
 			for(y = 0; y < sll - 1; ++y) {
 				for(x = 0; x < sll; ++x) {
 					for(k = 0; k < skip - 1; ++k) {
-						VecCopyf(mvd_f3[(slo2-2)*(skip-1)+(x*skip)+k + y*skip*(slo2-2)].co,
+						VecAddUf(mvd_f3[(slo2-2)*(skip-1)+(x*skip)+k + y*skip*(slo2-2)].co,
 							 mvs_e1->co);
 						++mvs_e1;
 					}
@@ -1099,7 +1113,7 @@
 			mvd_f2 += (slo2 - 1) * (skip - 1);
 			for(y = 0; y < sll - 1; ++y) {
 				for(x = 0; x < sll - 1; ++x) {
-					VecCopyf(mvd_f2->co, mvs_f2->co);
+					VecAddUf(mvd_f2->co, mvs_f2->co);
 					mvd_f2 += skip;
 					++mvs_f2;
 				}
@@ -1114,27 +1128,27 @@
 	mvs_e2 = mvs + totvert - me->totvert - me->totedge * (slo1-2);
 	for(i = 0; i < me->totedge; ++i) {
 		for(j = 0; j < skip - 1; ++j) {
-			VecCopyf(mvd_e1->co, mvs_e1->co);
+			VecAddUf(mvd_e1->co, mvs_e1->co);
 			mvd_e1++;
 			mvs_e1++;
 		}
 		for(j = 0; j < slo1 - 2; j++) {
-			VecCopyf(mvd_e1->co, mvs_e2->co);
+			VecAddUf(mvd_e1->co, mvs_e2->co);
 			mvd_e1++;
 			mvs_e2++;
 			
 			for(k = 0; k < skip - 1; ++k) {
-				VecCopyf(mvd_e1->co, mvs_e1->co);
+				VecAddUf(mvd_e1->co, mvs_e1->co);
 				mvd_e1++;
 				mvs_e1++;
 			}
 		}
 	}
 
-	if(addverts) {
+	/*if(addverts) {
 		for(i = 0; i < totvert; ++i)
 			VecAddf(mvd[i].co, mvd[i].co, addverts[i].co);
-	}
+			}*/
 
 	final->needsFree = 1;
 	final->release(final);
@@ -1204,7 +1218,7 @@
 
 		orig = CDDM_from_mesh(me, NULL);
 
-		multires_subdisp(orig, me, final, mmd->totlvl - 1, mmd->totlvl, totsubvert, totsubedge, totsubface, NULL);
+		multires_subdisp(orig, me, final, mmd->totlvl - 1, mmd->totlvl, totsubvert, totsubedge, totsubface, 0);
 
 		orig->needsFree = 1;
 		orig->release(orig);
@@ -1485,8 +1499,8 @@
 
 		if(lvl < totlvl) {
 			/* Propagate disps upwards */
-			DerivedMesh *final, *orig_top_mrdm;
-			MVert *verts_new, *orig_top_verts;
+			DerivedMesh *final;
+			MVert *verts_new;
 			MultiresModifierData mmd;
 			MVert *cur_lvl_orig_verts = NULL;
 			
@@ -1498,13 +1512,6 @@
 			cur_lvl_orig_verts = CDDM_get_verts(subco_dm);
 			d.subco = cur_lvl_orig_verts;
 
-			/* Regenerate the vertex coords at the top level using the unmodified disps */
-			mmd.totlvl = totlvl;
-			mmd.lvl = totlvl;
-			orig_top_mrdm = multires_dm_create_from_derived(&mmd, orig, me, 0, 0);
-			MultiresDM_block_update(orig_top_mrdm);
-			orig_top_verts = CDDM_get_verts(orig_top_mrdm);
-
 			/* Subtract the original vertex cos from the new vertex cos */
 			verts_new = CDDM_get_verts(dm);
 			for(i = 0; i < dm->getNumVerts(dm); ++i)
@@ -1513,8 +1520,7 @@
 			final = multires_subdisp_pre(dm, totlvl - lvl);
 
 			multires_subdisp(orig, me, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm),
-					 dm->getNumFaces(dm), orig_top_verts);
-			orig_top_mrdm->release(orig_top_mrdm);
+					 dm->getNumFaces(dm), 1);
 		}
 		else {
 			/* Regenerate the current level's vertex coordinates without displacements */





More information about the Bf-blender-cvs mailing list