[Bf-blender-cvs] [c569634b721] greasepencil-object: WIP: More work on modifiers

Antonio Vazquez noreply at git.blender.org
Mon Jul 17 13:40:55 CEST 2017


Commit: c569634b7217796737d791ca677321c968e178a2
Author: Antonio Vazquez
Date:   Mon Jul 17 12:05:44 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBc569634b7217796737d791ca677321c968e178a2

WIP: More work on modifiers

Add new modifier for thickness and reorganize code

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
M	source/blender/modifiers/intern/MOD_gpencilnoise.c
M	source/blender/modifiers/intern/MOD_gpencilsubdiv.c
A	source/blender/modifiers/intern/MOD_gpencilthick.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 011c7a4fdb7..84ad120a97d 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1556,6 +1556,21 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col = split.column()
         row = col.row(align=True)
         row.prop(md, "level")
+        row.prop(md, "simple", text="", icon="PARTICLE_POINT")
+        col.prop(md, "passindex", text="Pass")
+
+
+        col = split.column()
+        col.label("Layer:")
+        col.prop_search(md, "layer", gpd, "layers", text="", icon="GREASEPENCIL")
+
+    def GP_THICK(self, layout, ob, md):
+        gpd = ob.grease_pencil
+        split = layout.split()
+
+        col = split.column()
+        row = col.row(align=True)
+        row.prop(md, "thickness")
         col.prop(md, "passindex", text="Pass")
 
         col = split.column()
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 958ae44fead..df1f9daab45 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -45,6 +45,7 @@ struct BoundBox;
 struct Object;
 struct GpencilNoiseModifierData;
 struct GpencilSubdivModifierData;
+struct GpencilThickModifierData;
 
 /* ------------ Grease-Pencil API ------------------ */
 
