[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55683] branches/soc-2008-mxcurioni/source /blender: Work-in-progress re-implementation of CustomData-based edge/ face marks.

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Sun Mar 31 12:33:28 CEST 2013


Revision: 55683
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55683
Author:   kjym3
Date:     2013-03-31 10:33:27 +0000 (Sun, 31 Mar 2013)
Log Message:
-----------
Work-in-progress re-implementation of CustomData-based edge/face marks.

Most changes in revision 55228 were reverted and Freestyle edge/face marks
were re-implemented using CD_ORIGINDEX layers of edge/poly custom data.

For this implementation to work properly, modifiers were updated so that
required CD_ORIGINDEX layers will be set.  As pilot cases, the Mirror and
Solidify modifiers were updated (see comments in the code).

Some Freestyle-specific code is necessary in DerivedMesh.c so that the
CD_FREESTYLE_EDGE/FACE layers will be transferred from meshes to derived
meshes.  This seems unnecessary, so further investigation is foreseen.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55228

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/DerivedMesh.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/mesh.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_mirror.c
    branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_solidify.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/DerivedMesh.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/DerivedMesh.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -1840,6 +1840,36 @@
 		}
 	}
 
+#ifdef WITH_FREESTYLE
+	/* This Freestyle-specific code still needs to get the Subdivision Surface modifier working */
+	if (CustomData_has_layer(&me->edata, CD_FREESTYLE_EDGE)) {
+		FreestyleEdge *fed = DM_get_edge_data_layer(finaldm, CD_FREESTYLE_EDGE);
+		if (fed) {
+			FreestyleEdge *source = CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE);
+			int a;
+			for (a = 0; a < me->totedge; a++) {
+				fed[a].flag = source[a].flag;
+			}
+			for (; a < finaldm->numEdgeData; a++) {
+				fed[a].flag = 0;
+			}
+		}
+	}
+	if (CustomData_has_layer(&me->pdata, CD_FREESTYLE_FACE)) {
+		FreestyleFace *ffa = DM_get_poly_data_layer(finaldm, CD_FREESTYLE_FACE);
+		if (ffa) {
+			FreestyleFace *source = CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
+			int a;
+			for (a = 0; a < me->totpoly; a++) {
+				ffa[a].flag = source[a].flag;
+			}
+			for (; a < finaldm->numPolyData; a++) {
+				ffa[a].flag = 0;
+			}
+		}
+	}
+#endif
+
 #ifdef WITH_GAMEENGINE
 	/* NavMesh - this is a hack but saves having a NavMesh modifier */
 	if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) {

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/mesh.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/mesh.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -2636,16 +2636,6 @@
 		}
 	}
 
-#ifdef WITH_FREESTYLE
-	if (CustomData_has_layer(pdata, CD_FREESTYLE_FACE)) {
-		FreestyleEdge *poly_ffa = CustomData_get_layer(pdata, CD_FREESTYLE_FACE);
-		FreestyleEdge *face_ffa = CustomData_add_layer(fdata, CD_FREESTYLE_FACE, CD_CALLOC, NULL, totface);
-		for (mface_index = 0; mface_index < totface; mface_index++) {
-			face_ffa[mface_index] = poly_ffa[mface_to_poly_map[mface_index]];
-		}
-	}
-#endif
-
 	mf = mface;
 	for (mface_index = 0; mface_index < totface; mface_index++, mf++) {
 

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -3108,10 +3108,6 @@
 	MEdge *medge = NULL;
 	/* MFace *mface = NULL; */
 	MPoly *mpoly = NULL;
-#ifdef WITH_FREESTYLE
-	FreestyleEdge *fed = NULL, *ccgdm_fed = NULL;
-	FreestyleFace *ffa = NULL, *ccgdm_ffa = NULL;
-#endif
 
 	DM_from_template(&ccgdm->dm, dm, DM_TYPE_CCGDM,
 	                 ccgSubSurf_getNumFinalVerts(ss),
@@ -3286,19 +3282,6 @@
 
 	has_edge_origindex = CustomData_has_layer(&ccgdm->dm.edgeData, CD_ORIGINDEX);
 
-#ifdef WITH_FREESTYLE
-	fed = DM_get_edge_data_layer(dm, CD_FREESTYLE_EDGE);
-	if (fed) {
-		ccgdm_fed = CustomData_add_layer(&ccgdm->dm.edgeData, CD_FREESTYLE_EDGE, CD_CALLOC, NULL,
-		                                 ccgSubSurf_getNumFinalEdges(ss));
-	}
-	ffa = DM_get_poly_data_layer(dm, CD_FREESTYLE_FACE);
-	if (ffa) {
-		ccgdm_ffa = CustomData_add_layer(&ccgdm->dm.faceData, CD_FREESTYLE_FACE, CD_CALLOC, NULL,
-		                                 ccgSubSurf_getNumFinalFaces(ss));
-	}
-#endif
-
 	loopindex = loopindex2 = 0; /* current loop index */
 	for (index = 0; index < totface; index++) {
 		CCGFace *f = ccgdm->faceMap[index].face;
@@ -3435,12 +3418,6 @@
 					/* This is a simple one to one mapping, here... */
 					polyidx[faceNum] = faceNum;
 
-#ifdef WITH_FREESTYLE
-					if (ffa && ffa[index].flag & FREESTYLE_FACE_MARK) {
-						ccgdm_ffa[faceNum].flag |= FREESTYLE_FACE_MARK;
-					}
-#endif
-
 					faceNum++;
 				}
 			}
@@ -3490,14 +3467,6 @@
 			}
 		}
 
