GPv3: Subdivide operator #116740
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
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#116740
Loading…
Reference in New Issue
No description provided.
Delete Branch "ChengduLittleA/blender:gp3-subdiv"
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?
Subdiv operator for GP3 implemented using the new curves and array APIs.
Compared to the old one, this implementation added a "keep_shape" property
so we could take advantage of the improved
smooth_curve_attribute()
function.Tested subdiv in stroke/point selection mode, smooth is also working.
Current problems:
Not sure how to do the equivalentpoll()
of the oldgpencil_subdivide_curve_edit_poll_property()
.WIP: Subdivide operator for Grease Pencil 3.0to WIP: GPv3: Subdivide operatorThanks for working on this! Did a quick pass with some comments.
@ -32,6 +32,8 @@
#include "ED_grease_pencil.hh"
#include "ED_screen.hh"
#include "../../geometry/GEO_subdivide_curves.hh"
You shouldn't need use relative paths here. If it doesn't work without relative paths, add
../../geometry
toblender/source/blender/editors/grease_pencil/CMakeLists.txt
@ -1643,0 +1768,4 @@
wmOperator * /*op*/,
const PropertyRNA *prop)
{
/* I'm not sure how to deal with these below: */
There is no
GPENCIL_CURVE_EDIT_SESSIONS_ON
in GPv3 so this function is not needed.@ -1643,0 +1803,4 @@
/* api callbacks */
ot->exec = gpencil_stroke_subdivide_exec;
ot->poll = grease_active_layer_poll;
No need for a new poll function, use
ed::editable_grease_pencil_poll
instead.Some more comments.
@ -1643,0 +1689,4 @@
use_point_selection = VArray<bool>(point_selection);
}
else {
use_point_selection = VArray<bool>::ForSingle(true, curves.point_num);
Use
curves.points_num()
. Generally we try to avoid accessing the members directly and use the API instead. (Also change in other places)@ -1643,0 +1764,4 @@
return OPERATOR_FINISHED;
}
bool grease_active_layer_poll(bContext *C)
This function can be removed now.
@ -1643,0 +1727,4 @@
changed.store(true, std::memory_order_relaxed);
/* Smooth curves after being subdivided. */
auto do_smooth = [&](const char *attr) {
const auto do_smooth = [&](const StringRef attirubte_name) {
That's not related to this PR. Edit Mode can't use Global Undo and there is no special undo system for grease pencil. Hopefully this will be solved within the next two weeks.
Some more comments :)
@ -1643,0 +1671,4 @@
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
const OffsetIndices points_by_curve = curves.points_by_curve();
const VArray<bool> cyclic = curves.cyclic();
These two lines are only needed in the
else if
below, so you can move them in there.@ -1643,0 +1676,4 @@
const VArray<bool> point_selection = *curves.attributes().lookup_or_default<bool>(
".selection", bke::AttrDomain::Point, true);
VArray<bool> use_point_selection;
point_selection
anduse_point_selection
are unused and can be removed.@ -1643,0 +1687,4 @@
if (selection_domain == bke::AttrDomain::Curve || (!only_selected)) {
/* Subdivide entire selected curve, every stroke subdivides to the same cut. */
vcuts = VArray<int>::ForSingle(cuts, curves.points_num());
blender::bke::AnonymousAttributePropagationInfo pinfo;
You can remove the rest of the lines in this if and remove the
if (!vcuts.is_empty()) {
(leaving just the code inside) below.WIP: GPv3: Subdivide operatorto GPv3: Subdivide operator@ -1643,0 +1678,4 @@
}
else if (selection_domain == bke::AttrDomain::Point) {
/* Subdivide between selected points. Only cut between selected points. */
/* Make the cut array the same length as point count for specifying */
Multi-line comments typically don't have the
/
on the start of every line@ -1643,0 +1680,4 @@
/* Subdivide between selected points. Only cut between selected points. */
/* Make the cut array the same length as point count for specifying */
/* cut/uncut for each segment. */
Array<int> use_cuts(curves.points_num(), 0);
Declaring
use_cuts
right before the loop below will make it clear where its values are filled in@ -1643,0 +1690,4 @@
/* The cut is after each point, so the last point selected wouldn't need to be registered. */
for (const int curves_i : curves.curves_range()) {
for (const int points_i : points_by_curve[curves_i]) {
const bool cyc = cyclic[curves_i];
Let's just right the full word "cyclic" instead of "cyc". It's much easier to read that way, and we're not really getting anything for those three skipped characters
@ -1643,0 +1691,4 @@
for (const int curves_i : curves.curves_range()) {
for (const int points_i : points_by_curve[curves_i]) {
const bool cyc = cyclic[curves_i];
if (selection[points_i] && /* Point is selected. */
I think this will be much easier to read if we split this giant if statement into multiple and use
continue
for each check.@ -1643,0 +1706,4 @@
}
blender::bke::AnonymousAttributePropagationInfo pinfo;
curves = blender::geometry::subdivide_curves(curves, strokes, vcuts, pinfo);
We're already in the blender namespace here, no need to specify it. Also a bit simpler to just pass
{}
instead ofpinfo
@ -1643,0 +1712,4 @@
});
if (changed) {
/* Notifiers. */
This
Notifiers
comment doesn't really help IMO, considering the code itself has words like "tag_update" and "add_notifier"@ -1643,0 +1713,4 @@
if (changed) {
/* Notifiers. */
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
Not sure about
ID_RECALC_TRANSFORM
here, I think that's not used for object data since it has no location@ -1643,0 +1741,4 @@
/* properties */
prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 10, "Number of Cuts", "", 1, 5);
/* avoid re-using last var because it can cause _very_ high value and annoy users */
Comment style
I copied this from the old place. There are a few other places in this file also have some tiny problem with comment styles, I'll fix those other ones in a separate commit.
@ -1643,0 +1758,4 @@
wmOperatorType *ot;
ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
"Subdivide And Smooth",
Title case means "And" isn't capitalized:
Subdivide and Smooth
This should also document the changes in #114419.
The subdivide number is now linear instead of exponential (limit should probably be increased a bit).
We used to allow 10 cuts in the old subdiv, which means 1 segment will become 1024 segments (is this too high?). In the case of mesh, I think
ctrl-number
only goes to 5, in the case of gpencil/curve it will be 32 segments per 1 original segment, I think this is a more reasonable limit. 🤔@ -1643,0 +1672,4 @@
VArray<int> vcuts = {};
if (selection_domain == bke::AttrDomain::Curve || (!only_selected)) {
Unnecessary parentheses here around
!only_selected
@ -1643,0 +1693,4 @@
for (const int points_i : points_by_curve[curves_i]) {
const bool is_cyclic = cyclic[curves_i];
/* The point itself should be selected. */
if (!selection[points_i]){ continue; }
Clang format missing
@ -1643,0 +1695,4 @@
/* The point itself should be selected. */
if (!selection[points_i]){ continue; }
/* If the next point in the curve is selected, then cut this segment. */
if ((points_i < points_by_curve[curves_i].last()) && selection[points_i + 1]){
This could be simplified by not including the last point in the loop:
This means you don't need to check whether the point is the last in the curve or not inside the loop.
Also I guess it's actually
.drop_back(!cyclic[curve])
, since it's when the curve isn't cyclic that you don't want to process the segment.But did you find it didn't work if you just filled in that value anyway? IIRC the subdivide code should handle that check.
Huh I actually never knew that subdiv code handles it... So I guess I'll just drop the check all together and see if it runs correctly 😅
@ -1643,0 +1690,4 @@
Array<int> use_cuts(curves.points_num(), 0);
/* The cut is after each point, so the last point selected wouldn't need to be registered. */
for (const int curves_i : curves.curves_range()) {
curves_i
->curve
points_i
->point
It's nice to be consistent with these variable names. Conceptually these things are just indices into various arrays anyway.
@ -1643,0 +1699,4 @@
continue;
}
/* If the next point in the curve is selected, then cut this segment. */
if ((points_i < points_by_curve[curves_i].last()) && selection[points_i + 1]) {
points_i < points_by_curve[curves_i].last()
This part is unnecessary now too
@ -1643,0 +1705,4 @@
}
/* Always register the last point in the curve, the subdiv call will check for cyclic
* curves and cut them correctly. */
use_cuts[points_by_curve[curves_i].last()] = cuts;
Shouldn't this check the selection of the last point too?
And couldn't it just be handled inside the points loop too then?
@ -1643,0 +1707,4 @@
* curves and cut them correctly. */
use_cuts[points_by_curve[curves_i].last()] = cuts;
}
vcuts = VArray<int>::ForContainer(use_cuts);
std::move(use_cuts)
to avoid a copyHi Yiming, I found 2 things when looking/testing the code :)
Re: problem when curve is cyclic:
Alt C
to make curve cyclic@ -1643,0 +1685,4 @@
".selection", bke::AttrDomain::Point, true);
const OffsetIndices points_by_curve = curves.points_by_curve();
const VArray<bool> cyclic = curves.cyclic();
This is unused :)
@ -1643,0 +1700,4 @@
continue;
}
/* If the next point in the curve is selected, then cut this segment. */
if (selection[point + 1]) {
Looks like you'll need to handle special case when curve is cyclic and only "first and last" point selected.
Currently it'll skip the below code and new point is not added
Thanks @PratikPB2123 Indeed. I do need to move the check outside the loop then :D .