Animation: Weight Paint select more/less for faces
#105607
Merged
Christoph Lendenfeld
merged 13 commits from ChrisLend/blender:weight_paint_grow_sel_face
into main
Reviewers
Request review
No reviewers
Labels
Clear labels
Issues relating to security: https://wiki.blender.org/wiki/Process/Vulnerability_Reports
Apply labels
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
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
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
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
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
Issues relating to security: https://wiki.blender.org/wiki/Process/Vulnerability_Reports
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 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
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
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
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
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
Milestone
Set milestone
Clear milestone
No items
No Milestone
Projects
Set Project
Clear projects
No project
Assignees
Assign users
Clear assignees
No Assignees
5 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#105607
Reference in New Issue
There is no content yet.
Delete Branch "ChrisLend/blender:weight_paint_grow_sel_face"
Deleting a branch is permanent. It CANNOT be undone. Continue?
This adds the select more/less operators to the weight paint mode face selection.
Just like in edit mode, press
CTRL
+Numpad Plus/Minus
to use them.They have also been added to the
Select
menu.Relying on the existing selection flushing between domains seems like a nice way to do this.
@ -353,0 +401,4 @@
paintface_flush_flags(C, ob, true, false);
}
void paintface_select_less(bContext *C, Object *ob, const bool face_step)
It might be clearer for these functions to have slightly lower level arguments, like
(Mesh &mesh, const bool face_step)
in this case. That separates the abstraction levels more clearly, and means this function could be used in other situations where the context is different or the update tags aren't the same.@ -353,0 +419,4 @@
const Span<MLoop> loops = mesh->loops();
const Span<MEdge> edges = mesh->edges();
std::vector<bool> verts_of_unselected_faces(mesh->totvert, false);
I assume you're using
std::vector<bool>
because it works as a bitmap internally?blender::BitVector
should be a better choice here. See the reasoning at the top of that header.@ -353,0 +422,4 @@
std::vector<bool> verts_of_unselected_faces(mesh->totvert, false);
/* Find all vertices of unselected faces to help find neighboring faces after. */
for (const int i : select_poly.span.index_range()) {
Small thing, but maybe it's a bit clearer to write
polys.index_range()
thanselect_poly.span.index_range()
. That's just semantically closer to the goal of iterating over all polys.@ -353,0 +439,4 @@
}
const MPoly &poly = polys[i];
for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
What do you think about splitting this part into a separate function-- something like
bool poly_has_unselected_neighbor(Span<MLoop> poly_loops, bool face_step)
?I think that would make the logic here a bit simpler, and avoid the need for breaking inside the loop.
Something similar would be helpful above too.
@blender-bot package
Package build started. Download here when ready.
@ -353,0 +401,4 @@
paintface_flush_flags(C, ob, true, false);
}
void paintface_select_less(bContext *C, Object *ob, const bool face_step)
This might be my limited understanding of C++ but I can't get this to work.
Could it be that because the header file is
ED_mesh.h
meaning it's pure C so it doesn't understand references?Edit since it seems to not have linked to your comment.
It was about passing in
Mesh &mesh
instead of bContext and Object@ -353,0 +439,4 @@
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
const Span<MPoly> polys = mesh->polys();
I've split up this part. the argument list is a bit long though so I am a bit unsure if that is an improvement. Let me know what you think
@blender-bot package
Package build started. Download here when ready.
@ -353,0 +401,4 @@
paintface_flush_flags(C, ob, true, false);
}
static bool poly_has_unselected_neighbour(const MPoly &poly,
Yeah right, a couple options-- keep a function with this signature in the public header, and a static function with the signature I suggested, or use the signature I suggested with a pointer instead of a reference (that's probably the better option IMO).
Mainly I think it's nice to avoid just using the object argument to retrieve the mesh, and it's nice to avoid the null check because this function really shouldn't be concerned with whether there is no mesh, that's the job of somewhere else.
@ -353,0 +404,4 @@
static bool poly_has_unselected_neighbour(const MPoly &poly,
blender::Span<MLoop> poly_loops,
blender::Span<MEdge> edges,
blender::BitVector<> &verts_of_unselected_faces,
Replace the
BitVector
reference withconst BitSpan
, that will give a better idea of ownership and the fact that this doesn't need to modify the data.@ -353,0 +409,4 @@
{
for (const MLoop &loop : poly_loops.slice(poly.loopstart, poly.totloop)) {
const MEdge &edge = edges[loop.e];
bool unselected_neighbor = false;
It's not a big deal, but the function could be a bit simpler without the
unselected_neighbor
variable. It's nice to assign a variable a meaningful value in the same expression you initialize it, and that's not really the case here. Given the function name, returning early reads as "poly has an unselected neighbor" anyway.@ -353,0 +411,4 @@
const MEdge &edge = edges[loop.e];
bool unselected_neighbor = false;
if (face_step) {
unselected_neighbor = verts_of_unselected_faces[edge.v1].test() ||
What do you think about removing the
.test()
and usingBitRef
's implicit bool conversion?@ -353,0 +439,4 @@
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
const Span<MPoly> polys = mesh->polys();
poly_loops
is generally the name for a span containing the loops of a single polygon. Thepoly
argument could be removed by slicing theloops
span before passing it to the function.@ -353,0 +446,4 @@
BitVector<> verts_of_unselected_faces(mesh->totvert, false);
/* Find all vertices of unselected faces to help find neighboring faces after. */
for (const int i : select_poly.span.index_range()) {
Might as well change this to
polys.index_range()
instead ofselect_poly.span.index_range()
for the same reason I mentioned earlier too-- it just says more clearly "we're iterating over all faces" rather than "we're iterating over the face selection".I realize that's a bit nitpicky, just hoping you might agree and appreciate the more literal semantic argument :P
@ -353,0 +401,4 @@
blender::BitSpan verts_of_unselected_faces,
const bool face_step)
{
for (const MLoop &loop : poly_loops) {
now takes a
Mesh*
a potential clean up is to check if that can be done for other functions as well
@ -353,0 +409,4 @@
{
for (const MLoop &loop : poly_loops.slice(poly.loopstart, poly.totloop)) {
const MEdge &edge = edges[loop.e];
bool unselected_neighbor = false;
I thought to make it explicit what it is that the bool logic tests for, but I agree it's in the function name anyway
@ -353,0 +411,4 @@
const MEdge &edge = edges[loop.e];
bool unselected_neighbor = false;
if (face_step) {
unselected_neighbor = verts_of_unselected_faces[edge.v1].test() ||
yes good idea, done that
@ -353,0 +446,4 @@
BitVector<> verts_of_unselected_faces(mesh->totvert, false);
/* Find all vertices of unselected faces to help find neighboring faces after. */
for (const int i : select_poly.span.index_range()) {
yep agreed, missed that one :)
Almost there, thanks for the updates. Will need to be updated for #104424 though.
@ -353,0 +385,4 @@
selected_neighbor = select_vert.span[edge.v1] && select_vert.span[edge.v2];
}
if (selected_neighbor) {
select_poly.span[i] = true;
This is feeling a bit picky, sorry about that, but might as well extract this check for the poly instead of using a
break
like below (poly_has_unselected_neighbour
) I think it makes sense for them to be consistent anyway.@ -353,0 +396,4 @@
select_vert.finish();
}
static bool poly_has_unselected_neighbour(blender::Span<MLoop> poly_loops,
Blender uses American English spelling, so
neighbor
instead ofneighbor
@ -353,0 +440,4 @@
}
const MPoly &poly = polys[i];
for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
verts_of_unselected_faces[loop.v].set(true);
MLoop
has been replaced by two arrays inmain
. This loop can be simplified now:@HooglyBoogly I've implemented the changes for
MLoop
and extracted the functionpoly_has_selected_neighbor
it takes a
Span<bool>
as opposed topoly_has_unselected_neighbor
which takes aBitSpan
apart from that the functions are identical and I am wondering if they can be merged
Just one comment about an argument name, otherwise looks good!
@ -350,6 +350,131 @@ void paintface_select_linked(bContext *C, Object *ob, const int mval[2], const b
paintface_flush_flags(C, ob, true, false);
}
static bool poly_has_selected_neighbor(blender::Span<int> edge_indices,
Canonical variable name for the edges of a face is
poly_edges
@ -353,0 +452,4 @@
continue;
}
const MPoly &poly = polys[i];
for (const int vert_index : corner_verts.slice(poly.loopstart, poly.totloop)) {
vert_index
->vert
here too, though I mentioned that in chatLGTM!
Just one inline note, but no strong feelings about it -- just wanted to offer an alternative view. I'll leave the decision to you @ChrisLend.
@ -353,0 +395,4 @@
continue;
}
const MPoly &poly = polys[i];
if (poly_has_selected_neighbor(corner_edges.slice(poly.loopstart, poly.totloop),
The condition can be avoided by doing something like:
Not sure if it's worth it though, you choose @ChrisLend. Could be applied below as well.
@ -353,0 +395,4 @@
continue;
}
const MPoly &poly = polys[i];
if (poly_has_selected_neighbor(corner_edges.slice(poly.loopstart, poly.totloop),
had a look at it but I think it's a bit clearer if the bool is set explicitly so I left it as is
@ -353,0 +396,4 @@
select_vert.finish();
}
static bool poly_has_unselected_neighbour(blender::Span<MLoop> poly_loops,
thanks, that always gets me
0187943a3d
into mainJust noting this is also for other modes using paint mask (vertexpaint & imagepaint equally benefit from it), noice!
Reviewers
0187943a3d
.