[Bf-blender-cvs] [da957a2678d] greasepencil-object: More changes to noise modifier

Antonio Vazquez noreply at git.blender.org
Sun Jul 16 17:43:24 CEST 2017


Commit: da957a2678d938fdfae125dbbec505417535a395
Author: Antonio Vazquez
Date:   Sun Jul 16 13:24:55 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBda957a2678d938fdfae125dbbec505417535a395

More changes to noise modifier

Apply more changes and add support functions for apply, remove, etc.

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

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/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
D	source/blender/draw/engines/gpencil/gpencil_modifier.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_gpencilnoise.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8d5b5b12af1..169ec07c6b3 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1533,12 +1533,21 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         split = layout.split()
 
         col = split.column()
-        col.prop_search(md, "layer", gpd, "layers", text="", icon="GREASEPENCIL")
+        row = col.row(align=True)
+        row.prop(md, "factor")
+        row.prop(md, "random", text="", icon="TIME", toggle=True)
         col.prop(md, "passindex", text="Pass")
 
         col = split.column()
-        col.prop(md, "factor")
-        col.prop(md, "seed", text="Seed")
+        col.label("Layer:")
+        col.prop_search(md, "layer", gpd, "layers", text="", icon="GREASEPENCIL")
+
+        row = layout.row(align=True)
+        row.label("Affect:")
+        row = layout.row(align=True)
+        row.prop(md, "affect_position", text="Position", icon='MESH_DATA', toggle=True)
+        row.prop(md, "affect_strength", text="Strength", icon='COLOR', toggle=True)
+        row.prop(md, "affect_thickness", text="Thickness", icon='LINE_DATA', toggle=True)
 
 classes = (
     DATA_PT_modifiers,
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index b43c91a09a5..e0e2da5dd8b 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -43,6 +43,7 @@ struct Main;
 struct PaletteColor;
 struct BoundBox;
 struct Object;
+struct GpencilNoiseModifierData;
 
 /* ------------ Grease-Pencil API ------------------ */
 
@@ -131,4 +132,8 @@ void BKE_gpencil_palettecolor_delete_allstrokes(struct PaletteColor *palcolor);
 /* object boundbox */
 struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
 
+/* modifiers */
+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);
+
 #endif /*  __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 910f8457625..8b42b50c2bd 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -40,6 +40,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_math_vector.h"
 #include "BLI_string_utils.h"
+#include "BLI_rand.h"
 
 #include "BLT_translation.h"
 
@@ -48,6 +49,7 @@
 #include "DNA_userdef_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_modifier_types.h"
 
 #include "BKE_action.h"
 #include "BKE_animsys.h"
