[Bf-blender-cvs] [e48c4d7] master: Replace MFace with looptri for dynamicpaint

Campbell Barton noreply at git.blender.org
Mon Jul 27 08:07:03 CEST 2015


Commit: e48c4d73d378b5ac7e8679b1eea04b265ef31612
Author: Campbell Barton
Date:   Mon Jul 27 15:52:54 2015 +1000
Branches: master
https://developer.blender.org/rBe48c4d73d378b5ac7e8679b1eea04b265ef31612

Replace MFace with looptri for dynamicpaint

D1429 by @lichtwerk, with edits

===================================================================

M	source/blender/blenkernel/BKE_dynamicpaint.h
M	source/blender/blenkernel/intern/dynamicpaint.c
M	source/blender/render/extern/include/RE_render_ext.h
M	source/blender/render/extern/include/RE_shader_ext.h
M	source/blender/render/intern/source/render_texture.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_dynamicpaint.h b/source/blender/blenkernel/BKE_dynamicpaint.h
index e7384fb..0025617 100644
--- a/source/blender/blenkernel/BKE_dynamicpaint.h
+++ b/source/blender/blenkernel/BKE_dynamicpaint.h
@@ -45,12 +45,10 @@ typedef struct PaintPoint {
 
 	/* Wet paint is handled at effect layer only
 	 * and mixed to surface when drying */
-	float e_color[3];
-	float e_alpha;
+	float e_color[4];
 	float wetness;
 	short state;
-	float color[3];
-	float alpha;
+	float color[4];
 } PaintPoint;
 
 /* heigh field waves	*/
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index 4372f96..6f510d8 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -200,12 +200,11 @@ typedef struct PaintBakeData {
 /* UV Image sequence format point	*/
 typedef struct PaintUVPoint {
 	/* Pixel / mesh data */
-	unsigned int face_index, pixel_index;   /* face index on domain derived mesh */
+	unsigned int tri_index, pixel_index;    /* tri index on domain derived mesh */
 	unsigned int v1, v2, v3;                /* vertex indexes */
 
 	unsigned int neighbour_pixel;   /* If this pixel isn't uv mapped to any face,
 	                                 * but it's neighboring pixel is */
-	short quad;
 } PaintUVPoint;
 
 typedef struct ImgSeqFormatData {
@@ -457,7 +456,7 @@ static void blendColors(const float t_color[3], float t_alpha, const float s_col
 }
 
 /* Mix two alpha weighed colors by a defined ratio. output is saved at a_color */
-static float mixColors(float a_color[3], float a_weight, float b_color[3], float b_weight, float ratio)
+static float mixColors(float a_color[3], float a_weight, const float b_color[3], float b_weight, float ratio)
 {
 	float weight_ratio, factor;
 	if (b_weight) {
@@ -1465,24 +1464,26 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface
 		/* apply color to every surface point */
 #pragma omp parallel for schedule(static)
 		for (i = 0; i < sData->total_points; i++) {
-			copy_v3_v3(pPoint[i].color, surface->init_color);
-			pPoint[i].alpha = surface->init_color[3];
+			copy_v4_v4(pPoint[i].color, surface->init_color);
 		}
 	}
 	/* UV mapped texture */
 	else if (surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) {
 		Tex *tex = surface->init_texture;
-		MTFace *tface;
-		MFace *mface = dm->getTessFaceArray(dm);
-		int numOfFaces = dm->getNumTessFaces(dm);
+
+		const MLoop *mloop = dm->getLoopArray(dm);
+		const MLoopTri *mlooptri = dm->getLoopTriArray(dm);
+		const int tottri = dm->getNumLoopTri(dm);
+		const MLoopUV *mloopuv = NULL;
+
 		char uvname[MAX_CUSTOMDATA_LAYER_NAME];
 
 		if (!tex) return;
 
 		/* get uv map */
-		CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, surface->init_layername, uvname);
-		tface = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
-		if (!tface) return;
+		CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, surface->init_layername, uvname);
+		mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
+		if (!mloopuv) return;
 
 		/* for vertex surface loop through tfaces and find uv color
 		 *  that provides highest alpha */
@@ -1490,23 +1491,22 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface
 			struct ImagePool *pool = BKE_image_pool_new();
 
 #pragma omp parallel for schedule(static) shared(pool)
-			for (i = 0; i < numOfFaces; i++) {
-				int numOfVert = (mface[i].v4) ? 4 : 3;
+			for (i = 0; i < tottri; i++) {
 				float uv[3] = {0.0f};
 				int j;
-				for (j = 0; j < numOfVert; j++) {
+				for (j = 0; j < 3; j++) {
 					TexResult texres = {0};
-					unsigned int *vert = (&mface[i].v1) + j;
+					unsigned int vert = mloop[mlooptri[i].tri[j]].v;
 
 					/* remap to -1.0 to 1.0 */
-					uv[0] = tface[i].uv[j][0] * 2.0f - 1.0f;
-					uv[1] = tface[i].uv[j][1] * 2.0f - 1.0f;
+					uv[0] = mloopuv[mlooptri[i].tri[j]].uv[0] * 2.0f - 1.0f;
+					uv[1] = mloopuv[mlooptri[i].tri[j]].uv[1] * 2.0f - 1.0f;
 
 					multitex_ext_safe(tex, uv, &texres, pool, scene_color_manage, false);
 
-					if (texres.tin > pPoint[*vert].alpha) {
-						copy_v3_v3(pPoint[*vert].color, &texres.tr);
-						pPoint[*vert].alpha = texres.tin;
+					if (texres.tin > pPoint[vert].color[3]) {
+						copy_v3_v3(pPoint[vert].color, &texres.tr);
+						pPoint[vert].color[3] = texres.tin;
 					}
 				}
 			}
@@ -1525,8 +1525,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface
 
 				/* collect all uvs */
 				for (j = 0; j < 3; j++) {
-					int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j;
-					copy_v2_v2(&uv[j * 3], tface[f_data->uv_p[i].face_index].uv[v]);
+					copy_v2_v2(&uv[j * 3], mloopuv[mlooptri[f_data->uv_p[i].tri_index].tri[j]].uv);
 				}
 
 				/* interpolate final uv pos */
@@ -1540,7 +1539,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface
 
 				/* apply color */
 				copy_v3_v3(pPoint[i].color, &texres.tr);
-				pPoint[i].alpha = texres.tin;
+				pPoint[i].color[3] = texres.tin;
 			}
 		}
 	}
@@ -1549,46 +1548,40 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface
 
 		/* for vertex surface, just copy colors from mcol */
 		if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
-			MLoop *mloop = dm->getLoopArray(dm);
-			int numOfLoops = dm->getNumLoops(dm);
-			MCol *col = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, surface->init_layername);
+			const MLoop *mloop = dm->getLoopArray(dm);
+			const int totloop = dm->getNumLoops(dm);
+			const MLoopCol *col = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, surface->init_layername);
 			if (!col) return;
 
 #pragma omp parallel for schedule(static)
