From 3fad3f63b76bd5989a3ffdd7a3094b8282daa863 Mon Sep 17 00:00:00 2001
From: Alecu100 <lui_alecu@yahoo.co.uk>
Date: Thu, 16 Feb 2012 06:35:16 +0200
Subject: [PATCH] fixed the complex shape to generate dismember partitions if
 the required data is provided

---
 include/ComplexShape.h |  4 ++--
 src/ComplexShape.cpp   | 27 ++++++++++++++++-----------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/include/ComplexShape.h b/include/ComplexShape.h
index ede2cdac..7358ed0d 100644
--- a/include/ComplexShape.h
+++ b/include/ComplexShape.h
@@ -306,7 +306,7 @@ public:
 	 * Sets the association between the body parts and the faces in the complex shape
 	 * \param[in] The new association meaning that the face at the position of the index corresponds to the body part group given by the value at the position of the index of the face
 	 */
-	NIFLIB_API void SetDismemberPartitionsFaces( vector<int> value );
+	NIFLIB_API void SetDismemberPartitionsFaces( const vector<int>& value );
 
 	/*
 	 * Gets a list of the dismember groups
@@ -318,7 +318,7 @@ public:
 	 * Gets the association between the faces in the complex shape and the corresponding body parts
 	 * \param[in] A list of the dismember groups;
 	 */
-	NIFLIB_API void SetDismemberPartitionsBodyParts( vector<BodyPartList> value);
+	NIFLIB_API void SetDismemberPartitionsBodyParts( const vector<BodyPartList>& value);
 
 private:
 	vector<BodyPartList> dismemberPartitionsBodyParts;
diff --git a/src/ComplexShape.cpp b/src/ComplexShape.cpp
index 16a6895c..d0cf2069 100644
--- a/src/ComplexShape.cpp
+++ b/src/ComplexShape.cpp
@@ -149,15 +149,19 @@ vector<int> ComplexShape::GetDismemberPartitionsFaces() const {
 	return dismemberPartitionsFaces;
 }
 
-void ComplexShape::SetDismemberPartitionsFaces( vector<int> value ) {
-	dismemberPartitionsFaces = value;
+void ComplexShape::SetDismemberPartitionsFaces(const vector<int>& value ) {
+	dismemberPartitionsFaces.resize(value.size());
+
+	for(int i = 0; i < dismemberPartitionsFaces.size(); i++) {
+		dismemberPartitionsFaces[i] = value[i];
+	}
 }
 
 vector<BodyPartList> ComplexShape::GetDismemberPartitionsBodyParts() const {
 	return dismemberPartitionsBodyParts;
 }
 
-void ComplexShape::SetDismemberPartitionsBodyParts( vector<BodyPartList> value ) {
+void ComplexShape::SetDismemberPartitionsBodyParts( const vector<BodyPartList>& value ) {
 	dismemberPartitionsBodyParts = value;
 }
 
@@ -787,11 +791,14 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int
 		vector<Triangle> shapeTriangles;
 
 		//a vector that holds in what dismember groups or skin partition does each face belong
-		vector<BodyPartList> current_dismember_partitions;
+		vector<BodyPartList> current_dismember_partitions = dismemberPartitionsBodyParts;
 
 		//create a map betweem the faces and the dismember groups
 		vector<int> current_dismember_partitions_faces;
 
+		//since we might have dismember partitions the face index is also required
+		int current_face_index = 0;
+
 		//Loop through all faces, and all points on each face
 		//to set the vertices in the CompoundVertex list
 		for ( vector<ComplexFace>::const_iterator face = faces.begin(); face != faces.end(); ++face ) {
@@ -887,18 +894,16 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int
 					shapeTriangles.push_back(new_face);
 
 					//all the resulting triangles belong in the the same dismember partition or better said skin partition
-					current_dismember_partitions_faces.push_back(dismemberPartitionsFaces[i]);
+					current_dismember_partitions_faces.push_back(dismemberPartitionsFaces[current_face_index]);
 				}
-			}			
+			}
+			current_face_index++;
 		}
 
 		//Clean up the dismember skin partitions
 		//if no face points to a certain dismember partition then that dismember partition must be removed
 		if(use_dismember_partitions == true) {
-			vector<bool> used_dismember_groups;
-			for(int x = 0; x < current_dismember_partitions.size(); x++) {
-				used_dismember_groups.push_back(false);
-			}
+			vector<bool> used_dismember_groups(current_dismember_partitions.size(), false);
 			for(int x = 0; x < current_dismember_partitions_faces.size(); x++) {
 				if(used_dismember_groups[current_dismember_partitions_faces[x]] == false) {
 					used_dismember_groups[current_dismember_partitions_faces[x]] = true;
@@ -921,7 +926,7 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int
 		}
 
 		//Attatch properties if any
-		//Check if the properties are skyrim specific in which case attach them in the 2 special slots
+		//Check if the properties are skyrim specific in which case attach them in the 2 special slots called bs_properties
 		if ( propGroups.size() > 0 ) {
 			BSLightingShaderPropertyRef shader_property = NULL;
 
-- 
GitLab