use one header for all xml-tags.
parent
b474e75e29
commit
454b8919b0
|
@ -67,6 +67,22 @@ namespace XmlTag {
|
||||||
static const std::string item = "item";
|
static const std::string item = "item";
|
||||||
static const std::string objectid = "objectid";
|
static const std::string objectid = "objectid";
|
||||||
static const std::string transform = "transform";
|
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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pSce
|
||||||
|
|
||||||
D3MF::D3MFExporter myExporter( outfile, pScene );
|
D3MF::D3MFExporter myExporter( outfile, pScene );
|
||||||
if ( myExporter.validate() ) {
|
if ( myExporter.validate() ) {
|
||||||
bool ok = myExporter.exportAsset();
|
bool ok = myExporter.exportArchive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,25 @@ bool D3MFExporter::validate() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool D3MFExporter::exportAsset() {
|
bool D3MFExporter::exportArchive() {
|
||||||
|
bool ok( true );
|
||||||
|
ok |= exportRelations();
|
||||||
|
ok |= export3DModel();
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool D3MFExporter::exportRelations() {
|
||||||
|
mOutput.clear();
|
||||||
|
|
||||||
|
mOutput << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
||||||
|
mOutput
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool D3MFExporter::export3DModel() {
|
||||||
|
mOutput.clear();
|
||||||
|
|
||||||
writeHeader();
|
writeHeader();
|
||||||
mOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
|
mOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
|
||||||
<< "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
|
<< "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
|
||||||
|
|
|
@ -63,7 +63,9 @@ public:
|
||||||
D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene );
|
D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene );
|
||||||
~D3MFExporter();
|
~D3MFExporter();
|
||||||
bool validate();
|
bool validate();
|
||||||
bool exportAsset();
|
bool exportArchive();
|
||||||
|
bool exportRelations();
|
||||||
|
bool export3DModel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void writeHeader();
|
void writeHeader();
|
||||||
|
|
|
@ -79,15 +79,10 @@ public:
|
||||||
scene->mRootNode = new aiNode();
|
scene->mRootNode = new aiNode();
|
||||||
std::vector<aiNode*> children;
|
std::vector<aiNode*> children;
|
||||||
|
|
||||||
while(ReadToEndElement(D3MF::XmlTag::model))
|
while(ReadToEndElement(D3MF::XmlTag::model)) {
|
||||||
{
|
if(xmlReader->getNodeName() == D3MF::XmlTag::object) {
|
||||||
|
|
||||||
if(xmlReader->getNodeName() == D3MF::XmlTag::object)
|
|
||||||
{
|
|
||||||
children.push_back(ReadObject(scene));
|
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->mRootNode->mName.Set( "3MF" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes]();
|
scene->mMeshes = new aiMesh*[scene->mNumMeshes]();
|
||||||
|
|
||||||
|
|
|
@ -55,30 +55,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include <contrib/unzip/unzip.h>
|
#include <contrib/unzip/unzip.h>
|
||||||
|
#include "3MFXmlTags.h"
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace D3MF {
|
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 {
|
class IOSystem2Unzip {
|
||||||
public:
|
public:
|
||||||
static voidpf open(voidpf opaque, const char* filename, int mode);
|
static voidpf open(voidpf opaque, const char* filename, int mode);
|
||||||
|
@ -194,9 +177,10 @@ private:
|
||||||
size_t m_Size;
|
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);
|
ai_assert(m_Size != 0);
|
||||||
|
|
||||||
m_Buffer = ::malloc(m_Size);
|
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());
|
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
||||||
|
|
||||||
relPtr->id = xmlReader->getAttributeValue(XmlTag::RELS_ATTRIB_ID.c_str());
|
relPtr->id = xmlReader->getAttributeValue(XmlTag::RELS_ATTRIB_ID.c_str());
|
||||||
|
@ -446,42 +428,41 @@ public:
|
||||||
|
|
||||||
m_relationShips.push_back(relPtr);
|
m_relationShips.push_back(relPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<OpcPackageRelationshipPtr> m_relationShips;
|
std::vector<OpcPackageRelationshipPtr> m_relationShips;
|
||||||
};
|
};
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
|
D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
|
||||||
: m_RootStream(nullptr)
|
: mRootStream(nullptr)
|
||||||
{
|
, mZipArchive() {
|
||||||
zipArchive.reset(new D3MF::D3MFZipArchive( pIOHandler, rFile ));
|
mZipArchive.reset( new D3MF::D3MFZipArchive( pIOHandler, rFile ) );
|
||||||
if(!zipArchive->isOpen()) {
|
if(!mZipArchive->isOpen()) {
|
||||||
throw DeadlyImportError("Failed to open file " + rFile+ ".");
|
throw DeadlyImportError("Failed to open file " + rFile+ ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> fileList;
|
std::vector<std::string> fileList;
|
||||||
zipArchive->getFileList(fileList);
|
mZipArchive->getFileList(fileList);
|
||||||
|
|
||||||
for(auto& file: fileList){
|
for (auto& file: fileList) {
|
||||||
if(file == D3MF::XmlTag::ROOT_RELATIONSHIPS_ARCHIVE) {
|
if(file == D3MF::XmlTag::ROOT_RELATIONSHIPS_ARCHIVE) {
|
||||||
//PkgRelationshipReader pkgRelReader(file, 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);
|
ai_assert(fileStream != nullptr);
|
||||||
|
|
||||||
std::string rootFile = ReadPackageRootRelationship(fileStream);
|
std::string rootFile = ReadPackageRootRelationship(fileStream);
|
||||||
if(rootFile.size() > 0 && rootFile[0] == '/')
|
if ( rootFile.size() > 0 && rootFile[ 0 ] == '/' ) {
|
||||||
rootFile = rootFile.substr(1);
|
rootFile = rootFile.substr( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
DefaultLogger::get()->debug(rootFile);
|
DefaultLogger::get()->debug(rootFile);
|
||||||
|
|
||||||
m_RootStream = zipArchive->Open(rootFile.c_str());
|
mRootStream = mZipArchive->Open(rootFile.c_str());
|
||||||
|
|
||||||
ai_assert(m_RootStream != nullptr);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ai_assert(mRootStream != nullptr);
|
||||||
|
|
||||||
// const size_t size = zipArchive->FileSize();
|
// const size_t size = zipArchive->FileSize();
|
||||||
// m_Data.resize( size );
|
// m_Data.resize( size );
|
||||||
|
@ -492,50 +473,40 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
|
||||||
// m_Data.clear();
|
// m_Data.clear();
|
||||||
// return false;
|
// 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
|
IOStream* D3MFOpcPackage::RootStream() const {
|
||||||
{
|
return mRootStream;
|
||||||
return m_RootStream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream* stream) {
|
||||||
std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream* stream)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(stream));
|
std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(stream));
|
||||||
std::unique_ptr<XmlReader> xml(irr::io::createIrrXMLReader(xmlStream.get()));
|
std::unique_ptr<XmlReader> xml(irr::io::createIrrXMLReader(xmlStream.get()));
|
||||||
|
|
||||||
OpcPackageRelationshipReader reader(xml.get());
|
OpcPackageRelationshipReader reader(xml.get());
|
||||||
|
|
||||||
|
|
||||||
auto itr = std::find_if(reader.m_relationShips.begin(), reader.m_relationShips.end(), [](const OpcPackageRelationshipPtr& rel){
|
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;
|
return rel->type == XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(itr == reader.m_relationShips.end())
|
if(itr == reader.m_relationShips.end())
|
||||||
throw DeadlyImportError("Cannot find" + XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE);
|
throw DeadlyImportError("Cannot find" + XmlTag::PACKAGE_START_PART_RELATIONSHIP_TYPE);
|
||||||
|
|
||||||
return (*itr)->target;
|
return (*itr)->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace D3MF
|
} // Namespace D3MF
|
||||||
|
|
||||||
}
|
} // Namespace Assimp
|
||||||
|
|
||||||
#endif //ASSIMP_BUILD_NO_3MF_IMPORTER
|
#endif //ASSIMP_BUILD_NO_3MF_IMPORTER
|
||||||
|
|
|
@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "irrXMLWrapper.h"
|
#include "irrXMLWrapper.h"
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
|
||||||
typedef irr::io::IrrXMLReader XmlReader;
|
typedef irr::io::IrrXMLReader XmlReader;
|
||||||
|
@ -66,8 +65,8 @@ protected:
|
||||||
std::string ReadPackageRootRelationship(IOStream* stream);
|
std::string ReadPackageRootRelationship(IOStream* stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IOStream* m_RootStream;
|
IOStream* mRootStream;
|
||||||
std::unique_ptr<D3MFZipArchive> zipArchive;
|
std::unique_ptr<D3MFZipArchive> mZipArchive;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue