GPencil: Several Weight Paint additions #106663
No reviewers
Labels
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
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
Viewport & EEVEE
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#106663
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "SietseB/blender:gp-weight-paint-additions"
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?
This patch adds several tools and options to the weight paint mode of Grease Pencil.
More tools
Draw tool: switch easily between 'add' and 'subtract'
With the + and - icons in the toolbar, the user can easily switch between adding and subtracting weight while drawing weights.
With shortcut
D
you can toggle between these two.New option: auto-normalize
The auto-normalize options ensures that all bone-deforming vertex groups add up to 1.0 while weight painting.
Radial control for weight
With
Ctrl-F
a radial control for weight is invoked (in addition to the radial controls for brush size and strength).Sample weight
With
Ctrl-RMB
the user can sample the weight. This sets the brush Weight from the weight under the cursor.Quick bone selection
When painting weights in vertex groups for bones, the user can quickly switch to another vertex group by clicking on a bone with
Ctrl-LMB
.For this to work, follow these steps:
Ctrl-LMB
. The corresponding vertex group is automatically activated.Technical note
Where possible, the same logic and conventions as in the 3D weight paint section of Blender were followed.
Thank you for the PR :)
Unfortunately, since the GP 3.0 project has started, we try to not change the current behavior of grease pencil. However, it looks like this code will be easy to port to the new data structure. So I would put this on hold and then integrate it once weight painting is there in GP 3.0.
I've already put it on the Grease Pencil workboard.
I don't know how the GP 3.0 refactor will be organized after the first milestone is reached (core devs only or a community project), but if it is of any use, I could assist in the refactor of weight paint code - since I am acquainted with it now :-)
It will be a community effort, so help in getting the weight painting code up to speed will be very welcome!
First review pass on this. Overall the code already looks very good 👍 I still need to do some more testing though.
@ -1417,0 +1418,4 @@
gp_settings = brush.gpencil_settings
text = "" if compact else "Direction"
layout.prop(gp_settings, "direction", expand=True, text=text)
I think in this case it's nicer to inline the
if compact else
.layout.prop(gp_settings, "direction", expand=True, text="" if compact else "Direction")
@ -45,6 +45,7 @@ def generate_from_enum_ex(
dict(
idname=idname_prefix + name,
label=name,
description=(enum.description),
No need for the parentheses.
@ -4253,1 +4253,4 @@
if (!MAIN_VERSION_ATLEAST(bmain, 306, 5)) {
/* Rename Grease Pencil weight draw brush. */
do_versions_rename_id(bmain, ID_BR, "Draw Weight", "Weight Draw");
Would like to confirm that this works correctly.
@ -164,2 +235,2 @@
if (buffer_array != NULL) {
memset(buffer_array, 0, sizeof(tGP_Selected) * *buffer_size);
/* Ensure a vertex group for the weight paint brush. */
static void gpencil_vertex_group_ensure(tGP_BrushWeightpaintData *gso)
This function should use the "early return" pattern.
E.g.
I meant to say that this whole function should use this pattern. It can be rewritten like so:
There are a few things that are suspicious to me in this. Like tagging all the relations in
bmain
and the fact that the return value ofBKE_object_defgroup_add_name
is unused.I could have understood that the first time ;-)
Done. Removed the last
dg =
.I didn't write this code myself, just moved it. Don't know much about the depsgraph, so I don't know if the
DEG_relations_tag_update
is entirely necessary.I noticed some similarities in
ED_wpaint_ensure_data
inpaint_vertex_weight_utils.c
, including the unuseddg =
, so maybe some of the code was borrowed from there in the past.@ -166,0 +277,4 @@
/* Get boolean array of vertex groups deformed by GP armature modifiers.
* GP equivalent of `BKE_object_defgroup_validmap_get`.
*/
bool *gpencil_vgroup_bone_deformed_map_get(Object *ob, const int defbase_tot)
Should be
static bool *
@ -166,0 +324,4 @@
/* Mark vertex groups with reference in the bone hash table. */
vgroup_bone_deformed = MEM_mallocN(sizeof(*vgroup_bone_deformed) * defbase_tot,
"wpaint bone deformed map");
Should use
__func__
for the allocation name.@ -248,0 +632,4 @@
/* Calculate the average (=blurred) weight. */
float blur_weight = 0.0f, dist_sum = 0.0f;
int i, count = 0;
Move declaration of
i
in thefor
loop(s).@ -248,0 +684,4 @@
float point_dot[8] = {0};
float point_dir[2];
float score_max = 0.0f, dist_min = FLT_MAX, dist_max = 0.0f;
int i_max = -1, count = 0, i;
Same as above, move declaration of
i
inside the loop.@ -526,3 +1129,4 @@
* required to do some step. Now is not used, but the operator is ready.
*--------------------------------------------------------------------- */
int gps_index = -1;
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
Should use
LISTBASE_FOREACH_INDEX
.@ -3095,2 +3091,2 @@
* are in object mode it might falsely toggle object selection. Alternatively, this could be
* put in the poll function instead. */
if (obact && obact->type == OB_GPENCIL_LEGACY &&
GPENCIL_NON_WEIGHT_MODE((bGPdata *)obact->data)) {
No need for a new macro, this should just be
(obact->data && (gpd->flag & GP_DATA_STROKE_WEIGHTMODE == 0))
It's a bit tricky one. Selection is allowed in Weight Mode and Object Mode, so that's the test here. But there is no active way to test for Object Mode, AFAIK. Hence the macro...
All those macro names are a bit obscure, none of them mentions Object Mode. So I followed that convention. But I can easily rename it, of course. Or you even have a better solution...
Alright, lets keep it like you have it for now.
Also needs a merge with
main
.Gpencil: several weight paint additionsto GPencil: Several Weight Paint additionsI processed the review comments (except for the last one, see my reaction).
And merged with
main
.Oh yeah, I discovered a small error in the old code today: a double falloff was applied in the weight brush. I added a fix for that too.
Second pass. Some more smaller things that stood out to me.
@ -170,0 +409,4 @@
return true;
}
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
Declare
i
in this loop.@ -170,0 +434,4 @@
if (sum_lock >= 1.0f - VERTEX_WEIGHT_LOCK_EPSILON) {
/* locked groups make it impossible to fully normalize,
* zero out what we can and return false */
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
Same as above.
@ -170,0 +448,4 @@
if (sum_unlock != 0.0f) {
fac = (1.0f - sum_lock) / sum_unlock;
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
Same as above.
@ -170,0 +462,4 @@
fac = (1.0f - sum_lock) / tot;
CLAMP(fac, 0.0f, 1.0f);
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
Same as above.
@ -911,0 +1642,4 @@
/* Look for two closest points. */
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = gps->points + i;
Generally we do not use pointer arithmetic when accessing elements in an array. Use
&gps->points[i]
.@ -911,0 +1652,4 @@
if ((dist < closest_dist[0]) || (dist < closest_dist[1])) {
/* Get weight. */
MDeformVert *dvert = gps->dvert + i;
Same as above.
@antoniov We need to make sure this gets added to the release notes and also update the manual once we merge.
@blender-bot build
Second review processed. And merged with
main
again.