Refactor: Sculpt: Simplify fake neighbors API

Remove the unnecessary "enabled/disabled" toggle in the struct.
That's unnecessary because they're practically always recalculated
anyway. Also remove outdated comments and move documentation
to the header.
This commit is contained in:
Hans Goudey
2024-09-23 11:27:12 -04:00
parent 78a88ef6ad
commit 576843aa92
4 changed files with 19 additions and 47 deletions

View File

@@ -333,8 +333,6 @@ struct SculptBoundaryPreview {
};
struct SculptFakeNeighbors {
bool use_fake_neighbors;
/* Max distance used to calculate neighborhood information. */
float current_max_distance;

View File

@@ -5482,26 +5482,6 @@ void SCULPT_OT_brush_stroke(wmOperatorType *ot)
}
/* Fake Neighbors. */
/* This allows the sculpt brushes to work on meshes with multiple connected components as they had
* only one connected component. When initialized and enabled, the sculpt API will return extra
* connectivity neighbors that are not in the real mesh. These neighbors are calculated for each
* vertex using the minimum distance to a vertex that is in a different connected component. */
/* The fake neighbors first need to be ensured to be initialized.
* After that brushes which needs fake neighbors functionality need to
* temporarily enable it:
*
* void my_awesome_sculpt_brush_type() {
* SCULPT_fake_neighbors_ensure(object, brush->disconnected_distance_max);
* SCULPT_fake_neighbors_enable(ob);
*
* ... Logic of the brush type ...
* SCULPT_fake_neighbors_disable(ob);
* }
*
* Such approach allows to keep all the connectivity information ready for reuse
* (without having lag prior to every stroke), but also makes it so the affect
* is localized to a specific brushes and brush types only. */
static void fake_neighbor_init(Object &object, const float max_dist)
{
@@ -5794,7 +5774,9 @@ void ensure_boundary_info(Object &object)
} // namespace blender::ed::sculpt_paint::boundary
void SCULPT_fake_neighbors_ensure(const Depsgraph &depsgraph, Object &ob, const float max_dist)
Span<int> SCULPT_fake_neighbors_ensure(const Depsgraph &depsgraph,
Object &ob,
const float max_dist)
{
using namespace blender::ed::sculpt_paint;
SculptSession &ss = *ob.sculpt;
@@ -5804,26 +5786,14 @@ void SCULPT_fake_neighbors_ensure(const Depsgraph &depsgraph, Object &ob, const
if (!ss.fake_neighbors.fake_neighbor_index.is_empty() &&
ss.fake_neighbors.current_max_distance == max_dist)
{
return;
return ss.fake_neighbors.fake_neighbor_index;
}
islands::ensure_cache(ob);
fake_neighbor_init(ob, max_dist);
fake_neighbor_search(depsgraph, ob, max_dist * max_dist, ss.fake_neighbors.fake_neighbor_index);
}
void SCULPT_fake_neighbors_enable(Object &ob)
{
SculptSession &ss = *ob.sculpt;
BLI_assert(!ss.fake_neighbors.fake_neighbor_index.is_empty());
ss.fake_neighbors.use_fake_neighbors = true;
}
void SCULPT_fake_neighbors_disable(Object &ob)
{
SculptSession &ss = *ob.sculpt;
BLI_assert(!ss.fake_neighbors.fake_neighbor_index.is_empty());
ss.fake_neighbors.use_fake_neighbors = false;
return ss.fake_neighbors.fake_neighbor_index;
}
void SCULPT_fake_neighbors_free(Object &ob)

View File

@@ -534,9 +534,14 @@ Span<int> vert_neighbors_get_mesh(OffsetIndices<int> faces,
#define FAKE_NEIGHBOR_NONE -1
void SCULPT_fake_neighbors_ensure(const Depsgraph &depsgraph, Object &ob, float max_dist);
void SCULPT_fake_neighbors_enable(Object &ob);
void SCULPT_fake_neighbors_disable(Object &ob);
/**
* This allows the sculpt brushes to work on meshes with multiple connected components as if they
* had only one connected component. These neighbors are calculated for each vertex using the
* minimum distance to a vertex that is in a different connected component.
*/
blender::Span<int> SCULPT_fake_neighbors_ensure(const Depsgraph &depsgraph,
Object &ob,
float max_dist);
void SCULPT_fake_neighbors_free(Object &ob);
/** \} */

View File

@@ -334,8 +334,9 @@ BLI_NOINLINE static void add_fake_neighbors(const Span<int> fake_neighbors,
const MutableSpan<Vector<int>> neighbors)
{
for (const int i : verts.index_range()) {
if (fake_neighbors[verts[i]] != FAKE_NEIGHBOR_NONE) {
neighbors[i].append(fake_neighbors[verts[i]]);
const int neighbor = fake_neighbors[verts[i]];
if (neighbor != FAKE_NEIGHBOR_NONE) {
neighbors[i].append(neighbor);
}
}
}
@@ -1884,7 +1885,9 @@ static std::unique_ptr<IKChain> ik_chain_init(const Depsgraph &depsgraph,
if (use_fake_neighbors) {
SCULPT_fake_neighbors_ensure(depsgraph, ob, brush.disconnected_distance_max);
SCULPT_fake_neighbors_enable(ob);
}
else {
SCULPT_fake_neighbors_free(ob);
}
switch (brush.pose_origin_type) {
@@ -1899,10 +1902,6 @@ static std::unique_ptr<IKChain> ik_chain_init(const Depsgraph &depsgraph,
break;
}
if (use_fake_neighbors) {
SCULPT_fake_neighbors_disable(ob);
}
return ik_chain;
}