Files
Carlo Baronchelli 741791a0e4 Copia locale Iniziale
2022-05-19 16:04:07 +02:00

111 lines
3.2 KiB
Lua

-- 2021/03/18
-- Parti solide gestite come travi BTL
-- Intestazioni
require( 'EgtBase')
_ENV = EgtProtectGlobal()
EgtEnableDebug( false)
-- calcolo del riferimento del minimo box
local function SolidMinBox( nId)
-- ciclo sulle facce della superficie
local nFacCnt = EgtSurfTmFacetCount( nId)
local dVolMin
local refMin
local b3Min
for i = 1, nFacCnt do
local refFace = EgtSurfTmFacetMinAreaRectangle( nId, i - 1, GDB_ID.ROOT)
if refFace then
local b3Box = EgtGetBBoxRef( nId, GDB_BB.STANDARD, refFace)
if b3Box then
local dVol = b3Box:getDimX() * b3Box:getDimY() * b3Box:getDimZ()
if not dVolMin or dVol < dVolMin then
dVolMin = dVol
refMin = refFace
b3Min = b3Box
end
end
end
end
return refMin, b3Min
end
-- Trasformazione di un oggetto solido
local function ProcessOneSolid( nId1, ptPos)
-- Calcolo il riferimento del suo box minimo
local refMin, b3Min = SolidMinBox( nId1)
if not refMin then
EgtOutText( 'Errore nel calcolo del box minimo della superficie')
EgtPause( 1000)
return
end
-- Modifico il riferimento in modo che X sia sul più lungo, quindi Z e poi Y
local dDimX = b3Min:getDimX()
local dDimY = b3Min:getDimY()
local dDimZ = b3Min:getDimZ()
if dDimX < dDimY then
refMin:rotate( refMin:getOrigin(), refMin:getVersZ(), 90)
dDimX, dDimY = dDimY, dDimX
end
if dDimX < dDimZ then
refMin:rotate( refMin:getOrigin(), refMin:getVersY(), 90)
dDimX, dDimZ = dDimZ, dDimX
end
if dDimZ < dDimY then
refMin:rotate( refMin:getOrigin(), refMin:getVersX(), 90)
dDimZ, dDimY = dDimY, dDimZ
end
-- Porto il solido nell'origine
refMin:invert()
EgtTransform( nId1, refMin, GDB_RT.GLOB)
local b3Box = EgtGetBBoxGlob( nId1, GDB_BB.STANDARD)
local vtMove = ORIG() - b3Box:getMin()
EgtMove( nId1, vtMove, GDB_RT.GLOB)
b3Box:move( vtMove)
-- Creo un nuovo pezzo
local PzId = EgtGroup( GDB_ID.ROOT)
local PartId = EgtGroup( PzId)
EgtSetName( PartId or GDB_ID.NULL, 'Part')
local BoxId = EgtGroup( PzId)
EgtSetName( BoxId or GDB_ID.NULL, 'Box')
local ProcId = EgtGroup( PzId)
EgtSetName( ProcId or GDB_ID.NULL, 'Proc')
-- Sposto il solido nel pezzo
EgtRelocate( nId1, ProcId)
-- Calcolo il box
local SboxId = EgtSurfTmBBox( BoxId, b3Box)
EgtSetColor( SboxId or GDB_ID.NULL, {206,199,113,30})
-- Assegno il nome
local sText = string.format( 'Part%d %.0f x %.0f x %.0f', PzId, dDimX, dDimY, dDimZ)
local ptText = b3Box:getCenter() + Vector3d( 0, 0, dDimZ / 2)
local TxtId = EgtTextAdv( PartId, ptText, 0, sText, '', 100, 'S', dDimY / 4, 1, 0, GDB_TI.MC)
EgtSetColor( TxtId or GDB_ID.NULL, {0,0,0,100})
EgtSetName( PzId or GDB_ID.NULL, sText)
-- Sposto il pezzo
if ptPos then
EgtMove( PzId, ptPos - ORIG())
end
EgtDraw()
end
-------------------------------------------------------------------
local ptIns = ORIG()
local nId = EgtGetFirstSelectedObj()
while nId do
EgtDeselectObj( nId)
ProcessOneSolid( nId, ptIns)
ptIns = ptIns + Vector3d( 0, 300, 0)
nId = EgtGetFirstSelectedObj()
end