From 09a5946dbd9a1a6b667e2ced842d3d56c06895e6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 23 Nov 2017 22:47:18 +0100 Subject: [PATCH] Prepare archive structure. --- code/D3MFExporter.cpp | 42 ++++++++++++++--- code/D3MFExporter.h | 9 +++- code/D3MFOpcPackage.cpp | 2 +- code/FIReader.cpp | 6 +-- code/MMDImporter.cpp | 2 +- include/assimp/IOSystem.hpp | 89 +++++++++++++++++++++++++++++-------- 6 files changed, 119 insertions(+), 31 deletions(-) diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp index 6fc3bf065..4d3d45f8c 100644 --- a/code/D3MFExporter.cpp +++ b/code/D3MFExporter.cpp @@ -57,9 +57,9 @@ void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pSce throw DeadlyExportError( "Could not open output .3ds file: " + std::string( pFile ) ); } - D3MF::D3MFExporter myExporter( outfile, pScene ); + D3MF::D3MFExporter myExporter( outfile, pIOSystem, pScene ); if ( myExporter.validate() ) { - bool ok = myExporter.exportArchive(); + bool ok = myExporter.exportArchive(pFile); } } @@ -67,8 +67,9 @@ namespace D3MF { #ifndef ASSIMP_BUILD_NO3MF_EXPORTER -D3MFExporter::D3MFExporter( std::shared_ptr outfile, const aiScene* pScene ) -: mStream( outfile.get() ) +D3MFExporter::D3MFExporter( std::shared_ptr outfile, IOSystem* pIOSystem, const aiScene* pScene ) +: mIOSystem( pIOSystem ) +, mStream( outfile.get() ) , mScene( pScene ) , mBuildItems() { // empty @@ -78,6 +79,26 @@ D3MFExporter::~D3MFExporter() { // empty } +bool D3MFExporter::createFileStructure( const char *file ) { + if ( !mIOSystem->CreateDirectory( file ) ) { + return false; + } + + if ( !mIOSystem->ChangeDirectory( file ) ) { + return false; + } + + if ( !mIOSystem->CreateDirectory( "3D" ) ) { + return false; + } + + if ( !mIOSystem->CreateDirectory( "_rels" ) ) { + return false; + } + + return true; +} + bool D3MFExporter::validate() { if ( nullptr == mStream ) { return false; @@ -90,8 +111,9 @@ bool D3MFExporter::validate() { return true; } -bool D3MFExporter::exportArchive() { +bool D3MFExporter::exportArchive( const char *file ) { bool ok( true ); + ok |= createFileStructure( file ); ok |= exportRelations(); ok |= export3DModel(); @@ -102,7 +124,10 @@ bool D3MFExporter::exportRelations() { mOutput.clear(); mOutput << "\n"; - mOutput + //mOutput + + writeRelInfoToFile(); + return true; } @@ -117,6 +142,8 @@ bool D3MFExporter::export3DModel() { writeObjects(); + writeModelToArchive(); + mOutput << "\n"; writeBuild(); @@ -202,6 +229,9 @@ void D3MFExporter::writeBuild() { mOutput << "\n"; } +bool writeModelToArchive(); +bool writeRelInfoToFile(); + #endif // ASSIMP_BUILD_NO3MF_EXPORTER } diff --git a/code/D3MFExporter.h b/code/D3MFExporter.h index 0fbd8f100..eacf91069 100644 --- a/code/D3MFExporter.h +++ b/code/D3MFExporter.h @@ -53,6 +53,7 @@ struct aiMesh; namespace Assimp { class IOStream; +class IOSystem; namespace D3MF { @@ -60,10 +61,11 @@ namespace D3MF { class D3MFExporter { public: - D3MFExporter( std::shared_ptr outfile, const aiScene* pScene ); + D3MFExporter( std::shared_ptr outfile, IOSystem* pIOSystem, const aiScene* pScene ); ~D3MFExporter(); bool validate(); - bool exportArchive(); + bool createFileStructure( const char *file ); + bool exportArchive( const char *file ); bool exportRelations(); bool export3DModel(); @@ -74,8 +76,11 @@ protected: void writeVertex( const aiVector3D &pos ); void writeFaces( aiMesh *mesh ); void writeBuild(); + bool writeModelToArchive(); + bool writeRelInfoToFile(); private: + IOSystem *mIOSystem; IOStream *mStream; const aiScene *mScene; std::ostringstream mOutput; diff --git a/code/D3MFOpcPackage.cpp b/code/D3MFOpcPackage.cpp index 3d8317f4e..ed792461b 100644 --- a/code/D3MFOpcPackage.cpp +++ b/code/D3MFOpcPackage.cpp @@ -416,7 +416,7 @@ public: } void ParseAttributes(XmlReader*) { - + // empty } void ParseChildNode(XmlReader* xmlReader) { diff --git a/code/FIReader.cpp b/code/FIReader.cpp index 53cff257a..f8058e784 100755 --- a/code/FIReader.cpp +++ b/code/FIReader.cpp @@ -714,7 +714,7 @@ public: if (floatValue) { return floatValue->value.size() == 1 ? floatValue->value.front() : 0; } - return atof(attr->value->toString().c_str()); + return static_cast( atof( attr->value->toString().c_str() ) ); } virtual float getAttributeValueAsFloat(int idx) const /*override*/ { @@ -725,7 +725,7 @@ public: if (floatValue) { return floatValue->value.size() == 1 ? floatValue->value.front() : 0; } - return atof(attributes[idx].value->toString().c_str()); + return static_cast( atof( attributes[ idx ].value->toString().c_str() ) ); } virtual const char* getNodeName() const /*override*/ { @@ -1792,7 +1792,7 @@ public: virtual void registerDecoder(const std::string &/*algorithmUri*/, std::unique_ptr /*decoder*/) /*override*/ {} - virtual void registerVocabulary(const std::string &/*vocabularyUri*/, const FIVocabulary */*vocabulary*/) /*override*/ {} + virtual void registerVocabulary(const std::string &/*vocabularyUri*/, const FIVocabulary * /*vocabulary*/) /*override*/ {} private: diff --git a/code/MMDImporter.cpp b/code/MMDImporter.cpp index cf7c87c8a..01f009519 100644 --- a/code/MMDImporter.cpp +++ b/code/MMDImporter.cpp @@ -107,7 +107,7 @@ const aiImporterDesc *MMDImporter::GetInfo() const { return &desc; } // ------------------------------------------------------------------------------------------------ // MMD import implementation void MMDImporter::InternReadFile(const std::string &file, aiScene *pScene, - IOSystem */*pIOHandler*/) { + IOSystem * /*pIOHandler*/) { // Read file by istream std::filebuf fb; if (!fb.open(file, std::ios::in | std::ios::binary)) { diff --git a/include/assimp/IOSystem.hpp b/include/assimp/IOSystem.hpp index e7a216e4e..35f58e8b6 100644 --- a/include/assimp/IOSystem.hpp +++ b/include/assimp/IOSystem.hpp @@ -56,10 +56,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "types.h" +#ifdef _WIN32 +# include +# include +# include +#else +# include +# include +#endif // _WIN32 + #include namespace Assimp { -class IOStream; + + class IOStream; // --------------------------------------------------------------------------- /** @brief CPP-API: Interface to the file system. @@ -198,20 +208,35 @@ public: */ virtual bool PopDirectory(); + // ------------------------------------------------------------------- + /** @brief CReates an new directory at the given path. + * @param path [in] The path to create. + * @return True, when a directory was created. False if the directory + * cannot be created. + */ + virtual bool CreateDirectory( const std::string &path ); + + // ------------------------------------------------------------------- + /** @brief Will change the current directory to the given path. + * @param path [in] The path to change to. + * @return True, when the directory has changed successfully. + */ + virtual bool ChangeDirectory( const std::string &path ); + private: std::vector m_pathStack; }; // ---------------------------------------------------------------------------- -AI_FORCE_INLINE IOSystem::IOSystem() : - m_pathStack() -{ +AI_FORCE_INLINE +IOSystem::IOSystem() +: m_pathStack() { // empty } // ---------------------------------------------------------------------------- -AI_FORCE_INLINE IOSystem::~IOSystem() -{ +AI_FORCE_INLINE +IOSystem::~IOSystem() { // empty } @@ -222,9 +247,8 @@ AI_FORCE_INLINE IOSystem::~IOSystem() // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- -AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile, - const std::string& pMode) -{ +AI_FORCE_INLINE +IOStream* IOSystem::Open(const std::string& pFile, const std::string& pMode) { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions @@ -232,8 +256,8 @@ AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile, } // ---------------------------------------------------------------------------- -AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const -{ +AI_FORCE_INLINE +bool IOSystem::Exists( const std::string& pFile) const { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions @@ -241,9 +265,8 @@ AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const } // ---------------------------------------------------------------------------- -inline bool IOSystem::ComparePaths (const std::string& one, - const std::string& second) const -{ +AI_FORCE_INLINE +bool IOSystem::ComparePaths (const std::string& one, const std::string& second) const { // NOTE: // For compatibility, interface was changed to const char* to // avoid crashes between binary incompatible STL versions @@ -251,7 +274,8 @@ inline bool IOSystem::ComparePaths (const std::string& one, } // ---------------------------------------------------------------------------- -inline bool IOSystem::PushDirectory( const std::string &path ) { +AI_FORCE_INLINE +bool IOSystem::PushDirectory( const std::string &path ) { if ( path.empty() ) { return false; } @@ -262,7 +286,8 @@ inline bool IOSystem::PushDirectory( const std::string &path ) { } // ---------------------------------------------------------------------------- -inline const std::string &IOSystem::CurrentDirectory() const { +AI_FORCE_INLINE +const std::string &IOSystem::CurrentDirectory() const { if ( m_pathStack.empty() ) { static const std::string Dummy(""); return Dummy; @@ -271,12 +296,14 @@ inline const std::string &IOSystem::CurrentDirectory() const { } // ---------------------------------------------------------------------------- -inline size_t IOSystem::StackSize() const { +AI_FORCE_INLINE +size_t IOSystem::StackSize() const { return m_pathStack.size(); } // ---------------------------------------------------------------------------- -inline bool IOSystem::PopDirectory() { +AI_FORCE_INLINE +bool IOSystem::PopDirectory() { if ( m_pathStack.empty() ) { return false; } @@ -287,6 +314,32 @@ inline bool IOSystem::PopDirectory() { } // ---------------------------------------------------------------------------- +AI_FORCE_INLINE +bool IOSystem::CreateDirectory( const std::string &path ) { + if ( path.empty() ) { + return false; + } + +#ifdef _WIN32 + return 0 != ::_mkdir( path.c_str() ); +#else + return 0 != ::mkdir( path.c_str(), 0777 ); +#endif // _WIN32 +} + +// ---------------------------------------------------------------------------- +AI_FORCE_INLINE +bool IOSystem::ChangeDirectory( const std::string &path ) { + if ( path.empty() ) { + return false; + } + +#ifdef _WIN32 + return 0 != ::_chdir( path.c_str() ); +#else + return 0 != ::chdir( path.c_str() ); +#endif // _WIN32 +} } //!ns Assimp