GPv3: Delete operator #111571

Merged
Falk David merged 22 commits from casey-bianco-davis/blender:GPv3-delete into main 2023-11-17 10:36:05 +01:00

Adds the delete operator to edit mode grease pencil, and also adds it to the delete menu.

Adds the delete operator to edit mode grease pencil, and also adds it to the delete menu.
casey-bianco-davis added 1 commit 2023-08-27 01:55:29 +02:00

Hi, please, just use already exist code of points delete from Delete Geometry node for curve geometry (see: source\blender\nodes\geometry\nodes\node_geo_delete_geometry.cc, separate_curves_selection) (you can move it to source\blender\geometry as shared geometry function).

EDIT: Even more than that, you just need to call bke::curves_copy_point_selection.

Hi, please, just use already exist code of points delete from Delete Geometry node for curve geometry (see: `source\blender\nodes\geometry\nodes\node_geo_delete_geometry.cc`, `separate_curves_selection`) (you can move it to `source\blender\geometry` as shared geometry function). EDIT: Even more than that, you just need to call `bke::curves_copy_point_selection`.
Iliya Katushenock added this to the Grease Pencil project 2023-08-27 02:00:42 +02:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-08-27 02:00:49 +02:00
Author
Member

Hi, please, just use already exist code of points delete from Delete Geometry node for curve geometry (see: source\blender\nodes\geometry\nodes\node_geo_delete_geometry.cc, separate_curves_selection) (you can move it to source\blender\geometry as shared geometry function).

EDIT: Even more than that, you just need to call bke::curves_copy_point_selection.

Hi @mod_moder if I am not mistaken bke::curves_copy_point_selection does not break the strokes into separate parts. and behaves like dissolve. where as this will break up the curves.

> Hi, please, just use already exist code of points delete from Delete Geometry node for curve geometry (see: `source\blender\nodes\geometry\nodes\node_geo_delete_geometry.cc`, `separate_curves_selection`) (you can move it to `source\blender\geometry` as shared geometry function). > > EDIT: Even more than that, you just need to call `bke::curves_copy_point_selection`. Hi @mod_moder if I am not mistaken `bke::curves_copy_point_selection` does not break the strokes into separate parts. and behaves like dissolve. where as this will break up the curves.

Well, actually, i'm not sure if you're supposed to split curves by removing points.

Well, actually, i'm not sure if you're supposed to split curves by removing points.
Author
Member

Well, actually, i'm not sure if you're supposed to split curves by removing points.