-			for (i = 0; i < numOfLoops; i++) {
-				pPoint[mloop[i].v].color[0] = 1.0f / 255.f * (float)col[i].b;
-				pPoint[mloop[i].v].color[1] = 1.0f / 255.f * (float)col[i].g;
-				pPoint[mloop[i].v].color[2] = 1.0f / 255.f * (float)col[i].r;
-				pPoint[mloop[i].v].alpha = 1.0f / 255.f * (float)col[i].a;
+			for (i = 0; i < totloop; i++) {
+				rgba_uchar_to_float(pPoint[mloop[i].v].color, (const unsigned char *)&col[mloop[i].v].r);
 			}
 		}
 		else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) {
+			const MLoopTri *mlooptri = dm->getLoopTriArray(dm);
 			ImgSeqFormatData *f_data = (ImgSeqFormatData *)sData->format_data;
 			int samples = (surface->flags & MOD_DPAINT_ANTIALIAS) ? 5 : 1;
-			MCol *col = CustomData_get_layer_named(&dm->faceData, CD_MCOL, surface->init_layername);
+			// should this be replaced by CD_MLOOPCOL?
+			MLoopCol *col = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, surface->init_layername);
 			if (!col) return;
 
 #pragma omp parallel for schedule(static)
 			for (i = 0; i < sData->total_points; i++) {
-				int face_ind = f_data->uv_p[i].face_index;
-				float colors[3][4] = {{0.0f, 0.0f, 0.0f, 0.0f}};
+				int tri_ind = f_data->uv_p[i].tri_index;
+				float colors[3][4];
 				float final_color[4];
 				int j;
+
 				/* collect color values */
 				for (j = 0; j < 3; j++) {
-					int v = (f_data->uv_p[i].quad && j > 0) ? j + 1 : j;
-					colors[j][0] = 1.0f / 255.f * (float)col[face_ind * 4 + v].b;
-					colors[j][1] = 1.0f / 255.f * (float)col[face_ind * 4 + v].g;
-					colors[j][2] = 1.0f / 255.f * (float)col[face_ind * 4 + v].r;
-					colors[j][3] = 1.0f / 255.f * (float)col[face_ind * 4 + v].a;
+					rgba_uchar_to_float(colors[j], (const unsigned char *)&col[mlooptri[tri_ind].tri[j]].r);
 				}
-				
+
 				/* interpolate final color */
-				interp_v4_v4v4v4(final_color, colors[0], colors[1], colors[2],
-				                 f_data->barycentricWeights[i * samples].v);
+				interp_v4_v4v4v4(final_color, UNPACK3(colors), f_data->barycentricWeights[i * samples].v);
 
-				copy_v3_v3(pPoint[i].color, final_color);
-				pPoint[i].alpha = final_color[3];
+				copy_v4_v4(pPoint[i].color, final_color);
 			}
 		}
 	}
