3Mf-Export: add prototypes for relations and rest of 3MF-document.

pull/1598/head
Kim Kulling 2017-11-21 18:41:16 +01:00
parent a7be5b527f
commit b474e75e29
6 changed files with 73 additions and 57 deletions

View File

@ -44,7 +44,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef AI_3DSFILEHELPER_H_INC #ifndef AI_3DSFILEHELPER_H_INC
#define AI_3DSFILEHELPER_H_INC #define AI_3DSFILEHELPER_H_INC
#include "SpatialSort.h" #include "SpatialSort.h"
#include "SmoothingGroups.h" #include "SmoothingGroups.h"
#include "StringUtils.h" #include "StringUtils.h"
@ -64,16 +63,19 @@ namespace D3DS {
/** Discreet3DS class: Helper class for loading 3ds files. Defines chunks /** Discreet3DS class: Helper class for loading 3ds files. Defines chunks
* and data structures. * and data structures.
*/ */
class Discreet3DS class Discreet3DS {
{
private: private:
inline Discreet3DS() {} Discreet3DS() {
// empty
}
~Discreet3DS() {
// empty
}
public: public:
//! data structure for a single chunk in a .3ds file //! data structure for a single chunk in a .3ds file
struct Chunk struct Chunk {
{
uint16_t Flag; uint16_t Flag;
uint32_t Size; uint32_t Size;
} PACK_STRUCT; } PACK_STRUCT;

View File

@ -50,7 +50,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "3MFXmlTags.h" #include "3MFXmlTags.h"
namespace Assimp { namespace Assimp {
namespace D3MF {
void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/ ) { void ExportScene3MF( const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/ ) {
std::shared_ptr<IOStream> outfile( pIOSystem->Open( pFile, "wb" ) ); std::shared_ptr<IOStream> outfile( pIOSystem->Open( pFile, "wb" ) );
@ -58,12 +57,16 @@ 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 ) );
} }
D3MFExporter myExporter( outfile, pScene ); D3MF::D3MFExporter myExporter( outfile, pScene );
if ( myExporter.validate() ) { if ( myExporter.validate() ) {
bool ok = myExporter.exportAsset(); bool ok = myExporter.exportAsset();
} }
} }
namespace D3MF {
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene ) D3MFExporter::D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene )
: mStream( outfile.get() ) : mStream( outfile.get() )
, mScene( pScene ) , mScene( pScene )
@ -101,6 +104,8 @@ bool D3MFExporter::exportAsset() {
mOutput << "</" << XmlTag::model << ">\n"; mOutput << "</" << XmlTag::model << ">\n";
std::string exportedFile = mOutput.str();
return true; return true;
} }
@ -179,5 +184,7 @@ void D3MFExporter::writeBuild() {
mOutput << "</" << XmlTag::build << ">\n"; mOutput << "</" << XmlTag::build << ">\n";
} }
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
} }
} // Namespace Assimp } // Namespace Assimp

View File

@ -56,6 +56,8 @@ class IOStream;
namespace D3MF { namespace D3MF {
#ifndef ASSIMP_BUILD_NO3MF_EXPORTER
class D3MFExporter { class D3MFExporter {
public: public:
D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene ); D3MFExporter( std::shared_ptr<IOStream> outfile, const aiScene* pScene );
@ -78,6 +80,8 @@ private:
std::vector<unsigned int> mBuildItems; std::vector<unsigned int> mBuildItems;
}; };
#endif // ASSIMP_BUILD_NO3MF_EXPORTER
} }
} // Namespace Assimp } // Namespace Assimp

View File

