GPv3: Set caps operator #113978

Merged
Antonio Vazquez merged 18 commits from antoniov/blender:GPv3_capsmode into main 2023-11-12 14:13:24 +01:00

This operator is similar to V2 GPENCIL_OT_caps_set to set the type of cap used by the stroke curve.

Related to #113977

This operator is similar to V2 GPENCIL_OT_caps_set to set the type of cap used by the stroke curve. Related to #113977
Antonio Vazquez added 1 commit 2023-10-20 19:36:57 +02:00
624138696b GPv3: Set caps operator
This operator is similar to V2 GPENCIL_OT_caps_set
Antonio Vazquez requested review from Falk David 2023-10-20 19:37:11 +02:00
Antonio Vazquez requested review from Matias Mendiola 2023-10-20 19:37:19 +02:00
Antonio Vazquez added this to the Grease Pencil project 2023-10-20 19:37:27 +02:00
Antonio Vazquez added 1 commit 2023-10-20 19:51:44 +02:00

It works well, but the menu name should be "Toggle Caps" and the Both submenu is in uppercase ( BOTH) when it should be "Both"

image

It works well, but the menu name should be "Toggle Caps" and the Both submenu is in uppercase ( BOTH) when it should be "Both" ![image](/attachments/71183a5d-7f3d-485f-aeb4-0cf15fdd362d)
Author
Member

@mendio Both changed.

@mendio `Both` changed.
Antonio Vazquez added 1 commit 2023-10-21 10:54:48 +02:00
Antonio Vazquez added 1 commit 2023-10-21 16:09:53 +02:00
Falk David requested changes 2023-10-21 17:19:29 +02:00
Falk David left a comment
Member

Thanks for working on this :) Added some comments.

