Cleanup: Use C++ types, return values for loose edge subdivision

This commit is contained in:
Hans Goudey
2024-05-20 21:32:25 -04:00
parent 8f9fa07cc1
commit c5bec86e71
4 changed files with 37 additions and 52 deletions

View File

@@ -39,12 +39,11 @@ Mesh *subdiv_to_mesh(Subdiv *subdiv, const ToMeshSettings *settings, const Mesh
* If `is_simple` is false, this will perform a B-Spline interpolation using the edge neighbors,
* otherwise a linear interpolation will be done base on the edge vertices.
*/
void mesh_interpolate_position_on_edge(const float (*coarse_positions)[3],
const blender::int2 *coarse_edges,
blender::GroupedSpan<int> vert_to_edge_map,
int coarse_edge_index,
bool is_simple,
float u,
float pos_r[3]);
float3 mesh_interpolate_position_on_edge(Span<float3> coarse_positions,
Span<int2> coarse_edges,
GroupedSpan<int> vert_to_edge_map,
int coarse_edge_index,
bool is_simple,
float u);
} // namespace blender::bke::subdiv

View File

@@ -13,9 +13,11 @@
#include "BLI_array.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_task.hh"
#include "BKE_attribute_math.hh"
#include "BKE_customdata.hh"
#include "BKE_key.hh"
#include "BKE_mesh.hh"
@@ -955,7 +957,7 @@ static void subdiv_mesh_vertex_loose(const ForeachContext *foreach_context,
/* Get neighbor edges of the given one.
* - neighbors[0] is an edge adjacent to edge->v1.
* - neighbors[1] is an edge adjacent to edge->v2. */
static void find_edge_neighbors(const int2 *coarse_edges,
static void find_edge_neighbors(const Span<int2> coarse_edges,
const GroupedSpan<int> vert_to_edge_map,
const int edge_index,
const int2 *neighbors[2])
@@ -993,10 +995,10 @@ static void find_edge_neighbors(const int2 *coarse_edges,
}
}
static void points_for_loose_edges_interpolation_get(const float (*coarse_positions)[3],
static void points_for_loose_edges_interpolation_get(const Span<float3> coarse_positions,
const int2 &coarse_edge,
const int2 *neighbors[2],
float points_r[4][3])
float3 points_r[4])
{
/* Middle points corresponds to the edge. */
copy_v3_v3(points_r[1], coarse_positions[coarse_edge[0]]);
@@ -1029,28 +1031,25 @@ static void points_for_loose_edges_interpolation_get(const float (*coarse_positi
}
}
void mesh_interpolate_position_on_edge(const float (*coarse_positions)[3],
const int2 *coarse_edges,
const GroupedSpan<int> vert_to_edge_map,
const int coarse_edge_index,
const bool is_simple,
const float u,
float pos_r[3])
float3 mesh_interpolate_position_on_edge(const Span<float3> coarse_positions,
const Span<int2> coarse_edges,
const GroupedSpan<int> vert_to_edge_map,
const int coarse_edge_index,
const bool is_simple,
const float u)
{
const int2 &coarse_edge = coarse_edges[coarse_edge_index];
const int2 edge = coarse_edges[coarse_edge_index];
if (is_simple) {
interp_v3_v3v3(pos_r, coarse_positions[coarse_edge[0]], coarse_positions[coarse_edge[1]], u);
}
else {
/* Find neighbors of the coarse edge. */
const int2 *neighbors[2];
find_edge_neighbors(coarse_edges, vert_to_edge_map, coarse_edge_index, neighbors);
float points[4][3];
points_for_loose_edges_interpolation_get(coarse_positions, coarse_edge, neighbors, points);
float weights[4];
key_curve_position_weights(u, weights, KEY_BSPLINE);
interp_v3_v3v3v3v3(pos_r, points[0], points[1], points[2], points[3], weights);
return math::interpolate(coarse_positions[edge[0]], coarse_positions[edge[1]], u);
}
/* Find neighbors of the coarse edge. */
const int2 *neighbors[2];
find_edge_neighbors(coarse_edges, vert_to_edge_map, coarse_edge_index, neighbors);
float3 points[4];
points_for_loose_edges_interpolation_get(coarse_positions, edge, neighbors, points);
float4 weights;
key_curve_position_weights(u, weights, KEY_BSPLINE);
return bke::attribute_math::mix4(weights, points[0], points[1], points[2], points[3]);
}
static void subdiv_mesh_vertex_of_loose_edge_interpolate(SubdivMeshContext *ctx,
@@ -1093,14 +1092,13 @@ static void subdiv_mesh_vertex_of_loose_edge(const ForeachContext *foreach_conte
subdiv_mesh_vertex_of_loose_edge_interpolate(ctx, coarse_edge, u, subdiv_vertex_index);
}
/* Interpolate coordinate. */
mesh_interpolate_position_on_edge(
reinterpret_cast<const float(*)[3]>(ctx->coarse_positions.data()),
ctx->coarse_edges.data(),
ctx->subdiv_positions[subdiv_vertex_index] = mesh_interpolate_position_on_edge(
ctx->coarse_positions,
ctx->coarse_edges,
ctx->vert_to_edge_map,
coarse_edge_index,
is_simple,
u,
ctx->subdiv_positions[subdiv_vertex_index]);
u);
}
/** \} */

View File

@@ -2270,14 +2270,8 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
DRWSubdivLooseVertex &subd_v1 = loose_subd_verts[subd_vert_offset];
subd_v1.coarse_vertex_index = (i == 0) ? coarse_edge[0] : -1u;
const float u1 = i * inv_resolution_1;
bke::subdiv::mesh_interpolate_position_on_edge(
reinterpret_cast<const float(*)[3]>(coarse_positions.data()),
coarse_edges.data(),
vert_to_edge_map,
coarse_edge_index,
is_simple,
u1,
subd_v1.co);
subd_v1.co = bke::subdiv::mesh_interpolate_position_on_edge(
coarse_positions, coarse_edges, vert_to_edge_map, coarse_edge_index, is_simple, u1);
subd_edge.loose_subdiv_v1_index = subd_vert_offset++;
@@ -2285,14 +2279,8 @@ void DRW_subdivide_loose_geom(DRWSubdivCache *subdiv_cache, MeshBufferCache *cac
DRWSubdivLooseVertex &subd_v2 = loose_subd_verts[subd_vert_offset];
subd_v2.coarse_vertex_index = ((i + 1) == resolution - 1) ? coarse_edge[1] : -1u;
const float u2 = (i + 1) * inv_resolution_1;
bke::subdiv::mesh_interpolate_position_on_edge(
reinterpret_cast<const float(*)[3]>(coarse_positions.data()),
coarse_edges.data(),
vert_to_edge_map,
coarse_edge_index,
is_simple,
u2,
subd_v2.co);
subd_v2.co = bke::subdiv::mesh_interpolate_position_on_edge(
coarse_positions, coarse_edges, vert_to_edge_map, coarse_edge_index, is_simple, u2);
subd_edge.loose_subdiv_v2_index = subd_vert_offset++;
}

View File

@@ -74,8 +74,8 @@ struct DRWSubdivLooseVertex {
* of subdivision. */
unsigned int coarse_vertex_index;
/* Position and normal of the vertex. */
float co[3];
float nor[3];
float3 co;
float3 nor;
};
/** \} */