Refactor: Sculpt: Use local array of displacement factors in layer brush
This commit is contained in:
@@ -232,7 +232,7 @@ static void calc_translations_grids(const SubdivCCG &subdiv_ccg,
|
||||
tls.translations.reinitialize(grid_verts_num);
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
translations_from_new_positions(new_positions, positions, translations);
|
||||
scatter_data_grids(subdiv_ccg, translations, grids, all_translations);
|
||||
scatter_data_grids(subdiv_ccg, translations.as_span(), grids, all_translations);
|
||||
}
|
||||
|
||||
static void calc_translations_bmesh(PBVHNode &node,
|
||||
|
||||
@@ -36,6 +36,7 @@ struct LocalData {
|
||||
Vector<float> factors;
|
||||
Vector<float> distances;
|
||||
Vector<float> masks;
|
||||
Vector<float> displacement_factors;
|
||||
};
|
||||
|
||||
static void calc_faces(const Sculpt &sd,
|
||||
@@ -92,9 +93,13 @@ static void calc_faces(const Sculpt &sd,
|
||||
const float bstrength = cache.bstrength;
|
||||
const OrigPositionData orig_data = orig_position_data_get_mesh(object, node);
|
||||
|
||||
tls.displacement_factors.reinitialize(verts.size());
|
||||
const MutableSpan<float> displacement_factors = tls.displacement_factors;
|
||||
array_utils::gather(layer_displacement_factor.as_span(), verts, displacement_factors);
|
||||
|
||||
if (use_persistent_base) {
|
||||
BKE_pbvh_vertex_iter_begin (*ss.pbvh, &node, vd, PBVH_ITER_UNIQUE) {
|
||||
float *disp_factor = &layer_displacement_factor[vd.index];
|
||||
float *disp_factor = &displacement_factors[vd.i];
|
||||
|
||||
/* When using persistent base, the layer brush (holding Control) invert mode resets the
|
||||
* height of the layer to 0. This makes possible to clean edges of previously added layers
|
||||
@@ -125,8 +130,7 @@ static void calc_faces(const Sculpt &sd,
|
||||
}
|
||||
else {
|
||||
BKE_pbvh_vertex_iter_begin (*ss.pbvh, &node, vd, PBVH_ITER_UNIQUE) {
|
||||
const int vi = vd.index;
|
||||
float *disp_factor = &layer_displacement_factor[vi];
|
||||
float *disp_factor = &displacement_factors[vd.i];
|
||||
|
||||
(*disp_factor) += factors[vd.i] * bstrength * (1.05f - std::abs(*disp_factor));
|
||||
const float clamp_mask = masks.is_empty() ? 1.0f : (1.0f - masks[vd.i]);
|
||||
@@ -144,6 +148,8 @@ static void calc_faces(const Sculpt &sd,
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
}
|
||||
|
||||
array_utils::scatter(displacement_factors.as_span(), verts, layer_displacement_factor);
|
||||
}
|
||||
|
||||
static void calc_grids(const Sculpt &sd,
|
||||
@@ -190,13 +196,16 @@ static void calc_grids(const Sculpt &sd,
|
||||
const MutableSpan<float> masks = tls.masks;
|
||||
mask::gather_mask_grids(subdiv_ccg, grids, masks);
|
||||
|
||||
tls.displacement_factors.reinitialize(grid_verts_num);
|
||||
const MutableSpan<float> displacement_factors = tls.displacement_factors;
|
||||
gather_data_grids(subdiv_ccg, layer_displacement_factor.as_span(), grids, displacement_factors);
|
||||
|
||||
PBVHVertexIter vd;
|
||||
const float bstrength = cache.bstrength;
|
||||
const OrigPositionData orig_data = orig_position_data_get_grids(object, node);
|
||||
|
||||
BKE_pbvh_vertex_iter_begin (*ss.pbvh, &node, vd, PBVH_ITER_UNIQUE) {
|
||||
const int vi = vd.index;
|
||||
float *disp_factor = &layer_displacement_factor[vi];
|
||||
float *disp_factor = &displacement_factors[vd.i];
|
||||
|
||||
(*disp_factor) += factors[vd.i] * bstrength * (1.05f - std::abs(*disp_factor));
|
||||
const float clamp_mask = 1.0f - masks[vd.i];
|
||||
@@ -213,6 +222,8 @@ static void calc_grids(const Sculpt &sd,
|
||||
SCULPT_clip(sd, ss, vd.co, final_co);
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
|
||||
scatter_data_grids(subdiv_ccg, displacement_factors.as_span(), grids, layer_displacement_factor);
|
||||
}
|
||||
|
||||
static void calc_bmesh(const Sculpt &sd,
|
||||
@@ -263,10 +274,12 @@ static void calc_bmesh(const Sculpt &sd,
|
||||
const MutableSpan<float> masks = tls.masks;
|
||||
mask::gather_mask_bmesh(*ss.bm, verts, masks);
|
||||
|
||||
BKE_pbvh_vertex_iter_begin (*ss.pbvh, &node, vd, PBVH_ITER_UNIQUE) {
|
||||
const int vi = vd.index;
|
||||
tls.displacement_factors.reinitialize(verts.size());
|
||||
const MutableSpan<float> displacement_factors = tls.displacement_factors;
|
||||
gather_data_vert_bmesh(layer_displacement_factor.as_span(), verts, displacement_factors);
|
||||
|
||||
float *disp_factor = &layer_displacement_factor[vi];
|
||||
BKE_pbvh_vertex_iter_begin (*ss.pbvh, &node, vd, PBVH_ITER_UNIQUE) {
|
||||
float *disp_factor = &displacement_factors[vd.i];
|
||||
|
||||
(*disp_factor) += factors[vd.i] * bstrength * (1.05f - std::abs(*disp_factor));
|
||||
|
||||
@@ -284,6 +297,8 @@ static void calc_bmesh(const Sculpt &sd,
|
||||
SCULPT_clip(sd, ss, vd.co, final_co);
|
||||
}
|
||||
BKE_pbvh_vertex_iter_end;
|
||||
|
||||
scatter_data_vert_bmesh(displacement_factors.as_span(), verts, layer_displacement_factor);
|
||||
}
|
||||
|
||||
} // namespace layer_cc
|
||||
|
||||
@@ -97,22 +97,22 @@ void gather_grids_normals(const SubdivCCG &subdiv_ccg,
|
||||
void gather_bmesh_normals(const Set<BMVert *, 0> &verts, MutableSpan<float3> normals);
|
||||
|
||||
/** Gather data from an array aligned with all geometry vertices. */
|
||||
template<typename T>
|
||||
void gather_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
Span<float3> src,
|
||||
Span<T> src,
|
||||
Span<int> grids,
|
||||
MutableSpan<float3> node_data);
|
||||
void gather_data_vert_bmesh(Span<float3> src,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
MutableSpan<float3> node_data);
|
||||
MutableSpan<T> node_data);
|
||||
template<typename T>
|
||||
void gather_data_vert_bmesh(Span<T> src, const Set<BMVert *, 0> &verts, MutableSpan<T> node_data);
|
||||
|
||||
/** Scatter data from an array of the node's data to the referenced geometry vertices. */
|
||||
template<typename T>
|
||||
void scatter_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
Span<float3> node_data,
|
||||
Span<T> node_data,
|
||||
Span<int> grids,
|
||||
MutableSpan<float3> dst);
|
||||
void scatter_data_vert_bmesh(Span<float3> node_data,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
MutableSpan<float3> dst);
|
||||
MutableSpan<T> dst);
|
||||
template<typename T>
|
||||
void scatter_data_vert_bmesh(Span<T> node_data, const Set<BMVert *, 0> &verts, MutableSpan<T> dst);
|
||||
|
||||
/**
|
||||
* Calculate initial influence factors based on vertex visibility.
|
||||
|
||||
@@ -277,7 +277,6 @@ float3 SCULPT_vertex_limit_surface_get(const SculptSession &ss, PBVHVertRef vert
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
float SCULPT_mask_get_at_grids_vert_index(const SubdivCCG &subdiv_ccg,
|
||||
const CCGKey &key,
|
||||
const int vert_index)
|
||||
@@ -6717,10 +6716,11 @@ void gather_bmesh_normals(const Set<BMVert *, 0> &verts, const MutableSpan<float
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void gather_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
const Span<float3> src,
|
||||
const Span<T> src,
|
||||
const Span<int> grids,
|
||||
const MutableSpan<float3> node_data)
|
||||
const MutableSpan<T> node_data)
|
||||
{
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
BLI_assert(grids.size() * key.grid_area == node_data.size());
|
||||
@@ -6732,9 +6732,10 @@ void gather_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
}
|
||||
}
|
||||
|
||||
void gather_data_vert_bmesh(const Span<float3> src,
|
||||
template<typename T>
|
||||
void gather_data_vert_bmesh(const Span<T> src,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
const MutableSpan<float3> node_data)
|
||||
const MutableSpan<T> node_data)
|
||||
{
|
||||
BLI_assert(verts.size() == node_data.size());
|
||||
|
||||
@@ -6745,10 +6746,11 @@ void gather_data_vert_bmesh(const Span<float3> src,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void scatter_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
const Span<float3> node_data,
|
||||
const Span<T> node_data,
|
||||
const Span<int> grids,
|
||||
const MutableSpan<float3> dst)
|
||||
const MutableSpan<T> dst)
|
||||
{
|
||||
const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
|
||||
BLI_assert(grids.size() * key.grid_area == node_data.size());
|
||||
@@ -6760,9 +6762,10 @@ void scatter_data_grids(const SubdivCCG &subdiv_ccg,
|
||||
}
|
||||
}
|
||||
|
||||
void scatter_data_vert_bmesh(const Span<float3> node_data,
|
||||
template<typename T>
|
||||
void scatter_data_vert_bmesh(const Span<T> node_data,
|
||||
const Set<BMVert *, 0> &verts,
|
||||
const MutableSpan<float3> dst)
|
||||
const MutableSpan<T> dst)
|
||||
{
|
||||
BLI_assert(verts.size() == node_data.size());
|
||||
|
||||
@@ -6773,6 +6776,36 @@ void scatter_data_vert_bmesh(const Span<float3> node_data,
|
||||
}
|
||||
}
|
||||
|
||||
template void gather_data_grids<float>(const SubdivCCG &,
|
||||
Span<float>,
|
||||
Span<int>,
|
||||
MutableSpan<float>);
|
||||
template void gather_data_grids<float3>(const SubdivCCG &,
|
||||
Span<float3>,
|
||||
Span<int>,
|
||||
MutableSpan<float3>);
|
||||
template void gather_data_vert_bmesh<float>(Span<float>,
|
||||
const Set<BMVert *, 0> &,
|
||||
MutableSpan<float>);
|
||||
template void gather_data_vert_bmesh<float3>(Span<float3>,
|
||||
const Set<BMVert *, 0> &,
|
||||
MutableSpan<float3>);
|
||||
|
||||
template void scatter_data_grids<float>(const SubdivCCG &,
|
||||
Span<float>,
|
||||
Span<int>,
|
||||
MutableSpan<float>);
|
||||
template void scatter_data_grids<float3>(const SubdivCCG &,
|
||||
Span<float3>,
|
||||
Span<int>,
|
||||
MutableSpan<float3>);
|
||||
template void scatter_data_vert_bmesh<float>(Span<float>,
|
||||
const Set<BMVert *, 0> &,
|
||||
MutableSpan<float>);
|
||||
template void scatter_data_vert_bmesh<float3>(Span<float3>,
|
||||
const Set<BMVert *, 0> &,
|
||||
MutableSpan<float3>);
|
||||
|
||||
void fill_factor_from_hide(const Mesh &mesh,
|
||||
const Span<int> verts,
|
||||
const MutableSpan<float> r_factors)
|
||||
|
||||
Reference in New Issue
Block a user