GPv3: Create weights on draw for new strokes. #119302

Open
casey-bianco-davis wants to merge 14 commits from casey-bianco-davis/blender:GPv3-Create-weights-on-draw into main

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

Implements the legacy weight_data_add button for GPv3.

Note: This PR properly accounts for the bone's transformation when applying so that the stroke does not appear to teleport after drawing, unlike the legacy system.

Implements the legacy `weight_data_add` button for GPv3. Note: This PR properly accounts for the bone's transformation when applying so that the stroke does not appear to teleport after drawing, unlike the legacy system.
casey-bianco-davis added the
Interest
Grease Pencil
Module
Grease Pencil
labels 2024-03-11 01:54:10 +01:00
casey-bianco-davis added 1 commit 2024-03-11 01:54:15 +01:00
casey-bianco-davis added this to the Grease Pencil project 2024-03-11 01:54:18 +01:00
casey-bianco-davis requested review from Falk David 2024-03-11 01:59:46 +01:00
casey-bianco-davis added 1 commit 2024-03-11 02:07:14 +01:00
casey-bianco-davis added 1 commit 2024-03-11 03:14:14 +01:00
casey-bianco-davis added 1 commit 2024-03-13 04:17:00 +01:00
Sietse Brouwer reviewed 2024-03-13 19:49:47 +01:00
Sietse Brouwer left a comment
Member

You are really on fire, I see a lot of great PRs from your hand – very nice!

A few tiny remarks from a fellow community contributor.

Btw, I like the addition of compensating for the bone transformation. It's one of those smart little things that make Grease Pencil artist-friendly.

You are really on fire, I see a lot of great PRs from your hand – very nice! A few tiny remarks from a fellow community contributor. Btw, I like the addition of compensating for the bone transformation. It's one of those smart little things that make Grease Pencil artist-friendly.
@ -596,0 +616,4 @@
const bDeformGroup *defgroup = static_cast<const bDeformGroup *>(
BLI_findlink(BKE_object_defgroup_list(object), def_nr));
Member

In case there is no vertex group:

if (def_nr == -1) {
  return;
}
In case there is no vertex group: ``` if (def_nr == -1) { return; } ```
casey-bianco-davis marked this conversation as resolved
@ -596,0 +620,4 @@
const StringRef vertex_group_name = defgroup->name;
blender::bke::greasepencil::assign_to_vertex_group_from_selection(
curves, IndexMask(points), vertex_group_name, 1.0f);
Member

Any reason to switch here from IndexRange to IndexMask? Ignore my question when there is 🔕

And at first glance I thought this function had something to do with the .selection attribute. So perhaps something like assign_to_vertex_group_from_range is a better name?

Any reason to switch here from `IndexRange` to `IndexMask`? Ignore my question when there is :no_bell: And at first glance I thought this function had something to do with the `.selection` attribute. So perhaps something like `assign_to_vertex_group_from_range` is a better name?
casey-bianco-davis marked this conversation as resolved
@ -596,0 +623,4 @@
curves, IndexMask(points), vertex_group_name, 1.0f);
/* Loop through all modifiers trying to find the pose channel for the vertex group name. */
bPoseChannel *channel = NULL;
Member

Here and below: NULL -> nullptr

Here and below: `NULL` -> `nullptr`
casey-bianco-davis marked this conversation as resolved
@ -596,0 +635,4 @@
continue;
}
GreasePencilArmatureModifierData *amd = (GreasePencilArmatureModifierData *)md;
Member

reinterpret_cast<GreasePencilArmatureModifierData *>(md)

`reinterpret_cast<GreasePencilArmatureModifierData *>(md)`
casey-bianco-davis marked this conversation as resolved
@ -596,0 +655,4 @@
break;
}
/* nothing valid was found. */
Member

Nitpick: Capital N.

Nitpick: Capital N.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 5 commits 2024-03-13 21:25:34 +01:00
Falk David requested changes 2024-03-29 12:56:25 +01:00
Dismissed
Falk David left a comment
Member

Thanks for looking into this. One concern I have is about trying to inverse the deformation of modifiers in the paint tool. From what I could find, this wasn't done in GPv2? Generally, if we wanted to support this, we should be using the get_evaluated_grease_pencil_drawing_deformation API. This would allow you to get a matrix per curve/point with the deformation. And each modifier that supports this deformed space, would write into the edit component.

