*/}}
Procházet zdrojové kódy

Edge subdiv and face cutting working correctly (I guess)

YimingWu před 1 rokem
rodič
revize
2dfa897946
1 změnil soubory, kde provedl 19 přidání a 2 odebrání
  1. 19 2
      la_tns_mesh.c

+ 19 - 2
la_tns_mesh.c

@@ -21,6 +21,16 @@
 
 extern tnsMain *T;
 
+void tnsPrintMeshTopology(tnsMeshObject*mo){
+    for(tnsMVert* mv=mo->mv.pFirst;mv;mv=mv->Item.pNext){ printf("%d ",mv->i); } printf("\n");
+    for(tnsMEdge* me=mo->me.pFirst;me;me=me->Item.pNext){ printf("%d-%d ",me->vl->i,me->vr->i); } printf("\n");
+    for(tnsMFace* mf=mo->mf.pFirst;mf;mf=mf->Item.pNext){ printf("%d-[",mf->looplen);
+        for(laListItemPointer* lip=mf->l.pFirst;lip;lip=lip->pNext){ tnsMEdge*ie=lip->p;
+        printf("%d%s%d ",ie->vl->i,(ie->fl&&ie->fr)?":":(ie->fl?"l":(ie->fr?"r":"-")),ie->vr->i); }
+        printf("] ");
+    }printf("\n");
+}
+
 tnsEdgeHash* tnsCreateEdgeHash(int OptionalInitialVertCount){
     tnsEdgeHash*eh=memAcquireSimple(sizeof(tnsEdgeHash));
     eh->max=OptionalInitialVertCount;
@@ -367,6 +377,11 @@ void tnsMMeshFaceAddEdge(tnsMFace* mf, tnsMEdge* me){
     lstAppendPointer(&mf->l, me); mf->looplen++;
     if(!me->fl) me->fl=mf; elif(!me->fr) me->fr=mf;
 }
+void tnsMMeshFaceAddEdgeReplaceFace(tnsMFace* mf, tnsMEdge* me, tnsMFace* to_be_replaced){
+    lstAppendPointer(&mf->l, me); mf->looplen++;
+    if(me->fl==to_be_replaced) me->fl=mf; elif(me->fr==to_be_replaced) me->fr=mf;
+    elif(!me->fl) me->fl=mf; elif(!me->fr) me->fr=mf;
+}
 tnsMFace* tnsMMeshFaceHasVert(tnsMFace* mf, tnsMVert* mv){
     if(!mf||!mv) return 0; for(laListItemPointer*lip=mf->l.pFirst;lip;lip=lip->pNext){ if(tnsMMeshEdgeAnotherVert(lip->p, mv)) return mf; }
     return 0;
@@ -387,14 +402,15 @@ int tnsMMeshSplitFace(tnsMeshObject* mo, tnsMFace* mf, tnsMEdge* me, tnsMFace**
     }
     tnsMFace* f1=tnsMMeshNewFace(mo);
     for(laListItemPointer*lip=StartLip;lip;lip=NextLip){ NextLip=lip->pNext?lip->pNext:mf->l.pFirst; 
-         if(lip==EndLip){ tnsMMeshFaceAddEdge(f1, me); break; } tnsMMeshFaceAddEdge(f1, lip->p);
+         if(lip==EndLip){ tnsMMeshFaceAddEdgeReplaceFace(f1, me, mf); break; } tnsMMeshFaceAddEdgeReplaceFace(f1, lip->p, mf);
     }
     tnsMFace* f2=tnsMMeshNewFace(mo);
     for(laListItemPointer*lip=EndLip;lip;lip=NextLip){ NextLip=lip->pNext?lip->pNext:mf->l.pFirst; 
-         if(lip==StartLip){ tnsMMeshFaceAddEdge(f2, me); break; } tnsMMeshFaceAddEdge(f2, lip->p);
+         if(lip==StartLip){ tnsMMeshFaceAddEdgeReplaceFace(f2, me, mf); break; } tnsMMeshFaceAddEdgeReplaceFace(f2, lip->p, mf);
     }
     tnsMMeshRemoveFaceOnly(mo, mf);
     if(r_f1){ *r_f1=f1; }  if(r_f2){ *r_f2=f2; }
+    //tnsPrintMeshTopology(mo);
     return 1;
 }
 tnsMEdge* tnsMMeshMakeEdge(tnsMeshObject* mo, tnsMVert* v1, tnsMVert* v2){
@@ -475,6 +491,7 @@ int tnsMMeshEdgeInsertVert(tnsMeshObject* mo, tnsMEdge* me, tnsMVert* mv, tnsMVe
     }
     me->fl=me->fr=0; tnsMMeshRemoveEdgeFace(mo,me);
     if(ref_e1v_optional&&tnsMMeshEdgeShareVert(me1, ref_e1v_optional)){ if(r_e1)*r_e1=me1; if(r_e2)*r_e2=me2; }else{ if(r_e1)*r_e1=me2; if(r_e2)*r_e2=me1; }
+    //tnsPrintMeshTopology(mo);
     return 1;
 }
 tnsMVert* tnsMMeshEdgeInsertVertAt(tnsMeshObject* mo, tnsMEdge* me, real at, tnsMVert* ref_e1v_optional, tnsMEdge** r_e1, tnsMEdge** r_e2){