GPv3: Stroke smoothing operator #109635
No reviewers
Labels
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109635
Loading…
Reference in New Issue
No description provided.
Delete Branch "amelief/blender:gpv3-blur-stroke-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 smoothing operator for strokes, which works on the curves geometry inner data, including position and other attributes, such as radius (optional).
5271bc6847
to6ca5f950f2
This PR is waiting for 109733 to land so that we can add the option to smooth radius and opacity.
e13150085a
tofdcba22d38
WIP: GPv3 stroke smoothing operatorto GPv3 stroke smoothing operatorSome cleanup comments. Additionally this should add a menu and entry for the operator in the UI.
Add a class below
VIEW3D_MT_edit_greasepencil
inblender/scripts/startup/bl_ui/space_view3d.py
:Also declare it at the bottom of the file.
Then add an if-case (line 1010):
@ -81,0 +95,4 @@
* \{ */
template<typename T>
static Span<T> gaussian_blur_1D_ex(const bool is_cyclic,
is_cyclic
should be belowkeep_shape
in the parameters.@ -81,0 +143,4 @@
* Note these weights only work because the averaging is done in relative coordinates.
*/
/* Avoid computation if the mask is empty */
All comments should end in a
.
.@ -81,0 +159,4 @@
const int64_t first_pt = curve_points.first();
const int64_t last_pt = curve_points.last();
const int64_t nb_pts = curve_points.size();
nb_pts
->total_points
@ -81,0 +172,4 @@
}
});
for (int step = iterations; step > 0; step--) {
Does this need to go from
iterations
->0
?Otherwise I think something like
for (const int step : IndexRange(iterations))
would be better.Yes, that's why it loops over the indices. I can also reverse it and replace
step
byiterations - step
inside the loop. Idk what is best.I think I am just gonna do :
And then use
offset
instead ofstep
in the loopLooks good!
@ -81,0 +180,4 @@
return;
}
float w_before = float(w - w2);
Could these be just
double
?@ -81,0 +263,4 @@
static int grease_pencil_stroke_smooth_exec(bContext *C, wmOperator *op)
{
using namespace blender;
Scene *scene = CTX_data_scene(C);
const Scene *
I like where you're headed with this! It's nice to have the slightly generalized 1D Gaussian blur functions.
However, I think the generalization can go a bit further. I got a bit carried away and did some prototyping in the code:
attribute_math::convert_to_static_type
is used to generate the code necessary for each typeHopefully that's all reasonable. Sorry to paste a bunch of text here:
@ -81,0 +291,4 @@
/* Position. */
Array<float3> curves_positions_copy;
if (smooth_position && !curves.positions().is_empty()) {
curves_positions_copy = curves.positions();
You can count on the position attribute always being available
Hm the code doesn't check if the
position
attribute is available, only if it's empty. Can the position attribute not be empty?Ah, sure. But maybe it makes sense to just return early at the top if the curves are empty, skipping everything
@ -81,0 +293,4 @@
if (smooth_position && !curves.positions().is_empty()) {
curves_positions_copy = curves.positions();
}
/* Opacity. */
These comments don't really help IMO, since what they say is reading just a few words of the code. The blank line would be nice though
@ -81,0 +294,4 @@
curves_positions_copy = curves.positions();
}
/* Opacity. */
Array<float> curves_opacities_copy;
How about simplifying the naming like
opacities_orig
? The "curves" part of the existing name doesn't really help, and "orig" helps to make the purpose clearer (as in "why do we make a copy (which we can see with theArray
))@ -81,0 +304,4 @@
curves_radii_copy = drawing.radii().get_internal_span();
}
/* Cyclic. */
const offset_indices::OffsetIndices<int> points_by_curve = curves.points_by_curve();
offset_indices::OffsetIndices<int>
->OffsetIndices
@ -81,0 +307,4 @@
const offset_indices::OffsetIndices<int> points_by_curve = curves.points_by_curve();
const VArray<bool> cyclic = curves.cyclic();
/* Selection. */
bke::AttributeAccessor curves_attributes = curves.attributes();
VArray
directly since the attribute reader isn't used later on@ -81,0 +337,4 @@
smooth_ends,
keep_shape,
is_cyclic,
curves.positions_for_write(),
These attribute access functions do string lookups, so they are a bit too expensive to call once per curve
@ -62,5 +63,25 @@ void create_blank(Main &bmain, Object &object, int frame_number);
void create_stroke(Main &bmain, Object &object, float4x4 matrix, int frame_number);
void create_suzanne(Main &bmain, Object &object, float4x4 matrix, const int frame_number);
Span<float3> gaussian_blur_1D_float3(const IndexRange curve_points,
dst
anywayconst
for all arguments passed by value is unnecessary here in the declaration (so onlymask
needs to haveconst
dst
should be the last argument (it's just more typical to have order return arguments or changed data last2134127aa0
tob34deb16f4
GPv3 stroke smoothing operatorto GPv3: Stroke smoothing operator@HooglyBoogly I implemented some of your suggestions above. There are some noteworthy differences though:
gaussian_blur_1D
does not receive anIndexMask
anymore. It always blurs the entire source span. Previously, when smoothing only a portion of a curve (even withsmooth_ends
disabled) the result could lead to a discontinuous curve. This was because thesmooth_ends
option only applied to the start and end point of a curve. Now, we consider the start and end points of a selected range as the "ends". IMHO this leads to more expected results.smooth_curve_attributes
function, I implemented a function that smooths a single curve attribute. This means that I can choose different smoothing parameters per attribute (which is needed in the grease pencil case, e.g. only for positions do we enablekeep_shape
).Ready to be merged from my point of view.
5eeda5e954
to084f5b193c