GSoC 2020: Editing grease pencil strokes using curves - Weekly reports

I will be posting my weekly progress here in this thread. You can also find all the reports on my blender wiki page.

Week 1 (June 01 - 07)

  • Added a dummy operator mainly to test the curve data structure that was added to the bGPDstroke structure.
  • The bGPDstroke data structure now has a bGPDcurve structure. This holds an array of BezTriple that will represent the curve points.
  • Implemented the RNA structure for bGPDcurve .
  • Added reading and writing of the bGPDcurve structure to file.
  • Added a toggle button for the edit curve mode in the header bar of grease pencil edit mode

Week 2 (June 08 - 14)

  • Implemented a function to create a bézier curve from a grease pencil stroke. It uses the algorithms defined in curve_fit_nd.h .
  • When the user switches to curve edit mode, the selected strokes will automatically be used to generate their curves.
  • Implemented a function to (re)create grease pencil stroke points from a bézier curve.
  • Implemented interpolation for pressure, strength and vertex colors between curve points. Currently this uses linear interpolation.
  • When the coordinates, strength, pressure or vertex color of the curve points change, an update of the stroke points is automatically triggered.
  • Implemented the select_all operator to make it work with curve points if the object is in curve edit mode. This includes deselection and invert selection.
  • Implemented the select_linked , select_more , select_less operator for curve points.
  • Added a curve_resolution parameter to the bGPdata structure. This parameter controls the number of segments that get created when the editcurve is transformed back into a stroke (visually this controls how smooth the stroke looks).
  • When the curve_resolution parameter changes, the stroke is automatically updated.

Week 3 (June 15 - 21)

  • Added a error_threshold property to the select_all operator. When a stroke is first converted to a curve, the fitting can be adjusted with this parameter.
  • Implemented click selection for curve points and handles. This includes deselection for clicking in empty space, toggle selection and extend selection (with shift ). The selection also takes the overlay settings into account, e.g. if a handle is not displayed it cannot be selected.
  • Implemented basic transformation for curve points. This includes translation, rotation, scaling, changing the thickness and changing the strength/opacity for every curve point. The handles are treated as type free and do not move with the control point for now.
  • Exiting curve edit mode deselects all the stroke points and strokes on the current frame. This will change later, as we aim to synchronize the selection between strokes and edit curves.

Week 4 (June 22 - 28)

  • Worked on selection synchronization when entering/exiting curve edit mode. Currently, if a handle is selected, the corresponding stroke point of the control point will be selected. If two neighbouring handles are selected, all of the stroke points in between will additionally be selected.
  • More conceptual work was done on solving a code design issue, when it comes to the curve fitting. We would want the fitting to be triggered when the user selects a stroke in curve edit mode. More details on this issue can be found in this devtalk thread.

Week 5 (June 29 - July 05)

  • Added an operator to set the handle type of a curve point ( GPENCIL_OT_stroke_editcurve_set_handle_type ).
  • Added a BKE function to recalculate the handle positions depending on the type ( BKE_gpencil_editcurve_recalculate_handles ).
  • Support transformation of all handle types.
  • Added custom shortcuts for curve edit mode. Currently there are only two shortcuts ( V to toggle the handle type and U to toggle curve edit mode). All the usual shortcuts in edit mode still work in curve edit mode, unless they are overwritten (e.g. V is “split” in edit mode, but “toggle handle type” in curve edit mode). They can all be changed through the keymap editor.
  • Fixed some crashes when editing points in edit mode and when editing individual handles.
  • Reworked parts of the handling of the conversion from curve to stroke and vice versa. Both the stroke and the curve now have a flag that indicates they are no longer synchronized with the other data structure. This allows us to recalculate stroke and curve data only when needed.