Merge branch 'master' into fix/multibody-binary-stls
This commit is contained in:
@@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
|
||||
|
||||
@@ -210,6 +209,12 @@ Discreet3DSExporter:: Discreet3DSExporter(std::shared_ptr<IOStream> outfile, con
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Discreet3DSExporter::~Discreet3DSExporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int Discreet3DSExporter::WriteHierarchy(const aiNode& node, int seq, int sibling_level)
|
||||
{
|
||||
|
||||
+7
-10
@@ -60,23 +60,21 @@ namespace Assimp
|
||||
{
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
/** Helper class to export a given scene to a 3DS file. */
|
||||
/**
|
||||
* @brief Helper class to export a given scene to a 3DS file.
|
||||
*/
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
class Discreet3DSExporter
|
||||
{
|
||||
class Discreet3DSExporter {
|
||||
public:
|
||||
Discreet3DSExporter(std::shared_ptr<IOStream> outfile, const aiScene* pScene);
|
||||
~Discreet3DSExporter();
|
||||
|
||||
private:
|
||||
|
||||
void WriteMeshes();
|
||||
void WriteMaterials();
|
||||
void WriteTexture(const aiMaterial& mat, aiTextureType type, uint16_t chunk_flags);
|
||||
|
||||
void WriteFaceMaterialChunk(const aiMesh& mesh);
|
||||
|
||||
int WriteHierarchy(const aiNode& node, int level, int sibling_level);
|
||||
|
||||
void WriteString(const std::string& s);
|
||||
void WriteString(const aiString& s);
|
||||
void WriteColor(const aiColor3D& color);
|
||||
@@ -84,7 +82,6 @@ private:
|
||||
void WritePercentChunk(double f);
|
||||
|
||||
private:
|
||||
|
||||
const aiScene* const scene;
|
||||
StreamWriterLE writer;
|
||||
|
||||
@@ -95,6 +92,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif
|
||||
#endif // AI_3DSEXPORTER_H_INC
|
||||
|
||||
+9
-7
@@ -44,7 +44,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef AI_3DSFILEHELPER_H_INC
|
||||
#define AI_3DSFILEHELPER_H_INC
|
||||
|
||||
|
||||
#include "SpatialSort.h"
|
||||
#include "SmoothingGroups.h"
|
||||
#include "StringUtils.h"
|
||||
@@ -64,16 +63,19 @@ namespace D3DS {
|
||||
/** Discreet3DS class: Helper class for loading 3ds files. Defines chunks
|
||||
* and data structures.
|
||||
*/
|
||||
class Discreet3DS
|
||||
{
|
||||
class Discreet3DS {
|
||||
private:
|
||||
inline Discreet3DS() {}
|
||||
Discreet3DS() {
|
||||
// empty
|
||||
}
|
||||
|
||||
~Discreet3DS() {
|
||||
// empty
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! data structure for a single chunk in a .3ds file
|
||||
struct Chunk
|
||||
{
|
||||
struct Chunk {
|
||||
uint16_t Flag;
|
||||
uint32_t Size;
|
||||
} PACK_STRUCT;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Assimp {
|
||||
namespace D3MF {
|
||||
|
||||
namespace XmlTag {
|
||||
static const std::string model = "model";
|
||||
static const std::string model_unit = "unit";
|
||||
static const std::string metadata = "metadata";
|
||||
static const std::string resources = "resources";
|
||||
static const std::string object = "object";
|
||||
static const std::string mesh = "mesh";
|
||||
static const std::string vertices = "vertices";
|
||||
static const std::string vertex = "vertex";
|
||||
static const std::string triangles = "triangles";
|
||||
static const std::string triangle = "triangle";
|
||||
static const std::string x = "x";
|
||||
static const std::string y = "y";
|
||||
static const std::string z = "z";
|
||||
static const std::string v1 = "v1";
|
||||
static const std::string v2 = "v2";
|
||||
static const std::string v3 = "v3";
|
||||
static const std::string id = "id";
|
||||
static const std::string name = "name";
|
||||
static const std::string type = "type";
|
||||
static const std::string build = "build";
|
||||
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";
|
||||
|
||||
}
|
||||
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
@@ -677,8 +677,11 @@ ADD_ASSIMP_IMPORTER( GLTF
|
||||
ADD_ASSIMP_IMPORTER( 3MF
|
||||
D3MFImporter.h
|
||||
D3MFImporter.cpp
|
||||
D3MFExporter.h
|
||||
D3MFExporter.cpp
|
||||
D3MFOpcPackage.h
|
||||
D3MFOpcPackage.cpp
|
||||
3MFXmlTags.h
|
||||
)
|
||||
|
||||
ADD_ASSIMP_IMPORTER( MMD
|
||||
@@ -740,6 +743,14 @@ SET( unzip_SRCS
|
||||
)
|
||||
SOURCE_GROUP( unzip FILES ${unzip_SRCS})
|
||||
|
||||
SET( ziplib_SRCS
|
||||
../contrib/zip/src/miniz.h
|
||||
../contrib/zip/src/zip.c
|
||||
../contrib/zip/src/zip.h
|
||||
)
|
||||
|
||||
SOURCE_GROUP( ziplib FILES ${ziplib_SRCS} )
|
||||
|
||||
SET ( openddl_parser_SRCS
|
||||
../contrib/openddlparser/code/OpenDDLParser.cpp
|
||||
../contrib/openddlparser/code/DDLNode.cpp
|
||||
@@ -851,6 +862,7 @@ SET( assimp_src
|
||||
${Clipper_SRCS}
|
||||
${openddl_parser_SRCS}
|
||||
${open3dgc_SRCS}
|
||||
${ziplib_SRCS}
|
||||
# Necessary to show the headers in the project when using the VC++ generator:
|
||||
|
||||
${PUBLIC_HEADERS}
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
|
||||
|
||||
#include "D3MFExporter.h"
|
||||
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
#include "Exceptional.h"
|
||||
#include "3MFXmlTags.h"
|
||||
#include "D3MFOpcPackage.h"
|
||||
|
||||
#include <contrib/zip/src/zip.h>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/ ) {
|
||||
if ( nullptr == pIOSystem ) {
|
||||
throw DeadlyExportError( "Could not export 3MP archive: " + std::string( pFile ) );
|
||||
}
|
||||
D3MF::D3MFExporter myExporter( pFile, pScene );
|
||||
if ( myExporter.validate() ) {
|
||||
bool ok = myExporter.exportArchive(pFile);
|
||||
if ( !ok ) {
|
||||
throw DeadlyExportError( "Could not export 3MP archive: " + std::string( pFile ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace D3MF {
|
||||
|
||||
D3MFExporter::D3MFExporter( const char* pFile, const aiScene* pScene )
|
||||
: mArchiveName( pFile )
|
||||
, m_zipArchive( nullptr )
|
||||
, mScene( pScene )
|
||||
, mBuildItems()
|
||||
, mRelations() {
|
||||
// empty
|
||||
}
|
||||
|
||||
D3MFExporter::~D3MFExporter() {
|
||||
for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
||||
delete mRelations[ i ];
|
||||
}
|
||||
mRelations.clear();
|
||||
}
|
||||
|
||||
bool D3MFExporter::validate() {
|
||||
if ( mArchiveName.empty() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( nullptr == mScene ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3MFExporter::exportArchive( const char *file ) {
|
||||
bool ok( true );
|
||||
|
||||
m_zipArchive = zip_open( file, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w' );
|
||||
if ( nullptr == m_zipArchive ) {
|
||||
return false;
|
||||
}
|
||||
ok |= export3DModel();
|
||||
ok |= exportRelations();
|
||||
|
||||
zip_close( m_zipArchive );
|
||||
m_zipArchive = nullptr;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool D3MFExporter::exportRelations() {
|
||||
mRelOutput.clear();
|
||||
|
||||
mRelOutput << "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n";
|
||||
mRelOutput << "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">\n";
|
||||
|
||||
for ( size_t i = 0; i < mRelations.size(); ++i ) {
|
||||
mRelOutput << "<Relationship Target =\"/3D/" << mRelations[ i ]->target << "\" ";
|
||||
mRelOutput << "id=\"" << mRelations[i]->id << "\" ";
|
||||
mRelOutput << "Type=\"" << mRelations[ i ]->type << "/>";
|
||||
mRelOutput << std::endl;
|
||||
}
|
||||
mRelOutput << "</Relationships>";
|
||||
mRelOutput << std::endl;
|
||||
|
||||
writeRelInfoToFile( "_rels", ".rels" );
|
||||
mRelOutput.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3MFExporter::export3DModel() {
|
||||
mModelOutput.clear();
|
||||
|
||||
writeHeader();
|
||||
mModelOutput << "<" << XmlTag::model << " " << XmlTag::model_unit << "=\"millimeter\""
|
||||
<< "xmlns=\"http://schemas.microsoft.com/3dmanufacturing/core/2015/02\">"
|
||||
<< std::endl;
|
||||
mModelOutput << "<" << XmlTag::resources << ">";
|
||||
mModelOutput << std::endl;
|
||||
|
||||
writeObjects();
|
||||
|
||||
|
||||
mModelOutput << "</" << XmlTag::resources << ">";
|
||||
mModelOutput << std::endl;
|
||||
writeBuild();
|
||||
|
||||
mModelOutput << "</" << XmlTag::model << ">\n";
|
||||
|
||||
OpcPackageRelationship *info = new OpcPackageRelationship;
|
||||
info->id = mArchiveName;
|
||||
info->target = "rel0";
|
||||
info->type = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
||||
mRelations.push_back( info );
|
||||
|
||||
writeModelToArchive( "3D", "3DModel.model" );
|
||||
mModelOutput.flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3MFExporter::writeHeader() {
|
||||
mModelOutput << "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
|
||||
void D3MFExporter::writeObjects() {
|
||||
if ( nullptr == mScene->mRootNode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
aiNode *root = mScene->mRootNode;
|
||||
for ( unsigned int i = 0; i < root->mNumChildren; ++i ) {
|
||||
aiNode *currentNode( root->mChildren[ i ] );
|
||||
if ( nullptr == currentNode ) {
|
||||
continue;
|
||||
}
|
||||
mModelOutput << "<" << XmlTag::object << " id=\"" << currentNode->mName.C_Str() << "\" type=\"model\">";
|
||||
mModelOutput << std::endl;
|
||||
for ( unsigned int j = 0; j < currentNode->mNumMeshes; ++j ) {
|
||||
aiMesh *currentMesh = mScene->mMeshes[ currentNode->mMeshes[ j ] ];
|
||||
if ( nullptr == currentMesh ) {
|
||||
continue;
|
||||
}
|
||||
writeMesh( currentMesh );
|
||||
}
|
||||
mBuildItems.push_back( i );
|
||||
|
||||
mModelOutput << "</" << XmlTag::object << ">";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void D3MFExporter::writeMesh( aiMesh *mesh ) {
|
||||
if ( nullptr == mesh ) {
|
||||
return;
|
||||
}
|
||||
|
||||
mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
|
||||
mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
|
||||
for ( unsigned int i = 0; i < mesh->mNumVertices; ++i ) {
|
||||
writeVertex( mesh->mVertices[ i ] );
|
||||
}
|
||||
mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
|
||||
mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
|
||||
|
||||
writeFaces( mesh );
|
||||
}
|
||||
|
||||
void D3MFExporter::writeVertex( const aiVector3D &pos ) {
|
||||
mModelOutput << "<" << XmlTag::vertex << " x=\"" << pos.x << "\" y=\"" << pos.y << "\" z=\"" << pos.z << "\">";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
|
||||
void D3MFExporter::writeFaces( aiMesh *mesh ) {
|
||||
if ( nullptr == mesh ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !mesh->HasFaces() ) {
|
||||
return;
|
||||
}
|
||||
mModelOutput << "<" << XmlTag::triangles << ">" << std::endl;
|
||||
for ( unsigned int i = 0; i < mesh->mNumFaces; ++i ) {
|
||||
aiFace ¤tFace = mesh->mFaces[ i ];
|
||||
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[ 0 ] << "\" v2=\""
|
||||
<< currentFace.mIndices[ 1 ] << "\" v3=\"" << currentFace.mIndices[ 2 ] << "\"/>";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
mModelOutput << "</" << XmlTag::triangles << ">";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
|
||||
void D3MFExporter::writeBuild() {
|
||||
mModelOutput << "<" << XmlTag::build << ">" << std::endl;
|
||||
|
||||
for ( size_t i = 0; i < mBuildItems.size(); ++i ) {
|
||||
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 1 << "\"/>";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
mModelOutput << "</" << XmlTag::build << ">";
|
||||
mModelOutput << std::endl;
|
||||
}
|
||||
|
||||
void D3MFExporter::writeModelToArchive( const std::string &folder, const std::string &modelName ) {
|
||||
if ( nullptr == m_zipArchive ) {
|
||||
throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
|
||||
}
|
||||
const std::string entry = folder + "/" + modelName;
|
||||
zip_entry_open( m_zipArchive, entry.c_str() );
|
||||
|
||||
const std::string &exportTxt( mModelOutput.str() );
|
||||
zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );
|
||||
|
||||
zip_entry_close( m_zipArchive );
|
||||
}
|
||||
|
||||
void D3MFExporter::writeRelInfoToFile( const std::string &folder, const std::string &relName ) {
|
||||
if ( nullptr == m_zipArchive ) {
|
||||
throw DeadlyExportError( "3MF-Export: Zip archive not valid, nullptr." );
|
||||
}
|
||||
const std::string entry = folder + "/" + relName;
|
||||
zip_entry_open( m_zipArchive, entry.c_str() );
|
||||
|
||||
const std::string &exportTxt( mRelOutput.str() );
|
||||
zip_entry_write( m_zipArchive, exportTxt.c_str(), exportTxt.size() );
|
||||
|
||||
zip_entry_close( m_zipArchive );
|
||||
}
|
||||
|
||||
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2017, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* Neither the name of the assimp team, nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of the assimp team.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <assimp/vector3.h>
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
struct aiMaterial;
|
||||
struct aiMesh;
|
||||
|
||||
struct zip_t;
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
class IOStream;
|
||||
|
||||
namespace D3MF {
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
|
||||
struct OpcPackageRelationship;
|
||||
|
||||
class D3MFExporter {
|
||||
public:
|
||||
D3MFExporter( const char* pFile, const aiScene* pScene );
|
||||
~D3MFExporter();
|
||||
bool validate();
|
||||
bool exportArchive( const char *file );
|
||||
bool exportRelations();
|
||||
bool export3DModel();
|
||||
|
||||
protected:
|
||||
void writeHeader();
|
||||
void writeObjects();
|
||||
void writeMesh( aiMesh *mesh );
|
||||
void writeVertex( const aiVector3D &pos );
|
||||
void writeFaces( aiMesh *mesh );
|
||||
void writeBuild();
|
||||
void writeModelToArchive( const std::string &folder, const std::string &modelName );
|
||||
void writeRelInfoToFile( const std::string &folder, const std::string &relName );
|
||||
|
||||
private:
|
||||
std::string mArchiveName;
|
||||
zip_t *m_zipArchive;
|
||||
const aiScene *mScene;
|
||||
std::ostringstream mModelOutput;
|
||||
std::ostringstream mRelOutput;
|
||||
std::vector<unsigned int> mBuildItems;
|
||||
std::vector<OpcPackageRelationship*> mRelations;
|
||||
};
|
||||
|
||||
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
|
||||
} // Namespace D3MF
|
||||
} // Namespace Assimp
|
||||
|
||||
+27
-63
@@ -59,65 +59,37 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "D3MFOpcPackage.h"
|
||||
#include <contrib/unzip/unzip.h>
|
||||
#include "irrXMLWrapper.h"
|
||||
#include "3MFXmlTags.h"
|
||||
|
||||
namespace Assimp {
|
||||
namespace D3MF {
|
||||
|
||||
namespace XmlTag {
|
||||
static const std::string model = "model";
|
||||
static const std::string metadata = "metadata";
|
||||
static const std::string resources = "resources";
|
||||
static const std::string object = "object";
|
||||
static const std::string mesh = "mesh";
|
||||
static const std::string vertices = "vertices";
|
||||
static const std::string vertex = "vertex";
|
||||
static const std::string triangles = "triangles";
|
||||
static const std::string triangle = "triangle";
|
||||
static const std::string x = "x";
|
||||
static const std::string y = "y";
|
||||
static const std::string z = "z";
|
||||
static const std::string v1 = "v1";
|
||||
static const std::string v2 = "v2";
|
||||
static const std::string v3 = "v3";
|
||||
static const std::string id = "id";
|
||||
static const std::string name = "name";
|
||||
static const std::string type = "type";
|
||||
static const std::string build = "build";
|
||||
static const std::string item = "item";
|
||||
static const std::string objectid = "objectid";
|
||||
static const std::string transform = "transform";
|
||||
}
|
||||
|
||||
|
||||
class XmlSerializer
|
||||
{
|
||||
class XmlSerializer {
|
||||
public:
|
||||
XmlSerializer(XmlReader* xmlReader)
|
||||
: xmlReader(xmlReader)
|
||||
{
|
||||
: xmlReader(xmlReader) {
|
||||
// empty
|
||||
}
|
||||
|
||||
~XmlSerializer() {
|
||||
|
||||
}
|
||||
|
||||
void ImportXml(aiScene* scene) {
|
||||
scene->mRootNode = new aiNode();
|
||||
std::vector<aiNode*> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(scene->mRootNode->mName.length == 0)
|
||||
scene->mRootNode->mName.Set("3MF");
|
||||
|
||||
if ( scene->mRootNode->mName.length == 0 ) {
|
||||
scene->mRootNode->mName.Set( "3MF" );
|
||||
}
|
||||
|
||||
scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
|
||||
scene->mMeshes = new aiMesh*[scene->mNumMeshes]();
|
||||
@@ -178,10 +150,8 @@ private:
|
||||
|
||||
}
|
||||
|
||||
aiMesh* ReadMesh()
|
||||
{
|
||||
aiMesh* ReadMesh() {
|
||||
aiMesh* mesh = new aiMesh();
|
||||
|
||||
while(ReadToEndElement(D3MF::XmlTag::mesh))
|
||||
{
|
||||
if(xmlReader->getNodeName() == D3MF::XmlTag::vertices)
|
||||
@@ -192,10 +162,8 @@ private:
|
||||
{
|
||||
ImportTriangles(mesh);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@@ -216,6 +184,7 @@ private:
|
||||
std::copy(vertices.begin(), vertices.end(), mesh->mVertices);
|
||||
|
||||
}
|
||||
|
||||
aiVector3D ReadVertex()
|
||||
{
|
||||
aiVector3D vertex;
|
||||
@@ -261,7 +230,6 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool ReadToStartElement(const std::string& startTag)
|
||||
{
|
||||
while(xmlReader->read())
|
||||
@@ -305,6 +273,7 @@ private:
|
||||
|
||||
} //namespace D3MF
|
||||
|
||||
static const std::string Extension = "3mf";
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"3mf Importer",
|
||||
@@ -316,24 +285,22 @@ static const aiImporterDesc desc = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"3mf"
|
||||
Extension.c_str()
|
||||
};
|
||||
|
||||
|
||||
D3MFImporter::D3MFImporter()
|
||||
{
|
||||
|
||||
: BaseImporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
D3MFImporter::~D3MFImporter()
|
||||
{
|
||||
|
||||
D3MFImporter::~D3MFImporter() {
|
||||
// empty
|
||||
}
|
||||
|
||||
bool D3MFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const
|
||||
{
|
||||
bool D3MFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
const std::string extension = GetExtension(pFile);
|
||||
if(extension == "3mf") {
|
||||
if(extension == Extension ) {
|
||||
return true;
|
||||
} else if ( !extension.length() || checkSig ) {
|
||||
if (nullptr == pIOHandler ) {
|
||||
@@ -344,18 +311,15 @@ bool D3MFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool
|
||||
return false;
|
||||
}
|
||||
|
||||
void D3MFImporter::SetupProperties(const Importer * /*pImp*/)
|
||||
{
|
||||
|
||||
void D3MFImporter::SetupProperties(const Importer * /*pImp*/) {
|
||||
// empty
|
||||
}
|
||||
|
||||
const aiImporterDesc *D3MFImporter::GetInfo() const
|
||||
{
|
||||
const aiImporterDesc *D3MFImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
void D3MFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler)
|
||||
{
|
||||
void D3MFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||
D3MF::D3MFOpcPackage opcPackage(pIOHandler, pFile);
|
||||
|
||||
std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(opcPackage.RootStream()));
|
||||
|
||||
+5
-7
@@ -46,21 +46,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
class D3MFImporter : public BaseImporter
|
||||
{
|
||||
class D3MFImporter : public BaseImporter {
|
||||
public:
|
||||
// BaseImporter interface
|
||||
D3MFImporter();
|
||||
~D3MFImporter();
|
||||
|
||||
// BaseImporter interface
|
||||
public:
|
||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
|
||||
void SetupProperties(const Importer *pImp);
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
|
||||
protected:
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // AI_D3MFLOADER_H_INCLUDED
|
||||
|
||||
+57
-135
@@ -55,49 +55,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include <contrib/unzip/unzip.h>
|
||||
#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);
|
||||
|
||||
static uLong read(voidpf opaque, voidpf stream, void* buf, uLong size);
|
||||
|
||||
static uLong write(voidpf opaque, voidpf stream, const void* buf, uLong size);
|
||||
|
||||
static long tell(voidpf opaque, voidpf stream);
|
||||
|
||||
static long seek(voidpf opaque, voidpf stream, uLong offset, int origin);
|
||||
|
||||
static int close(voidpf opaque, voidpf stream);
|
||||
|
||||
static int testerror(voidpf opaque, voidpf stream);
|
||||
|
||||
static zlib_filefunc_def get(IOSystem* pIOHandler);
|
||||
public:
|
||||
static voidpf open(voidpf opaque, const char* filename, int mode);
|
||||
static uLong read(voidpf opaque, voidpf stream, void* buf, uLong size);
|
||||
static uLong write(voidpf opaque, voidpf stream, const void* buf, uLong size);
|
||||
static long tell(voidpf opaque, voidpf stream);
|
||||
static long seek(voidpf opaque, voidpf stream, uLong offset, int origin);
|
||||
static int close(voidpf opaque, voidpf stream);
|
||||
static int testerror(voidpf opaque, voidpf stream);
|
||||
static zlib_filefunc_def get(IOSystem* pIOHandler);
|
||||
};
|
||||
|
||||
voidpf IOSystem2Unzip::open(voidpf opaque, const char* filename, int mode) {
|
||||
@@ -116,7 +90,6 @@ voidpf IOSystem2Unzip::open(voidpf opaque, const char* filename, int mode) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (voidpf) io_system->Open(filename, mode_fopen);
|
||||
}
|
||||
|
||||
@@ -186,44 +159,33 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem* pIOHandler) {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
class ZipFile : public IOStream
|
||||
{
|
||||
class ZipFile : public IOStream {
|
||||
friend class D3MFZipArchive;
|
||||
|
||||
public:
|
||||
explicit ZipFile(size_t size);
|
||||
|
||||
~ZipFile();
|
||||
|
||||
virtual ~ZipFile();
|
||||
size_t Read(void* pvBuffer, size_t pSize, size_t pCount );
|
||||
|
||||
size_t Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/);
|
||||
|
||||
size_t FileSize() const;
|
||||
|
||||
aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/);
|
||||
|
||||
size_t Tell() const;
|
||||
|
||||
void Flush();
|
||||
|
||||
private:
|
||||
|
||||
void* m_Buffer;
|
||||
|
||||
void *m_Buffer;
|
||||
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);
|
||||
m_Buffer = ::malloc(m_Size);
|
||||
}
|
||||
|
||||
ZipFile::~ZipFile() {
|
||||
free(m_Buffer);
|
||||
::free(m_Buffer);
|
||||
m_Buffer = NULL;
|
||||
}
|
||||
|
||||
@@ -236,8 +198,12 @@ size_t ZipFile::Read(void* pvBuffer, size_t pSize, size_t pCount) {
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t ZipFile::Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) {
|
||||
return 0;
|
||||
size_t ZipFile::Write(const void* pvBuffer, size_t size, size_t pCount ) {
|
||||
const size_t size_to_write( size * pCount );
|
||||
if ( 0 == size_to_write ) {
|
||||
return 0U;
|
||||
}
|
||||
return 0U;
|
||||
}
|
||||
|
||||
size_t ZipFile::FileSize() const {
|
||||
@@ -256,55 +222,36 @@ void ZipFile::Flush() {
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
class D3MFZipArchive : public IOSystem
|
||||
{
|
||||
class D3MFZipArchive : public IOSystem {
|
||||
public:
|
||||
|
||||
static const unsigned int FileNameSize = 256;
|
||||
|
||||
public:
|
||||
|
||||
D3MFZipArchive(IOSystem* pIOHandler, const std::string & rFile);
|
||||
|
||||
~D3MFZipArchive();
|
||||
|
||||
bool Exists(const char* pFile) const;
|
||||
|
||||
char getOsSeparator() const;
|
||||
|
||||
IOStream* Open(const char* pFile, const char* pMode = "rb");
|
||||
|
||||
void Close(IOStream* pFile);
|
||||
|
||||
bool isOpen() const;
|
||||
|
||||
void getFileList(std::vector<std::string> &rFileList);
|
||||
|
||||
private:
|
||||
|
||||
bool mapArchive();
|
||||
|
||||
private:
|
||||
|
||||
unzFile m_ZipFileHandle;
|
||||
|
||||
std::map<std::string, ZipFile*> m_ArchiveMap;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
D3MFZipArchive::D3MFZipArchive(IOSystem* pIOHandler, const std::string& rFile)
|
||||
: m_ZipFileHandle(NULL), m_ArchiveMap()
|
||||
{
|
||||
if (! rFile.empty())
|
||||
{
|
||||
: m_ZipFileHandle(NULL)
|
||||
, m_ArchiveMap() {
|
||||
if (! rFile.empty()) {
|
||||
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
|
||||
|
||||
m_ZipFileHandle = unzOpen2(rFile.c_str(), &mapping);
|
||||
|
||||
if(m_ZipFileHandle != NULL) {
|
||||
mapArchive();
|
||||
}
|
||||
@@ -434,24 +381,12 @@ bool D3MFZipArchive::mapArchive() {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
struct OpcPackageRelationship
|
||||
{
|
||||
std::string id;
|
||||
std::string type;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<OpcPackageRelationship> OpcPackageRelationshipPtr;
|
||||
|
||||
class OpcPackageRelationshipReader
|
||||
{
|
||||
class OpcPackageRelationshipReader {
|
||||
public:
|
||||
|
||||
OpcPackageRelationshipReader(XmlReader* xmlReader)
|
||||
{
|
||||
|
||||
while(xmlReader->read())
|
||||
{
|
||||
OpcPackageRelationshipReader(XmlReader* xmlReader) {
|
||||
while(xmlReader->read()) {
|
||||
if(xmlReader->getNodeType() == irr::io::EXN_ELEMENT &&
|
||||
xmlReader->getNodeName() == XmlTag::RELS_RELATIONSHIP_CONTAINER)
|
||||
{
|
||||
@@ -474,13 +409,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void ParseAttributes(XmlReader*)
|
||||
{
|
||||
|
||||
void ParseAttributes(XmlReader*) {
|
||||
// empty
|
||||
}
|
||||
|
||||
void ParseChildNode(XmlReader* xmlReader)
|
||||
{
|
||||
void ParseChildNode(XmlReader* xmlReader) {
|
||||
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
||||
|
||||
relPtr->id = xmlReader->getAttributeValue(XmlTag::RELS_ATTRIB_ID.c_str());
|
||||
@@ -489,42 +422,41 @@ public:
|
||||
|
||||
m_relationShips.push_back(relPtr);
|
||||
}
|
||||
|
||||
std::vector<OpcPackageRelationshipPtr> 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<std::string> 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 );
|
||||
@@ -535,50 +467,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<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(stream));
|
||||
std::unique_ptr<XmlReader> 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
|
||||
|
||||
+12
-7
@@ -48,26 +48,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "irrXMLWrapper.h"
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
namespace D3MF {
|
||||
|
||||
typedef irr::io::IrrXMLReader XmlReader;
|
||||
typedef std::shared_ptr<XmlReader> XmlReaderPtr;
|
||||
|
||||
struct OpcPackageRelationship {
|
||||
std::string id;
|
||||
std::string type;
|
||||
std::string target;
|
||||
};
|
||||
|
||||
class D3MFZipArchive;
|
||||
|
||||
class D3MFOpcPackage
|
||||
{
|
||||
class D3MFOpcPackage {
|
||||
public:
|
||||
D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile);
|
||||
~D3MFOpcPackage();
|
||||
|
||||
IOStream* RootStream() const;
|
||||
private:
|
||||
|
||||
protected:
|
||||
std::string ReadPackageRootRelationship(IOStream* stream);
|
||||
|
||||
private:
|
||||
IOStream* m_RootStream;
|
||||
std::unique_ptr<D3MFZipArchive> zipArchive;
|
||||
IOStream* mRootStream;
|
||||
std::unique_ptr<D3MFZipArchive> mZipArchive;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+17
-12
@@ -95,29 +95,30 @@ void ExportSceneGLTF2(const char*, IOSystem*, const aiScene*, const ExportProper
|
||||
void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneX3D(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportScene3MF( const char*, IOSystem*, const aiScene*, const ExportProperties* );
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// global array of all export formats which Assimp supports in its current build
|
||||
Exporter::ExportFormatEntry gExporters[] =
|
||||
{
|
||||
#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
|
||||
Exporter::ExportFormatEntry( "collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada),
|
||||
Exporter::ExportFormatEntry( "collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_X_EXPORTER
|
||||
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
|
||||
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs),
|
||||
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_STEP_EXPORTER
|
||||
Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0),
|
||||
Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0 ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER
|
||||
Exporter::ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */),
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
|
||||
Exporter::ExportFormatEntry( "objnomtl", "Wavefront OBJ format without material file", "obj", &ExportSceneObjNoMtl,
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */),
|
||||
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_STL_EXPORTER
|
||||
@@ -140,28 +141,32 @@ Exporter::ExportFormatEntry gExporters[] =
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
|
||||
Exporter::ExportFormatEntry( "3ds", "Autodesk 3DS (legacy)", "3ds" , &ExportScene3DS,
|
||||
aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices),
|
||||
aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
|
||||
Exporter::ExportFormatEntry( "gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
Exporter::ExportFormatEntry( "glb", "GL Transmission Format (binary)", "glb", &ExportSceneGLB,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf2", &ExportSceneGLTF2,
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType),
|
||||
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER
|
||||
Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0),
|
||||
Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0 ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
|
||||
Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0),
|
||||
Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0 ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_X3D_EXPORTER
|
||||
Exporter::ExportFormatEntry( "x3d", "Extensible 3D", "x3d" , &ExportSceneX3D, 0),
|
||||
Exporter::ExportFormatEntry( "x3d", "Extensible 3D", "x3d" , &ExportSceneX3D, 0 ),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
|
||||
Exporter::ExportFormatEntry( "3mf", "The 3MF-File-Format", "3mf", &ExportScene3MF, 0 )
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
+3
-1
@@ -715,6 +715,7 @@ public:
|
||||
if (floatValue) {
|
||||
return floatValue->value.size() == 1 ? floatValue->value.front() : 0;
|
||||
}
|
||||
|
||||
return fast_atof(attr->value->toString().c_str());
|
||||
}
|
||||
|
||||
@@ -1793,7 +1794,8 @@ 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:
|
||||
|
||||
|
||||
@@ -70,9 +70,7 @@ namespace Assimp {
|
||||
* }
|
||||
* @endcode
|
||||
**/
|
||||
class CIrrXML_IOStreamReader
|
||||
: public irr::io::IFileReadCallBack
|
||||
{
|
||||
class CIrrXML_IOStreamReader : public irr::io::IFileReadCallBack {
|
||||
public:
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user