|
@@ -39,25 +39,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
----------------------------------------------------------------------
|
|
----------------------------------------------------------------------
|
|
*/
|
|
*/
|
|
#include "D3MFExporter.h"
|
|
#include "D3MFExporter.h"
|
|
|
|
+
|
|
#include <assimp/scene.h>
|
|
#include <assimp/scene.h>
|
|
#include <assimp/IOSystem.hpp>
|
|
#include <assimp/IOSystem.hpp>
|
|
#include <assimp//IOStream.hpp>
|
|
#include <assimp//IOStream.hpp>
|
|
#include <assimp/Exporter.hpp>
|
|
#include <assimp/Exporter.hpp>
|
|
-
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
|
#include <assimp/DefaultLogger.hpp>
|
|
|
|
|
|
#include "Exceptional.h"
|
|
#include "Exceptional.h"
|
|
#include "3MFXmlTags.h"
|
|
#include "3MFXmlTags.h"
|
|
|
|
+#include "D3MFOpcPackage.h"
|
|
|
|
|
|
namespace Assimp {
|
|
namespace Assimp {
|
|
|
|
|
|
void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/ ) {
|
|
void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/ ) {
|
|
- std::shared_ptr<IOStream> outfile( pIOSystem->Open( pFile, "wb" ) );
|
|
|
|
- if ( !outfile ) {
|
|
|
|
- throw DeadlyExportError( "Could not open output .3ds file: " + std::string( pFile ) );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- D3MF::D3MFExporter myExporter( outfile, pIOSystem, pScene );
|
|
|
|
|
|
+ D3MF::D3MFExporter myExporter( pFile, pIOSystem, pScene );
|
|
if ( myExporter.validate() ) {
|
|
if ( myExporter.validate() ) {
|
|
bool ok = myExporter.exportArchive(pFile);
|
|
bool ok = myExporter.exportArchive(pFile);
|
|
}
|
|
}
|
|
@@ -67,16 +63,20 @@ namespace D3MF {
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
|
|
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
|
|
|
|
|
|
-D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> outfile, IOSystem* pIOSystem, const aiScene* pScene )
|
|
|
|
|
|
+D3MFExporter::D3MFExporter( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene )
|
|
: mIOSystem( pIOSystem )
|
|
: mIOSystem( pIOSystem )
|
|
-, mStream( outfile.get() )
|
|
|
|
|
|
+, mArchiveName( pFile )
|
|
, mScene( pScene )
|
|
, mScene( pScene )
|
|
-, mBuildItems() {
|
|
|
|
|
|
+, mBuildItems()
|
|
|
|
+, mRelations() {
|
|
// empty
|
|
// empty
|
|
}
|
|
}
|
|
|
|
|
|
D3MFExporter::~D3MFExporter() {
|
|
D3MFExporter::~D3MFExporter() {
|
|
- // empty
|
|
|
|
|
|
+ for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
|
|
|
+ delete mRelations[ i ];
|
|
|
|
+ }
|
|
|
|
+ mRelations.clear();
|
|
}
|
|
}
|
|
|
|
|
|
bool D3MFExporter::createFileStructure( const char *file ) {
|
|
bool D3MFExporter::createFileStructure( const char *file ) {
|
|
@@ -100,7 +100,7 @@ bool D3MFExporter::createFileStructure( const char *file ) {
|
|
}
|
|
}
|
|
|
|
|
|
bool D3MFExporter::validate() {
|
|
bool D3MFExporter::validate() {
|
|
- if ( nullptr == mStream ) {
|
|
|
|
|
|
+ if ( mArchiveName.empty() ) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,6 +117,9 @@ bool D3MFExporter::exportArchive( const char *file ) {
|
|
ok |= exportRelations();
|
|
ok |= exportRelations();
|
|
ok |= export3DModel();
|
|
ok |= export3DModel();
|
|
|
|
|
|
|
|
+ if ( ok ) {
|
|
|
|
+ createZipArchiveFromeFileStructure();
|
|
|
|
+ }
|
|
return ok;
|
|
return ok;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -124,9 +127,16 @@ bool D3MFExporter::exportRelations() {
|
|
mOutput.clear();
|
|
mOutput.clear();
|
|
|
|
|
|
mOutput << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
|
mOutput << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
|
- //mOutput
|
|
|
|
|
|
+ mOutput << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n";
|
|
|
|
|
|
- writeRelInfoToFile();
|
|
|
|
|
|
+ for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
|
|
|
+ mOutput << "<Relationship Target =\"/3D/" << mRelations[ i ]->target << " ";
|
|
|
|
+ mOutput << "id=\"" << mRelations[i]->id << " ";
|
|
|
|
+ mOutput << "Type=\"" << mRelations[ i ]->type << "/>\n";
|
|
|
|
+ }
|
|
|
|
+ mOutput << "</Relationships>\n";
|
|
|
|
+
|
|
|
|
+ writeRelInfoToFile( "_rels", ".rels" );
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -142,14 +152,21 @@ bool D3MFExporter::export3DModel() {
|
|
|
|
|
|
writeObjects();
|
|
writeObjects();
|
|
|
|
|
|
- writeModelToArchive();
|
|
|
|
|
|
|
|
mOutput << "</" << XmlTag::resources << ">\n";
|
|
mOutput << "</" << XmlTag::resources << ">\n";
|
|
writeBuild();
|
|
writeBuild();
|
|
|
|
|
|
mOutput << "</" << XmlTag::model << ">\n";
|
|
mOutput << "</" << XmlTag::model << ">\n";
|
|
|
|
|
|
- std::string exportedFile = mOutput.str();
|
|
|
|
|
|
+ OpcPackageRelationship *info = new OpcPackageRelationship;
|
|
|
|
+ info->id = mArchiveName;
|
|
|
|
+ info->target = "rel0";
|
|
|
|
+ info->type = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
|
|
|
+ mRelations.push_back( info );
|
|
|
|
+
|
|
|
|
+ writeModelToArchive( "3D", mArchiveName );
|
|
|
|
+
|
|
|
|
+ mOutput.clear();
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -229,10 +246,49 @@ void D3MFExporter::writeBuild() {
|
|
mOutput << "</" << XmlTag::build << ">\n";
|
|
mOutput << "</" << XmlTag::build << ">\n";
|
|
}
|
|
}
|
|
|
|
|
|
-bool writeModelToArchive();
|
|
|
|
-bool writeRelInfoToFile();
|
|
|
|
|
|
+void D3MFExporter::writeModelToArchive( const std::string &folder, const std::string &modelName ) {
|
|
|
|
+ const std::string &oldFolder( mIOSystem->CurrentDirectory() );
|
|
|
|
+ if ( folder != oldFolder ) {
|
|
|
|
+ mIOSystem->PushDirectory( oldFolder );
|
|
|
|
+ mIOSystem->ChangeDirectory( folder );
|
|
|
|
|
|
-#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
|
|
|
|
|
+ const std::string &exportTxt( mOutput.str() );
|
|
|
|
+ std::shared_ptr<IOStream> outfile( mIOSystem->Open( modelName, "wb" ) );
|
|
|
|
+ if ( !outfile ) {
|
|
|
|
+ throw DeadlyExportError( "Could not open output model file: " + std::string( modelName ) );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const size_t writtenBytes( outfile->Write( exportTxt.c_str(), sizeof( char ), exportTxt.size() ) );
|
|
|
|
+
|
|
|
|
+ mIOSystem->ChangeDirectory( ".." );
|
|
|
|
+ mIOSystem->PopDirectory();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void D3MFExporter::writeRelInfoToFile( const std::string &folder, const std::string &relName ) {
|
|
|
|
+ const std::string &oldFolder( mIOSystem->CurrentDirectory() );
|
|
|
|
+ if ( folder != oldFolder ) {
|
|
|
|
+ mIOSystem->PushDirectory( oldFolder );
|
|
|
|
+ mIOSystem->ChangeDirectory( folder );
|
|
|
|
+
|
|
|
|
+ const std::string &exportTxt( mOutput.str() );
|
|
|
|
+ std::shared_ptr<IOStream> outfile( mIOSystem->Open( relName, "wb" ) );
|
|
|
|
+ if ( !outfile ) {
|
|
|
|
+ throw DeadlyExportError( "Could not open output model file: " + std::string( relName ) );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const size_t writtenBytes( outfile->Write( exportTxt.c_str(), sizeof( char ), exportTxt.size() ) );
|
|
|
|
+
|
|
|
|
+ mIOSystem->ChangeDirectory( ".." );
|
|
|
|
+ mIOSystem->PopDirectory();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void D3MFExporter::createZipArchiveFromeFileStructure() {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
|
|
|
+
|
|
|
|
+} // Namespace D3MF
|
|
} // Namespace Assimp
|
|
} // Namespace Assimp
|