Prepare archive structure.

pull/1598/head
Kim Kulling 2017-11-23 22:47:18 +01:00
parent 454b8919b0
commit 09a5946dbd
6 changed files with 119 additions and 31 deletions

View File

@ -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 ) ); 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() ) { if ( myExporter.validate() ) {
bool ok = myExporter.exportArchive(); bool ok = myExporter.exportArchive(pFile);
} }
} }
@ -67,8 +67,9 @@ namespace D3MF {
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER #ifndef ASSIMP_BUILD_NO3MF_EXPORTER
D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene ) D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> outfile, IOSystem* pIOSystem, const aiScene* pScene )
: mStream( outfile.get() ) : mIOSystem( pIOSystem )
, mStream( outfile.get() )
, mScene( pScene ) , mScene( pScene )
, mBuildItems() { , mBuildItems() {
// empty // empty
@ -78,6 +79,26 @@ D3MFExporter::~D3MFExporter() {
// empty // 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() { bool D3MFExporter::validate() {
if ( nullptr == mStream ) { if ( nullptr == mStream ) {
return false; return false;
@ -90,8 +111,9 @@ bool D3MFExporter::validate() {
return true; return true;
} }
bool D3MFExporter::exportArchive() { bool D3MFExporter::exportArchive( const char *file ) {
bool ok( true ); bool ok( true );
ok |= createFileStructure( file );
ok |= exportRelations(); ok |= exportRelations();
ok |= export3DModel(); ok |= export3DModel();
@ -102,7 +124,10 @@ 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
writeRelInfoToFile();
return true; return true;
} }
@ -117,6 +142,8 @@ bool D3MFExporter::export3DModel() {
writeObjects(); writeObjects();
writeModelToArchive();
mOutput << "</" << XmlTag::resources << ">\n"; mOutput << "</" << XmlTag::resources << ">\n";
writeBuild(); writeBuild();
@ -202,6 +229,9 @@ void D3MFExporter::writeBuild() {
mOutput << "</" << XmlTag::build << ">\n"; mOutput << "</" << XmlTag::build << ">\n";
} }
bool writeModelToArchive();
bool writeRelInfoToFile();
#endif // ASSIMP_BUILD_NO3MF_EXPORTER #endif // ASSIMP_BUILD_NO3MF_EXPORTER
} }

View File

@ -53,6 +53,7 @@ struct aiMesh;
namespace Assimp { namespace Assimp {
class IOStream; class IOStream;
class IOSystem;
namespace D3MF { namespace D3MF {
@ -60,10 +61,11 @@ namespace D3MF {
class D3MFExporter { class D3MFExporter {
public: public:
D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene ); D3MFExporter( std::shared_ptr<IOStream> outfile, IOSystem* pIOSystem, const aiScene* pScene );
~D3MFExporter(); ~D3MFExporter();
bool validate(); bool validate();
bool exportArchive(); bool createFileStructure( const char *file );
bool exportArchive( const char *file );
bool exportRelations(); bool exportRelations();
bool export3DModel(); bool export3DModel();
@ -74,8 +76,11 @@ protected:
void writeVertex( const aiVector3D &pos ); void writeVertex( const aiVector3D &pos );
void writeFaces( aiMesh *mesh ); void writeFaces( aiMesh *mesh );
void writeBuild(); void writeBuild();
bool writeModelToArchive();
bool writeRelInfoToFile();
private: private:
IOSystem *mIOSystem;
IOStream *mStream; IOStream *mStream;
const aiScene *mScene; const aiScene *mScene;
std::ostringstream mOutput; std::ostringstream mOutput;

View File

@ -416,7 +416,7 @@ public:
} }
void ParseAttributes(XmlReader*) { void ParseAttributes(XmlReader*) {
// empty
} }
void ParseChildNode(XmlReader* xmlReader) { void ParseChildNode(XmlReader* xmlReader) {

View File

@ -714,7 +714,7 @@ public:
if (floatValue) { if (floatValue) {
return floatValue->value.size() == 1 ? floatValue->value.front() : 0; return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
} }
return atof(attr->value->toString().c_str()); return static_cast<float>( atof( attr->value->toString().c_str() ) );
} }
virtual float getAttributeValueAsFloat(int idx) const /*override*/ { virtual float getAttributeValueAsFloat(int idx) const /*override*/ {
@ -725,7 +725,7 @@ public:
if (floatValue) { if (floatValue) {
return floatValue->value.size() == 1 ? floatValue->value.front() : 0; return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
} }
return atof(attributes[idx].value->toString().c_str()); return static_cast<float>( atof( attributes[ idx ].value->toString().c_str() ) );
} }
virtual const char* getNodeName() const /*override*/ { virtual const char* getNodeName() const /*override*/ {
@ -1792,7 +1792,7 @@ public:
virtual void registerDecoder(const std::string &/*algorithmUri*/, std::unique_ptr<FIDecoder> /*decoder*/) /*override*/ {} virtual void registerDecoder(const std::string &/*algorithmUri*/, std::unique_ptr<FIDecoder> /*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: private:

View File

@ -107,7 +107,7 @@ const aiImporterDesc *MMDImporter::GetInfo() const { return &desc; }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// MMD import implementation // MMD import implementation
void MMDImporter::InternReadFile(const std::string &file, aiScene *pScene, void MMDImporter::InternReadFile(const std::string &file, aiScene *pScene,
IOSystem */*pIOHandler*/) { IOSystem * /*pIOHandler*/) {
// Read file by istream // Read file by istream
std::filebuf fb; std::filebuf fb;
if (!fb.open(file, std::ios::in | std::ios::binary)) { if (!fb.open(file, std::ios::in | std::ios::binary)) {

View File

@ -56,10 +56,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "types.h" #include "types.h"
#ifdef _WIN32
# include <direct.h>
# include <stdlib.h>
# include <stdio.h>
#else
# include <sys/stat.h>
# include <sys/types.h>
#endif // _WIN32
#include <vector> #include <vector>
namespace Assimp { namespace Assimp {
class IOStream;
class IOStream;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** @brief CPP-API: Interface to the file system. /** @brief CPP-API: Interface to the file system.
@ -198,20 +208,35 @@ public:
*/ */
virtual bool PopDirectory(); 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: private:
std::vector<std::string> m_pathStack; std::vector<std::string> m_pathStack;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
AI_FORCE_INLINE IOSystem::IOSystem() : AI_FORCE_INLINE
m_pathStack() IOSystem::IOSystem()
{ : m_pathStack() {
// empty // empty
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
AI_FORCE_INLINE IOSystem::~IOSystem() AI_FORCE_INLINE
{ IOSystem::~IOSystem() {
// empty // empty
} }
@ -222,9 +247,8 @@ AI_FORCE_INLINE IOSystem::~IOSystem()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile, AI_FORCE_INLINE
const std::string& pMode) IOStream* IOSystem::Open(const std::string& pFile, const std::string& pMode) {
{
// NOTE: // NOTE:
// For compatibility, interface was changed to const char* to // For compatibility, interface was changed to const char* to
// avoid crashes between binary incompatible STL versions // 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: // NOTE:
// For compatibility, interface was changed to const char* to // For compatibility, interface was changed to const char* to
// avoid crashes between binary incompatible STL versions // 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, AI_FORCE_INLINE
const std::string& second) const bool IOSystem::ComparePaths (const std::string& one, const std::string& second) const {
{
// NOTE: // NOTE:
// For compatibility, interface was changed to const char* to // For compatibility, interface was changed to const char* to
// avoid crashes between binary incompatible STL versions // 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() ) { if ( path.empty() ) {
return false; 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() ) { if ( m_pathStack.empty() ) {
static const std::string Dummy(""); static const std::string Dummy("");
return 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(); return m_pathStack.size();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
inline bool IOSystem::PopDirectory() { AI_FORCE_INLINE
bool IOSystem::PopDirectory() {
if ( m_pathStack.empty() ) { if ( m_pathStack.empty() ) {
return false; 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 } //!ns Assimp