From 843e56c252cae442c727f39b6f656bb3057a89e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Terziman?= Date: Fri, 28 Feb 2014 15:21:10 +0100 Subject: [PATCH] Added matrix properties --- code/Assimp.cpp | 16 ++++++++++++++++ code/BaseImporter.cpp | 1 + code/Importer.cpp | 19 +++++++++++++++++++ code/Importer.h | 11 ++++++++--- include/assimp/Importer.hpp | 16 ++++++++++++++++ include/assimp/cimport.h | 18 ++++++++++++++++++ 6 files changed, 78 insertions(+), 3 deletions(-) diff --git a/code/Assimp.cpp b/code/Assimp.cpp index ce05468f7..b11951854 100644 --- a/code/Assimp.cpp +++ b/code/Assimp.cpp @@ -172,6 +172,7 @@ const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFl pimpl->mIntProperties = pp->ints; pimpl->mFloatProperties = pp->floats; pimpl->mStringProperties = pp->strings; + pimpl->mMatrixProperties = pp->matrices; } // setup a custom IO system if necessary if (pFS) { @@ -230,6 +231,7 @@ const aiScene* aiImportFileFromMemoryWithProperties( pimpl->mIntProperties = pp->ints; pimpl->mFloatProperties = pp->floats; pimpl->mStringProperties = pp->strings; + pimpl->mMatrixProperties = pp->matrices; } // and have it read the file from the memory buffer @@ -504,6 +506,20 @@ ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName ASSIMP_END_EXCEPTION_REGION(void); } +// ------------------------------------------------------------------------------------------------ +// Importer::SetPropertyMatrix +ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName, + const C_STRUCT aiMatrix4x4* mat) +{ + if (!mat) { + return; + } + ASSIMP_BEGIN_EXCEPTION_REGION(); + PropertyMap* pp = reinterpret_cast(p); + SetGenericProperty(pp->matrices,szName,*mat,NULL); + ASSIMP_END_EXCEPTION_REGION(void); +} + // ------------------------------------------------------------------------------------------------ // Rotation matrix to quaternion ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat) diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index dab4eb003..b43c1c40f 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -578,6 +578,7 @@ void BatchLoader::LoadAll() pimpl->mFloatProperties = (*it).map.floats; pimpl->mIntProperties = (*it).map.ints; pimpl->mStringProperties = (*it).map.strings; + pimpl->mMatrixProperties = (*it).map.matrices; if (!DefaultLogger::isNullLogger()) { diff --git a/code/Importer.cpp b/code/Importer.cpp index 1445299e1..1ad2ea498 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -197,6 +197,7 @@ Importer::Importer(const Importer &other) pimpl->mIntProperties = other.pimpl->mIntProperties; pimpl->mFloatProperties = other.pimpl->mFloatProperties; pimpl->mStringProperties = other.pimpl->mStringProperties; + pimpl->mMatrixProperties = other.pimpl->mMatrixProperties; } // ------------------------------------------------------------------------------------------------ @@ -937,6 +938,16 @@ void Importer::SetPropertyString(const char* szName, const std::string& value, ASSIMP_END_EXCEPTION_REGION(void); } +// ------------------------------------------------------------------------------------------------ +// Set a configuration property +void Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value, + bool* bWasExisting /*= NULL*/) +{ + ASSIMP_BEGIN_EXCEPTION_REGION(); + SetGenericProperty(pimpl->mMatrixProperties, szName,value,bWasExisting); + ASSIMP_END_EXCEPTION_REGION(void); +} + // ------------------------------------------------------------------------------------------------ // Get a configuration property int Importer::GetPropertyInteger(const char* szName, @@ -961,6 +972,14 @@ const std::string& Importer::GetPropertyString(const char* szName, return GetGenericProperty(pimpl->mStringProperties,szName,iErrorReturn); } +// ------------------------------------------------------------------------------------------------ +// Get a configuration property +const aiMatrix4x4& Importer::GetPropertyMatrix(const char* szName, + const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const +{ + return GetGenericProperty(pimpl->mMatrixProperties,szName,iErrorReturn); +} + // ------------------------------------------------------------------------------------------------ // Get the memory requirements of a single node inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode) diff --git a/code/Importer.h b/code/Importer.h index f4733c141..c61d32456 100644 --- a/code/Importer.h +++ b/code/Importer.h @@ -63,11 +63,12 @@ public: // Data type to store the key hash typedef unsigned int KeyType; - // typedefs for our three configuration maps. + // typedefs for our four configuration maps. // We don't need more, so there is no need for a generic solution typedef std::map IntPropertyMap; typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; + typedef std::map MatrixPropertyMap; public: @@ -100,6 +101,9 @@ public: /** List of string properties */ StringPropertyMap mStringProperties; + /** List of Matrix properties */ + MatrixPropertyMap mMatrixProperties; + /** Used for testing - extra verbose mode causes the ValidateDataStructure-Step * to be executed before and after every single postprocess step */ bool bExtraVerbose; @@ -135,14 +139,15 @@ public: ImporterPimpl::IntPropertyMap ints; ImporterPimpl::FloatPropertyMap floats; ImporterPimpl::StringPropertyMap strings; + ImporterPimpl::MatrixPropertyMap matrices; bool operator == (const PropertyMap& prop) const { // fixme: really isocpp? gcc complains - return ints == prop.ints && floats == prop.floats && strings == prop.strings; + return ints == prop.ints && floats == prop.floats && strings == prop.strings && matrices == prop.matrices; } bool empty () const { - return ints.empty() && floats.empty() && strings.empty(); + return ints.empty() && floats.empty() && strings.empty() && matrices.empty(); } }; //! @endcond diff --git a/include/assimp/Importer.hpp b/include/assimp/Importer.hpp index e0d55d4da..4260300a7 100644 --- a/include/assimp/Importer.hpp +++ b/include/assimp/Importer.hpp @@ -230,6 +230,13 @@ public: void SetPropertyString(const char* szName, const std::string& sValue, bool* bWasExisting = NULL); + // ------------------------------------------------------------------- + /** Set a matrix configuration property. + * @see SetPropertyInteger() + */ + void SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue, + bool* bWasExisting = NULL); + // ------------------------------------------------------------------- /** Get a configuration property. * @param szName Name of the property. All supported properties @@ -273,6 +280,15 @@ public: const std::string& GetPropertyString(const char* szName, const std::string& sErrorReturn = "") const; + // ------------------------------------------------------------------- + /** Get a matrix configuration property + * + * The return value remains valid until the property is modified. + * @see GetPropertyInteger() + */ + const aiMatrix4x4& GetPropertyMatrix(const char* szName, + const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const; + // ------------------------------------------------------------------- /** Supplies a custom IO handler to the importer to use to open and * access files. If you need the importer to use custion IO logic to diff --git a/include/assimp/cimport.h b/include/assimp/cimport.h index 237e65c29..adc27502b 100644 --- a/include/assimp/cimport.h +++ b/include/assimp/cimport.h @@ -79,6 +79,7 @@ struct aiLogStream * @see aiSetPropertyInteger * @see aiSetPropertyFloat * @see aiSetPropertyString + * @see aiSetPropertyMatrix */ // -------------------------------------------------------------------------------- struct aiPropertyStore { char sentinel; }; @@ -397,6 +398,23 @@ ASSIMP_API void aiSetImportPropertyString( const char* szName, const C_STRUCT aiString* st); +// -------------------------------------------------------------------------------- +/** Set a matrix property. + * + * This is the C-version of #Assimp::Importer::SetPropertyMatrix(). In the C + * interface, properties are always shared by all imports. It is not possible to + * specify them per import. + * + * @param property store to modify. Use #aiCreatePropertyStore to obtain a store. + * @param szName Name of the configuration property to be set. All supported + * public properties are defined in the config.h header file (#AI_CONFIG_XXX). + * @param value New value for the property + */ +ASSIMP_API void aiSetImportPropertyMatrix( + C_STRUCT aiPropertyStore* store, + const char* szName, + const C_STRUCT aiMatrix4x4* mat); + // -------------------------------------------------------------------------------- /** Construct a quaternion from a 3x3 rotation matrix. * @param quat Receives the output quaternion.