@@ -221,7 +221,6 @@ class CVertexWelder {
221221
222222 constexpr auto INVALID_INDEX = std::numeric_limits<uint32_t >::max ();
223223 core::vector<uint32_t > remappedVertexIndexes (vertexCount);
224- std::fill (remappedVertexIndexes.begin (), remappedVertexIndexes.end (), INVALID_INDEX);
225224
226225 uint32_t maxRemappedIndex = 0 ;
227226 // iterate by index, so that we always use the smallest index when multiple vertexes can be welded together
@@ -230,24 +229,31 @@ class CVertexWelder {
230229 hlsl::float32_t3 position;
231230 positionView.decodeElement <hlsl::float32_t3>(index, position);
232231 auto remappedVertexIndex = INVALID_INDEX;
233- bool foundVertex = false ;
234232 as.forEachBroadphaseNeighborCandidates (position, [&](const typename AccelStructureT::vertex_data_t & candidate) {
235233 const auto neighborRemappedIndex = remappedVertexIndexes[candidate.index ];
236- if (index == candidate.index ) {
237- foundVertex = true ;
234+ // make sure we can only map higher indices to lower indices to disallow loops
235+ if (candidate.index <index)
236+ {
237+ auto neighborRemappedIndex = remappedVertexIndexes[candidate.index ];
238+ if (neighborRemappedIndex == INVALID_INDEX)
239+ return true ;
240+ // the link should only be 1 step away (vertices should only remap to vertices that aren't getting remapped)
241+ if (neighborRemappedIndex != remappedVertexIndexes[neighborRemappedIndex])
242+ return true ;
243+
244+ if (shouldWeldFn (polygon, index, neighborRemappedIndex))
245+ {
246+ remappedVertexIndex = neighborRemappedIndex;
247+ return false ;
248+ }
238249 }
239- else if (neighborRemappedIndex != INVALID_INDEX && shouldWeldFn (polygon, index, candidate.index )) {
240- remappedVertexIndex = neighborRemappedIndex;
250+ else if (index==candidate.index )
251+ {
252+ remappedVertexIndex = index;
253+ maxRemappedIndex = index;
241254 }
242- return !(foundVertex && remappedVertexIndex != INVALID_INDEX) ;
255+ return true ;
243256 });
244- if (foundVertex)
245- {
246- if (remappedVertexIndex == INVALID_INDEX) {
247- remappedVertexIndex = index;
248- maxRemappedIndex = index;
249- }
250- }
251257 remappedVertexIndexes[index] = remappedVertexIndex;
252258 }
253259
0 commit comments