[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37277] branches/soc-2011-onion: Revision: 30693

Jason Wilkins Jason.A.Wilkins at gmail.com
Tue Jun 7 00:25:28 CEST 2011


Revision: 37277
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37277
Author:   jwilkins
Date:     2011-06-06 22:25:28 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
Revision: 30693
Author: nicholasbishop
Date: 1:05:33 PM, Saturday, July 24, 2010
Message:
== Multires ==

Some refactoring to support vpaint

* For multires_mark_as_modified, make sure the DM is a CCGDM first
* Make the gridkey a parameter to various functions, rather than using the same one everywhere.
** Most important, when doing a multires update, enforces use of the same gridkey as the DM its updating from.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h
    branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
    branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c

Property Changed:
----------------
    branches/soc-2011-onion/


Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-30676,30692
/trunk/blender:36833-37206
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-30676,30692-30693
/trunk/blender:36833-37206

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h	2011-06-06 22:10:05 UTC (rev 37276)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h	2011-06-06 22:25:28 UTC (rev 37277)
@@ -35,6 +35,7 @@
  */
 
 struct DerivedMesh;
+struct GridKey;
 struct Mesh;
 struct MFace;
 struct Multires;
@@ -50,10 +51,11 @@
 void multires_force_render_update(struct Object *ob);
 void multires_force_external_reload(struct Object *ob);
 
+/* note: gridkey can be NULL, will provide a context-sensitive default */
 void multiresModifier_set_levels_from_disps(struct MultiresModifierData *mmd, struct Object *ob);
 
 struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*,
-	int local_mmd, struct DerivedMesh*, struct Object *, int, int);
+	int local_mmd, struct DerivedMesh*, struct Object *, struct GridKey *, int, int);
 
 struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene,
 	struct ModifierData *lastmd);

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-06-06 22:10:05 UTC (rev 37276)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-06-06 22:25:28 UTC (rev 37277)
@@ -162,8 +162,10 @@
 
 void multires_mark_as_modified(Object *ob)
 {
-	if(ob && ob->derivedFinal)
-		multires_dm_mark_as_modified(ob->derivedFinal);
+	DerivedMesh *dm = ob->derivedFinal;
+
+	if(ob && dm && dm->type == DM_TYPE_CCGDM)
+		multires_dm_mark_as_modified(dm);
 }
 
 void multires_force_update(Object *ob)
@@ -491,7 +493,9 @@
 	multires_set_tot_level(ob, mmd, lvl);
 }
 
-static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int totlvl, int simple)
+static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm,
+					     GridKey *gridkey, int lvl,
+					     int totlvl, int simple)
 {
 	MultiresModifierData mmd= {{NULL}};
 
@@ -501,13 +505,15 @@
 	mmd.totlvl = totlvl;
 	mmd.simple = simple;
 
-	return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0, 0);
+	return multires_dm_create_from_derived(&mmd, 1, dm, ob, gridkey, 0, 0);
 }
 
-static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal)
+static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm,
+					    GridKey *gridkey, int lvl,
+					    int simple, int optimal)
 {
 	SubsurfModifierData smd= {{NULL}};
-	GridKey gridkey;
+	GridKey default_gridkey;
 	int color_totlayer;
 	int pmask_totlayer;
 
@@ -518,14 +524,17 @@
 	if(optimal)
 		smd.flags |= eSubsurfModifierFlag_ControlEdges;
 
+	if(!gridkey) {
 	/* TODO: enable/disable element types */
 	color_totlayer = CustomData_number_of_layers(&get_mesh(ob)->fdata,
 						     CD_MCOL);
 	pmask_totlayer = CustomData_number_of_layers(&get_mesh(ob)->vdata,
 						     CD_PAINTMASK);
-	GRIDELEM_KEY_INIT(&gridkey, 1, color_totlayer, pmask_totlayer, 1);
+		GRIDELEM_KEY_INIT(&default_gridkey, 1, color_totlayer, pmask_totlayer, 1);
+		gridkey = &default_gridkey;
+	}
 			  
-	return subsurf_make_derived_from_derived(dm, &smd, &gridkey, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
+	return subsurf_make_derived_from_derived(dm, &smd, gridkey, 0, NULL, 0, 0, (ob->mode & OB_MODE_EDIT));
 }
 
 
@@ -542,6 +551,7 @@
 void multiresModifier_base_apply(MultiresModifierData *mmd, Object *ob)
 {
 	DerivedMesh *cddm, *dispdm, *origdm;
+	GridKey gridkey;
 	Mesh *me;
 	ListBase *fmap;
 	float (*origco)[3];
@@ -552,16 +562,15 @@
 	me = get_mesh(ob);
 	totlvl = mmd->totlvl;
 
-	/* nothing to do */
-	if(!totlvl)
-		return;
+	/* only need vert/norm grid data */
+	GRIDELEM_KEY_INIT(&gridkey, 1, 0, 0, 1);
 
 	/* XXX - probably not necessary to regenerate the cddm so much? */
 
 	/* generate highest level with displacements */
 	cddm = CDDM_from_mesh(me, NULL);
 	DM_set_only_copy(cddm, CD_MASK_BAREMESH);
-	dispdm = multires_dm_create_local(ob, cddm, totlvl, totlvl, 0);
+	dispdm = multires_dm_create_local(ob, cddm, &gridkey, totlvl, totlvl, 0);
 	cddm->release(cddm);
 
 	/* copy the new locations of the base verts into the mesh */
@@ -640,7 +649,7 @@
 	/* subdivide the mesh to highest level without displacements */
 	cddm = CDDM_from_mesh(me, NULL);
 	DM_set_only_copy(cddm, CD_MASK_BAREMESH);
-	origdm = subsurf_dm_create_local(ob, cddm, totlvl, 0, 0);
+	origdm = subsurf_dm_create_local(ob, cddm, &gridkey, totlvl, 0, 0);
 	cddm->release(cddm);
 
 	/* calc disps */
@@ -689,11 +698,11 @@
 		/* create subsurf DM from original mesh at high level */
 		cddm = CDDM_from_mesh(me, NULL);
 		DM_set_only_copy(cddm, CD_MASK_BAREMESH);
-		highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0);
+		highdm = subsurf_dm_create_local(ob, cddm, NULL, totlvl, simple, 0);
 		gridkey = highdm->getGridKey(highdm);
 
 		/* create multires DM from original mesh at low level */
-		lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple);
+		lowdm = multires_dm_create_local(ob, cddm, NULL, lvl, lvl, simple);
 		cddm->release(cddm);
 
 		/* copy subsurf grids and replace them with low displaced grids */