Thanks for working on this :) Added some comments.
@ -951,0 +955,4 @@
enum class CapsMode : int8_t {
/* Toggle both ends. */
TOGGLE,
Member

I think it would be better to call this BOTH.
START and AND also perform a toggle of the cap type.

I think it would be better to call this `BOTH`. `START` and `AND` also perform a toggle of the cap type.
antoniov marked this conversation as resolved
@ -951,0 +1001,4 @@
selected_curves.foreach_index([&](const int curve_index) {
if (mode == CapsMode::TOGGLE || mode == CapsMode::START) {
start_caps.span[curve_index] += 1;
Member

We generally don't do arithmetics on enum types.
I think it would be better to just do something like:

if (start_caps.span[curve_index] == GP_STROKE_CAP_TYPE_FLAT) {
  start_caps.span[curve_index] = GP_STROKE_CAP_TYPE_ROUND;
}
else {
  start_caps.span[curve_index] = GP_STROKE_CAP_TYPE_FLAT;
}

Also notice that the enum is a different one for gpv3. It's GreasePencilStrokeCapType.

We generally don't do arithmetics on enum types. I think it would be better to just do something like: ``` if (start_caps.span[curve_index] == GP_STROKE_CAP_TYPE_FLAT) { start_caps.span[curve_index] = GP_STROKE_CAP_TYPE_ROUND; } else { start_caps.span[curve_index] = GP_STROKE_CAP_TYPE_FLAT; } ``` Also notice that the enum is a different one for gpv3. It's `GreasePencilStrokeCapType`.
Author
Member

I used this code because the old code was ready to have more caps modes, but now it's better use if. Changed.

I used this code because the old code was ready to have more caps modes, but now it's better use if. Changed.
antoniov marked this conversation as resolved
@ -951,0 +1012,4 @@
end_caps.span[curve_index] = GP_STROKE_CAP_ROUND;
}
}
if (mode == CapsMode::DEFAULT) {
Member

This case doesn't need to be in this loop. We can add an if case above and put the selected_curves.foreach_index loop in the else:

if (mode == CapsMode::DEFAULT) {
  index_mask::masked_fill(
      start_caps.span, int8_t(GP_STROKE_CAP_TYPE_ROUND), selected_curves);
  index_mask::masked_fill(
      end_caps.span, int8_t(GP_STROKE_CAP_TYPE_ROUND), selected_curves);
}
This case doesn't need to be in this loop. We can add an if case above and put the `selected_curves.foreach_index` loop in the `else`: ``` if (mode == CapsMode::DEFAULT) { index_mask::masked_fill( start_caps.span, int8_t(GP_STROKE_CAP_TYPE_ROUND), selected_curves); index_mask::masked_fill( end_caps.span, int8_t(GP_STROKE_CAP_TYPE_ROUND), selected_curves); } ```
antoniov marked this conversation as resolved
Hans Goudey reviewed 2023-10-21 17:24:31 +02:00
Hans Goudey left a comment
Member

Actually, for CapsMode::DEFAULT I think we can just remove the attribute(s). It's nice to do that where possible to reduce the memory usage later on.

Could "Default" be renamed to "Round"? Generally we try to avoid calling things just "default" in the UI since it's not so descriptive.

Actually, for `CapsMode::DEFAULT` I think we can just remove the attribute(s). It's nice to do that where possible to reduce the memory usage later on. Could "Default" be renamed to "Round"? Generally we try to avoid calling things just "default" in the UI since it's not so descriptive.
@ -951,0 +997,4 @@
attributes.lookup_or_add_for_write_span<int8_t>("end_cap", ATTR_DOMAIN_CURVE);
IndexMaskMemory memory;
IndexMask selected_curves = ed::curves::retrieve_selected_curves(curves, memory);
Member

The has_anything_selected and points_num() == 0 checks are redundant with this index mask. Could be simplified by moving this above the access of the attributes, and return early if selected_curves.is_empty(). That can replace the has_anything_selected check.

Also IndexMask selected_curves -> const IndexMask selected_curves

The `has_anything_selected` and `points_num() == 0` checks are redundant with this index mask. Could be simplified by moving this above the access of the attributes, and return early if `selected_curves.is_empty()`. That can replace the `has_anything_selected` check. Also `IndexMask selected_curves` -> `const IndexMask selected_curves`
antoniov marked this conversation as resolved

Could "Default" be renamed to "Round"? Generally we try to avoid calling things just "default" in the UI since it's not so descriptive.

Although I agree with your point we already called it Default in the old operator:

image

So if we were to change it it would break the API and must be documented in the GP2 -> GP3 API migration document (which may or may not exist). I personally would avoid any change and just stick to the GP2 behaviour for simplicity sake. Not my call though.

> Could "Default" be renamed to "Round"? Generally we try to avoid calling things just "default" in the UI since it's not so descriptive. Although I agree with your point we already called it `Default` in the old operator: ![image](/attachments/87408b29-cd7d-4889-85c7-3a40e061d382) So if we were to change it it would break the API and must be documented in the GP2 -> GP3 API migration document (which may or may not exist). I personally would avoid any change and just stick to the GP2 behaviour for simplicity sake. Not my call though.
Antonio Vazquez added 2 commits 2023-10-21 23:35:35 +02:00
Author
Member

About change Default ... I think would be better change to Rounded too. We are breaking the API a lot, so this change is only one more.

About change `Default` ... I think would be better change to `Rounded` too. We are breaking the API a lot, so this change is only one more.
Antonio Vazquez added 1 commit 2023-10-21 23:39:30 +02:00
Antonio Vazquez added 3 commits 2023-11-02 18:04:56 +01:00
Hans Goudey reviewed 2023-11-02 18:09:47 +01:00
@ -960,0 +1009,4 @@
index_mask::masked_fill(end_caps.span, int8_t(GP_STROKE_CAP_TYPE_ROUND), selected_curves);
}
else {
selected_curves.foreach_index([&](const int curve_index) {
Member

The logic inside the lambda could be extracted to a separate function with const IndexMask &selection and MutableSpan<int8_t> caps arguments, and called once for start and end caps

The logic inside the lambda could be extracted to a separate function with `const IndexMask &selection` and `MutableSpan<int8_t> caps` arguments, and called once for start and end caps
Author
Member

I really don't know what you mean. The lines of your code have changed since you made the comment. Could you explain more about the change?

I really don't know what you mean. The lines of your code have changed since you made the comment. Could you explain more about the change?
Member

A function toggle_caps(const IndexMask &selection, MutableSpan<int8_t> caps) can process one array at a time.

A function `toggle_caps(const IndexMask &selection, MutableSpan<int8_t> caps)` can process one array at a time.
antoniov marked this conversation as resolved

Since we changed the Default operator option to Rounded, and the menu is called Set Caps, I would suggest also adding the Flat option and renaming the others like the mockup below. IMO this change makes the options clearer and easier to use.

  • Rounded (Sets both stroke caps rounded)
  • Flat (Sets both stroke caps flat)
  • Toggle start (Inverts start stroke cap)
  • Toggle end (Inverts end stroke cap)

Note: With this change, there is no need to keep Both option

image

Since we changed the `Default` operator option to `Rounded`, and the menu is called `Set Caps`, I would suggest also adding the `Flat` option and renaming the others like the mockup below. IMO this change makes the options clearer and easier to use. - `Rounded` (Sets both stroke caps rounded) - `Flat` (Sets both stroke caps flat) - `Toggle start` (Inverts start stroke cap) - `Toggle end` (Inverts end stroke cap) Note: With this change, there is no need to keep `Both` option ![image](/attachments/37fc6080-afe7-446a-bf6d-a422ff38c402)
Antonio Vazquez added 1 commit 2023-11-02 22:47:34 +01:00
8b5877ee9f GPv3: Change options for set caps
Now we have:

* Set both Rounded.
* Set both Flat.
* Toggle Start.
* Toggle End.

This change was proposed by Matias Mendiola.
Author
Member

Now the menu looks like this:

image

Now the menu looks like this: ![image](/attachments/023b5338-b79b-4441-86db-7efa07427d0e)
First-time contributor

how about adding more caps ? like those : sword and its sheath
image

how about adding more caps ? like those : sword and its sheath ![image](/attachments/39106557-bb77-4a2f-9244-ef5b2a00efec)
144 KiB

@hamza-el-barmaki right now we have to focus on port the same features that we have in Grease Pencil v2, when we finish with that we could revisit everything making updates and adding new features.

@hamza-el-barmaki right now we have to focus on port the same features that we have in Grease Pencil v2, when we finish with that we could revisit everything making updates and adding new features.
Matias Mendiola approved these changes 2023-11-06 17:32:34 +01:00
Author
Member

@filedescriptor I guess we can merge this too, no?

@filedescriptor I guess we can merge this too, no?
Antonio Vazquez added 1 commit 2023-11-08 16:43:46 +01:00
6e95fd3edd Merge branch 'main' into GPv3_capsmode
Conflicts:
	scripts/startup/bl_ui/space_view3d.py
        source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc
Antonio Vazquez added 1 commit 2023-11-08 16:45:32 +01:00
6b674fa06b Merge branch 'main' into GPv3_capsmode
Conflicts:
	source/blender/editors/grease_pencil/intern/grease_pencil_edit.cc
Antonio Vazquez added 2 commits 2023-11-08 17:59:11 +01:00
Hans Goudey requested changes 2023-11-08 22:32:40 +01:00
Hans Goudey left a comment
Member

I left a comment about the structure of the main loop that should still be resolved.

I left a comment about the structure of the main loop that should still be resolved.
Antonio Vazquez added 1 commit 2023-11-09 10:45:45 +01:00
3bea6db2e8 GPv3: Cleanup code to remove duplications
Note: The deafult is needed in switch to avoid compiler warning.
Antonio Vazquez added 1 commit 2023-11-09 15:12:25 +01:00
Author
Member

@HooglyBoogly is this ok now?

@HooglyBoogly is this ok now?
Hans Goudey approved these changes 2023-11-11 21:07:35 +01:00
Antonio Vazquez added 1 commit 2023-11-12 14:12:17 +01:00
Antonio Vazquez merged commit 7c899d2271 into main 2023-11-12 14:13:24 +01:00
Antonio Vazquez deleted branch GPv3_capsmode 2023-11-12 14:13:26 +01:00
Sign in to join this conversation.
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#113978
No description provided.