Refactor: Sculpt: Remove corner_tris reference from PBVH

Part of #118145.
This commit is contained in:
Hans Goudey
2024-06-25 21:33:20 -04:00
parent 59d6eae116
commit 9b9ed0a76d
9 changed files with 34 additions and 15 deletions

View File

@@ -167,6 +167,7 @@ bool raycast_node(PBVH &pbvh,
const float (*origco)[3],
bool use_origco,
Span<int> corner_verts,
Span<int3> corner_tris,
Span<int> corner_tri_faces,
Span<bool> hide_poly,
const float ray_start[3],
@@ -207,6 +208,7 @@ bool find_nearest_to_ray_node(PBVH &pbvh,
const float (*origco)[3],
bool use_origco,
Span<int> corner_verts,
Span<int3> corner_tris,
Span<int> corner_tri_faces,
Span<bool> hide_poly,
const float ray_start[3],
@@ -576,7 +578,7 @@ blender::float4 BKE_pbvh_vertex_color_get(const PBVH &pbvh,
blender::GroupedSpan<int> vert_to_face_map,
PBVHVertRef vertex);
void BKE_pbvh_ensure_node_loops(PBVH &pbvh);
void BKE_pbvh_ensure_node_loops(PBVH &pbvh, blender::Span<blender::int3> corner_tris);
int BKE_pbvh_debug_draw_gen_get(PBVHNode &node);
namespace blender::bke::pbvh {

View File

@@ -1818,7 +1818,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
/* Ensure pbvh nodes have loop indices; the sculpt undo system
* needs them for color attributes.
*/
BKE_pbvh_ensure_node_loops(*ss.pbvh);
BKE_pbvh_ensure_node_loops(*ss.pbvh, mesh_orig->corner_tris());
}
/*

View File

@@ -323,7 +323,7 @@ static void build_leaf(PBVH &pbvh,
/* Still need vb for searches */
update_vb(pbvh.prim_indices, &node, prim_bounds, offset, count);
if (!pbvh.corner_tris.is_empty()) {
if (!corner_tris.is_empty()) {
build_mesh_leaf_node(corner_verts, corner_tris, tri_faces, hide_poly, vert_bitmap, &node);
}
else {
@@ -657,7 +657,6 @@ std::unique_ptr<PBVH> build_mesh(Mesh *mesh)
MutableSpan<float3> vert_positions = mesh->vert_positions_for_write();
const Span<int> corner_verts = mesh->corner_verts();
const Span<int3> corner_tris = mesh->corner_tris();
pbvh->corner_tris = corner_tris;
pbvh->mesh = mesh;
@@ -1999,6 +1998,7 @@ static bool pbvh_faces_node_raycast(PBVH &pbvh,
const PBVHNode *node,
const float (*origco)[3],
const Span<int> corner_verts,
const Span<int3> corner_tris,
const Span<int> corner_tri_faces,
const Span<bool> hide_poly,
const float ray_start[3],
@@ -2016,7 +2016,7 @@ static bool pbvh_faces_node_raycast(PBVH &pbvh,
for (const int i : node->prim_indices.index_range()) {
const int tri_i = node->prim_indices[i];
const int3 &tri = pbvh.corner_tris[tri_i];
const int3 &tri = corner_tris[tri_i];
const int3 face_verts = node->face_vert_indices[i];
if (!hide_poly.is_empty() && hide_poly[corner_tri_faces[tri_i]]) {
@@ -2165,6 +2165,7 @@ bool raycast_node(PBVH &pbvh,
const float (*origco)[3],
bool use_origco,
const Span<int> corner_verts,
const Span<int3> corner_tris,
const Span<int> corner_tri_faces,
const Span<bool> hide_poly,
const float ray_start[3],
@@ -2187,6 +2188,7 @@ bool raycast_node(PBVH &pbvh,
node,
origco,
corner_verts,
corner_tris,
corner_tri_faces,
hide_poly,
ray_start,
@@ -2358,6 +2360,7 @@ static bool pbvh_faces_node_nearest_to_ray(PBVH &pbvh,
const PBVHNode *node,
const float (*origco)[3],
const Span<int> corner_verts,
const Span<int3> corner_tris,
const Span<int> corner_tri_faces,
const Span<bool> hide_poly,
const float ray_start[3],
@@ -2371,7 +2374,7 @@ static bool pbvh_faces_node_nearest_to_ray(PBVH &pbvh,
for (const int i : node->prim_indices.index_range()) {
const int tri_i = node->prim_indices[i];
const int3 &corner_tri = pbvh.corner_tris[tri_i];
const int3 &corner_tri = corner_tris[tri_i];
const int3 face_verts = node->face_vert_indices[i];
if (!hide_poly.is_empty() && hide_poly[corner_tri_faces[tri_i]]) {
@@ -2468,6 +2471,7 @@ bool find_nearest_to_ray_node(PBVH &pbvh,
const float (*origco)[3],
bool use_origco,
const Span<int> corner_verts,
const Span<int3> corner_tris,
const Span<int> corner_tri_faces,
const Span<bool> hide_poly,
const float ray_start[3],
@@ -2487,6 +2491,7 @@ bool find_nearest_to_ray_node(PBVH &pbvh,
node,
origco,
corner_verts,
corner_tris,
corner_tri_faces,
hide_poly,
ray_start,
@@ -2591,7 +2596,7 @@ static blender::draw::pbvh::PBVH_GPU_Args pbvh_draw_args_init(const Mesh &mesh,
args.vert_positions = pbvh.vert_positions;
args.corner_verts = mesh.corner_verts();
args.corner_edges = mesh.corner_edges();
args.corner_tris = pbvh.corner_tris;
args.corner_tris = mesh.corner_tris();
args.vert_normals = pbvh.vert_normals;
args.face_normals = pbvh.face_normals;
/* Retrieve data from the original mesh. Ideally that would be passed to this function to
@@ -3052,7 +3057,7 @@ void BKE_pbvh_update_active_vcol(PBVH &pbvh, Mesh *mesh)
BKE_pbvh_get_color_layer(mesh, &pbvh.color_layer, &pbvh.color_domain);
}
void BKE_pbvh_ensure_node_loops(PBVH &pbvh)
void BKE_pbvh_ensure_node_loops(PBVH &pbvh, const Span<blender::int3> corner_tris)
{
using namespace blender;
BLI_assert(BKE_pbvh_type(pbvh) == PBVH_FACES);
@@ -3084,7 +3089,7 @@ void BKE_pbvh_ensure_node_loops(PBVH &pbvh)
corner_indices.clear();
for (const int i : node.prim_indices) {
const int3 &tri = pbvh.corner_tris[i];
const int3 &tri = corner_tris[i];
for (int k = 0; k < 3; k++) {
if (!BLI_BITMAP_TEST(visit, tri[k])) {

View File

@@ -154,7 +154,6 @@ struct PBVH {
/** Only valid for polygon meshes. */
blender::OffsetIndices<int> faces;
blender::Span<int> corner_verts;
blender::Span<blender::int3> corner_tris;
/* Grid Data */
CCGKey gridkey;

View File

@@ -669,7 +669,7 @@ static bool update_pixels(PBVH &pbvh, Mesh *mesh, Image *image, ImageUser *image
const VArraySpan uv_map = *attributes.lookup<float2>(active_uv_name, AttrDomain::Corner);
uv_islands::MeshData mesh_data(
pbvh.corner_tris, mesh->corner_verts(), uv_map, pbvh.vert_positions);
mesh->corner_tris(), mesh->corner_verts(), uv_map, pbvh.vert_positions);
uv_islands::UVIslands islands(mesh_data);
uv_islands::UVIslandsMask uv_masks;

View File

@@ -1975,9 +1975,10 @@ static int vpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
event->type);
Object &ob = *CTX_data_active_object(C);
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
if (SCULPT_has_loop_colors(ob) && ob.sculpt->pbvh) {
BKE_pbvh_ensure_node_loops(*ob.sculpt->pbvh);
BKE_pbvh_ensure_node_loops(*ob.sculpt->pbvh, mesh.corner_tris());
}
undo::push_begin_ex(ob, "Vertex Paint");

View File

@@ -3125,6 +3125,7 @@ struct SculptRaycastData {
float depth;
bool original;
Span<int> corner_verts;
Span<blender::int3> corner_tris;
Span<int> corner_tri_faces;
blender::VArraySpan<bool> hide_poly;
@@ -3144,6 +3145,7 @@ struct SculptFindNearestToRayData {
float dist_sq_to_ray;
bool original;
Span<int> corner_verts;
Span<blender::int3> corner_tris;
Span<int> corner_tri_faces;
blender::VArraySpan<bool> hide_poly;
};
@@ -3605,7 +3607,8 @@ static void do_brush_action(const Scene &scene,
return;
}
BKE_pbvh_ensure_node_loops(*ss.pbvh);
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
BKE_pbvh_ensure_node_loops(*ss.pbvh, mesh.corner_tris());
}
const bool use_original = sculpt_tool_needs_original(brush.sculpt_tool) ? true :
@@ -5137,6 +5140,7 @@ static void sculpt_raycast_cb(PBVHNode &node, SculptRaycastData &srd, float *tmi
origco,
use_origco,
srd.corner_verts,
srd.corner_tris,
srd.corner_tri_faces,
srd.hide_poly,
srd.ray_start,
@@ -5181,6 +5185,7 @@ static void sculpt_find_nearest_to_ray_cb(PBVHNode &node,
origco,
use_origco,
srd.corner_verts,
srd.corner_tris,
srd.corner_tri_faces,
srd.hide_poly,
srd.ray_start,
@@ -5276,6 +5281,7 @@ bool SCULPT_cursor_geometry_info_update(bContext *C,
if (BKE_pbvh_type(*ss.pbvh) == PBVH_FACES) {
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
srd.corner_verts = mesh.corner_verts();
srd.corner_tris = mesh.corner_tris();
srd.corner_tri_faces = mesh.corner_tri_faces();
const bke::AttributeAccessor attributes = mesh.attributes();
srd.hide_poly = *attributes.lookup<bool>(".hide_poly", bke::AttrDomain::Face);
@@ -5426,6 +5432,7 @@ bool SCULPT_stroke_get_location_ex(bContext *C,
if (BKE_pbvh_type(*ss.pbvh) == PBVH_FACES) {
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
srd.corner_verts = mesh.corner_verts();
srd.corner_tris = mesh.corner_tris();
srd.corner_tri_faces = mesh.corner_tri_faces();
const bke::AttributeAccessor attributes = mesh.attributes();
srd.hide_poly = *attributes.lookup<bool>(".hide_poly", bke::AttrDomain::Face);
@@ -5460,6 +5467,7 @@ bool SCULPT_stroke_get_location_ex(bContext *C,
if (BKE_pbvh_type(*ss.pbvh) == PBVH_FACES) {
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
srd.corner_verts = mesh.corner_verts();
srd.corner_tris = mesh.corner_tris();
srd.corner_tri_faces = mesh.corner_tri_faces();
const bke::AttributeAccessor attributes = mesh.attributes();
srd.hide_poly = *attributes.lookup<bool>(".hide_poly", bke::AttrDomain::Face);
@@ -6406,6 +6414,7 @@ bool SCULPT_vertex_is_occluded(SculptSession &ss, PBVHVertRef vertex, bool origi
srd.face_normal = face_normal;
srd.corner_verts = ss.corner_verts;
if (BKE_pbvh_type(*ss.pbvh) == PBVH_FACES) {
srd.corner_tris = BKE_pbvh_get_mesh(*ss.pbvh)->corner_tris();
srd.corner_tri_faces = BKE_pbvh_get_mesh(*ss.pbvh)->corner_tri_faces();
}

View File

@@ -25,6 +25,7 @@
#include "BKE_brush.hh"
#include "BKE_context.hh"
#include "BKE_layer.hh"
#include "BKE_mesh.hh"
#include "BKE_modifier.hh"
#include "BKE_object_types.hh"
#include "BKE_paint.hh"
@@ -113,7 +114,8 @@ void cache_init(bContext *C,
ss.filter_cache->random_seed = rand();
if (undo_type == undo::Type::Color) {
BKE_pbvh_ensure_node_loops(pbvh);
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
BKE_pbvh_ensure_node_loops(pbvh, mesh.corner_tris());
}
ss.filter_cache->nodes = bke::pbvh::search_gather(

View File

@@ -878,7 +878,8 @@ static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEven
const bool preserve_mask = RNA_boolean_get(op->ptr, "preserve_previous_mask");
if (SCULPT_has_loop_colors(ob)) {
BKE_pbvh_ensure_node_loops(*ss.pbvh);
const Mesh &mesh = *static_cast<const Mesh *>(ob.data);
BKE_pbvh_ensure_node_loops(*ss.pbvh, mesh.corner_tris());
}
if (RNA_boolean_get(op->ptr, "contiguous")) {