diff --git a/source/blender/blenkernel/BKE_pbvh_api.hh b/source/blender/blenkernel/BKE_pbvh_api.hh index 1f6a62e8740..f656bb1f9f5 100644 --- a/source/blender/blenkernel/BKE_pbvh_api.hh +++ b/source/blender/blenkernel/BKE_pbvh_api.hh @@ -167,6 +167,7 @@ bool raycast_node(PBVH &pbvh, const float (*origco)[3], bool use_origco, Span corner_verts, + Span corner_tris, Span corner_tri_faces, Span 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 corner_verts, + Span corner_tris, Span corner_tri_faces, Span hide_poly, const float ray_start[3], @@ -576,7 +578,7 @@ blender::float4 BKE_pbvh_vertex_color_get(const PBVH &pbvh, blender::GroupedSpan vert_to_face_map, PBVHVertRef vertex); -void BKE_pbvh_ensure_node_loops(PBVH &pbvh); +void BKE_pbvh_ensure_node_loops(PBVH &pbvh, blender::Span corner_tris); int BKE_pbvh_debug_draw_gen_get(PBVHNode &node); namespace blender::bke::pbvh { diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index 7d65b614f87..b3927bde067 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -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()); } /* diff --git a/source/blender/blenkernel/intern/pbvh.cc b/source/blender/blenkernel/intern/pbvh.cc index 61a034f5045..6662a8c5fbd 100644 --- a/source/blender/blenkernel/intern/pbvh.cc +++ b/source/blender/blenkernel/intern/pbvh.cc @@ -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 build_mesh(Mesh *mesh) MutableSpan vert_positions = mesh->vert_positions_for_write(); const Span corner_verts = mesh->corner_verts(); const Span 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 corner_verts, + const Span corner_tris, const Span corner_tri_faces, const Span 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 corner_verts, + const Span corner_tris, const Span corner_tri_faces, const Span 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 corner_verts, + const Span corner_tris, const Span corner_tri_faces, const Span 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 corner_verts, + const Span corner_tris, const Span corner_tri_faces, const Span 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 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])) { diff --git a/source/blender/blenkernel/intern/pbvh_intern.hh b/source/blender/blenkernel/intern/pbvh_intern.hh index 3bbb86c0fe1..34cd233d337 100644 --- a/source/blender/blenkernel/intern/pbvh_intern.hh +++ b/source/blender/blenkernel/intern/pbvh_intern.hh @@ -154,7 +154,6 @@ struct PBVH { /** Only valid for polygon meshes. */ blender::OffsetIndices faces; blender::Span corner_verts; - blender::Span corner_tris; /* Grid Data */ CCGKey gridkey; diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc index b83e67133e9..339ee86fd59 100644 --- a/source/blender/blenkernel/intern/pbvh_pixels.cc +++ b/source/blender/blenkernel/intern/pbvh_pixels.cc @@ -669,7 +669,7 @@ static bool update_pixels(PBVH &pbvh, Mesh *mesh, Image *image, ImageUser *image const VArraySpan uv_map = *attributes.lookup(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; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.cc b/source/blender/editors/sculpt_paint/paint_vertex.cc index 2dd00776df1..14762bd79c6 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex.cc @@ -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(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"); diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 17b29aa5caa..6e685865d9d 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -3125,6 +3125,7 @@ struct SculptRaycastData { float depth; bool original; Span corner_verts; + Span corner_tris; Span corner_tri_faces; blender::VArraySpan hide_poly; @@ -3144,6 +3145,7 @@ struct SculptFindNearestToRayData { float dist_sq_to_ray; bool original; Span corner_verts; + Span corner_tris; Span corner_tri_faces; blender::VArraySpan 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(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(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(".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(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(".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(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(".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(); } diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc index 1a8503331b6..7ca5fe3e1a9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc @@ -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(ob.data); + BKE_pbvh_ensure_node_loops(pbvh, mesh.corner_tris()); } ss.filter_cache->nodes = bke::pbvh::search_gather( diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 88c466a020f..75ab7dc9f08 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -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(ob.data); + BKE_pbvh_ensure_node_loops(*ss.pbvh, mesh.corner_tris()); } if (RNA_boolean_get(op->ptr, "contiguous")) {