@@ -182,29 +182,39 @@ public virtual int[] StitchLoop(int[] vloop1, int[] vloop2, int group_id = -1)
182182 /// <summary>
183183 /// Stitch two sets of boundary edges that are provided as unordered pairs of edges, by
184184 /// adding triangulated quads between each edge pair.
185- /// If a failure is encountered during stitching, the triangles added up to that point are removed.
185+ /// If bAbortOnFailure==true and a failure is encountered during stitching, the triangles added up to that point are removed.
186+ /// If bAbortOnFailure==false, failures are ignored and the returned triangle list may contain invalid values!
186187 /// </summary>
187- public virtual int [ ] StitchUnorderedEdges ( List < Index2i > EdgePairs , int group_id = - 1 )
188+ public virtual int [ ] StitchUnorderedEdges ( List < Index2i > EdgePairs , int group_id , bool bAbortOnFailure , out bool stitch_incomplete )
188189 {
189190 int N = EdgePairs . Count ;
190191 int [ ] new_tris = new int [ N * 2 ] ;
192+ if ( bAbortOnFailure == false ) {
193+ for ( int k = 0 ; k < new_tris . Length ; ++ k )
194+ new_tris [ k ] = DMesh3 . InvalidID ;
195+ }
196+ stitch_incomplete = false ;
191197
192198 int i = 0 ;
193199 for ( ; i < N ; ++ i ) {
194200 Index2i edges = EdgePairs [ i ] ;
195201
196202 // look up and orient the first edge
197203 Index4i edge_a = Mesh . GetEdge ( edges . a ) ;
198- if ( edge_a . d != DMesh3 . InvalidID )
199- goto operation_failed ;
204+ if ( edge_a . d != DMesh3 . InvalidID ) {
205+ if ( bAbortOnFailure ) goto operation_failed ;
206+ else { stitch_incomplete = true ; continue ; }
207+ }
200208 Index3i edge_a_tri = Mesh . GetTriangle ( edge_a . c ) ;
201209 int a = edge_a . a , b = edge_a . b ;
202210 IndexUtil . orient_tri_edge ( ref a , ref b , edge_a_tri ) ;
203211
204212 // look up and orient the second edge
205213 Index4i edge_b = Mesh . GetEdge ( edges . b ) ;
206- if ( edge_b . d != DMesh3 . InvalidID )
207- goto operation_failed ;
214+ if ( edge_b . d != DMesh3 . InvalidID ) {
215+ if ( bAbortOnFailure ) goto operation_failed ;
216+ else { stitch_incomplete = true ; continue ; }
217+ }
208218 Index3i edge_b_tri = Mesh . GetTriangle ( edge_b . c ) ;
209219 int c = edge_b . a , d = edge_b . b ;
210220 IndexUtil . orient_tri_edge ( ref c , ref d , edge_b_tri ) ;
@@ -218,8 +228,10 @@ public virtual int[] StitchUnorderedEdges(List<Index2i> EdgePairs, int group_id
218228 int tid1 = Mesh . AppendTriangle ( t1 , group_id ) ;
219229 int tid2 = Mesh . AppendTriangle ( t2 , group_id ) ;
220230
221- if ( tid1 < 0 || tid2 < 0 )
222- goto operation_failed ;
231+ if ( tid1 < 0 || tid2 < 0 ) {
232+ if ( bAbortOnFailure ) goto operation_failed ;
233+ else { stitch_incomplete = true ; continue ; }
234+ }
223235
224236 new_tris [ 2 * i ] = tid1 ;
225237 new_tris [ 2 * i + 1 ] = tid2 ;
@@ -235,6 +247,11 @@ public virtual int[] StitchUnorderedEdges(List<Index2i> EdgePairs, int group_id
235247 }
236248 return null ;
237249 }
250+ public virtual int [ ] StitchUnorderedEdges ( List < Index2i > EdgePairs , int group_id = - 1 , bool bAbortOnFailure = true )
251+ {
252+ bool incomplete = false ;
253+ return StitchUnorderedEdges ( EdgePairs , group_id , bAbortOnFailure , out incomplete ) ;
254+ }
238255
239256
240257
0 commit comments