From 527e18043cf48a3fd3f1c46f24f6dd927e1231dc Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 2 Jul 2024 14:01:19 -0400 Subject: [PATCH] Refactor: Subdiv: Add utility to evaluate all limit points in a grid --- source/blender/blenkernel/BKE_subdiv_ccg.hh | 4 ++++ source/blender/blenkernel/intern/subdiv_ccg.cc | 17 +++++++++++++++++ .../brushes/multires_displacement_eraser.cc | 16 ++++------------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.hh b/source/blender/blenkernel/BKE_subdiv_ccg.hh index e53981de3e2..fab87596873 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.hh +++ b/source/blender/blenkernel/BKE_subdiv_ccg.hh @@ -258,6 +258,10 @@ inline int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG &subdiv_ccg, const void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG &subdiv_ccg, const SubdivCCGCoord &coord, float r_point[3]); +void BKE_subdiv_ccg_eval_limit_positions(const SubdivCCG &subdiv_ccg, + const CCGKey &key, + int grid_index, + blender::MutableSpan r_limit_positions); enum SubdivCCGAdjacencyType { SUBDIV_CCG_ADJACENT_NONE, diff --git a/source/blender/blenkernel/intern/subdiv_ccg.cc b/source/blender/blenkernel/intern/subdiv_ccg.cc index f3450533a92..799263cd532 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.cc +++ b/source/blender/blenkernel/intern/subdiv_ccg.cc @@ -1709,4 +1709,21 @@ void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG &subdiv_ccg, eval_limit_point(subdiv, ptex_face_index, u, v, r_point); } +void BKE_subdiv_ccg_eval_limit_positions(const SubdivCCG &subdiv_ccg, + const CCGKey &key, + const int grid_index, + const MutableSpan r_limit_positions) +{ + SubdivCCGCoord coord{}; + coord.grid_index = grid_index; + for (const int y : IndexRange(key.grid_size)) { + for (const int x : IndexRange(key.grid_size)) { + const int i = CCG_grid_xy_to_index(key.grid_size, x, y); + coord.x = x; + coord.y = y; + BKE_subdiv_ccg_eval_limit_point(subdiv_ccg, coord, r_limit_positions[i]); + } + } +} + /** \} */ diff --git a/source/blender/editors/sculpt_paint/brushes/multires_displacement_eraser.cc b/source/blender/editors/sculpt_paint/brushes/multires_displacement_eraser.cc index f2c190cdf15..15b5995cc99 100644 --- a/source/blender/editors/sculpt_paint/brushes/multires_displacement_eraser.cc +++ b/source/blender/editors/sculpt_paint/brushes/multires_displacement_eraser.cc @@ -38,18 +38,10 @@ static BLI_NOINLINE void calc_limit_positions(const SubdivCCG &subdiv_ccg, const MutableSpan limit_positions) { const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg); - for (const int grid : grids) { - const int start = grid * key.grid_area; - for (const int y : IndexRange(key.grid_size)) { - for (const int x : IndexRange(key.grid_size)) { - const int offset = CCG_grid_xy_to_index(key.grid_size, x, y); - SubdivCCGCoord coord{}; - coord.grid_index = grid; - coord.x = x; - coord.y = y; - BKE_subdiv_ccg_eval_limit_point(subdiv_ccg, coord, limit_positions[start + offset]); - } - } + for (const int i : grids.index_range()) { + const int start = i * key.grid_area; + BKE_subdiv_ccg_eval_limit_positions( + subdiv_ccg, key, grids[i], limit_positions.slice(start, key.grid_area)); } }