From e5f7fe0c3ab6b2b92176dab2dbed6d83679b48d8 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Wed, 5 Jan 2011 22:07:51 +0000 Subject: [PATCH] - More work on the current draft of the export interface. Again, please comment. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@886 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/Exporter.cpp | 122 +++++++++++++++++++++++ include/assimp.hpp | 1 + include/export.h | 31 ++++-- include/export.hpp | 183 +++++++++++++++++++++++++++++++++++ workspaces/vc9/assimp.vcproj | 10 +- 5 files changed, 338 insertions(+), 9 deletions(-) create mode 100644 code/Exporter.cpp create mode 100644 include/export.hpp diff --git a/code/Exporter.cpp b/code/Exporter.cpp new file mode 100644 index 000000000..db359adcc --- /dev/null +++ b/code/Exporter.cpp @@ -0,0 +1,122 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (ASSIMP) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2010, ASSIMP Development 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 Development 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. +--------------------------------------------------------------------------- +*/ + +#include "AssimpPCH.h" + +#if 0 + +// ------------------------------------------------------------------------------------------------ +// Exporters +// ------------------------------------------------------------------------------------------------ +#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER +//# include "ColladaExporter.h" +void ExportSceneCollada (aiExportDataBlob*, const aiScene*); +#endif +#ifndef ASSIMP_BUILD_NO_3DS_EXPORTER +void ExportScene3DS(aiExportDataBlob*, const aiScene*); +#endif + + +// ------------------------------------------------------------------------------------------------ +// Table of export format descriptors along with the corresponding exporter functions +// ------------------------------------------------------------------------------------------------ +namespace Assimp { + + typedef void (*fpExportFunc) (aiExportDataBlob*, const aiScene*) /* throw DeadlyExportError */; + + // + aiExportFormatDesc g_aExportInfo[] = { + { + "collada" + , "COLLADA Open Standard for Painful Asset Interchange" + , "dae" + }, + { + "3ds" + , "Autodesk(tm) 3DS file format" + , "3ds" + } + }; + + fpExportFunc g_aExportFunctions[] = { + ExportSceneCollada, + ExportScene3DS + }; +} + + + +// ------------------------------------------------------------------------------------------------ +ASSIMP_API size_t aiGetExportFormatCount(void) +{ + return 0; +} + + +// ------------------------------------------------------------------------------------------------ +ASSIMP_API const C_STRUCT aiExportFormatDesc* aiGetExportFormatDescription( size_t pIndex) +{ + return NULL; +} + + +// ------------------------------------------------------------------------------------------------ +ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportScene( const aiScene* pScene, const char* pFormatId ) +{ + return NULL; +} + + +// ------------------------------------------------------------------------------------------------ +ASSIMP_API C_STRUCT aiReturn aiWriteBlobToFile( const C_STRUCT aiExportDataBlob* pBlob, const char* pPath, const aiFileIO* pIOSystem ) +{ + return AI_FAILURE; +} + + +// ------------------------------------------------------------------------------------------------ +ASSIMP_API C_STRUCT void aiReleaseExportData( const aiExportDataBlob* pData ) +{ + delete pData; +} + + +#endif diff --git a/include/assimp.hpp b/include/assimp.hpp index 5c89e58a2..94e7fb1a5 100644 --- a/include/assimp.hpp +++ b/include/assimp.hpp @@ -58,6 +58,7 @@ namespace Assimp { // ======================================================================= // Public interface to Assimp class Importer; + class Exporter; // export.hpp class IOStream; class IOSystem; class ProgressHandler; diff --git a/include/export.h b/include/export.h index 31860e5f8..d45582f7d 100644 --- a/include/export.h +++ b/include/export.h @@ -44,6 +44,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef AI_EXPORT_H_INC #define AI_EXPORT_H_INC + +#ifndef ASSIMP_BUILD_NO_EXPORT + #include "aiTypes.h" #ifdef __cplusplus @@ -67,13 +70,8 @@ struct aiExportFormatDesc /// to allow the user to select an export format. const char* description; - /// Recommended file extension for the exported file + /// Recommended file extension for the exported file in lower case. const char* fileExtension; - -#ifdef __cplusplus - /// Default constructor - aiExportFormatDesc() { id = description = fileExtension = NULL; } -#endif // __cplusplus }; /** Returns the number of export file formats available in the current Assimp build. @@ -112,6 +110,8 @@ struct aiExportDataBlob #endif // __cplusplus }; + +// -------------------------------------------------------------------------------- /** Exports the given scene to a chosen file format. Returns the exported data as a binary blob which * you can write into a file or something. When you're done with the data, use aiReleaseExportedData() * to free the resources associated with the export. @@ -120,16 +120,31 @@ struct aiExportDataBlob * aiGetExportFormatCount() / aiGetExportFormatDescription() to learn which export formats are available. * @return the exported data or NULL in case of error */ -ASSIMP_API C_STRUCT aiExportDataBlob* aiExportScene( const aiScene* pScene, const char* pFormatId); +ASSIMP_API const C_STRUCT aiExportDataBlob* aiExportScene( const C_STRUCT aiScene* pScene, const char* pFormatId ); + +// -------------------------------------------------------------------------------- +/** Convenience function to write a blob to a file. The file is written using standard C + * file IO functionality or via a user-supplied IOSystem implementation. + * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be NULL. + * @param pPath Full target file name. Target must be accessible. + * @param pIOSystem Custom IO implementation to be used for writing. Pass NULL to + * use the default implementation, which uses the standard C file IO functionality. + * @return AI_SUCCESS if everything was fine. */ +ASSIMP_API aiReturn aiWriteBlobToFile( const C_STRUCT aiExportDataBlob* pBlob, const char* pPath, const C_STRUCT aiFileIO* pIOSystem ); + + +// -------------------------------------------------------------------------------- /** Releases the memory associated with the given exported data. Use this function to free a data blob * returned by aiExportScene(). * @param pData the data blob returned by aiExportScene */ -ASSIMP_API C_STRUCT void aiReleaseExportData( aiExportDataBlob* pData); +ASSIMP_API C_STRUCT void aiReleaseExportData( const C_STRUCT aiExportDataBlob* pData ); #ifdef __cplusplus } #endif +#endif // ASSIMP_BUILD_NO_EXPORT #endif // AI_EXPORT_H_INC + diff --git a/include/export.hpp b/include/export.hpp new file mode 100644 index 000000000..2049d2f9b --- /dev/null +++ b/include/export.hpp @@ -0,0 +1,183 @@ +/* +--------------------------------------------------------------------------- +Open Asset Import Library (ASSIMP) +--------------------------------------------------------------------------- + +Copyright (c) 2006-2011, ASSIMP Development 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 Development 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. +--------------------------------------------------------------------------- +*/ + +/** @file export.hpp +* @brief Defines the CPP-API for the Assimp export interface +*/ +#ifndef AI_EXPORT_HPP_INC +#define AI_EXPORT_HPP_INC + +#ifndef ASSIMP_BUILD_NO_EXPORT + +#include "export.h" + +namespace Assimp { + +class ASSIMP_API Exporter +#ifdef __cplusplus + : public boost::noncopyable +#endif // __cplusplus +{ +public: + + + Exporter() : blob() { + } + + + ~Exporter() { + if (blob) { + ::aiReleaseExportData(blob); + } + } + +public: + + // ------------------------------------------------------------------- + /** Exports the given scene to a chosen file format. Returns the exported + * data as a binary blob which you can write into a file or something. + * When you're done with the data, simply let the #Exporter instance go + * out of scope to have it released automatically. + * @param pScene The scene to export. Stays in possession of the caller, + * is not changed by the function. + * @param pFormatId ID string to specify to which format you want to + * export to. Use + * #GetExportFormatCount / #GetExportFormatDescription to learn which + * export formats are available. + * @return the exported data or NULL in case of error. + * @note If the Exporter instance did already hold a blob from + * a previous call to #ExportToBlob, it will be disposed. */ + const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const char* pFormatId ) { + if (blob) { + ::aiReleaseExportData(blob); + } + + return blob = ::aiExportScene(pScene,pFormatId); + } + + + // ------------------------------------------------------------------- + /** Convenience function to export directly to a file. + * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be NULL. + * @param pPath Full target file name. Target must be accessible. + * @return AI_SUCCESS if everything was fine. */ + aiReturn ExportToFile( const aiScene* pScene, const char* pFormatId, const char* pPath ) { + + if(!ExportToBlob(pScene,pFormatId)) { + return AI_FAILURE; + } + + + return WriteBlobToFile(pPath); + } + + + // ------------------------------------------------------------------- + /** Convenience function to write a blob to a file. + * @param pBlob A data blob obtained from a previous call to #aiExportScene. Must not be NULL. + * @param pPath Full target file name. Target must be accessible. + * @return AI_SUCCESS if everything was fine. */ + aiReturn WriteBlobToFile( const char* pPath ) const { + if (!blob) { + return AI_FAILURE; + } + + // TODO + return AI_FAILURE; // ::aiWriteBlobToFile(blob,pPath,mIOSystem); + } + + + // ------------------------------------------------------------------- + aiReturn WriteBlobToFile( const std::string& pPath ) const { + return WriteBlobToFile(pPath.c_str()); + } + + + // ------------------------------------------------------------------- + /** Return the blob obtained from the last call to #ExportToBlob */ + const aiExportDataBlob* GetBlob() const { + return blob; + } + + + // ------------------------------------------------------------------- + /** Orphan the blob from the last call to #ExportToBlob. That means + * the caller takes ownership and is thus responsible for calling + * #aiReleaseExportData to free the data again. */ + const aiExportDataBlob* GetOrphanedBlob() const { + const aiExportDataBlob* tmp = blob; + blob = NULL; + return tmp; + } + + + // ------------------------------------------------------------------- + /** Returns the number of export file formats available in the current + * Assimp build. Use #Exporter::GetExportFormatDescription to + * retrieve infos of a specific export format */ + size_t aiGetExportFormatCount() const { + return ::aiGetExportFormatCount(); + } + + + // ------------------------------------------------------------------- + /** Returns a description of the nth export file format. Use # + * #Exporter::GetExportFormatCount to learn how many export + * formats are supported. + * @param pIndex Index of the export format to retrieve information + * for. Valid range is 0 to #Exporter::GetExportFormatCount + * @return A description of that specific export format. + * NULL if pIndex is out of range. */ + const aiExportFormatDesc* aiGetExportFormatDescription( size_t pIndex ) const { + return ::aiGetExportFormatDescription(pIndex); + } + + +private: + + const aiExportDataBlob* blob; + Assimp::IOSystem* mIOSystem; +}; + +} // namespace Assimp +#endif // ASSIMP_BUILD_NO_EXPORT +#endif // AI_EXPORT_HPP_INC + diff --git a/workspaces/vc9/assimp.vcproj b/workspaces/vc9/assimp.vcproj index 34032c181..0867d9839 100644 --- a/workspaces/vc9/assimp.vcproj +++ b/workspaces/vc9/assimp.vcproj @@ -1,7 +1,7 @@ + + @@ -2326,6 +2330,10 @@ RelativePath="..\..\code\Exceptional.h" > + +