diff --git a/code/3MFXmlTags.h b/code/3MFXmlTags.h index 73d151aa0..9ee17c7e4 100644 --- a/code/3MFXmlTags.h +++ b/code/3MFXmlTags.h @@ -67,6 +67,22 @@ namespace XmlTag { static const std::string item = "item"; static const std::string objectid = "objectid"; static const std::string transform = "transform"; + + static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml"; + static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels"; + static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types"; + static const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships"; + static const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships"; + static const std::string RELS_RELATIONSHIP_NODE = "Relationship"; + static const std::string RELS_ATTRIB_TARGET = "Target"; + static const std::string RELS_ATTRIB_TYPE = "Type"; + static const std::string RELS_ATTRIB_ID = "Id"; + static const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"; + static const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket"; + static const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture"; + static const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"; + static const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; + } } diff --git a/code/D3MFExporter.cpp b/code/D3MFExporter.cpp index 6ffd7c9bb..6fc3bf065 100644 --- a/code/D3MFExporter.cpp +++ b/code/D3MFExporter.cpp @@ -59,7 +59,7 @@ void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pSce D3MF::D3MFExporter myExporter( outfile, pScene ); if ( myExporter.validate() ) { - bool ok = myExporter.exportAsset(); + bool ok = myExporter.exportArchive(); } } @@ -90,7 +90,25 @@ bool D3MFExporter::validate() { return true; } -bool D3MFExporter::exportAsset() { +bool D3MFExporter::exportArchive() { + bool ok( true ); + ok |= exportRelations(); + ok |= export3DModel(); + + return ok; +} + +bool D3MFExporter::exportRelations() { + mOutput.clear(); + + mOutput << "\n"; + mOutput + return true; +} + +bool D3MFExporter::export3DModel() { + mOutput.clear(); + writeHeader(); mOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\"" << "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">" diff --git a/code/D3MFExporter.h b/code/D3MFExporter.h index 1ed2a9bba..0fbd8f100 100644 --- a/code/D3MFExporter.h +++ b/code/D3MFExporter.h @@ -63,7 +63,9 @@ public: D3MFExporter( std::shared_ptr outfile, const aiScene* pScene ); ~D3MFExporter(); bool validate(); - bool exportAsset(); + bool exportArchive(); + bool exportRelations(); + bool export3DModel(); protected: void writeHeader(); diff --git a/code/D3MFImporter.cpp b/code/D3MFImporter.cpp index 6f77706f9..2fcfefa6d 100644 --- a/code/D3MFImporter.cpp +++ b/code/D3MFImporter.cpp @@ -79,15 +79,10 @@ public: scene->mRootNode = new aiNode(); std::vector children; - while(ReadToEndElement(D3MF::XmlTag::model)) - { - - if(xmlReader->getNodeName() == D3MF::XmlTag::object) - { + while(ReadToEndElement(D3MF::XmlTag::model)) { + if(xmlReader->getNodeName() == D3MF::XmlTag::object) { children.push_back(ReadObject(scene)); - } - else if(xmlReader->getNodeName() == D3MF::XmlTag::build) - { + } else if(xmlReader->getNodeName() == D3MF::XmlTag::build) { } } @@ -96,7 +91,6 @@ public: scene->mRootNode->mName.Set( "3MF" ); } - scene->mNumMeshes = static_cast(meshes.size()); scene->mMeshes = new aiMesh*[scene->mNumMeshes](); diff --git a/code/D3MFOpcPackage.cpp b/code/D3MFOpcPackage.cpp index dd5c28817..3d8317f4e 100644 --- a/code/D3MFOpcPackage.cpp +++ b/code/D3MFOpcPackage.cpp @@ -55,30 +55,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include - #include +#include "3MFXmlTags.h" namespace Assimp { namespace D3MF { -namespace XmlTag { - static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml"; - static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels"; - static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types"; - static const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships"; - static const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships"; - static const std::string RELS_RELATIONSHIP_NODE = "Relationship"; - static const std::string RELS_ATTRIB_TARGET = "Target"; - static const std::string RELS_ATTRIB_TYPE = "Type"; - static const std::string RELS_ATTRIB_ID = "Id"; - static const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"; - static const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket"; - static const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture"; - static const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"; - static const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"; -} - class IOSystem2Unzip { public: static voidpf open(voidpf opaque, const char* filename, int mode); @@ -194,9 +177,10 @@ private: size_t m_Size; }; -ZipFile::ZipFile(size_t size) : m_Size(size) { +ZipFile::ZipFile(size_t size) +: m_Buffer( nullptr ) +, m_Size(size) { ai_assert(m_Size != 0); - m_Buffer = ::malloc(m_Size); } @@ -431,13 +415,11 @@ public: } } - void ParseAttributes(XmlReader*) - { + void ParseAttributes(XmlReader*) { } - void ParseChildNode(XmlReader* xmlReader) - { + void ParseChildNode(XmlReader* xmlReader) { OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship()); relPtr->id = xmlReader->getAttributeValue(XmlTag::RELS_ATTRIB_ID.c_str()); @@ -446,42 +428,41 @@ public: m_relationShips.push_back(relPtr); } + std::vector m_relationShips; }; // ------------------------------------------------------------------------------------------------ D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile) - : m_RootStream(nullptr) -{ - zipArchive.reset(new D3MF::D3MFZipArchive( pIOHandler, rFile )); - if(!zipArchive->isOpen()) { +: mRootStream(nullptr) +, mZipArchive() { + mZipArchive.reset( new D3MF::D3MFZipArchive( pIOHandler, rFile ) ); + if(!mZipArchive->isOpen()) { throw DeadlyImportError("Failed to open file " + rFile+ "."); } std::vector fileList; - zipArchive->getFileList(fileList); + mZipArchive->getFileList(fileList); - for(auto& file: fileList){ + for (auto& file: fileList) { if(file == D3MF::XmlTag::ROOT_RELATIONSHIPS_ARCHIVE) { //PkgRelationshipReader pkgRelReader(file, archive); - ai_assert(zipArchive->Exists(file.c_str())); + ai_assert(mZipArchive->Exists(file.c_str())); - IOStream *fileStream = zipArchive->Open(file.c_str()); + IOStream *fileStream = mZipArchive->Open(file.c_str()); ai_assert(fileStream != nullptr); std::string rootFile = ReadPackageRootRelationship(fileStream); - if(rootFile.size() > 0 && rootFile[0] == '/') - rootFile = rootFile.substr(1); + if ( rootFile.size() > 0 && rootFile[ 0 ] == '/' ) { + rootFile = rootFile.substr( 1 ); + } DefaultLogger::get()->debug(rootFile); - m_RootStream = zipArchive->Open(rootFile.c_str()); - - ai_assert(m_RootStream != nullptr); - - + mRootStream = mZipArchive->Open(rootFile.c_str()); + ai_assert(mRootStream != nullptr); // const size_t size = zipArchive->FileSize(); // m_Data.resize( size ); @@ -492,50 +473,40 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile) // m_Data.clear(); // return false; // } - zipArchive->Close( fileStream ); + mZipArchive->Close( fileStream ); - } - else if( file == D3MF::XmlTag::CONTENT_TYPES_ARCHIVE) - { + } else if( file == D3MF::XmlTag::CONTENT_TYPES_ARCHIVE) { } } } -D3MFOpcPackage::~D3MFOpcPackage() -{ - +D3MFOpcPackage::~D3MFOpcPackage() { + // empty } -IOStream* D3MFOpcPackage::RootStream() const -{ - return m_RootStream; +IOStream* D3MFOpcPackage::RootStream() const { + return mRootStream; } - -std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream* stream) -{ - +std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream* stream) { std::unique_ptr xmlStream(new CIrrXML_IOStreamReader(stream)); std::unique_ptr xml(irr::io::createIrrXMLReader(xmlStream.get())); OpcPackageRelationshipReader reader(xml.get()); - auto itr = std::find_if(reader.m_relationShips.begin(), reader.m_relationShips.end(), [](const OpcPackageRelationshipPtr& rel){ return rel->type == XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE; }); - - if(itr == reader.m_relationShips.end()) throw DeadlyImportError("Cannot find" + XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE); return (*itr)->target; } -} //namespace D3MF +} // Namespace D3MF -} +} // Namespace Assimp #endif //ASSIMP_BUILD_NO_3MF_IMPORTER diff --git a/code/D3MFOpcPackage.h b/code/D3MFOpcPackage.h index 9ac9ade58..40ab2e462 100644 --- a/code/D3MFOpcPackage.h +++ b/code/D3MFOpcPackage.h @@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "irrXMLWrapper.h" namespace Assimp { - namespace D3MF { typedef irr::io::IrrXMLReader XmlReader; @@ -66,8 +65,8 @@ protected: std::string ReadPackageRootRelationship(IOStream* stream); private: - IOStream* m_RootStream; - std::unique_ptr zipArchive; + IOStream* mRootStream; + std::unique_ptr mZipArchive; }; }