Cleanup: Rename Sculpt BMesh helper method and use it consistently

Pull Request: https://projects.blender.org/blender/blender/pulls/139122
This commit is contained in:
Sean Kim
2025-05-20 21:44:03 +02:00
committed by Sean Kim
parent 44e36ef581
commit 7ada8e28d7
21 changed files with 42 additions and 45 deletions

View File

@@ -309,8 +309,7 @@ void calc_smooth_translations(const Depsgraph &depsgraph,
break;
}
case bke::pbvh::Type::BMesh:
BM_mesh_elem_index_ensure(ss.bm, BM_VERT);
BM_mesh_elem_table_ensure(ss.bm, BM_VERT);
vert_random_access_ensure(const_cast<Object &>(object));
const Span<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
node_mask.foreach_index(GrainSize(1), [&](const int i) {
brushes::LocalData &tls = all_tls.local();

View File

@@ -262,8 +262,7 @@ void do_smooth_brush(const Depsgraph &depsgraph,
break;
}
case bke::pbvh::Type::BMesh: {
BM_mesh_elem_index_ensure(ss.bm, BM_VERT);
BM_mesh_elem_table_ensure(ss.bm, BM_VERT);
vert_random_access_ensure(object);
threading::EnumerableThreadSpecific<LocalData> all_tls;
for (const float strength : iteration_strengths(brush_strength)) {
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();

View File

@@ -308,8 +308,7 @@ void do_smooth_mask_brush(const Depsgraph &depsgraph,
}
case bke::pbvh::Type::BMesh: {
threading::EnumerableThreadSpecific<LocalData> all_tls;
BM_mesh_elem_index_ensure(ss.bm, BM_VERT);
BM_mesh_elem_table_ensure(ss.bm, BM_VERT);
vert_random_access_ensure(object);
const int mask_offset = CustomData_get_offset_named(
&ss.bm->vdata, CD_PROP_FLOAT, ".sculpt_mask");
for (const float strength : iteration_strengths(brush_strength)) {

View File

@@ -405,7 +405,7 @@ void do_surface_smooth_brush(const Depsgraph &depsgraph,
break;
}
case bke::pbvh::Type::BMesh: {
BM_mesh_elem_index_ensure(ss.bm, BM_VERT);
vert_random_access_ensure(object);
do_surface_smooth_brush_bmesh(
depsgraph, sd, brush, node_mask, object, ss.cache->surface_smooth_laplacian_disp);
break;

View File

@@ -1802,7 +1802,7 @@ static void paint_cursor_draw_3d_view_brush_cursor_inactive(PaintCursorContext &
Object &active_object = *pcontext.vc.obact;
paint_cursor_update_object_space_radius(pcontext);
SCULPT_vertex_random_access_ensure(active_object);
vert_random_access_ensure(active_object);
/* Setup drawing. */
wmViewport(&pcontext.region->winrct);

View File

@@ -1085,7 +1085,7 @@ static Array<bool> duplicate_visibility_bmesh(const Object &object)
const SculptSession &ss = *object.sculpt;
BMesh &bm = *ss.bm;
Array<bool> result(bm.totvert);
BM_mesh_elem_table_ensure(&bm, BM_VERT);
vert_random_access_ensure(const_cast<Object &>(object));
for (const int i : result.index_range()) {
result[i] = BM_elem_flag_test_bool(BM_vert_at_index(&bm, i), BM_ELEM_HIDDEN);
}

View File

@@ -82,7 +82,7 @@ Array<float> duplicate_mask(const Object &object)
result.fill(0.0f);
}
else {
BM_mesh_elem_table_ensure(&bm, BM_VERT);
vert_random_access_ensure(const_cast<Object &>(object));
for (const int i : result.index_range()) {
result[i] = BM_ELEM_CD_GET_FLOAT(BM_vert_at_index(&bm, i), offset);
}

View File

@@ -139,16 +139,15 @@ bool report_if_shape_key_is_locked(const Object &ob, ReportList *reports)
return false;
}
} // namespace blender::ed::sculpt_paint
void SCULPT_vertex_random_access_ensure(Object &object)
void vert_random_access_ensure(Object &object)
{
SculptSession &ss = *object.sculpt;
if (blender::bke::object::pbvh_get(object)->type() == blender::bke::pbvh::Type::BMesh) {
if (bke::object::pbvh_get(object)->type() == bke::pbvh::Type::BMesh) {
BM_mesh_elem_index_ensure(ss.bm, BM_VERT);
BM_mesh_elem_table_ensure(ss.bm, BM_VERT);
}
}
} // namespace blender::ed::sculpt_paint
int SCULPT_vertex_count_get(const Object &object)
{
@@ -4696,7 +4695,7 @@ bool cursor_geometry_info_update(bContext *C,
else if (pbvh->type() == bke::pbvh::Type::Grids) {
srd.subdiv_ccg = ss.subdiv_ccg;
}
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
srd.ray_start = ray_start;
srd.ray_normal = ray_normal;
srd.depth = depth;
@@ -4836,7 +4835,7 @@ static bool stroke_get_location_bvh_ex(bContext *C,
else if (pbvh.type() == bke::pbvh::Type::Grids) {
rd.subdiv_ccg = ss.subdiv_ccg;
}
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
rd.depth = depth;
rd.use_original = original;
isect_ray_tri_watertight_v3_precalc(&rd.isect_precalc, ray_normal);
@@ -6134,7 +6133,7 @@ bool vertex_is_occluded(const Depsgraph &depsgraph,
else if (pbvh.type() == bke::pbvh::Type::Grids) {
srd.subdiv_ccg = ss.subdiv_ccg;
}
SCULPT_vertex_random_access_ensure(const_cast<Object &>(object));
vert_random_access_ensure(const_cast<Object &>(object));
isect_ray_tri_watertight_v3_precalc(&srd.isect_precalc, ray_normal);
bke::pbvh::raycast(
@@ -6247,7 +6246,7 @@ static SculptTopologyIslandCache calc_topology_islands_bmesh(const Object &objec
const bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(object);
const Span<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
BMesh &bm = *ss.bm;
BM_mesh_elem_index_ensure(&bm, BM_VERT);
vert_random_access_ensure(const_cast<Object &>(object));
IndexMaskMemory memory;
const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);

View File

@@ -1641,7 +1641,7 @@ std::unique_ptr<Cache> cache_init(const Depsgraph &depsgraph,
int mode = calc_effective_bits(sd, brush);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
if (mode & BRUSH_AUTOMASKING_TOPOLOGY && ss.active_vert_index() != -1) {
islands::ensure_cache(ob);
automasking->settings.initial_island_nr = islands::vert_id_get(ss, ss.active_vert_index());
@@ -1679,24 +1679,24 @@ std::unique_ptr<Cache> cache_init(const Depsgraph &depsgraph,
/* Additive modes. */
if (mode_enabled(sd, brush, BRUSH_AUTOMASKING_TOPOLOGY)) {
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
automasking->settings.topology_use_brush_limit = is_constrained_by_radius(brush);
fill_topology_automasking_factors(depsgraph, sd, ob, factors);
}
if (mode_enabled(sd, brush, BRUSH_AUTOMASKING_FACE_SETS)) {
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
init_face_sets_masking(sd, ob, factors);
}
const int steps = boundary_propagation_steps(sd, brush);
if (mode_enabled(sd, brush, BRUSH_AUTOMASKING_BOUNDARY_EDGES)) {
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
init_boundary_masking(ob, depsgraph, BoundaryAutomaskMode::Edges, steps, factors);
}
if (mode_enabled(sd, brush, BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS)) {
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
init_boundary_masking(ob, depsgraph, BoundaryAutomaskMode::FaceSets, steps, factors);
}

View File

@@ -3500,7 +3500,7 @@ std::unique_ptr<SculptBoundary> data_init_bmesh(Object &object,
{
SculptSession &ss = *object.sculpt;
SCULPT_vertex_random_access_ensure(object);
vert_random_access_ensure(object);
boundary::ensure_boundary_info(object);
const std::optional<BMVert *> boundary_initial_vert = get_closest_boundary_vert_bmesh(

View File

@@ -611,8 +611,7 @@ void ensure_nodes_constraints(const Sculpt &sd,
return cloth_sim.node_state[node_index] == SCULPT_CLOTH_NODE_UNINITIALIZED;
});
BMesh &bm = *ss.bm;
BM_mesh_elem_index_ensure(&bm, BM_VERT);
BM_mesh_elem_table_ensure(&bm, BM_VERT);
vert_random_access_ensure(object);
uninitialized_nodes.foreach_index([&](const int i) {
const Set<BMVert *, 0> &bm_verts = BKE_pbvh_bmesh_node_unique_verts(&nodes[i]);
const Span<int> verts = calc_visible_vert_indices_bmesh(bm_verts, vert_indices);
@@ -2299,7 +2298,7 @@ static wmOperatorStatus sculpt_cloth_filter_modal(bContext *C,
const float len = event->prev_press_xy[0] - event->xy[0];
filter_strength = filter_strength * -len * 0.001f * UI_SCALE_FAC;
SCULPT_vertex_random_access_ensure(object);
vert_random_access_ensure(object);
BKE_sculpt_update_object_for_edit(depsgraph, &object, false);

View File

@@ -888,7 +888,7 @@ static wmOperatorStatus dyntopo_detail_size_edit_invoke(bContext *C,
rotate_v2_v2fl(cd->preview_tri[i], y_axis, DEG2RAD(120.0f * i));
}
SCULPT_vertex_random_access_ensure(active_object);
vert_random_access_ensure(active_object);
WM_event_add_modal_handler(C, op);
ED_region_tag_redraw(region);

View File

@@ -1559,7 +1559,7 @@ static void write_mask_data(Object &object, const Span<float> mask)
case bke::pbvh::Type::BMesh: {
BMesh &bm = *ss.bm;
const int offset = CustomData_get_offset_named(&bm.vdata, CD_PROP_FLOAT, ".sculpt_mask");
BM_mesh_elem_table_ensure(&bm, BM_VERT);
vert_random_access_ensure(object);
for (const int i : mask.index_range()) {
BM_ELEM_CD_SET_FLOAT(BM_vert_at_index(&bm, i), offset, mask[i]);
}
@@ -2253,7 +2253,7 @@ static void ensure_sculptsession_data(Object &ob)
{
SculptSession &ss = *ob.sculpt;
islands::ensure_cache(ob);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
boundary::ensure_boundary_info(ob);
if (!ss.tex_pool) {
ss.tex_pool = BKE_image_pool_new();
@@ -2778,7 +2778,7 @@ static wmOperatorStatus sculpt_expand_invoke(bContext *C, wmOperator *op, const
}
case bke::pbvh::Type::BMesh: {
BMesh &bm = *ob.sculpt->bm;
BM_mesh_elem_table_ensure(&bm, BM_VERT);
vert_random_access_ensure(ob);
if (boundary::vert_is_boundary(BM_vert_at_index(&bm, initial_vert))) {
falloff_type = FalloffType::BoundaryTopology;
}

View File

@@ -1103,7 +1103,7 @@ static wmOperatorStatus change_visibility_invoke(bContext *C, wmOperator *op, co
* cursor updates. */
CursorGeometryInfo cgi;
const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
cursor_geometry_info_update(C, &cgi, mval_fl, false);
return change_visibility_exec(C, op);

View File

@@ -917,7 +917,7 @@ static wmOperatorStatus sculpt_mask_filter_exec(bContext *C, wmOperator *op)
case bke::pbvh::Type::BMesh: {
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
BMesh &bm = *ss.bm;
BM_mesh_elem_index_ensure(&bm, BM_VERT);
vert_random_access_ensure(ob);
const int mask_offset = CustomData_get_offset_named(
&bm.vdata, CD_PROP_FLOAT, ".sculpt_mask");

View File

@@ -1713,7 +1713,7 @@ static void calc_sharpen_filter(const Depsgraph &depsgraph,
}
case bke::pbvh::Type::BMesh: {
BMesh &bm = *ss.bm;
BM_mesh_elem_index_ensure(&bm, BM_VERT);
vert_random_access_ensure(object);
threading::EnumerableThreadSpecific<LocalData> all_tls;
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
node_mask.foreach_index(GrainSize(1), [&](const int node_index) {
@@ -2122,7 +2122,7 @@ static void sculpt_mesh_filter_apply(bContext *C, wmOperator *op, bool is_replay
const MeshFilterType filter_type = MeshFilterType(RNA_enum_get(op->ptr, "type"));
const float strength = RNA_float_get(op->ptr, "strength");
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
const IndexMask &node_mask = ss.filter_cache->node_mask;
if (auto_mask::is_enabled(sd, ob, nullptr) && ss.filter_cache->automasking &&
@@ -2422,7 +2422,7 @@ static wmOperatorStatus sculpt_mesh_filter_start(bContext *C, wmOperator *op)
cursor_geometry_info_update(C, &cgi, mval_fl, false);
}
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
if (needs_topology_info) {
boundary::ensure_boundary_info(ob);
}

View File

@@ -547,8 +547,10 @@ void sculpt_project_v3_normal_align(const SculptSession &ss,
/** \name Sculpt mesh accessor API
* \{ */
namespace blender::ed::sculpt_paint {
/** Ensure random access; required for blender::bke::pbvh::Type::BMesh */
void SCULPT_vertex_random_access_ensure(Object &object);
void vert_random_access_ensure(Object &object);
} // namespace blender::ed::sculpt_paint
int SCULPT_vertex_count_get(const Object &object);

View File

@@ -1195,7 +1195,7 @@ static wmOperatorStatus mask_from_cavity_exec(bContext *C, wmOperator *op)
BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), &ob, mmd);
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
const ApplyMaskMode mode = ApplyMaskMode(RNA_enum_get(op->ptr, "mix_mode"));
const float factor = RNA_float_get(op->ptr, "mix_factor");
@@ -1389,7 +1389,7 @@ static wmOperatorStatus mask_from_boundary_exec(bContext *C, wmOperator *op)
BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), &ob, mmd);
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
const ApplyMaskMode mode = ApplyMaskMode(RNA_enum_get(op->ptr, "mix_mode"));
const float factor = RNA_float_get(op->ptr, "mix_factor");

View File

@@ -780,7 +780,7 @@ static void calc_pose_origin_and_factor_bmesh(Object &object,
MutableSpan<float> r_pose_factor)
{
BLI_assert(!r_pose_factor.is_empty());
SCULPT_vertex_random_access_ensure(object);
vert_random_access_ensure(object);
/* Calculate the pose rotation point based on the boundaries of the brush factor. */
flood_fill::FillDataBMesh flood(BM_mesh_elem_count(ss.bm, BM_VERT),
@@ -1568,7 +1568,7 @@ static std::optional<float3> calc_average_face_set_center(const Depsgraph &depsg
break;
}
case bke::pbvh::Type::BMesh: {
SCULPT_vertex_random_access_ensure(object);
vert_random_access_ensure(object);
BMesh &bm = *object.sculpt->bm;
const int face_set_offset = CustomData_get_offset_named(
&bm.pdata, CD_PROP_INT32, ".sculpt_face_set");
@@ -1781,7 +1781,7 @@ static std::unique_ptr<IKChain> ik_chain_init_face_sets_fk_bmesh(const Depsgraph
const float radius,
const float3 &initial_location)
{
SCULPT_vertex_random_access_ensure(object);
vert_random_access_ensure(object);
BMesh &bm = *ss.bm;
const int face_set_offset = CustomData_get_offset_named(

View File

@@ -72,7 +72,7 @@ void init_transform(bContext *C, Object &ob, const float mval_fl[2], const char
ss.pivot_rot[3] = 1.0f;
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
filter::cache_init(C, ob, sd, undo::Type::Position, mval_fl, 5.0, 1.0f);
@@ -541,7 +541,7 @@ void update_modal_transform(bContext *C, Object &ob)
SculptSession &ss = *ob.sculpt;
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
BKE_sculpt_update_object_for_edit(depsgraph, &ob, false);
switch (sd.transform_mode) {

View File

@@ -753,7 +753,7 @@ static void initialize_cursor_info(bContext &C,
{
Object &ob = *CTX_data_active_object(&C);
SCULPT_vertex_random_access_ensure(ob);
vert_random_access_ensure(ob);
int mval[2];
RNA_int_get_array(op.ptr, "location", mval);