From 49f7b82532cacae6653edcab513e32fb7a932a9e Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Sat, 5 May 2007 05:27:23 +0000
Subject: [PATCH] More documentation. Added ClearHardareSkinInfo function to
 NiTriBasedGeom so that SetSkinPartition functions could be made
 NIFLIB_HIDDEN.

---
 include/obj/NiGeometry.h      |  2 +-
 include/obj/NiSkinData.h      | 67 +++++++++++++++++++++++++++++++----
 include/obj/NiSkinInstance.h  | 41 +++++++++++++++++++--
 include/obj/NiSkinPartition.h |  9 +++--
 include/obj/NiTriBasedGeom.h  |  5 +++
 src/obj/NiGeometry.cpp        |  2 +-
 src/obj/NiSkinData.cpp        | 10 +++---
 src/obj/NiSkinInstance.cpp    |  6 ++--
 src/obj/NiTriBasedGeom.cpp    | 14 ++++++++
 9 files changed, 133 insertions(+), 23 deletions(-)

diff --git a/include/obj/NiGeometry.h b/include/obj/NiGeometry.h
index 991d0594..85f85717 100644
--- a/include/obj/NiGeometry.h
+++ b/include/obj/NiGeometry.h
@@ -79,7 +79,7 @@ public:
 	 * Sets the geometry data object used by this geometry node.  This contains the vertices, normals, etc. and can be shared among several geometry nodes.
 	 * \param[in] n The new geometry data object, or NULL to clear the current one.
 	 */
-	NIFLIB_API void SetData( const Ref<NiGeometryData> & n );
+	NIFLIB_API void SetData( NiGeometryData * n );
 
 	/*!
 	 * Retrieves the object pointed to by the unknown link in this geometry node, if any.
diff --git a/include/obj/NiSkinData.h b/include/obj/NiSkinData.h
index 99221d6b..e26ba1cf 100644
--- a/include/obj/NiSkinData.h
+++ b/include/obj/NiSkinData.h
@@ -28,10 +28,10 @@ public:
 	NIFLIB_API NiSkinData();
 
 	/*!
-	 * This constructor is called by NiGeometry when it creates a new skin
-	 * instance using the BindSkin function.
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * This constructor is called by NiGeometry when it creates a new skin instance using the BindSkin function.
 	 */
-	NIFLIB_HIDDEN NiSkinData( const Ref<NiGeometry> & owner );
+	NIFLIB_HIDDEN NiSkinData( NiGeometry * owner );
 
 	NIFLIB_API ~NiSkinData();
 
@@ -47,18 +47,71 @@ public:
 	NIFLIB_HIDDEN virtual void FixLinks( const map<unsigned int,NiObjectRef> & objects, list<unsigned int> & link_stack, const NifInfo & info );
 	NIFLIB_HIDDEN virtual list<NiObjectRef> GetRefs() const;
 
-	NIFLIB_API void ResetOffsets( const Ref<NiGeometry> & owner );
+	/*!
+	 * Retrieves the current overall transform for this skin.  This is the transform from the geometry node back to its skeleton root.
+	 * \return The current overall transform for this skin.
+	 */
 	NIFLIB_API Matrix44 GetOverallTransform() const;
+
+	/*!
+	 * Sets the overall transform for this skin.  This is the transform from the geometry node back to the skeleton root.
+	 * \param[in] transform The new overall transform for this skin.
+	 */
 	NIFLIB_API void SetOverallTransform( const Matrix44 & transform );
+
+	/*!
+	 * Retrieves the number of bones influences affecting this skin.  These are NiNodes which cause the skin to deform when they move.
+	 * \return The number of bonees influencing this skin.
+	 */
 	NIFLIB_API unsigned int GetBoneCount() const;
+
+	/*!
+	 * Retrieves the transform for a particular bone.  This is the transform from geometry node back to this bone in skeleton root coordinates.
+	 * \param[in] bone_index The numeric index of the bone that the transform matrix should be returned for.  Must be >= zero and < the number returned by GetBoneCount.
+	 * \return The transform matrix for the specified bone.
+	 */
 	NIFLIB_API Matrix44 GetBoneTransform( unsigned int bone_index ) const;
+
+	/*!
+	 * Retrieves the skin weights for a particular bone.  This information includes the vertex index into the geometry data's vertex array, and the percentage weight that defines how much the movement of this bone influences its position.
+	 * \param[in] bone_index The numeric index of the bone that the skin weight data should be returned for.  Must be >= zero and < the number returned by GetBoneCount.
+	 * \return The skin weight data for the specified bone.
+	 */
 	NIFLIB_API vector<SkinWeight> GetBoneWeights( unsigned int bone_index ) const;
