Commit: 52edc1a9c6e0c7ebc3d66ca96816b2f7e1a940fc
Author: Joshua Leung
Date:   Wed Nov 1 03:13:16 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB52edc1a9c6e0c7ebc3d66ca96816b2f7e1a940fc

Port Subdiv GP Modifier

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

M       source/blender/blenkernel/BKE_gpencil.h
M       source/blender/blenkernel/intern/gpencil_modifier.c
M       source/blender/modifiers/intern/MOD_gpencilsubdiv.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index 90f48d590c8..d2de9597a2f 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -201,7 +201,6 @@ void BKE_gpencil_geometry_modifiers(struct Object *ob, 
struct bGPDlayer *gpl, st
 
 void BKE_gpencil_stroke_normal(const struct bGPDstroke *gps, float 
r_normal[3]);
 
-void BKE_gpencil_subdiv_modifier(int id, struct GpencilSubdivModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 void BKE_gpencil_simplify_modifier(int id, struct GpencilSimplifyModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 void BKE_gpencil_array_modifier(int id, struct GpencilArrayModifierData *mmd, 
struct Object *ob, int elem_idx[3], float r_mat[4][4]);
 void BKE_gpencil_dupli_modifier(int id, struct GpencilDupliModifierData *mmd, 
struct Object *ob, struct bGPDlayer *gpl, struct bGPDframe *gpf);
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c 
b/source/blender/blenkernel/intern/gpencil_modifier.c
index 09259fb7215..4dce7ab4b36 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -98,90 +98,6 @@ void BKE_gpencil_stroke_normal(const bGPDstroke *gps, float 
r_normal[3])
        normalize_v3(r_normal);
 }
 
-/* subdivide stroke to get more control points */
-void BKE_gpencil_subdiv_modifier(
-        int UNUSED(id), GpencilSubdivModifierData *mmd, Object *UNUSED(ob), 
bGPDlayer *gpl, bGPDstroke *gps)
-{
-       bGPDspoint *temp_points;
-       int totnewpoints, oldtotpoints;
-       int i2;
-
-       if (!is_stroke_affected_by_modifier(
-               mmd->layername, mmd->pass_index, 3, gpl, gps,
-               mmd->flag & GP_SUBDIV_INVERSE_LAYER, mmd->flag & 
GP_SUBDIV_INVERSE_PASS))
-       {
-               return;
-       }
-
-       /* loop as many times as levels */
-       for (int s = 0; s < mmd->level; s++) {
-               totnewpoints = gps->totpoints - 1;
-               /* duplicate points in a temp area */
-               temp_points = MEM_dupallocN(gps->points);
-               oldtotpoints = gps->totpoints;
-
-               /* resize the points arrys */
-               gps->totpoints += totnewpoints;
-               gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * 
gps->totpoints);
-               gps->flag |= GP_STROKE_RECALC_CACHES;
-
-               /* move points from last to first to new place */
-               i2 = gps->totpoints - 1;
-               for (int i = oldtotpoints - 1; i > 0; i--) {
-                       bGPDspoint *pt = &temp_points[i];
-                       bGPDspoint *pt_final = &gps->points[i2];
-
-                       copy_v3_v3(&pt_final->x, &pt->x);
-                       pt_final->pressure = pt->pressure;
-                       pt_final->strength = pt->strength;
-                       pt_final->time = pt->time;
-                       pt_final->flag = pt->flag;
-                       pt_final->totweight = pt->totweight;
-                       pt_final->weights = pt->weights;
-                       i2 -= 2;
-               }
-               /* interpolate mid points */
-               i2 = 1;
-               for (int i = 0; i < oldtotpoints - 1; i++) {
-                       bGPDspoint *pt = &temp_points[i];
-                       bGPDspoint *next = &temp_points[i + 1];
-                       bGPDspoint *pt_final = &gps->points[i2];
-
-                       /* add a half way point */
-                       interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f);
-                       pt_final->pressure = interpf(pt->pressure, 
next->pressure, 0.5f);
-                       pt_final->strength = interpf(pt->strength, 
next->strength, 0.5f);
-                       CLAMP(pt_final->strength, GPENCIL_STRENGTH_MIN, 1.0f);
-                       pt_final->time = interpf(pt->time, next->time, 0.5f);
-                       pt_final->totweight = 0;
-                       pt_final->weights = NULL;
-                       i2 += 2;
-               }
-
-               MEM_SAFE_FREE(temp_points);
-
-               /* move points to smooth stroke (not simple flag )*/
-               if ((mmd->flag & GP_SUBDIV_SIMPLE) == 0) {
-                       /* duplicate points in a temp area with the new 
subdivide data */
-                       temp_points = MEM_dupallocN(gps->points);
-
-                       /* extreme points are not changed */
-                       for (int i = 0; i < gps->totpoints - 2; i++) {
-                               bGPDspoint *pt = &temp_points[i];
-                               bGPDspoint *next = &temp_points[i + 1];
-                               bGPDspoint *pt_final = &gps->points[i + 1];
-
-                               /* move point */
-                               interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 
0.5f);
-                       }
-                       /* free temp memory */
-                       MEM_SAFE_FREE(temp_points);
-               }
-       }
-}
-
-
-
 /* helper function to sort strokes using qsort */
 static int gpencil_stroke_cache_compare(const void *a1, const void *a2)
 {
@@ -644,10 +560,6 @@ void BKE_gpencil_stroke_modifiers(Object *ob, bGPDlayer 
*gpl, bGPDframe *UNUSED(
 
                        // XXX: The following lines need to all be converted to 
modifier callbacks...
                        switch (md->type) {
-                                       // Subdiv Modifier
-                               case eModifierType_GpencilSubdiv:
-                                       BKE_gpencil_subdiv_modifier(id, 
(GpencilSubdivModifierData *)md, ob, gpl, gps);
-                                       break;
                                        // Simplify Modifier
                                case eModifierType_GpencilSimplify:
                                        BKE_gpencil_simplify_modifier(id, 
(GpencilSimplifyModifierData *)md, ob, gpl, gps);
diff --git a/source/blender/modifiers/intern/MOD_gpencilsubdiv.c 
b/source/blender/modifiers/intern/MOD_gpencilsubdiv.c
index b76330bc4f7..e5cf6085874 100644
--- a/source/blender/modifiers/intern/MOD_gpencilsubdiv.c
+++ b/source/blender/modifiers/intern/MOD_gpencilsubdiv.c
@@ -30,10 +30,13 @@
 
 #include <stdio.h>
 
+#include "MEM_guardedalloc.h"
+
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
 #include "DNA_gpencil_types.h"
 
+#include "BLI_math.h"
 #include "BLI_utildefines.h"
  
 #include "BKE_context.h"
@@ -42,6 +45,7 @@
 #include "DEG_depsgraph.h"
 
 #include "MOD_modifiertypes.h"
+#include "MOD_gpencil_util.h"
 
 static void initData(ModifierData *md)
 {
@@ -57,7 +61,90 @@ static void copyData(ModifierData *md, ModifierData *target)
        modifier_copyData_generic(md, target);
 }
 
-static void bakeModifierGP(const bContext *C, const EvaluationContext 
*UNUSED(eval_ctx),
+/* subdivide stroke to get more control points */
+static void deformStroke(ModifierData *md, const EvaluationContext 
*UNUSED(eval_ctx),
+                         Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
+{
+       GpencilSubdivModifierData *mmd = (GpencilSubdivModifierData *)md;
+       bGPDspoint *temp_points;
+       int totnewpoints, oldtotpoints;
+       int i2;
+
+       if (!is_stroke_affected_by_modifier(
+               mmd->layername, mmd->pass_index, 3, gpl, gps,
+               mmd->flag & GP_SUBDIV_INVERSE_LAYER, mmd->flag & 
GP_SUBDIV_INVERSE_PASS))
+       {
+               return;
+       }
+
+       /* loop as many times as levels */
+       for (int s = 0; s < mmd->level; s++) {
+               totnewpoints = gps->totpoints - 1;
+               /* duplicate points in a temp area */
+               temp_points = MEM_dupallocN(gps->points);
+               oldtotpoints = gps->totpoints;
+
+               /* resize the points arrys */
+               gps->totpoints += totnewpoints;
+               gps->points = MEM_recallocN(gps->points, sizeof(*gps->points) * 
gps->totpoints);
+               gps->flag |= GP_STROKE_RECALC_CACHES;
+
+               /* move points from last to first to new place */
+               i2 = gps->totpoints - 1;
+               for (int i = oldtotpoints - 1; i > 0; i--) {
+                       bGPDspoint *pt = &temp_points[i];
+                       bGPDspoint *pt_final = &gps->points[i2];
+
+                       copy_v3_v3(&pt_final->x, &pt->x);
+                       pt_final->pressure = pt->pressure;
+                       pt_final->strength = pt->strength;
+                       pt_final->time = pt->time;
+                       pt_final->flag = pt->flag;
+                       pt_final->totweight = pt->totweight;
+                       pt_final->weights = pt->weights;
+                       i2 -= 2;
+               }
+               /* interpolate mid points */
+               i2 = 1;
+               for (int i = 0; i < oldtotpoints - 1; i++) {
+                       bGPDspoint *pt = &temp_points[i];
+                       bGPDspoint *next = &temp_points[i + 1];
+                       bGPDspoint *pt_final = &gps->points[i2];
+
+                       /* add a half way point */
+                       interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 0.5f);
+                       pt_final->pressure = interpf(pt->pressure, 
next->pressure, 0.5f);
+                       pt_final->strength = interpf(pt->strength, 
next->strength, 0.5f);
+                       CLAMP(pt_final->strength, GPENCIL_STRENGTH_MIN, 1.0f);
+                       pt_final->time = interpf(pt->time, next->time, 0.5f);
+                       pt_final->totweight = 0;
+                       pt_final->weights = NULL;
+                       i2 += 2;
+               }
+
+               MEM_SAFE_FREE(temp_points);
+
+               /* move points to smooth stroke (not simple flag )*/
+               if ((mmd->flag & GP_SUBDIV_SIMPLE) == 0) {
+                       /* duplicate points in a temp area with the new 
subdivide data */
+                       temp_points = MEM_dupallocN(gps->points);
+
+                       /* extreme points are not changed */
+                       for (int i = 0; i < gps->totpoints - 2; i++) {
+                               bGPDspoint *pt = &temp_points[i];
+                               bGPDspoint *next = &temp_points[i + 1];
+                               bGPDspoint *pt_final = &gps->points[i + 1];
+
+                               /* move point */
+                               interp_v3_v3v3(&pt_final->x, &pt->x, &next->x, 
0.5f);
+                       }
+                       /* free temp memory */
+                       MEM_SAFE_FREE(temp_points);
+               }
+       }
+}
+
+static void bakeModifierGP(const bContext *UNUSED(C), const EvaluationContext 
*eval_ctx,
                            ModifierData *md, Object *ob)
 {
        bGPdata *gpd = ob->data;
@@ -65,7 +152,7 @@ static void bakeModifierGP(const bContext *C, const 
EvaluationContext *UNUSED(ev
        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
                for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
                        for (bGPDstroke *gps = gpf->strokes.first; gps; gps = 
gps->next) {
-                               BKE_gpencil_subdiv_modifier(-1, 
(GpencilSubdivModifierData *)md, ob, gpl, gps);
+                               deformStroke(md, eval_ctx, ob, gpl, gps);
                        }
                }
        }
@@ -85,7 +172,7 @@ ModifierTypeInfo modifierType_GpencilSubdiv = {
        /* deformMatricesEM */  NULL,
        /* applyModifier */     NULL,
        /* applyModifierEM */   NULL,
-       /* deformStroke */      NULL,
+       /* deformStroke */      deformStroke,
        /* generateStrokes */   NULL,
        /* bakeModifierGP */    bakeModifierGP,
        /* initData */          initData,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to