From 5a5cc4e6c56178964271205a272ed4e7470af619 Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Sat, 10 Jun 2006 01:41:22 +0000
Subject: [PATCH] Added access functions to all classes used by Maya importer.
 Implemented Color3 object. Adjusted project settings to make the Maya
 importer link faster.

---
 NIF_IO.cpp                  | 13 +++++++
 NIF_IO.h                    |  4 ++
 nif_math.cpp                |  6 ++-
 nif_math.h                  | 37 ++++++++++++++++++-
 niflib.vcproj               |  4 +-
 obj/NiAVObject.cpp          | 40 ++++++++++++++++++++
 obj/NiAVObject.h            | 15 ++++++++
 obj/NiAlphaProperty.cpp     | 16 ++++++++
 obj/NiAlphaProperty.h       |  6 +++
 obj/NiMaterialProperty.cpp  | 55 +++++++++++++++++++++++++++
 obj/NiMaterialProperty.h    | 23 ++++++++++++
 obj/NiMorphData.cpp         |  2 +-
 obj/NiSourceTexture.cpp     | 74 +++++++++++++++++++++++++++++++++++++
 obj/NiSourceTexture.h       | 29 +++++++++++++++
 obj/NiTexturingProperty.cpp |  2 +
 obj/NiTriBasedGeom.cpp      | 30 +++++++++++++++
 obj/NiTriBasedGeom.h        | 12 ++++++
 17 files changed, 363 insertions(+), 5 deletions(-)

diff --git a/NIF_IO.cpp b/NIF_IO.cpp
index a02bf437..09c4bf57 100644
--- a/NIF_IO.cpp
+++ b/NIF_IO.cpp
@@ -397,6 +397,19 @@ void NifStream( Matrix44 const & val, ostream& out, uint version ) {
 	}
 }
 