-	NIFLIB_API void SetBoneWeights( unsigned int bone_index, const vector<SkinWeight> & n, Vector3 center, float radius );
 
-	NIFLIB_API void NormalizeWeights( unsigned numVertices );
+	/*!
+	 * Sets the skin weights for a particular bone.  This information includes the vertex index into the geometry data's vertex array, and the percentage weight that defines how much the movement of this bone influences its position.
+	 * \param[in] bone_index The numeric index of the bone that the skin weight data should be set for.  Must be >= zero and < the number returned by GetBoneCount.
+	 * \param[in] weights The new skin weight data for the specified bone.
+	 * \param[in] center The center point of all the vertices affected by this bone.  This is the mid point between the minimums and maximums in each of the 3 directions.
+	 * \param[in] radius The radius of a bounding circle centered at the center point which contains all the vertices affected by this bone.  This is the distance from the center to vertex that is the greatest distance away.
+	 * \return The skin weight data for the specified bone.
+	 */
+	NIFLIB_API void SetBoneWeights( unsigned int bone_index, const vector<SkinWeight> & weights, Vector3 center, float radius );
 	
+	/*!
+	 * Returns a reference to the hardware skin partition data object, if any.
+	 * \return The hardware skin partition data, or NULL if none is used.
+	 */
 	NIFLIB_API Ref<NiSkinPartition> GetSkinPartition() const;
-	NIFLIB_API void SetSkinPartition(Ref<NiSkinPartition> skinPartition);
+
+	/*
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * This can be used to set or clear the hardware skin partition data.  To create partition data, the NiTriBasedGeom::GenHardwareSkinInfo function should be used.
+	 * \param[in] skinPartition The new hardware skin partition data object to use, or NULL to clear the existing one.
+	 */
+	NIFLIB_HIDDEN void SetSkinPartition( NiSkinPartition * skinPartition );
+
+	/*
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * This is called by NiGeometry when the NormalizeSkinWeights function of that object is called, which is a public function.
+	 */
+	NIFLIB_HIDDEN void NormalizeWeights( unsigned numVertices );
+	/*!
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * This function resets the bone offsets to their current positions, effetivley changing the bind pose.  This does not cause any tranformations to the vertex positions, however, so is mostly usful for instances where the world positions of the old and new bind pose are equivalent, but result from different local transformations along the way.  It is called by NiGeometry when the interum transforms are flattened.
+	 */
+	NIFLIB_HIDDEN void ResetOffsets( NiGeometry * owner );
 
 protected:
 	NI_SKIN_DATA_MEMBERS
diff --git a/include/obj/NiSkinInstance.h b/include/obj/NiSkinInstance.h
index 1c3eec1a..b0355b6c 100644
--- a/include/obj/NiSkinInstance.h
+++ b/include/obj/NiSkinInstance.h
@@ -33,7 +33,7 @@ public:
 	 * instance using the BindSkin function.
 	 */
 #ifndef SWIG // for some reason SWIG cannot properly hide this function in NiSkinInstanceRef
-	NIFLIB_HIDDEN NiSkinInstance( Ref<NiNode> skeleton_root, vector< Ref<NiNode> > bone_nodes );
+	NIFLIB_HIDDEN NiSkinInstance( NiNode * skeleton_root, vector< Ref<NiNode> > bone_nodes );
 #endif
 
 	NIFLIB_API ~NiSkinInstance();
@@ -49,17 +49,52 @@ public:
 	NIFLIB_HIDDEN virtual void FixLinks( const map<unsigned int,NiObjectRef> & objects, list<unsigned int> & link_stack, const NifInfo & info );
 	NIFLIB_HIDDEN virtual list<NiObjectRef> GetRefs() const;
 
+	/*!
+	 * Retrieves the number of NiNode bones that influence this skin.
+	 * \return The number of bones that influence this skin.
+	 */
 	NIFLIB_API unsigned int GetBoneCount() const;
+
+	/*!
+	 * Retrieves a list of references to all the NiNode bones that influence this skin.
+	 * \return All the bones that influence this skin.
+	 */
 	NIFLIB_API vector< Ref<NiNode> > GetBones() const;
+
+	/*!
+	 * Retrieves the root node of the skeleton that influences this skin.  This is the common ancestor of all bones and the skin itself.
+	 * \return The skeleton root.
+	 */
 	NIFLIB_API Ref<NiNode> GetSkeletonRoot() const;
 
+	/*!
+	 * Retrieves the root node of the skeleton that influences this skin.  This is the common ancestor of all bones and the skin itself.
+	 * \return The skeleton root.
+	 */
 	NIFLIB_API Ref<NiSkinData> GetSkinData() const;
-	NIFLIB_API void SetSkinData( const Ref<NiSkinData> & n );
 
