Animation: Weight Paint select more/less for faces #105607
|
@ -350,6 +350,29 @@ 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,
|
||||
|
||||
blender::Span<MEdge> edges,
|
||||
blender::Span<bool> select_vert,
|
||||
const bool face_step)
|
||||
{
|
||||
for (const int edge_index : edge_indices) {
|
||||
const MEdge &edge = edges[edge_index];
|
||||
/* If a poly is selected, all of its verts are selected too, meaning that neighboring faces
|
||||
* will have some vertices selected. */
|
||||
if (face_step) {
|
||||
if (select_vert[edge.v1] || select_vert[edge.v2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (select_vert[edge.v1] && select_vert[edge.v2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void paintface_select_more(Mesh *mesh, const bool face_step)
|
||||
{
|
||||
using namespace blender;
|
||||
|
@ -372,22 +395,11 @@ void paintface_select_more(Mesh *mesh, const bool face_step)
|
|||
continue;
|
||||
}
|
||||
const MPoly &poly = polys[i];
|
||||
|
||||
for (const int edge_index : corner_edges.slice(poly.loopstart, poly.totloop)) {
|
||||
const MEdge &edge = edges[edge_index];
|
||||
/* If a poly is selected, all of its verts are selected too, meaning that neighboring faces
|
||||
* will have some vertices selected. */
|
||||
bool selected_neighbor = false;
|
||||
if (face_step) {
|
||||
selected_neighbor = select_vert.span[edge.v1] || select_vert.span[edge.v2];
|
||||
}
|
||||
else {
|
||||
selected_neighbor = select_vert.span[edge.v1] && select_vert.span[edge.v2];
|
||||
}
|
||||
if (selected_neighbor) {
|
||||
select_poly.span[i] = true;
|
||||
break;
|
||||
}
|
||||
if (poly_has_selected_neighbor(corner_edges.slice(poly.loopstart, poly.totloop),
|
||||
Sybren A. Stüvel
commented
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. The condition can be avoided by doing something like:
```cpp
const bool has_selected_neighbour = poly_has_selected_neighbor(...);
select_poly.span[i] |= has_selected_neighbour;
```
Not sure if it's worth it though, you choose @ChrisLend. Could be applied below as well.
|
||||
edges,
|
||||
Hans Goudey
commented
Blender uses American English spelling, so Blender uses American English spelling, so `neighbor` instead of `neighbor`
|
||||
select_vert.span,
|
||||
face_step)) {
|
||||
select_poly.span[i] = true;
|
||||
}
|
||||
}
|
||||
Hans Goudey
commented
It might be clearer for these functions to have slightly lower level arguments, like 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.
This might be my limited understanding of C++ but I can't get this to work. Edit since it seems to not have linked to your comment. 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
Hans Goudey
commented
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. 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.
|
||||
});
|
||||
|
|
Canonical variable name for the edges of a face is
poly_edges