Thanks for looking into this. One concern I have is about trying to inverse the deformation of modifiers in the paint tool. From what I could find, this wasn't done in GPv2? Generally, if we wanted to support this, we should be using the `get_evaluated_grease_pencil_drawing_deformation` API. This would allow you to get a matrix per curve/point with the deformation. And each modifier that supports this deformed space, would write into the edit component.
Author
Member

The legacy system did not convert the points when applying the weights.

I will look in to using get_evaluated_grease_pencil_drawing_deformation but currently it does not work with deform_mats

The legacy system did not convert the points when applying the weights. I will look in to using `get_evaluated_grease_pencil_drawing_deformation` but currently it does not work with `deform_mats`
casey-bianco-davis added 1 commit 2024-05-18 00:48:03 +02:00
casey-bianco-davis added 2 commits 2024-07-06 04:57:56 +02:00
Falk David requested changes 2024-07-08 11:08:08 +02:00
Dismissed
Falk David left a comment
Member

Did a quick pass over this.

Did a quick pass over this.
@ -68,0 +90,4 @@
const MutableSpan<MDeformVert> dverts = curves.deform_verts_for_write();
mask.foreach_index([&](const int point_i) {
MDeformWeight *dw = BKE_defvert_ensure_index(&dverts[point_i], def_nr);
if (dw) {
Member

Might as well write it like this: if (MDeformWeight *dw = BKE_defvert_ensure_index(&dverts[point_i], def_nr)) {

Might as well write it like this: `if (MDeformWeight *dw = BKE_defvert_ensure_index(&dverts[point_i], def_nr)) {`
casey-bianco-davis marked this conversation as resolved
@ -1335,0 +1358,4 @@
curves, IndexMask(points), vertex_group_name, 1.0f);
/* Loop through all modifiers trying to find the pose channel for the vertex group name. */
bPoseChannel *channel = nullptr;
Member

Not sure why these two variables are forward declared.

Not sure why these two variables are forward declared.
Author
Member

The variables are declared outside of the loop so that they can be used if both are found at the end.

The variables are declared outside of the loop so that they can be used if both are found at the end.
@ -1335,0 +1404,4 @@
const float4x4 matrix = postmat * math::invert(float4x4(channel->chan_mat)) * premat;
/* Update the position of the stroke to undo the movement caused by the modifier.*/
MutableSpan<float3> positions = curves.positions_for_write().slice(points);
Member

Looks like we can use curves.transform(matrix); here.

Looks like we can use `curves.transform(matrix);` here.
Author
Member

curves.transform(matrix) works on all curves where as this wants only the newly added curve.
(I could modify curves.transform(matrix) to take a IndexMask if you what?)

`curves.transform(matrix)` works on all curves where as this wants only the newly added curve. (I could modify `curves.transform(matrix)` to take a `IndexMask` if you what?)
Member

Sorry, my bad, this is fine then.

Sorry, my bad, this is fine then.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis requested review from Falk David 2024-07-08 21:56:58 +02:00
casey-bianco-davis added 1 commit 2024-07-08 21:57:23 +02:00
Falk David requested changes 2024-07-16 11:08:20 +02:00
Dismissed
Falk David left a comment
Member

Tested this locally, and it seems to work well. Thank you. Just have one comment.

Tested this locally, and it seems to work well. Thank you. Just have one comment.
@ -1335,0 +1355,4 @@
const StringRef vertex_group_name = defgroup->name;
blender::bke::greasepencil::assign_to_vertex_group_from_mask(
curves, IndexMask(points), vertex_group_name, 1.0f);
Member

I checked the old code and it uses toolsettings->vgroup_weight here, instead of 1.0f. Seems a bit weird, but I would rather keep the old behavior than change it.

I checked the old code and it uses `toolsettings->vgroup_weight` here, instead of `1.0f`. Seems a bit weird, but I would rather keep the old behavior than change it.
casey-bianco-davis marked this conversation as resolved
casey-bianco-davis added 1 commit 2024-07-16 20:57:39 +02:00
Cleanup: Use edit mode vertex weight.
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
674ae6dbca
casey-bianco-davis requested review from Falk David 2024-07-16 20:57:41 +02:00
Falk David approved these changes 2024-07-17 14:06:07 +02:00
Member

@blender-bot build

@blender-bot build
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u GPv3-Create-weights-on-draw:casey-bianco-davis-GPv3-Create-weights-on-draw
git checkout casey-bianco-davis-GPv3-Create-weights-on-draw
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
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#119302
No description provided.