[Bf-blender-cvs] [b1f2825ce1f] soc-2020-greasepencil-curve: GPencil: Add function to write sample data to edit curve

Falk David noreply at git.blender.org
Wed Jun 3 10:04:55 CEST 2020


Commit: b1f2825ce1f0d425ba8ed0261e4570e54f1a9909
Author: Falk David
Date:   Wed Jun 3 10:04:02 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rBb1f2825ce1f0d425ba8ed0261e4570e54f1a9909

GPencil: Add function to write sample data to edit curve

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

M	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index caca83cdd5c..32b8041aa69 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -36,6 +36,9 @@
 #include "BKE_context.h"
 #include "BKE_gpencil.h"
 
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -49,23 +52,45 @@
 /** \name Test Operator for curve editing
  * \{ */
 
-static int gp_test_stroke_curve_data_exec(bContext *C, wmOperator *op)
+static bGPDcurve *create_example_gp_curve(void)
+{
+  int num_points = 2;
+  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 = (bGPdata *)ob->data;
+  bGPdata *gpd = ob->data;
 
-  /* sanity checks */
   if (ELEM(NULL, gpd)) {
     return OPERATOR_CANCELLED;
   }
 
-  /* TODO: create new gp object with curve data */
   bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
-  bGPDlayer *gpf = gpl->actframe;
+  bGPDframe *gpf = gpl->actframe;
   if (ELEM(NULL, gpf)) {
     return OPERATOR_CANCELLED;
   }
 
+  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+    gps->editcurve = create_example_gp_curve();
+  }
+
   /* notifiers */
   DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
   WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -73,17 +98,17 @@ static int gp_test_stroke_curve_data_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-void GPENCIL_OT_test_stroke_curve_data(wmOperatorType *ot)
+void GPENCIL_OT_write_sample_stroke_curve_data(wmOperatorType *ot)
 {
   PropertyRNA *prop;
 
   /* identifiers */
-  ot->name = "Test stroke curve data";
-  ot->idname = "GPENCIL_OT_test_stroke_curve_data";
-  ot->description = "Test operator to test the curve data in a grease pencil stroke.";
+  ot->name = "Write sample stroke curve data";
+  ot->idname = "GPENCIL_OT_write_stroke_curve_data";
+  ot->description = "Test operator to write to the curve data in a grease pencil stroke.";
 
   /* api callbacks */
-  ot->exec = gp_test_stroke_curve_data_exec;
+  ot->exec = gp_write_stroke_curve_data_exec;
   ot->poll = gp_active_layer_poll;
 
   /* flags */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 11b3b78928e..4e101031ed5 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -444,7 +444,7 @@ void GPENCIL_OT_snap_cursor_to_selected(struct wmOperatorType *ot);
 void GPENCIL_OT_reproject(struct wmOperatorType *ot);
 void GPENCIL_OT_recalc_geometry(struct wmOperatorType *ot);
 
-void GPENCIL_OT_test_stroke_curve_data(struct wmOperatorType *ot);
+void GPENCIL_OT_write_sample_stroke_curve_data(struct wmOperatorType *ot);
 
 /* stroke sculpting -- */
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index d86ee47adad..16d663e11cd 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -569,7 +569,7 @@ void ED_operatortypes_gpencil(void)
   WM_operatortype_append(GPENCIL_OT_sculpt_paint);
   WM_operatortype_append(GPENCIL_OT_weight_paint);
 
-  WM_operatortype_append(GPENCIL_OT_test_stroke_curve_data);
+  WM_operatortype_append(GPENCIL_OT_write_sample_stroke_curve_data);
 
   /* Editing (Buttons) ------------ */



More information about the Bf-blender-cvs mailing list