[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55228] branches/soc-2008-mxcurioni/source /blender: New implementation of Freestyle edge/face marks

Tamito Kajiyama rd6t-kjym at asahi-net.or.jp
Wed Mar 13 07:44:43 CET 2013


Revision: 55228
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55228
Author:   kjym3
Date:     2013-03-13 06:44:43 +0000 (Wed, 13 Mar 2013)
Log Message:
-----------
New implementation of Freestyle edge/face marks

The previous implementation of Freestyle edge/face marks was refactored
based on suggestions from the latest code review by Campbell.  The new
implementation relies on mesh CustomData to store edge/face marks, instead
of introducing extra flags in the core Mesh and BMesh data structures.
The CustomData-based implementation will allow further additions of new
edge/face attributes because of the independence from Mesh/BMesh.

This revision is work in progress, mainly intended to address the review
comments and ask for further code review in view of the trunk merger in
the upcoming 2.67 release.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/customdata.c
    branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c
    branches/soc-2008-mxcurioni/source/blender/bmesh/bmesh_class.h
    branches/soc-2008-mxcurioni/source/blender/bmesh/intern/bmesh_construct.c
    branches/soc-2008-mxcurioni/source/blender/bmesh/intern/bmesh_mesh_conv.c
    branches/soc-2008-mxcurioni/source/blender/bmesh/operators/bmo_similar.c
    branches/soc-2008-mxcurioni/source/blender/editors/mesh/editmesh_select.c
    branches/soc-2008-mxcurioni/source/blender/editors/mesh/editmesh_tools.c
    branches/soc-2008-mxcurioni/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_customdata_types.h
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_mesh_types.h
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_meshdata_types.h
    branches/soc-2008-mxcurioni/source/blender/makesrna/intern/rna_mesh.c
    branches/soc-2008-mxcurioni/source/blender/python/bmesh/bmesh_py_types.c
    branches/soc-2008-mxcurioni/source/blender/python/bmesh/bmesh_py_types_customdata.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/include/render_types.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c

Modified: branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/customdata.c	2013-03-13 06:36:27 UTC (rev 55227)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/customdata.c	2013-03-13 06:44:43 UTC (rev 55228)
@@ -1143,7 +1143,11 @@
 	 layerFree_grid_paint_mask, NULL, NULL, NULL},
 	/* 36: CD_SKIN_NODE */
 	{sizeof(MVertSkin), "MVertSkin", 1, NULL, NULL, NULL,
-	 layerInterp_mvert_skin, NULL, layerDefault_mvert_skin}
+	 layerInterp_mvert_skin, NULL, layerDefault_mvert_skin},
+	/* 37: CD_FREESTYLE_EDGE */
+	{sizeof(FreestyleEdge), "FreestyleEdge", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+	/* 38: CD_FREESTYLE_FACE */
+	{sizeof(FreestyleFace), "FreestyleFace", 1, NULL, NULL, NULL, NULL, NULL, NULL}
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1158,7 +1162,8 @@
 /* BMESH ONLY */
 	/* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight",
 	/* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
-	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin"
+	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
+	/* 37-38 */ "CDFreestyleEdge", "CDFreestyleFace"
 };
 
 
@@ -1170,7 +1175,7 @@
     CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP |
     CD_MASK_MTEXPOLY | CD_MASK_NORMAL | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
 const CustomDataMask CD_MASK_EDITMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX |
@@ -1183,13 +1188,13 @@
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL |
     CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT |
     CD_MASK_PREVIEW_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
-    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN;
+    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
 const CustomDataMask CD_MASK_BMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
     CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS |
     CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
 const CustomDataMask CD_MASK_FACECORNERS =
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL;

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-13 06:36:27 UTC (rev 55227)
+++ branches/soc-2008-mxcurioni/source/blender/blenkernel/intern/subsurf_ccg.c	2013-03-13 06:44:43 UTC (rev 55228)
@@ -964,11 +964,7 @@
 
 		edgeFlag = (ccgdm->edgeFlags) ? &ccgdm->edgeFlags[i] : NULL;
 		if (edgeFlag)
