Cleanup: Sculpt: Move topology islands API to C++ namespace

This commit is contained in:
Hans Goudey
2024-08-04 14:04:58 -04:00
parent a57c3be05e
commit c0d37d97de
9 changed files with 40 additions and 40 deletions

View File

@@ -79,7 +79,7 @@ void sync_all_from_faces(Object &object)
SculptSession &ss = *object.sculpt;
Mesh &mesh = *static_cast<Mesh *>(object.data);
SCULPT_topology_islands_invalidate(ss);
islands::invalidate(ss);
switch (ss.pbvh->type()) {
case bke::pbvh::Type::Mesh: {
@@ -536,7 +536,7 @@ static int hide_show_all_exec(bContext *C, wmOperator *op)
/* End undo. */
undo::push_end(ob);
SCULPT_topology_islands_invalidate(*ob.sculpt);
islands::invalidate(*ob.sculpt);
tag_update_visibility(*C);
return OPERATOR_FINISHED;
@@ -652,7 +652,7 @@ static int hide_show_masked_exec(bContext *C, wmOperator *op)
/* End undo. */
undo::push_end(ob);
SCULPT_topology_islands_invalidate(*ob.sculpt);
islands::invalidate(*ob.sculpt);
tag_update_visibility(*C);
return OPERATOR_FINISHED;
@@ -802,7 +802,7 @@ static int visibility_invert_exec(bContext *C, wmOperator *op)
undo::push_end(object);
SCULPT_topology_islands_invalidate(*object.sculpt);
islands::invalidate(*object.sculpt);
tag_update_visibility(*C);
return OPERATOR_FINISHED;
@@ -1148,7 +1148,7 @@ static int visibility_filter_exec(bContext *C, wmOperator *op)
}
undo::push_end(object);
SCULPT_topology_islands_invalidate(*object.sculpt);
islands::invalidate(*object.sculpt);
tag_update_visibility(*C);
return OPERATOR_FINISHED;
@@ -1305,7 +1305,7 @@ static void hide_show_apply_for_symmetry_pass(bContext &C, gesture::GestureData
}
static void hide_show_end(bContext &C, gesture::GestureData &gesture_data)
{
SCULPT_topology_islands_invalidate(*gesture_data.vc.obact->sculpt);
islands::invalidate(*gesture_data.vc.obact->sculpt);
tag_update_visibility(C);
undo::push_end(*gesture_data.vc.obact);
}

View File

@@ -6259,7 +6259,7 @@ static void do_fake_neighbor_search_task(SculptSession &ss,
{
PBVHVertexIter vd;
BKE_pbvh_vertex_iter_begin (*ss.pbvh, node, vd, PBVH_ITER_UNIQUE) {
int vd_topology_id = SCULPT_vertex_island_get(ss, vd.vertex);
int vd_topology_id = islands::vert_id_get(ss, vd.vertex);
if (vd_topology_id != nvtd->current_topology_id &&
ss.fake_neighbors.fake_neighbor_index[vd.index] == FAKE_NEIGHBOR_NONE)
{
@@ -6294,7 +6294,7 @@ static PBVHVertRef fake_neighbor_search(Object &ob, const PBVHVertRef vertex, fl
NearestVertexFakeNeighborData nvtd;
nvtd.nearest_vertex.i = -1;
nvtd.nearest_vertex_distance_sq = FLT_MAX;
nvtd.current_topology_id = SCULPT_vertex_island_get(ss, vertex);
nvtd.current_topology_id = islands::vert_id_get(ss, vertex);
nvtd = threading::parallel_reduce(
nodes.index_range(),
@@ -6370,7 +6370,7 @@ void SCULPT_fake_neighbors_ensure(Object &ob, const float max_dist)
return;
}
SCULPT_topology_islands_ensure(ob);
islands::ensure_cache(ob);
fake_neighbor_init(ss, max_dist);
for (int i = 0; i < totvert; i++) {
@@ -6477,7 +6477,9 @@ void SCULPT_stroke_id_ensure(Object &ob)
}
}
int SCULPT_vertex_island_get(const SculptSession &ss, PBVHVertRef vertex)
namespace blender::ed::sculpt_paint::islands {
int vert_id_get(const SculptSession &ss, PBVHVertRef vertex)
{
if (ss.attrs.topology_island_key) {
return *static_cast<uint8_t *>(SCULPT_vertex_attr_get(vertex, ss.attrs.topology_island_key));
@@ -6486,15 +6488,13 @@ int SCULPT_vertex_island_get(const SculptSession &ss, PBVHVertRef vertex)
return -1;
}
void SCULPT_topology_islands_invalidate(SculptSession &ss)
void invalidate(SculptSession &ss)
{
ss.islands_valid = false;
}
void SCULPT_topology_islands_ensure(Object &ob)
void ensure_cache(Object &ob)
{
using namespace blender;
using namespace blender::ed::sculpt_paint;
SculptSession &ss = *ob.sculpt;
if (ss.attrs.topology_island_key && ss.islands_valid &&
@@ -6551,6 +6551,8 @@ void SCULPT_topology_islands_ensure(Object &ob)
ss.islands_valid = true;
}
} // namespace blender::ed::sculpt_paint::islands
void SCULPT_cube_tip_init(const Sculpt & /*sd*/,
const Object &ob,
const Brush &brush,

View File

@@ -550,7 +550,7 @@ float factor_get(const Cache *automasking,
if (!automasking->settings.topology_use_brush_limit &&
automasking->settings.flags & BRUSH_AUTOMASKING_TOPOLOGY &&
SCULPT_vertex_island_get(ss, vert) != automasking->settings.initial_island_nr)
islands::vert_id_get(ss, vert) != automasking->settings.initial_island_nr)
{
return 0.0f;
}
@@ -956,8 +956,8 @@ std::unique_ptr<Cache> cache_init(const Sculpt &sd, const Brush *brush, Object &
int mode = calc_effective_bits(sd, brush);
if (mode & BRUSH_AUTOMASKING_TOPOLOGY && ss.active_vertex.i != PBVH_REF_NONE) {
SCULPT_topology_islands_ensure(ob);
automasking->settings.initial_island_nr = SCULPT_vertex_island_get(ss, ss.active_vertex);
islands::ensure_cache(ob);
automasking->settings.initial_island_nr = islands::vert_id_get(ss, ss.active_vertex);
}
bool use_stroke_id = false;

View File

@@ -132,7 +132,7 @@ static bool is_vert_in_active_component(const SculptSession &ss,
const PBVHVertRef v)
{
for (int i = 0; i < EXPAND_SYMM_AREAS; i++) {
if (SCULPT_vertex_island_get(ss, v) == expand_cache->active_connected_islands[i]) {
if (islands::vert_id_get(ss, v) == expand_cache->active_connected_islands[i]) {
return true;
}
}
@@ -422,7 +422,7 @@ static void check_topology_islands(Object &ob, FalloffType falloff_type)
FalloffType::Normals);
if (ss.expand_cache->check_islands) {
SCULPT_topology_islands_ensure(ob);
islands::ensure_cache(ob);
}
}
@@ -1765,8 +1765,7 @@ static void find_active_connected_components_from_vert(Object &ob,
const PBVHVertRef symm_vertex = get_vert_index_for_symmetry_pass(ob, symm_it, initial_vertex);
expand_cache->active_connected_islands[int(symm_it)] = SCULPT_vertex_island_get(ss,
symm_vertex);
expand_cache->active_connected_islands[int(symm_it)] = islands::vert_id_get(ss, symm_vertex);
}
}
@@ -1842,7 +1841,7 @@ static void move_propagation_origin(bContext *C,
static void ensure_sculptsession_data(Object &ob)
{
SculptSession &ss = *ob.sculpt;
SCULPT_topology_islands_ensure(ob);
islands::ensure_cache(ob);
SCULPT_vertex_random_access_ensure(ss);
boundary::ensure_boundary_info(ob);
if (!ss.tex_pool) {

View File

@@ -900,7 +900,7 @@ static int change_visibility_exec(bContext *C, wmOperator *op)
bke::pbvh::update_visibility(*ss.pbvh);
BKE_sculpt_hide_poly_pointer_update(object);
SCULPT_topology_islands_invalidate(*object.sculpt);
islands::invalidate(*object.sculpt);
hide::tag_update_visibility(*C);
return OPERATOR_FINISHED;

View File

@@ -2222,17 +2222,18 @@ void ensure_valid_pivot(const Object &ob, Scene &scene);
* Uses the `ss->topology_island_key` attribute.
*/
/* Ensures vertex island keys exist and are valid. */
void SCULPT_topology_islands_ensure(Object &ob);
namespace blender::ed::sculpt_paint::islands {
/**
* Mark vertex island keys as invalid.
* Call when adding or hiding geometry.
*/
void SCULPT_topology_islands_invalidate(SculptSession &ss);
/* Ensure vertex island keys exist and are valid. */
void ensure_cache(Object &object);
/** Mark vertex island keys as invalid. Call when adding or hiding geometry. */
void invalidate(SculptSession &ss);
/** Get vertex island key. */
int SCULPT_vertex_island_get(const SculptSession &ss, PBVHVertRef vertex);
int vert_id_get(const SculptSession &ss, PBVHVertRef vert);
}
/** \} */

View File

@@ -145,10 +145,10 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
});
break;
case InitMode::Island:
SCULPT_topology_islands_ensure(ob);
islands::ensure_cache(ob);
write_mask_mesh(ob, nodes, [&](MutableSpan<float> mask, Span<int> verts) {
for (const int vert : verts) {
const int island = SCULPT_vertex_island_get(ss, PBVHVertRef{vert});
const int island = islands::vert_id_get(ss, PBVHVertRef{vert});
mask[vert] = BLI_hash_int_01(island + seed);
}
});
@@ -201,7 +201,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
break;
}
case InitMode::Island: {
SCULPT_topology_islands_ensure(ob);
islands::ensure_cache(ob);
init_mask_grids(
bmain,
scene,
@@ -212,8 +212,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
const int verts_start = grid_index * key.grid_area;
BKE_subdiv_ccg_foreach_visible_grid_vert(
key, grid_hidden, grid_index, [&](const int i) {
const int island = SCULPT_vertex_island_get(ss,
PBVHVertRef{verts_start + i});
const int island = islands::vert_id_get(ss, PBVHVertRef{verts_start + i});
CCG_elem_offset_mask(key, grid, i) = BLI_hash_int_01(island + seed);
});
});
@@ -243,8 +242,7 @@ static int sculpt_mask_init_exec(bContext *C, wmOperator *op)
BM_ELEM_CD_SET_FLOAT(
vert,
offset,
BLI_hash_int_01(SCULPT_vertex_island_get(ss, PBVHVertRef{intptr_t(vert)}) +
seed));
BLI_hash_int_01(islands::vert_id_get(ss, PBVHVertRef{intptr_t(vert)}) + seed));
break;
}
}

View File

@@ -244,7 +244,7 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
SCULPT_topology_islands_invalidate(ss);
islands::invalidate(ss);
/* Redraw. */
SCULPT_pbvh_clear(ob);

View File

@@ -518,7 +518,7 @@ static void gesture_begin(bContext &C, wmOperator &op, gesture::GestureData &ges
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(&C);
generate_geometry(gesture_data);
SCULPT_topology_islands_invalidate(ss);
islands::invalidate(ss);
BKE_sculpt_update_object_for_edit(depsgraph, gesture_data.vc.obact, false);
undo::geometry_begin(*gesture_data.vc.obact, &op);
}