diff --git a/TopChicken.lua b/TopChicken.lua index 6f9e2fe..0b7d39e 100644 --- a/TopChicken.lua +++ b/TopChicken.lua @@ -77,7 +77,7 @@ local sUNICode = os.date( '%y%m%d%H%M%S', os.time()).."_" -- FUNZIONI BASE PER GENERARE I COMPO SOLID INIZIO ------------------------------------------------------------------------------------------------------------------------- -local function SaveMEPlease() +local function SaveMePlease() EgtSaveFile('D:\\Temp\\marmo\\Vein3D\\FUCK.nge') end @@ -99,7 +99,7 @@ local function CreatePartLayer(PartName) local LAux= EgtGroup(Pz,GDB_RT.LOC) -- layer etichette EgtSetName(LAux,'Aux') EgtOutLog(' Creo Part: '..sUNICode..PartName) - SaveMEPlease() + --SaveMePlease() return Pz end -- @@ -289,7 +289,7 @@ end -- dTh : spessore pezzo -- dOffset : per messa in piano dei pezzi (0 se non si usa) -- bInLoop : tipo di contorno -local function CreatePart(tbLayer, sName, tbIdEntCrv, dTh, bInLoop) +local function CreatePart(tbLayer, sName, tbIdEntCrv, dTh, bInLoop) -- recupero il layer del contorno local IdCurrLayer = EgtGetParent( tbIdEntCrv[1]) -- recupero l'Id del part @@ -461,7 +461,7 @@ local function SetReference() -- Esempio Punto per dimension: -- CreatePointReference( tbName[1], 'OutLoop', 'A1', 'R4', 0, CMP.SB, '0,0,-x') - SaveMEPlease() + --SaveMePlease() end -- @@ -502,7 +502,7 @@ function ImportOutLoop( tbLayer, sNameFileNGE) EgtSetInfo(tbIdLoop[5],'AF',2) EgtSetInfo(tbIdLoop[6],'AF',2) EgtSetInfo(tbIdLoop[7],'AF',2) - SaveMEPlease() + --SaveMePlease() -- definizione SideAng -- EgtSetInfo( tbIdLoop[1], 'OrigSideAng', 45) return tbIdLoop @@ -657,86 +657,128 @@ local function IsDataChanged() end local function CalcDraftAngle( vtDir1, vtDir2, dPairAng1, dPairAng2, dAngBetween) - -- vengono restituiti l'angolo in 3d, i due nuovi angoli di forma per i due pezzi + -- vengono restituiti il SideAng ( calcolato dall'angolo in 3d), i due nuovi angoli di forma per i due pezzi -- dBeta1 è riferito al pezzo 1 e dBeta2 è riferito al pezzo 2 local dAngTilt1 = dPairAng1 - 90 local dAngTilt2 = dPairAng2 - 90 local vtN1 = Vector3d({0,100,0}) local vtN2 = Vector3d({0,100,0}) vtN1:rotate(X_AX(),dAngTilt1) - vtN2:rotate(X_AX(), dAngBetween) - vtN2:rotate(Z_AX(), dPAng) + vtN2:rotate(X_AX(), dAngTilt2) + vtN2:rotate(Z_AX(), dAngBetween) local vtPerp = vtN1 ^ vtN2 local vtInters1 = vtN1 ^ vtPerp - local vtInters2 = vtN2 ^ vtPerp - local dAng3d = GetRotation(vtInters1, vtInters2, vtPerp) - local dBeta1 = GetAngle( vtDir1 ^ vtPerp) - local dBeta2 = GetAngle( vtDir2 ^ vtPerp) - return dAng3d, dBeta1, dBeta2 + local vtInters2 = vtPerp ^ vtN2 + --local dAng3d = GetRotation(vtInters1, vtInters2, vtPerp) + local dAng3d = GetAngle(vtInters1, vtInters2) + local dBeta1 = GetAngle( vtDir1, vtPerp) + local dBeta2 = GetAngle( vtDir2, vtPerp) + local dSideAng = (180 - dAng3d) / 2 + return dSideAng, dBeta1, dBeta2 end -local function TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2) +local function TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2, bOnLoop) -- restituisce le lunghezze L1 e L2 adattate in base al tipo di giunzione -- nType == 1 -> TrimStart ( del Part2) -- nType == 2 -> TrimEnd ( del Part1) + local dXOffset = 0 + if not bOnLoop then bOnLoop = false end if dAngBetween > 0 then if nType == 1 then - dLen2 = dLne2 - dTh1 / sin(dAngBetween) + -- trim start + local dDeltaStart = - dTh1 / sin(dAngBetween) + dLen2 = dLen2 + dDeltaStart + dXOffset = dDeltaStart + -- extend end + dLen1 = dLen1 + dTh1 * tan(90- math.abs(dAngBetween)) elseif nType == 2 then - dLen1 = dLne1 - dTh2 / sin(dAngBetween) + -- trim end + dLen1 = dLen1 - dTh2 / sin(dAngBetween) + -- extend start + local dDeltaStart = dTh2 * tan(90- math.abs(dAngBetween)) + dLen2 = dLen2 + dDeltaStart + dXOffset = dDeltaStart end else + -- qui sto estendendo le lunghezze, infatti gli angoli sono nergativi e quindi anche il loro seno if nType == 1 then - dLen1 = dLne1 - dTh2 / sin(dAngBetween) + -- il trim start diventa un extend end + local dDelta = - dTh2 / sin(dAngBetween) + if not bOnLoop then dDelta = dDelta - dTh1 * tan(90 - math.abs(dAngBetween)) end + dLen1 = dLen1 + dDelta + -- accorcio lo start + local dDeltaStart = - dTh2 * tan(90- math.abs(dAngBetween)) + dLen2 = dLen2 + dDeltaStart + dXOffset = dDeltaStart elseif nType == 2 then - dLen2 = dLne2 - dTh1 / sin(dAngBetween) + -- il trim end diventa un extend start + local dDeltaStart = - dTh1 / sin(dAngBetween) + if not bOnLoop then dDeltaStart = dDeltaStart - dTh2 * tan(90 - math.abs(dAngBetween)) end + dLen2 = dLen2 + dDeltaStart + dXOffset = math.abs(dDeltaStart) + -- accorcio l'end + dLen1 = dLen1 - dTh1 * tan(90- math.abs(dAngBetween)) end end - return dLen1, dLen2 + return dLen1, dLen2, dXOffset end -local function AngleJunction(dAngBetween, dTh1, dTh2, dLen1, dLen2) +local function AngleJunction(dAngBetween, dTh1, dTh2, dLen1, dLen2, bOnLoop) -- modifico la lughezza dei lati solo se ho un angolo convesso - if dAngBetween > 0 then - dLen1 = dLen1 - dTh2 / sin( dAngBetween) - dLen2 = dLen2 - dTh1 / sin( dAngBetween) + local dXOffest = 0 + if not bOnLoop then + local dDelta1 = dTh2 / sin( dAngBetween) + local dDelta2 = dTh1 / sin( dAngBetween) + if dAngBetween > 0 then + dLen1 = dLen1 - dDelta1 + dLen2 = dLen2 - dDelta2 + else + dLen1 = dLen1 + dDelta1 + dLen2 = dLen2 + dDelta2 + end end - return dLen1, dLen2 + return dLen1, dLen2, dXOffest end -local function ManageJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2) +local function ManageJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2, bOnLoop) --nJunctionType -- 1 TrimStart, 2 TrimEnd, 3Ang if nType == 1 or nType == 2 then - return TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2) + return TJunction(dAngBetween, dTh1, dTh2, nType, dLen1, dLen2, bOnLoop) elseif nType == 3 then - return AngleJunction(dAngBetween, dTh1, dTh2, dLen1, dLen2) + return AngleJunction(dAngBetween, dTh1, dTh2, dLen1, dLen2, bOnLoop) end end -local function CreateAdjustedPart( nLayOutloop, dLen, dH, dTh, dBeta1, dBeta2) +local function CreateAdjustedPart( nLayOutloop, dLen, dH, dBeta1, dBeta2) -- genero la regione piana del rettangolo deformato : -- dLen è la lunghezza del lato su cui si va ad agganciare il pezzo che sto creando, quindi è un dato fisso -- bisogna calcolare gli altri tre lati del quadrilatero -- dProj1 dProj2 -- __|_____________________________|__ - -- \ | | / | - -- \ | beta1 beta2 | / |dH - -- \ |/___________dLen________\| / | + -- \ / | + -- \ beta1 beta2 / |dH + -- \ /___________dLen__________\ / | -- beta 1 e beta 2 sono gli angoli alla base -- dLen1 e dLen2 sono le proiezioni delle diagonali sulla base maggiore -- beta 1 e beta 2 possono essere < 90 e quindi potrei avere anche un trapezio ribaltato, oppure un quasi parallelogramma - + if dBeta1 == nil then dBeta1 = 90 end + if dBeta2 == nil then dBeta2 = 90 end local dProj1 = dH * tan( dBeta1 - 90) local dProj2 = dH * tan( dBeta2 - 90) local pt1 = ORIG() local pt2 = Point3d(dLen,0,0) - local nLine1 = EgtLine( nLayOutloop, pt2, pt2) + local nLine1 = EgtLine( nLayOutloop, pt1, pt2) + EgtSetName(nLine1, "A1") local pt3 = Point3d(dLen + dProj2,dH,0) local nLine2 = EgtLine( nLayOutloop, pt2, pt3) - local pt4 = Point3d( dPorj1,dH,0) + EgtSetName(nLine2, "A2") + local pt4 = Point3d( dProj1,dH,0) local nLine3 = EgtLine( nLayOutloop, pt3, pt4) + EgtSetName(nLine3, "A3") local nLine4 = EgtLine( nLayOutloop, pt4, pt1) + EgtSetName(nLine4, "A4") + SetMachiningInfo(nLayOutloop, false) return {nLine1, nLine2, nLine3, nLine4} end @@ -764,17 +806,17 @@ function CMP_Draw(bPreview) -- PIANO POLLO local Pz_Top = CreatePartLayer( 'TopChicken') -- Creo il contorno esterno - local tbIdLoop = ImportOutLoop( FindLayers( Pz_Top), sPath .. 'TopChicken.nge') + local tbIdLoopTC = ImportOutLoop( FindLayers( Pz_Top), sPath .. 'TopChicken.nge') -- Creo il pezzo dato il contorno - CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoop, CMP.ST, false) + CreatePart( FindLayers( Pz_Top), 'TopChicken', tbIdLoopTC, CMP.ST, false) --local nJunctionType -- 1 TrimStart, 2 TrimEnd, 3Ang - local vtDirCurr = EgtSV( tbIdLoop[1], GDB_RT.GLOB) - local nPrev = #tbIdLoop - local vtDirPrev = EgtEV( tbIdLoop[nPrev], GDB_RT.GLOB) + 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( tbIdLoop[nNext], GDB_RT.GLOB) - local nTypePrev = EgtGetInfo(tbIdLoop[nPrev], 'AF', 'i') or 0 - local nTypeNext = EgtGetInfo(tbIdLoop[nNext], 'AF', 'i') or 0 + 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 dPairAngPrev = 0 local dPairAngNext = 0 local dPairAng = 0 @@ -782,6 +824,8 @@ function CMP_Draw(bPreview) local dLenPrev = EgtCurveLength(tbIdLoopTC[#tbIdLoopTC]) local dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) local tbPartsInfo = {} + local bOnLoop = false + local nJunctionType = 1 for i=1, #tbIdLoopTC do local tbInfo = {} local nType = EgtGetInfo(tbIdLoopTC[i], 'AF', 'i') or 0 @@ -800,69 +844,147 @@ function CMP_Draw(bPreview) -- 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 tbInfo.dPairAng = dPairAng - local nJunctionType = 3 + nJunctionType = 3 -- angle junction + bOnLoop = true + ----- caratteristiche forntalino dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) local PAng, NAng = GetPrevNextAng(tbIdLoopTC[i]) - local tbLayer = FindLayers(pz_A) -- calcolo l'angolo di sformo con il pezzo precedente - local dAng3d_2, _, dBeta_DX = CalcDraftAngle( vtDirPrev, vtDirCurr, dPairAngPrev, dPairAng, PAng) - tbInfo.AngBR = dBeta_DX - tbInfo.SideAngR = dAng3d_2 - dLenPrev, dLen = ManageJunction(PAng,CMP.ST, CMP.ST,nJunctionType, dLenPrev, dLen) + if nJunctionType == 3 then + local dSideAng_4, _, dBeta_DX = CalcDraftAngle( vtDirPrev, vtDirCurr, dPairAngPrev, dPairAng, PAng) + tbInfo.dAngBR = 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 + end + if not bOnLoop then + dLenPrev, dLen = ManageJunction(PAng,CMP.ST, CMP.ST,nJunctionType, dLenPrev, dLen) + end -- calcolo l'angolo di sformo con il pezzo successivo - local dAng3d_4, dBeta_SX, __ = CalcDraftAngle( vtDirCurr, vtDirNext, dPairAng, dPairAngNext, NAng) - tbInfo.AngBL = dBeta_SX - tbInfo.SideAngL = dAng3d_4 - dLen, dLenNext = ManageJunction(NAng, CMP.ST, CMP.ST, nJunctionType, dLen, dLenNext) + if nJunctionType == 3 then + local dSideAng_2, dBeta_SX, __ = CalcDraftAngle( vtDirCurr, vtDirNext, dPairAng, dPairAngNext, NAng) + tbInfo.dAngBL = 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 + end + if not bOnLoop then + dLen, dLenNext = ManageJunction(NAng, CMP.ST, CMP.ST, nJunctionType, dLen, dLenNext) + end tbInfo.dLen = dLen tbInfo.sDestRefOff = '0,0,-x' + tbInfo.sRefOff = '0,0,0' elseif nType == 1 then -- SPLASHTOP - local dH = 200 + 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 - local sNamePz = 'A'.. tostring(i)..'Splahtop' - local Pz_A = CreatePartLayer(sNamePz) - local dLen = EgtCurveLength(tbIdLoopTC[i]) + 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]) - -- local tbIdLoopTC, PAng = CreateSplashtop( FindLayers(Pz_A), 'OutLoop', {dLen, dH,0}, PAng, NAng, IsPrevSplashtop(tbIdLoop, i), IsNextSplashtop(tbIdLoop, i)) - -- CreatePart( FindLayers(Pz_A), sNamePz, tbIdLoopWF, CMP.ST, 0) - CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(i), 'R'..tostring(i), CMP.ST, '0,0,0') - CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, tostring(sin(PAng)*CMP.ST)..',0,-x') - SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(i), -1, 90, 1) + -- 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.sName] = tbInfo + tbPartsInfo[tbInfo.nId] = tbInfo + dLenPrev = EgtCurveLength(tbIdLoopTC[i]) + dLen = EgtCurveLength(tbIdLoopTC[nNext]) nPrev = i - nNext = i == #tbIdLoopTC and 1 or i + 1 + nNext = nNext == #tbIdLoopTC and 1 or nNext + 1 vtDirPrev = vtDirCurr vtDirCurr = vtDirNext vtDirNext = EgtSV(nNext, GDB_RT.GLOB) - dLenPrev = dLen - dLen = dLenNext + --dLenPrev = dLen + --dLen = dLenNext dLenNext = EgtCurveLength(tbIdLoopTC[nNext]) nTypePrev = nType nType = nTypeNext nTypeNext = EgtGetInfo(tbIdLoopTC[nNext], 'AF', 'i') or 0 end - for sNamePz, tbPart in pairs( tbPartsInfo) do - local nPart = EgtGetFirstNameInGroup(GDB_ID.ROOT, sNamePz) - if nPart then - local nEdge = string.sub(sNamePz, 6) - local tbLayer = FindLayers(nPart) - local tbIdLoop = CreateAdjustedPart( tbLayer['OutLoop'],tbPart.dLen, tbPart.dH, CMP.ST, tbPart.dAngBL, tbPart.dAngBR) - CreatePart(tbLayer,sNamePz,tbIdLoop,CMP.ST,false) - CreateReference( 'TopChicken', 'OutLoop', 'A'..tostring(nEdge), 'R'..tostring(nEdge), CMP.ST, tbPart.sDestRefOff) - CreateReference(sNamePz, 'OutLoop', 'A3', 'R3', CMP.ST, '0,0,0') - SetPairInfo(sNamePz, 'R3', 'TopChicken', 'R'..tostring(nEdge), -1, tbPart.dPairAng, 1) - SetSideAng(nPart, 'A2', tbPart.dSideAngR) - SetSideAng(nPart, 'A4', tbPart.dSideAngL) - end + for nPart, tbPart in pairs( tbPartsInfo) do + EgtOutLog(tostring(nPart)) + 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) + 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 end + --SaveMePlease() CreateLayerDimension() SetReference() @@ -882,7 +1004,7 @@ function CMP_Draw(bPreview) OrigData() end --EgtSaveFile(EgtGetStringFromIni( "Vein3D", "Vein3D_Dir", "", EgtGetIniFile()) ..'\\'.. "FOO.nge") - EgtSaveFile("D:\\Temp\\marmo\\Vein3D\\creazione_generica.nge") + EgtSaveFile("D:\\Temp\\marmo\\Vein3D\\piano_assemblato.nge") end end