[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39319] branches/soc-2011-onion/source/ blender: Revision: 30916

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Aug 12 05:34:32 CEST 2011


Revision: 39319
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39319
Author:   jwilkins
Date:     2011-08-12 03:34:31 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
Revision: 30916
Author: nicholasbishop
Date: 6:45:40 PM, Friday, July 30, 2010
Message:
== VPaint/Multires ==

Added a function to apply multires colors as regular mcols; used when applying multires modifier and rendering

----
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_multires.h
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
Modified : /branches/soc-2010-nicolasbishop/source/blender/modifiers/intern/MOD_multires.c

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

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h	2011-08-12 03:18:04 UTC (rev 39318)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_multires.h	2011-08-12 03:34:31 UTC (rev 39319)
@@ -51,12 +51,15 @@
 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);
 
+/* note: gridkey can be NULL, will provide a context-sensitive default */
 struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*,
 	int local_mmd, struct DerivedMesh*, struct Object *, struct GridKey *, int, int);
 
+/* convert multires color layers to standard mcol layers */
+void multires_apply_colors(struct DerivedMesh *cddm, struct DerivedMesh *ccgdm);
+
 struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene,
 	struct ModifierData *lastmd);
 struct MultiresModifierData *get_multires_modifier(struct Scene *scene, struct Object *ob, int use_first);

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-08-12 03:18:04 UTC (rev 39318)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/multires.c	2011-08-12 03:34:31 UTC (rev 39319)
@@ -193,8 +193,12 @@
 
 void multires_force_render_update(Object *ob)
 {
-	if(ob && (ob->mode & OB_MODE_SCULPT) && modifiers_findByType(ob, eModifierType_Multires))
+	if (ob &&
+	    (ob->mode & (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT)) &&
+	    modifiers_findByType(ob, eModifierType_Multires))
+	{
 		multires_force_update(ob);
+	}
 }
 
 int multiresModifier_reshapeFromDM(Scene *scene, MultiresModifierData *mmd,
@@ -1195,6 +1199,60 @@
 	return result;
 }
 
+/* convert multires color layers to standard mcol layers */
+void multires_apply_colors(DerivedMesh *cddm, DerivedMesh *ccgdm)
+{
+	DMGridData **grids;
+	GridKey *gridkey;
+	MCol **mcol;
+	int i, j, k, x, y, gridsize, boundary, totgrid;
+
+	grids = ccgdm->getGridData(ccgdm);
+	gridkey = ccgdm->getGridKey(ccgdm);
+	gridsize = ccgdm->getGridSize(ccgdm);
+	totgrid = ccgdm->getNumGrids(ccgdm);
+	boundary = gridsize - 1;
+
+	/* get multires mcol layers */
+	mcol = MEM_callocN(sizeof(MCol*)*gridkey->color,
+			   "multires_apply_colors.mcol");
+	for(i = 0; i < gridkey->color; ++i) {
+		char *name = gridkey->color_names[i];
+
+		/* TODO: note that this works because plain subdivided mcols
+		   already generated, that's inefficient and should be fixed */
+		mcol[i] = CustomData_get_layer_named(&cddm->faceData, CD_MCOL, name);
+	}
+
+	for(i = 0; i < totgrid; ++i) {
+		DMGridData *grid = grids[i];
+
+		for(y = 0; y < boundary; ++y) {
+			for(x = 0; x < boundary; ++x) {
+				for(j = 0; j < gridkey->color; ++j) {
+					float *col[4];
+
+					col[0] = GRIDELEM_COLOR_AT(grid, y*gridsize+x, gridkey)[j];
+					col[1] = GRIDELEM_COLOR_AT(grid, (y+1)*gridsize+x, gridkey)[j];
+					col[2] = GRIDELEM_COLOR_AT(grid, (y+1)*gridsize+(x+1), gridkey)[j];
+					col[3] = GRIDELEM_COLOR_AT(grid, y*gridsize+(x+1), gridkey)[j];
+
+					for(k = 0; k < 4; ++k) {
+						mcol[j][k].b = col[k][0] * 255;
+						mcol[j][k].g = col[k][1] * 255;
+						mcol[j][k].r = col[k][2] * 255;
+						mcol[j][k].a = col[k][3] * 255;
+					}
+
+					mcol[j] += 4;
+				}
+			}
+		}
+	}
+
+	MEM_freeN(mcol);
+}
+
 /**** Old Multires code ****
 ***************************/
 
@@ -1781,7 +1839,7 @@
 	mmd->lvl = mmd->totlvl;
 	orig = CDDM_from_mesh(me, NULL);
 	dm = multires_dm_create_from_derived(mmd, 0, orig, ob, NULL, 0, 0);
-					   
+
 	multires_load_old_dm(dm, me, mmd->totlvl+1);
 
 	multires_dm_mark_as_modified(dm);

Modified: branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c
===================================================================
--- branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c	2011-08-12 03:18:04 UTC (rev 39318)
+++ branches/soc-2011-onion/source/blender/modifiers/intern/MOD_multires.c	2011-08-12 03:34:31 UTC (rev 39319)
@@ -91,6 +91,9 @@
 
 	if(useRenderParams || !isFinalCalc) {
 		DerivedMesh *cddm= CDDM_copy(result);
+
+		multires_apply_colors(cddm, result);
+
 		result->release(result);
 		result= cddm;
 	}




More information about the Bf-blender-cvs mailing list