There is the Dissolve operator does not split the curves (#111079), but in the legacy grease pencil system there is a operator called delete (accessed by the menu that opens with 'x') that remove the points while breaking the curve into separate segments.

> Well, actually, i'm not sure if you're supposed to split curves by removing points. There is the `Dissolve` operator does not split the curves (#111079), but in the legacy grease pencil system there is a operator called `delete` (accessed by the menu that opens with 'x') that remove the points while breaking the curve into separate segments.
Iliya Katushenock removed the
Interest
Geometry Nodes
label 2023-08-27 03:10:43 +02:00
Falk David requested review from Falk David 2023-09-11 11:56:12 +02:00
casey-bianco-davis added 1 commit 2023-09-13 02:23:37 +02:00
Falk David reviewed 2023-10-11 11:00:32 +02:00
@ -561,0 +579,4 @@
{0, nullptr, 0, nullptr, nullptr},
};
static bke::CurvesGeometry delete_points(const bke::CurvesGeometry &curves,
Member

I think we should name this something like remove_points_and_split.

I think we should name this something like `remove_points_and_split`.
casey-bianco-davis marked this conversation as resolved
Falk David requested review from Hans Goudey 2023-10-11 11:00:45 +02:00
casey-bianco-davis added 1 commit 2023-10-12 04:40:40 +02:00
casey-bianco-davis added 1 commit 2023-10-12 04:56:05 +02:00
Pratik Borhade reviewed 2023-10-13 10:56:43 +02:00
@ -561,0 +579,4 @@
{0, nullptr, 0, nullptr, nullptr},
};
static bke::CurvesGeometry remove_points_and_split(const bke::CurvesGeometry &curves,
Member

I guess it would be better to move this function in curves_geometry.cc
Falk/Hans ^

I guess it would be better to move this function in `curves_geometry.cc` Falk/Hans ^
Member

Maybe at some point, but since Curves don't have this functionality at the moment, it's fine to be a static function here.

Maybe at some point, but since `Curves` don't have this functionality at the moment, it's fine to be a static function here.
filedescriptor marked this conversation as resolved
Falk David requested changes 2023-10-13 11:19:37 +02:00
Falk David left a comment
Member

Thank you for working on this! Some initial comments :)

Thank you for working on this! Some initial comments :)
@ -561,0 +562,4 @@
/** \name Delete Operator
* \{ */
enum class DeleteMode {
Member

I think we shouldn't have this property on the operator.
The operator should delete points vs strokes depending on the selection mode.

I think we shouldn't have this property on the operator. The operator should delete points vs strokes depending on the selection mode.
casey-bianco-davis marked this conversation as resolved
@ -561,0 +688,4 @@
bool changed = false;
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int /*drawing_index*/, bke::greasepencil::Drawing &drawing) {
Member

In main the foreach_editable_drawing drawing function changed. This now gives a layer_index instead of the drawing_index, so the parameter should be renamed (not that it matters for the logic of the code below).

In `main` the `foreach_editable_drawing` drawing function changed. This now gives a `layer_index` instead of the `drawing_index`, so the parameter should be renamed (not that it matters for the logic of the code below).
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 2 commits 2023-10-14 04:29:12 +02:00
casey-bianco-davis requested review from Falk David 2023-10-14 04:30:04 +02:00
casey-bianco-davis added 2 commits 2023-10-23 03:34:10 +02:00
casey-bianco-davis added 1 commit 2023-11-01 02:01:15 +01:00
Falk David requested changes 2023-11-01 16:05:43 +01:00
Falk David left a comment
Member

I did a pass together with Hans on this. Here are some comments

I did a pass together with Hans on this. Here are some comments
@ -564,0 +566,4 @@
* \{ */
static bke::CurvesGeometry remove_points_and_split(const bke::CurvesGeometry &curves,
const VArray<bool> selection)
Member

Should be const VArray<bool> &selection. Avoids some smallish overhead when copying the VArray.

Should be `const VArray<bool> &selection`. Avoids some smallish overhead when copying the `VArray`.
casey-bianco-davis marked this conversation as resolved
@ -564,0 +570,4 @@
{
const OffsetIndices<int> points_by_curve = curves.points_by_curve();
const VArray<bool> src_cyclic = curves.cyclic();
const Span<bool> points_to_delete = selection.get_internal_span();
Member

Although the selection is usually a span, this call can still fail. This should use VArraySpan<bool>.

Although the selection is usually a span, this call can still fail. This should use `VArraySpan<bool>`.
casey-bianco-davis marked this conversation as resolved
@ -564,0 +595,4 @@
IndexRange first_range = ranges_to_keep.first().shift(points.first());
IndexRange last_range = ranges_to_keep.last().shift(points.first());
const bool is_last_segment_selected = first_range.first() == points.first() &&
Member

Since it looks like we're only using first_range and last_range once, we can write it like this: const bool is_last_segment_selected = curve_cyclic && ranges_to_keep.first().first() == 0 && ranges_to_keep.last().last() == points.size() - 1;

Since it looks like we're only using `first_range` and `last_range` once, we can write it like this: `const bool is_last_segment_selected = curve_cyclic && ranges_to_keep.first().first() == 0 && ranges_to_keep.last().last() == points.size() - 1;`
casey-bianco-davis marked this conversation as resolved
@ -564,0 +601,4 @@
const bool is_cyclic = ranges_to_keep.size() == 1 && is_last_segment_selected;
IndexRange range_ids = ranges_to_keep.index_range();
for (const int range_id : range_ids) {
Member

Usually we like to name the iterator thing_i. Also we can skip over the first element using drop_front:
for (const int range_i : ranges_to_keep.index_range().drop_front(is_curve_self_joined)) {

Usually we like to name the iterator `thing_i`. Also we can skip over the first element using `drop_front`: `for (const int range_i : ranges_to_keep.index_range().drop_front(is_curve_self_joined)) {`
casey-bianco-davis marked this conversation as resolved
@ -564,0 +676,4 @@
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int /*layer_index*/, bke::greasepencil::Drawing &drawing) {
bke::CurvesGeometry &curves = drawing.strokes_for_write();
if (curves.points_num() == 0) {
Member

With the ed::curves::has_anything_selected(curves) check below, this check is not necessary.

With the `ed::curves::has_anything_selected(curves)` check below, this check is not necessary.
casey-bianco-davis marked this conversation as resolved
@ -564,0 +688,4 @@
blender::ed::curves::select_linked(curves);
}
const VArray<bool> selection = *curves.attributes().lookup_or_default<bool>(
Member

This should use ed::curves::retrieve_selected_curves in the case of ATTR_DOMAIN_CURVE. This also means the select_linked above is not necessary.

This should use `ed::curves::retrieve_selected_curves` in the case of `ATTR_DOMAIN_CURVE`. This also means the `select_linked` above is not necessary.
casey-bianco-davis marked this conversation as resolved
@ -564,0 +714,4 @@
/* Identifiers. */
ot->name = "Delete";
ot->idname = "GREASE_PENCIL_OT_delete";
ot->description = "Delete selected Grease Pencil strokes or points";
Member

"Delete selected strokes or points"

`"Delete selected strokes or points"`
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 6 commits 2023-11-04 03:10:22 +01:00
casey-bianco-davis added 4 commits 2023-11-05 04:41:15 +01:00
casey-bianco-davis requested review from Falk David 2023-11-05 05:20:39 +01:00
Falk David approved these changes 2023-11-16 11:48:35 +01:00
Falk David left a comment
Member

This is pretty much ready to go. One last comment.

This is pretty much ready to go. One last comment.
@ -564,0 +641,4 @@
const bke::AttributeAccessor src_attributes = curves.attributes();
/* Transfer curve attributes. */
for (bke::AttributeTransferData &attribute : bke::retrieve_attributes_for_transfer(
Member

There is a new API that we can use here: bke::gather_attributes (the one with the Span<int> indices parameter).

There is a new API that we can use here: `bke::gather_attributes` (the one with the `Span<int> indices` parameter).
casey-bianco-davis marked this conversation as resolved
@ -564,0 +651,4 @@
array_utils::copy(dst_cyclic.as_span(), dst_curves.cyclic_for_write());
/* Transfer point attributes. */
for (bke::AttributeTransferData &attribute : bke::retrieve_attributes_for_transfer(
Member

Same as above.

Same as above.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 3 commits 2023-11-17 03:38:58 +01:00
Member

Thanks for the patience :) I'll merge this now.

Thanks for the patience :) I'll merge this now.
Falk David merged commit 4dfed520a3 into main 2023-11-17 10:36:05 +01:00
Falk David referenced this issue from a commit 2023-11-17 10:36:07 +01:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111571
No description provided.