GPv3: Weight gradient tool #118671

Open
Sietse Brouwer wants to merge 5 commits from SietseB/blender:gpv3-weight-gradient-tool into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

This PR implements the Weight Gradient tool for GPv3. The tool applies
a linear/radial weight gradient to all editable stroke points for the
active vertex group. Useful for creating smooth weight transitions.

The tool works interactively in the viewport. With click-and-drag
a dashed line is drawn in the viewport, representing the orientation
and length of the gradient. The effect of the gradient on the vertex
weights is shown in real time.

The gradient weight is added or substracted to the existing vertex
weight. The direction (Add/Subtract) can be toggled with D.
Alternatively, Ctrl-drag can be used. Holding Ctrl inverts the
direction.

When the 'Auto Normalize' option is enabled and the Grease Pencil
object is deformed by an armature, all deforming weights assigned
to a single vertex (stroke point) automatically add up to 1.0.

The gradient tool will do nothing when the active vertex group is
locked.
When there is no active vertex group, a new one will be created.

This PR implements the Weight Gradient tool for GPv3. The tool applies a linear/radial weight gradient to all editable stroke points for the active vertex group. Useful for creating smooth weight transitions. The tool works interactively in the viewport. With click-and-drag a dashed line is drawn in the viewport, representing the orientation and length of the gradient. The effect of the gradient on the vertex weights is shown in real time. The gradient weight is added or substracted to the existing vertex weight. The direction (Add/Subtract) can be toggled with `D`. Alternatively, `Ctrl`-drag can be used. Holding `Ctrl` inverts the direction. When the 'Auto Normalize' option is enabled and the Grease Pencil object is deformed by an armature, all deforming weights assigned to a single vertex (stroke point) automatically add up to 1.0. The gradient tool will do nothing when the active vertex group is locked. When there is no active vertex group, a new one will be created.
Sietse Brouwer added 3 commits 2024-02-23 16:47:13 +01:00
Author
Member

Note: grease_pencil_weight_paint.cc only needs code review from line 275 and further. The first part is the same as in #118347: GPv3: Weight Paint tools (Draw, Blur, Average, Smear, Sample weight). It's only present in this PR so that it can be build on its own.

Note: `grease_pencil_weight_paint.cc` only needs code review from line 275 and further. The first part is the same as in [#118347: GPv3: Weight Paint tools (Draw, Blur, Average, Smear, Sample weight)](https://projects.blender.org/blender/blender/pulls/118347). It's only present in this PR so that it can be build on its own.
Sietse Brouwer added this to the Grease Pencil project 2024-02-23 16:54:04 +01:00
Sietse Brouwer requested review from Falk David 2024-02-23 16:54:21 +01:00
Author
Member

Little demo with Thickness and Offset modifiers:

Little demo with Thickness and Offset modifiers: <video src="/attachments/fcd58082-d469-471d-a4fb-a6b71c4eb345" title="Weight gradient tool GPv3.mp4" controls></video>
Iliya Katushenock reviewed 2024-02-24 12:44:34 +01:00
@ -0,0 +206,4 @@
return true;
}
void normalize_vertex_weights(const MDeformVert &dvert,

Should this be static in this PR?

Should this be static in this PR?
SietseB marked this conversation as resolved
@ -0,0 +276,4 @@
/** \name Weight Gradient Operator
* \{ */
enum {
enum class WeightGradientType : int8_t {
  Linear,
  Radial,
};
```Cpp enum class WeightGradientType : int8_t { Linear, Radial, }; ```
SietseB marked this conversation as resolved
@ -0,0 +366,4 @@
/* Calculate weight change. */
float gradient_factor = 0.0f;
if (gradient_type == WPAINT_GRADIENT_TYPE_LINEAR) {

Should be switch.

Should be switch.
SietseB marked this conversation as resolved
@ -0,0 +568,4 @@
cache.point_positions = Array<float2>(deformation.positions.size());
cache.point_original_weights = Array<float>(deformation.positions.size());
cache.point_flags = Array<uint8_t>(deformation.positions.size(), 0);

cache.point_flags.reinitialize(deformation.positions.size())

`cache.point_flags.reinitialize(deformation.positions.size())`

Also, can this be index mask?

Also, can this be index mask?
Author
Member

In general, a lot of stroke points are affected by the gradient tool. I wouldn't recommend using an index mask for that; it would be less performant.

In general, a lot of stroke points are affected by the gradient tool. I wouldn't recommend using an index mask for that; it would be less performant.

No, index mask usually much faster than a branches in hot loops.
Main reason to do not build index mask is the case of complicated condition for each element, but not sure is there this case is here...

No, index mask usually much faster than a branches in hot loops. Main reason to do not build index mask is the case of complicated condition for each element, but not sure is there this case is here...
Author
Member

I can't see how we can gain much from an index mask. The gradient is an interactive tool, so at the operator's invoke we can't build a mask yet. And at the execute we already have to loop over all the stroke points to see if they are affected by the gradient – we could dynamically build an index mask then, but to what end?

I can't see how we can gain much from an index mask. The gradient is an interactive tool, so at the operator's `invoke` we can't build a mask yet. And at the `execute` we already have to loop over all the stroke points to see if they are affected by the gradient – we could dynamically build an index mask then, but to what end?
Sietse Brouwer added 1 commit 2024-02-26 13:43:20 +01:00
Sietse Brouwer added 1 commit 2024-04-11 23:13:30 +02:00
This pull request has changes conflicting with the target branch.
  • source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc
  • source/blender/editors/grease_pencil/intern/grease_pencil_weight_paint.cc
  • source/blender/editors/include/ED_grease_pencil.hh

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u gpv3-weight-gradient-tool:SietseB-gpv3-weight-gradient-tool
git checkout SietseB-gpv3-weight-gradient-tool
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
2 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#118671
No description provided.