Cleanup: Tweak PBVH node face indices functions, add comments
This commit is contained in:
@@ -381,9 +381,22 @@ blender::Span<int> BKE_pbvh_node_get_vert_indices(const PBVHNode *node);
|
||||
blender::Span<int> BKE_pbvh_node_get_unique_vert_indices(const PBVHNode *node);
|
||||
blender::Span<int> BKE_pbvh_node_get_loops(const PBVHNode *node);
|
||||
|
||||
void BKE_pbvh_node_calc_face_indices(const PBVH &pbvh,
|
||||
const PBVHNode &node,
|
||||
blender::Vector<int> &faces);
|
||||
namespace blender::bke::pbvh {
|
||||
|
||||
/**
|
||||
* Gather the indices of all faces (not triangles) used by the node.
|
||||
* For convenience, pass a reference to the data in the result.
|
||||
*/
|
||||
Span<int> node_face_indices_calc_mesh(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces);
|
||||
|
||||
/**
|
||||
* Gather the indices of all base mesh faces in the node.
|
||||
* For convenience, pass a reference to the data in the result.
|
||||
*/
|
||||
Span<int> node_face_indices_calc_grids(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces);
|
||||
|
||||
} // namespace blender::bke::pbvh
|
||||
|
||||
blender::Vector<int> BKE_pbvh_node_calc_face_indices(const PBVH &pbvh, const PBVHNode &node);
|
||||
|
||||
/* Get number of faces in the mesh; for PBVH_GRIDS the
|
||||
|
||||
@@ -1804,43 +1804,57 @@ blender::Span<int> BKE_pbvh_node_get_unique_vert_indices(const PBVHNode *node)
|
||||
return node->vert_indices.as_span().take_front(node->uniq_verts);
|
||||
}
|
||||
|
||||
void BKE_pbvh_node_calc_face_indices(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces)
|
||||
namespace blender::bke::pbvh {
|
||||
|
||||
Span<int> node_face_indices_calc_mesh(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces)
|
||||
{
|
||||
faces.clear();
|
||||
const Span<int> looptri_faces = pbvh.looptri_faces;
|
||||
int prev_face = -1;
|
||||
for (const int tri : node.prim_indices) {
|
||||
const int face = looptri_faces[tri];
|
||||
if (face != prev_face) {
|
||||
faces.append(face);
|
||||
prev_face = face;
|
||||
}
|
||||
}
|
||||
return faces.as_span();
|
||||
}
|
||||
|
||||
Span<int> node_face_indices_calc_grids(const PBVH &pbvh, const PBVHNode &node, Vector<int> &faces)
|
||||
{
|
||||
faces.clear();
|
||||
const Span<int> grid_to_face_map = pbvh.subdiv_ccg->grid_to_face_map;
|
||||
int prev_face = -1;
|
||||
for (const int prim : node.prim_indices) {
|
||||
const int face = grid_to_face_map[prim];
|
||||
if (face != prev_face) {
|
||||
faces.append(face);
|
||||
prev_face = face;
|
||||
}
|
||||
}
|
||||
return faces.as_span();
|
||||
}
|
||||
|
||||
} // namespace blender::bke::pbvh
|
||||
|
||||
blender::Vector<int> BKE_pbvh_node_calc_face_indices(const PBVH &pbvh, const PBVHNode &node)
|
||||
{
|
||||
using namespace blender::bke::pbvh;
|
||||
Vector<int> faces;
|
||||
switch (pbvh.header.type) {
|
||||
case PBVH_FACES: {
|
||||
const Span<int> looptri_faces = pbvh.looptri_faces;
|
||||
int prev_face = -1;
|
||||
for (const int tri : node.prim_indices) {
|
||||
const int face = looptri_faces[tri];
|
||||
if (face != prev_face) {
|
||||
faces.append(face);
|
||||
prev_face = face;
|
||||
}
|
||||
}
|
||||
node_face_indices_calc_mesh(pbvh, node, faces);
|
||||
break;
|
||||
}
|
||||
case PBVH_GRIDS: {
|
||||
const SubdivCCG &subdiv_ccg = *pbvh.subdiv_ccg;
|
||||
int prev_face = -1;
|
||||
for (const int prim : node.prim_indices) {
|
||||
const int face = BKE_subdiv_ccg_grid_to_face_index(subdiv_ccg, prim);
|
||||
if (face != prev_face) {
|
||||
faces.append(face);
|
||||
prev_face = face;
|
||||
}
|
||||
}
|
||||
node_face_indices_calc_grids(pbvh, node, faces);
|
||||
break;
|
||||
}
|
||||
case PBVH_BMESH:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
blender::Vector<int> BKE_pbvh_node_calc_face_indices(const PBVH &pbvh, const PBVHNode &node)
|
||||
{
|
||||
Vector<int> faces;
|
||||
BKE_pbvh_node_calc_face_indices(pbvh, node, faces);
|
||||
return faces;
|
||||
}
|
||||
|
||||
|
||||
@@ -497,9 +497,8 @@ static void face_sets_update(Object &object,
|
||||
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
|
||||
TLS &tls = all_tls.local();
|
||||
for (PBVHNode *node : nodes.slice(range)) {
|
||||
tls.face_indices.clear();
|
||||
BKE_pbvh_node_calc_face_indices(pbvh, *node, tls.face_indices);
|
||||
const Span<int> faces = tls.face_indices;
|
||||
const Span<int> faces = bke::pbvh::node_face_indices_calc_mesh(
|
||||
pbvh, *node, tls.face_indices);
|
||||
|
||||
tls.new_face_sets.reinitialize(faces.size());
|
||||
MutableSpan<int> new_face_sets = tls.new_face_sets;
|
||||
@@ -954,9 +953,8 @@ static void face_hide_update(Object &object,
|
||||
threading::parallel_for(nodes.index_range(), 1, [&](const IndexRange range) {
|
||||
TLS &tls = all_tls.local();
|
||||
for (PBVHNode *node : nodes.slice(range)) {
|
||||
tls.face_indices.clear();
|
||||
BKE_pbvh_node_calc_face_indices(pbvh, *node, tls.face_indices);
|
||||
const Span<int> faces = tls.face_indices;
|
||||
const Span<int> faces = bke::pbvh::node_face_indices_calc_mesh(
|
||||
pbvh, *node, tls.face_indices);
|
||||
|
||||
tls.new_hide.reinitialize(faces.size());
|
||||
MutableSpan<bool> new_hide = tls.new_hide;
|
||||
|
||||
@@ -326,7 +326,7 @@ static void update_modified_node_mesh(PBVHNode *node, void *userdata)
|
||||
Vector<int> faces;
|
||||
if (!data->modified_face_set_faces.is_empty()) {
|
||||
if (faces.is_empty()) {
|
||||
faces = BKE_pbvh_node_calc_face_indices(*data->pbvh, *node);
|
||||
bke::pbvh::node_face_indices_calc_mesh(*data->pbvh, *node, faces);
|
||||
}
|
||||
for (const int face : faces) {
|
||||
if (data->modified_face_set_faces[face]) {
|
||||
@@ -337,7 +337,7 @@ static void update_modified_node_mesh(PBVHNode *node, void *userdata)
|
||||
}
|
||||
if (!data->modified_hidden_faces.is_empty()) {
|
||||
if (faces.is_empty()) {
|
||||
faces = BKE_pbvh_node_calc_face_indices(*data->pbvh, *node);
|
||||
bke::pbvh::node_face_indices_calc_mesh(*data->pbvh, *node, faces);
|
||||
}
|
||||
for (const int face : faces) {
|
||||
if (data->modified_hidden_faces[face]) {
|
||||
@@ -370,7 +370,7 @@ static void update_modified_node_grids(PBVHNode *node, void *userdata)
|
||||
Vector<int> faces;
|
||||
if (!data->modified_face_set_faces.is_empty()) {
|
||||
if (faces.is_empty()) {
|
||||
faces = BKE_pbvh_node_calc_face_indices(*data->pbvh, *node);
|
||||
bke::pbvh::node_face_indices_calc_grids(*data->pbvh, *node, faces);
|
||||
}
|
||||
for (const int face : faces) {
|
||||
if (data->modified_face_set_faces[face]) {
|
||||
@@ -381,7 +381,7 @@ static void update_modified_node_grids(PBVHNode *node, void *userdata)
|
||||
}
|
||||
if (!data->modified_hidden_faces.is_empty()) {
|
||||
if (faces.is_empty()) {
|
||||
faces = BKE_pbvh_node_calc_face_indices(*data->pbvh, *node);
|
||||
bke::pbvh::node_face_indices_calc_grids(*data->pbvh, *node, faces);
|
||||
}
|
||||
for (const int face : faces) {
|
||||
if (data->modified_hidden_faces[face]) {
|
||||
|
||||
Reference in New Issue
Block a user