+//Color3
+void NifStream( Color3 & val, istream& in, uint version ) {
+	val.r = ReadFloat( in );
+	val.g = ReadFloat( in );
+	val.b = ReadFloat( in );
+};
+
+void NifStream( Color3 const & val, ostream& out, uint version ) {
+	WriteFloat( val.r, out );
+	WriteFloat( val.g, out );
+	WriteFloat( val.b, out );
+};
+
 //Color4
 void NifStream( Color4 & val, istream& in, uint version ) {
 	val.r = ReadFloat( in );
diff --git a/NIF_IO.h b/NIF_IO.h
index 3558b4b2..673a37b5 100644
--- a/NIF_IO.h
+++ b/NIF_IO.h
@@ -303,6 +303,10 @@ void NifStream( Float4 const & val, ostream& out, uint version = 0  );
 void NifStream( Matrix44 & val, istream& in, uint version = 0 );
 void NifStream( Matrix44 const & val, ostream& out, uint version = 0 );
 
+//Color3
+void NifStream( Color3 & val, istream& in, uint version = 0 );
+void NifStream( Color3 const & val, ostream& out, uint version = 0  );
+
 //Color4
 void NifStream( Color4 & val, istream& in, uint version = 0 );
 void NifStream( Color4 const & val, ostream& out, uint version = 0  );
diff --git a/nif_math.cpp b/nif_math.cpp
index 1ad11b43..cf89aed5 100644
--- a/nif_math.cpp
+++ b/nif_math.cpp
@@ -445,8 +445,12 @@ ostream & operator<<( ostream & out, Matrix44 const & val ) {
 	return out;
 }
 
+ostream & operator<<( ostream & out, Color3 const & val ) {
+	return out << "{R:" << setw(6) << val.r << " G:" << setw(6) << val.g << " B:" << setw(6) << val.b << "}";
+}
+
 ostream & operator<<( ostream & out, Color4 const & val ) {
-	return out << "R:" << setw(6) << val.r << " G:" << setw(6) << val.g << " B:" << setw(6) << val.b << " A:" << setw(6) << val.a << "}";
+	return out << "{R:" << setw(6) << val.r << " G:" << setw(6) << val.g << " B:" << setw(6) << val.b << " A:" << setw(6) << val.a << "}";
 }
 
 ostream & operator<<( ostream & out, Quaternion const & val ) {
diff --git a/nif_math.h b/nif_math.h
index 950eced1..b5a2c573 100644
--- a/nif_math.h
+++ b/nif_math.h
@@ -745,6 +745,40 @@ struct Matrix44 {
     }
 };
 
+/*! Stores a color along with alpha translucency */
+struct NIFLIB_API Color3 {
+	float r; /*!< The red component of this color.  Should be between 0.0f and 1.0f. */ 
+	float g; /*!< The green component of this color.  Should be between 0.0f and 1.0f. */ 
+	float b; /*!< The blue component of this color.  Should be between 0.0f and 1.0f. */ 
+
+	/*! Default constructor */
+	Color3() {}
+
+	/*! This constructor can be used to set all values in this structure during initialization
+	 * \param r The value to set the red component of this color to.  Should be between 0.0f and 1.0f.
+	 * \param g The value to set the green component of this color to. Should be between 0.0f and 1.0f.
+	 * \param b The value to set the blue component of this color to.  Should be between 0.0f and 1.0f.
+	 * \param a The value to set the alpha translucency component of this color to.  Should be between 0.0f and 1.0f.
+	 */
+	Color3(float r, float g, float b) {
+		this->r = r;
+		this->g = g;
+		this->b = b;
+	}
+
+	/*! This function can be used to set all values in the structure at the same time.
+	 * \param r The value to set the red component of this color to.  Should be between 0.0f and 1.0f.
+	 * \param g The value to set the green component of this color to. Should be between 0.0f and 1.0f.
+	 * \param b The value to set the blue component of this color to.  Should be between 0.0f and 1.0f.
+	 * \param a The value to set the alpha translucency component of this color to.  Should be between 0.0f and 1.0f.
+	 */
+	void Set(float r, float g, float b) {
+		this->r = r;
+		this->g = g;
+		this->b = b;
+	}
+};
+
 /*! Stores a color along with alpha translucency */
 struct NIFLIB_API Color4 {
 	float r; /*!< The red component of this color.  Should be between 0.0f and 1.0f. */ 
@@ -840,9 +874,8 @@ ostream & operator<<( ostream & out, Matrix22 const & val );
 ostream & operator<<( ostream & out, Float3 const & val );
 ostream & operator<<( ostream & out, Matrix33 const & val );
 ostream & operator<<( ostream & out, Float4 const & val );
+ostream & operator<<( ostream & out, Color3 const & val );
 ostream & operator<<( ostream & out, Color4 const & val );
 ostream & operator<<( ostream & out, Quaternion const & val );
 
-typedef Float3 Color3;
-
 #endif
diff --git a/niflib.vcproj b/niflib.vcproj
index 6aa18a8e..668b8e28 100644
--- a/niflib.vcproj
+++ b/niflib.vcproj
@@ -4,6 +4,7 @@
 	Version="8.00"
 	Name="NIFlib"
 	ProjectGUID="{19FD8EE6-79CC-4BAC-9744-D9573BE47C7E}"
+	RootNamespace="NIFlib"
 	Keyword="Win32Proj"
 	>
 	<Platforms>
@@ -105,7 +106,8 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				AdditionalOptions="/FI&quot;pch.h&quot;"
-				Optimization="3"
+				Optimization="0"
+				WholeProgramOptimization="false"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 				RuntimeLibrary="0"
 				UsePrecompiledHeader="2"
diff --git a/obj/NiAVObject.cpp b/obj/NiAVObject.cpp
index 79ebeacb..6a1fb5b0 100644
--- a/obj/NiAVObject.cpp
+++ b/obj/NiAVObject.cpp
@@ -139,4 +139,44 @@ Ref<NiProperty> NiAVObject::GetPropertyByType( const Type & compare_to ) {
 	}
 	//No matching properties found, return NULL
 	return NULL;
+}
+
+ushort NiAVObject::GetFlags() const {
+	return flags;
+}
+
+void NiAVObject::SetFlags( ushort n ) {
+	flags = n;
+}
+
+Matrix33 NiAVObject::GetLocalRotation() const {
+	return rotation;
+}
+
+void NiAVObject::SetLocalRotation( const Matrix33 & n ) {
+	rotation = n;
+}
+
+Vector3 NiAVObject::GetLocalTranslation() const {
+	return translation;
+}
+
+void NiAVObject::SetLocalTranslation( const Vector3 & n ) {
+	translation = n;
+}
+
+float NiAVObject::GetLocalScale() const {
+	return scale;
+}
+
+void NiAVObject::SetLocalScale( float n ) {
+	scale = n;
+}
+
+Vector3 NiAVObject::GetVelocity() const {
+	return velocity;
+}
+
+void NiAVObject::SetVelocity( const Vector3 & n ) {
+	velocity = n;
 }
\ No newline at end of file
diff --git a/obj/NiAVObject.h b/obj/NiAVObject.h
index 53550da7..863cdf37 100644
--- a/obj/NiAVObject.h
+++ b/obj/NiAVObject.h
@@ -83,6 +83,21 @@ public:
 	vector< Ref<NiProperty> > GetProperties() const;
 	Ref<NiProperty> GetPropertyByType( const Type & compare_to );
 
+	ushort GetFlags() const;
+	void SetFlags( ushort n );
+
+	Matrix33 GetLocalRotation() const;
+	void SetLocalRotation( const Matrix33 & n );
+
+	Vector3 GetLocalTranslation() const;
+	void SetLocalTranslation( const Vector3 & n );
+
+	float GetLocalScale() const;
+	void SetLocalScale( float n );
+
+	Vector3 GetVelocity() const;
+	void SetVelocity( const Vector3 & n );
+
 private:
 	NI_A_V_OBJECT_MEMBERS
 
diff --git a/obj/NiAlphaProperty.cpp b/obj/NiAlphaProperty.cpp
index e9d0d5f8..8a3ac9c8 100644
--- a/obj/NiAlphaProperty.cpp
+++ b/obj/NiAlphaProperty.cpp
@@ -34,3 +34,19 @@ const Type & NiAlphaProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiAlphaProperty::GetFlags() const {
+	return flags;
+}
+
+void NiAlphaProperty::SetFlags( ushort n ) {
+	flags = n;
+}
+
+byte NiAlphaProperty::GetAlphaTestThreshold() const {
+	return threshold;
+}
+
+void NiAlphaProperty::SetAlphaTestThreshold( byte n ) {
+	threshold = n;
+}
+
diff --git a/obj/NiAlphaProperty.h b/obj/NiAlphaProperty.h
index dbbab41c..caceab6b 100644
--- a/obj/NiAlphaProperty.h
+++ b/obj/NiAlphaProperty.h
@@ -27,6 +27,12 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+	ushort GetFlags() const;
+	void SetFlags( ushort n );
+
+	byte GetAlphaTestThreshold() const;
+	void SetAlphaTestThreshold( byte n );
 protected:
 	NI_ALPHA_PROPERTY_MEMBERS
 };
