From 578a7ac5022f26facaef146390cedbd5229c347f Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Tue, 9 Jun 2020 11:20:48 -0700 Subject: [PATCH 01/12] add Callback API in ExporterProperties --- code/Common/Exporter.cpp | 16 ++++- include/assimp/Exporter.hpp | 135 +++++++++++++++++++----------------- 2 files changed, 87 insertions(+), 64 deletions(-) diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index c34457be5..e8ee188e6 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -580,10 +580,24 @@ ExportProperties::ExportProperties(const ExportProperties &other) : mIntProperties(other.mIntProperties) , mFloatProperties(other.mFloatProperties) , mStringProperties(other.mStringProperties) -, mMatrixProperties(other.mMatrixProperties) { +, mMatrixProperties(other.mMatrixProperties) +//wangyi 0608 +, mCallbackProperties(other.mCallbackProperties){ // empty } +//wangyi 0608 +bool ExportProperties::SetPropertyCallback(const char *szName, std::function &f) { + return SetGenericProperty>(mCallbackProperties, szName, f); +} +std::function ExportProperties::GetPropertyCallback(const char *szName) const { + return GetGenericProperty>(mCallbackProperties, szName, 0); +} +//wangyi 0608 +bool ExportProperties::HasPropertyCallback(const char *szName) const { + return HasGenericProperty>(mCallbackProperties, szName); +} + // ------------------------------------------------------------------------------------------------ // Set a configuration property bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) { diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index dc6661c11..4abea6ad0 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -47,16 +47,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_EXPORT_HPP_INC #ifdef __GNUC__ -# pragma GCC system_header +#pragma GCC system_header #endif #ifndef ASSIMP_BUILD_NO_EXPORT #include "cexport.h" #include +//wangyi 0608 +#include namespace Assimp { - + class ExporterPimpl; class IOSystem; class ProgressHandler; @@ -84,7 +86,7 @@ class ASSIMP_API ExportProperties; class ASSIMP_API Exporter { public: /** Function pointer type of a Export worker function */ - typedef void (*fpExportFunc)(const char*, IOSystem*, const aiScene*, const ExportProperties*); + typedef void (*fpExportFunc)(const char *, IOSystem *, const aiScene *, const ExportProperties *); /** Internal description of an Assimp export format option */ struct ExportFormatEntry { @@ -98,8 +100,7 @@ public: unsigned int mEnforcePP; // Constructor to fill all entries - ExportFormatEntry( const char* pId, const char* pDesc, const char* pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) - { + ExportFormatEntry(const char *pId, const char *pDesc, const char *pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) { mDescription.id = pId; mDescription.description = pDesc; mDescription.fileExtension = pExtension; @@ -108,9 +109,8 @@ public: } ExportFormatEntry() : - mExportFunction() - , mEnforcePP() - { + mExportFunction(), + mEnforcePP() { mDescription.id = NULL; mDescription.description = NULL; mDescription.fileExtension = NULL; @@ -142,7 +142,7 @@ public: * * @param pIOHandler The IO handler to be used in all file accesses * of the Importer. */ - void SetIOHandler( IOSystem* pIOHandler); + void SetIOHandler(IOSystem *pIOHandler); // ------------------------------------------------------------------- /** Retrieves the IO handler that is currently set. @@ -151,7 +151,7 @@ public: * handler is active as long the application doesn't supply its own * custom IO handler via #SetIOHandler(). * @return A valid IOSystem interface, never NULL. */ - IOSystem* GetIOHandler() const; + IOSystem *GetIOHandler() const; // ------------------------------------------------------------------- /** Checks whether a default IO handler is active @@ -171,7 +171,7 @@ public: * disable progress reporting. * @note Progress handlers can be used to abort the loading * at almost any time.*/ - void SetProgressHandler(ProgressHandler* pHandler); + void SetProgressHandler(ProgressHandler *pHandler); // ------------------------------------------------------------------- /** Exports the given scene to a chosen file format. Returns the exported @@ -191,10 +191,10 @@ public: * Any IO handlers set via #SetIOHandler are ignored here. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene. */ - const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); - const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); + const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const char *pFormatId, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); + const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const std::string &pFormatId, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Convenience function to export directly to a file. Use @@ -229,10 +229,10 @@ public: * @return AI_SUCCESS if everything was fine. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene.*/ - aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); - aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); + aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); + aiReturn Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Returns an error description of an error that occurred in #Export @@ -244,17 +244,17 @@ public: * * @note The returned function remains valid until one of the * following methods is called: #Export, #ExportToBlob, #FreeBlob */ - const char* GetErrorString() const; + const char *GetErrorString() const; // ------------------------------------------------------------------- /** Return the blob obtained from the last call to #ExportToBlob */ - const aiExportDataBlob* GetBlob() const; + const aiExportDataBlob *GetBlob() const; // ------------------------------------------------------------------- /** Orphan the blob from the last call to #ExportToBlob. This means * the caller takes ownership and is thus responsible for calling * the C API function #aiReleaseExportBlob to release it. */ - const aiExportDataBlob* GetOrphanedBlob() const; + const aiExportDataBlob *GetOrphanedBlob() const; // ------------------------------------------------------------------- /** Frees the current blob. @@ -264,7 +264,7 @@ public: * automatically by the destructor. The only reason to call * it manually would be to reclaim as much storage as possible * without giving up the #Exporter instance yet. */ - void FreeBlob( ); + void FreeBlob(); // ------------------------------------------------------------------- /** Returns the number of export file formats available in the current @@ -290,7 +290,7 @@ public: * 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* GetExportFormatDescription( size_t pIndex ) const; + const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const; // ------------------------------------------------------------------- /** Register a custom exporter. Custom export formats are limited to @@ -303,7 +303,7 @@ public: * registered. A common cause that would prevent an exporter * from being registered is that its format id is already * occupied by another format. */ - aiReturn RegisterExporter(const ExportFormatEntry& desc); + aiReturn RegisterExporter(const ExportFormatEntry &desc); // ------------------------------------------------------------------- /** Remove an export format previously registered with #RegisterExporter @@ -314,11 +314,11 @@ public: * 'id' field of #aiExportFormatDesc. * @note Calling this method on a format description not yet registered * has no effect.*/ - void UnregisterExporter(const char* id); + void UnregisterExporter(const char *id); protected: // Just because we don't want you to know how we're hacking around. - ExporterPimpl* pimpl; + ExporterPimpl *pimpl; }; class ASSIMP_API ExportProperties { @@ -332,6 +332,8 @@ public: typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; typedef std::map MatrixPropertyMap; + //wangyi 0608 + typedef std::map> CallbackPropertyMap; public: /** Standard constructor @@ -345,7 +347,7 @@ public: * This copies the configuration properties of another ExportProperties. * @see ExportProperties(const ExportProperties& other) */ - ExportProperties(const ExportProperties& other); + ExportProperties(const ExportProperties &other); // ------------------------------------------------------------------- /** Set an integer configuration property. @@ -360,7 +362,7 @@ public: * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ - bool SetPropertyInteger(const char* szName, int iValue); + bool SetPropertyInteger(const char *szName, int iValue); // ------------------------------------------------------------------- /** Set a boolean configuration property. Boolean properties @@ -369,27 +371,30 @@ public: * #GetPropertyBool and vice versa. * @see SetPropertyInteger() */ - bool SetPropertyBool(const char* szName, bool value) { - return SetPropertyInteger(szName,value); + bool SetPropertyBool(const char *szName, bool value) { + return SetPropertyInteger(szName, value); } // ------------------------------------------------------------------- /** Set a floating-point configuration property. * @see SetPropertyInteger() */ - bool SetPropertyFloat(const char* szName, ai_real fValue); + bool SetPropertyFloat(const char *szName, ai_real fValue); // ------------------------------------------------------------------- /** Set a string configuration property. * @see SetPropertyInteger() */ - bool SetPropertyString(const char* szName, const std::string& sValue); + bool SetPropertyString(const char *szName, const std::string &sValue); // ------------------------------------------------------------------- /** Set a matrix configuration property. * @see SetPropertyInteger() */ - bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue); + bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); + + //wangyi 0608 + bool SetPropertyCallback(const char *szName, std::function &f); // ------------------------------------------------------------------- /** Get a configuration property. @@ -404,8 +409,8 @@ public: * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ - int GetPropertyInteger(const char* szName, - int iErrorReturn = 0xffffffff) const; + int GetPropertyInteger(const char *szName, + int iErrorReturn = 0xffffffff) const; // ------------------------------------------------------------------- /** Get a boolean configuration property. Boolean properties @@ -414,16 +419,16 @@ public: * #GetPropertyBool and vice versa. * @see GetPropertyInteger() */ - bool GetPropertyBool(const char* szName, bool bErrorReturn = false) const { - return GetPropertyInteger(szName,bErrorReturn)!=0; + bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const { + return GetPropertyInteger(szName, bErrorReturn) != 0; } // ------------------------------------------------------------------- /** Get a floating-point configuration property * @see GetPropertyInteger() */ - ai_real GetPropertyFloat(const char* szName, - ai_real fErrorReturn = 10e10f) const; + ai_real GetPropertyFloat(const char *szName, + ai_real fErrorReturn = 10e10f) const; // ------------------------------------------------------------------- /** Get a string configuration property @@ -431,8 +436,8 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const std::string GetPropertyString(const char* szName, - const std::string& sErrorReturn = "") const; + const std::string GetPropertyString(const char *szName, + const std::string &sErrorReturn = "") const; // ------------------------------------------------------------------- /** Get a matrix configuration property @@ -440,37 +445,42 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const aiMatrix4x4 GetPropertyMatrix(const char* szName, - const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const; + const aiMatrix4x4 GetPropertyMatrix(const char *szName, + const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; - // ------------------------------------------------------------------- - /** Determine a integer configuration property has been set. + //wangyi 0608 + std::function GetPropertyCallback(const char* szName) const; + + // ------------------------------------------------------------------- + /** Determine a integer configuration property has been set. * @see HasPropertyInteger() */ - bool HasPropertyInteger(const char* szName) const; + bool HasPropertyInteger(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyBool() */ - bool HasPropertyBool(const char* szName) const; + bool HasPropertyBool(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyFloat() */ - bool HasPropertyFloat(const char* szName) const; + bool HasPropertyFloat(const char *szName) const; /** Determine a String configuration property has been set. * @see HasPropertyString() */ - bool HasPropertyString(const char* szName) const; + bool HasPropertyString(const char *szName) const; /** Determine a Matrix configuration property has been set. * @see HasPropertyMatrix() */ - bool HasPropertyMatrix(const char* szName) const; + bool HasPropertyMatrix(const char *szName) const; + + //wangyi 0608 + bool HasPropertyCallback(const char *szName) const; protected: - /** List of integer properties */ IntPropertyMap mIntProperties; @@ -482,23 +492,22 @@ protected: /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; + + //wangyi 0608 + CallbackPropertyMap mCallbackProperties; }; // ---------------------------------------------------------------------------------- -inline -const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const std::string& pFormatId, - unsigned int pPreprocessing, const ExportProperties* pProperties) -{ - return ExportToBlob(pScene,pFormatId.c_str(),pPreprocessing, pProperties); +inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId, + unsigned int pPreprocessing, const ExportProperties *pProperties) { + return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties); } // ---------------------------------------------------------------------------------- -inline -aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId, - const std::string& pPath, unsigned int pPreprocessing, - const ExportProperties* pProperties) -{ - return Export(pScene,pFormatId.c_str(),pPath.c_str(),pPreprocessing, pProperties); +inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId, + const std::string &pPath, unsigned int pPreprocessing, + const ExportProperties *pProperties) { + return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties); } } // namespace Assimp From f57e7221c07f385cebcc457d294e90c446995d41 Mon Sep 17 00:00:00 2001 From: ywang Date: Wed, 10 Jun 2020 13:23:29 -0700 Subject: [PATCH 02/12] temp --- code/AssetLib/glTF2/glTF2Exporter.cpp | 17 +++++++++++++++-- code/Common/Exporter.cpp | 2 +- include/assimp/Exporter.hpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 566f95e80..98eb79e57 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -115,7 +115,20 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportScene(); ExportAnimations(); - + + //wangyi 0608 + if(mProperties->HasPropertyCallback("extras")) + { + std::function ExportExtras = mProperties->GetPropertyCallback("extras"); + char* ret = (char*)ExportExtras((void*)mAsset.get()); + + Document extrasD; + extrasD.Parse(ret); + std::string strHello = extrasD["hello"].GetString(); + + printf("wangyi 0608 ret: %s\r\n", ret); + } + AssetWriter writer(*mAsset); if (isBinary) { diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index e8ee188e6..5fef455bb 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -587,7 +587,7 @@ ExportProperties::ExportProperties(const ExportProperties &other) } //wangyi 0608 -bool ExportProperties::SetPropertyCallback(const char *szName, std::function &f) { +bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } std::function ExportProperties::GetPropertyCallback(const char *szName) const { diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 4abea6ad0..87c12f374 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -394,7 +394,7 @@ public: bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); //wangyi 0608 - bool SetPropertyCallback(const char *szName, std::function &f); + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- /** Get a configuration property. From e65434bf8241a5408ff213dc315d5b8d3ed2f60e Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 11 Jun 2020 17:37:06 -0700 Subject: [PATCH 03/12] extra callback --- code/AssetLib/glTF2/glTF2Asset.h | 3 ++- code/AssetLib/glTF2/glTF2AssetWriter.inl | 6 +++++- code/AssetLib/glTF2/glTF2Exporter.cpp | 10 ++-------- code/Common/Exporter.cpp | 5 ++--- include/assimp/Exporter.hpp | 12 +++--------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index fc0fe1544..de252b329 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -1006,6 +1006,7 @@ public: } extensionsRequired; AssetMetadata asset; + Value* extras = nullptr; // Dictionaries for each type of object diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 361af40cd..0a4d0b2f4 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -600,6 +600,10 @@ namespace glTF2 { if (mAsset.scene) { mDoc.AddMember("scene", mAsset.scene->index, mAl); } + + if(mAsset.extras) { + mDoc.AddMember("extras", *mAsset.extras, mAl); + } } inline void AssetWriter::WriteFile(const char* path) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 98eb79e57..537787eb7 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -116,17 +116,11 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportAnimations(); - //wangyi 0608 + // export extras if(mProperties->HasPropertyCallback("extras")) { std::function ExportExtras = mProperties->GetPropertyCallback("extras"); - char* ret = (char*)ExportExtras((void*)mAsset.get()); - - Document extrasD; - extrasD.Parse(ret); - std::string strHello = extrasD["hello"].GetString(); - - printf("wangyi 0608 ret: %s\r\n", ret); + mAsset->extras = (rapidjson::Value*)ExportExtras(0); } AssetWriter writer(*mAsset); diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 5fef455bb..30ab3a813 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -581,19 +581,18 @@ ExportProperties::ExportProperties(const ExportProperties &other) , mFloatProperties(other.mFloatProperties) , mStringProperties(other.mStringProperties) , mMatrixProperties(other.mMatrixProperties) -//wangyi 0608 , mCallbackProperties(other.mCallbackProperties){ // empty } -//wangyi 0608 bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } + std::function ExportProperties::GetPropertyCallback(const char *szName) const { return GetGenericProperty>(mCallbackProperties, szName, 0); } -//wangyi 0608 + bool ExportProperties::HasPropertyCallback(const char *szName) const { return HasGenericProperty>(mCallbackProperties, szName); } diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 87c12f374..8e47e24db 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -54,7 +54,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cexport.h" #include -//wangyi 0608 #include namespace Assimp { @@ -332,7 +331,6 @@ public: typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; typedef std::map MatrixPropertyMap; - //wangyi 0608 typedef std::map> CallbackPropertyMap; public: @@ -392,8 +390,7 @@ public: * @see SetPropertyInteger() */ bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); - - //wangyi 0608 + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- @@ -448,7 +445,6 @@ public: const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; - //wangyi 0608 std::function GetPropertyCallback(const char* szName) const; // ------------------------------------------------------------------- @@ -476,8 +472,7 @@ public: * @see HasPropertyMatrix() */ bool HasPropertyMatrix(const char *szName) const; - - //wangyi 0608 + bool HasPropertyCallback(const char *szName) const; protected: @@ -492,8 +487,7 @@ protected: /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; - - //wangyi 0608 + CallbackPropertyMap mCallbackProperties; }; From 0b18d27042b37429a3f82fd546500411fe1360c2 Mon Sep 17 00:00:00 2001 From: Hill Ma Date: Sun, 28 Jun 2020 15:58:20 -0700 Subject: [PATCH 04/12] Use strrchr() when finding the '.' that begins the file extension. Sometimes we encounter file paths like ../foo/bar.obj; searching from the end of the string would yield the correct result. --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index bcc964efe..01704a1e4 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -376,7 +376,7 @@ int main(int argc, char **argv) // Check and validate the specified model file extension. model_file = argv[1]; - const char* extension = strchr(model_file, '.'); + const char* extension = strrchr(model_file, '.'); if (!extension) { print_error("Please provide a file with a valid extension."); return EXIT_FAILURE; From 30f09e9fc019a078228ea818ba7dc1a41b436a3c Mon Sep 17 00:00:00 2001 From: Hill Ma Date: Sun, 28 Jun 2020 17:36:21 -0700 Subject: [PATCH 05/12] Fix build when ASSIMP_DOUBLE_PRECISION is on. Tested: $ cmake -DASSIMP_DOUBLE_PRECISION=1 -DASSIMP_BUILD_MDL_IMPORTER=0 ..; make The MDL importer is disabled due to the fact that there is some float-only code in MDL. This also means bin/assimp and bin/unit would not link successfully with the above build flags. --- code/Common/Assimp.cpp | 2 +- code/Common/SpatialSort.cpp | 2 +- code/PostProcessing/ProcessHelper.h | 2 +- include/assimp/cimport.h | 2 +- test/unit/AssimpAPITest_aiMatrix4x4.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/code/Common/Assimp.cpp b/code/Common/Assimp.cpp index 33de72e0f..26aa52300 100644 --- a/code/Common/Assimp.cpp +++ b/code/Common/Assimp.cpp @@ -1079,7 +1079,7 @@ ASSIMP_API void aiMatrix4DecomposeIntoScalingAxisAnglePosition( const C_STRUCT aiMatrix4x4 *mat, C_STRUCT aiVector3D *scaling, C_STRUCT aiVector3D *axis, - float *angle, + ai_real *angle, C_STRUCT aiVector3D *position) { ai_assert(nullptr != mat); ai_assert(nullptr != scaling); diff --git a/code/Common/SpatialSort.cpp b/code/Common/SpatialSort.cpp index 86e22b242..3b8a64606 100644 --- a/code/Common/SpatialSort.cpp +++ b/code/Common/SpatialSort.cpp @@ -214,7 +214,7 @@ BinFloat ToBinary(const ai_real &pValue) { const bool OneComplement = ((-42 == ~42) && (binValue & 0x80000000)); if (DefaultValue) - return BinFloat(1 << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue; + return BinFloat(BinFloat(1) << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue; // One's complement? else if (OneComplement) return BinFloat(-0) - binValue; diff --git a/code/PostProcessing/ProcessHelper.h b/code/PostProcessing/ProcessHelper.h index 660555ef0..8520b21ec 100644 --- a/code/PostProcessing/ProcessHelper.h +++ b/code/PostProcessing/ProcessHelper.h @@ -222,7 +222,7 @@ template <> struct MinMaxChooser { void operator()(aiVertexWeight &min, aiVertexWeight &max) { MinMaxChooser()(min.mVertexId, max.mVertexId); - MinMaxChooser()(min.mWeight, max.mWeight); + MinMaxChooser()(min.mWeight, max.mWeight); } }; diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index a6ab93051..3e1b75a31 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -1044,7 +1044,7 @@ ASSIMP_API void aiMatrix4DecomposeIntoScalingAxisAnglePosition( const C_STRUCT aiMatrix4x4* mat, C_STRUCT aiVector3D* scaling, C_STRUCT aiVector3D* axis, - float* angle, + ai_real* angle, C_STRUCT aiVector3D* position); // -------------------------------------------------------------------------------- diff --git a/test/unit/AssimpAPITest_aiMatrix4x4.cpp b/test/unit/AssimpAPITest_aiMatrix4x4.cpp index 2c89726e0..89883dc0d 100644 --- a/test/unit/AssimpAPITest_aiMatrix4x4.cpp +++ b/test/unit/AssimpAPITest_aiMatrix4x4.cpp @@ -176,7 +176,7 @@ TEST_F(AssimpAPITest_aiMatrix4x4, aiMatrix4DecomposeIntoScalingAxisAnglePosition aiVector3D scaling_c, scaling_cpp, axis_c, axis_cpp, position_c, position_cpp; - float angle_c, angle_cpp; + ai_real angle_c, angle_cpp; result_c = result_cpp = get_predetermined_transformation_matrix_for_decomposition(); result_cpp.Decompose(scaling_cpp, axis_cpp, angle_cpp, position_cpp); From 03340787ecf769837fabc2b7ba9adfa6a46f4f66 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Mon, 29 Jun 2020 07:50:51 -0400 Subject: [PATCH 06/12] Fixed variable in loop - HL1MDLLoader.cpp Commit 7e5a0acc48efc54d7aa7900c36cd63db1fbeec9b made changes to HL1MDLLoader.cpp. Several variables have been renamed. A loop variable 'i' was renamed to faceIdx, but one reference was left unchanged. --- code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index 261214dac..2bb7b42ee 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -829,7 +829,7 @@ void HL1MDLLoader::read_meshes() { } } else { for (int faceIdx = 0; faceIdx < num_faces; ++faceIdx) { - if (i & 1) { + if (faceIdx & 1) { // Preserve winding order. mesh_faces.push_back(HL1MeshFace{ tricmds[faceIdx + 1], From 693da43095555a809d9d840a0ecc442ed3a3a00c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 2 Jul 2020 15:22:06 +0200 Subject: [PATCH 07/12] closes https://github.com/assimp/assimp/issues/3305: remove merge issue. --- code/AMF/AMFImporter.cpp | 707 --------------------------------------- 1 file changed, 707 deletions(-) delete mode 100644 code/AMF/AMFImporter.cpp diff --git a/code/AMF/AMFImporter.cpp b/code/AMF/AMFImporter.cpp deleted file mode 100644 index d93ca54cf..000000000 --- a/code/AMF/AMFImporter.cpp +++ /dev/null @@ -1,707 +0,0 @@ -/* ---------------------------------------------------------------------------- -Open Asset Import Library (assimp) ---------------------------------------------------------------------------- - -Copyright (c) 2006-2020, 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. ---------------------------------------------------------------------------- -*/ - -/// \file AMFImporter.cpp -/// \brief AMF-format files importer for Assimp: main algorithm implementation. -/// \date 2016 -/// \author smal.root@gmail.com - -#ifndef ASSIMP_BUILD_NO_AMF_IMPORTER - -// Header files, Assimp. -#include "AMFImporter.hpp" -#include "AMFImporter_Macro.hpp" - -#include -#include - -// Header files, stdlib. -#include - -namespace Assimp -{ - -/// \var aiImporterDesc AMFImporter::Description -/// Conastant which hold importer description -const aiImporterDesc AMFImporter::Description = { - "Additive manufacturing file format(AMF) Importer", - "smalcom", - "", - "See documentation in source code. Chapter: Limitations.", - aiImporterFlags_SupportTextFlavour | aiImporterFlags_LimitedSupport | aiImporterFlags_Experimental, - 0, - 0, - 0, - 0, - "amf" -}; - -void AMFImporter::Clear() -{ - mNodeElement_Cur = nullptr; - mUnit.clear(); - mMaterial_Converted.clear(); - mTexture_Converted.clear(); - // Delete all elements - if(!mNodeElement_List.empty()) - { - for(CAMFImporter_NodeElement* ne: mNodeElement_List) { delete ne; } - - mNodeElement_List.clear(); - } -} - -AMFImporter::~AMFImporter() -{ - if(mReader != nullptr) delete mReader; - // Clear() is accounting if data already is deleted. So, just check again if all data is deleted. - Clear(); -} - -/*********************************************************************************************************************************************/ -/************************************************************ Functions: find set ************************************************************/ -/*********************************************************************************************************************************************/ - -bool AMFImporter::Find_NodeElement(const std::string& pID, const CAMFImporter_NodeElement::EType pType, CAMFImporter_NodeElement** pNodeElement) const -{ - for(CAMFImporter_NodeElement* ne: mNodeElement_List) - { - if((ne->ID == pID) && (ne->Type == pType)) - { - if(pNodeElement != nullptr) *pNodeElement = ne; - - return true; - } - }// for(CAMFImporter_NodeElement* ne: mNodeElement_List) - - return false; -} - -bool AMFImporter::Find_ConvertedNode(const std::string& pID, std::list& pNodeList, aiNode** pNode) const -{ -aiString node_name(pID.c_str()); - - for(aiNode* node: pNodeList) - { - if(node->mName == node_name) - { - if(pNode != nullptr) *pNode = node; - - return true; - } - }// for(aiNode* node: pNodeList) - - return false; -} - -bool AMFImporter::Find_ConvertedMaterial(const std::string& pID, const SPP_Material** pConvertedMaterial) const -{ - for(const SPP_Material& mat: mMaterial_Converted) - { - if(mat.ID == pID) - { - if(pConvertedMaterial != nullptr) *pConvertedMaterial = &mat; - - return true; - } - }// for(const SPP_Material& mat: mMaterial_Converted) - - return false; -} - -/*********************************************************************************************************************************************/ -/************************************************************ Functions: throw set ***********************************************************/ -/*********************************************************************************************************************************************/ - -void AMFImporter::Throw_CloseNotFound(const std::string& pNode) -{ - throw DeadlyImportError("Close tag for node <" + pNode + "> not found. Seems file is corrupt."); -} - -void AMFImporter::Throw_IncorrectAttr(const std::string& pAttrName) -{ - throw DeadlyImportError("Node <" + std::string(mReader->getNodeName()) + "> has incorrect attribute \"" + pAttrName + "\"."); -} - -void AMFImporter::Throw_IncorrectAttrValue(const std::string& pAttrName) -{ - throw DeadlyImportError("Attribute \"" + pAttrName + "\" in node <" + std::string(mReader->getNodeName()) + "> has incorrect value."); -} - -void AMFImporter::Throw_MoreThanOnceDefined(const std::string& pNodeType, const std::string& pDescription) -{ - throw DeadlyImportError("\"" + pNodeType + "\" node can be used only once in " + mReader->getNodeName() + ". Description: " + pDescription); -} - -void AMFImporter::Throw_ID_NotFound(const std::string& pID) const -{ - throw DeadlyImportError("Not found node with name \"" + pID + "\"."); -} - -/*********************************************************************************************************************************************/ -/************************************************************* Functions: XML set ************************************************************/ -/*********************************************************************************************************************************************/ - -void AMFImporter::XML_CheckNode_MustHaveChildren() -{ - if(mReader->isEmptyElement()) throw DeadlyImportError(std::string("Node <") + mReader->getNodeName() + "> must have children."); -} - -void AMFImporter::XML_CheckNode_SkipUnsupported(const std::string& pParentNodeName) -{ - static const size_t Uns_Skip_Len = 3; - const char* Uns_Skip[Uns_Skip_Len] = { "composite", "edge", "normal" }; - - static bool skipped_before[Uns_Skip_Len] = { false, false, false }; - - std::string nn(mReader->getNodeName()); - bool found = false; - bool close_found = false; - size_t sk_idx; - - for(sk_idx = 0; sk_idx < Uns_Skip_Len; sk_idx++) - { - if(nn != Uns_Skip[sk_idx]) continue; - - found = true; - if(mReader->isEmptyElement()) - { - close_found = true; - - goto casu_cres; - } - - while(mReader->read()) - { - if((mReader->getNodeType() == irr::io::EXN_ELEMENT_END) && (nn == mReader->getNodeName())) - { - close_found = true; - - goto casu_cres; - } - } - }// for(sk_idx = 0; sk_idx < Uns_Skip_Len; sk_idx++) - -casu_cres: - - if(!found) throw DeadlyImportError("Unknown node \"" + nn + "\" in " + pParentNodeName + "."); - if(!close_found) Throw_CloseNotFound(nn); - - if(!skipped_before[sk_idx]) - { - skipped_before[sk_idx] = true; - ASSIMP_LOG_WARN_F("Skipping node \"", nn, "\" in ", pParentNodeName, "."); - } -} - -bool AMFImporter::XML_SearchNode(const std::string& pNodeName) -{ - while(mReader->read()) - { - if((mReader->getNodeType() == irr::io::EXN_ELEMENT) && XML_CheckNode_NameEqual(pNodeName)) return true; - } - - return false; -} - -bool AMFImporter::XML_ReadNode_GetAttrVal_AsBool(const int pAttrIdx) -{ - std::string val(mReader->getAttributeValue(pAttrIdx)); - - if((val == "false") || (val == "0")) - return false; - else if((val == "true") || (val == "1")) - return true; - else - throw DeadlyImportError("Bool attribute value can contain \"false\"/\"0\" or \"true\"/\"1\" not the \"" + val + "\""); -} - -float AMFImporter::XML_ReadNode_GetAttrVal_AsFloat(const int pAttrIdx) -{ - std::string val; - float tvalf; - - ParseHelper_FixTruncatedFloatString(mReader->getAttributeValue(pAttrIdx), val); - fast_atoreal_move(val.c_str(), tvalf, false); - - return tvalf; -} - -uint32_t AMFImporter::XML_ReadNode_GetAttrVal_AsU32(const int pAttrIdx) -{ - return strtoul10(mReader->getAttributeValue(pAttrIdx)); -} - -float AMFImporter::XML_ReadNode_GetVal_AsFloat() -{ - std::string val; - float tvalf; - - if(!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. No data, seems file is corrupt."); - if(mReader->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsFloat. Invalid type of XML element, seems file is corrupt."); - - ParseHelper_FixTruncatedFloatString(mReader->getNodeData(), val); - fast_atoreal_move(val.c_str(), tvalf, false); - - return tvalf; -} - -uint32_t AMFImporter::XML_ReadNode_GetVal_AsU32() -{ - if(!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. No data, seems file is corrupt."); - if(mReader->getNodeType() != irr::io::EXN_TEXT) throw DeadlyImportError("XML_ReadNode_GetVal_AsU32. Invalid type of XML element, seems file is corrupt."); - - return strtoul10(mReader->getNodeData()); -} - -void AMFImporter::XML_ReadNode_GetVal_AsString(std::string& pValue) -{ - if(!mReader->read()) throw DeadlyImportError("XML_ReadNode_GetVal_AsString. No data, seems file is corrupt."); - if(mReader->getNodeType() != irr::io::EXN_TEXT) - throw DeadlyImportError("XML_ReadNode_GetVal_AsString. Invalid type of XML element, seems file is corrupt."); - - pValue = mReader->getNodeData(); -} - -/*********************************************************************************************************************************************/ -/************************************************************ Functions: parse set ***********************************************************/ -/*********************************************************************************************************************************************/ - -void AMFImporter::ParseHelper_Node_Enter(CAMFImporter_NodeElement* pNode) -{ - mNodeElement_Cur->Child.push_back(pNode);// add new element to current element child list. - mNodeElement_Cur = pNode;// switch current element to new one. -} - -void AMFImporter::ParseHelper_Node_Exit() -{ - // check if we can walk up. - if(mNodeElement_Cur != nullptr) mNodeElement_Cur = mNodeElement_Cur->Parent; -} - -void AMFImporter::ParseHelper_FixTruncatedFloatString(const char* pInStr, std::string& pOutString) -{ - size_t instr_len; - - pOutString.clear(); - instr_len = strlen(pInStr); - if(!instr_len) return; - - pOutString.reserve(instr_len * 3 / 2); - // check and correct floats in format ".x". Must be "x.y". - if(pInStr[0] == '.') pOutString.push_back('0'); - - pOutString.push_back(pInStr[0]); - for(size_t ci = 1; ci < instr_len; ci++) - { - if((pInStr[ci] == '.') && ((pInStr[ci - 1] == ' ') || (pInStr[ci - 1] == '-') || (pInStr[ci - 1] == '+') || (pInStr[ci - 1] == '\t'))) - { - pOutString.push_back('0'); - pOutString.push_back('.'); - } - else - { - pOutString.push_back(pInStr[ci]); - } - } -} - -static bool ParseHelper_Decode_Base64_IsBase64(const char pChar) -{ - return (isalnum(pChar) || (pChar == '+') || (pChar == '/')); -} - -void AMFImporter::ParseHelper_Decode_Base64(const std::string& pInputBase64, std::vector& pOutputData) const -{ - // With help from - // René Nyffenegger http://www.adp-gmbh.ch/cpp/common/base64.html - const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - uint8_t tidx = 0; - uint8_t arr4[4], arr3[3]; - - // check input data - if(pInputBase64.size() % 4) throw DeadlyImportError("Base64-encoded data must have size multiply of four."); - // prepare output place - pOutputData.clear(); - pOutputData.reserve(pInputBase64.size() / 4 * 3); - - for(size_t in_len = pInputBase64.size(), in_idx = 0; (in_len > 0) && (pInputBase64[in_idx] != '='); in_len--) - { - if(ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx])) - { - arr4[tidx++] = pInputBase64[in_idx++]; - if(tidx == 4) - { - for(tidx = 0; tidx < 4; tidx++) arr4[tidx] = (uint8_t)base64_chars.find(arr4[tidx]); - - arr3[0] = (arr4[0] << 2) + ((arr4[1] & 0x30) >> 4); - arr3[1] = ((arr4[1] & 0x0F) << 4) + ((arr4[2] & 0x3C) >> 2); - arr3[2] = ((arr4[2] & 0x03) << 6) + arr4[3]; - for(tidx = 0; tidx < 3; tidx++) pOutputData.push_back(arr3[tidx]); - - tidx = 0; - }// if(tidx == 4) - }// if(ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx])) - else - { - in_idx++; - }// if(ParseHelper_Decode_Base64_IsBase64(pInputBase64[in_idx])) else - } - - if(tidx) - { - for(uint8_t i = tidx; i < 4; i++) arr4[i] = 0; - for(uint8_t i = 0; i < 4; i++) arr4[i] = (uint8_t)(base64_chars.find(arr4[i])); - - arr3[0] = (arr4[0] << 2) + ((arr4[1] & 0x30) >> 4); - arr3[1] = ((arr4[1] & 0x0F) << 4) + ((arr4[2] & 0x3C) >> 2); - arr3[2] = ((arr4[2] & 0x03) << 6) + arr4[3]; - for(uint8_t i = 0; i < (tidx - 1); i++) pOutputData.push_back(arr3[i]); - } -} - -void AMFImporter::ParseFile(const std::string& pFile, IOSystem* pIOHandler) -{ - irr::io::IrrXMLReader* OldReader = mReader;// store current XMLreader. - std::unique_ptr file(pIOHandler->Open(pFile, "rb")); - - // Check whether we can read from the file - if (file.get() == nullptr) { - throw DeadlyImportError("Failed to open AMF file " + pFile + "."); - } - - // generate a XML reader for it - std::unique_ptr mIOWrapper(new CIrrXML_IOStreamReader(file.get())); - mReader = irr::io::createIrrXMLReader(mIOWrapper.get()); - if(!mReader) throw DeadlyImportError("Failed to create XML reader for file" + pFile + "."); - // - // start reading - // search for root tag - if(XML_SearchNode("amf")) - ParseNode_Root(); - else - throw DeadlyImportError("Root node \"amf\" not found."); - - delete mReader; - // restore old XMLreader - mReader = OldReader; -} - -// -// -// Root XML element. -// Multi elements - No. -void AMFImporter::ParseNode_Root() -{ - std::string unit, version; - CAMFImporter_NodeElement *ne( nullptr ); - - // Read attributes for node . - MACRO_ATTRREAD_LOOPBEG; - MACRO_ATTRREAD_CHECK_RET("unit", unit, mReader->getAttributeValue); - MACRO_ATTRREAD_CHECK_RET("version", version, mReader->getAttributeValue); - MACRO_ATTRREAD_LOOPEND_WSKIP; - - // Check attributes - if(!mUnit.empty()) - { - if((mUnit != "inch") && (mUnit != "millimeter") && (mUnit != "meter") && (mUnit != "feet") && (mUnit != "micron")) Throw_IncorrectAttrValue("unit"); - } - - // create root node element. - ne = new CAMFImporter_NodeElement_Root(nullptr); - mNodeElement_Cur = ne;// set first "current" element - // and assign attribute's values - ((CAMFImporter_NodeElement_Root*)ne)->Unit = unit; - ((CAMFImporter_NodeElement_Root*)ne)->Version = version; - - // Check for child nodes - if(!mReader->isEmptyElement()) - { - MACRO_NODECHECK_LOOPBEGIN("amf"); - if(XML_CheckNode_NameEqual("object")) { ParseNode_Object(); continue; } - if(XML_CheckNode_NameEqual("material")) { ParseNode_Material(); continue; } - if(XML_CheckNode_NameEqual("texture")) { ParseNode_Texture(); continue; } - if(XML_CheckNode_NameEqual("constellation")) { ParseNode_Constellation(); continue; } - if(XML_CheckNode_NameEqual("metadata")) { ParseNode_Metadata(); continue; } - MACRO_NODECHECK_LOOPEND("amf"); - mNodeElement_Cur = ne;// force restore "current" element - }// if(!mReader->isEmptyElement()) - - mNodeElement_List.push_back(ne);// add to node element list because its a new object in graph. -} - -// -// -// A collection of objects or constellations with specific relative locations. -// Multi elements - Yes. -// Parent element - . -void AMFImporter::ParseNode_Constellation() -{ - std::string id; - CAMFImporter_NodeElement* ne( nullptr ); - - // Read attributes for node . - MACRO_ATTRREAD_LOOPBEG; - MACRO_ATTRREAD_CHECK_RET("id", id, mReader->getAttributeValue); - MACRO_ATTRREAD_LOOPEND; - - // create and if needed - define new grouping object. - ne = new CAMFImporter_NodeElement_Constellation(mNodeElement_Cur); - - CAMFImporter_NodeElement_Constellation& als = *((CAMFImporter_NodeElement_Constellation*)ne);// alias for convenience - - if(!id.empty()) als.ID = id; - // Check for child nodes - if(!mReader->isEmptyElement()) - { - ParseHelper_Node_Enter(ne); - MACRO_NODECHECK_LOOPBEGIN("constellation"); - if(XML_CheckNode_NameEqual("instance")) { ParseNode_Instance(); continue; } - if(XML_CheckNode_NameEqual("metadata")) { ParseNode_Metadata(); continue; } - MACRO_NODECHECK_LOOPEND("constellation"); - ParseHelper_Node_Exit(); - }// if(!mReader->isEmptyElement()) - else - { - mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element - }// if(!mReader->isEmptyElement()) else - - mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph. -} - -// -// -// A collection of objects or constellations with specific relative locations. -// Multi elements - Yes. -// Parent element - . -void AMFImporter::ParseNode_Instance() -{ - std::string objectid; - CAMFImporter_NodeElement* ne( nullptr ); - - // Read attributes for node . - MACRO_ATTRREAD_LOOPBEG; - MACRO_ATTRREAD_CHECK_RET("objectid", objectid, mReader->getAttributeValue); - MACRO_ATTRREAD_LOOPEND; - - // used object id must be defined, check that. - if(objectid.empty()) throw DeadlyImportError("\"objectid\" in must be defined."); - // create and define new grouping object. - ne = new CAMFImporter_NodeElement_Instance(mNodeElement_Cur); - - CAMFImporter_NodeElement_Instance& als = *((CAMFImporter_NodeElement_Instance*)ne);// alias for convenience - - als.ObjectID = objectid; - // Check for child nodes - if(!mReader->isEmptyElement()) - { - bool read_flag[6] = { false, false, false, false, false, false }; - - als.Delta.Set(0, 0, 0); - als.Rotation.Set(0, 0, 0); - ParseHelper_Node_Enter(ne); - MACRO_NODECHECK_LOOPBEGIN("instance"); - MACRO_NODECHECK_READCOMP_F("deltax", read_flag[0], als.Delta.x); - MACRO_NODECHECK_READCOMP_F("deltay", read_flag[1], als.Delta.y); - MACRO_NODECHECK_READCOMP_F("deltaz", read_flag[2], als.Delta.z); - MACRO_NODECHECK_READCOMP_F("rx", read_flag[3], als.Rotation.x); - MACRO_NODECHECK_READCOMP_F("ry", read_flag[4], als.Rotation.y); - MACRO_NODECHECK_READCOMP_F("rz", read_flag[5], als.Rotation.z); - MACRO_NODECHECK_LOOPEND("instance"); - ParseHelper_Node_Exit(); - // also convert degrees to radians. - als.Rotation.x = AI_MATH_PI_F * als.Rotation.x / 180.0f; - als.Rotation.y = AI_MATH_PI_F * als.Rotation.y / 180.0f; - als.Rotation.z = AI_MATH_PI_F * als.Rotation.z / 180.0f; - }// if(!mReader->isEmptyElement()) - else - { - mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element - }// if(!mReader->isEmptyElement()) else - - mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph. -} - -// -// -// An object definition. -// Multi elements - Yes. -// Parent element - . -void AMFImporter::ParseNode_Object() -{ - std::string id; - CAMFImporter_NodeElement* ne( nullptr ); - - // Read attributes for node . - MACRO_ATTRREAD_LOOPBEG; - MACRO_ATTRREAD_CHECK_RET("id", id, mReader->getAttributeValue); - MACRO_ATTRREAD_LOOPEND; - - // create and if needed - define new geometry object. - ne = new CAMFImporter_NodeElement_Object(mNodeElement_Cur); - - CAMFImporter_NodeElement_Object& als = *((CAMFImporter_NodeElement_Object*)ne);// alias for convenience - - if(!id.empty()) als.ID = id; - // Check for child nodes - if(!mReader->isEmptyElement()) - { - bool col_read = false; - - ParseHelper_Node_Enter(ne); - MACRO_NODECHECK_LOOPBEGIN("object"); - if(XML_CheckNode_NameEqual("color")) - { - // Check if color already defined for object. - if(col_read) Throw_MoreThanOnceDefined("color", "Only one color can be defined for ."); - // read data and set flag about it - ParseNode_Color(); - col_read = true; - - continue; - } - - if(XML_CheckNode_NameEqual("mesh")) { ParseNode_Mesh(); continue; } - if(XML_CheckNode_NameEqual("metadata")) { ParseNode_Metadata(); continue; } - MACRO_NODECHECK_LOOPEND("object"); - ParseHelper_Node_Exit(); - }// if(!mReader->isEmptyElement()) - else - { - mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element - }// if(!mReader->isEmptyElement()) else - - mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph. -} - -// -// -// Specify additional information about an entity. -// Multi elements - Yes. -// Parent element - , , , , . -// -// Reserved types are: -// "Name" - The alphanumeric label of the entity, to be used by the interpreter if interacting with the user. -// "Description" - A description of the content of the entity -// "URL" - A link to an external resource relating to the entity -// "Author" - Specifies the name(s) of the author(s) of the entity -// "Company" - Specifying the company generating the entity -// "CAD" - specifies the name of the originating CAD software and version -// "Revision" - specifies the revision of the entity -// "Tolerance" - specifies the desired manufacturing tolerance of the entity in entity's unit system -// "Volume" - specifies the total volume of the entity, in the entity's unit system, to be used for verification (object and volume only) -void AMFImporter::ParseNode_Metadata() -{ - std::string type, value; - CAMFImporter_NodeElement* ne( nullptr ); - - // read attribute - MACRO_ATTRREAD_LOOPBEG; - MACRO_ATTRREAD_CHECK_RET("type", type, mReader->getAttributeValue); - MACRO_ATTRREAD_LOOPEND; - // and value of node. - value = mReader->getNodeData(); - // Create node element and assign read data. - ne = new CAMFImporter_NodeElement_Metadata(mNodeElement_Cur); - ((CAMFImporter_NodeElement_Metadata*)ne)->Type = type; - ((CAMFImporter_NodeElement_Metadata*)ne)->Value = value; - mNodeElement_Cur->Child.push_back(ne);// Add element to child list of current element - mNodeElement_List.push_back(ne);// and to node element list because its a new object in graph. -} - -/*********************************************************************************************************************************************/ -/******************************************************** Functions: BaseImporter set ********************************************************/ -/*********************************************************************************************************************************************/ - -bool AMFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool pCheckSig) const -{ - const std::string extension = GetExtension(pFile); - - if ( extension == "amf" ) { - return true; - } - - if(!extension.length() || pCheckSig) - { - const char* tokens[] = { "& pExtensionList) -{ - pExtensionList.insert("amf"); -} - -const aiImporterDesc* AMFImporter::GetInfo () const -{ - return &Description; -} - -void AMFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) -{ - Clear();// delete old graph. - ParseFile(pFile, pIOHandler); - Postprocess_BuildScene(pScene); - // scene graph is ready, exit. -} - -}// namespace Assimp - -#endif // !ASSIMP_BUILD_NO_AMF_IMPORTER From 51150cb3dfa13afaf829b005b68fae00253a7c96 Mon Sep 17 00:00:00 2001 From: Malcolm Tyrrell Date: Thu, 2 Jul 2020 14:53:29 +0100 Subject: [PATCH 08/12] Ensure asserts are defined where expected. --- code/PostProcessing/ArmaturePopulate.cpp | 1 - include/assimp/ai_assert.h | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index 97feca31c..48dcecb15 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -168,7 +168,6 @@ void ArmaturePopulate::BuildBoneStack(aiNode *, const std::vector &bones, std::map &bone_stack, std::vector &node_stack) { - ai_assert(scene); ai_assert(root_node); ai_assert(!node_stack.empty()); diff --git a/include/assimp/ai_assert.h b/include/assimp/ai_assert.h index 8b2b396f4..195ebbfd0 100644 --- a/include/assimp/ai_assert.h +++ b/include/assimp/ai_assert.h @@ -42,12 +42,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_ASSERT_H_INC #define AI_ASSERT_H_INC +#include + #if defined(ASSIMP_BUILD_DEBUG) namespace Assimp { // Assert violation behavior can be customized: see AssertHandler.h. - void aiAssertViolation(const char* failedExpression, const char* file, int line); + ASSIMP_API void aiAssertViolation(const char* failedExpression, const char* file, int line); } # define ai_assert(expression) (void)((!!(expression)) || (Assimp::aiAssertViolation(#expression, __FILE__, __LINE__), 0)) From 3fb7747429c2f773fc40dd6e437a1da9cbbae9b7 Mon Sep 17 00:00:00 2001 From: Hill Ma Date: Fri, 3 Jul 2020 18:14:45 -0700 Subject: [PATCH 09/12] Improve ToBinary() for double precision. The constant 0x80000000 is specific to 32 bit types. Make the bit mask according to the size of types. --- code/Common/SpatialSort.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/Common/SpatialSort.cpp b/code/Common/SpatialSort.cpp index 3b8a64606..88f06b618 100644 --- a/code/Common/SpatialSort.cpp +++ b/code/Common/SpatialSort.cpp @@ -208,13 +208,14 @@ BinFloat ToBinary(const ai_real &pValue) { // floating-point numbers are of sign-magnitude format, so find out what signed number // representation we must convert negative values to. // See http://en.wikipedia.org/wiki/Signed_number_representations. + const BinFloat mask = BinFloat(1) << (CHAR_BIT * sizeof(BinFloat) - 1); // Two's complement? - const bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & 0x80000000)); - const bool OneComplement = ((-42 == ~42) && (binValue & 0x80000000)); + const bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & mask)); + const bool OneComplement = ((-42 == ~42) && (binValue & mask)); if (DefaultValue) - return BinFloat(BinFloat(1) << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue; + return mask - binValue; // One's complement? else if (OneComplement) return BinFloat(-0) - binValue; From 9aa468262f615dee390e3ce1bf34cdc14a676fa5 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Tue, 7 Jul 2020 17:35:03 +0200 Subject: [PATCH 10/12] closes https://github.com/assimp/assimp/issues/3252: fix build. --- code/AssetLib/3DS/3DSHelper.h | 2 +- code/AssetLib/IFC/IFCReaderGen_2x3.h | 2 +- code/AssetLib/M3D/m3d.h | 4 +++- code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp | 4 ++-- code/AssetLib/Step/STEPFile.h | 6 +++--- code/Common/Exporter.cpp | 4 ++-- code/Common/Subdivision.cpp | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 89c15f5f2..3ccb1fd07 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -321,7 +321,7 @@ public: struct Face : public FaceWithSmoothingGroup { }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(disable : 4315) #endif diff --git a/code/AssetLib/IFC/IFCReaderGen_2x3.h b/code/AssetLib/IFC/IFCReaderGen_2x3.h index 8ae623dd8..b3f71a7f1 100644 --- a/code/AssetLib/IFC/IFCReaderGen_2x3.h +++ b/code/AssetLib/IFC/IFCReaderGen_2x3.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssetLib/Step/STEPFile.h" -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning( disable : 4512 ) #endif // _WIN32 diff --git a/code/AssetLib/M3D/m3d.h b/code/AssetLib/M3D/m3d.h index 3d7a2564c..5ab3d16de 100644 --- a/code/AssetLib/M3D/m3d.h +++ b/code/AssetLib/M3D/m3d.h @@ -85,7 +85,9 @@ typedef uint16_t M3D_INDEX; #define M3D_BONEMAXLEVEL 8 #endif #ifndef _MSC_VER +#ifndef _inline #define _inline __inline__ +#endif #define _pack __attribute__((packed)) #define _unused __attribute__((unused)) #else @@ -99,7 +101,7 @@ typedef uint16_t M3D_INDEX; #define _register #endif -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning(push) # pragma warning(disable : 4100 4127 4189 4505 4244 4403 4701 4703) # if (_MSC_VER > 1800 ) diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index 2bb7b42ee..e9930dfed 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -68,8 +68,8 @@ namespace Assimp { namespace MDL { namespace HalfLife { -#ifdef _WIN32 -# pragma warning(disable : 4706) +#if _MSC_VER > 1920 +# pragma warning(disable : 4706) #endif // _WIN32 // ------------------------------------------------------------------------------------------------ diff --git a/code/AssetLib/Step/STEPFile.h b/code/AssetLib/Step/STEPFile.h index 1448c107f..72648e462 100644 --- a/code/AssetLib/Step/STEPFile.h +++ b/code/AssetLib/Step/STEPFile.h @@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning(push) # pragma warning(disable : 4127 4456 4245 4512 ) #endif // _WIN32 @@ -727,7 +727,7 @@ struct InternGenericConvert> { } }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(push) #pragma warning(disable : 4127) #endif // _WIN32 @@ -960,7 +960,7 @@ private: const EXPRESS::ConversionSchema *schema; }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(pop) #endif // _WIN32 diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 58fc01d91..a47c52a6c 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -74,8 +74,8 @@ Here we implement only the C++ interface (Assimp::Exporter). namespace Assimp { -#ifdef _WIN32 -# pragma warning( disable : 4800 ) +#if _MSC_VER > 1920 +# pragma warning( disable : 4800 ) #endif // _WIN32 diff --git a/code/Common/Subdivision.cpp b/code/Common/Subdivision.cpp index b1f07c9f5..4f64a00c4 100644 --- a/code/Common/Subdivision.cpp +++ b/code/Common/Subdivision.cpp @@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; void mydummy() {} -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(disable : 4709) #endif // _WIN32 // ------------------------------------------------------------------------------------------------ From b8ec93aa2137d18e8fb861df17fb6878b8e7d656 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 11 Jul 2020 22:34:43 +0200 Subject: [PATCH 11/12] use c-styl cast in a c-file --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index 01704a1e4..bcb109564 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -278,7 +278,7 @@ void do_motion (void) static int frames = 0; int time = glutGet(GLUT_ELAPSED_TIME); - angle += static_cast((time-prev_time)*0.01); + angle += (float)((time-prev_time)*0.01); prev_time = time; frames += 1; From 108b3a62e5b1ace725f3ddee06a701eddc19199e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 11 Jul 2020 22:45:45 +0200 Subject: [PATCH 12/12] Update Exporter.hpp revert merge issue --- include/assimp/Exporter.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 6fcbafe92..15918dd47 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -110,9 +110,9 @@ public: ExportFormatEntry() : mExportFunction(), mEnforcePP() { - mDescription.id = NULL; - mDescription.description = NULL; - mDescription.fileExtension = NULL; + mDescription.id = nullptr; + mDescription.description = nullptr; + mDescription.fileExtension = nullptr; } };