From aa9a2e57b53661d549b6a46cf1d6b9e562285f9b Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Thu, 8 Jun 2006 15:09:50 +0000
Subject: [PATCH] Some additional functions I added while trying to update my
 Maya importer.

---
 obj/NiAVObject.cpp          | 10 ++++
 obj/NiAVObject.h            |  1 +
 obj/NiTexturingProperty.cpp | 93 +++++++++++++++++++++++--------------
 obj/NiTexturingProperty.h   | 11 +++++
 4 files changed, 81 insertions(+), 34 deletions(-)

diff --git a/obj/NiAVObject.cpp b/obj/NiAVObject.cpp
index 4e790b29..79ebeacb 100644
--- a/obj/NiAVObject.cpp
+++ b/obj/NiAVObject.cpp
@@ -130,3 +130,13 @@ void NiAVObject::ClearProperties() {
 vector< Ref<NiProperty> > NiAVObject::GetProperties() const {
 	return properties;
 }
+
+Ref<NiProperty> NiAVObject::GetPropertyByType( const Type & compare_to ) {
+	for ( uint i = 0; i < properties.size(); ++i ) {
+		if ( properties[i]->IsSameType( compare_to ) ) {
+			return properties[i];
+		}
+	}
+	//No matching properties found, return NULL
+	return NULL;
+}
\ No newline at end of file
diff --git a/obj/NiAVObject.h b/obj/NiAVObject.h
index 1c2dd620..53550da7 100644
--- a/obj/NiAVObject.h
+++ b/obj/NiAVObject.h
@@ -81,6 +81,7 @@ public:
 	void RemoveProperty( Ref<NiProperty> obj );
 	void ClearProperties();
 	vector< Ref<NiProperty> > GetProperties() const;
+	Ref<NiProperty> GetPropertyByType( const Type & compare_to );
 
 private:
 	NI_A_V_OBJECT_MEMBERS
diff --git a/obj/NiTexturingProperty.cpp b/obj/NiTexturingProperty.cpp
index 59f71092..c9515568 100644
--- a/obj/NiTexturingProperty.cpp
+++ b/obj/NiTexturingProperty.cpp
@@ -137,40 +137,7 @@ void NiTexturingProperty::SetTextureCount( int new_count ) {
 
 	if ( new_count < int(textureCount) ) {
 		for ( int i = int(textureCount); i > new_count; --i ) {
-			switch (i) {
-				case BASE_MAP:
-					hasBaseTexture = false;
-					baseTexture.source = NULL;
-					break;
-				case DARK_MAP:
-					hasDarkTexture = false;
-					darkTexture.source = NULL;
-					break;
-				case DETAIL_MAP:
-					hasDetailTexture = false;
-					detailTexture.source = NULL;
-					break;
-				case GLOSS_MAP:
-					hasGlossTexture = false;
-					glossTexture.source = NULL;
-					break;
-				case GLOW_MAP:
-					hasGlowTexture = false;
-					glowTexture.source = NULL;
-					break;
-				case BUMP_MAP:
-					hasBumpMapTexture = false;
-					bumpMapTexture.source = NULL;
-					break;
-				case DECAL_0_MAP:
-					hasDecal0Texture = false;
-					decal0Texture.source = NULL;
-					break;
-				case DECAL_1_MAP:
-					hasDecal1Texture = false;
-					decal1Texture.source = NULL;
-					break;
-			};
+			ClearTexture(i);
 		}
 	}
 }
@@ -226,3 +193,61 @@ void NiTexturingProperty::SetShaderTexture( int n, TexDesc & new_val ) {
 	//Copy the values
 	shaderTextures[n].textureData = new_val;
 }
+
+bool NiTexturingProperty::HasTexture( int n ) const {
+	switch (n) {
+		case BASE_MAP:
+			return hasBaseTexture;
+		case DARK_MAP:
+			return hasDarkTexture;
+		case DETAIL_MAP:
+			return hasDetailTexture;
+		case GLOSS_MAP:
+			return hasGlossTexture;
+		case GLOW_MAP:
+			return hasGlowTexture;
+		case BUMP_MAP:
+			return hasBumpMapTexture;
+		case DECAL_0_MAP:
+			return hasDecal0Texture;
+		case DECAL_1_MAP:
+			return hasDecal1Texture;
+	};
+}
+
+void NiTexturingProperty::ClearTexture( int n ) {
+	switch (n) {
+		case BASE_MAP:
+			hasBaseTexture = false;
+			baseTexture.source = NULL;
+			break;
+		case DARK_MAP:
+			hasDarkTexture = false;
+			darkTexture.source = NULL;
+			break;
+		case DETAIL_MAP:
+			hasDetailTexture = false;
+			detailTexture.source = NULL;
+			break;
+		case GLOSS_MAP:
+			hasGlossTexture = false;
+			glossTexture.source = NULL;
+			break;
+		case GLOW_MAP:
+			hasGlowTexture = false;
+			glowTexture.source = NULL;
+			break;
+		case BUMP_MAP:
+			hasBumpMapTexture = false;
+			bumpMapTexture.source = NULL;
+			break;
+		case DECAL_0_MAP:
+			hasDecal0Texture = false;
+			decal0Texture.source = NULL;
+			break;
+		case DECAL_1_MAP:
+			hasDecal1Texture = false;
+			decal1Texture.source = NULL;
+			break;
+	};
+}
diff --git a/obj/NiTexturingProperty.h b/obj/NiTexturingProperty.h
index 38cce00e..392efc81 100644
--- a/obj/NiTexturingProperty.h
+++ b/obj/NiTexturingProperty.h
@@ -73,6 +73,17 @@ public:
 	 */
 	TexDesc GetTexture( int n ) const;
 
+	/*! Checks whether a particular texture type is being used
+	 * \param n The slot number of the texture to check.  This is a positive zero based index that must be less than the value returned by NiTexturingProperty::GetTextureCount.
+	 * \return true if the texture in this slot is used, false otherwise.
+	 */
+	bool HasTexture( int n ) const;
+
+	/*! Clears a specific texture slot.
+	 * \param n The slot number of the texture to clear.  This is a positive zero based index that must be less than the value returned by NiTexturingProperty::GetTextureCount.
+	 */
+	void ClearTexture( int n );
+
 	/*! Sets a new description for the texture in the given slot number.  The TexType enum is provided to make it easy to select the texture slot with the specific qualities that you want.
 	 * \param n The slot number of the texture to set the texture description of.  This is a positive zero based index that must be less than the value returned by ITexturingProperty::GetTextureCount.
 	 * \param new_val Thew new texture descriptoin for the texture at the given slot number.
-- 
GitLab