Add missing file export into archive.
parent
09a5946dbd
commit
0bdb375804
|
@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
|
||||
|
||||
|
|
|
@ -85,5 +85,5 @@ namespace XmlTag {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
|
|
|
@ -39,25 +39,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
----------------------------------------------------------------------
|
||||
*/
|
||||
#include "D3MFExporter.h"
|
||||
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp//IOStream.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
#include "Exceptional.h"
|
||||
#include "3MFXmlTags.h"
|
||||
#include "D3MFOpcPackage.h"
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
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() ) {
|
||||
bool ok = myExporter.exportArchive(pFile);
|
||||
}
|
||||
|
@ -67,16 +63,20 @@ namespace D3MF {
|
|||
|
||||
#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 )
|
||||
, mStream( outfile.get() )
|
||||
, mArchiveName( pFile )
|
||||
, mScene( pScene )
|
||||
, mBuildItems() {
|
||||
, mBuildItems()
|
||||
, mRelations() {
|
||||
// empty
|
||||
}
|
||||
|
||||
D3MFExporter::~D3MFExporter() {
|
||||
// empty
|
||||
for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
||||
delete mRelations[ i ];
|
||||
}
|
||||
mRelations.clear();
|
||||
}
|
||||
|
||||
bool D3MFExporter::createFileStructure( const char *file ) {
|
||||
|
@ -100,7 +100,7 @@ bool D3MFExporter::createFileStructure( const char *file ) {
|
|||
}
|
||||
|
||||
bool D3MFExporter::validate() {
|
||||
if ( nullptr == mStream ) {
|
||||
if ( mArchiveName.empty() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,9 @@ bool D3MFExporter::exportArchive( const char *file ) {
|
|||
ok |= exportRelations();
|
||||
ok |= export3DModel();
|
||||
|
||||
if ( ok ) {
|
||||
createZipArchiveFromeFileStructure();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -124,9 +127,16 @@ bool D3MFExporter::exportRelations() {
|
|||
mOutput.clear();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -142,14 +152,21 @@ bool D3MFExporter::export3DModel() {
|
|||
|
||||
writeObjects();
|
||||
|
||||
writeModelToArchive();
|
||||
|
||||
mOutput << "</" << XmlTag::resources << ">\n";
|
||||
writeBuild();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -229,10 +246,49 @@ void D3MFExporter::writeBuild() {
|
|||
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 );
|
||||
|
||||
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
|
||||
|
|
|
@ -59,9 +59,11 @@ namespace D3MF {
|
|||
|
||||
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
|
||||
struct OpcPackageRelationship;
|
||||
|
||||
class D3MFExporter {
|
||||
public:
|
||||
D3MFExporter( std::shared_ptr<IOStream> outfile, IOSystem* pIOSystem, const aiScene* pScene );
|
||||
D3MFExporter( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene );
|
||||
~D3MFExporter();
|
||||
bool validate();
|
||||
bool createFileStructure( const char *file );
|
||||
|
@ -76,19 +78,21 @@ protected:
|
|||
void writeVertex( const aiVector3D &pos );
|
||||
void writeFaces( aiMesh *mesh );
|
||||
void writeBuild();
|
||||
bool writeModelToArchive();
|
||||
bool writeRelInfoToFile();
|
||||
void writeModelToArchive( const std::string &folder, const std::string &modelName );
|
||||
void writeRelInfoToFile( const std::string &folder, const std::string &relName );
|
||||
void createZipArchiveFromeFileStructure();
|
||||
|
||||
private:
|
||||
IOSystem *mIOSystem;
|
||||
IOStream *mStream;
|
||||
std::string mArchiveName;
|
||||
const aiScene *mScene;
|
||||
std::ostringstream mOutput;
|
||||
std::vector<unsigned int> mBuildItems;
|
||||
std::vector<OpcPackageRelationship*> mRelations;
|
||||
};
|
||||
|
||||
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
|
||||
}
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
|
||||
|
|
|
@ -381,12 +381,6 @@ bool D3MFZipArchive::mapArchive() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
struct OpcPackageRelationship {
|
||||
std::string id;
|
||||
std::string type;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<OpcPackageRelationship> OpcPackageRelationshipPtr;
|
||||
|
||||
class OpcPackageRelationshipReader {
|
||||
|
|
|
@ -53,6 +53,12 @@ namespace D3MF {
|
|||
typedef irr::io::IrrXMLReader XmlReader;
|
||||
typedef std::shared_ptr<XmlReader> XmlReaderPtr;
|
||||
|
||||
struct OpcPackageRelationship {
|
||||
std::string id;
|
||||
std::string type;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
class D3MFZipArchive;
|
||||
|
||||
class D3MFOpcPackage {
|
||||
|
|
Loading…
Reference in New Issue