[Bf-blender-cvs] [5eab1b3f212] greasepencil-edit-curve: GPencil: Include last GSoC commits

Antonio Vazquez noreply at git.blender.org
Sat Jun 6 11:53:08 CEST 2020


Commit: 5eab1b3f212ab1a79aafb2decbaa707ce577afb9
Author: Antonio Vazquez
Date:   Sat Jun 6 11:18:41 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB5eab1b3f212ab1a79aafb2decbaa707ce577afb9

GPencil: Include last GSoC commits

Minor update due merge error in writefile.c

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/gpencil/CMakeLists.txt
A	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 7f1047cec74..e351c678789 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -736,6 +736,12 @@ class VIEW3D_HT_header(Header):
                 row.prop(tool_settings, "use_gpencil_vertex_select_mask_stroke", text="")
                 row.prop(tool_settings, "use_gpencil_vertex_select_mask_segment", text="")
 
+            # Curve edit mode
+            if gpd.use_stroke_edit_mode:
+                row = layout.row(align=True)
+                row.prop(gpd, "use_curve_edit", text="",
+                         icon='IPO_BEZIER')
+
             if (
                     gpd.use_stroke_edit_mode or
                     gpd.is_stroke_sculpt_mode or
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 85ba8175143..3cf2a6dd259 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -48,6 +48,7 @@ struct bGPDlayer;
 struct bGPDlayer_Mask;
 struct bGPDspoint;
 struct bGPDstroke;
+struct bGPDcurve;
 struct bGPdata;
 
 #define GPENCIL_SIMPLIFY(scene) ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ENABLE))
@@ -89,6 +90,7 @@ struct bGPdata;
 
 void BKE_gpencil_free_point_weights(struct MDeformVert *dvert);
 void BKE_gpencil_free_stroke_weights(struct bGPDstroke *gps);
+void BKE_gpencil_free_stroke_editcurve(struct bGPDstroke *gps);
 void BKE_gpencil_free_stroke(struct bGPDstroke *gps);
 bool BKE_gpencil_free_strokes(struct bGPDframe *gpf);
 void BKE_gpencil_free_frames(struct bGPDlayer *gpl);
@@ -110,6 +112,7 @@ struct bGPdata *BKE_gpencil_data_addnew(struct Main *bmain, const char name[]);
 struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
 struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
 void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe *gpf_dst);
+struct bGPDcurve *BKE_gpencil_stroke_curve_duplicate(struct bGPDcurve *gpc_src);
 struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src, const bool dup_points);
 
 struct bGPdata *BKE_gpencil_copy(struct Main *bmain, const struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 75cd16f13a0..c606be6e16a 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -177,6 +177,20 @@ void BKE_gpencil_free_stroke_weights(bGPDstroke *gps)
   }
 }
 
+void BKE_gpencil_free_stroke_editcurve(bGPDstroke *gps)
+{
+  if (gps == NULL) {
+    return;
+  }
+  bGPDcurve *editcurve = gps->editcurve;
+  if (editcurve == NULL) {
+    return;
+  }
+  MEM_freeN(editcurve->curve_points);
+  MEM_freeN(editcurve->point_index_array);
+  MEM_freeN(editcurve);
+}
+
 /* free stroke, doesn't unlink from any listbase */
 void BKE_gpencil_free_stroke(bGPDstroke *gps)
 {
@@ -194,6 +208,9 @@ void BKE_gpencil_free_stroke(bGPDstroke *gps)
   if (gps->triangles) {
     MEM_freeN(gps->triangles);
   }
+  if (gps->editcurve != NULL) {
+    BKE_gpencil_free_stroke_editcurve(gps);
+  }
 
   MEM_freeN(gps);
 }
@@ -569,6 +586,8 @@ bGPDstroke *BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness)
 
   gps->mat_nr = mat_idx;
 
+  gps->editcurve = NULL;
+
   return gps;
 }
 
@@ -617,7 +636,20 @@ void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_d
   BKE_defvert_array_copy(gps_dst->dvert, gps_src->dvert, gps_src->totpoints);
 }
 