diff --git a/obj/NiMaterialProperty.cpp b/obj/NiMaterialProperty.cpp
index 1d5df1d6..8c9b07cc 100644
--- a/obj/NiMaterialProperty.cpp
+++ b/obj/NiMaterialProperty.cpp
@@ -34,3 +34,58 @@ const Type & NiMaterialProperty::GetType() const {
 	return TYPE;
 };
 
+ushort NiMaterialProperty::GetFlags() const {
+	return flags;
+}
+
+void NiMaterialProperty::SetFlags( ushort n ) {
+	flags = n;
+}
+
+float NiMaterialProperty::GetTransparency() const {
+	return alpha;
+}
+
+void NiMaterialProperty::SetTransparency( float n ) {
+	alpha = n;
+}
+
+float NiMaterialProperty::GetGlossiness() const {
+	return glossiness;
+}
+
+void NiMaterialProperty::SetGlossiness( float n ) {
+	glossiness = n;
+}
+
+Color3 NiMaterialProperty::GetAmbientColor() const {
+	return ambientColor;
+}
+
+void NiMaterialProperty::SetAmbientColor( const Color3 & n ) {
+	ambientColor = n;
+}
+
+Color3 NiMaterialProperty::GetDiffuseColor() const {
+	return diffuseColor;
+}
+
+void NiMaterialProperty::SetDiffuseColor( const Color3 & n ) {
+	diffuseColor = n;
+}
+
+Color3 NiMaterialProperty::GetEmissiveColor() const {
+	return emissiveColor;
+}
+
+void NiMaterialProperty::SetEmissiveColor( const Color3 & n ) {
+	emissiveColor = n;
+}
+
+Color3 NiMaterialProperty::GetSpecularColor() const {
+	return specularColor;
+}
+
+void NiMaterialProperty::SetSpecularColor( const Color3 & n ) {
+	specularColor = n;
+}
diff --git a/obj/NiMaterialProperty.h b/obj/NiMaterialProperty.h
index 0706b211..db8938c4 100644
--- a/obj/NiMaterialProperty.h
+++ b/obj/NiMaterialProperty.h
@@ -27,6 +27,29 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+	ushort GetFlags() const;
+	void SetFlags( ushort n );
+
+	float GetTransparency() const;
+	void SetTransparency( float n );
+
+	float GetGlossiness() const;
+	void SetGlossiness( float n );
+
+	Color3 GetAmbientColor() const;
+	void SetAmbientColor( const Color3 & n );
+
+	Color3 GetDiffuseColor() const;
+	void SetDiffuseColor( const Color3 & n );
+
+	Color3 GetEmissiveColor() const;
+	void SetEmissiveColor( const Color3 & n );
+
+	Color3 GetSpecularColor() const;
+	void SetSpecularColor( const Color3 & n );
+	
+
 protected:
 	NI_MATERIAL_PROPERTY_MEMBERS
 };
