@@ -709,7 +709,7 @@ void extractClosedPath( std::vector<VertId>& path, std::vector<VertId>& closedPa
709
709
}
710
710
711
711
// for all vertices get over all incident vertices to find connected sequences
712
- size_t duplicateNonManifoldVertices ( Triangulation & t, FaceBitSet * region, std::vector<VertDuplication>* dups )
712
+ size_t duplicateNonManifoldVertices ( Triangulation & t, FaceBitSet * region, std::vector<VertDuplication>* dups, VertId lastValidVert )
713
713
{
714
714
MR_TIMER;
715
715
if ( t.empty () )
@@ -718,11 +718,12 @@ size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region, std
718
718
std::vector<IncidentVert> incidentItemsVector;
719
719
preprocessTriangles ( t, region, incidentItemsVector );
720
720
721
- auto lastUsedVertId = incidentItemsVector.back ().srcVert ;
721
+ if ( !lastValidVert )
722
+ lastValidVert = incidentItemsVector.back ().srcVert ;
722
723
723
724
std::vector<VertId> path;
724
725
std::vector<VertId> closedPath;
725
- VertBitSet visitedVertices (lastUsedVertId);
726
+ VertBitSet visitedVertices ( incidentItemsVector. back (). srcVert ); // explicitly not `lastValidVert` but last vert used in triangulation
726
727
size_t duplicatedVerticesCnt = 0 ;
727
728
size_t posBegin = 0 , posEnd = 0 ;
728
729
while ( posEnd != incidentItemsVector.size () )
@@ -767,7 +768,7 @@ size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region, std
767
768
{
768
769
if ( foundChains )
769
770
{
770
- incidentItems.duplicateVertex ( path, lastUsedVertId , dups );
771
+ incidentItems.duplicateVertex ( path, lastValidVert , dups );
771
772
++duplicatedVerticesCnt;
772
773
}
773
774
++foundChains;
@@ -787,7 +788,7 @@ size_t duplicateNonManifoldVertices( Triangulation & t, FaceBitSet * region, std
787
788
788
789
if ( foundChains )
789
790
{
790
- incidentItems.duplicateVertex ( closedPath, lastUsedVertId , dups );
791
+ incidentItems.duplicateVertex ( closedPath, lastValidVert , dups );
791
792
++duplicatedVerticesCnt;
792
793
}
793
794
++foundChains;
@@ -873,6 +874,7 @@ int uniteCloseVertices( Mesh& mesh, const UniteCloseParams& params /*= {} */ )
873
874
if ( numChanged <= 0 )
874
875
return numChanged;
875
876
877
+ auto lastValidVert = mesh.topology .lastValidVert (); // need to take it before removing faces
876
878
Triangulation t ( mesh.topology .faceSize () );
877
879
FaceBitSet region ( mesh.topology .faceSize () );
878
880
for ( auto f : mesh.topology .getValidFaces () )
@@ -891,10 +893,11 @@ int uniteCloseVertices( Mesh& mesh, const UniteCloseParams& params /*= {} */ )
891
893
if ( params.duplicateNonManifold )
892
894
{
893
895
std::vector<MeshBuilder::VertDuplication> localDups;
894
- duplicateNonManifoldVertices ( t, ®ion, &localDups );
896
+ duplicateNonManifoldVertices ( t, ®ion, &localDups, lastValidVert );
895
897
if ( !localDups.empty () )
896
898
{
897
- mesh.points .resize ( localDups.back ().dupVert + 1 );
899
+ mesh.points .resizeNoInit ( localDups.back ().dupVert + 1 );
900
+ mesh.topology .vertResize ( mesh.points .size () );
898
901
for ( auto [org, dup] : localDups )
899
902
mesh.points [dup] = mesh.points [org];
900
903
if ( params.optionalDuplications )
0 commit comments