GPv3: Extrude operator #121249
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#121249
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "amelief/blender:gpv3-extrude-point-operator"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@ -225,4 +225,120 @@ void duplicate_curves(bke::CurvesGeometry &curves, const IndexMask &mask)
}
}
void extrude_curve_points(const bke::CurvesGeometry &src,
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? 🤔
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)\
@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\
The curves extrude version doesn't do what GPv2 does, so we can't reuse it.
Thanks for spotting this @PratikPB2123 !
I will move it to
grease_pencil_edit.cc
🙂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);
This could be initialized direcly like so:
@ -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(
Using
IndexMask::from_intersection
works, but is a tad overkill. You can doIt's still not super efficient (
slice_content
isO(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).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 usepoints_by_curve
, but ofc happy to change if it's not the case here.slice_content
will do for now, I just mentionedCurvesGeometry::point_to_curve_map()
in case it might come in handy in the future.@ -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{};
Small thing, but usually we just pass
{}
togather_attributes
, no need for a variable.@ -228,0 +338,4 @@
}
dst.update_curve_types();
dst.tag_topology_changed();
This line is not needed (
resize
or construction will automatically tag the topology).@ -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(
Instead of
retrieve_editable_and_selected_elements
useretrieve_editable_and_selected_points
here. The former is used when both domains need to be supported.@ -2478,0 +2496,4 @@
return;
}
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
Use
info.drawing.strokes()
here to get aconst bke::CurvesGeometry &curves
.@ -2478,0 +2500,4 @@
bke::CurvesGeometry dst;
curves::extrude_curve_points(curves, points_to_extrude, dst);
info.drawing.geometry.wrap() = std::move(dst);
Instead of declaring
bke::CurvesGeometry dst;
then passing it intoextrude_curve_points
as a mutable reference and then moving into the geometry of the drawing, you can do all that like so:This means that
extrude_curve_points
should construct a newCurvesGeometry
and return it (by value).So where you have
dst.resize(new_points_num, new_curves_num);
now, doMove semantics will ensure that the curves geometry is constructed and then directly moved into the drawing, without any copy.
@ -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);
I suppose this code can just be removed?
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.
@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.
7310379437
to0b369be623
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;
No longer a need for the
IndexMaskMemory
:)