Refactor: Sculpt: Add face set offset parameter for BMesh functions
Part of #118145. Even though BMesh face set functionality does not currently work, there are some reasonable assumptions we can make about the needed parameters for some APIs. This commit changes the signature for relevant unique face set functions so that future changes are easier when / if face sets are fully supported within BMesh. Pull Request: https://projects.blender.org/blender/blender/pulls/127640
This commit is contained in:
@@ -347,6 +347,7 @@ static void do_relax_face_sets_brush_grids(const Depsgraph &depsgraph,
|
||||
static void calc_factors_bmesh(const Depsgraph &depsgraph,
|
||||
Object &object,
|
||||
const Brush &brush,
|
||||
const int face_set_offset,
|
||||
bke::pbvh::BMeshNode &node,
|
||||
const float strength,
|
||||
const bool relax_face_sets,
|
||||
@@ -379,7 +380,8 @@ static void calc_factors_bmesh(const Depsgraph &depsgraph,
|
||||
scale_factors(factors, strength);
|
||||
|
||||
calc_brush_texture_factors(ss, brush, positions, factors);
|
||||
face_set::filter_verts_with_unique_face_sets_bmesh(relax_face_sets, verts, factors);
|
||||
face_set::filter_verts_with_unique_face_sets_bmesh(
|
||||
face_set_offset, relax_face_sets, verts, factors);
|
||||
}
|
||||
|
||||
static void do_relax_face_sets_brush_bmesh(const Depsgraph &depsgraph,
|
||||
@@ -396,6 +398,9 @@ static void do_relax_face_sets_brush_bmesh(const Depsgraph &depsgraph,
|
||||
const OffsetIndices<int> node_vert_offsets = create_node_vert_offsets_bmesh(
|
||||
nodes, node_mask, node_offset_data);
|
||||
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&object.sculpt->bm->pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
|
||||
Array<float3> current_positions(node_vert_offsets.total_size());
|
||||
Array<float3> translations(node_vert_offsets.total_size());
|
||||
Array<float> factors(node_vert_offsets.total_size());
|
||||
@@ -406,6 +411,7 @@ static void do_relax_face_sets_brush_bmesh(const Depsgraph &depsgraph,
|
||||
calc_factors_bmesh(depsgraph,
|
||||
object,
|
||||
brush,
|
||||
face_set_offset,
|
||||
nodes[i],
|
||||
strength,
|
||||
relax_face_sets,
|
||||
@@ -419,6 +425,7 @@ static void do_relax_face_sets_brush_bmesh(const Depsgraph &depsgraph,
|
||||
smooth::calc_relaxed_translations_bmesh(
|
||||
BKE_pbvh_bmesh_node_unique_verts(&nodes[i]),
|
||||
current_positions.as_mutable_span().slice(node_vert_offsets[pos]),
|
||||
face_set_offset,
|
||||
relax_face_sets,
|
||||
factors.as_span().slice(node_vert_offsets[pos]),
|
||||
tls.vert_neighbors,
|
||||
@@ -710,6 +717,8 @@ static void do_topology_relax_brush_bmesh(const Depsgraph &depsgraph,
|
||||
{
|
||||
bke::pbvh::Tree &pbvh = *bke::object::pbvh_get(object);
|
||||
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&object.sculpt->bm->pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
|
||||
Array<int> node_offset_data;
|
||||
const OffsetIndices<int> node_vert_offsets = create_node_vert_offsets_bmesh(
|
||||
@@ -738,6 +747,7 @@ static void do_topology_relax_brush_bmesh(const Depsgraph &depsgraph,
|
||||
smooth::calc_relaxed_translations_bmesh(
|
||||
BKE_pbvh_bmesh_node_unique_verts(&nodes[i]),
|
||||
current_positions.as_mutable_span().slice(node_vert_offsets[pos]),
|
||||
face_set_offset,
|
||||
false,
|
||||
factors.as_span().slice(node_vert_offsets[pos]),
|
||||
tls.vert_neighbors,
|
||||
|
||||
@@ -408,8 +408,10 @@ bool vert_has_unique_face_set(const Object &object, PBVHVertRef vertex)
|
||||
return vert_has_unique_face_set(vert_to_face_map, face_sets, vertex.i);
|
||||
}
|
||||
case bke::pbvh::Type::BMesh: {
|
||||
BMVert *v = (BMVert *)vertex.i;
|
||||
return vert_has_unique_face_set(v);
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&object.sculpt->bm->pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
BMVert *v = reinterpret_cast<BMVert *>(vertex.i);
|
||||
return vert_has_unique_face_set(face_set_offset, *v);
|
||||
}
|
||||
case bke::pbvh::Type::Grids: {
|
||||
const Mesh &base_mesh = *static_cast<const Mesh *>(object.data);
|
||||
@@ -514,7 +516,7 @@ bool vert_has_unique_face_set(const GroupedSpan<int> vert_to_face_map,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vert_has_unique_face_set(const BMVert * /*vert*/)
|
||||
bool vert_has_unique_face_set(const int /*face_set_offset*/, const BMVert & /*vert*/)
|
||||
{
|
||||
/* TODO: Obviously not fully implemented yet. Needs to be implemented for Relax Face Sets brush
|
||||
* to work. */
|
||||
|
||||
@@ -1227,13 +1227,15 @@ static void init_boundary_masking_bmesh(Object &object,
|
||||
MutableSpan<float> factors)
|
||||
{
|
||||
SculptSession &ss = *object.sculpt;
|
||||
BMesh *bm = ss.bm;
|
||||
const int num_verts = BM_mesh_elem_count(bm, BM_VERT);
|
||||
BMesh &bm = *ss.bm;
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&bm.pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
const int num_verts = BM_mesh_elem_count(&bm, BM_VERT);
|
||||
|
||||
Array<int> edge_distance(num_verts, EDGE_DISTANCE_INF);
|
||||
|
||||
for (const int i : IndexRange(num_verts)) {
|
||||
BMVert *vert = BM_vert_at_index(bm, i);
|
||||
BMVert *vert = BM_vert_at_index(&bm, i);
|
||||
switch (mode) {
|
||||
case BoundaryAutomaskMode::Edges:
|
||||
if (boundary::vert_is_boundary(vert)) {
|
||||
@@ -1241,7 +1243,7 @@ static void init_boundary_masking_bmesh(Object &object,
|
||||
}
|
||||
break;
|
||||
case BoundaryAutomaskMode::FaceSets:
|
||||
if (!face_set::vert_has_unique_face_set(vert)) {
|
||||
if (!face_set::vert_has_unique_face_set(face_set_offset, *vert)) {
|
||||
edge_distance[i] = 0;
|
||||
}
|
||||
}
|
||||
@@ -1254,7 +1256,7 @@ static void init_boundary_masking_bmesh(Object &object,
|
||||
continue;
|
||||
}
|
||||
|
||||
BMVert *vert = BM_vert_at_index(bm, i);
|
||||
BMVert *vert = BM_vert_at_index(&bm, i);
|
||||
for (BMVert *neighbor : vert_neighbors_get_bmesh(*vert, neighbors)) {
|
||||
const int neighbor_idx = BM_elem_index_get(neighbor);
|
||||
|
||||
|
||||
@@ -256,15 +256,16 @@ void filter_verts_with_unique_face_sets_grids(const GroupedSpan<int> vert_to_fac
|
||||
}
|
||||
}
|
||||
|
||||
void filter_verts_with_unique_face_sets_bmesh(const bool unique,
|
||||
const Set<BMVert *, 0> verts,
|
||||
void filter_verts_with_unique_face_sets_bmesh(int face_set_offset,
|
||||
const bool unique,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
const MutableSpan<float> factors)
|
||||
{
|
||||
BLI_assert(verts.size() == factors.size());
|
||||
|
||||
int i = 0;
|
||||
for (const BMVert *vert : verts) {
|
||||
if (unique == face_set::vert_has_unique_face_set(vert)) {
|
||||
if (unique == face_set::vert_has_unique_face_set(face_set_offset, *vert)) {
|
||||
factors[i] = 0.0f;
|
||||
}
|
||||
i++;
|
||||
|
||||
@@ -43,7 +43,7 @@ bool vert_has_unique_face_set(GroupedSpan<int> vert_to_face_map,
|
||||
Span<int> face_sets,
|
||||
const SubdivCCG &subdiv_ccg,
|
||||
SubdivCCGCoord coord);
|
||||
bool vert_has_unique_face_set(const BMVert *vert);
|
||||
bool vert_has_unique_face_set(int face_set_offset, const BMVert &vert);
|
||||
|
||||
/**
|
||||
* Creates the sculpt face set attribute on the mesh if it doesn't exist.
|
||||
@@ -75,8 +75,9 @@ void filter_verts_with_unique_face_sets_grids(GroupedSpan<int> vert_to_face_map,
|
||||
bool unique,
|
||||
Span<int> grids,
|
||||
MutableSpan<float> factors);
|
||||
void filter_verts_with_unique_face_sets_bmesh(bool unique,
|
||||
const Set<BMVert *, 0> verts,
|
||||
void filter_verts_with_unique_face_sets_bmesh(int face_set_offset,
|
||||
bool unique,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
MutableSpan<float> factors);
|
||||
|
||||
} // namespace blender::ed::sculpt_paint::face_set
|
||||
|
||||
@@ -1089,6 +1089,9 @@ static void calc_relax_filter(const Depsgraph &depsgraph,
|
||||
Vector<float3> translations;
|
||||
};
|
||||
BMesh &bm = *ss.bm;
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&bm.pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
|
||||
threading::EnumerableThreadSpecific<LocalData> all_tls;
|
||||
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
|
||||
threading::parallel_for(node_mask.index_range(), 1, [&](const IndexRange range) {
|
||||
@@ -1108,7 +1111,7 @@ static void calc_relax_filter(const Depsgraph &depsgraph,
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
smooth::calc_relaxed_translations_bmesh(
|
||||
verts, positions, false, factors, tls.vert_neighbors, translations);
|
||||
verts, positions, face_set_offset, false, factors, tls.vert_neighbors, translations);
|
||||
|
||||
zero_disabled_axis_components(*ss.filter_cache, translations);
|
||||
clip_and_lock_translations(sd, ss, positions, translations);
|
||||
@@ -1265,6 +1268,8 @@ static void calc_relax_face_sets_filter(const Depsgraph &depsgraph,
|
||||
Vector<float3> translations;
|
||||
};
|
||||
BMesh &bm = *ss.bm;
|
||||
const int face_set_offset = CustomData_get_offset_named(
|
||||
&bm.pdata, CD_PROP_INT32, ".sculpt_face_set");
|
||||
threading::EnumerableThreadSpecific<LocalData> all_tls;
|
||||
MutableSpan<bke::pbvh::BMeshNode> nodes = pbvh.nodes<bke::pbvh::BMeshNode>();
|
||||
threading::parallel_for(node_mask.index_range(), 1, [&](const IndexRange range) {
|
||||
@@ -1281,12 +1286,18 @@ static void calc_relax_face_sets_filter(const Depsgraph &depsgraph,
|
||||
scale_factors(factors, strength);
|
||||
clamp_factors(factors, 0.0f, 1.0f);
|
||||
|
||||
face_set::filter_verts_with_unique_face_sets_bmesh(relax_face_sets, verts, factors);
|
||||
face_set::filter_verts_with_unique_face_sets_bmesh(
|
||||
face_set_offset, relax_face_sets, verts, factors);
|
||||
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
smooth::calc_relaxed_translations_bmesh(
|
||||
verts, positions, relax_face_sets, factors, tls.vert_neighbors, translations);
|
||||
smooth::calc_relaxed_translations_bmesh(verts,
|
||||
positions,
|
||||
face_set_offset,
|
||||
relax_face_sets,
|
||||
factors,
|
||||
tls.vert_neighbors,
|
||||
translations);
|
||||
|
||||
zero_disabled_axis_components(*ss.filter_cache, translations);
|
||||
clip_and_lock_translations(sd, ss, positions, translations);
|
||||
|
||||
@@ -604,6 +604,7 @@ void calc_relaxed_translations_grids(const SubdivCCG &subdiv_ccg,
|
||||
|
||||
void calc_relaxed_translations_bmesh(const Set<BMVert *, 0> &verts,
|
||||
const Span<float3> positions,
|
||||
const int face_set_offset,
|
||||
const bool filter_boundary_face_sets,
|
||||
const Span<float> factors,
|
||||
Vector<Vector<BMVert *>> &neighbors,
|
||||
@@ -636,8 +637,9 @@ void calc_relaxed_translations_bmesh(const Set<BMVert *, 0> &verts,
|
||||
}
|
||||
|
||||
if (filter_boundary_face_sets) {
|
||||
neighbors[i].remove_if(
|
||||
[&](const BMVert *vert) { return face_set::vert_has_unique_face_set(vert); });
|
||||
neighbors[i].remove_if([&](const BMVert *vert) {
|
||||
return face_set::vert_has_unique_face_set(face_set_offset, *vert);
|
||||
});
|
||||
}
|
||||
|
||||
if (neighbors[i].is_empty()) {
|
||||
|
||||
@@ -110,6 +110,7 @@ void calc_relaxed_translations_grids(const SubdivCCG &subdiv_ccg,
|
||||
MutableSpan<float3> translations);
|
||||
void calc_relaxed_translations_bmesh(const Set<BMVert *, 0> &verts,
|
||||
Span<float3> positions,
|
||||
const int face_set_offset,
|
||||
bool filter_boundary_face_sets,
|
||||
Span<float> factors,
|
||||
Vector<Vector<BMVert *>> &neighbors,
|
||||
|
||||
Reference in New Issue
Block a user