[Bf-blender-cvs] [3474115e734] greasepencil-object: WIP: First modifier for grease pencil
Antonio Vazquez
noreply at git.blender.org
Sun Jul 16 17:43:23 CEST 2017
Commit: 3474115e734b386bddd639c951de9fe6704b4058
Author: Antonio Vazquez
Date: Sat Jul 15 19:46:06 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB3474115e734b386bddd639c951de9fe6704b4058
WIP: First modifier for grease pencil
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_modifier.h
M source/blender/blenkernel/intern/object.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
A 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/editors/space_buttons/buttons_context.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
A source/blender/modifiers/intern/MOD_gpencilnoise.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 05321ee4486..8d5b5b12af1 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1528,6 +1528,17 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
if md.rest_source == 'BIND':
layout.operator("object.correctivesmooth_bind", text="Unbind" if is_bind else "Bind")
+ def GP_NOISE(self, layout, ob, md):
+ gpd = ob.grease_pencil
+ split = layout.split()
+
+ col = split.column()
+ col.prop_search(md, "layer", gpd, "layers", text="", icon="GREASEPENCIL")
+ col.prop(md, "passindex", text="Pass")
+
+ col = split.column()
+ col.prop(md, "factor")
+ col.prop(md, "seed", text="Seed")
classes = (
DATA_PT_modifiers,
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 95f28f8fa6f..0a94158bd2e 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -70,6 +70,8 @@ typedef enum {
* of the object, rather some of its CustomData layers.
* E.g. UVProject and WeightVG modifiers. */
eModifierTypeType_NonGeometrical,
+ /* specila mode for grease pencil modifiers */
+ eModifierTypeType_Gpencil,
} ModifierTypeType;
typedef enum {
@@ -104,6 +106,8 @@ typedef enum {
/* For modifiers that use CD_PREVIEW_MCOL for preview. */
eModifierTypeFlag_UsesPreview = (1 << 9),
eModifierTypeFlag_AcceptsLattice = (1 << 10),
+ /* Grease pencil modifiers (do not change mesh, only is placeholder) */
+ eModifierTypeFlag_GpencilMod = (1 << 11),
} ModifierTypeFlag;
/* IMPORTANT! Keep ObjectWalkFunc and IDWalkFunc signatures compatible. */
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index c2472685fca..083e75fd9ea 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -255,16 +255,25 @@ bool BKE_object_support_modifier_type_check(Object *ob, int modifier_type)
mti = modifierType_getInfo(modifier_type);
/* only geometry objects should be able to get modifiers [#25291] */
- if (!ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
+ if (!ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
return false;
}
+ if (ob->type == OB_GPENCIL) {
+ if (mti->flags & eModifierTypeFlag_GpencilMod) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
if (ob->type == OB_LATTICE && (mti->flags & eModifierTypeFlag_AcceptsLattice) == 0) {
return false;
}
if (!((mti->flags & eModifierTypeFlag_AcceptsCVs) ||
- (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh))))
+ (ob->type == OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh))))
{
return false;
}
@@ -277,7 +286,7 @@ void BKE_object_link_modifiers(struct Object *ob_dst, const struct Object *ob_sr
ModifierData *md;
BKE_object_free_modifiers(ob_dst);
- if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE)) {
+ if (!ELEM(ob_dst->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_LATTICE, OB_GPENCIL)) {
/* only objects listed above can have modifiers and linking them to objects
* which doesn't have modifiers stack is quite silly */
return;
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 85a0850d11b..7a974db07e0 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -91,6 +91,7 @@ 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 01ee830d451..a532c87a1b8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -497,7 +497,7 @@ 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,
- 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];
@@ -523,10 +523,15 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
if (cache->is_dirty) {
/* apply modifiers */
bGPDstroke *gps_mod;
- gps_mod = MEM_dupallocN(gps);
- gps_mod->points = MEM_dupallocN(gps->points);
- gps_mod->triangles = MEM_dupallocN(gps->triangles);
-
+ 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);
+ }
+ 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);
@@ -536,9 +541,11 @@ static void gpencil_add_stroke_shgroup(GpencilBatchCache *cache, DRWShadingGroup
}
/* free modifier temp data */
- MEM_SAFE_FREE(gps_mod->triangles);
- MEM_SAFE_FREE(gps_mod->points);
- MEM_SAFE_FREE(gps_mod);
+ if (ob->modifiers.first) {
+ MEM_SAFE_FREE(gps_mod->triangles);
+ MEM_SAFE_FREE(gps_mod->points);
+ MEM_SAFE_FREE(gps_mod);
+ }
}
DRW_shgroup_call_add(strokegrp, cache->batch_stroke[cache->cache_idx], gpf->viewmatrix);
}
@@ -626,7 +633,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
gpencil_add_fill_shgroup(cache, fillgrp, gpd, gpl, gpf, gps, tintcolor, onion, custonion);
}
/* stroke */
- gpencil_add_stroke_shgroup(cache, strokegrp, gpd, gpl, gpf, gps, opacity, tintcolor, onion, custonion);
+ gpencil_add_stroke_shgroup(cache, strokegrp, ob, gpd, gpl, gpf, gps, opacity, tintcolor, onion, custonion);
/* edit points (only in edit mode) */
if (!onion) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 4334ec7b859..d570b219369 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -181,4 +181,6 @@ 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
new file mode 100644
index 00000000000..de4db3c27dd
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/gpencil_modifier.c
@@ -0,0 +1,92 @@
+/*
+ * ***** 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 useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008, Blender Foundation
+ * This is a new part of Blender
+ *
+ * Contributor(s): Antonio Vazquez
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/gpencil/gpencil_modifier.c
+ * \ingroup edgpencil
+ */
+
+
+#include "DNA_gpencil_types.h"
+#include "DNA_object_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BLI_math.h"
+#include "BLI_rand.h"
+
+#include "BKE_gpencil.h"
+#include "ED_gpencil.h"
+
+/* calculate a noise base on stroke direction */
+static void ED_gpencil_noise_modifier(Object *ob, GpencilNoiseModifierData *mmd, bGPDstroke *gps)
+{
+ float normal[3];
+ float vec1[3], vec2[3];
+
+ /* Need three points or more */
+ if (gps->totpoints < 3) {
+ return;
+ }
+ /* calculate stroke normal*/
+ ED_gpencil_stroke_normal(gps, normal);
+
+ /* move points (starting in point 2) */
+ bGPDspoint *pt0, *pt1;
+ float shift;
+ for (int i = 1; i < gps->totpoints; i++) {
+ pt0 = &gps->points[i - 1];
+ pt1 = &gps->points[i];
+ /* initial vector (p0 -> p1) */
+ sub_v3_v3v3(vec1, &pt1->x, &pt0->x);
+ /* vector orthogonal to normal */
+ cross_v3_v3v3(vec2, vec1, normal);
+ normalize_v3(vec2);
+ shift = BLI_frand() * (mmd->seed / 10.0f) * mmd->factor;
+ if (BLI_frand() > 0.5f) {
+ mul_v3_fl(vec2, shift);
+ }
+ else {
+ mul_v3_fl(vec2, shift * -1.0f);
+ }
+ add_v3_v3(&pt1->x, vec2);
+ }
+}
+
+/* apply all modifiers */
+void ED_gpencil_apply_modifiers(Object *ob, bGPDstroke *gps)
+{
+ ModifierData *md;
+
+ for (md = ob->modifiers.first; md; md = md->next) {
+ if (md->mode & (eModifierMode_Realtime | eModifierMode_Render)) {
+ if (md->type == eModifierType_GpencilNoise) {
+ GpencilNoiseModifierData *mmd = (GpencilNoiseModifierData *)md;
+ ED_gpencil_noise_modifier(ob, mmd, gps);
+ }
+ }
+ }
+
+}
+
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index c99ba4
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list