[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15752] branches/soc-2008-nicholasbishop/ source/blender/blenkernel: Reduced the multires memory usage a bit during level creation and level update .

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 25 05:13:25 CEST 2008


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

Log Message:
-----------
Reduced the multires memory usage a bit during level creation and level update.

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

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h	2008-07-25 02:49:49 UTC (rev 15751)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h	2008-07-25 03:13:16 UTC (rev 15752)
@@ -117,7 +117,7 @@
 	int type;
 	int invert;
 	float (*orco)[3];
-	float (*subco)[3];
+	struct MVert *subco;
 	float weight;
 
 	int x, y, ax, ay;

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-25 02:49:49 UTC (rev 15751)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c	2008-07-25 03:13:16 UTC (rev 15752)
@@ -1375,7 +1375,7 @@
 	data = d->grid->disps[d->y * d->sidetot + d->x];
 
 	if(d->invert)
-		VecSubf(disp, co, *d->subco);
+		VecSubf(disp, co, d->subco->co);
 	else
 		VecCopyf(disp, data);
 
@@ -1467,25 +1467,36 @@
 
 	if(mdisps) {
 		MultiresDisplacer d;
+		SubsurfModifierData smd;
 		const int lvl = MultiresDM_get_lvl(dm);
 		const int totlvl = MultiresDM_get_totlvl(dm);
 		const int gridFaces = multires_side_tot[lvl - 2] - 1;
 		const int edgeSize = multires_side_tot[lvl - 1] - 1;
 		ListBase *map = MultiresDM_get_vert_face_map(dm);
 		Mesh *me = MultiresDM_get_mesh(dm);
+		DerivedMesh *orig, *subco_dm;
 		int S, x, y;
 		
 		mvert = CDDM_get_verts(dm);
 		medge = MultiresDM_get_mesh(dm)->medge;
 		mface = MultiresDM_get_mesh(dm)->mface;
 
-		d.subco = MultiresDM_get_subco(dm);
+		orig = CDDM_from_mesh(me, NULL);
 
 		if(lvl < totlvl) {
 			/* Propagate disps upwards */
-			DerivedMesh *orig = CDDM_from_mesh(me, NULL), *orig_mrdm, *final, *orig_top_mrdm;
+			DerivedMesh *final, *orig_top_mrdm;
+			MVert *verts_new, *orig_top_verts;
 			MultiresModifierData mmd;
-			MVert *verts_orig, *verts_new, *orig_top_verts;
+			MVert *cur_lvl_orig_verts = NULL;
+			
+			/* Regenerate the current level's vertex coordinates without sculpting */
+			mmd.totlvl = totlvl;
+			mmd.lvl = lvl;
+			subco_dm = multires_dm_create_from_derived(&mmd, orig, me, 0, 0);
+			MultiresDM_block_update(subco_dm);
+			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;
@@ -1494,96 +1505,90 @@
 			MultiresDM_block_update(orig_top_mrdm);
 			orig_top_verts = CDDM_get_verts(orig_top_mrdm);
 
-			/* Regenerate the current level as a MultiresDM using the unmodified disps */
-			mmd.totlvl = totlvl;
-			mmd.lvl = lvl;
-			orig_mrdm = multires_dm_create_from_derived(&mmd, orig, me, 0, 0);
-			MultiresDM_block_update(orig_mrdm);
-
 			/* Subtract the original vertex cos from the new vertex cos */
-			verts_orig = CDDM_get_verts(orig_mrdm);
 			verts_new = CDDM_get_verts(dm);
 			for(i = 0; i < dm->getNumVerts(dm); ++i)
-				VecSubf(verts_new[i].co, verts_new[i].co, verts_orig[i].co);
+				VecSubf(verts_new[i].co, verts_new[i].co, cur_lvl_orig_verts[i].co);
 
-			orig_mrdm->release(orig_mrdm);
-
 			final = multires_subdisp_pre(dm, totlvl - lvl);
 
-			// ?
-			orig->release(orig);
-			orig = CDDM_from_mesh(me, NULL);
-
 			multires_subdisp(orig, me, final, lvl, totlvl, dm->getNumVerts(dm), dm->getNumEdges(dm),
 					 dm->getNumFaces(dm), orig_top_verts);
-			orig->release(orig);
 			orig_top_mrdm->release(orig_top_mrdm);
-
-			return;
 		}
+		else {
+			/* Regenerate the current level's vertex coordinates without displacements */
+			memset(&smd, 0, sizeof(SubsurfModifierData));
+			smd.levels = lvl - 1;
+			subco_dm = subsurf_make_derived_from_derived_with_multires(orig, &smd, NULL, 0, NULL, 0, 0);
+			d.subco = CDDM_get_verts(subco_dm);
 
-		/* Update the current level */
-		for(i = 0; i < MultiresDM_get_mesh(dm)->totface; ++i) {
-			const int numVerts = mface[i].v4 ? 4 : 3;
+			/* Update the current level */
+			for(i = 0; i < MultiresDM_get_mesh(dm)->totface; ++i) {
+				const int numVerts = mface[i].v4 ? 4 : 3;
 			
-			// convert from mvert->co to disps
-			multires_displacer_init(&d, dm, i, 1);
-			multires_displacer_anchor(&d, 1, 0);
-			multires_displace(&d, mvert->co);
-			++mvert;
-			++d.subco;
+				// convert from mvert->co to disps
+				multires_displacer_init(&d, dm, i, 1);
+				multires_displacer_anchor(&d, 1, 0);
+				multires_displace(&d, mvert->co);
+				++mvert;
+				++d.subco;
 
-			for(S = 0; S < numVerts; ++S) {
-				multires_displacer_anchor(&d, 2, S);
-				for(x = 1; x < gridFaces; ++x) {
-					multires_displace(&d, mvert->co);
-					++mvert;
-					++d.subco;
-				}
-			}
-
-			for(S = 0; S < numVerts; S++) {
-				multires_displacer_anchor(&d, 3, S);
-				for(y = 1; y < gridFaces; y++) {
-					for(x = 1; x < gridFaces; x++) {
+				for(S = 0; S < numVerts; ++S) {
+					multires_displacer_anchor(&d, 2, S);
+					for(x = 1; x < gridFaces; ++x) {
 						multires_displace(&d, mvert->co);
 						++mvert;
 						++d.subco;
 					}
-					multires_displacer_jump(&d);
 				}
-			}
-		}
 
-		for(i = 0; i < MultiresDM_get_mesh(dm)->totedge; ++i) {
-			const MEdge *e = &medge[i];
-			for(x = 1; x < edgeSize; ++x) {
-				IndexNode *n1, *n2;
-				/* TODO: Better to have these loops outside the x loop */
-				for(n1 = map[e->v1].first; n1; n1 = n1->next) {
-					for(n2 = map[e->v2].first; n2; n2 = n2->next) {
-						if(n1->index == n2->index) {
-							multires_displacer_init(&d, dm, n1->index, 1);
-							multires_displacer_anchor_edge(&d, e->v1, e->v2, x);
+				for(S = 0; S < numVerts; S++) {
+					multires_displacer_anchor(&d, 3, S);
+					for(y = 1; y < gridFaces; y++) {
+						for(x = 1; x < gridFaces; x++) {
 							multires_displace(&d, mvert->co);
+							++mvert;
+							++d.subco;
 						}
+						multires_displacer_jump(&d);
 					}
 				}
+			}
+
+			for(i = 0; i < MultiresDM_get_mesh(dm)->totedge; ++i) {
+				const MEdge *e = &medge[i];
+				for(x = 1; x < edgeSize; ++x) {
+					IndexNode *n1, *n2;
+					/* TODO: Better to have these loops outside the x loop */
+					for(n1 = map[e->v1].first; n1; n1 = n1->next) {
+						for(n2 = map[e->v2].first; n2; n2 = n2->next) {
+							if(n1->index == n2->index) {
+								multires_displacer_init(&d, dm, n1->index, 1);
+								multires_displacer_anchor_edge(&d, e->v1, e->v2, x);
+								multires_displace(&d, mvert->co);
+							}
+						}
+					}
+					++mvert;
+					++d.subco;
+				}
+			}
+		
+			for(i = 0; i < MultiresDM_get_mesh(dm)->totvert; ++i) {
+				IndexNode *n;
+				for(n = map[i].first; n; n = n->next) {
+					multires_displacer_init(&d, dm, n->index, 1);
+					multires_displacer_anchor_vert(&d, i);
+					multires_displace(&d, mvert->co);
+				}
 				++mvert;
 				++d.subco;
 			}
 		}
 		
-		for(i = 0; i < MultiresDM_get_mesh(dm)->totvert; ++i) {
-			IndexNode *n;
-			for(n = map[i].first; n; n = n->next) {
-				multires_displacer_init(&d, dm, n->index, 1);
-				multires_displacer_anchor_vert(&d, i);
-				multires_displace(&d, mvert->co);
-			}
-			++mvert;
-			++d.subco;
-		}
+		orig->release(orig);
+		subco_dm->release(subco_dm);
 	}
 }
 

Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2008-07-25 02:49:49 UTC (rev 15751)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2008-07-25 03:13:16 UTC (rev 15752)
@@ -493,7 +493,6 @@
 	int *origIndex;
 	FaceVertWeight *qweight, *tweight;
 	MultiresDisplacer d;
-	float *mr_orig;
 
 	calc_ss_weights(gridFaces, &qweight, &tweight);
 
@@ -531,7 +530,6 @@
 		result = MultiresDM_new(ms, dm, ccgSubSurf_getNumFinalVerts(ss),
 					ccgSubSurf_getNumFinalEdges(ss),
 					ccgSubSurf_getNumFinalFaces(ss));
-		mr_orig = MultiresDM_get_subco(result);
 	}
 	else {
 		if(dm) {
@@ -565,8 +563,6 @@
 		DM_interp_vert_data(dm, result, vertIdx, weight[0][0], numVerts, i);
 		VecCopyf(mvert->co, ccgSubSurf_getFaceCenterData(ss, f));
 		if(ms) {
-			VecCopyf(mr_orig, mvert->co);
-			mr_orig += 3;
 			multires_displacer_init(&d, result, index, 0);
 			multires_displacer_anchor(&d, 1, 0);
 			multires_displace(&d, mvert->co);
@@ -591,11 +587,9 @@
 				DM_interp_vert_data(dm, result, vertIdx, w, numVerts, i);
 				VecCopyf(mvert->co,
 				         ccgSubSurf_getFaceGridEdgeData(ss, f, S, x));
-				if(ms) {
-					VecCopyf(mr_orig, mvert->co);
-					mr_orig += 3;
+				if(ms)
 					multires_displace(&d, mvert->co);
-				}
+
 				*origIndex = ORIGINDEX_NONE;
 				++mvert;
 				++origIndex;
@@ -619,11 +613,8 @@
 					DM_interp_vert_data(dm, result, vertIdx, w, numVerts, i);
 					VecCopyf(mvert->co,
 					         ccgSubSurf_getFaceGridData(ss, f, S, x, y));
-					if(ms) {
-						VecCopyf(mr_orig, mvert->co);
-						mr_orig += 3;
+					if(ms)
 						multires_displace(&d, mvert->co);
-					}
 
 					*origIndex = ORIGINDEX_NONE;
 					++mvert;
@@ -660,9 +651,6 @@
 				int numFaces = ccgSubSurf_getEdgeNumFaces(ss, e);
 				int edgeface;
 
-				VecCopyf(mr_orig, mvert->co);
-				mr_orig += 3;
-
 				multires_displacer_weight(&d, 1.0f / numFaces);
 				/* Could be made more efficient by moving this outside the x loop */
 				for(edgeface = 0; edgeface < numFaces; ++edgeface) {
@@ -697,9 +685,6 @@
 			int numFaces = ccgSubSurf_getVertNumFaces(ss, v);
 			int vertface;
 
-			VecCopyf(mr_orig, mvert->co);
-			mr_orig += 3;
-
 			multires_displacer_weight(&d, 1.0f / numFaces);
 			for(vertface = 0; vertface < numFaces; ++vertface) {
 				CCGFace *f = ccgSubSurf_getVertFace(ss, v, vertface);





More information about the Bf-blender-cvs mailing list