*/}}
Browse Source

Use repeated merge

YimingWu 1 year ago
parent
commit
677605cd75
2 changed files with 9 additions and 8 deletions
  1. 1 1
      la_tns_mesh.c
  2. 8 7
      resources/la_modelling.c

+ 1 - 1
la_tns_mesh.c

@@ -800,7 +800,7 @@ int tnsMMeshMergeVerts(tnsMeshObject* mo, tnsMVert* into, tnsMVert* mv){
     lstRemoveItem(&mo->mv,mv); memLeave(mv); mo->totmv--;
     lstRemoveItem(&mo->me,me); memLeave(me); mo->totme--;
     tnsMMeshClearFirstLastSelection(mo);
-    tnsPrintMeshTopology(mo);
+    //tnsPrintMeshTopology(mo);
     return 1;
 }
 

+ 8 - 7
resources/la_modelling.c

@@ -1495,11 +1495,13 @@ int la_MergeGetCenter(tnsMeshObject* mo, int SelectMode, int MergeMode, real* ce
     return 1;
 }
 void la_MergeSelected(tnsMeshObject* mo, real* center, int* count_success, int* count_fail){
-    tnsMVert* fmv=0,*NextMv=0; int success=0,fail=0;
-    for(tnsMVert* mv=mo->mv.pFirst;mv;mv=NextMv){ NextMv=mv->Item.pNext;
-        if(!(mv->flags&TNS_MESH_FLAG_SELECTED)) continue; if(!fmv){ fmv=mv; success++; continue; }
-        if(tnsMMeshMergeVerts(mo,fmv,mv)){ success++; }else{ fail++; }
-    }
+    tnsMVert* fmv=0,*NextMv=0; int success=0,fail=0,has_success=0;
+    do{ fail=0; has_success=0;
+        for(tnsMVert* mv=mo->mv.pFirst;mv;mv=NextMv){ NextMv=mv->Item.pNext;
+            if((!(mv->flags&TNS_MESH_FLAG_SELECTED))||mv==fmv) continue; if(!fmv){ fmv=mv; success++; continue; }
+            if(tnsMMeshMergeVerts(mo,fmv,mv)){ success++; has_success=1; }else{ fail++; }
+        }
+    }while(has_success&&fail);
     if(count_success){ *count_success=success; } if(count_fail){ *count_fail=fail; }
     if(!fmv) return; tnsVectorCopy3d(center,fmv->p);
     tnsMMeshRefreshIndex(mo);
@@ -1522,7 +1524,7 @@ int OPINV_Merge(laOperator *a, laEvent *e){
             return LA_FINISHED;
         }
         int success,fail;
-        la_MergeSelected(mo,center,&success,&fail); printf("succeeded: %d failed:%d\n",success,fail);
+        la_MergeSelected(mo,center,&success,&fail); //printf("succeeded: %d failed:%d\n",success,fail);
         if(fail){
             char* msg[256]; sprintf(msg,"Succeeded: %d vertices, failed: %d vertices.",success,fail);
             laEnableMessagePanel(a, 0, "Merging partially succeeded.", msg, e->x, e->y, 0, e);
@@ -1574,5 +1576,4 @@ void la_RegisterModellingOperators(){
     laCreateOperatorType("M_knife", "Knife", "Cut through edges", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Knife, OPMOD_Knife, 0, LA_EXTRA_TO_PANEL);
     at=laCreateOperatorType("M_merge", "Merge", "Merge vertices", OPCHK_ViewportAndSceneExists, 0, 0, OPINV_Merge, OPMOD_FinishOnData, 0, LA_EXTRA_TO_PANEL);
     at->UiDefine=laui_Merge;
-    
 }