@@ -137,5 +138,6 @@ struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
 void ED_gpencil_stroke_modifiers(struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 void ED_gpencil_noise_modifier(struct GpencilNoiseModifierData *mmd, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 void ED_gpencil_subdiv_modifier(struct GpencilSubdivModifierData *mmd, struct bGPDlayer *gpl, struct bGPDstroke *gps);
+void ED_gpencil_thick_modifier(struct GpencilThickModifierData *mmd, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 
 #endif /*  __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index ce13e385114..d83adefaa31 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1526,6 +1526,28 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
 }
 
 /********************  Modifiers **********************************/
+/* verify if valid layer and pass index */
+static bool is_stroke_affected_by_modifier(char *mlayername, int mpassindex, int minpoints, bGPDlayer *gpl, bGPDstroke *gps)
+{
+	/* omit if filter by layer */
+	if (mlayername[0] != '\0') {
+		if (!STREQ(mlayername, gpl->info)) {
+			return false;
+		}
+	}
+	/* verify pass */
+	if (gps->palcolor->index != mpassindex) {
+		return false;
+	}
+
+	/* need to have a minimum number of points */
+	if ((minpoints > 0) && (gps->totpoints < minpoints)) {
+		return false;
+	}
+
+	return true;;
+}
+
 /* calculate stroke normal using some points */
 static void ED_gpencil_stroke_normal(const bGPDstroke *gps, float r_normal[3])
 {
@@ -1565,18 +1587,7 @@ void ED_gpencil_noise_modifier(GpencilNoiseModifierData *mmd, bGPDlayer *gpl, bG
 	float normal[3];
 	float vec1[3], vec2[3];
 
-	/* Need three points or more */
-	if (gps->totpoints < 3) {
-		return;
-	}
-	/* omit if filter by layer */
-	if (mmd->layername[0] != '\0') {
-		if (!STREQ(mmd->layername, gpl->info)) {
-			return;
-		}
-	}
-	/* verify pass */
-	if (gps->palcolor->index != mmd->passindex) {
+	if (!is_stroke_affected_by_modifier(mmd->layername, mmd->passindex, 3, gpl, gps)) {
 		return;
 	}
 
@@ -1647,17 +1658,7 @@ void ED_gpencil_subdiv_modifier(GpencilSubdivModifierData *mmd, bGPDlayer *gpl,
 	int totnewpoints, oldtotpoints;
 	int i2;
 
-	if (gps->totpoints < 2) {
-		return;
-	}
-	/* omit if filter by layer */
-	if (mmd->layername[0] != '\0') {
-		if (!STREQ(mmd->layername, gpl->info)) {
-			return;
-		}
-	}
-	/* verify pass */
-	if (gps->palcolor->index != mmd->passindex) {
+	if (!is_stroke_affected_by_modifier(mmd->layername, mmd->passindex, 2, gpl, gps)) {
 		return;
 	}
 
@@ -1707,6 +1708,16 @@ void ED_gpencil_subdiv_modifier(GpencilSubdivModifierData *mmd, bGPDlayer *gpl,
 	}
 }
 
+/* subdivision surface */
+void ED_gpencil_thick_modifier(GpencilThickModifierData *mmd, bGPDlayer *gpl, bGPDstroke *gps)
+{
+	if (!is_stroke_affected_by_modifier(mmd->layername, mmd->passindex, 0, gpl, gps)) {
+		return;
+	}
+
+	gps->thickness += mmd->thickness;
+}
+
 /* apply stroke modifiers */
 void ED_gpencil_stroke_modifiers(Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
 {
@@ -1720,10 +1731,14 @@ void ED_gpencil_stroke_modifiers(Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
 			case eModifierType_GpencilNoise:
 				ED_gpencil_noise_modifier((GpencilNoiseModifierData *)md, gpl, gps);
 				break;
-				// Noise Modifier
+			// Subdiv Modifier
 			case eModifierType_GpencilSubdiv:
 				ED_gpencil_subdiv_modifier((GpencilSubdivModifierData *)md, gpl, gps);
 				break;
+			// Subdiv Surface
+			case eModifierType_GpencilThick:
+				ED_gpencil_thick_modifier((GpencilThickModifierData *)md, gpl, gps);
+				break;
 			default:
 				break;
 			}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 1cbf8de4ed6..20999e09271 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -494,11 +494,12 @@ static void gpencil_add_fill_shgroup(GpencilBatchCache *cache, DRWShadingGroup *
 
 /* add stroke shading group to pass */
 static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup *strokegrp,
-	Object *ob, bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps, 
+	Object *ob, bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps,
 	const float opacity, const float tintcolor[4], const bool onion, const bool custonion)
 {
 	float tcolor[4];
 	float ink[4];
+	short sthickness;
 	bool is_edit = (bool)(gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE));
 
 	/* set color using palette, tint color and opacity */
@@ -516,40 +517,39 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
 			copy_v4_v4(ink, tcolor);
 		}
 	}
-	short sthickness = gps->thickness + gpl->thickness;
-	if (sthickness > 0) {
-		if (cache->is_dirty) {
-			/* apply modifiers */
-			bGPDstroke *gps_mod;
-			if ((ob->modifiers.first) && (!is_edit)) {
-			//if (ob->modifiers.first) {
-				gps_mod = MEM_dupallocN(gps);
-				gps_mod->points = MEM_dupallocN(gps->points);
-				gps_mod->triangles = MEM_dupallocN(gps->triangles);
-				ED_gpencil_stroke_modifiers(ob, gpl, gps_mod);
-			}
-			else {
-				gps_mod = gps;
-			}
-			gpencil_batch_cache_check_free_slots(gpd);
-			if ((gps->totpoints > 1) && (gps->palcolor->stroke_style != STROKE_STYLE_VOLUMETRIC)) {
-				cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_stroke_geom(gpf, gps_mod, sthickness, ink);
-			}
-			else {
-				cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_point_geom(gps_mod, sthickness, ink);
-			}
 
-			/* free modifier temp data */
-			if ((ob->modifiers.first) && (!is_edit)) {
-				MEM_SAFE_FREE(gps_mod->triangles);
-				MEM_SAFE_FREE(gps_mod->points);
-				MEM_SAFE_FREE(gps_mod);
-			}
+	if (cache->is_dirty) {
+		/* apply modifiers */
+		bGPDstroke *gps_mod;
+		if ((ob->modifiers.first) && (!is_edit)) {
+			gps_mod = MEM_dupallocN(gps);
+			gps_mod->points = MEM_dupallocN(gps->points);
+			gps_mod->triangles = MEM_dupallocN(gps->triangles);
+			gps_mod->palcolor = MEM_dupallocN(gps->palcolor);
+			ED_gpencil_stroke_modifiers(ob, gpl, gps_mod);
+		}
+		else {
+			gps_mod = gps;
+		}
+		sthickness = gps_mod->thickness + gpl->thickness;
+		CLAMP_MIN(sthickness, 1);
+		gpencil_batch_cache_check_free_slots(gpd);
+		if ((gps_mod->totpoints > 1) && (gps_mod->palcolor->stroke_style != STROKE_STYLE_VOLUMETRIC)) {
+			cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_stroke_geom(gpf, gps_mod, sthickness, ink);
+		}
+		else {
+			cache->batch_stroke[cache->cache_idx] = DRW_gpencil_get_point_geom(gps_mod, sthickness, ink);
+		}
+		/* free modifier temp data */
+		if ((ob->modifiers.first) && (!is_edit)) {
+			MEM_SAFE_FREE(gps_mod->triangles);
+			MEM_SAFE_FREE(gps_mod->points);
+			MEM_SAFE_FREE(gps_mod->palcolor);
+			MEM_SAFE_FREE(gps_mod);
 		}
-		DRW_shgroup_call_add(strokegrp, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
 	}
+	DRW_shgroup_call_add(strokegrp, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
 }
-
 /* add edit points shading group to pass */
 static void gpencil_add_editpoints_shgroup(GPENCIL_StorageList *stl, GpencilBatchCache *cache, ToolSettings *ts,
 	Object *ob, bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index b44eb1a79d0..796204f49f2 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -89,6 +89,7 @@ typedef enum ModifierType {
 	eModifierType_SurfaceDeform     = 53,
 	eModifierType_GpencilNoise      = 54,
 	eModifierType_GpencilSubdiv     = 55,
+	eModifierType_GpencilThick    = 56,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1623,12 +1624,12 @@ typedef struct GpencilNoiseModifierData {
 	char pad[4];
 } GpencilNoiseModifierData;
 
-typedef enum eGpencilSubdiv_Flag {
+typedef enum eGpencilNoise_Flag {
 	GP_NOISE_USE_RANDOM     = (1 << 0),
 	GP_NOISE_MOD_LOCATION   = (1 << 1),
 	GP_NOISE_MOD_STRENGTH   = (1 << 2),
 	GP_NOISE_MOD_THICKNESS  = (1 << 3),
-} eGpencilSubdiv_Flag;
+} eGpencilNoise_Flag;
 
 
 typedef struct GpencilSubdivModifierData {
@@ -1640,6 +1641,19 @@ typedef struct GpencilSubdivModifierData {
 	char pad[4];
 } GpencilSubdivModifierData;
 
+typedef enum eGpencilSubdiv_Flag {
+	GP_SUBDIV_SIMPLE      = (1 << 0),
+} eGpencilSubdiv_Flag;
+
+typedef struct GpencilThickModifierData {
+	ModifierData modifier;
+	char layername[64];          /* layer name */
+	int passindex;               /* custom index for passes */
+	int flag;                    /* flags */
+	int thickness;          

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list