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.

Week 6 (July 06 - 12)

  • Support cyclic strokes (rB96eca6c3d447, rBfa662dceef37, rBab91491963f5). The fitting algorithm now can fit a curve to a cyclic stroke.
  • Allow individual handles to have different handle types (rB486a06d71be1).
  • Prepare all editmode operators to be used in curve edit mode (rB967c5b7da555, rBc62bc08f45b7, rB596f10a0cf14, rB6b12994ccf11). All the editmode operators need to be adapted to support curve edit mode. Some of the operators already work (e.g. GPENCIL_OT_stroke_apply_thickness , GPENCIL_OT_stroke_caps_set , GPENCIL_OT_stroke_change_color ) some will need to be ported. All the operators are now adapted, so that they don’t crash when being executed.
  • Implement circle select operator (rB6fa8efd81592).
  • Implement subdivide operator (rB9fa9ee613688). The algorithm will not change the shape of curve and supports cyclic curves.

Week 7 (July 13 - 19)

  • Implemented box and lasso select for curves (rB5122c75fd62c).
  • Implement a more accurate algorithm for selecting fill shapes (rBeb22e7a650a2).
  • Implement all remaining select operators: GPENCIL_OT_select_grouped (rBfcd22007b520), GPENCIL_OT_select_more and GPENCIL_OT_select_less (rBbd71007ebda7), GPENCIL_OT_select_first and GPENCIL_OT_select_last (rB95d0192308f5), GPENCIL_OT_select_alternate (rBd0d9490ac009).
  • Convert stroke to curve when a stroke with no editcurve is clicked on in curve edit mode (rB5bac474903e9).
  • Recalculate curve data when entering edit mode and the stroke data has changed (rB9d69d642ff17).

Week 8 (July 20 - 26)

  • Implemented an algorithm for adaptive curve resolution (rBf16a50ba946a). This algorithm makes sure that the sample points are more evenly distributed along the curve, resulting in uniform detail.

Adaptive curve resolution off

Adaptive curve resolution on

  • Implement multi-dimensional curve fitting (rBc18eb01eb641, rB2d9e869b18b9, rB48e52c5a5ced). Previously the fitting algorithm would only fit to the shape of the stroke and ignore pressure, strength and vertex colour. This meant that detail in those parameters would be lost when converting to a curve. Now the algorithm will also fit the curve to pressure, strength and vertex colour.
  • Implemented dissolve operator (rB075276ee803a).

Week 9 (July 27 - August 03)

  • Fixed a bug related to single point curves. In general, we would like to avoid single point curves (as a curve needs at least one segment to be an actual curve, which requires two points) (rBf2e2913a5838).
  • Finished the implementation for curve point deletion (rB331e1639c499).
  • Implemented snapping to the viewport grid of curve points (rB944ba1b38d01).
  • Implemented basic support for extruding. Currently only end points can be extruded (rBc825d70811f3).

Week 10 (August 04 - 09)

  • Rewrote the transform code from scratch. Previously the transform code had multiple issues:
    • center point of rotation and scale is not in the right location when control point is selected
    • scaling and rotating of handle points should scale and rotate the control point (and not try to scale or rotate the handle which does nothing)
    • proportional editing is not working at all

To solve these issues the transform code for strokes and curves were separated and the transform code for the curves was rewritten from scratch. The issues mentioned were thereby fixed (rB0ae02b130a78).

Week 11 (August 10 - 16)

  • Make the handle types update when moved. Previously, transforming vector or auto handles was not possible. These handles will now update their handle type when moved (rBe1e1b303fa32).
  • Update editcurve data when stroke data has changed. Previously, this caused a bug where the stroke and curve data would be out of sync (e.g. when the user switched to sculpt mode, changed the stroke, then switched back to curve edit mode). This now has been fixed (rBa8cc21f09ec4).
  • Curve points in the middle of the curve can now be extruded (rBc6650146eb1c).
  • Moved the checkbox “Adaptive Resolution” to the bottom of the panel for semantic consistency (rBa0152042b846).
  • Added automatic corner detection for the curve fitting. A parameter “Corner Angle” was added to the Curve Editing panel to control the angle threshold for corners (rB8bd1469d86d4).
  • Started to write documentation.

Week 12 (August 17 - 23)

  • Compiled the soc-2020-greasepencil-curve branch into a single patch (D8660). All the changes in the branch will also be updated in the patch.
  • Fixed a memory issue in the transform code, that caused crashes on some systems (rB3633a6197e8a).
  • Implemented transform gizmo drawing for curves. Previously the gizmo was not drawn in curve edit mode. (rBe0985ffcc153).
  • Operators that are not supported yet, will display an error message when used (rB062595b6f970).
  • Wrote the first draft of my final GSoC report. Can be found here.

Week 13 (August 24 - 30)

  • Fixed a crash where a curve with a single or two points was not handled properly (rB274c8ae9e27a).
  • Convert stroke to curve while in curve edit mode using selection. This was disabled for some selection operators because there were issues with the conversions. The issues were fixed and conversion is enabled for all selection operators (rB9c6d0ba92397, rBf2174e082ae0).
  • Implement duplicate operator (rB21cac5fed364).
  • Worked on the final report.
19 Likes