GPv3: Extrude operator #121249

Merged
Falk David merged 11 commits from amelief/blender:gpv3-extrude-point-operator into main 2024-05-02 12:51:42 +02:00

Implementation of the extrude operator for grease pencil v3.
If an endpoint is selected, the extrusion will extend the stroke.
If an inner point is selected, the extrusion will create a new stroke tied to the one that is selected.
Change of behavior from gpv2 : the endpoints of a cyclic curve follow the same behavior as inner points.

Implementation of the extrude operator for grease pencil v3. If an endpoint is selected, the extrusion will extend the stroke. If an inner point is selected, the extrusion will create a new stroke tied to the one that is selected. Change of behavior from gpv2 : the endpoints of a cyclic curve follow the same behavior as inner points.
Amélie Fondevilla added 5 commits 2024-04-30 10:25:43 +02:00
Amélie Fondevilla added this to the Grease Pencil project 2024-04-30 10:26:47 +02:00
Amélie Fondevilla requested review from Falk David 2024-04-30 10:27:04 +02:00
Pratik Borhade reviewed 2024-04-30 10:50:04 +02:00
@ -225,4 +225,120 @@ void duplicate_curves(bke::CurvesGeometry &curves, const IndexMask &mask)
}
}
void extrude_curve_points(const bke::CurvesGeometry &src,
Member

Hi, "curves extrude" already exists and all functions are defined in curves_extrude.cc: !116354
this function is only used in grease_pencil_edit.cc so I think it might make sense to move definition in grease_pencil_edit file? 🤔

Hi, "curves extrude" already exists and all functions are defined in curves_extrude.cc: !116354 this function is only used in grease_pencil_edit.cc so I think it might make sense to move definition in grease_pencil_edit file? 🤔
Member

Yes, I think for now it's ok if this is just a static function in grease_pencil_edit.cc.

Yes, I think for now it's ok if this is just a static function in `grease_pencil_edit.cc`.

Think its better to use already done version (at least without a lot of vector loops)\

Think its better to use already done version (at least without a lot of vector loops)\

@filedescriptor Wrote stupid question, update page and try to delete my one, but accidentally did delete your response

I see, okay, generalization can be done later\

@filedescriptor Wrote stupid question, update page and try to delete my one, but accidentally did delete your response I see, okay, generalization can be done later\
Member

The curves extrude version doesn't do what GPv2 does, so we can't reuse it.

The curves extrude version doesn't do what GPv2 does, so we can't reuse it.
Author
Member

Thanks for spotting this @PratikPB2123 !
I will move it to grease_pencil_edit.cc 🙂

Thanks for spotting this @PratikPB2123 ! I will move it to `grease_pencil_edit.cc` 🙂
amelief marked this conversation as resolved
Falk David requested changes 2024-04-30 11:42:44 +02:00
Falk David left a comment
Member

Thanks :) Overall, the logic looks good. Just some cleanup comments and C++ thingies.

Thanks :) Overall, the logic looks good. Just some cleanup comments and C++ thingies.
@ -228,0 +241,4 @@
array_utils::fill_index_range(dst_to_src_curves.as_mutable_span());
Vector<bool> dst_selected(old_points_num, false);
Vector<int> dst_curve_counts(old_curves_num);
Member

This could be initialized direcly like so:

