[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30916] branches/soc-2010-nicolasbishop/ source/blender: == VPaint/Multires ==

Nicholas Bishop nicholasbishop at gmail.com
Sat Jul 31 01:45:40 CEST 2010


Revision: 30916
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30916
Author:   nicholasbishop
Date:     2010-07-31 01:45:40 +0200 (Sat, 31 Jul 2010)

Log Message:
-----------
== VPaint/Multires ==

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

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

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_multires.h	2010-07-30 23:32:49 UTC (rev 30915)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_multires.h	2010-07-30 23:45:40 UTC (rev 30916)
@@ -49,6 +49,9 @@
 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 DerivedMesh *get_multires_dm(struct Scene *scene, struct MultiresModifierData *mmd,

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-30 23:32:49 UTC (rev 30915)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/multires.c	2010-07-30 23:45:40 UTC (rev 30916)
@@ -155,7 +155,7 @@
 
 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);
 }
 
@@ -1152,6 +1152,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 ****
 ***************************/
 

Modified: branches/soc-2010-nicolasbishop/source/blender/modifiers/intern/MOD_multires.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/modifiers/intern/MOD_multires.c	2010-07-30 23:32:49 UTC (rev 30915)
+++ branches/soc-2010-nicolasbishop/source/blender/modifiers/intern/MOD_multires.c	2010-07-30 23:45:40 UTC (rev 30916)
@@ -83,6 +83,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