//---------------------------------------------------------------------------- // EgalTech 2020-2020 //---------------------------------------------------------------------------- // File : LUA_GdbGetSurf.cpp Data : 23.03.20 Versione : 2.2c3 // Contenuto : Funzioni di interrogazione delle superfici per LUA. // // // // Modifiche : 23.03.20 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "LUA.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkCurve.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkSurfTriMesh.h" #include "/EgtDev/Include/EGkLuaAux.h" using namespace std ; //---------------------------------------------------------------------------- static int LuaSurfArea( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero la sua area double dArea ; if ( ExeSurfArea( nId, dArea)) LuaSetParam( L, dArea) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfIsClosed( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // verifico se č superficie chiusa bool bOk = ExeSurfIsClosed( nId) ; LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfVolume( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il suo eventuale volume (se chiusa) double dVol ; if ( ExeSurfVolume( nId, dVol)) LuaSetParam( L, dVol) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrNormVersor( lua_State* L) { // 1 o 2 parametri : Id [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nRefId = nId ; LuaGetParam( L, 2, nRefId) ; LuaClearStack( L) ; // recupero il versore Vector3d vtNorm ; if ( ExeSurfFrNormVersor( nId, nRefId, vtNorm)) LuaSetParam( L, vtNorm) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrGrossArea( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero la sua area senza eventuali buchi double dArea ; if ( ExeSurfFrGrossArea( nId, dArea)) LuaSetParam( L, dArea) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrChunkCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di componenti connessi (chunk) della regione int nNbr = ExeSurfFrChunkCount( nId) ; LuaSetParam( L, nNbr) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrChunkSimpleClassify( lua_State* L) { // 4 o 5 parametri : Id1, Chunk1, Id2, Chunk2 [, dToler] int nId1 ; LuaCheckParam( L, 1, nId1) int nChunk1 ; LuaCheckParam( L, 2, nChunk1) int nId2 ; LuaCheckParam( L, 3, nId2) int nChunk2 ; LuaCheckParam( L, 4, nChunk2) double dToler = 0 ; LuaGetParam( L, 5, dToler) ; LuaClearStack( L) ; // classifico il chunk della prima regione rispetto a quello della seconda int nClass = ExeSurfFrChunkSimpleClassify( nId1, nChunk1, nId2, nChunk2, dToler) ; LuaSetParam( L, nClass) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrTestExternal( lua_State* L) { // 2 o 3 parametri : Id1, Id2 [, dMinDist] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) double dMinDist = 0 ; LuaGetParam( L, 3, dMinDist) ; LuaClearStack( L) ; // verifico se le due regioni sono esterne con distanza superiore al minimo bool bOk = ExeSurfFrTestExternal( nId1, nId2, dMinDist) ; LuaSetParam( L, bOk) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaExtractSurfFrChunkLoops( lua_State* L) { // 3 parametri : nId, nChunk, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nChunk ; LuaCheckParam( L, 2, nChunk) int nDestGrpId ; LuaCheckParam( L, 3, nDestGrpId) LuaClearStack( L) ; // recupero i contorni del chunk della regione int nCount = 0 ; int nNewId = ExeExtractSurfFrChunkLoops( nId, nChunk, nDestGrpId, &nCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfFrMoveSimpleNoCollision( lua_State* L) { // 3 o 4 parametri : nId1, nId2, vtMove [, nRefType] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) Vector3d vtMove ; LuaCheckParam( L, 3, vtMove) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 4, nRefType) ; LuaClearStack( L) ; // verifico quale č la massima traslazione possibile double dLen = vtMove.Len() ; Vector3d vtDir = ( dLen > EPS_SMALL ? vtMove / dLen : V_NULL) ; bool bOk = ExeSurfFrMoveSimpleNoCollision( nId1, nId2, vtDir, dLen, nRefType) ; // restituisco il risultato if ( bOk) LuaSetParam( L, dLen) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfFrRotateSimpleNoCollision( lua_State* L) { // 4 o 5 parametri : nId1, nId2, ptCen, dAngDeg [, nRefType] int nId1 ; LuaCheckParam( L, 1, nId1) int nId2 ; LuaCheckParam( L, 2, nId2) Point3d ptCen ; LuaCheckParam( L, 3, ptCen) double dAngDeg ; LuaCheckParam( L, 4, dAngDeg) int nRefType = RTY_DEFAULT ; LuaGetParam( L, 5, nRefType) ; LuaClearStack( L) ; // verifico quale č la massima (in valore assoluto) rotazione possibile bool bOk = ExeSurfFrRotateSimpleNoCollision( nId1, nId2, ptCen, dAngDeg, nRefType) ; // restituisco il risultato if ( bOk) LuaSetParam( L, dAngDeg) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmVertexCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di vertici della superficie trimesh int nNbr = ExeSurfTmVertexCount( nId) ; LuaSetParam( L, nNbr) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di facce della superficie trimesh int nNbr = ExeSurfTmFacetCount( nId) ; LuaSetParam( L, nNbr) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmPartCount( lua_State* L) { // 1 parametro : Id int nId ; LuaCheckParam( L, 1, nId) LuaClearStack( L) ; // recupero il numero di parti della superficie trimesh int nParts = ExeSurfTmPartCount( nId) ; if ( nParts >= 0) LuaSetParam( L, nParts) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetVertex( lua_State* L) { // 2 o 3 parametri : Id, nVert, [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nVert ; LuaCheckParam( L, 2, nVert) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero il vertice di indice dato (0-based) Point3d ptVert ; bool bOk = ExeSurfTmGetVertex( nId, nVert, nRefId, ptVert) ; if ( bOk) LuaSetParam( L, ptVert) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetNearestVertex( lua_State* L) { // 2 o 3 parametri : Id, ptNear [, nRefId] int nId ; LuaCheckParam( L, 1, nId) Point3d ptNear ; LuaCheckParam( L, 2, ptNear) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero il vertice pių vicino della superficie int nVert ; Point3d ptVert ; bool bOk = ExeSurfTmGetNearestVertex( nId, ptNear, nRefId, nVert, ptVert) ; if ( bOk) { LuaSetParam( L, nVert) ; LuaSetParam( L, ptVert) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetFromTria( lua_State* L) { // 2 parametri : nId, nTria int nId ; LuaCheckParam( L, 1, nId) int nTria ; LuaCheckParam( L, 2, nTria) LuaClearStack( L) ; // recupero l'indice della faccia cui appartiene il triangolo della superficie int nFacet = ExeSurfTmFacetFromTria( nId, nTria) ; // restituisco il risultato if ( nFacet != SVT_NULL) LuaSetParam( L, nFacet) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetAllVertInFacet( lua_State* L) { // 2 parametri : nId, nFacet int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) LuaClearStack( L) ; // recupero l'elenco dei vertici nella faccia INTVECTOR vVert ; bool bOk = ExeSurfTmGetAllVertInFacet( nId, nFacet, vVert) ; // restituisco il risultato if ( bOk) LuaSetParam( L, vVert) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetFacetBBox( lua_State* L) { // 3 parametri : nId, nFacet, nFlag int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nFlag ; LuaCheckParam( L, 3, nFlag) LuaClearStack( L) ; // recupero il bounding box della faccia in locale BBox3d b3Box ; bool bOk = ExeSurfTmGetFacetBBox( nId, nFacet, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetFacetBBoxGlob( lua_State* L) { // 3 parametri : nId, nFacet, nFlag int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nFlag ; LuaCheckParam( L, 3, nFlag) LuaClearStack( L) ; // recupero il bounding box della faccia in globale BBox3d b3Box ; bool bOk = ExeSurfTmGetFacetBBoxGlob( nId, nFacet, nFlag, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetFacetBBoxRef( lua_State* L) { // 4 parametri : nId, nFacet, nFlag, frRef int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nFlag ; LuaCheckParam( L, 3, nFlag) Frame3d frRef ; LuaCheckParam( L, 4, frRef) LuaClearStack( L) ; // recupero il bounding box della faccia nel riferimento indicato BBox3d b3Box ; bool bOk = ExeSurfTmGetFacetBBoxRef( nId, nFacet, nFlag, frRef, b3Box) ; // restituisco il risultato if ( bOk) LuaSetParam( L, b3Box) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetAdjacencies( lua_State* L) { // 2 parametri : nId, nFacet int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) LuaClearStack( L) ; // recupero le adiacenze della faccetta della superficie INTMATRIX vAdj ; bool bOk = ExeSurfTmFacetAdjacencies( nId, nFacet, vAdj) ; // restituisco il risultato if ( bOk) LuaSetParam( L, vAdj) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetNearestEndPoint( lua_State* L) { // 3 o 4 parametri : Id, nFacet, ptNear [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) Point3d ptNear ; LuaCheckParam( L, 3, ptNear) int nRefId = nId ; LuaGetParam( L, 4, nRefId) ; LuaClearStack( L) ; // recupero il punto End pių vicino della faccia della superficie trimesh Point3d ptEnd ; Vector3d vtN ; if ( ExeSurfTmFacetNearestEndPoint( nId, nFacet, ptNear, nRefId, ptEnd, vtN)) { LuaSetParam( L, ptEnd) ; LuaSetParam( L, vtN) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetNearestMidPoint( lua_State* L) { // 3 o 4 parametri : Id, nFacet, ptNear [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) Point3d ptNear ; LuaCheckParam( L, 3, ptNear) int nRefId = nId ; LuaGetParam( L, 4, nRefId) ; LuaClearStack( L) ; // recupero il punto Mid pių vicino della faccia della superficie trimesh Point3d ptMid ; Vector3d vtN ; if ( ExeSurfTmFacetNearestMidPoint( nId, nFacet, ptNear, nRefId, ptMid, vtN)) { LuaSetParam( L, ptMid) ; LuaSetParam( L, vtN) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetCenter( lua_State* L) { // 2 o 3 parametri : Id, nFacet [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero il centro della faccia della superficie trimesh Point3d ptCen ; Vector3d vtN ; if ( ExeSurfTmFacetCenter( nId, nFacet, nRefId, ptCen, vtN)) { LuaSetParam( L, ptCen) ; LuaSetParam( L, vtN) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetNormVersor( lua_State* L) { // 2 o 3 parametri : Id, nFacet [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero la normale della faccia della superficie trimesh Vector3d vtNorm ; if ( ExeSurfTmFacetNormVersor( nId, nFacet, nRefId, vtNorm)) LuaSetParam( L, vtNorm) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetMinAreaRectangle( lua_State* L) { // 2 o 3 parametri : Id, nFacet [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nRefId = nId ; LuaGetParam( L, 3, nRefId) ; LuaClearStack( L) ; // recupero il rettangolo di minima area della faccia della superficie trimesh Frame3d frRect ; double dDimX, dDimY ; if ( ExeSurfTmFacetMinAreaRectangle( nId, nFacet, nRefId, frRect, dDimX, dDimY)) { LuaSetParam( L, frRect) ; LuaSetParam( L, dDimX) ; LuaSetParam( L, dDimY) ; return 3 ; } else { LuaSetParam( L) ; return 1 ; } } //---------------------------------------------------------------------------- static int LuaSurfTmFacetElevationInBBox( lua_State* L) { // 3 o 4 o 5 parametri : Id, nFacet, b3Box [, bAcceptOutFacet] [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) BBox3d b3Box ; LuaCheckParam( L, 3, b3Box) bool bAcceptOutFacet = false ; int nRefId = nId ; if ( ! LuaGetParam( L, 4, nRefId)) { LuaGetParam( L, 4, bAcceptOutFacet) ; LuaGetParam( L, 5, nRefId) ; } LuaClearStack( L) ; // calcolo elevazione double dElev ; bool bOk = ExeSurfTmFacetElevationInBBox( nId, nFacet, b3Box, bAcceptOutFacet, nRefId, dElev) ; if ( bOk) LuaSetParam( L, dElev) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetElevationInClosedSurfTm( lua_State* L) { // 3 o 4 parametri : nFacetStmId, nFacet, nClosedStmId [, bAcceptOutFacet] int nFacetStmId ; LuaCheckParam( L, 1, nFacetStmId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nClosedStmId ; LuaCheckParam( L, 3, nClosedStmId) bool bAcceptOutFacet = false ; LuaGetParam( L, 4, bAcceptOutFacet) ; LuaClearStack( L) ; // calcolo elevazione double dElev ; bool bOk = ExeSurfTmFacetElevationInClosedSurfTm( nFacetStmId, nFacet, nClosedStmId, bAcceptOutFacet, dElev) ; if ( bOk) LuaSetParam( L, dElev) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetOppositeSide( lua_State* L) { // 3 o 4 parametri : Id, nFacet, vtDir [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) Vector3d vtDir ; LuaCheckParam( L, 3, vtDir) int nRefId = nId ; LuaGetParam( L, 4, nRefId) ; LuaClearStack( L) ; // recupero i punti estremi della parte di faccia opposta alla direzione Point3d ptP1, ptPm, ptP2 ; Vector3d vtIn1, vtOut2 ; double dLen, dWidth ; if ( ExeSurfTmFacetOppositeSideEx( nId, nFacet, vtDir, nRefId, ptP1, ptPm, ptP2, vtIn1, vtOut2, dLen, dWidth)) { LuaSetParam( L, ptP1) ; LuaSetParam( L, ptPm) ; LuaSetParam( L, ptP2) ; LuaSetParam( L, vtIn1) ; LuaSetParam( L, vtOut2) ; LuaSetParam( L, dLen) ; LuaSetParam( L, dWidth) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; } return 7 ; } //---------------------------------------------------------------------------- static int LuaSurfTmFacetsContact( lua_State* L) { // 3 o 4 parametri : Id, nF1, nF2 [, nRefId] int nId ; LuaCheckParam( L, 1, nId) int nF1 ; LuaCheckParam( L, 2, nF1) int nF2 ; LuaCheckParam( L, 3, nF2) int nRefId = nId ; LuaGetParam( L, 4, nRefId) ; LuaClearStack( L) ; // recupero i dati di contatto tra le due facce bool bAdjac ; Point3d ptP1, ptP2 ; double dAng = 0 ; if ( ExeSurfTmFacetsContact( nId, nF1, nF2, nRefId, bAdjac, ptP1, ptP2, dAng)) { LuaSetParam( L, bAdjac) ; LuaSetParam( L, ptP1) ; LuaSetParam( L, ptP2) ; LuaSetParam( L, dAng) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; } return 4 ; } //---------------------------------------------------------------------------- static int LuaExtractSurfTmLoops( lua_State* L) { // 2 parametri : nId, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nDestGrpId ; LuaCheckParam( L, 2, nDestGrpId) LuaClearStack( L) ; // recupero i contorni della superficie int nCount = 0 ; int nNewId = ExeExtractSurfTmLoops( nId, nDestGrpId, &nCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- static int LuaGetSurfTmSilhouette( lua_State* L) { // 4 o 5 o 6 parametri : nId, vtDir, dToler, nDestGrpId [, nRefType [, bAllTria]] int nId ; LuaCheckParam( L, 1, nId) Vector3d vtDir ; LuaCheckParam( L, 2, vtDir) double dToler ; LuaCheckParam( L, 3, dToler) int nDestGrpId ; LuaCheckParam( L, 4, nDestGrpId) int nRefType = RTY_DEFAULT ; bool bAllTria = false ; if ( LuaGetParam( L, 5, nRefType)) LuaGetParam( L, 6, bAllTria) ; else LuaGetParam( L, 5, bAllTria) ; LuaClearStack( L) ; // recupero i contorni della superficie int nCount = 0 ; int nNewId = ExeGetSurfTmSilhouette( nId, vtDir, dToler, nDestGrpId, nRefType, &nCount, bAllTria) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- static int LuaExtractSurfTmFacetLoops( lua_State* L) { // 3 parametri : nId, nFacet, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nDestGrpId ; LuaCheckParam( L, 3, nDestGrpId) LuaClearStack( L) ; // recupero i contorni della faccetta della superficie int nCount = 0 ; int nNewId = ExeExtractSurfTmFacetLoops( nId, nFacet, nDestGrpId, &nCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //---------------------------------------------------------------------------- static int LuaCopySurfTmFacet( lua_State* L) { // 3 parametri : nId, nFacet, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nFacet ; LuaCheckParam( L, 2, nFacet) int nDestGrpId ; LuaCheckParam( L, 3, nDestGrpId) LuaClearStack( L) ; // copio la faccia della superficie nel gruppo indicato int nNewId = ExeCopySurfTmFacet( nId, nFacet, nDestGrpId) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfTmGetEdges( lua_State* L) { // 2 o 3 parametri : nId, nDestGrpId [, bSmoothAng] int nId ; LuaCheckParam( L, 1, nId) int nDestGrpId ; LuaCheckParam( L, 2, nDestGrpId) bool bSmoothAng = true ; LuaGetParam( L, 3, bSmoothAng) ; LuaClearStack( L) ; // calcolo gli spigoli della superficie int nCount ; int nFirstId = ExeSurfTmGetEdges( nId, nDestGrpId, bSmoothAng, &nCount) ; // restituisco il risultato if ( nFirstId != GDB_ID_NULL || nCount != -1) { LuaSetParam( L, nFirstId) ; LuaSetParam( L, nCount) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; } return 2 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetPoint( lua_State* L) { // 3 o 4 parametri : nSurfId, dU, dV [, nRefId] int nSurfId ; LuaCheckParam( L, 1, nSurfId) double dU ; LuaCheckParam( L, 2, dU) double dV ; LuaCheckParam( L, 3, dV) int nRefId = nSurfId ; LuaGetParam( L, 4, nRefId) ; LuaClearStack( L) ; // recupero i dati del punto Point3d ptP ; bool bOk = ExeSurfBezierGetPoint( nSurfId, dU, dV, nRefId, ptP) ; if ( bOk) LuaSetParam( L, ptP) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetPointD1( lua_State* L) { // 5 o 6 parametri : nSurfId, dU, dV, nUsd, nVsd [, nRefId] int nSurfId ; LuaCheckParam( L, 1, nSurfId) double dU ; LuaCheckParam( L, 2, dU) double dV ; LuaCheckParam( L, 3, dV) int nUsd ; LuaCheckParam( L, 4, nUsd) int nVsd ; LuaCheckParam( L, 5, nVsd) int nRefId = nSurfId ; LuaGetParam( L, 6, nRefId) ; LuaClearStack( L) ; // recupero i dati del punto Point3d ptP ; Vector3d vtDerU, vtDerV ; bool bOk = ExeSurfBezierGetPointD1( nSurfId, dU, dV, nUsd, nVsd, nRefId, ptP, vtDerU, vtDerV) ; if ( bOk) { LuaSetParam( L, ptP) ; LuaSetParam( L, vtDerU) ; LuaSetParam( L, vtDerV) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; } return 3 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetPointNrmD1( lua_State* L) { // 5 o 6 parametri : nSurfId, dU, dV, nUsd, nVsd [, nRefId] int nSurfId ; LuaCheckParam( L, 1, nSurfId) double dU ; LuaCheckParam( L, 2, dU) double dV ; LuaCheckParam( L, 3, dV) int nUsd ; LuaCheckParam( L, 4, nUsd) int nVsd ; LuaCheckParam( L, 5, nVsd) int nRefId = nSurfId ; LuaGetParam( L, 6, nRefId) ; LuaClearStack( L) ; // recupero i dati del punto Point3d ptP ; Vector3d vtN ; Vector3d vtDerU, vtDerV ; bool bOk = ExeSurfBezierGetPointNrmD1( nSurfId, dU, dV, nUsd, nVsd, nRefId, ptP, vtN, vtDerU, vtDerV) ; if ( bOk) { LuaSetParam( L, ptP) ; LuaSetParam( L, vtN) ; LuaSetParam( L, vtDerU) ; LuaSetParam( L, vtDerV) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; } return 4 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetCurveU( lua_State* L) { // 3 parametri : nSurfId, dV, nDestGrp int nSurfId ; LuaCheckParam( L, 1, nSurfId) double dV ; LuaCheckParam( L, 2, dV) int nDestGrp ; LuaCheckParam( L, 3, nDestGrp) LuaClearStack( L) ; // recupero la curva int nNewId = ExeSurfBezierGetCurveU( nSurfId, dV, nDestGrp) ; if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetCurveV( lua_State* L) { // 3 parametri : nSurfId, dU, nDestGrp int nSurfId ; LuaCheckParam( L, 1, nSurfId) double dU ; LuaCheckParam( L, 2,dU) int nDestGrp ; LuaCheckParam( L, 3, nDestGrp) LuaClearStack( L) ; // recupero la curva int nNewId = ExeSurfBezierGetCurveV( nSurfId, dU, nDestGrp) ; if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetInfo( lua_State* L) { // 1 parametro : nSurfId int nSurfId ; LuaCheckParam( L, 1, nSurfId) LuaClearStack( L) ; // recupero la curva int nDegU, nDegV ; int nSpanU, nSpanV ; bool bIsRat, bTrimmed ; bool bOk = ExeSurfBezierGetInfo( nSurfId, nDegU, nDegV, nSpanU, nSpanV, bIsRat, bTrimmed) ; if ( bOk) { LuaSetParam( L, nDegU) ; LuaSetParam( L, nDegV) ; LuaSetParam( L, nSpanU) ; LuaSetParam( L, nSpanV) ; LuaSetParam( L, bIsRat) ; LuaSetParam( L, bTrimmed) ; } else { LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; LuaSetParam( L) ; } return 6 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetControlCurveU( lua_State* L) { // 3 parametri : nSurfId, nIndV, nDestGrp int nSurfId ; LuaCheckParam( L, 1, nSurfId) int nIndV ; LuaCheckParam( L, 2, nIndV) int nDestGrp ; LuaCheckParam( L, 3, nDestGrp) LuaClearStack( L) ; // recupero la curva int nNewId = ExeSurfBezierGetControlCurveU( nSurfId, nIndV, nDestGrp) ; if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaSurfBezierGetControlCurveV( lua_State* L) { // 3 parametri : nSurfId, nIndU, nDestGrp int nSurfId ; LuaCheckParam( L, 1, nSurfId) int nIndU ; LuaCheckParam( L, 2, nIndU) int nDestGrp ; LuaCheckParam( L, 3, nDestGrp) LuaClearStack( L) ; // recupero la curva int nNewId = ExeSurfBezierGetControlCurveV( nSurfId, nIndU, nDestGrp) ; if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; return 1 ; } //---------------------------------------------------------------------------- static int LuaExtractSurfBezierLoops( lua_State* L) { // 2 parametri : nId, nDestGrpId int nId ; LuaCheckParam( L, 1, nId) int nDestGrpId ; LuaCheckParam( L, 2, nDestGrpId) LuaClearStack( L) ; // recupero i contorni della superficie int nCount = 0 ; int nNewId = ExeExtractSurfBezierLoops( nId, nDestGrpId, &nCount) ; // restituisco il risultato if ( nNewId != GDB_ID_NULL) LuaSetParam( L, nNewId) ; else LuaSetParam( L) ; LuaSetParam( L, nCount) ; return 2 ; } //------------------------------------------------------------------------------- bool LuaInstallGdbGetSurf( LuaMgr& luaMgr) { bool bOk = ( &luaMgr != nullptr) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfArea", LuaSurfArea) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfIsClosed", LuaSurfIsClosed) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfVolume", LuaSurfVolume) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrNormVersor", LuaSurfFrNormVersor) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrGrossArea", LuaSurfFrGrossArea) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrChunkCount", LuaSurfFrChunkCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrChunkSimpleClassify", LuaSurfFrChunkSimpleClassify) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrTestExternal", LuaSurfFrTestExternal) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfFrChunkLoops", LuaExtractSurfFrChunkLoops) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrMoveSimpleNoCollision", LuaSurfFrMoveSimpleNoCollision) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrRotateSimpleNoCollision", LuaSurfFrRotateSimpleNoCollision) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmVertexCount", LuaSurfTmVertexCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCount", LuaSurfTmFacetCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmPartCount", LuaSurfTmPartCount) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetVertex", LuaSurfTmGetVertex) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetNearestVertex", LuaSurfTmGetNearestVertex) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetFromTria", LuaSurfTmFacetFromTria) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetAllVertInFacet", LuaSurfTmGetAllVertInFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBox", LuaSurfTmGetFacetBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBoxGlob", LuaSurfTmGetFacetBBoxGlob) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetFacetBBoxRef", LuaSurfTmGetFacetBBoxRef) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetAdjacencies", LuaSurfTmFacetAdjacencies) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestEndPoint", LuaSurfTmFacetNearestEndPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNearestMidPoint", LuaSurfTmFacetNearestMidPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetCenter", LuaSurfTmFacetCenter) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetNormVersor", LuaSurfTmFacetNormVersor) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetMinAreaRectangle", LuaSurfTmFacetMinAreaRectangle) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetElevationInBBox", LuaSurfTmFacetElevationInBBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetElevationInClosedSurfTm", LuaSurfTmFacetElevationInClosedSurfTm) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetOppositeSide", LuaSurfTmFacetOppositeSide) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmFacetsContact", LuaSurfTmFacetsContact) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmLoops", LuaExtractSurfTmLoops) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetSurfTmSilhouette", LuaGetSurfTmSilhouette) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfTmFacetLoops", LuaExtractSurfTmFacetLoops) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopySurfTmFacet", LuaCopySurfTmFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmGetEdges", LuaSurfTmGetEdges) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPoint", LuaSurfBezierGetPoint) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPointD1", LuaSurfBezierGetPointD1) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetPointNrmD1", LuaSurfBezierGetPointNrmD1) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetCurveU", LuaSurfBezierGetCurveU) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetCurveV", LuaSurfBezierGetCurveV) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetInfo", LuaSurfBezierGetInfo) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetControlCurveU", LuaSurfBezierGetControlCurveU) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfBezierGetControlCurveV", LuaSurfBezierGetControlCurveV) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExtractSurfBezierLoops", LuaExtractSurfBezierLoops) ; return bOk ; }