[Bf-blender-cvs] [49aabfa] cycles-ptex-24: WIP Subsurf modifier updates

Nicholas Bishop noreply at git.blender.org
Fri Jan 30 18:00:30 CET 2015


Commit: 49aabfaf010ffb8b58cb095fd943075049e99779
Author: Nicholas Bishop
Date:   Tue Jan 20 13:55:01 2015 +0100
Branches: cycles-ptex-24
https://developer.blender.org/rB49aabfaf010ffb8b58cb095fd943075049e99779

WIP Subsurf modifier updates

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

M	source/blender/blenkernel/intern/subsurf_ccg.c

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

diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 45ec337..a0c06f5 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -62,6 +62,7 @@
 #include "BKE_mesh_mapping.h"
 #include "BKE_multires.h"
 #include "BKE_paint.h"
+#include "BKE_ptex.h"
 #include "BKE_scene.h"
 #include "BKE_subsurf.h"
 
@@ -2819,6 +2820,52 @@ static void ccgDM_release(DerivedMesh *dm)
 	}
 }
 
+static int choose_weight_index(const MLoopInterp *loop_interp)
+{
+	int highest = 0;
+	int i;
+
+	// TODO could assert that there's no tie
+
+	for (i = 0; i < 4; i++) {
+		const MLoopInterp *src = &loop_interp[i];
+		int j;
+
+		/* Find highest-weighted corner index */
+		for (j = 0; j < src->num_loops; j++) {
+			if (src->weights[j] > src->weights[highest]) {
+				highest = j;
+			}
+		}
+	}
+
+	return highest;
+}
+
+// TODO
+static void ccg_corner_ptex_uv_interp(MTessFacePtex *tess_face_ptex,
+									  const MLoopInterp *loop_interp)
+{
+	const int highest = choose_weight_index(loop_interp);
+	int i;
+	/* TODO: outer bias */
+
+	for (i = 0; i < 4; i++) {
+		const MLoopInterp *src = &loop_interp[i];
+		const int num_loops = src->num_loops;
+		MLoopPtexUV *dst = &tess_face_ptex->corners[i];
+		float weights[3] = {0, 0, 0};
+
+		weights[0] = src->weights[(highest + num_loops - 1) % num_loops];
+		weights[1] = src->weights[highest];
+		weights[2] = src->weights[(highest + 1) % num_loops];
+
+		dst->uv[0] = weights[0] / weights[1];
+		dst->uv[1] = weights[2] / weights[1];
+		dst->id = src->orig_loop_indices[highest];
+	}
+}
+
 static void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata, 
                                  CustomData *pdata, int loopstart, int findex,  int polyindex,
                                  const int numTex, const int numCol, const int hasPCol, const int hasOrigSpace)
@@ -2869,6 +2916,19 @@ static void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata,
 			copy_v2_v2(of->uv[j], lof->uv);
 		}
 	}
+
+	// TODO
+	{
+		MTessFacePtex *dst = CustomData_get(fdata, findex, CD_TESSFACE_PTEX);
+		
+		//ME_MTEXFACE_CPY(texface, texpoly);
+
+		MLoopInterp *loop_interp = CustomData_get(ldata, loopstart,
+												  CD_LOOP_INTERP);
+		if (loop_interp) {
+			ccg_corner_ptex_uv_interp(dst, loop_interp);
+		}
+	}
 }
 
 static void *ccgDM_get_vert_data_layer(DerivedMesh *dm, int type)
