GPv3: Subdivide operator #116740

Merged
YimingWu merged 14 commits from ChengduLittleA/blender:gp3-subdiv into main 2024-01-10 15:16:39 +01:00
Member

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:

  • Global undo doesn't seem to be working.
  • Not sure how to do the equivalent poll() of the old gpencil_subdivide_curve_edit_poll_property().
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: - Global undo doesn't seem to be working. - ~~Not sure how to do the equivalent `poll()` of the old `gpencil_subdivide_curve_edit_poll_property()`.~~
YimingWu added the
Interest
Grease Pencil
Module
Grease Pencil
labels 2024-01-03 11:44:42 +01:00
YimingWu added 5 commits 2024-01-03 11:44:52 +01:00
Iliya Katushenock added this to the Grease Pencil project 2024-01-03 11:46:03 +01:00
Iliya Katushenock removed the
Module
Grease Pencil
Interest
Grease Pencil
labels 2024-01-03 11:46:08 +01:00
YimingWu requested review from Falk David 2024-01-03 11:46:17 +01:00
YimingWu requested review from Hans Goudey 2024-01-03 11:46:18 +01:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2024-01-03 11:46:20 +01:00
YimingWu changed title from WIP: Subdivide operator for Grease Pencil 3.0 to WIP: GPv3: Subdivide operator 2024-01-03 11:50:53 +01:00
Falk David requested changes 2024-01-08 10:48:48 +01:00
Falk David left a comment
Member

Thanks for working on this! Did a quick pass with some comments.

Thanks 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"
Member

You shouldn't need use relative paths here. If it doesn't work without relative paths, add ../../geometry to blender/source/blender/editors/grease_pencil/CMakeLists.txt

You shouldn't need use relative paths here. If it doesn't work without relative paths, add `../../geometry` to `blender/source/blender/editors/grease_pencil/CMakeLists.txt`
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1768,4 @@
wmOperator * /*op*/,
const PropertyRNA *prop)
{
/* I'm not sure how to deal with these below: */
Member

There is no GPENCIL_CURVE_EDIT_SESSIONS_ON in GPv3 so this function is not needed.

There is no `GPENCIL_CURVE_EDIT_SESSIONS_ON` in GPv3 so this function is not needed.
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1803,4 @@
/* api callbacks */
ot->exec = gpencil_stroke_subdivide_exec;
ot->poll = grease_active_layer_poll;
Member

No need for a new poll function, use ed::editable_grease_pencil_poll instead.

No need for a new poll function, use `ed::editable_grease_pencil_poll` instead.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-08 11:58:43 +01:00
Falk David requested changes 2024-01-08 12:09:19 +01:00
Falk David left a comment
Member

Some more comments.

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);
Member

Use curves.points_num(). Generally we try to avoid accessing the members directly and use the API instead. (Also change in other places)

Use `curves.points_num()`. Generally we try to avoid accessing the members directly and use the API instead. (Also change in other places)
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1764,4 @@
return OPERATOR_FINISHED;
}
bool grease_active_layer_poll(bContext *C)
Member

This function can be removed now.

This function can be removed now.
ChengduLittleA marked this conversation as resolved
Iliya Katushenock reviewed 2024-01-08 12:14:54 +01:00
@ -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) {

`const auto do_smooth = [&](const StringRef attirubte_name) {`
ChengduLittleA marked this conversation as resolved
Member

Global undo doesn't seem to be working.

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.

> Global undo doesn't seem to be working. 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.
YimingWu added 1 commit 2024-01-08 13:14:50 +01:00
YimingWu added 1 commit 2024-01-08 13:18:03 +01:00
Falk David requested changes 2024-01-08 13:59:59 +01:00
Falk David left a comment
Member

Some more comments :)

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();
Member

These two lines are only needed in the else if below, so you can move them in there.

These two lines are only needed in the `else if` below, so you can move them in there.
ChengduLittleA marked this conversation as resolved
@ -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;
Member

point_selection and use_point_selection are unused and can be removed.

`point_selection` and `use_point_selection` are unused and can be removed.
ChengduLittleA marked this conversation as resolved
@ -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;
Member

You can remove the rest of the lines in this if and remove the if (!vcuts.is_empty()) { (leaving just the code inside) below.

You can remove the rest of the lines in this if and remove the `if (!vcuts.is_empty()) {` (leaving just the code inside) below.
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-08 15:29:06 +01:00
YimingWu changed title from WIP: GPv3: Subdivide operator to GPv3: Subdivide operator 2024-01-08 15:52:27 +01:00
Hans Goudey requested changes 2024-01-08 17:35:42 +01:00
@ -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 */
Member

Multi-line comments typically don't have the / on the start of every line

Multi-line comments typically don't have the `/` on the start of every line
ChengduLittleA marked this conversation as resolved
@ -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);
Member

Declaring use_cuts right before the loop below will make it clear where its values are filled in

Declaring `use_cuts` right before the loop below will make it clear where its values are filled in
ChengduLittleA marked this conversation as resolved
@ -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];
Member

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

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
ChengduLittleA marked this conversation as resolved
@ -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. */
Member

I think this will be much easier to read if we split this giant if statement into multiple and use continue for each check.

I think this will be much easier to read if we split this giant if statement into multiple and use `continue` for each check.
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1706,4 @@
}
blender::bke::AnonymousAttributePropagationInfo pinfo;
curves = blender::geometry::subdivide_curves(curves, strokes, vcuts, pinfo);
Member