@@ -1724,7 +1717,7 @@ static DerivedMesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd,
 #pragma omp parallel for schedule(static)
 						for (i = 0; i < sData->total_points; i++) {
 							/* blend dry and wet layer */
-							blendColors(pPoint[i].color, pPoint[i].alpha, pPoint[i].e_color, pPoint[i].e_alpha, &fcolor[i * 4]);
+							blendColors(pPoint[i].color, pPoint[i].color[3], pPoint[i].e_color, pPoint[i].e_color[3], &fcolor[i * 4]);
 						}
 
 						/* viewport preview */
@@ -2051,7 +2044,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
 	 *	Check if shifted point is on same face -> it's a correct neighbor
 	 *   (and if it isn't marked as an "edge pixel")
 	 */
-	if ((tPoint->face_index == cPoint->face_index) && (tPoint->neighbour_pixel == -1))
+	if ((tPoint->tri_index == cPoint->tri_index) && (tPoint->neighbour_pixel == -1))
 		return (x + w * y);
 
 	/*
@@ -2062,7 +2055,7 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
 	 *	This should work fine as long as uv island
 	 *	margin is > 1 pixel.
 	 */
-	if ((tPoint->face_index != -1) && (tPoint->neighbour_pixel == -1)) {
+	if ((tPoint->tri_index != -1) && (tPoint->neighbour_pixel == -1)) {
 		return (x + w * y);
 	}
 
@@ -2080,9 +2073,10 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
 	 *	TODO: Implement something more accurate / optimized?
 	 */
 	{
-		int numOfFaces = dm->getNumTessFaces(dm);
-		MFace *mface = dm->getTessFaceArray(dm);
-		MTFace *tface =  CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
+		const MLoop *mloop = dm->getLoopArray(dm);
+		const MLoopTri *mlooptri = dm->getLoopTriArray(dm);
+		const int tottri = dm->getNumLoopTri(dm);
+		const MLoopUV *mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
 
 		/* Get closest edge to that subpixel on UV map	*/
 		{
@@ -2090,8 +2084,8 @@ static int dynamicPaint_findNeighbourPixel(PaintUVPoint *tempPoints, DerivedMesh
 			/* distances only used for comparison */
 			float dist_squared, t_dist_squared;
 
-			int i, uindex[3], edge1_index, edge2_index,
-			    e1_index, e2_index, target_face;
+			int i, edge1_index, edge

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list