-#ifdef WITH_FREESTYLE
-			flags |= (*edgeFlag & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER;
-#else
 			flags |= (*edgeFlag & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER;
-#endif
 		else
 			flags |= ME_EDGEDRAW | ME_EDGERENDER;
 
@@ -1236,11 +1232,7 @@
 
 		if (edgeFlags) {
 			if (edgeIdx != -1) {
-#ifdef WITH_FREESTYLE
-				ed_flag |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER);
-#else
 				ed_flag |= ((edgeFlags[index] & (ME_SEAM | ME_SHARP)) | ME_EDGEDRAW | ME_EDGERENDER);
-#endif
 			}
 		}
 		else {
@@ -3117,6 +3109,10 @@
 	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),
@@ -3291,6 +3287,18 @@
 
 	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++) {
@@ -3430,6 +3438,12 @@
 					/* 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++;
 				}
 			}
@@ -3479,6 +3493,14 @@
 			}
 		}
 
+#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/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c	2013-03-13 06:36:27 UTC (rev 55227)
+++ branches/soc-2008-mxcurioni/source/blender/blenloader/intern/readfile.c	2013-03-13 06:44:43 UTC (rev 55228)
@@ -9094,6 +9094,64 @@
 				linestyle->rounds = 3;
 		}
 	}
+	/* The code segment below will be removed when the trunk merger is done.
+	   For now it is kept for backward compatibility, giving branch users time
+	   to migrate to the new CustomData-based edge/face marks. */
+	{
+		Mesh *me;
+		MEdge *medge;
+		MPoly *mpoly;
+		int i, found;
+
+		for (me = main->mesh.first; me; me = me->id.next) {
+			/* Freestyle edge marks */
+			found = 0;
+			medge = me->medge;
+			for (i = 0; i < me->totedge; i++) {
+				if (medge->flag & ME_FREESTYLE_EDGE) {
+					found = 1;
+					break;
+				}
+				medge++;
+			}
+			if (found) {
+				FreestyleEdge *fed = CustomData_add_layer(&me->edata, CD_FREESTYLE_EDGE, CD_CALLOC, NULL, me->totedge);
+				medge = me->medge;
+				for (i = 0; i < me->totedge; i++) {
+					if (medge->flag & ME_FREESTYLE_EDGE) {
+						medge->flag &= ~ME_FREESTYLE_EDGE;
+						fed->flag |= FREESTYLE_EDGE_MARK;
+					}
+					medge++;
+					fed++;
+				}
+				printf("Migrated to CustomData-based Freestyle edge marks\n");
+			}
+			/* Freestyle face marks */
+			found = 0;
+			mpoly = me->mpoly;
+			for (i = 0; i < me->totpoly; i++) {
+				if (mpoly->flag & ME_FREESTYLE_FACE) {
+					found = 1;
+					break;
+				}
+				mpoly++;
+			}
+			if (found) {
+				FreestyleFace *ffa = CustomData_add_layer(&me->pdata, CD_FREESTYLE_FACE, CD_CALLOC, NULL, me->totpoly);
+				mpoly = me->mpoly;
+				for (i = 0; i < me->totpoly; i++) {
+					if (mpoly->flag & ME_FREESTYLE_FACE) {
+						mpoly->flag &= ~ME_FREESTYLE_FACE;
+						ffa->flag |= FREESTYLE_FACE_MARK;
+					}
+					mpoly++;
+					ffa++;
+				}
+				printf("Migrated to CustomData-based Freestyle face marks\n");
+			}
+		}
+	}
 #endif
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: branches/soc-2008-mxcurioni/source/blender/bmesh/bmesh_class.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/bmesh/bmesh_class.h	2013-03-13 06:36:27 UTC (rev 55227)
+++ branches/soc-2008-mxcurioni/source/blender/bmesh/bmesh_class.h	2013-03-13 06:44:43 UTC (rev 55228)
@@ -246,9 +246,6 @@
 
 	/* spare tag, assumed dirty, use define in each function to name based on use */
 	// _BM_ELEM_TAG_ALT = (1 << 6),  // UNUSED
-#ifdef WITH_FREESTYLE
-	BM_ELEM_FREESTYLE = (1 << 6), /* used for Freestyle faces and edges */
-#endif
 
 	BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
                                      * since tools may want to tag verts and

Modified: branches/soc-2008-mxcurioni/source/blender/bmesh/intern/bmesh_construct.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/bmesh/intern/bmesh_construct.c	2013-03-13 06:36:27 UTC (rev 55227)
+++ branches/soc-2008-mxcurioni/source/blender/bmesh/intern/bmesh_construct.c	2013-03-13 06:44:43 UTC (rev 55228)
@@ -1002,28 +1002,18 @@
 }
 char BM_edge_flag_from_mflag(const short meflag)
 {
-	return ( ((meflag & SELECT)            ? BM_ELEM_SELECT    : 0) |
-	         ((meflag & ME_SEAM)           ? BM_ELEM_SEAM      : 0) |
-	         ((meflag & ME_EDGEDRAW)       ? BM_ELEM_DRAW      : 0) |
-	         ((meflag & ME_SHARP) == 0     ? BM_ELEM_SMOOTH    : 0) | /* invert */
-	         ((meflag & ME_HIDE)           ? BM_ELEM_HIDDEN    : 0) |
-#ifdef WITH_FREESTYLE
-	         ((meflag & ME_FREESTYLE_EDGE) ? BM_ELEM_FREESTYLE : 0)
-#else
-	         0
-#endif
+	return ( ((meflag & SELECT)        ? BM_ELEM_SELECT : 0) |
+	         ((meflag & ME_SEAM)       ? BM_ELEM_SEAM   : 0) |
+	         ((meflag & ME_EDGEDRAW)   ? BM_ELEM_DRAW   : 0) |
+	         ((meflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0) | /* invert */
+	         ((meflag & ME_HIDE)       ? BM_ELEM_HIDDEN : 0)
 	         );
 }
 char BM_face_flag_from_mflag(const char  meflag)
 {
-	return ( ((meflag & ME_FACE_SEL)       ? BM_ELEM_SELECT    : 0) |
-	         ((meflag & ME_SMOOTH)         ? BM_ELEM_SMOOTH    : 0) |
-	         ((meflag & ME_HIDE)           ? BM_ELEM_HIDDEN    : 0) |
-#ifdef WITH_FREESTYLE
-	         ((meflag & ME_FREESTYLE_FACE) ? BM_ELEM_FREESTYLE : 0)
-#else
-	         0
-#endif
+	return ( ((meflag & ME_FACE_SEL)  ? BM_ELEM_SELECT : 0) |
+	         ((meflag & ME_SMOOTH)    ? BM_ELEM_SMOOTH : 0) |
+	         ((meflag & ME_HIDE)      ? BM_ELEM_HIDDEN : 0)
 	         );
 }
 
@@ -1041,15 +1031,12 @@
 {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list