-#ifdef WITH_FREESTYLE
-		if (fed && fed[index].flag & FREESTYLE_EDGE_MARK) {
-			for (i = 0; i < numFinalEdges; ++i) {
-				ccgdm_fed[edgeNum + i].flag |= FREESTYLE_EDGE_MARK;
-			}
-		}
-#endif
-
 		edgeNum += numFinalEdges;
 	}
 

Modified: branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_mirror.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_mirror.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_mirror.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -161,6 +161,15 @@
 		dm->copyPolyArray(dm, CDDM_get_polys(result));
 	}
 
+#if 1 /* WITH_FREESTYLE generic changes */
+	/* if the source DM does not have edge CD_ORIGINDEX layer, then
+	 * the corresponding layer of the result DM is filled with zeros
+	 * (see CDDM_from_template()) */
+	if (!CustomData_has_layer(&dm->edgeData, CD_ORIGINDEX)) {
+		range_vn_i(DM_get_edge_data_layer(result, CD_ORIGINDEX), maxEdges, 0);
+	}
+#endif
+
 	/* copy customdata to new geometry,
 	 * copy from its self because this data may have been created in the checks above */
 	DM_copy_vert_data(result, result, 0, maxVerts, maxVerts);

Modified: branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_solidify.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_solidify.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/modifiers/intern/MOD_solidify.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -374,6 +374,27 @@
 	DM_copy_poly_data(dm, result, 0, 0, numFaces);
 	DM_copy_poly_data(dm, result, 0, numFaces, numFaces);
 
+#if 1 /* WITH_FREESTYLE generic changes */
+	/* When the input DM has no edge CD_ORIGINDEX layer (i.e., the corresponding
+	 * layer of the result DM is filled with zeros; see CDDM_from_template()),
+	 * set the layer to an identity mapping */
+	if (!CustomData_has_layer(&dm->edgeData, CD_ORIGINDEX)) {
+		int *index = DM_get_edge_data_layer(result, CD_ORIGINDEX);
+		range_vn_i(index, numEdges, 0);
+		range_vn_i(index+numEdges, numEdges, 0);
+	}
+	/* Do the same for poly CD_ORIGINDEX layer */
+	if (!CustomData_has_layer(&dm->polyData, CD_ORIGINDEX)) {
+		int *index, a;
+		DM_add_poly_layer(result, CD_ORIGINDEX, CD_CALLOC, NULL);
+		index = DM_get_poly_data_layer(result, CD_ORIGINDEX);
+		range_vn_i(index, numFaces, 0);
+		range_vn_i(index+numFaces, numFaces, 0);
+		for (a = 0; a < newFaces; a++)
+			index[numFaces*2+a] = ORIGINDEX_NONE;
+	}
+#endif
+
 	/* if the original has it, get the result so we can update it */
 	face_nors_result = CustomData_get_layer(&result->polyData, CD_NORMAL);
 

Modified: branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c	2013-03-31 03:28:46 UTC (rev 55682)
+++ branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c	2013-03-31 10:33:27 UTC (rev 55683)
@@ -2660,6 +2660,8 @@
 	MFace *mface;
 	Material *ma;
 #ifdef WITH_FREESTYLE
