[Bf-blender-cvs] [8bcc203ed70] temp-gpencil-bezier-stroke-type: GPencil: Add Bezier support to Lattice modifier
Antonio Vazquez
noreply at git.blender.org
Tue Mar 30 15:43:12 CEST 2021
Commit: 8bcc203ed707f6b6af008df9b7d6eac460654fca
Author: Antonio Vazquez
Date: Tue Mar 30 15:27:16 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB8bcc203ed707f6b6af008df9b7d6eac460654fca
GPencil: Add Bezier support to Lattice modifier
===================================================================
M source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
===================================================================
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
index 85908152f7a..eb936249ef1 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
@@ -75,6 +75,25 @@ static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
BKE_gpencil_modifier_copydata_generic(md, target);
}
+static bool do_modifier(Object *ob,
+ LatticeGpencilModifierData *mmd,
+ bGPDlayer *gpl,
+ bGPDstroke *gps)
+{
+ return is_stroke_affected_by_modifier(ob,
+ mmd->layername,
+ mmd->material,
+ mmd->pass_index,
+ mmd->layer_pass,
+ 1,
+ gpl,
+ gps,
+ mmd->flag & GP_LATTICE_INVERT_LAYER,
+ mmd->flag & GP_LATTICE_INVERT_PASS,
+ mmd->flag & GP_LATTICE_INVERT_LAYERPASS,
+ mmd->flag & GP_LATTICE_INVERT_MATERIAL);
+}
+
static void deformPolyline(GpencilModifierData *md,
Depsgraph *UNUSED(depsgraph),
Object *ob,
@@ -86,18 +105,7 @@ static void deformPolyline(GpencilModifierData *md,
LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md;
const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
- if (!is_stroke_affected_by_modifier(ob,
- mmd->layername,
- mmd->material,
- mmd->pass_index,
- mmd->layer_pass,
- 1,
- gpl,
- gps,
- mmd->flag & GP_LATTICE_INVERT_LAYER,
- mmd->flag & GP_LATTICE_INVERT_PASS,
- mmd->flag & GP_LATTICE_INVERT_LAYERPASS,
- mmd->flag & GP_LATTICE_INVERT_MATERIAL)) {
+ if (!do_modifier(ob, mmd, gpl, gps)) {
return;
}
@@ -122,6 +130,47 @@ static void deformPolyline(GpencilModifierData *md,
BKE_gpencil_stroke_geometry_update(gpd, gps);
}
+static void deformBezier(GpencilModifierData *md,
+ Depsgraph *UNUSED(depsgraph),
+ Object *ob,
+ bGPDlayer *gpl,
+ bGPDframe *UNUSED(gpf),
+ bGPDstroke *gps)
+{
+ bGPdata *gpd = ob->data;
+ LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md;
+ const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
+
+ if (!do_modifier(ob, mmd, gpl, gps)) {
+ return;
+ }
+
+ if (mmd->cache_data == NULL) {
+ return;
+ }
+
+ bGPDcurve *gpc = gps->editcurve;
+ for (int i = 0; i < gpc->tot_curve_points; i++) {
+ bGPDcurve_point *pt = &gpc->curve_points[i];
+ BezTriple *bezt = &pt->bezt;
+ MDeformVert *dvert = gpc->dvert != NULL ? &gpc->dvert[i] : NULL;
+
+ /* verify vertex group */
+ const float weight = get_modifier_point_weight(
+ dvert, (mmd->flag & GP_LATTICE_INVERT_VGROUP) != 0, def_nr);
+ if (weight < 0.0f) {
+ continue;
+ }
+ for (int j = 0; j < 3; j++) {
+ BKE_lattice_deform_data_eval_co(
+ (struct LatticeDeformData *)mmd->cache_data, bezt->vec[j], mmd->strength * weight);
+ }
+ }
+ /* Calc geometry data. */
+ gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE; /* Calc geometry data. */
+ BKE_gpencil_stroke_geometry_update(gpd, gps);
+}
+
/* FIXME: Ideally we be doing this on a copy of the main depsgraph
* (i.e. one where we don't have to worry about restoring state)
*/
@@ -272,7 +321,7 @@ GpencilModifierTypeInfo modifierType_Gpencil_Lattice = {
/* copyData */ copyData,
/* deformPolyline */ deformPolyline,
- /* deformBezier */ NULL,
+ /* deformBezier */ deformBezier,
/* generateStrokes */ NULL,
/* bakeModifier */ bakeModifier,
/* remapTime */ NULL,
More information about the Bf-blender-cvs
mailing list