Vector<int> dst_curve_counts(old_curves_num);
offset_indices::copy_group_sizes(points_by_curve, src.curves_range(), dst_curve_counts.as_mutable_span())
This could be initialized direcly like so: ```cpp Vector<int> dst_curve_counts(old_curves_num); offset_indices::copy_group_sizes(points_by_curve, src.curves_range(), dst_curve_counts.as_mutable_span()) ```
amelief marked this conversation as resolved
@ -228,0 +250,4 @@
for (const int curve_index : src.curves_range()) {
const IndexRange curve_points = points_by_curve[curve_index];
IndexMaskMemory mem;
const IndexMask curve_points_to_extrude = IndexMask::from_intersection(
Member

Using IndexMask::from_intersection works, but is a tad overkill. You can do

const IndexRange curve_points = points_by_curve[curve_index];
const IndexMask curve_points_to_extrude = points_to_extrude.slice_content(curve_points);

It's still not super efficient (slice_content is O(log N)), but will do fine for now.

There is also CurvesGeometry::point_to_curve_map() which will give you the curve index like so:
const int curve_index = point_to_curve_map[point_index];, but I don't know if this would make the rest of your logic work (since we're going over the same curve multiple times then).

Using `IndexMask::from_intersection` works, but is a tad overkill. You can do ```cpp const IndexRange curve_points = points_by_curve[curve_index]; const IndexMask curve_points_to_extrude = points_to_extrude.slice_content(curve_points); ``` It's still not super efficient (`slice_content` is `O(log N)`), but will do fine for now. There is also `CurvesGeometry::point_to_curve_map()` which will give you the curve index like so: `const int curve_index = point_to_curve_map[point_index];`, but I don't know if this would make the rest of your logic work (since we're going over the same curve multiple times then).
Author
Member

I suspected that the intersection was not efficient yes 😅
For point_to_curve_map, I think I recall Hans saying that it was better to loop over the curves and use points_by_curve, but ofc happy to change if it's not the case here.

I suspected that the intersection was not efficient yes 😅 For `point_to_curve_map`, I think I recall Hans saying that it was better to loop over the curves and use `points_by_curve`, but ofc happy to change if it's not the case here.
Member

slice_content will do for now, I just mentioned CurvesGeometry::point_to_curve_map() in case it might come in handy in the future.

`slice_content` will do for now, I just mentioned `CurvesGeometry::point_to_curve_map()` in case it might come in handy in the future.
amelief marked this conversation as resolved
@ -228,0 +303,4 @@
/* Attributes. */
const bke::AttributeAccessor src_attributes = src.attributes();
bke::MutableAttributeAccessor dst_attributes = dst.attributes_for_write();
const bke::AnonymousAttributePropagationInfo propagation_info{};
Member

Small thing, but usually we just pass {} to gather_attributes, no need for a variable.

Small thing, but usually we just pass `{}` to `gather_attributes`, no need for a variable.
amelief marked this conversation as resolved
@ -228,0 +338,4 @@
}
dst.update_curve_types();
dst.tag_topology_changed();
Member

This line is not needed (resize or construction will automatically tag the topology).

This line is not needed (`resize` or construction will automatically tag the topology).
amelief marked this conversation as resolved
@ -2478,0 +2490,4 @@
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
/* Extrusion always happens in the point domain. */
IndexMaskMemory memory;
const IndexMask points_to_extrude = retrieve_editable_and_selected_elements(
Member

Instead of retrieve_editable_and_selected_elements use retrieve_editable_and_selected_points here. The former is used when both domains need to be supported.

Instead of `retrieve_editable_and_selected_elements` use `retrieve_editable_and_selected_points` here. The former is used when both domains need to be supported.
amelief marked this conversation as resolved
@ -2478,0 +2496,4 @@
return;
}
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
Member

Use info.drawing.strokes() here to get a const bke::CurvesGeometry &curves.

Use `info.drawing.strokes()` here to get a `const bke::CurvesGeometry &curves`.
amelief marked this conversation as resolved
@ -2478,0 +2500,4 @@
bke::CurvesGeometry dst;
curves::extrude_curve_points(curves, points_to_extrude, dst);
info.drawing.geometry.wrap() = std::move(dst);
Member

Instead of declaring bke::CurvesGeometry dst; then passing it into extrude_curve_points as a mutable reference and then moving into the geometry of the drawing, you can do all that like so:

info.drawing.strokes_for_write() = std::move(curves::extrude_curve_points(curves, points_to_extrude));

This means that extrude_curve_points should construct a new CurvesGeometry and return it (by value).
So where you have dst.resize(new_points_num, new_curves_num); now, do

CurvesGeometry dst(new_points_num, new_curves_num);
...
return dst;

Move semantics will ensure that the curves geometry is constructed and then directly moved into the drawing, without any copy.

Instead of declaring `bke::CurvesGeometry dst;` then passing it into `extrude_curve_points` as a mutable reference and then moving into the geometry of the drawing, you can do all that like so: ```cpp info.drawing.strokes_for_write() = std::move(curves::extrude_curve_points(curves, points_to_extrude)); ``` This means that `extrude_curve_points` should construct a new `CurvesGeometry` and return it (by value). So where you have `dst.resize(new_points_num, new_curves_num);` now, do ```cpp CurvesGeometry dst(new_points_num, new_curves_num); ... return dst; ```` Move semantics will ensure that the curves geometry is constructed and then directly moved into the drawing, without any copy.
amelief marked this conversation as resolved
@ -182,0 +187,4 @@
OPTYPE_UNDO | OPTYPE_REGISTER);
WM_operatortype_macro_define(ot, "GREASE_PENCIL_OT_extrude");
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
// RNA_boolean_set(otmacro->ptr, "gpencil_strokes", true);
Member

I suppose this code can just be removed?

I suppose this code can just be removed?
amelief marked this conversation as resolved
Author
Member

Hey @filedescriptor thanks for the review, I'll edit the code.
I was wondering it we could optimize this by separating the case of the extrude containing endpoints or not.
If the selection does not include endpoints, then we can do the whole operation directly on the source, by resizing it and updating the attributes only on the newly created points, so it may be more efficient than the current implementation.
If the selection includes endpoints, then we cannot do that anymore, because we have to insert points inside of the existing curves.

I am wondering if it's worth it though, because we would have to go over all the curves and selected points just to check this. The readability would also be affected, but that's not a huge issue.

Hey @filedescriptor thanks for the review, I'll edit the code. I was wondering it we could optimize this by separating the case of the extrude containing endpoints or not. If the selection does not include endpoints, then we can do the whole operation directly on the source, by resizing it and updating the attributes only on the newly created points, so it may be more efficient than the current implementation. If the selection includes endpoints, then we cannot do that anymore, because we have to insert points inside of the existing curves. I am wondering if it's worth it though, because we would have to go over all the curves and selected points just to check this. The readability would also be affected, but that's not a huge issue.
Member

@amelief I think they way you wrote it now is fine. We could check for this edge case, but I think it's not worth it. In the end, we might want to change the way extrude works anyway to try and unify it with the curves code.

@amelief I think they way you wrote it now is fine. We could check for this edge case, but I think it's not worth it. In the end, we might want to change the way extrude works anyway to try and unify it with the curves code.
Amélie Fondevilla force-pushed gpv3-extrude-point-operator from 7310379437 to 0b369be623 2024-05-02 12:35:09 +02:00 Compare
Falk David approved these changes 2024-05-02 12:44:52 +02:00
Falk David left a comment
Member

Only have a cleanup comment, but this looks ready to me, so I will accept it. Also did a local test and it works as I expect.

Only have a cleanup comment, but this looks ready to me, so I will accept it. Also did a local test and it works as I expect.
@ -2485,0 +2512,4 @@
int point_offset = 0;
for (const int curve_index : src.curves_range()) {
const IndexRange curve_points = points_by_curve[curve_index];
IndexMaskMemory mem;
Member

No longer a need for the IndexMaskMemory :)

No longer a need for the `IndexMaskMemory` :)
amelief marked this conversation as resolved
Amélie Fondevilla added 1 commit 2024-05-02 12:48:44 +02:00
Falk David referenced this issue from a commit 2024-05-02 12:51:42 +02:00
Falk David merged commit 725408e842 into main 2024-05-02 12:51:42 +02:00
Falk David deleted branch gpv3-extrude-point-operator 2024-05-02 12:51:44 +02: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#121249
No description provided.