We're already in the blender namespace here, no need to specify it. Also a bit simpler to just pass {} instead of pinfo

We're already in the blender namespace here, no need to specify it. Also a bit simpler to just pass `{}` instead of `pinfo`
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1712,4 @@
});
if (changed) {
/* Notifiers. */
Member

This Notifiers comment doesn't really help IMO, considering the code itself has words like "tag_update" and "add_notifier"

This `Notifiers` comment doesn't really help IMO, considering the code itself has words like "tag_update" and "add_notifier"
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1713,4 @@
if (changed) {
/* Notifiers. */
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
Member

Not sure about ID_RECALC_TRANSFORM here, I think that's not used for object data since it has no location

Not sure about `ID_RECALC_TRANSFORM` here, I think that's not used for object data since it has no location
ChengduLittleA marked this conversation as resolved
@ -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 */
Member

Comment style

Comment style
Author
Member

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.

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.
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1758,4 @@
wmOperatorType *ot;
ot = WM_operatortype_append_macro("GREASE_PENCIL_OT_stroke_subdivide_smooth",
"Subdivide And Smooth",
Member

Title case means "And" isn't capitalized: Subdivide and Smooth

Title case means "And" isn't capitalized: `Subdivide and Smooth`
ChengduLittleA marked this conversation as resolved
Member

This should also document the changes in #114419.

The subdivide number is now linear instead of exponential (limit should probably be increased a bit).

This should also document the changes in https://projects.blender.org/blender/blender/issues/114419. The subdivide number is now linear instead of exponential (limit should probably be increased a bit).
Author
Member

(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. 🤔

> (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. 🤔
YimingWu added 1 commit 2024-01-09 02:41:54 +01:00
Hans Goudey reviewed 2024-01-09 03:32:22 +01:00
@ -1643,0 +1672,4 @@
VArray<int> vcuts = {};
if (selection_domain == bke::AttrDomain::Curve || (!only_selected)) {
Member

Unnecessary parentheses here around !only_selected

Unnecessary parentheses here around `!only_selected`
ChengduLittleA marked this conversation as resolved
@ -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; }
Member

Clang format missing

Clang format missing
HooglyBoogly marked this conversation as resolved
@ -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]){
Member

This could be simplified by not including the last point in the loop:

for (const int point : points_by_curve[curve].drop_back(cyclic[curve])) {
This could be simplified by not including the last point in the loop: ```cpp for (const int point : points_by_curve[curve].drop_back(cyclic[curve])) { ```
Member

This means you don't need to check whether the point is the last in the curve or not inside the loop.

This means you don't need to check whether the point is the last in the curve or not inside the loop.
Member

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.

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.
Author
Member

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 😅

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 😅
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-09 05:15:56 +01:00
YimingWu added 1 commit 2024-01-09 15:58:36 +01:00
Hans Goudey reviewed 2024-01-09 16:37:27 +01:00
@ -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()) {
Member
  • 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.

- `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.
ChengduLittleA marked this conversation as resolved
@ -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]) {
Member

points_i < points_by_curve[curves_i].last()

This part is unnecessary now too

`points_i < points_by_curve[curves_i].last()` This part is unnecessary now too
ChengduLittleA marked this conversation as resolved
@ -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;
Member

Shouldn't this check the selection of the last point too?
And couldn't it just be handled inside the points loop too then?

Shouldn't this check the selection of the last point too? And couldn't it just be handled inside the points loop too then?
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1707,4 @@
* curves and cut them correctly. */
use_cuts[points_by_curve[curves_i].last()] = cuts;
}
vcuts = VArray<int>::ForContainer(use_cuts);
Member

std::move(use_cuts) to avoid a copy

`std::move(use_cuts)` to avoid a copy
ChengduLittleA marked this conversation as resolved
YimingWu added 1 commit 2024-01-10 03:57:48 +01:00
Pratik Borhade reviewed 2024-01-10 12:31:00 +01:00
Pratik Borhade left a comment
Member

Hi Yiming, I found 2 things when looking/testing the code :)

Re: problem when curve is cyclic:

  • Open attached file (end points already selected)
  • Alt C to make curve cyclic
  • Subdivide (won't add new point)
Hi Yiming, I found 2 things when looking/testing the code :) Re: problem when curve is cyclic: - Open attached file (end points already selected) - `Alt C` to make curve cyclic - Subdivide (won't add new point)
@ -1643,0 +1685,4 @@
".selection", bke::AttrDomain::Point, true);
const OffsetIndices points_by_curve = curves.points_by_curve();
const VArray<bool> cyclic = curves.cyclic();
Member

This is unused :)

This is unused :)
ChengduLittleA marked this conversation as resolved
@ -1643,0 +1700,4 @@
continue;
}
/* If the next point in the curve is selected, then cut this segment. */
if (selection[point + 1]) {
Member

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

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
ChengduLittleA marked this conversation as resolved
Author
Member

Thanks @PratikPB2123 Indeed. I do need to move the check outside the loop then :D .

Thanks @PratikPB2123 Indeed. I do need to move the check outside the loop then :D .
YimingWu added 1 commit 2024-01-10 12:47:20 +01:00
Hans Goudey approved these changes 2024-01-10 13:46:59 +01:00
YimingWu merged commit 991902cb28 into main 2024-01-10 15:16:39 +01:00
YimingWu referenced this issue from a commit 2024-01-10 15:16:40 +01:00
YimingWu deleted branch gp3-subdiv 2024-01-10 15:16:41 +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
6 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#116740
No description provided.