Cleanup: Sculpt: Pass vertex instead of iterator struct to relax function
This commit is contained in:
@@ -78,18 +78,19 @@ void sculpt_project_v3_normal_align(const SculptSession &ss,
|
||||
namespace blender::ed::sculpt_paint::smooth {
|
||||
|
||||
static void relax_vertex_interior(SculptSession &ss,
|
||||
PBVHVertexIter *vd,
|
||||
PBVHVertRef vert,
|
||||
const float factor,
|
||||
const bool filter_boundary_face_sets,
|
||||
float *r_final_pos)
|
||||
{
|
||||
const float3 &co = SCULPT_vertex_co_get(ss, vert);
|
||||
float smooth_pos[3];
|
||||
int avg_count = 0;
|
||||
int neighbor_count = 0;
|
||||
zero_v3(smooth_pos);
|
||||
|
||||
SculptVertexNeighborIter ni;
|
||||
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd->vertex, ni) {
|
||||
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vert, ni) {
|
||||
neighbor_count++;
|
||||
if (!filter_boundary_face_sets ||
|
||||
(filter_boundary_face_sets && !face_set::vert_has_unique_face_set(ss, ni.vertex)))
|
||||
@@ -103,43 +104,44 @@ static void relax_vertex_interior(SculptSession &ss,
|
||||
|
||||
/* Don't modify corner vertices. */
|
||||
if (neighbor_count <= 2) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
if (avg_count == 0) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
mul_v3_fl(smooth_pos, 1.0f / avg_count);
|
||||
|
||||
const float3 vno = SCULPT_vertex_normal_get(ss, vd->vertex);
|
||||
const float3 vno = SCULPT_vertex_normal_get(ss, vert);
|
||||
|
||||
if (is_zero_v3(vno)) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
float plane[4];
|
||||
plane_from_point_normal_v3(plane, vd->co, vno);
|
||||
plane_from_point_normal_v3(plane, co, vno);
|
||||
|
||||
float smooth_closest_plane[3];
|
||||
closest_to_plane_v3(smooth_closest_plane, plane, smooth_pos);
|
||||
|
||||
float final_disp[3];
|
||||
sub_v3_v3v3(final_disp, smooth_closest_plane, vd->co);
|
||||
sub_v3_v3v3(final_disp, smooth_closest_plane, co);
|
||||
|
||||
mul_v3_fl(final_disp, factor);
|
||||
add_v3_v3v3(r_final_pos, vd->co, final_disp);
|
||||
add_v3_v3v3(r_final_pos, co, final_disp);
|
||||
}
|
||||
|
||||
static void relax_vertex_boundary(SculptSession &ss,
|
||||
PBVHVertexIter *vd,
|
||||
PBVHVertRef vert,
|
||||
const float factor,
|
||||
const bool filter_boundary_face_sets,
|
||||
float *r_final_pos)
|
||||
{
|
||||
const float3 &co = SCULPT_vertex_co_get(ss, vert);
|
||||
float smooth_pos[3];
|
||||
float boundary_normal[3];
|
||||
int avg_count = 0;
|
||||
@@ -148,7 +150,7 @@ static void relax_vertex_boundary(SculptSession &ss,
|
||||
zero_v3(boundary_normal);
|
||||
|
||||
SculptVertexNeighborIter ni;
|
||||
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd->vertex, ni) {
|
||||
SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vert, ni) {
|
||||
neighbor_count++;
|
||||
if (!filter_boundary_face_sets ||
|
||||
(filter_boundary_face_sets && !face_set::vert_has_unique_face_set(ss, ni.vertex)))
|
||||
@@ -164,7 +166,7 @@ static void relax_vertex_boundary(SculptSession &ss,
|
||||
|
||||
/* Calculate a normal for the constraint plane using the edges of the boundary. */
|
||||
float to_neighbor[3];
|
||||
sub_v3_v3v3(to_neighbor, SCULPT_vertex_co_get(ss, ni.vertex), vd->co);
|
||||
sub_v3_v3v3(to_neighbor, SCULPT_vertex_co_get(ss, ni.vertex), co);
|
||||
normalize_v3(to_neighbor);
|
||||
add_v3_v3(boundary_normal, to_neighbor);
|
||||
}
|
||||
@@ -173,12 +175,12 @@ static void relax_vertex_boundary(SculptSession &ss,
|
||||
|
||||
/* Don't modify corner vertices. */
|
||||
if (neighbor_count <= 2) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
if (avg_count == 0) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,38 +191,38 @@ static void relax_vertex_boundary(SculptSession &ss,
|
||||
normalize_v3_v3(vno, boundary_normal);
|
||||
}
|
||||
else {
|
||||
vno = SCULPT_vertex_normal_get(ss, vd->vertex);
|
||||
vno = SCULPT_vertex_normal_get(ss, vert);
|
||||
}
|
||||
|
||||
if (is_zero_v3(vno)) {
|
||||
copy_v3_v3(r_final_pos, vd->co);
|
||||
copy_v3_v3(r_final_pos, co);
|
||||
return;
|
||||
}
|
||||
|
||||
float plane[4];
|
||||
plane_from_point_normal_v3(plane, vd->co, vno);
|
||||
plane_from_point_normal_v3(plane, co, vno);
|
||||
|
||||
float smooth_closest_plane[3];
|
||||
closest_to_plane_v3(smooth_closest_plane, plane, smooth_pos);
|
||||
|
||||
float final_disp[3];
|
||||
sub_v3_v3v3(final_disp, smooth_closest_plane, vd->co);
|
||||
sub_v3_v3v3(final_disp, smooth_closest_plane, co);
|
||||
|
||||
mul_v3_fl(final_disp, factor);
|
||||
add_v3_v3v3(r_final_pos, vd->co, final_disp);
|
||||
add_v3_v3v3(r_final_pos, co, final_disp);
|
||||
}
|
||||
|
||||
void relax_vertex(SculptSession &ss,
|
||||
PBVHVertexIter *vd,
|
||||
PBVHVertRef vert,
|
||||
const float factor,
|
||||
const bool filter_boundary_face_sets,
|
||||
float *r_final_pos)
|
||||
{
|
||||
if (boundary::vert_is_boundary(ss, vd->vertex)) {
|
||||
relax_vertex_boundary(ss, vd, factor, filter_boundary_face_sets, r_final_pos);
|
||||
if (boundary::vert_is_boundary(ss, vert)) {
|
||||
relax_vertex_boundary(ss, vert, factor, filter_boundary_face_sets, r_final_pos);
|
||||
}
|
||||
else {
|
||||
relax_vertex_interior(ss, vd, factor, filter_boundary_face_sets, r_final_pos);
|
||||
relax_vertex_interior(ss, vert, factor, filter_boundary_face_sets, r_final_pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1029,7 +1029,7 @@ static void calc_relax_filter(const Sculpt & /*sd*/,
|
||||
}
|
||||
orig_co = vd.co;
|
||||
|
||||
smooth::relax_vertex(ss, &vd, clamp_f(fade, 0.0f, 1.0f), false, val);
|
||||
smooth::relax_vertex(ss, vd.vertex, clamp_f(fade, 0.0f, 1.0f), false, val);
|
||||
disp = val - float3(vd.co);
|
||||
|
||||
disp = to_orientation_space(*ss.filter_cache) * disp;
|
||||
@@ -1091,7 +1091,7 @@ static void calc_relax_face_sets_filter(const Sculpt & /*sd*/,
|
||||
continue;
|
||||
}
|
||||
|
||||
smooth::relax_vertex(ss, &vd, clamp_f(fade, 0.0f, 1.0f), relax_face_sets, val);
|
||||
smooth::relax_vertex(ss, vd.vertex, clamp_f(fade, 0.0f, 1.0f), relax_face_sets, val);
|
||||
disp = val - float3(vd.co);
|
||||
|
||||
disp = to_orientation_space(*ss.filter_cache) * disp;
|
||||
|
||||
@@ -1688,7 +1688,7 @@ void surface_smooth_displace_step(Span<float3> laplacian_disp,
|
||||
|
||||
/* Slide/Relax */
|
||||
void relax_vertex(SculptSession &ss,
|
||||
PBVHVertexIter *vd,
|
||||
PBVHVertRef vert,
|
||||
float factor,
|
||||
bool filter_boundary_face_sets,
|
||||
float *r_final_pos);
|
||||
|
||||
Reference in New Issue
Block a user