From 5f2c853d42aec0c985049ca01fb0c2065ee2e17c Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 8 May 2025 09:02:34 +0200 Subject: [PATCH] EgtMachKernel : - ulteriori miglioramenti a AddRawPart con grezzo da Trimesh. --- MachMgrRawParts.cpp | 50 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/MachMgrRawParts.cpp b/MachMgrRawParts.cpp index ea7a1db..15547f3 100644 --- a/MachMgrRawParts.cpp +++ b/MachMgrRawParts.cpp @@ -415,13 +415,10 @@ MachMgr::AddRawPart( int nSurfId, Color cCol) pStm->GetLocalBBox( b3Srf) ; // ne calcolo la silhouette secondo Z+ bool bSilh = false ; - PtrOwner pCavParSilh( CreateCAvParSilhouettesSurfTm()) ; - if ( ! IsNull( pCavParSilh)) { - Frame3d frSrf( b3Srf.GetMin()) ; - const double SILH_TOL = 1.0 ; + const int NUM_TRIA_LIM = 500 ; + if ( pStm->GetTriangleCount() < NUM_TRIA_LIM) { POLYLINEVECTOR vPL ; - if ( pCavParSilh->SetData( { pStm}, frSrf, SILH_TOL) && - pCavParSilh->GetSilhouette( 0, vPL)) { + if ( pStm->GetSilhouette( Z_AX, 10.0, vPL) && ! vPL.empty()) { // cerco il contorno esterno int nInd = - 1 ; double dMaxArea = 0 ; @@ -435,9 +432,44 @@ MachMgr::AddRawPart( int nSurfId, Color cCol) } } // ne deduco la curva - if ( nInd >= 0 && pCrvCompo->FromPolyLine( vPL[nInd])) { - pCrvCompo->SetExtrusion( Z_AX) ; - bSilh = true ; + PtrOwner pCrvSilh( CreateCurveComposite()) ; + if ( nInd >= 0 && pCrvSilh->FromPolyLine( vPL[nInd])) { + pCrvSilh->SetExtrusion( Z_AX) ; + Plane3d plProj ; + plProj.Set( b3Srf.GetMin(), Z_AX) ; + pCrvCompo.Set( GetCurveComposite( ProjectCurveOnPlane( *pCrvSilh, plProj))) ; + if ( ! IsNull( pCrvCompo)) { + pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ; + bSilh = true ; + } + } + } + } + else { + PtrOwner pCavParSilh( CreateCAvParSilhouettesSurfTm()) ; + if ( ! IsNull( pCavParSilh)) { + Frame3d frSrf( b3Srf.GetMin()) ; + const double SILH_TOL = 1.0 ; + POLYLINEVECTOR vPL ; + if ( pCavParSilh->SetData( { pStm}, frSrf, SILH_TOL) && + pCavParSilh->GetSilhouette( 0, vPL)) { + // cerco il contorno esterno + int nInd = - 1 ; + double dMaxArea = 0 ; + for ( int i = 0 ; i < int( vPL.size()) ; ++ i) { + double dArea ; + if ( vPL[i].GetAreaXY( dArea) && abs( dArea) > dMaxArea) { + if ( dArea < 0) + vPL[i].Invert() ; + dMaxArea = abs( dArea) ; + nInd = i ; + } + } + // ne deduco la curva + if ( nInd >= 0 && pCrvCompo->FromPolyLine( vPL[nInd])) { + pCrvCompo->SetExtrusion( Z_AX) ; + bSilh = true ; + } } } }