diff --git a/obj/NiMorphData.cpp b/obj/NiMorphData.cpp
index 99bc06dc..7398d4a5 100644
--- a/obj/NiMorphData.cpp
+++ b/obj/NiMorphData.cpp
@@ -52,7 +52,7 @@ int NiMorphData::GetMorphCount() const {
 }
 
 void NiMorphData::SetMorphCount( int n ) {
-	int old_size = morphs.size();
+	uint old_size = uint(morphs.size());
 	morphs.resize( n );
 
 	//Make sure any new vertex groups are the right size
diff --git a/obj/NiSourceTexture.cpp b/obj/NiSourceTexture.cpp
index dd950235..4bfd2cee 100644
--- a/obj/NiSourceTexture.cpp
+++ b/obj/NiSourceTexture.cpp
@@ -36,3 +36,77 @@ const Type & NiSourceTexture::GetType() const {
 	return TYPE;
 };
 
+bool NiSourceTexture::IsTextureExternal () {
+	return ( useExternal != 0 );
+}
+
+void NiSourceTexture::SetExternalTexture( string file_name, const Ref<NiObject> & unk_link ) {
+	useExternal = 0;
+	pixelData = NULL;
+	this->originalFileName_.clear();
+
+	fileName = file_name;
+	unknownLink = unk_link;
+}
+
+
+void NiSourceTexture::SetInternalTexture( byte unk_byte, string original_file_name, const Ref<NiPixelData> & pixel_data ) {
+	useExternal = 1;
+	fileName.clear();
+	
+	//TODO: Fix name problem with Unknown Byte in XML
+	unknownByte = unk_byte;
+	originalFileName_ = original_file_name;
+	pixelData = pixel_data;
+}
+
+string NiSourceTexture::GetExternalFileName() const {
+	return fileName;
+}
+
+Ref<NiObject> NiSourceTexture::GetExternalUnknownLink() const {
+	return unknownLink;
+}
+
+byte NiSourceTexture::GetInternalUnknownByte() const {
+	return unknownByte;
+}
+
+string NiSourceTexture::GetInternalOriginalFileName() const {
+	return originalFileName_;
+}
+
+Ref<NiPixelData> NiSourceTexture::GetInternalPixelData() const {
+	return pixelData;
+}
+
+PixelLayout NiSourceTexture::GetPixelLayout() const {
+	return pixelLayout;
+}
+
+void NiSourceTexture::SetPixelLayout( PixelLayout n ) {
+	pixelLayout = n;
+}
+
+MipMapFormat NiSourceTexture::GetMipMapFormat() const {
+	return useMipmaps;
+}
+
+void NiSourceTexture::SetMipMapFormat( MipMapFormat n ) {
+	useMipmaps = n;
+}
+
+AlphaFormat NiSourceTexture::GetAlphaFormat() const {
+	return alphaFormat;
+}
+
+void NiSourceTexture::SetAlphaFormat( AlphaFormat n ) {
+	alphaFormat = n;
+}
+
+//TODO: Fix name problem with Unknown Byte in XML
+//byte NiSourceTexture::GetUnknownByte2() const;
+//SNiSourceTexture::etUnknownByte2( byte n );
+//
+//byte NiSourceTexture::GetUnknownByte3() const;
+//NiSourceTexture::SetUnknownByte3( byte n );
\ No newline at end of file
diff --git a/obj/NiSourceTexture.h b/obj/NiSourceTexture.h
index e890233b..646b4b29 100644
--- a/obj/NiSourceTexture.h
+++ b/obj/NiSourceTexture.h
@@ -32,6 +32,35 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+	bool IsTextureExternal ();
+
+	void SetExternalTexture( string file_name, const Ref<NiObject> & unk_link );
+
+	void SetInternalTexture( byte unk_byte, string original_file_name, const Ref<NiPixelData> & pixel_data );
+
+	string GetExternalFileName() const;
+	Ref<NiObject> GetExternalUnknownLink() const;
+
+	byte GetInternalUnknownByte() const;
+	string GetInternalOriginalFileName() const;
+	Ref<NiPixelData> GetInternalPixelData() const;
+
+	PixelLayout GetPixelLayout() const;
+	void SetPixelLayout( PixelLayout n );
+
+	MipMapFormat GetMipMapFormat() const;
+	void SetMipMapFormat( MipMapFormat n );
+
+	AlphaFormat GetAlphaFormat() const;
+	void SetAlphaFormat( AlphaFormat n );
+
+	//TODO: Fix name problem with Unknown Byte in XML
+	//byte GetUnknownByte2() const;
+	//SetUnknownByte2( byte n );
+
+	//byte GetUnknownByte3() const;
+	//SetUnknownByte3( byte n );
 protected:
 	NI_SOURCE_TEXTURE_MEMBERS
 };