+
+	/*!
+	 * Retrieves the hardare skin partition, if any.
+	 * \return The skeleton root.
+	 */
 	NIFLIB_API Ref<NiSkinPartition> GetSkinPartition() const;
-	NIFLIB_API void SetSkinPartition( const Ref<NiSkinPartition> & n );
 
 	/*! 
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * Called by NiGeometry during the skin binding process.
+	 */
+	NIFLIB_HIDDEN void SetSkinData( NiSkinData * n );
+
+	/*
+	 * NIFLIB_HIDDEN function.  For internal use only.
+	 * This can be used to set or clear the hardware skin partition data.  To create partition data, the NiTriBasedGeom::GenHardwareSkinInfo function should be used.
+	 * \param[in] n The new hardware skin partition data object to use, or NULL to clear the existing one.
+	 */
+	NIFLIB_HIDDEN void SetSkinPartition( NiSkinPartition * n );
+
+	/*! 
+	 * NIFLIB_HIDDEN function.  For internal use only.
 	 * Called by skeleton root NiNode when it self destructs to inform this skin
 	 * instance that the skeleton has been lost.  Should not be called directly.
 	 */
diff --git a/include/obj/NiSkinPartition.h b/include/obj/NiSkinPartition.h
index 9a18e8b4..488ec2e5 100644
--- a/include/obj/NiSkinPartition.h
+++ b/include/obj/NiSkinPartition.h
@@ -50,20 +50,23 @@ public:
 	NIFLIB_API vector<unsigned short> GetBoneMap( int partition ) const;
 
 	NIFLIB_API bool HasVertexWeights( int partition ) const;
+
 	NIFLIB_API vector<float> GetVertexWeights( int partition, int vertex ) const;
 
 	NIFLIB_API bool HasVertexBoneIndices( int partition ) const;
+
 	NIFLIB_API vector<unsigned short> GetVertexBoneIndices( int partition, int vertex ) const;
 
-	/*! Used to get the number of triangle strips that a particular skin partition
-	 * isis divided into.
+	/*!
+	 * Used to get the number of triangle strips that a particular skin partition is divided into.
 	 * \param[in] partition The specific partition to get the strip count from.
 	 * \return The number of triangle strips used by this mesh.
 	 * \sa NiSkinPartition::SetStripCount
 	 */
 	NIFLIB_API unsigned short GetStripCount( int partition ) const;
 
-	/*! Used to retrieve all the triangles from a specific triangle strip in a
+	/*!
+	 * Used to retrieve all the triangles from a specific triangle strip in a
 	 * particular skin partition.
 	 * \param[in] partition The specific partition to get the triangles from.
 	 * \param[in] index The index of the triangle strip to retrieve the triangles from.  This is a zero-based index which must be a positive number less than that returned by NiTriStripsData::GetStripCount.
diff --git a/include/obj/NiTriBasedGeom.h b/include/obj/NiTriBasedGeom.h
index de5e1a5c..bdbf292e 100644
--- a/include/obj/NiTriBasedGeom.h
+++ b/include/obj/NiTriBasedGeom.h
@@ -44,6 +44,11 @@ public:
 	 */
 	NIFLIB_API void GenHardwareSkinInfo( int max_bones_per_partition = 4, int max_bones_per_vertex = 4 );
 
