diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 35df068..5ed30ce 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -926,8 +926,8 @@ local function GetFeatureInfoAndDependency( vProcSingleRot, Part) TailProc.Topology.sName = 'TailCut' HeadProc.AvailableStrategies = GetStrategies( HeadProc, Part.sAISetupConfig) TailProc.AvailableStrategies = GetStrategies( TailProc, Part.sAISetupConfig) - local PtSortedHead = BeamLib.GetSurfTmSortedVertices( HeadProc.id) - local PtSortedTail = BeamLib.GetSurfTmSortedVertices( TailProc.id) + local PtSortedHead = BeamLib.GetSortedVertices( HeadProc) + local PtSortedTail = BeamLib.GetSortedVertices( TailProc) return vProcSingleRot end diff --git a/LuaLibs/BeamLib.lua b/LuaLibs/BeamLib.lua index 47aaddf..99c03a8 100644 --- a/LuaLibs/BeamLib.lua +++ b/LuaLibs/BeamLib.lua @@ -517,71 +517,64 @@ function BeamLib.GetDirectionFromSCC( nSCC) end ------------------------------------------------------------------------------------------------------------- --- Funzione che restituisce una tabella con i punti ai vertici di una trimesh (se almeno 3), in globale --- ordinati partendo da quello ai valori minimi degli assi e i successivi secondo rotazione attorno a X+ -function BeamLib.GetSurfTmSortedVertices( idSurfTm) - -- se più di una faccia si esce subito - if not ( EgtSurfTmFacetCount( idSurfTm) == 1) then - return - end - - local VerticesIndex = EgtSurfTmGetAllVertInFacet( idSurfTm, 0) - local nVerticesCount = #VerticesIndex - - -- Una faccia deve avere almeno 3 vertici - if nVerticesCount < 3 then - return - end - - local Vertices = {} - local nFirstVertex - - -- 1. Popolamento tabella Vertices e ricerca del vertice di partenza - local dMinYZ = GEO.INFINITO - for i = 1, nVerticesCount do - Vertices[i] = {} - Vertices[i].ptVertex = EgtSurfTmGetVertex( idSurfTm, VerticesIndex[i], GDB_RT.GLOB) - - -- Circular indexing 1 based - Vertices[i].nNextIndex = (i % nVerticesCount) + 1 - Vertices[i].nPrevIndex = ((i - 2 + nVerticesCount) % nVerticesCount) + 1 - - -- il primo punto è quello con il totale di coordinate Y e Z più basso - if( ( Vertices[i].ptVertex:getY() + Vertices[i].ptVertex:getZ()) < dMinYZ) then - nFirstVertex = i - dMinYZ = Vertices[i].ptVertex:getY() + Vertices[i].ptVertex:getZ() - end - end - - -- se non trova il punto con Y+Z minima c'è qualcosa che non va: si esce - if not nFirstVertex then - return - end - - local vtN = EgtSurfTmFacetNormVersor( idSurfTm, 0, GDB_ID.ROOT) +-- Funzione che restituisce una tabella con i punti ai vertici della tabella, in globale +-- ordinati partendo da quello ai valori minimi degli assi e i successivi secondo rotazione destrorsa X+; +-- solo per Proc a 1 faccia +function BeamLib.GetSortedVertices( Proc) local PtVerticesSorted = {} - -- 2. Ordinamento in base alla normale X - table.insert( PtVerticesSorted, Vertices[nFirstVertex].ptVertex) + -- se più di una faccia si esce subito + if Proc.nFct > 1 then + return + end - local nCurrentIndex = nFirstVertex - -- Faccia verso destra (avanti nell'indice della mesh) - if vtN:getX() > GEO.EPS_SMALL then - for _ = 1, nVerticesCount - 1 do - nCurrentIndex = Vertices[nCurrentIndex].nNextIndex - table.insert( PtVerticesSorted, Vertices[nCurrentIndex].ptVertex) + local PtVertices = {} + local nFirstIndex + local dMinYZ = GEO.INFINITO + for i = 1, #Proc.Faces[1].Edges do + local Edge = Proc.Faces[1].Edges[i] + table.insert( PtVertices, Edge.ptStart) + if ( Edge.ptStart:getY() + Edge.ptStart:getZ() < dMinYZ) then + nFirstIndex = i + dMinYZ = Edge.ptStart:getY() + Edge.ptStart:getZ() end - -- Faccia verso sinistra (indietro nell'indice della mesh) + end + + table.insert( PtVerticesSorted, PtVertices[nFirstIndex]) + local nCurrentIndex = nFirstIndex + -- faccia che guarda verso X+, ordine ok + if Proc.Faces[1].vtN:getX() > GEO.EPS_SMALL then + for _ = 1, #PtVertices - 1 do + _, nCurrentIndex = BeamLib.GetAdjacentIndices( nCurrentIndex, #PtVertices) + table.insert( PtVerticesSorted, PtVertices[nCurrentIndex]) + end + -- faccia che guarda verso X-, ordine da invertire else - for _ = 1, nVerticesCount - 1 do - nCurrentIndex = Vertices[nCurrentIndex].nPrevIndex - table.insert( PtVerticesSorted, Vertices[nCurrentIndex].ptVertex) + for _ = 1, #PtVertices - 1 do + nCurrentIndex = BeamLib.GetAdjacentIndices( nCurrentIndex, #PtVertices) + table.insert( PtVerticesSorted, PtVertices[nCurrentIndex]) end end return PtVerticesSorted end +------------------------------------------------------------------------------------------------------------- +-- restituisce il precedente e prossimo indice 1-based, tenendo conto del massimo indice +function BeamLib.GetAdjacentIndices( nCurrentIndex, nMaxIndex) + local nPreviousIndex, nNextIndex + + if ( nCurrentIndex < 1) or ( nCurrentIndex > nMaxIndex) then + return + end + + -- circular indexing 1-based + nPreviousIndex = ((nCurrentIndex - 2 + nMaxIndex) % nMaxIndex) + 1 + nNextIndex = (nCurrentIndex % nMaxIndex) + 1 + + return nPreviousIndex, nNextIndex +end + ------------------------------------------------------------------------------------------------------------- -- Funzione per determinare se la faccia ha lati molto corti (trascurabili) ed è quindi approssimabile ad una 3 facce function BeamLib.Is3EdgesApprox( Proc, idFace, nAddGrpId)