[Bf-blender-cvs] [31081018842] temp-gpencil-bezier-v2: GPencil: Offset modifier for curves

Falk David noreply at git.blender.org
Sat Mar 6 21:54:38 CET 2021


Commit: 310810188420af48246327022d1998146a95aa70
Author: Falk David
Date:   Sat Mar 6 21:51:33 2021 +0100
Branches: temp-gpencil-bezier-v2
https://developer.blender.org/rB310810188420af48246327022d1998146a95aa70

GPencil: Offset modifier for curves

This implementation is initialy added so it's easy to test runtime data
for curves.

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

M	source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
M	source/blender/makesdna/DNA_gpencil_types.h

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
index bc5dd763630..9b8db6ecea5 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
@@ -102,34 +102,62 @@ static void deformStroke(GpencilModifierData *md,
   }
   bGPdata *gpd = ob->data;
 
-  for (int i = 0; i < gps->totpoints; i++) {
-    bGPDspoint *pt = &gps->points[i];
-    MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
-
-    /* Verify vertex group. */
-    const float weight = get_modifier_point_weight(
-        dvert, (mmd->flag & GP_OFFSET_INVERT_VGROUP) != 0, def_nr);
-    if (weight < 0.0f) {
-      continue;
+  if (GPENCIL_STROKE_IS_CURVE(gps)) {
+    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_OFFSET_INVERT_VGROUP) != 0, def_nr);
+      if (weight < 0.0f) {
+        continue;
+      }
+      /* Calculate matrix. */
+      mul_v3_v3fl(loc, mmd->loc, weight);
+      mul_v3_v3fl(rot, mmd->rot, weight);
+      mul_v3_v3fl(scale, mmd->scale, weight);
+      add_v3_fl(scale, 1.0);
+      loc_eul_size_to_mat4(mat, loc, rot, scale);
+
+      /* Apply scale to thickness. */
+      float unit_scale = (scale[0] + scale[1] + scale[2]) / 3.0f;
+      pt->pressure *= unit_scale;
+
+      for (int j = 0; j < 3; j++) {
+        mul_m4_v3(mat, bezt->vec[j]);
+      }
     }
-    /* Calculate matrix. */
-    mul_v3_v3fl(loc, mmd->loc, weight);
-    mul_v3_v3fl(rot, mmd->rot, weight);
-    mul_v3_v3fl(scale, mmd->scale, weight);
-    add_v3_fl(scale, 1.0);
-    loc_eul_size_to_mat4(mat, loc, rot, scale);
-
-    /* Apply scale to thickness. */
-    float unit_scale = (scale[0] + scale[1] + scale[2]) / 3.0f;
-    pt->pressure *= unit_scale;
-
-    mul_m4_v3(mat, &pt->x);
+    gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
   }
-
-  if (GPENCIL_STROKE_IS_CURVE(gps)) {
-    gps->editcurve->flag |= GP_CURVE_NEEDS_STROKE_UPDATE;
+  else {
+    for (int i = 0; i < gps->totpoints; i++) {
+      bGPDspoint *pt = &gps->points[i];
+      MDeformVert *dvert = gps->dvert != NULL ? &gps->dvert[i] : NULL;
+
+      /* Verify vertex group. */
+      const float weight = get_modifier_point_weight(
+          dvert, (mmd->flag & GP_OFFSET_INVERT_VGROUP) != 0, def_nr);
+      if (weight < 0.0f) {
+        continue;
+      }
+      /* Calculate matrix. */
+      mul_v3_v3fl(loc, mmd->loc, weight);
+      mul_v3_v3fl(rot, mmd->rot, weight);
+      mul_v3_v3fl(scale, mmd->scale, weight);
+      add_v3_fl(scale, 1.0);
+      loc_eul_size_to_mat4(mat, loc, rot, scale);
+
+      /* Apply scale to thickness. */
+      float unit_scale = (scale[0] + scale[1] + scale[2]) / 3.0f;
+      pt->pressure *= unit_scale;
+
+      mul_m4_v3(mat, &pt->x);
+    }
   }
-
+  
   /* Calc geometry data. */
   BKE_gpencil_stroke_geometry_update(gpd, gps);
 }
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 54f21112e08..06aef507052 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -237,6 +237,10 @@ typedef struct bGPDcurve {
   short flag;
   char _pad[2];
   bGPDcurve_Runtime runtime;
+
+  /** Vertex weight data. */
+  struct MDeformVert *dvert;
+  void *_pad2;
 } bGPDcurve;
 
 /* bGPDcurve_Flag->flag */



More information about the Bf-blender-cvs mailing list