@@ -3011,13 +3071,14 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type)
 
 static void *ccgDM_get_poly_data_layer(DerivedMesh *dm, int type)
 {
+	CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
+	CCGSubSurf *ss = ccgdm->ss;
+	const int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
+
 	if (type == CD_ORIGINDEX) {
 		/* create origindex on demand to save memory */
-		CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
-		CCGSubSurf *ss = ccgdm->ss;
 		int *origindex;
 		int a, i, index, totface;
-		int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
 
 		/* Avoid re-creation if the layer exists already */
 		origindex = DM_get_poly_data_layer(dm, CD_ORIGINDEX);
@@ -3067,7 +3128,7 @@ static void *ccgDM_get_edge_data(DerivedMesh *dm, int index, int type)
 
 static void *ccgDM_get_tessface_data(DerivedMesh *dm, int index, int type)
 {
-	if (ELEM(type, CD_ORIGINDEX, CD_TESSLOOPNORMAL)) {
+	if (ELEM(type, CD_ORIGINDEX, CD_TESSLOOPNORMAL, CD_TESSFACE_PTEX)) {
 		/* ensure creation of CD_ORIGINDEX/CD_TESSLOOPNORMAL layers */
 		ccgDM_get_tessface_data_layer(dm, type);
 	}
@@ -3077,10 +3138,12 @@ static void *ccgDM_get_tessface_data(DerivedMesh *dm, int index, int type)
 
 static void *ccgDM_get_poly_data(DerivedMesh *dm, int index, int type)
 {
-	if (type == CD_ORIGINDEX) {
+#if 1
+	if (type == CD_ORIGINDEX || type == CD_TESSFACE_PTEX) {
 		/* ensure creation of CD_ORIGINDEX layer */
 		ccgDM_get_tessface_data_layer(dm, type);
 	}
+#endif
 
 	return DM_get_poly_data(dm, index, type);
 }
@@ -3451,6 +3514,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 	ccgdm->dm.getVertDataArray = ccgDM_get_vert_data_layer;
 	ccgdm->dm.getEdgeDataArray = ccgDM_get_edge_data_layer;
 	ccgdm->dm.getTessFaceDataArray = ccgDM_get_tessface_data_layer;
+	ccgdm->dm.getLoopDataArray = DM_get_loop_data_layer;
 	ccgdm->dm.getPolyDataArray = ccgDM_get_poly_data_layer;
 	ccgdm->dm.getNumGrids = ccgDM_getNumGrids;
 	ccgdm->dm.getGridSize = ccgDM_getGridSize;
@@ -3559,6 +3623,18 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 	mcol = DM_get_tessface_data_layer(&ccgdm->dm, CD_MCOL);
 #endif
 
+	
+	// TODO, quick hacks
+#if 1
+	// BKE_ptex_derived_mesh_interp_coords(dm);
+
+	// Loop DM thing will then interpolate correctly (?)
+
+	/* ccgDM_get_poly_data_layer(&ccgdm->dm, CD_TESSFACE_PTEX); */
+	CustomData_add_layer(&ccgdm->dm.faceData, CD_TESSFACE_PTEX, 
+	                     CD_CALLOC, NULL, ccgdm->dm.numTessFaceData);
+#endif
+
 	loopindex = loopindex2 = 0; /* current loop index */
 	for (index = 0; index < totface; index++) {
 		CCGFace *f = ccgdm->faceMap[index].face;
@@ -3571,7 +3647,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 #ifdef USE_DYNSIZE
 		int loopidx[numVerts], vertidx[numVerts];
 #endif
-
 		w = get_ss_weights(&wtable, gridCuts, numVerts);
 
 		ccgdm->faceMap[index].startVert = vertNum;
@@ -3658,25 +3733,30 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 			/*interpolate per-face data*/
 			for (y = 0; y < gridFaces; y++) {
 				for (x = 0; x < gridFaces; x++) {
-					w2 = w + s * numVerts * g2_wid * g2_wid + (y * g2_wid + x) * numVerts;
-					CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
-					                  loopidx, w2, NULL, numVerts, loopindex2);
-					loopindex2++;
-
-					w2 = w + s * numVerts * g2_wid * g2_wid + ((y + 1) * g2_wid + (x)) * numVerts;
-					CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
-					                  loopidx, w2, NULL, numVerts, loopindex2);
-					loopindex2++;
-
-					w2 = w + s * numVerts * g2_wid * g2_wid + ((y + 1) * g2_wid + (x + 1)) * numVerts;
-					CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
-					                  loopidx, w2, NULL, numVerts, loopindex2);
-					loopindex2++;
-					
-					w2 = w + s * numVerts * g2_wid * g2_wid + ((y) * g2_wid + (x + 1)) * numVerts;
-					CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
-					                  loopidx, w2, NULL, numVerts, loopindex2);
-					loopindex2++;
+					int x2, y2;
+					for (x2 = 0; x2 <= 1; x2++) {
+						for (y2 = 0; y2 <= 1; y2++) {
+							/* This gives the (x,y) pattern:
+							 * (0,0) (0,1) (1,1) (1,0) */
+							int y3 = (x2 == 0) ? y2 : 1 - y2;
+
+							/* Pointer arithmetic */
+							w2 = w + (s * numVerts * g2_wid * g2_wid +
+							          ((y + y3) * g2_wid +
+							           (x + x2)) * numVerts);
+
+							CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
+							                  loopidx, w2, NULL, numVerts, loopindex2);
+							/* if (src_loop_ptex_uvs) { */
+							/* 	dst_loop_ptex_uvs[loopindex2] = */
+							/* 		src_loop_ptex_uvs[loopidx[s]]; */
+							/* } */
+							/* ptex_uvs[loopindex2].uv[0] = w2[1]; */
+							/* ptex_uvs[loopindex2].uv[1] = w2[3]; */
+
+							loopindex2++;
+						}
+					}
 
 					/*copy over poly data, e.g. mtexpoly*/
 					CustomData_copy_data(&dm->polyData, &ccgdm->dm.polyData, origIndex, faceNum, 1);
@@ -3799,7 +3879,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 	ccgdm->dm.numPolyData = faceNum;
 
 	/* All tessellated CD layers were updated! */
-	ccgdm->dm.dirty &= ~DM_DIRTY_TESS_CDLAYERS;
+	//ccgdm->dm.dirty &= ~DM_DIRTY_TESS_CDLAYERS;
 
 #ifndef USE_DYNSIZE
 	BLI_array_free(vertidx);




More information about the Bf-blender-cvs mailing list