diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp
index 524f54400..462c30c76 100644
--- a/code/D3MFExporter.cpp
+++ b/code/D3MFExporter.cpp
@@ -104,46 +104,54 @@ bool D3MFExporter::exportArchive( const char *file ) {
if ( nullptr == m_zipArchive ) {
return false;
}
- ok |= exportRelations();
ok |= export3DModel();
+ ok |= exportRelations();
+
+ zip_close( m_zipArchive );
+ m_zipArchive = nullptr;
return ok;
}
bool D3MFExporter::exportRelations() {
- mOutput.clear();
+ mRelOutput.clear();
- mOutput << "\n";
- mOutput << "\n";
+ mRelOutput << "\n";
+ mRelOutput << "\n";
for ( size_t i = 0; i < mRelations.size(); ++i ) {
- mOutput << "target << " ";
- mOutput << "id=\"" << mRelations[i]->id << " ";
- mOutput << "Type=\"" << mRelations[ i ]->type << "/>\n";
+ mRelOutput << "target << "\" ";
+ mRelOutput << "id=\"" << mRelations[i]->id << "\" ";
+ mRelOutput << "Type=\"" << mRelations[ i ]->type << "/>";
+ mRelOutput << std::endl;
}
- mOutput << "\n";
+ mRelOutput << "";
+ mRelOutput << std::endl;
writeRelInfoToFile( "_rels", ".rels" );
+ mRelOutput.flush();
return true;
}
bool D3MFExporter::export3DModel() {
- mOutput.clear();
+ mModelOutput.clear();
writeHeader();
- mOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
+ mModelOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
<< "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
- << "\n";
- mOutput << "<" << XmlTag::resources << ">\n";
+ << std::endl;
+ mModelOutput << "<" << XmlTag::resources << ">";
+ mModelOutput << std::endl;
writeObjects();
- mOutput << "" << XmlTag::resources << ">\n";
+ mModelOutput << "" << XmlTag::resources << ">";
+ mModelOutput << std::endl;
writeBuild();
- mOutput << "" << XmlTag::model << ">\n";
+ mModelOutput << "" << XmlTag::model << ">\n";
OpcPackageRelationship *info = new OpcPackageRelationship;
info->id = mArchiveName;
@@ -151,15 +159,15 @@ bool D3MFExporter::export3DModel() {
info->type = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
mRelations.push_back( info );
- writeModelToArchive( "3D", mArchiveName );
-
- mOutput.clear();
+ writeModelToArchive( "3D", "3DModel.model" );
+ mModelOutput.flush();
return true;
}
void D3MFExporter::writeHeader() {
- mOutput << "" << "\n";
+ mModelOutput << "";
+ mModelOutput << std::endl;
}
void D3MFExporter::writeObjects() {
@@ -173,7 +181,8 @@ void D3MFExporter::writeObjects() {
if ( nullptr == currentNode ) {
continue;
}
- mOutput << "<" << XmlTag::object << " id=\"" << currentNode->mName.C_Str() << "\" type=\"model\">\n";
+ mModelOutput << "<" << XmlTag::object << " id=\"" << currentNode->mName.C_Str() << "\" type=\"model\">";
+ mModelOutput << std::endl;
for ( unsigned int j = 0; j < currentNode->mNumMeshes; ++j ) {
aiMesh *currentMesh = mScene->mMeshes[ currentNode->mMeshes[ j ] ];
if ( nullptr == currentMesh ) {
@@ -183,7 +192,8 @@ void D3MFExporter::writeObjects() {
}
mBuildItems.push_back( i );
- mOutput << "" << XmlTag::object << ">\n";
+ mModelOutput << "" << XmlTag::object << ">";
+ mModelOutput << std::endl;
}
}
@@ -192,19 +202,20 @@ void D3MFExporter::writeMesh( aiMesh *mesh ) {
return;
}
- mOutput << "<" << XmlTag::mesh << ">\n";
- mOutput << "<" << XmlTag::vertices << ">\n";
+ mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
+ mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
for ( unsigned int i = 0; i < mesh->mNumVertices; ++i ) {
writeVertex( mesh->mVertices[ i ] );
}
- mOutput << "" << XmlTag::vertices << ">\n";
- mOutput << "" << XmlTag::mesh << ">\n";
+ mModelOutput << "" << XmlTag::vertices << ">" << std::endl;
+ mModelOutput << "" << XmlTag::mesh << ">" << std::endl;
writeFaces( mesh );
}
void D3MFExporter::writeVertex( const aiVector3D &pos ) {
- mOutput << "<" << XmlTag::vertex << " x=\"" << pos.x << "\" y=\"" << pos.y << "\" z=\"" << pos.z << "\">\n";
+ mModelOutput << "<" << XmlTag::vertex << " x=\"" << pos.x << "\" y=\"" << pos.y << "\" z=\"" << pos.z << "\">";
+ mModelOutput << std::endl;
}
void D3MFExporter::writeFaces( aiMesh *mesh ) {
@@ -215,39 +226,45 @@ void D3MFExporter::writeFaces( aiMesh *mesh ) {
if ( !mesh->HasFaces() ) {
return;
}
- mOutput << "<" << XmlTag::triangles << ">\n";
+ mModelOutput << "<" << XmlTag::triangles << ">" << std::endl;
for ( unsigned int i = 0; i < mesh->mNumFaces; ++i ) {
aiFace ¤tFace = mesh->mFaces[ i ];
- mOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[ 0 ] << "\" v2=\""
- << currentFace.mIndices[ 1 ] << "\" v3=\"" << currentFace.mIndices[ 2 ] << "\"/>\n";
+ mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[ 0 ] << "\" v2=\""
+ << currentFace.mIndices[ 1 ] << "\" v3=\"" << currentFace.mIndices[ 2 ] << "\"/>";
+ mModelOutput << std::endl;
}
- mOutput << "" << XmlTag::triangles << ">\n";
+ mModelOutput << "" << XmlTag::triangles << ">";
+ mModelOutput << std::endl;
}
void D3MFExporter::writeBuild() {
- mOutput << "<" << XmlTag::build << ">\n";
+ mModelOutput << "<" << XmlTag::build << ">" << std::endl;
for ( size_t i = 0; i < mBuildItems.size(); ++i ) {
- mOutput << "<" << XmlTag::item << " objectid=\"" << i + 1 << "\"/>\n";
+ mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 1 << "\"/>";
+ mModelOutput << std::endl;
}
- mOutput << "" << XmlTag::build << ">\n";
+ mModelOutput << "" << XmlTag::build << ">";
+ mModelOutput << std::endl;
}
void D3MFExporter::writeModelToArchive( const std::string &folder, const std::string &modelName ) {
- const std::string entry = folder + "/" + mArchiveName;
+ const std::string entry = folder + "/" + modelName;
zip_entry_open( m_zipArchive, entry.c_str() );
- const std::string &exportTxt( mOutput.str() );
+ const std::string &exportTxt( mModelOutput.str() );
zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );
zip_entry_close( m_zipArchive );
}
void D3MFExporter::writeRelInfoToFile( const std::string &folder, const std::string &relName ) {
- const std::string entry = folder + "/" + "_rels";
+ const std::string entry = folder + "/" + relName;
zip_entry_open( m_zipArchive, entry.c_str() );
- const std::string &exportTxt( mOutput.str() );
+
+ const std::string &exportTxt( mRelOutput.str() );
zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );
+
zip_entry_close( m_zipArchive );
}
diff --git a/code/D3MFExporter.h b/code/D3MFExporter.h
index 9a80844ef..7227f957a 100644
--- a/code/D3MFExporter.h
+++ b/code/D3MFExporter.h
@@ -81,14 +81,14 @@ protected:
void writeBuild();
void writeModelToArchive( const std::string &folder, const std::string &modelName );
void writeRelInfoToFile( const std::string &folder, const std::string &relName );
- void createZipArchiveFromeFileStructure( const char* pFile );
private:
IOSystem *mIOSystem;
std::string mArchiveName;
zip_t *m_zipArchive;
const aiScene *mScene;
- std::ostringstream mOutput;
+ std::ostringstream mModelOutput;
+ std::ostringstream mRelOutput;
std::vector mBuildItems;
std::vector mRelations;
};
diff --git a/test/unit/utD3MFImportExport.cpp b/test/unit/utD3MFImportExport.cpp
index 0383a27b0..2479dfd19 100644
--- a/test/unit/utD3MFImportExport.cpp
+++ b/test/unit/utD3MFImportExport.cpp
@@ -67,7 +67,7 @@ public:
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/3MF/box.3mf", 0 );
Assimp::Exporter exporter;
- return nullptr != exporter.ExportToBlob( scene, "3mf", 0 );
+ return AI_SUCCESS == exporter.Export( scene, "3mf", "test.3mf" );
}
};