-/* make a copy of a given gpencil stroke */
+/* Make a copy of a given gpencil stroke editcurve */
+bGPDcurve *BKE_gpencil_stroke_curve_duplicate(bGPDcurve *gpc_src)
+{
+  bGPDcurve *gpc_dst = MEM_dupallocN(gpc_src);
+  gpc_dst->point_index_array = MEM_dupallocN(gpc_src->point_index_array);
+
+  if (gpc_src->curve_points != NULL) {
+    gpc_dst->curve_points = MEM_dupallocN(gpc_src->curve_points);
+  }
+
+  return gpc_dst;
+}
+
+/* Make a copy of a given gpencil stroke */
 bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src, const bool dup_points)
 {
   bGPDstroke *gps_dst = NULL;
@@ -638,6 +670,10 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src, const bool dup_poi
     }
   }
 
+  if (gps_src->editcurve != NULL) {
+    gps_dst->editcurve = BKE_gpencil_stroke_curve_duplicate(gps_src->editcurve);
+  }
+
   /* return new stroke */
   return gps_dst;
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0624ba5947a..f412e85a90f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7312,7 +7312,7 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
         /* relink stroke edit curve. */
         gps->editcurve = newdataadr(fd, gps->editcurve);
         if (gps->editcurve != NULL) {
-          gps->editcurve->curve = newdataadr(fd, gps->editcurve->curve);
+          gps->editcurve->curve_points = newdataadr(fd, gps->editcurve->curve_points);
           gps->editcurve->point_index_array = newdataadr(fd, gps->editcurve->point_index_array);
         }
 
@@ -11628,13 +11628,6 @@ static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd)
 {
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     expand_doit(fd, mainvar, gpl->parent);
-    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
-      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-        if ((gps->editcurve != NULL) && (gps->editcurve->curve != NULL)) {
-          expand_doit(fd, mainvar, gps->editcurve->curve);
-        }
-      }
-    }
   }
 
   for (int a = 0; a < gpd->totcol; a++) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 8c0ab7d972b..4a98d685d1c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2872,6 +2872,13 @@ static void write_gpencil(BlendWriter *writer, bGPdata *gpd, const void *id_addr
         LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
           BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points);
           BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles);
+          if (gps->editcurve != NULL) {
+            BLO_write_struct(writer, bGPDcurve, gps->editcurve);
+            BLO_write_struct_array(
+                writer, BezTriple, gps->editcurve->tot_curve_points, gps->editcurve->curve_points);
+            BLO_write_int32_array(
+                writer, gps->editcurve->tot_curve_points, gps->editcurve->point_index_array);
+          }
           write_dverts(writer, gps->totpoints, gps->dvert);
         }
       }
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 4083169d65c..b67d03b1c25 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC
   gpencil_convert.c
   gpencil_data.c
   gpencil_edit.c
+  gpencil_edit_curve.c
   gpencil_fill.c
   gpencil_interpolate.c
   gpencil_merge.c
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
new file mode 100644
index 00000000000..f19a4358a01
--- /dev/null
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -0,0 +1,132 @@
+/*
+ * 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
+ * Operators for editing Grease Pencil strokes
+ */
+
+/** \file
+ * \ingroup edgpencil
+ */
+
+#include <math.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_gpencil.h"
+
+#include "DEG_depsgraph.h"
+
+#include "gpencil_intern.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Test Operator for curve editing
+ * \{ */
+
+static bGPDcurve *create_example_gp_curve(int num_points)
+{
+  bGPDcurve *new_gp_curve = (bGPDcurve *)MEM_callocN(sizeof(bGPDcurve), __func__);
+  new_gp_curve->tot_curve_points = num_points;
+  new_gp_curve->curve_points = (BezTriple *)MEM_callocN(sizeof(BezTriple) * num_points, __func__);
+  new_gp_curve->point_index_array = (int *)MEM_callocN(sizeof(int) * num_points, __func__);
+
+  /* We just write some recognizable data to the BezTriple */
+  for (int i = 0; i < num_points; ++i) {
+    BezTriple *bezt = &new_gp_curve->curve_points[i];
+    for (int j = 0; j < 3; ++j) {
+      copy_v3_fl3(bezt->vec[j], i, j, i * j);
+    }
+    bezt->radius = 1.0f;
+    bezt->weight = 2.0f;
+  }
+  return new_gp_curve;
+}
+
+static int gp_write_stroke_curve_data_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = CTX_data_active_object(C);
+  bGPdata *gpd = ob->data;
+
+  int num_points = RNA_int_get(op->ptr, "num_points");
+
+  if (ELEM(NULL, gpd)) {
+    return OPERATOR_CANCELLED;
+  }
+
+  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+  bGPDframe *gpf = gpl->actframe;
+  if (ELEM(NULL, gpf)) {
+    return OPERATOR_CANCELLED;
+  }
+
+  LISTBASE_FOREACH (bG

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list