Browse Source

Added matrix properties

Léo Terziman 11 years ago
parent
commit
843e56c252
6 changed files with 78 additions and 3 deletions
  1. 16 0
      code/Assimp.cpp
  2. 1 0
      code/BaseImporter.cpp
  3. 19 0
      code/Importer.cpp
  4. 8 3
      code/Importer.h
  5. 16 0
      include/assimp/Importer.hpp
  6. 18 0
      include/assimp/cimport.h

+ 16 - 0
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<PropertyMap*>(p);
+	SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat,NULL);
+	ASSIMP_END_EXCEPTION_REGION(void);
+}
+
 // ------------------------------------------------------------------------------------------------
 // Rotation matrix to quaternion
 ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)

+ 1 - 0
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())
 		{

+ 19 - 0
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<aiMatrix4x4>(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<std::string>(pimpl->mStringProperties,szName,iErrorReturn);
 }
 
+// ------------------------------------------------------------------------------------------------
+// Get a configuration property
+const aiMatrix4x4& Importer::GetPropertyMatrix(const char* szName, 
+	const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
+{
+	return GetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties,szName,iErrorReturn);
+}
+
 // ------------------------------------------------------------------------------------------------
 // Get the memory requirements of a single node
 inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)

+ 8 - 3
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<KeyType, int> IntPropertyMap;
 	typedef std::map<KeyType, float> FloatPropertyMap;
 	typedef std::map<KeyType, std::string> StringPropertyMap;
+	typedef std::map<KeyType, aiMatrix4x4> 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

+ 16 - 0
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 

+ 18 - 0
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.