+	const int *index_mf_to_mpoly = NULL;
+	const int *index_mp_to_orig = NULL;
 	FreestyleFace *ffa;
 #endif
 	/* Curve *cu= ELEM(ob->type, OB_FONT, OB_CURVE) ? ob->data : NULL; */
@@ -2692,7 +2694,9 @@
 			end= dm->getNumTessFaces(dm);
 			mface= dm->getTessFaceArray(dm);
 #ifdef WITH_FREESTYLE
-			ffa= dm->getTessFaceDataArray(dm, CD_FREESTYLE_FACE);
+			index_mf_to_mpoly= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+			index_mp_to_orig= dm->getPolyDataArray(dm, CD_ORIGINDEX);
+			ffa= dm->getPolyDataArray(dm, CD_FREESTYLE_FACE);
 #endif
 
 			for (a=0; a<end; a++, mface++) {
@@ -2724,7 +2728,12 @@
 					vlr->flag= flag;
 					vlr->ec= 0; /* mesh edges rendered separately */
 #ifdef WITH_FREESTYLE
-					vlr->freestyle_face_mark= (ffa && (ffa[a].flag & FREESTYLE_FACE_MARK)) ? 1 : 0;
+					if (ffa) {
+						int index = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a;
+						vlr->freestyle_face_mark= (ffa[index].flag & FREESTYLE_FACE_MARK) ? 1 : 0;
+					} else {
+						vlr->freestyle_face_mark= 0;
+					}
 #endif
 
 					if (len==0) obr->totvlak--;
@@ -3240,15 +3249,27 @@
 	FreestyleEdge *fed;
 	MEdge *medge;
 	int totedge, a;
+	int *index;
 
 	medge = dm->getEdgeArray(dm);
 	totedge = dm->getNumEdges(dm);
+	index = dm->getEdgeDataArray(dm, CD_ORIGINDEX);
 	fed = dm->getEdgeDataArray(dm, CD_FREESTYLE_EDGE);
 	if (fed) {
-		for (a = 0; a < totedge; a++) {
-			if (fed[a].flag & FREESTYLE_EDGE_MARK)
-				BLI_edgehash_insert(edge_hash, medge[a].v1, medge[a].v2, medge+a);
+		if (!index) {
+			for (a = 0; a < totedge; a++) {
+				if (fed[a].flag & FREESTYLE_EDGE_MARK)
+					BLI_edgehash_insert(edge_hash, medge[a].v1, medge[a].v2, medge+a);
+			}
 		}
+		else {
+			for (a = 0; a < totedge; a++) {
+				if (index[a] == ORIGINDEX_NONE)
+					continue;
+				if (fed[index[a]].flag & FREESTYLE_EDGE_MARK)
+					BLI_edgehash_insert(edge_hash, medge[a].v1, medge[a].v2, medge+a);
+			}
+		}
 	}
 	return edge_hash;
 }
@@ -3280,6 +3301,8 @@
 	int recalc_normals = 0;	/* false by default */
 	int negative_scale;
 #ifdef WITH_FREESTYLE
+	const int *index_mf_to_mpoly = NULL;
+	const int *index_mp_to_orig = NULL;
 	FreestyleFace *ffa;
 #endif
 
@@ -3451,7 +3474,9 @@
 					end= dm->getNumTessFaces(dm);
 					mface= dm->getTessFaceArray(dm);
 #ifdef WITH_FREESTYLE
-					ffa= dm->getTessFaceDataArray(dm, CD_FREESTYLE_FACE);
+					index_mf_to_mpoly= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
+					index_mp_to_orig= dm->getPolyDataArray(dm, CD_ORIGINDEX);
+					ffa= dm->getPolyDataArray(dm, CD_FREESTYLE_FACE);
 #endif
 					
 					for (a=0; a<end; a++, mface++) {
@@ -3489,7 +3514,12 @@
 								}
 								vlr->freestyle_edge_mark= edge_mark;
 							}
-							vlr->freestyle_face_mark= (ffa && (ffa[a].flag & FREESTYLE_FACE_MARK)) ? 1 : 0;
+							if (ffa) {
+								int index = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a;
+								vlr->freestyle_face_mark= (ffa[index].flag & FREESTYLE_FACE_MARK) ? 1 : 0;
+							} else {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list