Sculpt: Refactor displacement eraser filter initialization

Part of #118145.
Parallelize the creation of the initial limit positions for the filter,
also using the API function to evaluate more than one vertex at a time,
and removing the old sculpt API function as well.
This commit is contained in:
Hans Goudey
2024-08-03 22:35:39 -04:00
parent f06d6185fc
commit cdd72e689f
3 changed files with 12 additions and 31 deletions

View File

@@ -224,23 +224,6 @@ const float *SCULPT_vertex_co_for_grab_active_get(const SculptSession &ss, PBVHV
return SCULPT_vertex_co_get(ss, vertex);
}
float3 SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex)
{
switch (ss.pbvh->type()) {
case blender::bke::pbvh::Type::Mesh:
case blender::bke::pbvh::Type::BMesh:
return SCULPT_vertex_co_get(ss, vertex);
case blender::bke::pbvh::Type::Grids: {
const CCGKey key = BKE_subdiv_ccg_key_top_level(*ss.subdiv_ccg);
SubdivCCGCoord coord = SubdivCCGCoord::from_index(key, vertex.i);
float3 tmp;
BKE_subdiv_ccg_eval_limit_point(*ss.subdiv_ccg, coord, tmp);
return tmp;
}
}
BLI_assert_unreachable();
return {};
}
PBVHVertRef SCULPT_active_vertex_get(const SculptSession &ss)
{

View File

@@ -503,15 +503,19 @@ static void mesh_filter_surface_smooth_init(SculptSession &ss,
static void mesh_filter_init_limit_surface_co(SculptSession &ss)
{
const int totvert = SCULPT_vertex_count_get(ss);
filter::Cache *filter_cache = ss.filter_cache;
const SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
const Span<CCGElem *> elems = subdiv_ccg.grids;
filter_cache->limit_surface_co = Array<float3>(totvert);
for (int i = 0; i < totvert; i++) {
PBVHVertRef vertex = BKE_pbvh_index_to_vertex(*ss.pbvh, i);
filter_cache->limit_surface_co[i] = SCULPT_vertex_limit_surface_get(ss, vertex);
}
ss.filter_cache->limit_surface_co = Array<float3>(elems.size() * key.grid_area);
MutableSpan<float3> limit_positions = ss.filter_cache->limit_surface_co;
threading::parallel_for(elems.index_range(), 512, [&](const IndexRange range) {
for (const int grid : range) {
const int start = grid * key.grid_area;
BKE_subdiv_ccg_eval_limit_positions(
subdiv_ccg, key, grid, limit_positions.slice(start, key.grid_area));
}
});
}
static void mesh_filter_sharpen_init(const Object &object,

View File

@@ -826,12 +826,6 @@ bool SCULPT_vertex_is_occluded(SculptSession &ss, PBVHVertRef vertex, bool origi
*/
const float *SCULPT_vertex_co_for_grab_active_get(const SculptSession &ss, PBVHVertRef vertex);
/**
* Returns the info of the limit surface when multi-res is available,
* otherwise it returns the current coordinate of the vertex.
*/
blender::float3 SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vertex);
/**
* Returns the pointer to the coordinates that should be edited from a brush tool iterator
* depending on the given deformation target.