@@ -64,14 +66,14 @@ void(*BKE_gpencil_batch_cache_free_cb)(bGPdata *gpd) = NULL;
 
 void BKE_gpencil_batch_cache_dirty(bGPdata *gpd)
 {
-	if (gpd->batch_cache) {
+	if ((gpd) && (gpd->batch_cache)) {
 		BKE_gpencil_batch_cache_dirty_cb(gpd);
 	}
 }
 
 void BKE_gpencil_batch_cache_free(bGPdata *gpd)
 {
-	if (gpd->batch_cache) {
+	if ((gpd) && (gpd->batch_cache)) {
 		BKE_gpencil_batch_cache_free_cb(gpd);
 	}
 }
@@ -1541,3 +1543,138 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
 
 	return ob->bb;
 }
+
+/********************  Modifiers **********************************/
+/* calculate stroke normal using some points */
+static void ED_gpencil_stroke_normal(const bGPDstroke *gps, float r_normal[3])
+{
+	if (gps->totpoints < 3) {
+		zero_v3(r_normal);
+		return;
+	}
+
+	bGPDspoint *points = gps->points;
+	int totpoints = gps->totpoints;
+
+	const bGPDspoint *pt0 = &points[0];
+	const bGPDspoint *pt1 = &points[1];
+	const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
+
+	float vec1[3];
+	float vec2[3];
+
+	/* initial vector (p0 -> p1) */
+	sub_v3_v3v3(vec1, &pt1->x, &pt0->x);
+
+	/* point vector at 3/4 */
+	sub_v3_v3v3(vec2, &pt3->x, &pt0->x);
+
+	/* vector orthogonal to polygon plane */
+	cross_v3_v3v3(r_normal, vec1, vec2);
+
+	/* Normalize vector */
+	normalize_v3(r_normal);
+}
+
+/* calculate a noise base on stroke direction */
+void ED_gpencil_noise_modifier(GpencilNoiseModifierData *mmd, bGPDlayer *gpl, bGPDstroke *gps)
+{
+	bGPDspoint *pt0, *pt1;
+	float shift, vran, vdir;
+	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) {
+		return;
+	}
+
+	/* calculate stroke normal*/
+	ED_gpencil_stroke_normal(gps, normal);
+
+	/* move points (starting in point 2) */
+	for (int i = 1; i < gps->totpoints - 1; i++) {
+		pt0 = &gps->points[i - 1];
+		pt1 = &gps->points[i];
+		/* initial vector (p0 -> p1) */
+		sub_v3_v3v3(vec1, &pt1->x, &pt0->x);
+		vran = len_v3(vec1);
+		/* vector orthogonal to normal */
+		cross_v3_v3v3(vec2, vec1, normal);
+		normalize_v3(vec2);
+		/* use random noise */
+		if (mmd->flag & GP_NOISE_USE_RANDOM) {
+			vran = BLI_frand();
+			vdir = BLI_frand();
+		}
+		else {
+			vran = 1.0f;
+			vdir = i % 2;
+		}
+
+		/* apply randomness to location of the point */
+		if (mmd->flag & GP_NOISE_MOD_LOCATION) {
+			/* factor is too sensitive, so need divide */
+			shift = vran * mmd->factor / 10.0f;
+			if (vdir > 0.5f) {
+				mul_v3_fl(vec2, shift);
+			}
+			else {
+				mul_v3_fl(vec2, shift * -1.0f);
+			}
+			add_v3_v3(&pt1->x, vec2);
+		}
+
+		/* apply randomness to thickness */
+		if (mmd->flag & GP_NOISE_MOD_THICKNESS) {
+			if (vdir > 0.5f) {
+				pt1->pressure -= pt1->pressure * vran * mmd->factor;
+			}
+			else {
+				pt1->pressure += pt1->pressure * vran * mmd->factor;;
+			}
+			CLAMP_MIN(pt1->pressure, GPENCIL_STRENGTH_MIN);
+		}
+
+		/* apply randomness to color strength */
+		if (mmd->flag & GP_NOISE_MOD_STRENGTH) {
+			if (vdir > 0.5f) {
+				pt1->strength -= pt1->strength * vran * mmd->factor;
+			}
+			else {
+				pt1->strength += pt1->strength * vran * mmd->factor;
+			}
+			CLAMP_MIN(pt1->strength, GPENCIL_STRENGTH_MIN);
+		}
+	}
+}
+
+/* apply stroke modifiers */
+void ED_gpencil_stroke_modifiers(Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
+{
+	ModifierData *md;
+
+	for (md = ob->modifiers.first; md; md = md->next) {
+		if (((md->mode & eModifierMode_Realtime) && ((G.f & G_RENDER_OGL) == 0)) ||
+			((md->mode & eModifierMode_Render) && (G.f & G_RENDER_OGL))) {
+			switch (md->type) {
+				// Noise Modifier
+			case eModifierType_GpencilNoise:
+				ED_gpencil_noise_modifier((GpencilNoiseModifierData *)md, gpl, gps);
+				break;
+			default:
+				break;
+			}
+		}
+	}
+}
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 7a974db07e0..85a0850d11b 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -91,7 +91,6 @@ set(SRC
 	engines/gpencil/gpencil_engine.c
 	engines/gpencil/gpencil_draw_cache_impl.c
 	engines/gpencil/gpencil_geom.c
-	engines/gpencil/gpencil_modifier.c
 
 	DRW_engine.h
 	intern/DRW_render.h
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 a532c87a1b8..3d8fbb1ae2a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -502,6 +502,7 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
 {
 	float tcolor[4];
 	float ink[4];
+	bool is_edit = (bool)(gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE));
 
 	/* set color using palette, tint color and opacity */
 	if (!onion) {
@@ -523,11 +524,12 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
 		if (cache->is_dirty) {
 			/* apply modifiers */
 			bGPDstroke *gps_mod;
-			if (ob->modifiers.first) {
+			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_apply_modifiers(ob, gps_mod);
+				ED_gpencil_stroke_modifiers(ob, gpl, gps_mod);
 			}
 			else {
 				gps_mod = gps;
@@ -541,7 +543,7 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
 			}
 
 			/* free modifier temp data */
-			if (ob->modifiers.first) {
+			if ((ob->modifiers.first) && (!is_edit)) {
 				MEM_SAFE_FREE(gps_mod->triangles);
 				MEM_SAFE_FREE(gps_mod->points);
 				MEM_SAFE_FREE(gps_mod);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index d570b219369..cbe4fd0d19a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -29,6 +29,7 @@
 #include "GPU_batch.h"
 
 struct tGPspoint;
+struct ModifierData;
 
  /* TODO: these could be system parameter in userprefs screen */
 #define GPENCIL_CACHE_BLOCK_SIZE 8 
@@ -181,6 +182,4 @@ bool gpencil_can_draw_stroke(const struct bGPDstroke *gps, const bool onion);
 struct tGPencilObjectCache *gpencil_object_cache_allocate(struct tGPencilObjectCache *cache, int *gp_cache_size, int *gp_cache_used);
 void gpencil_object_cache_add(struct tGPencilObjectCache *cache, struct Object *ob, int *gp_cache_used);
 
-void ED_gpencil_apply_modifiers(struct Object *ob, struct bGPDstroke *gps);
-
 #endif /* __GPENCIL_ENGINE_H__ */
diff --git a/source/blender/draw/engines/gpencil/gpencil_modifier.c b/source/blender/draw/engines/gpencil/gpencil_modifier.c
deleted file mode 100644
index de4db3c27dd..00000000000
--- a/source/blender/draw/engines/gpencil/gpencil_modifier.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list