diff --git a/obj/NiTexturingProperty.cpp b/obj/NiTexturingProperty.cpp
index c9515568..808325ea 100644
--- a/obj/NiTexturingProperty.cpp
+++ b/obj/NiTexturingProperty.cpp
@@ -212,6 +212,8 @@ bool NiTexturingProperty::HasTexture( int n ) const {
 			return hasDecal0Texture;
 		case DECAL_1_MAP:
 			return hasDecal1Texture;
+		default:
+			throw("You have specified an invalid texture type.");
 	};
 }
 
diff --git a/obj/NiTriBasedGeom.cpp b/obj/NiTriBasedGeom.cpp
index cfb0a011..505cd7bd 100644
--- a/obj/NiTriBasedGeom.cpp
+++ b/obj/NiTriBasedGeom.cpp
@@ -37,3 +37,33 @@ const Type & NiTriBasedGeom::GetType() const {
 	return TYPE;
 };
 
+Ref<NiTriBasedGeomData> NiTriBasedGeom::GetData() const {
+	return data;
+}
+
+void NiTriBasedGeom::SetData( const Ref<NiTriBasedGeomData> & n ) {
+	data = n;
+}
+
+Ref<NiObject> NiTriBasedGeom::GetUnknownLink() const {
+	return unknownLink;
+}
+
+void NiTriBasedGeom::SetUnknownLink( const Ref<NiObject> & n ) {
+	unknownLink = n;
+}
+
+string NiTriBasedGeom::GetShader() const {
+	return shaderName;
+}
+
+void NiTriBasedGeom::SetShader( const string & n ) {
+	//Check if name is blank, if so clear shader
+	if ( n.size() == 0 ) {
+		hasShader = false;
+		shaderName.clear();
+	} else {
+		shaderName = n;
+	}
+}
+	
\ No newline at end of file
diff --git a/obj/NiTriBasedGeom.h b/obj/NiTriBasedGeom.h
index 626528d5..85034e38 100644
--- a/obj/NiTriBasedGeom.h
+++ b/obj/NiTriBasedGeom.h
@@ -33,6 +33,18 @@ public:
 	virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version );
 	virtual list<NiObjectRef> GetRefs() const;
 	virtual const Type & GetType() const;
+
+	//TODO:  Handle attatchment of SkinInstance with new skinning API
+
+	Ref<NiTriBasedGeomData> GetData() const;
+	void SetData( const Ref<NiTriBasedGeomData> & n );
+
+	Ref<NiObject> GetUnknownLink() const;
+	void SetUnknownLink( const Ref<NiObject> & n );
+
+	string GetShader() const;
+	void SetShader( const string & n );
+	
 protected:
 	NI_TRI_BASED_GEOM_MEMBERS
 };
-- 
GitLab