Prepare archive structure.
parent
454b8919b0
commit
09a5946dbd
|
@ -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<IOStream> outfile, const aiScene* pScene )
|
||||
: mStream( outfile.get() )
|
||||
D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> 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 << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
||||
mOutput
|
||||
//mOutput
|
||||
|
||||
writeRelInfoToFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -117,6 +142,8 @@ bool D3MFExporter::export3DModel() {
|
|||
|
||||
writeObjects();
|
||||
|
||||
writeModelToArchive();
|
||||
|
||||
mOutput << "</" << XmlTag::resources << ">\n";
|
||||
writeBuild();
|
||||
|
||||
|
@ -202,6 +229,9 @@ void D3MFExporter::writeBuild() {
|
|||
mOutput << "</" << XmlTag::build << ">\n";
|
||||
}
|
||||
|
||||
bool writeModelToArchive();
|
||||
bool writeRelInfoToFile();
|
||||
|
||||
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
|
||||
}
|
||||
|
|
|
@ -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<IOStream> outfile, const aiScene* pScene );
|
||||
D3MFExporter( std::shared_ptr<IOStream> 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;
|
||||
|
|
|
@ -416,7 +416,7 @@ public:
|
|||
}
|
||||
|
||||
void ParseAttributes(XmlReader*) {
|
||||
|
||||
// empty
|
||||
}
|
||||
|
||||
void ParseChildNode(XmlReader* xmlReader) {
|
||||
|
|
|
@ -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<float>( 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<float>( 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<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:
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -56,10 +56,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#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>
|
||||
|
||||
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<std::string> 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue