From cd8d63998f948f40d7d0de8ddeeec1d01653282f Mon Sep 17 00:00:00 2001 From: SaraP Date: Fri, 13 May 2022 17:23:45 +0200 Subject: [PATCH] 3dPrinting : - corretti alcuni errori nella generazione dei solidi. --- LuaLibs/CalcSolids.lua | 51 +++++++++++++++++++++++++++++++--------- LuaLibs/CalcToolPath.lua | 6 ++++- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/LuaLibs/CalcSolids.lua b/LuaLibs/CalcSolids.lua index 1a58982..8ca1e87 100644 --- a/LuaLibs/CalcSolids.lua +++ b/LuaLibs/CalcSolids.lua @@ -87,7 +87,7 @@ local function CreateHalfSection( ptS, vtDir, dStrand, dH, nSolidGrp) end -------------------------------------------------------------------- -local function CreateSolid( nCrvId, nSolidGrp, LayerParams) +local function CreateSolid( nCrvId, nSolidGrp, dStrand, dH) -- punti e direzioni all'inizio e fine della curva guida local ptS = EgtSP( nCrvId) local vtS = EgtSV( nCrvId) @@ -96,17 +96,17 @@ local function CreateSolid( nCrvId, nSolidGrp, LayerParams) local vtE = EgtEV( nCrvId) vtE:rotate( Z_AX(), -90) -- creazione del solido aperto (tubo) - local nSectId = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) + local nSectId = CreateSection( ptS, vtS, dStrand, dH, nSolidGrp) local nSrfId = EgtSurfTmSwept( nSolidGrp, nSectId, nCrvId, false, 0.1) - EgtErase( nSectId) + EgtErase( nSectId) if not nSrfId then return nil end -- creazione del mezzo disco iniziale - local nSectS = CreateHalfSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) + local nSectS = CreateHalfSection( ptS, vtS, dStrand, dH, nSolidGrp) local nSrfS = EgtSurfTmByScrewing( nSolidGrp, nSectS, ptS, Z_AX(), 180, 0, false, 0.1) EgtErase( nSectS) if not nSrfS then return nil end -- creazione del mezzo disco finale - local nSectE = CreateHalfSection( ptE, vtE, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) + local nSectE = CreateHalfSection( ptE, vtE, dStrand, dH, nSolidGrp) local nSrfE = EgtSurfTmByScrewing( nSolidGrp, nSectE, ptE, Z_AX(), 180, 0, false, 0.1) EgtErase( nSectE) if not nSrfE then return nil end @@ -133,18 +133,42 @@ local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) local nParts = EgtIf( nType == TYPE.LINK, 1, 10) local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp) + EgtApproxCurve( nCopyId, GDB_CA.ARCS, 0.1) local nId = EgtSplitCurve( nCopyId, nParts) local bOk = true for nInd = 0, nParts - 1 do - local nGuideId = nId + nInd - local nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams) + local nGuideId = nId + nInd + local nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams.dStrand, LayerParams.dLayHeight) + + if not nSrfId then + -- ritento con sezione leggermente modificata + nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams.dStrand - 100 * GEO.EPS_SMALL, LayerParams.dLayHeight) + if not nSrfId then + -- ritento spezzando la curva + local nFirstCrv, nCrvNbr = EgtSplitCurveAtCorners( nGuideId, 60) + if nFirstCrv then + local nSrfIds = {} + for nInd2 = 0, nCrvNbr-1 do + local nSrfId2 = CreateSolid( nFirstCrv + nInd2, nSolidGrp, LayerParams.dStrand - 100 * GEO.EPS_SMALL, LayerParams.dLayHeight) + EgtErase( nFirstCrv + nInd2) + if nSrfId2 then + table.insert( nSrfIds, nSrfId2) + end + end + if #nSrfIds == nCrvNbr then + nSrfId = EgtSurfTmBySewing( nSolidGrp, nSrfIds) + end + end + end + end + if nSrfId then EgtSetColor( nSrfId, Color) EgtSetInfo( nSrfId, KEY_TYPE, nType) else - bOk = false - end + bOk = false + end EgtErase( nGuideId) end @@ -219,9 +243,14 @@ function CalcSolids.Exec( nPartId) end -- eventuale segnalazione errori - if #vErr > 0 then - EgtOutBox( 'Error on layers :\n' .. table.concat( vErr, ','), 'SolidCalc') + -- if #vErr > 0 then + -- EgtOutBox( 'Error on layers :\n' .. table.concat( vErr, ','), 'SolidCalc') + -- end + + for i = 1, #vErr do + EgtOutLog( 'Error on solid creation (layer ' .. vErr[i] .. ') - SolidCalc') end + end --------------------------------------------------------------------- diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 2aa4406..cb65cb0 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -48,6 +48,8 @@ local function AddLeadIn( nCrvId, LayerParams, nGrpId) vtOrtho:rotate( Z_AX(), dAng) local ptS = ptE - LayerParams.LeadInTangDist * vtTang + LayerParams.LeadInOrthoDist * vtOrtho + -- impongo che la coordinata z dei due punti sia la stessa + ptS = Point3d( ptS:getX(), ptS:getY(), ptE:getZ()) local nLeadInCrv = GDB_ID.NULL if LayerParams.LeadInType == LEAD_TYPE.LINEAR then @@ -76,7 +78,9 @@ local function AddLeadOut( nCrvId, LayerParams, nGrpId) end vtOrtho:rotate( Z_AX(), dAng) - local ptE = ptS + LayerParams.LeadOutTangDist * vtTang + LayerParams.LeadOutOrthoDist * vtOrtho + local ptE = ptS + LayerParams.LeadOutTangDist * vtTang + LayerParams.LeadOutOrthoDist * vtOrtho + -- impongo che la coordinata z dei due punti sia la stessa + ptE = Point3d( ptE:getX(), ptE:getY(), ptS:getZ()) local nLeadOutCrv = GDB_ID.NULL if LayerParams.LeadOutType == LEAD_TYPE.LINEAR then