From 03faedb62467f1d9ab96e972d57bfdeed7948896 Mon Sep 17 00:00:00 2001
From: Steve Carrow <sacarrow@users.sourceforge.net>
Date: Fri, 26 Sep 2008 01:26:25 +0000
Subject: [PATCH] Added "helper" vector of vertex indices to custom code.

---
 include/obj/NiGeometryData.h | 25 +++++++++++++++++++++++++
 src/obj/NiGeometryData.cpp   | 15 +++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/obj/NiGeometryData.h b/include/obj/NiGeometryData.h
index e9d9992c..d4eddadb 100644
--- a/include/obj/NiGeometryData.h
+++ b/include/obj/NiGeometryData.h
@@ -58,6 +58,10 @@ public:
 	NIFLIB_API virtual const Type & GetType() const;
 
 	//--BEGIN MISC CUSTOM CODE--//
+protected:
+	/*! The mesh vertex indices. */
+	vector<int > vertexIndices;
+public:
 
 	//--Counts--//
 
@@ -82,6 +86,13 @@ public:
 	 */
 	NIFLIB_API void SetUVSetCount(int n);
 
+	/*! 
+	 * Returns the number of vertec indices that make up this mesh.
+	 * \return The number of vertex indices that make up this mesh.
+	 * \sa IShapeData::SetVertexIndexCount
+	 */
+	NIFLIB_API int GetVertexIndexCount() const;
+
 	//--Getters--//
 
 	/*! 
@@ -132,6 +143,13 @@ public:
 	 */
 	NIFLIB_API vector<TexCoord> GetUVSet( int index ) const;
 	
+	/*! 
+	 * Used to retrive the vertex indices used by this mesh.  The size of the vector will be the same as the vertex count retrieved with the IShapeData::GetVertexIndexCount function.
+	 * \return A vector cntaining the vertex indices used by this mesh.
+	 * \sa IShapeData::SetVertexIndices, IShapeData::GetVertexIndexCount, IShapeData::SetVertexIndexCount.
+	 */
+	NIFLIB_API vector<int> GetVertexIndices() const;
+
 	//--Setters--//
 
 	/*! 
@@ -163,6 +181,13 @@ public:
 	 */
 	NIFLIB_API void SetUVSet( int index, const vector<TexCoord> & in );
 
+	/*! 
+	 * Used to set the vertex index data used by this mesh.  Calling this function will clear all other data in this object.
+	 * \param in A vector containing the vertex indices to replace those in the mesh with.  Note that there is no way to set vertices one at a time, they must be sent in one batch.
+	 * \sa IShapeData::GetVertexIndices, IShapeData::GetVertexIndexCount
+	 */
+	NIFLIB_API virtual void SetVertexIndices( const vector<int> & in );
+
 	/*!
 	 * Used to apply a transformation directly to all the vertices and normals in
 	 * this mesh.
diff --git a/src/obj/NiGeometryData.cpp b/src/obj/NiGeometryData.cpp
index 3db2cf9c..a81cd0d8 100644
--- a/src/obj/NiGeometryData.cpp
+++ b/src/obj/NiGeometryData.cpp
@@ -391,6 +391,10 @@ short NiGeometryData::GetUVSetCount() const {
 	return short(uvSets.size());
 }
 
+int NiGeometryData::GetVertexIndexCount() const {
+	return int(vertexIndices.size());
+}
+
 vector<Vector3> NiGeometryData::GetVertices() const {
 	return vertices;
 }
@@ -407,6 +411,10 @@ vector<TexCoord> NiGeometryData::GetUVSet( int index ) const {
 	return uvSets[index];
 }
 
+vector<int> NiGeometryData::GetVertexIndices() const {
+	return vertexIndices;
+}
+
 void NiGeometryData::SetUVSetCount(int n) {
 	uvSets.resize(n);
 	hasUv = ( uvSets.size() != 0 );
@@ -490,6 +498,13 @@ void NiGeometryData::SetUVSet( int index, const vector<TexCoord> & in ) {
 	uvSets[index] = in;
 }
 
+void NiGeometryData::SetVertexIndices( const vector<int> & in ) {
+	if (in.size() != vertices.size() && in.size() != 0 )
+		throw runtime_error("Vector size must equal Vertex Count or zero.");
+	vertexIndices = in;
+}
+
+
 Vector3 NiGeometryData::GetCenter() const {
 	return center;
 }
-- 
GitLab