diff --git a/EgtExchange.rc b/EgtExchange.rc index 312c6f6..8e1f662 100644 Binary files a/EgtExchange.rc and b/EgtExchange.rc differ diff --git a/Export3MF.cpp b/Export3MF.cpp index cfa8705..9981db7 100644 --- a/Export3MF.cpp +++ b/Export3MF.cpp @@ -82,7 +82,6 @@ Export3MF::Export( IGeomDB* pGDB, int nId, const string& sFile) return false ; } - // creo un iteratore PtrOwner pIter( CreateGdbIterator( pGDB)) ; if ( IsNull( pIter)) @@ -119,7 +118,7 @@ Export3MF::ExportObject( const IGdbIterator& iIter) if ( pGeoObj == nullptr) return true ; // se non è una superficie esco - if ( pGeoObj->GetType() != SRF_TRIMESH && pGeoObj->GetType() != SRF_FLATRGN) + if ( pGeoObj->GetType() != SRF_TRIMESH && pGeoObj->GetType() != SRF_FLATRGN) return true ; // recupero il riferimento globale dell'oggetto Frame3d frFrame ; @@ -225,16 +224,17 @@ Export3MF::ExportSTM( const std::string& sName, const IGeoObj* pGeoObj, const Fr int k = 0 ; for ( int i = 0 ; i < pSTM->GetTriangleSize() ; i++) { int nIdVert[3] ; + // se il triangolo non è valido passo al successivo if ( ! pSTM->GetTriangle( i, nIdVert)) - continue ; // se il triangolo non è valido passo al successivo - + continue ; + // assegno gli indici dei vertici vTriangles[k].m_Indices[0] = nIdVert[0] ; vTriangles[k].m_Indices[1] = nIdVert[1] ; vTriangles[k].m_Indices[2] = nIdVert[2] ; k ++ ; } - if ( vVertices.size() == 0 || vTriangles.size() == 0) { + if ( vVertices.size() == 0 || vTriangles.size() == 0) { LOG_ERROR( GetEExLogger(), ("Export3MF : surface \"" + sName + "\" is empty. Ignored.").c_str()) ; return true ; } diff --git a/Import3MF.cpp b/Import3MF.cpp index 6bde460..246f39f 100644 --- a/Import3MF.cpp +++ b/Import3MF.cpp @@ -222,6 +222,86 @@ Import3MF::ReadObject( const PObject pObj, ATTRVECTOR& vAttr, sTransform& sTrans bool Import3MF::ReadMesh( const Lib3MF_uint32& nId, ATTRVECTOR& vAttr, sTransform& sTransf) { + // Recupero puntatore alla mesh 3MF + PMeshObject pMesh = m_model->GetMeshObjectByID( nId) ; + if ( pMesh.get() == nullptr) + return false ; + + // Creo e inizializzo trimesh + PtrOwner pStm( CreateSurfTriMesh()) ; + if ( IsNull( pStm) || ! pStm->Init( 3, 1)) { + LOG_ERROR( GetEExLogger(), " Error reading 3MF mesh : ISurfTriMesh Create error") ; + return false ; + } + pStm->SetLinearTolerance( 10 * EPS_SMALL) ; + + // Ciclo sui vertici della mesh 3MF + for ( Lib3MF_uint32 i = 0 ; i < pMesh->GetVertexCount() ; i ++) { + // recupero le coordinate del vertice + sPosition pVertex = pMesh->GetVertex( i) ; + // applico la trasformazione + double x = 0.0, y = 0.0, z = 0.0 ; + for ( int k = 0 ; k < 3 ; k ++) { + x += pVertex.m_Coordinates[k] * sTransf.m_Fields[k][0] ; + y += pVertex.m_Coordinates[k] * sTransf.m_Fields[k][1] ; + z += pVertex.m_Coordinates[k] * sTransf.m_Fields[k][2] ; + } + x += sTransf.m_Fields[3][0] ; + y += sTransf.m_Fields[3][1] ; + z += sTransf.m_Fields[3][2] ; + // inserisco il vertice nella trimesh + if ( pStm->AddVertex( Point3d( x, y, z)) == SVT_NULL) { + LOG_ERROR( GetEExLogger(), " Error reading 3MF mesh : ISurfTriMesh AddVertex error") ; + return false ; + } + } + + // Ciclo sui triangoli della mesh 3MF + for ( Lib3MF_uint32 i = 0 ; i < pMesh->GetTriangleCount() ; i ++) { + // recupero gli indici dei vertici del triangolo + sTriangle tTrg = pMesh->GetTriangle( i) ; + int nIdV[3] = { int( tTrg.m_Indices[0]), int( tTrg.m_Indices[1]), int( tTrg.m_Indices[2])} ; + // se i vertici sono tutti diversi tra loro, inserisco il triangolo + if ( nIdV[0] != nIdV[1] && nIdV[0] != nIdV[2] && nIdV[1] != nIdV[2]) { + if ( pStm->AddTriangle( nIdV) == SVT_NULL) { + LOG_ERROR( GetEExLogger(), " Error reading 3MF mesh : ISurfTriMesh AddTriangle error") ; + return false ; + } + } + } + + // Aggiustamenti finali + if ( ! pStm->AdjustTopology()) { + LOG_ERROR( GetEExLogger(), " Error reading 3MF mesh : ISurfTriMesh AdjustTopology error") ; + return false ; + } + + // Inserimento nel DB geometrico + int nGeoId = m_pGDB->AddGeoObj( GDB_ID_NULL, m_nIdGroup, Release( pStm)) ; + if ( nGeoId == GDB_ID_NULL) { + LOG_ERROR( GetEExLogger(), " Error reading 3MF mesh : error adding GeoObject") ; + return false ; + } + + // colore + Lib3MF_uint32 pid, pindex ; + if ( pMesh->GetObjectLevelProperty( pid, pindex)) { + Color cCol ; + if ( FindColor( pid, pindex, cCol)) + m_pGDB->SetMaterial( nGeoId, cCol) ; + } + + // attributes + for ( size_t i = 0 ; i < vAttr.size() ; i++) { + if ( vAttr[i].first == "name") + m_pGDB->SetName( nGeoId, vAttr[i].second) ; + else + m_pGDB->SetInfo( nGeoId, vAttr[i].first, vAttr[i].second) ; + } + + return true ; + +#if 0 PMeshObject pMesh = m_model->GetMeshObjectByID( nId) ; StmFromTriangleSoup Stm ; @@ -292,6 +372,7 @@ Import3MF::ReadMesh( const Lib3MF_uint32& nId, ATTRVECTOR& vAttr, sTransform& sT } return true ; +#endif } //-----------------------------------------------------------------------------------