+	/*!
+	 * This clears any hardware acceleration skin data that was previously created.
+	 */
+	NIFLIB_API void ClearHardareSkinInfo();
+
 	/*!
 	 * Generate or update a NiStringExtraData object with precalculated
 	 * tangent and binormal data (Oblivion specific)
diff --git a/src/obj/NiGeometry.cpp b/src/obj/NiGeometry.cpp
index e2ce8c2c..3b2fac73 100644
--- a/src/obj/NiGeometry.cpp
+++ b/src/obj/NiGeometry.cpp
@@ -45,7 +45,7 @@ Ref<NiGeometryData> NiGeometry::GetData() const {
 	return data;
 }
 
-void NiGeometry::SetData( const Ref<NiGeometryData> & n ) {
+void NiGeometry::SetData( NiGeometryData * n ) {
 	data = n;
 }
 
diff --git a/src/obj/NiSkinData.cpp b/src/obj/NiSkinData.cpp
index 448428fd..7dc4c31a 100644
--- a/src/obj/NiSkinData.cpp
+++ b/src/obj/NiSkinData.cpp
@@ -61,12 +61,12 @@ vector<SkinWeight> NiSkinData::GetBoneWeights( unsigned int bone_index ) const {
 	return boneList[bone_index].vertexWeights;
 }
 
-void NiSkinData::SetBoneWeights( unsigned int bone_index, const vector<SkinWeight> & n, Vector3 center, float radius ) {
+void NiSkinData::SetBoneWeights( unsigned int bone_index, const vector<SkinWeight> & weights, Vector3 center, float radius ) {
 	if ( bone_index > boneList.size() ) {
 		throw runtime_error( "The specified bone index was larger than the number of bones in this NiSkinData." );
 	}
 
-	boneList[bone_index].vertexWeights = n;
+	boneList[bone_index].vertexWeights = weights;
    boneList[bone_index].boundingSphereOffset = center;
    boneList[bone_index].boundingSphereRadius = radius;
 }
@@ -79,7 +79,7 @@ void NiSkinData::SetOverallTransform( const Matrix44 & transform ) {
 	transform.Decompose( translation, rotation, scale );
 }
 
-NiSkinData::NiSkinData( const Ref<NiGeometry> & owner ) NI_SKIN_DATA_CONSTRUCT {
+NiSkinData::NiSkinData( NiGeometry * owner ) NI_SKIN_DATA_CONSTRUCT {
 	ResetOffsets( owner );
 }
 
@@ -120,7 +120,7 @@ void NiSkinData::NormalizeWeights( unsigned numVertices ) {
 	}	
 }
 
-void NiSkinData::ResetOffsets( const Ref<NiGeometry> & owner ) {
+void NiSkinData::ResetOffsets( NiGeometry * owner ) {
 
 	//Get skin instance
 	NiSkinInstanceRef skinInst = owner->GetSkinInstance();
@@ -167,7 +167,7 @@ Ref<NiSkinPartition> NiSkinData::GetSkinPartition() const {
    return skinPartition;
 }
 
-void NiSkinData::SetSkinPartition(Ref<NiSkinPartition> value) {
+void NiSkinData::SetSkinPartition( NiSkinPartition * value ) {
    skinPartition = value;
 }
 
diff --git a/src/obj/NiSkinInstance.cpp b/src/obj/NiSkinInstance.cpp
index 6794b761..cadbcb7e 100644
--- a/src/obj/NiSkinInstance.cpp
+++ b/src/obj/NiSkinInstance.cpp
@@ -13,7 +13,7 @@ const Type NiSkinInstance::TYPE("NiSkinInstance", &NI_SKIN_INSTANCE_PARENT::Type
 
 NiSkinInstance::NiSkinInstance() NI_SKIN_INSTANCE_CONSTRUCT {}
 
-NiSkinInstance::NiSkinInstance( Ref<NiNode> skeleton_root, vector< Ref<NiNode> > bone_nodes ) NI_SKIN_INSTANCE_CONSTRUCT {
+NiSkinInstance::NiSkinInstance( NiNode * skeleton_root, vector< Ref<NiNode> > bone_nodes ) NI_SKIN_INSTANCE_CONSTRUCT {
 	//Ensure that all bones are below the skeleton root node on the scene graph
 	for ( unsigned int i = 0; i < bone_nodes.size(); ++i ) {
 		bool is_decended = false;
@@ -105,7 +105,7 @@ Ref<NiSkinData> NiSkinInstance::GetSkinData() const {
 	return data;
 }
 
-void NiSkinInstance::SetSkinData( const Ref<NiSkinData> & n ) {
+void NiSkinInstance::SetSkinData( NiSkinData * n ) {
 	data = n;
 }
 
@@ -113,7 +113,7 @@ Ref<NiSkinPartition> NiSkinInstance::GetSkinPartition() const {
 	return skinPartition;
 }
 
-void NiSkinInstance::SetSkinPartition( const Ref<NiSkinPartition> & n ) {
+void NiSkinInstance::SetSkinPartition( NiSkinPartition * n ) {
 	skinPartition = n;
 }
 
diff --git a/src/obj/NiTriBasedGeom.cpp b/src/obj/NiTriBasedGeom.cpp
index be255c05..8a217ace 100644
--- a/src/obj/NiTriBasedGeom.cpp
+++ b/src/obj/NiTriBasedGeom.cpp
@@ -42,6 +42,20 @@ const Type & NiTriBasedGeom::GetType() const {
 	return TYPE;
 };
 
+void NiTriBasedGeom::ClearHardareSkinInfo() {
+   // Clear the partition info in both places.
+   NiSkinInstanceRef skinInst = GetSkinInstance();
+   if ( skinInst != NULL ) {
+      skinInst->SetSkinPartition( NULL );
+
+      NiSkinDataRef skinData = skinInst->GetSkinData();
+      if (skinData != NULL) {
+         skinData->SetSkinPartition( NULL );
+      }
+   }
+}
+
+
 void NiTriBasedGeom::GenHardwareSkinInfo( int max_bones_per_partition /*= 4*/, int max_bones_per_vertex /*= INT_MAX*/ ) {
    NiSkinPartitionRef skinPart; 
    if ( max_bones_per_partition == 0 ) //old method
-- 
GitLab