@@ -936,6 +945,7 @@
 	Mesh *me;
 	MDisps *mdisps;
 	MultiresModifierData *mmd;
+	GridKey *gridkey;
 
 	ob = ccgdm->multires.ob;
 	me = ccgdm->multires.ob->data;
@@ -944,6 +954,10 @@
 	CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface);
 	mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
 
+	/* use the same gridkey as the dm so that we don't try
+	   to update layers that didn't exist before */
+	gridkey = dm->getGridKey(dm);
+
 	if(mdisps) {
 		int lvl = ccgdm->multires.lvl;
 		int totlvl = ccgdm->multires.totlvl;
@@ -954,18 +968,16 @@
 			DMGridData **highGridData, **lowGridData, **subGridData, **gridData, *diffGrid;
 			CCGSubSurf *ss;
 			int i, j, numGrids, highGridSize, lowGridSize;
-			GridKey *gridkey;
 
 			/* create subsurf DM from original mesh at high level */
 			if (ob->derivedDeform) cddm = CDDM_copy(ob->derivedDeform);
 			else cddm = CDDM_from_mesh(me, NULL);
 			DM_set_only_copy(cddm, CD_MASK_BAREMESH);
 
-			highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0);
-			gridkey = highdm->getGridKey(highdm);
+			highdm = subsurf_dm_create_local(ob, cddm, gridkey, totlvl, mmd->simple, 0);
 
 			/* create multires DM from original mesh and displacements */
-			lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple);
+			lowdm = multires_dm_create_local(ob, cddm, gridkey, lvl, totlvl, mmd->simple);
 			cddm->release(cddm);
 
 			/* gather grid data */
@@ -1017,7 +1029,7 @@
 			else cddm = CDDM_from_mesh(me, NULL);
 			DM_set_only_copy(cddm, CD_MASK_BAREMESH);
 
-			subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0);
+			subdm = subsurf_dm_create_local(ob, cddm, gridkey, mmd->totlvl, mmd->simple, 0);
 			cddm->release(cddm);
 
 			multiresModifier_disp_run(dm, me, CALC_DISPS, subdm->getGridData(subdm), mmd->totlvl);
@@ -1047,7 +1059,7 @@
 }
 
 DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob,
-							int useRenderParams, int UNUSED(isFinalCalc))
+					     GridKey *gridkey, int useRenderParams, int UNUSED(isFinalCalc))
 {
 	Mesh *me= ob->data;
 	DerivedMesh *result;
@@ -1055,12 +1067,11 @@
 	DMGridData **gridData, **subGridData;
 	int lvl= multires_get_level(ob, mmd, useRenderParams);
 	int i, gridSize, numGrids;
-	GridKey *gridkey;
 
 	if(lvl == 0)
 		return dm;
 
-	result = subsurf_dm_create_local(ob, dm, lvl,
+	result = subsurf_dm_create_local(ob, dm, gridkey, lvl,
 		mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges);
 
 	if(!local_mmd) {
@@ -1078,6 +1089,7 @@
 	numGrids = result->getNumGrids(result);
 	gridSize = result->getGridSize(result);
 	gridData = result->getGridData(result);
+	/* null gridkey can be passed in, so update it here */
 	gridkey = result->getGridKey(result);
 
 	subGridData = MEM_callocN(sizeof(DMGridData*)*numGrids, "subGridData*");
@@ -1684,7 +1696,7 @@
 
 	mmd->lvl = mmd->totlvl;
 	orig = CDDM_from_mesh(me, NULL);
-	dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0, 0);
+	dm = multires_dm_create_from_derived(mmd, 0, orig, ob, NULL, 0, 0);
 					   
 	multires_load_old_dm(dm, me, mmd->totlvl+1);
 
@@ -1769,7 +1781,7 @@
 	MEM_freeN(vertCos);
 
 	/* scaled ccgDM for tangent space of object with applied scale */
-	dm= subsurf_dm_create_local(ob, cddm, high_mmd.totlvl, high_mmd.simple, 0);
+	dm= subsurf_dm_create_local(ob, cddm, NULL, high_mmd.totlvl, high_mmd.simple, 0);
 	cddm->release(cddm);
 
 	/*numGrids= dm->getNumGrids(dm);*/ /*UNUSED*/

Modified: branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c	2011-06-06 22:10:05 UTC (rev 37276)
+++ branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c	2011-06-06 22:25:28 UTC (rev 37277)
@@ -84,7 +84,7 @@
 		}
 	}
 
-	result = multires_dm_create_from_derived(mmd, 0, dm, ob, useRenderParams, isFinalCalc);
+	result = multires_dm_create_from_derived(mmd, 0, dm, ob, NULL, useRenderParams, isFinalCalc);
 
 	if(result == dm)
 		return dm;




More information about the Bf-blender-cvs mailing list