From 1b0089a22d060050c1fea8ea03be5715ed6dee67 Mon Sep 17 00:00:00 2001
From: Tazpn <tazpn@users.sourceforge.net>
Date: Mon, 5 Jan 2009 06:58:48 +0000
Subject: [PATCH] niflib: Allow strips as an option on the skin partition.

---
 include/obj/NiSkinPartition.h |  2 +-
 include/obj/NiTriBasedGeom.h  |  2 +-
 src/obj/NiSkinPartition.cpp   | 21 ++++++++++++++-------
 src/obj/NiTriBasedGeom.cpp    |  4 ++--
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/include/obj/NiSkinPartition.h b/include/obj/NiSkinPartition.h
index 6c0f2611..7386c5dd 100644
--- a/include/obj/NiSkinPartition.h
+++ b/include/obj/NiSkinPartition.h
@@ -156,7 +156,7 @@ public:
 protected:
    friend class NiTriBasedGeom;
    NiSkinPartition(Ref<NiTriBasedGeom> shape);
-   NiSkinPartition(Ref<NiTriBasedGeom> shape, int maxBonesPerPartition, int maxBonesPerVertex, int *faceMap);
+   NiSkinPartition(Ref<NiTriBasedGeom> shape, int maxBonesPerPartition, int maxBonesPerVertex, bool bStrippify, int *faceMap);
 
    void SetNumPartitions( int value );
    void SetWeightsPerVertex( int partition, unsigned short value );
diff --git a/include/obj/NiTriBasedGeom.h b/include/obj/NiTriBasedGeom.h
index e43f456e..23a35dfe 100644
--- a/include/obj/NiTriBasedGeom.h
+++ b/include/obj/NiTriBasedGeom.h
@@ -59,7 +59,7 @@ public:
 	 * \param[in] max_bones_per_partition The maximum number of bones that can affect a skin partition, i.e. a sub-mesh generated by chopping up the original mesh.  Proper value is game dependent.
 	 * \param[in] max_bones_per_vertex The maximum number of bones that can affect any one vertex.  Vertices affected by more bones than this will have the bone witht he smallest affect removed and the remaining bones will be normalized.
 	 */
-	NIFLIB_API void GenHardwareSkinInfo( int max_bones_per_partition = 4, int max_bones_per_vertex = 4, int* face2PartMap = NULL );
+	NIFLIB_API void GenHardwareSkinInfo( int max_bones_per_partition = 4, int max_bones_per_vertex = 4, bool bStrippify = true, int* face2PartMap = NULL );
 
 	/*!
 	 * This clears any hardware acceleration skin data that was previously created.
diff --git a/src/obj/NiSkinPartition.cpp b/src/obj/NiSkinPartition.cpp
index 25555ac2..cca5742e 100644
--- a/src/obj/NiSkinPartition.cpp
+++ b/src/obj/NiSkinPartition.cpp
@@ -644,7 +644,7 @@ void NiSkinPartition::SetTriangles( int partition, const vector<Triangle> & in )
    }
    SkinPartition& part = skinPartitionBlocks[partition];
    part.triangles = in;
-   part.hasFaces = (in.size() > 0) ? false : (part.strips.size() != 0);
+   part.hasFaces = (in.size() > 0) ? true : (part.strips.size() != 0);
    part.numTriangles = (unsigned int)(in.size()) * 3;
 }
 
@@ -797,7 +797,7 @@ size_t indexOf(I begin, I end, const V& val) {
 }
 
 
-NiSkinPartition::NiSkinPartition(Ref<NiTriBasedGeom> shape, int maxBonesPerPartition, int maxBonesPerVertex, int* faceMap ) {
+NiSkinPartition::NiSkinPartition(Ref<NiTriBasedGeom> shape, int maxBonesPerPartition, int maxBonesPerVertex, bool bStrippify, int* faceMap ) {
    NiSkinInstanceRef skinInst = shape->GetSkinInstance();
    if ( skinInst == NULL ) {
       throw runtime_error( "You must bind a skin before setting generating skin partitions.  No NiSkinInstance found." );
@@ -1132,11 +1132,18 @@ NiSkinPartition::NiSkinPartition(Ref<NiTriBasedGeom> shape, int maxBonesPerParti
       EnableVertexBoneIndices(p, true);
 
       // strippify the triangles
-      NiTriStripsDataRef data = new NiTriStripsData(triangles, true);
-      int nstrips = data->GetStripCount();
-      SetStripCount( p, nstrips );
-      for ( int i=0; i<nstrips; ++i ) {
-         SetStrip(p, i, data->GetStrip(i));
+      if (bStrippify)
+      {
+         NiTriStripsDataRef data = new NiTriStripsData(triangles, true);
+         int nstrips = data->GetStripCount();
+         SetStripCount( p, nstrips );
+         for ( int i=0; i<nstrips; ++i ) {
+            SetStrip(p, i, data->GetStrip(i));
+         }
+      }
+      else
+      {
+         SetTriangles(p, triangles);
       }
 
       //// Special case for pre-stripped data
diff --git a/src/obj/NiTriBasedGeom.cpp b/src/obj/NiTriBasedGeom.cpp
index d1589083..6a52eea5 100644
--- a/src/obj/NiTriBasedGeom.cpp
+++ b/src/obj/NiTriBasedGeom.cpp
@@ -107,12 +107,12 @@ void NiTriBasedGeom::ClearHardareSkinInfo() {
 }
 
 
-void NiTriBasedGeom::GenHardwareSkinInfo( int max_bones_per_partition /*= 4*/, int max_bones_per_vertex /*= INT_MAX*/, int* face2PartMap /*= NULL*/ ) {
+void NiTriBasedGeom::GenHardwareSkinInfo( int max_bones_per_partition /*= 4*/, int max_bones_per_vertex /*= INT_MAX*/, bool bStrippify /*= true*/, int* face2PartMap /*= NULL*/ ) {
    NiSkinPartitionRef skinPart; 
    if ( max_bones_per_partition == 0 ) //old method
       skinPart = new NiSkinPartition( this );
    else
-      skinPart = new NiSkinPartition( this, max_bones_per_partition, max_bones_per_vertex, face2PartMap );
+      skinPart = new NiSkinPartition( this, max_bones_per_partition, max_bones_per_vertex, bStrippify, face2PartMap );
 
    // Set the partition info in both places and it will be handled when exported.
    NiSkinInstanceRef skinInst = GetSkinInstance();
-- 
GitLab