@ -107,7 +107,6 @@ voidpf IOSystem2Unzip::open(voidpf opaque, const char* filename, int mode) {
} }
} }
return (voidpf) io_system->Open(filename, mode_fopen); return (voidpf) io_system->Open(filename, mode_fopen);
} }
@ -177,44 +176,32 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem* pIOHandler) {
return mapping; return mapping;
} }
class ZipFile : public IOStream {
class ZipFile : public IOStream
{
friend class D3MFZipArchive; friend class D3MFZipArchive;
public: public:
explicit ZipFile(size_t size); explicit ZipFile(size_t size);
virtual ~ZipFile();
~ZipFile();
size_t Read(void* pvBuffer, size_t pSize, size_t pCount ); 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 Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/);
size_t FileSize() const; size_t FileSize() const;
aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/); aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/);
size_t Tell() const; size_t Tell() const;
void Flush(); void Flush();
private: private:
void *m_Buffer;
void* m_Buffer;
size_t m_Size; size_t m_Size;
}; };
ZipFile::ZipFile(size_t size) : m_Size(size) { ZipFile::ZipFile(size_t size) : m_Size(size) {
ai_assert(m_Size != 0); ai_assert(m_Size != 0);
m_Buffer = malloc(m_Size); m_Buffer = ::malloc(m_Size);
} }
ZipFile::~ZipFile() { ZipFile::~ZipFile() {
free(m_Buffer); ::free(m_Buffer);
m_Buffer = NULL; m_Buffer = NULL;
} }
@ -227,8 +214,12 @@ size_t ZipFile::Read(void* pvBuffer, size_t pSize, size_t pCount) {
return size; return size;
} }
size_t ZipFile::Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/) { size_t ZipFile::Write(const void* pvBuffer, size_t size, size_t pCount ) {
return 0; const size_t size_to_write( size * pCount );
if ( 0 == size_to_write ) {
return 0U;
}
return 0U;
} }
size_t ZipFile::FileSize() const { size_t ZipFile::FileSize() const {
@ -247,7 +238,6 @@ void ZipFile::Flush() {
// empty // empty
} }
class D3MFZipArchive : public IOSystem { class D3MFZipArchive : public IOSystem {
public: public:
static const unsigned int FileNameSize = 256; static const unsigned int FileNameSize = 256;
@ -272,14 +262,12 @@ private:
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor. // Constructor.
D3MFZipArchive::D3MFZipArchive(IOSystem* pIOHandler, const std::string& rFile) D3MFZipArchive::D3MFZipArchive(IOSystem* pIOHandler, const std::string& rFile)
: m_ZipFileHandle(NULL), m_ArchiveMap() : m_ZipFileHandle(NULL)
{ , m_ArchiveMap() {
if (! rFile.empty()) if (! rFile.empty()) {
{
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler); zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
m_ZipFileHandle = unzOpen2(rFile.c_str(), &mapping); m_ZipFileHandle = unzOpen2(rFile.c_str(), &mapping);
if(m_ZipFileHandle != NULL) { if(m_ZipFileHandle != NULL) {
mapArchive(); mapArchive();
} }
@ -409,8 +397,7 @@ bool D3MFZipArchive::mapArchive() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
struct OpcPackageRelationship struct OpcPackageRelationship {
{
std::string id; std::string id;
std::string type; std::string type;
std::string target; std::string target;
@ -418,15 +405,10 @@ struct OpcPackageRelationship
typedef std::shared_ptr<OpcPackageRelationship> OpcPackageRelationshipPtr; typedef std::shared_ptr<OpcPackageRelationship> OpcPackageRelationshipPtr;
class OpcPackageRelationshipReader class OpcPackageRelationshipReader {
{
public: public:
OpcPackageRelationshipReader(XmlReader* xmlReader) {
OpcPackageRelationshipReader(XmlReader* xmlReader) while(xmlReader->read()) {
{
while(xmlReader->read())
{
if(xmlReader->getNodeType() == irr::io::EXN_ELEMENT && if(xmlReader->getNodeType() == irr::io::EXN_ELEMENT &&
xmlReader->getNodeName() == XmlTag::RELS_RELATIONSHIP_CONTAINER) xmlReader->getNodeName() == XmlTag::RELS_RELATIONSHIP_CONTAINER)
{ {

View File

@ -95,29 +95,30 @@ void ExportSceneGLTF2(const char*, IOSystem*, const aiScene*, const ExportProper
void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*); void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*);
void ExportSceneAssxml(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 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 // global array of all export formats which Assimp supports in its current build
Exporter::ExportFormatEntry gExporters[] = Exporter::ExportFormatEntry gExporters[] =
{ {
#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER #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 #endif
#ifndef ASSIMP_BUILD_NO_X_EXPORTER #ifndef ASSIMP_BUILD_NO_X_EXPORTER
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile, Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs), aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_STEP_EXPORTER #ifndef ASSIMP_BUILD_NO_STEP_EXPORTER
Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0), Exporter::ExportFormatEntry( "stp", "Step Files", "stp", &ExportSceneStep, 0 ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER #ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER
Exporter::ExportFormatEntry( "obj", "Wavefront OBJ format", "obj", &ExportSceneObj, 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, Exporter::ExportFormatEntry( "objnomtl", "Wavefront OBJ format without material file", "obj", &ExportSceneObjNoMtl,
aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */), aiProcess_GenSmoothNormals /*| aiProcess_PreTransformVertices */ ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_STL_EXPORTER #ifndef ASSIMP_BUILD_NO_STL_EXPORTER
@ -140,28 +141,32 @@ Exporter::ExportFormatEntry gExporters[] =
#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER #ifndef ASSIMP_BUILD_NO_3DS_EXPORTER
Exporter::ExportFormatEntry( "3ds", "Autodesk 3DS (legacy)", "3ds" , &ExportScene3DS, Exporter::ExportFormatEntry( "3ds", "Autodesk 3DS (legacy)", "3ds" , &ExportScene3DS,
aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices), aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER #ifndef ASSIMP_BUILD_NO_GLTF_EXPORTER
Exporter::ExportFormatEntry( "gltf", "GL Transmission Format", "gltf", &ExportSceneGLTF, 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, 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, Exporter::ExportFormatEntry( "gltf2", "GL Transmission Format v. 2", "gltf2", &ExportSceneGLTF2,
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType), aiProcess_JoinIdenticalVertices | aiProcess_Triangulate | aiProcess_SortByPType ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER #ifndef ASSIMP_BUILD_NO_ASSBIN_EXPORTER
Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0), Exporter::ExportFormatEntry( "assbin", "Assimp Binary", "assbin" , &ExportSceneAssbin, 0 ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER #ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0), Exporter::ExportFormatEntry( "assxml", "Assxml Document", "assxml" , &ExportSceneAssxml, 0 ),
#endif #endif
#ifndef ASSIMP_BUILD_NO_X3D_EXPORTER #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 #endif
}; };

View File

@ -43,8 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AbstractImportExportBase.h" #include "AbstractImportExportBase.h"
#include <assimp/Importer.hpp> #include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/scene.h> #include <assimp/scene.h>
#include "D3MFExporter.h"
class utD3MFImporterExporter : public AbstractImportExportBase { class utD3MFImporterExporter : public AbstractImportExportBase {
public: public:
virtual bool importerTest() { virtual bool importerTest() {
@ -58,8 +61,21 @@ public:
return ( nullptr != scene ); return ( nullptr != scene );
} }
virtual bool exporterTest() {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/3MF/box.3mf", 0 );
Assimp::Exporter exporter;
return nullptr != exporter.ExportToBlob( scene, "3mf", 0 );
}
}; };
TEST_F(utD3MFImporterExporter, import3MFFromFileTest) { TEST_F(utD3MFImporterExporter, import3MFFromFileTest) {
EXPECT_TRUE(importerTest()); EXPECT_TRUE(importerTest());
} }
TEST_F( utD3MFImporterExporter, export3MFtoMemTest ) {
EXPECT_TRUE( exporterTest() );
}