diff --git a/EXE_GdbModifySurf.cpp b/EXE_GdbModifySurf.cpp index 715142b..85a5a05 100644 --- a/EXE_GdbModifySurf.cpp +++ b/EXE_GdbModifySurf.cpp @@ -367,6 +367,74 @@ ExeSurfFrRotateSimpleNoCollision( int nId1, int nId2, const Point3d& ptCen, doub return ( bOk && CAvSimpleSurfFrMove( *pSfr1, *pSfr2L).Rotate(ptCenL, dAngDeg)) ; } +//------------------------------------------------------------------------------- +static int +MySurfTmToTriangles( int nId, int& nCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // recupero la superficie TriMesh + const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nId)) ; + if ( pStm == nullptr) + return GDB_ID_NULL ; + // recupero il numero di triangoli + int nTria = pStm->GetTriangleCount() ; + // se ci sono più triangoli, li separo + if ( nTria > 1) { + // copio tutti triangoli + int nFirstId = GDB_ID_NULL ; + nCount = 0 ; + for ( int i = 0 ; i < pStm->GetTriangleSize() ; ++ i) { + ISurfTriMesh* pFac = pStm->CloneTriangle( i) ; + if ( pFac == nullptr) + continue ; + // inserisco la superficie nello stesso gruppo e nello stesso posto del GeomDB + int nNewId = pGeomDB->InsertGeoObj( GDB_ID_NULL, nId, GDB_BEFORE, pFac) ; + if ( nNewId == GDB_ID_NULL) + return GDB_ID_NULL ; + // copio gli attributi + if ( ! pGeomDB->CopyAttributes( nId, nNewId)) + return GDB_ID_NULL ; + // aggiorno contatori + if ( nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + ++ nCount ; + } + // elimino la superficie originale + pGeomDB->Erase( nId) ; + // restituisco risultati + return nFirstId ; + } + // non devo fare alcunché + nCount = 1 ; + return nId ; +} + +//------------------------------------------------------------------------------- +int +ExeSurfTmToTriangles( int nId, int* pnCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + // verifico sia una superficie trimesh + int nFirstId = GDB_ID_NULL ; + int nCount = 0 ; + if ( pGeomDB->GetGeoType( nId) == SRF_TRIMESH) { + nFirstId = MySurfTmToTriangles( nId, nCount) ; + } + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtSurfTmToTriangles(" + ToString( nId) + ")" + + " -- Id1=" + ToString( nFirstId) + ",Nbr=" + ToString( nCount) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultati + if ( pnCount != nullptr) + *pnCount = nCount ; + return nFirstId ; +} + //------------------------------------------------------------------------------- bool ExeSurfTmRemoveFacet( int nId, int nFacet) diff --git a/EgtExecutor.rc b/EgtExecutor.rc index e6409ab..4ed6e2b 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GdbModifySurf.cpp b/LUA_GdbModifySurf.cpp index 5f1732f..7c31fe9 100644 --- a/LUA_GdbModifySurf.cpp +++ b/LUA_GdbModifySurf.cpp @@ -123,6 +123,25 @@ LuaSurfFrOffset( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +static int +LuaSurfTmToTriangles( lua_State* L) +{ + // 1 parametro : nId + int nId ; + LuaCheckParam( L, 1, nId) + LuaClearStack( L) ; + // esplosione della trimesh in triangoli + int nCount ; + int nFirstId = ExeSurfTmToTriangles( nId, &nCount) ; + if ( nFirstId != GDB_ID_NULL) + LuaSetParam( L, nFirstId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + return 2 ; +} + //---------------------------------------------------------------------------- static int LuaSurfTmRemoveFacet( lua_State* L) @@ -338,6 +357,7 @@ LuaInstallGdbModifySurf( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrSubtract", LuaSurfFrSubtract) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrIntersect", LuaSurfFrIntersect) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfFrOffset", LuaSurfFrOffset) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmToTriangles", LuaSurfTmToTriangles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemoveFacet", LuaSurfTmRemoveFacet) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSwapFacets", LuaSurfTmSwapFacets) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmRemovePart", LuaSurfTmRemovePart) ;