diff --git a/TopChicken.lua b/TopChicken.lua index 0b7d39e..b65098e 100644 --- a/TopChicken.lua +++ b/TopChicken.lua @@ -4,7 +4,7 @@ -- Intestazioni require( 'EgtBase') _ENV = EgtProtectGlobal() -EgtEnableDebug( false) +EgtEnableDebug( true) EgtAddToPackagePath(EgtGetSourceDir() .. 'LuaLibs\\?.lua') require( 'EgtCompo') @@ -495,13 +495,13 @@ function ImportOutLoop( tbLayer, sNameFileNGE) EgtErase(LastPart) local tbIdLoop = ExplodeAndNameEdges( IdLoop) - EgtSetInfo(tbIdLoop[1],'AF',2) - EgtSetInfo(tbIdLoop[2],'AF',2) - EgtSetInfo(tbIdLoop[3],'AF',2) - EgtSetInfo(tbIdLoop[4],'AF',2) - EgtSetInfo(tbIdLoop[5],'AF',2) - EgtSetInfo(tbIdLoop[6],'AF',2) - EgtSetInfo(tbIdLoop[7],'AF',2) + EgtSetInfo(tbIdLoop[1],'AF',1) + EgtSetInfo(tbIdLoop[2],'AF',1) + EgtSetInfo(tbIdLoop[3],'AF',1) + EgtSetInfo(tbIdLoop[4],'AF',1) + EgtSetInfo(tbIdLoop[5],'AF',1) + EgtSetInfo(tbIdLoop[6],'AF',1) + EgtSetInfo(tbIdLoop[7],'AF',1) --SaveMePlease() -- definizione SideAng -- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45) @@ -808,15 +808,16 @@ function CMP_Draw(bPreview) -- Creo il contorno esterno local tbIdLoopTC = ImportOutLoop( FindLayers( Pz_Top), sPath .. 'TopChicken.nge') -- Creo il pezzo dato il contorno - CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoopTC, CMP.ST, false) + local dTh_TC = CMP.ST + CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoopTC, dTh_TC, false) --local nJunctionType -- 1 TrimStart, 2 TrimEnd, 3Ang local vtDirCurr = EgtSV( tbIdLoopTC[1], GDB_RT.GLOB) local nPrev = #tbIdLoopTC local vtDirPrev = EgtEV( tbIdLoopTC[nPrev], GDB_RT.GLOB) local nNext = 2 local vtDirNext = EgtSV( tbIdLoopTC[nNext], GDB_RT.GLOB) - local nTypePrev = EgtGetInfo(tbIdLoopTC[nPrev], 'AF', 'i') or 0 - local nTypeNext = EgtGetInfo(tbIdLoopTC[nNext], 'AF', 'i') or 0 + -- local nTypePrev = EgtGetInfo(tbIdLoopTC[nPrev], 'AF', 'i') or 0 + -- local nTypeNext = EgtGetInfo(tbIdLoopTC[nNext], 'AF', 'i') or 0 local dPairAngPrev = 0 local dPairAngNext = 0 local dPairAng = 0 @@ -828,135 +829,138 @@ function CMP_Draw(bPreview) local nJunctionType = 1 for i=1, #tbIdLoopTC do local tbInfo = {} + local sNamePz = 'PartA'.. tostring(i) + local Pz_A = CreatePartLayer(sNamePz) + tbInfo.nId = Pz_A + tbInfo.sName = sNamePz + local nType = EgtGetInfo(tbIdLoopTC[i], 'AF', 'i') or 0 + local dPairAng = 0 + if nType == 1 then + dPairAng = 90 + elseif nType == 2 then + dPairAng = -90 + end + EgtSetInfo(Pz_A, 'PairAng', dPairAng) + tbPartsInfo[tbInfo.nId] = tbInfo + end + + for i=1,#tbIdLoopTC do + local sPartName = sUNICode..'PartA'..tostring(i) + local nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT,sPartName) + local tbInfo = tbPartsInfo[nPart] + dPairAngPrev = EgtGetInfo(nPart, 'PairAng', 'd') or 0 + dPairAngNext = EgtGetInfo(nPart, 'PairAng', 'd') or 0 + dPairAng = EgtGetInfo(nPart, 'PairAng', 'd') or 0 local nType = EgtGetInfo(tbIdLoopTC[i], 'AF', 'i') or 0 vtDirNext = EgtSV( tbIdLoopTC[nNext]) - if nTypePrev == 2 then - dPairAngPrev = -90 - elseif nTypePrev == 1 then - dPairAngPrev = 90 - end - if nTypeNext == 2 then - dPairAngNext = -90 - elseif nTypeNext == 1 then - dPairAngNext = 90 - end - if nType == 2 then - -- WATERFALL - local sNamePz = 'PartA'.. tostring(i) - local Pz_A = CreatePartLayer(sNamePz) - tbInfo.nId = Pz_A - tbInfo.sName = sNamePz - local dH = 100 - tbInfo.dH = dH - ----- caratteristiche forntalino - dPairAng = -90 + local dH = 100 + tbInfo.dH = dH + local dTh = 20 + if nType == 1 then + ----- caratteristiche alzatina + --dPairAng = 60 tbInfo.dPairAng = dPairAng + tbInfo.dSideAngT = dPairAng - 90 + dTh = 20 + tbInfo.dTh = dTh + tbInfo.dYOffset = dTh * tan(tbInfo.dSideAngT) + --nJunctionType = 2 -- trim end + --nJunctionType = 1 -- trim start + nJunctionType = 3 -- angle junction + bOnLoop = false + ----- caratteristiche alzatina + elseif nType == 2 then + ----- caratteristiche frontalino + --dPairAng = -90 + tbInfo.dPairAng = dPairAng + tbInfo.dSideAngT = -( -dPairAng - 90) + dTh = 20 + tbInfo.dTh = dTh + tbInfo.dYOffset = dTh * tan(tbInfo.dSideAngT) nJunctionType = 3 -- angle junction bOnLoop = true ----- caratteristiche forntalino - dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) - local PAng, NAng = GetPrevNextAng(tbIdLoopTC[i]) - -- calcolo l'angolo di sformo con il pezzo precedente + end + dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) + local PAng, NAng = GetPrevNextAng(tbIdLoopTC[i]) + -- calcolo l'angolo di sformo con il pezzo precedente + local dXOffset = 0 + local bSameSide = dPairAng * dPairAngPrev > 0 + if bSameSide then if nJunctionType == 3 then local dSideAng_4, _, dBeta_DX = CalcDraftAngle( vtDirPrev, vtDirCurr, dPairAngPrev, dPairAng, PAng) - tbInfo.dAngBR = dBeta_DX + tbInfo.dAngBR = 180 - dBeta_DX if bOnLoop then dSideAng_4 = dSideAng_4 * (-1) end if PAng < 0 then dSideAng_4 = dSideAng_4 * (-1) end tbInfo.dSideAngR = dSideAng_4 + if not bOnLoop then + dLenPrev, dLen, dXOffset = ManageJunction(PAng,dTh, dTh,nJunctionType, dLenPrev, dLen) + end + else + -- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off + dLenPrev, dLen, dXOffset = ManageJunction(PAng,dTh, dTh,nJunctionType, dLenPrev, dLen) + -- setto il sideang da giunzione a T + -- setto il sideang da giunzione a T + local dSideAng_4 = 90 - math.abs(PAng) + if bOnLoop then dSideAng_4 = dSideAng_4 * (-1) end + tbInfo.dSideAngR = dSideAng_4 end - if not bOnLoop then - dLenPrev, dLen = ManageJunction(PAng,CMP.ST, CMP.ST,nJunctionType, dLenPrev, dLen) + else + -- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo precedente) + local dSideAng = PAng < 0 and (90 + PAng) or 90-PAng + if bOnLoop then dSideAng = dSideAng * (-1) end + tbInfo.dSideAngR = dSideAng + -- visto che il pezzo precedente non è dallo stesso lato allora corrego l'estensione del pezzo corrente (in funzione del suo spessore) + if not bOnLoop then + local dOffset = dTh * tan( 90 - PAng) + dLen = dLen + dOffset + if nJunctionType == 1 then dXOffset = dXOffset + dOffset end end - -- calcolo l'angolo di sformo con il pezzo successivo + end + -- -- calcolo l'angolo di sformo con il pezzo successivo + bSameSide = dPairAng * dPairAngNext > 0 + if bSameSide then if nJunctionType == 3 then local dSideAng_2, dBeta_SX, __ = CalcDraftAngle( vtDirCurr, vtDirNext, dPairAng, dPairAngNext, NAng) - tbInfo.dAngBL = dBeta_SX + tbInfo.dAngBL = 180 - dBeta_SX if bOnLoop then dSideAng_2 = dSideAng_2 * (-1) end if NAng < 0 then dSideAng_2 = dSideAng_2 * (-1) end tbInfo.dSideAngL = dSideAng_2 + if not bOnLoop then + dLen, dLenNext = ManageJunction(NAng, dTh, dTh, nJunctionType, dLen, dLenNext) + end + else + -- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off + dLen, dLenNext = ManageJunction(NAng, dTh, dTh, nJunctionType, dLen, dLenNext) + -- setto il sideang da giunzione a T + local dSideAng_2 = 90 - math.abs(NAng) + if bOnLoop then dSideAng_2 = dSideAng_2 * (-1) end + tbInfo.dSideAngL = dSideAng_2 end + else + -- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo successivo) + local dSideAng = NAng < 0 and (90 + NAng) or 90-NAng + if bOnLoop then dSideAng = dSideAng * (-1) end + tbInfo.dSideAngL = dSideAng + -- visto che il pezzo successivo non è dallo stesso lato allora correggo l'estensione del pezzo corrente (in funzione del suo spessore) if not bOnLoop then - dLen, dLenNext = ManageJunction(NAng, CMP.ST, CMP.ST, nJunctionType, dLen, dLenNext) + local dOffset = dTh * tan( 90 - NAng) + dLen = dLen + dOffset + if nJunctionType == 2 then dXOffset = dXOffset + dOffset end end - tbInfo.dLen = dLen - tbInfo.sDestRefOff = '0,0,-x' - tbInfo.sRefOff = '0,0,0' - elseif nType == 1 then - -- SPLASHTOP - local sNamePz = 'PartA'.. tostring(i) - local Pz_A = CreatePartLayer(sNamePz) - tbInfo.nId = Pz_A - tbInfo.sName = sNamePz - local dH = 100 - tbInfo.dH = dH - ----- caratteristiche alzatina - dPairAng = 90 - tbInfo.dPairAng = dPairAng - --nJunctionType = 2 -- trim end - nJunctionType = 1 -- trim start - bOnLoop = false - ----- caratteristiche alzatina - dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) - local PAng, NAng = GetPrevNextAng(tbIdLoopTC[i]) - -- calcolo l'angolo di sformo con il pezzo precedente - local dXOffset = 0 - local bSameSide = dPairAng * dPairAngPrev > 0 - if bSameSide then - if nJunctionType == 3 then - local dSideAng_4, _, dBeta_DX = CalcDraftAngle( vtDirPrev, vtDirCurr, dPairAngPrev, dPairAng, PAng) - tbInfo.dAngBR = 180 - dBeta_DX - if bOnLoop then dSideAng_4 = dSideAng_4 * (-1) end - if PAng < 0 then dSideAng_4 = dSideAng_4 * (-1) end - tbInfo.dSideAngR = dSideAng_4 - if not bOnLoop then - dLenPrev, dLen, dXOffset = ManageJunction(PAng,CMP.ST, CMP.ST,nJunctionType, dLenPrev, dLen) - end - else - -- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off - dLenPrev, dLen, dXOffset = ManageJunction(PAng,CMP.ST, CMP.ST,nJunctionType, dLenPrev, dLen) - -- setto il sideang da giunzione a T - -- setto il sideang da giunzione a T - local dSideAng_4 = 90 - math.abs(PAng) - if bOnLoop then dSideAng_4 = dSideAng_4 * (-1) end - tbInfo.dSideAngR = dSideAng_4 - end - else - -- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo precedente) - tbInfo.dSideAngR = PAng < 0 and (90 + PAng) or -PAng - -- visto che il pezzo precedente non è dallo stesso lato allora estendo il pezzo corrente (in funzione del suo spessore) - dLen = dLen + CMP.ST * sin( 90 - math.abs(PAng)) - end - -- -- calcolo l'angolo di sformo con il pezzo successivo - bSameSide = dPairAng * dPairAngNext > 0 - if bSameSide then - if nJunctionType == 3 then - local dSideAng_2, dBeta_SX, __ = CalcDraftAngle( vtDirCurr, vtDirNext, dPairAng, dPairAngNext, NAng) - tbInfo.dAngBL = 180 - dBeta_SX - if bOnLoop then dSideAng_2 = dSideAng_2 * (-1) end - if NAng < 0 then dSideAng_2 = dSideAng_2 * (-1) end - tbInfo.dSideAngL = dSideAng_2 - if not bOnLoop then - dLen, dLenNext = ManageJunction(NAng, CMP.ST, CMP.ST, nJunctionType, dLen, dLenNext) - end - else - -- se ho una giunzione a T allora devo aggiustare la lunghezza dei pezzi sia che la faccia sia On, sia che sia Off - dLen, dLenNext = ManageJunction(NAng, CMP.ST, CMP.ST, nJunctionType, dLen, dLenNext) - -- setto il sideang da giunzione a T - local dSideAng_2 = 90 - math.abs(NAng) - if bOnLoop then dSideAng_2 = dSideAng_2 * (-1) end - tbInfo.dSideAngL = dSideAng_2 - end - else - -- setto il sideAng da giunzione a T (che va bene anche se la giunzione è angolata ma senza pezzo successivo) - tbInfo.dSideAngL = NAng < 0 and (90 + NAng) or -NAng - -- visto che il pezzo successivo non è dallo stesso lato allora estendo il pezzo corrente (in funzione del suo spessore) - dLen = dLen + CMP.ST * sin( 90 - math.abs(NAng)) - end - tbInfo.dLen = dLen - tbInfo.sDestRefOff = '0,0,0' - tbInfo.sRefOff = tostring(dXOffset)..',0,-x' end - tbPartsInfo[tbInfo.nId] = tbInfo + tbInfo.dLen = dLen + + -- setto l'offset dei riferimenti + if nType == 1 then + -- SPLASHTOP + tbInfo.sDestRefOff = '0,0,0' + tbInfo.sRefOff = tostring(dXOffset)..','..tostring(tbInfo.dYOffset)..',-x' + elseif nType == 2 then + -- WATERFALL + tbInfo.sDestRefOff = '0,0,-x' + tbInfo.sRefOff = '0,'..tostring(tbInfo.dYOffset)..',0' + end dLenPrev = EgtCurveLength(tbIdLoopTC[i]) dLen = EgtCurveLength(tbIdLoopTC[nNext]) nPrev = i @@ -967,9 +971,12 @@ function CMP_Draw(bPreview) --dLenPrev = dLen --dLen = dLenNext dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) - nTypePrev = nType - nType = nTypeNext - nTypeNext = EgtGetInfo(tbIdLoopTC[nNext], 'AF', 'i') or 0 + -- nTypePrev = nType + -- nType = nTypeNext + -- nTypeNext = EgtGetInfo(tbIdLoopTC[nNext], 'AF', 'i') or 0 + dPairAngPrev = dPairAng + dPairAng = dPairAngNext + dPairAngNext = EgtGetInfo( tbIdLoopTC[nNext], 'PairAng', 'd') or 0 end for nPart, tbPart in pairs( tbPartsInfo) do @@ -977,12 +984,13 @@ function CMP_Draw(bPreview) local nEdge = string.sub(tbPart.sName, 6) local tbLayer = FindLayers(nPart) local tbIdLoop = CreateAdjustedPart( tbLayer['OutLoop'],tbPart.dLen, tbPart.dH, tbPart.dAngBL, tbPart.dAngBR) - CreatePart(tbLayer,tbPart.sName,tbIdLoop,CMP.ST,false) - CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(nEdge), 'R'..tostring(nEdge), CMP.ST, tbPart.sDestRefOff) - CreateReference(tbPart.sName, 'OutLoop', 'A3', 'R3', CMP.ST, tbPart.sRefOff) + CreatePart(tbLayer,tbPart.sName,tbIdLoop,tbPart.dTh,false) + CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(nEdge), 'R'..tostring(nEdge), dTh_TC, tbPart.sDestRefOff) + CreateReference(tbPart.sName, 'OutLoop', 'A3', 'R3', tbPart.dTh, tbPart.sRefOff) SetPairInfo(tbPart.sName, 'R3', 'TopChicken', 'R'..tostring(nEdge), -1, tbPart.dPairAng, 2) if tbPart.dSideAngL then SetSideAng(tbLayer['OutLoop'], 'A2', tbPart.dSideAngL) end if tbPart.dSideAngR then SetSideAng(tbLayer['OutLoop'], 'A4', tbPart.dSideAngR) end + if tbPart.dSideAngT then SetSideAng(tbLayer['OutLoop'], 'A3', tbPart.dSideAngT) end end --SaveMePlease()