Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| /* The closest corner is defined to be the closest corner on the closest face. */ | /* The closest corner is defined to be the closest corner on the closest face. */ | ||||
| static void get_closest_mesh_corners(const Mesh &mesh, | static void get_closest_mesh_corners(const Mesh &mesh, | ||||
| const VArray<float3> &positions, | const VArray<float3> &positions, | ||||
| const IndexMask mask, | const IndexMask mask, | ||||
| const MutableSpan<int> r_corner_indices, | const MutableSpan<int> r_corner_indices, | ||||
| const MutableSpan<float> r_distances_sq, | const MutableSpan<float> r_distances_sq, | ||||
| const MutableSpan<float3> r_positions) | const MutableSpan<float3> r_positions) | ||||
| { | { | ||||
| const Span<MVert> verts = mesh.verts(); | const Span<float3> mesh_positions = mesh.positions(); | ||||
| const Span<MPoly> polys = mesh.polys(); | const Span<MPoly> polys = mesh.polys(); | ||||
| const Span<MLoop> loops = mesh.loops(); | const Span<MLoop> loops = mesh.loops(); | ||||
| BLI_assert(mesh.totloop > 0); | BLI_assert(mesh.totloop > 0); | ||||
| Array<int> poly_indices(positions.size()); | Array<int> poly_indices(positions.size()); | ||||
| get_closest_mesh_polys(mesh, positions, mask, poly_indices, {}, {}); | get_closest_mesh_polys(mesh, positions, mask, poly_indices, {}, {}); | ||||
| for (const int i : mask) { | for (const int i : mask) { | ||||
| const float3 position = positions[i]; | const float3 position = positions[i]; | ||||
| const int poly_index = poly_indices[i]; | const int poly_index = poly_indices[i]; | ||||
| const MPoly &poly = polys[poly_index]; | const MPoly &poly = polys[poly_index]; | ||||
| /* Find the closest vertex in the polygon. */ | /* Find the closest vertex in the polygon. */ | ||||
| float min_distance_sq = FLT_MAX; | float min_distance_sq = FLT_MAX; | ||||
| const MVert *closest_mvert; | int closest_vert_index = 0; | ||||
| int closest_loop_index = 0; | int closest_loop_index = 0; | ||||
| for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) { | for (const int loop_index : IndexRange(poly.loopstart, poly.totloop)) { | ||||
| const MLoop &loop = loops[loop_index]; | const MLoop &loop = loops[loop_index]; | ||||
| const int vertex_index = loop.v; | const int vertex_index = loop.v; | ||||
| const MVert &mvert = verts[vertex_index]; | const float distance_sq = math::distance_squared(position, mesh_positions[vertex_index]); | ||||
| const float distance_sq = math::distance_squared(position, float3(mvert.co)); | |||||
| if (distance_sq < min_distance_sq) { | if (distance_sq < min_distance_sq) { | ||||
| min_distance_sq = distance_sq; | min_distance_sq = distance_sq; | ||||
| closest_loop_index = loop_index; | closest_loop_index = loop_index; | ||||
| closest_mvert = &mvert; | closest_vert_index = vertex_index; | ||||
| } | } | ||||
| } | } | ||||
| if (!r_corner_indices.is_empty()) { | if (!r_corner_indices.is_empty()) { | ||||
| r_corner_indices[i] = closest_loop_index; | r_corner_indices[i] = closest_loop_index; | ||||
| } | } | ||||
| if (!r_positions.is_empty()) { | if (!r_positions.is_empty()) { | ||||
| r_positions[i] = closest_mvert->co; | r_positions[i] = mesh_positions[closest_vert_index]; | ||||
| } | } | ||||
| if (!r_distances_sq.is_empty()) { | if (!r_distances_sq.is_empty()) { | ||||
| r_distances_sq[i] = min_distance_sq; | r_distances_sq[i] = min_distance_sq; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static bool component_is_available(const GeometrySet &geometry, | static bool component_is_available(const GeometrySet &geometry, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||