Animation: Weight Paint select more/less for vertices #105633

Merged
Christoph Lendenfeld merged 14 commits from ChrisLend/blender:weight_paint_grow_sel_vert into main 2023-03-31 14:48:09 +02:00
1 changed files with 34 additions and 0 deletions
Showing only changes of commit b946ed4a8b - Show all commits

View File

@ -24,6 +24,7 @@
#include "BKE_customdata.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object.h"
#include "ED_mesh.h"
@ -659,6 +660,15 @@ void paintvert_select_linked(bContext *C, Object *ob)
paintvert_select_linked_vertices(C, ob, indices, true);
}
static void select_poly_verts(const MPoly &poly,
const blender::Span<MLoop> &loops,
blender::bke::SpanAttributeWriter<bool> &select_vert)
{
for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) {
select_vert.span[loop.v] = true;
}
}
void paintvert_select_more(bContext *C, Object *ob, const bool face_step)
{
using namespace blender;
@ -672,17 +682,33 @@ void paintvert_select_more(bContext *C, Object *ob, const bool face_step)
".select_vert", ATTR_DOMAIN_POINT);
const VArray<bool> hide_edge = attributes.lookup_or_default<bool>(
".hide_edge", ATTR_DOMAIN_EDGE, false);
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(

You set every value of the bit vector, so there's no need to explicitly initialize it to false here.

You set every value of the bit vector, so there's no need to explicitly initialize it to false here.
".hide_poly", ATTR_DOMAIN_FACE, false);

The functionality is the same, but mesh_topology::build_edge_to_poly_map(..) has an interface that's a bit more friendly in C++. Performance might be slightly worse currently, but there are plans to improve those functions in the near future.

The functionality is the same, but `mesh_topology::build_edge_to_poly_map(..)` has an interface that's a bit more friendly in C++. Performance might be slightly worse currently, but there are plans to improve those functions in the near future.
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
const Span<MEdge> edges = mesh->edges();
MeshElemMap *edge_poly_map;
int *edge_poly_mem;
if (face_step) {
BKE_mesh_edge_poly_map_create(&edge_poly_map,
&edge_poly_mem,
edges.size(),
polys.data(),
polys.size(),
loops.data(),
loops.size());
}
/* Need a copy of the selected verts that we can read from and is not modified. */
BitVector<> select_vert_original(mesh->totvert, false);
for (int i = 0; i < mesh->totvert; i++) {
select_vert_original[i].set(select_vert.span[i]);
}
/* If we iterated over polys we wouldn't extend the selection through edges that have no face
* attached to them. */
for (const int i : edges.index_range()) {
const MEdge &edge = edges[i];
bool has_vertex_selected = false;
@ -693,6 +719,14 @@ void paintvert_select_more(bContext *C, Object *ob, const bool face_step)
select_vert.span[edge.v1] = true;
select_vert.span[edge.v2] = true;
if (face_step && has_vertex_selected) {
const Span<int> neighbor_polys(edge_poly_map[i].indices, edge_poly_map[i].count);
for (const int poly_i : neighbor_polys) {
if (hide_poly[poly_i]) {
continue;
}
const MPoly &poly = polys[poly_i];
select_poly_verts(poly, loops, select_vert);
}
}
}