From 298b0a45062b873665034dd6e3d0cb7abef48b40 Mon Sep 17 00:00:00 2001 From: SaraP Date: Thu, 1 Dec 2022 11:31:18 +0100 Subject: [PATCH] 3dPrinting : - correzione calcolo toolpath in spiral vase quando sezione varia tra layer. --- LuaLibs/CalcPaths.lua | 16 ++++++++++------ LuaLibs/CalcToolPath.lua | 34 +++++++++++++++++++++++----------- LuaLibs/RunCalcSolids.lua | 5 +++-- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 1e410b6..820ad6f 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -116,12 +116,16 @@ local function ModifyStartPoint( nCrvId, vPtStart) -- cerco lo start point più vicino tra quelli possibili if vPtStart and #vPtStart > 0 then local nMinIdx = -1 - local dMinDist = GEO.INFINITO - for i = 1, #vPtStart do - local dDist = EgtPointCurveDist( vPtStart[i], nCrvId) - if dDist < dMinDist - 10 * GEO.EPS_SMALL then - dMinDist = dDist - nMinIdx = i + if #vPtStart == 1 then + nMinIdx = 1 + else + local dMinDist = GEO.INFINITO + for i = 1, #vPtStart do + local dDist = EgtPointCurveDist( vPtStart[i], nCrvId) + if dDist < dMinDist - 10 * GEO.EPS_SMALL then + dMinDist = dDist + nMinIdx = i + end end end EgtChangeClosedCurveStartPoint( nCrvId, vPtStart[nMinIdx]) diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 72e6d33..29549e6 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -944,7 +944,7 @@ local function AddSpiralVaseLeadOut( nOldId, LayerParams) local nLeadOut = AddLeadOut( nOldId, LayerParams, EgtGetParent( nOldId)) if nLeadOut then local dDelta = LayerParams.dLayHeight / EgtCurveLength( nOldId) * EgtCurveLength( nLeadOut) - EgtSpiralizeCurve( nLeadOut, dDelta) + EgtSpiralizeCurveAlongExtrusion( nLeadOut, dDelta) end AddRetractionOnLastCrv( nOldId, EgtGetParent( nOldId), LayerParams, LayerParams.dCoastingLen, LayerParams.dWipeLen, LayerParams.dWipeDir) else @@ -956,7 +956,7 @@ end --------------------------------------------------------------------- local function SpiralVase( vLayIds, dCorrZ, LayerParams) - local nOldId + local nOldId, nOldPathId local bFirst = true local nSlicingType = EgtGetInfo( s_nPartId, KEY_SLICING_TYPE, 'i') @@ -1007,13 +1007,15 @@ local function SpiralVase( vLayIds, dCorrZ, LayerParams) local nEntId = EgtGetFirstInGroup( nPathGrpId) while nEntId do local nNewEntId = EgtCopyGlob( nEntId, nTpathGrpId, GDB_IN.LAST_SON) - - -- correggo posizione in Z ( per essere sicuri di appoggiare sul piano) - EgtMove( nNewEntId, dCorrZ * Z_AX(), GDB_RT.GLOB) + + -- correggo la posizione del toolpath + local vtMove = dCorrZ * Z_AX() if nSlicingType == SLICING_TYPE.DEG45_X or nSlicingType == SLICING_TYPE.DEG45_Y then -- eventuale spostamento dell'altezza layer - EgtMove( nNewEntId, LayerParams.dLayHeight * LayerParams.vtSlicing, GDB_RT.GLOB) + vtMove = vtMove + LayerParams.dLayHeight * LayerParams.vtSlicing end + EgtMove( nNewEntId, vtMove, GDB_RT.GLOB) + EgtModifyCurveExtrusion( nNewEntId, LayerParams.vtSlicing, GDB_RT.GLOB) -- eventuale inversione if LayerParams.bInvert then @@ -1033,19 +1035,29 @@ local function SpiralVase( vLayIds, dCorrZ, LayerParams) end bFirst = false else - -- modifico lo start point per collegarlo alla curva precedente local ptOld = EgtEP( nOldId, GDB_ID.ROOT) - if dist( EgtSP( nNewEntId, GDB_ID.ROOT), ptOld) < LayerParams.dStrand + 10 then - EgtChangeClosedCurveStartPoint( nNewEntId, ptOld, GDB_RT.GLOB) - EgtModifyCurveStartPoint( nNewEntId, ptOld, GDB_RT.GLOB) + local ptNew = EgtSP( nNewEntId, GDB_ID.ROOT) + if dist( ptNew, ptOld) < LayerParams.dStrand then + -- se i punti sono vicini ma non coincidenti modifico la curva per avere transizione più uniforme + if not AreSamePointApprox( ptOld, ptNew) then + -- recupero la curva da usare come guida + local nGuideId = EgtCopyGlob( nOldPathId, nTpathGrpId) + -- la porto alla stessa quota del toolpath + EgtMove( nGuideId, vtMove + LayerParams.dLayHeight * LayerParams.vtSlicing, GDB_RT.GLOB) + EgtChangeClosedCurveStartPoint( nGuideId, ptOld, GDB_RT.GLOB) + + EgtSpiralizeCurveAlongGuide( nNewEntId, nGuideId) + EgtErase( nGuideId) + end else EgtOutLog( 'Warning : in spiral vase mode no link betweeen toolpaths (layer '..tostring( nIdx)..') - CalcToolPath') -- aggiungo uscita, coasting e wipe sulla curva precedente AddSpiralVaseLeadOut( nOldId, LayerParams) end - EgtSpiralizeCurve( nNewEntId, LayerParams.dLayHeight) + EgtSpiralizeCurveAlongExtrusion( nNewEntId, LayerParams.dLayHeight) end + nOldPathId = nEntId nOldId = nNewEntId nEntId = EgtGetNext( nEntId) end diff --git a/LuaLibs/RunCalcSolids.lua b/LuaLibs/RunCalcSolids.lua index f6f1b2c..5aea6bf 100644 --- a/LuaLibs/RunCalcSolids.lua +++ b/LuaLibs/RunCalcSolids.lua @@ -114,7 +114,8 @@ local function CreateSpiralVaseSolid( nCrvId, nSolidGrp, LayerParams, dStrand) -- appiattisco la curva local nCrvCopy = EgtCopyGlob( nCrvId, nGrpTmp) local dDelta = ( ptE - ptS) * LayerParams.vtSlicing - EgtSpiralizeCurve( nCrvCopy, - dDelta) + EgtSpiralizeCurveAlongExtrusion( nCrvCopy, - dDelta) + EgtMergeCurvesInCurveCompo( nCrvCopy) -- calcolo la sezione local vtDir = EgtSV( nCrvCopy, GDB_ID.ROOT) @@ -134,7 +135,7 @@ local function CreateSpiralVaseSolid( nCrvId, nSolidGrp, LayerParams, dStrand) end local dMove = ( ptRef - ptS) * LayerParams.vtSlicing EgtMove( vCrvs[i+1], LayerParams.vtSlicing * dMove, GDB_RT.GLOB) - EgtSpiralizeCurve( vCrvs[i+1], dDelta) + EgtSpiralizeCurveAlongExtrusion( vCrvs[i+1], dDelta) end local vSurfs = {} for i = 1, #vCrvs - 1 do