Skip to content
Snippets Groups Projects
Commit cadf0700 authored by Alecu100's avatar Alecu100
Browse files

added support for dismember skin in the complex shape. still bugged

parent b3138e29
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ All rights reserved. Please see niflib.h for license. */ ...@@ -6,6 +6,7 @@ All rights reserved. Please see niflib.h for license. */
#include "Ref.h" #include "Ref.h"
#include "obj/BSDismemberSkinInstance.h" #include "obj/BSDismemberSkinInstance.h"
#include "obj/NiSkinPartition.h"
#include "nif_math.h" #include "nif_math.h"
#include "nif_basic_types.h" #include "nif_basic_types.h"
#include "gen/BodyPartList.h" #include "gen/BodyPartList.h"
...@@ -21,6 +22,7 @@ class NiNode; ...@@ -21,6 +22,7 @@ class NiNode;
class NiAVObject; class NiAVObject;
class NiTriBasedGeom; class NiTriBasedGeom;
class BSDismemberSkinInstance; class BSDismemberSkinInstance;
class NiSkinPartition;
/*! Marks empty data indices */ /*! Marks empty data indices */
const unsigned int CS_NO_INDEX = 0xFFFFFFFF; const unsigned int CS_NO_INDEX = 0xFFFFFFFF;
......
...@@ -58,12 +58,16 @@ public: ...@@ -58,12 +58,16 @@ public:
//--BEGIN MISC CUSTOM CODE--// //--BEGIN MISC CUSTOM CODE--//
// Get list of dismemberment partitions /*!
// \return The current value. * Get list of dismemberment partitions
* \return The current value.
*/
NIFLIB_API vector<BodyPartList > GetPartitions() const; NIFLIB_API vector<BodyPartList > GetPartitions() const;
// Assign the dismemberment partition list /*!
// \param[in] value The new value. * Assign the dismemberment partition list
* \param[in] value The new value.
*/
NIFLIB_API void SetPartitions( const vector<BodyPartList >& value ); NIFLIB_API void SetPartitions( const vector<BodyPartList >& value );
//--END CUSTOM CODE--// //--END CUSTOM CODE--//
......
...@@ -212,7 +212,7 @@ void ComplexShape::Merge( NiAVObject * root ) { ...@@ -212,7 +212,7 @@ void ComplexShape::Merge( NiAVObject * root ) {
//Add it to the list //Add it to the list
shapes.push_back( DynamicCast<NiTriBasedGeom>(root) ); shapes.push_back( DynamicCast<NiTriBasedGeom>(root) );
} else if ( root->IsDerivedType( NiNode::TYPE ) ) { } else if ( root->IsDerivedType( NiNode::TYPE ) ) {
//The function was called on a NiNOde. Search for //The function was called on a NiNode. Search for
//shape children //shape children
NiNodeRef nodeRoot = DynamicCast<NiNode>(root); NiNodeRef nodeRoot = DynamicCast<NiNode>(root);
vector<NiAVObjectRef> children = nodeRoot->GetChildren(); vector<NiAVObjectRef> children = nodeRoot->GetChildren();
...@@ -270,6 +270,11 @@ void ComplexShape::Merge( NiAVObject * root ) { ...@@ -270,6 +270,11 @@ void ComplexShape::Merge( NiAVObject * root ) {
//If this is a skin influenced mesh, get vertices from niGeom //If this is a skin influenced mesh, get vertices from niGeom
if ( (*geom)->GetSkinInstance() != NULL ) { if ( (*geom)->GetSkinInstance() != NULL ) {
(*geom)->GetSkinDeformation( shapeVerts, shapeNorms ); (*geom)->GetSkinDeformation( shapeVerts, shapeNorms );
if((*geom)->GetSkinInstance()->GetType().IsSameType(BSDismemberSkinInstance::TYPE)) {
BSDismemberSkinInstanceRef dismember_skin = DynamicCast<BSDismemberSkinInstance>((*geom)->GetSkinInstance());
NiSkinPartitionRef skin_partition = dismember_skin->GetSkinPartition();
}
} else { } else {
shapeVerts = geomData->GetVertices(); shapeVerts = geomData->GetVertices();
shapeNorms = geomData->GetNormals(); shapeNorms = geomData->GetNormals();
...@@ -424,7 +429,7 @@ void ComplexShape::Merge( NiAVObject * root ) { ...@@ -424,7 +429,7 @@ void ComplexShape::Merge( NiAVObject * root ) {
uvSetIndex = (unsigned int)(texCoordSets.size()) - 1; uvSetIndex = (unsigned int)(texCoordSets.size()) - 1;
} }
//Loop through texture cooridnates in this set //Loop through texture coordinates in this set
if ( set >= shapeUVs.size() || set < 0 ) { if ( set >= shapeUVs.size() || set < 0 ) {
throw runtime_error("One of the UV sets specified in the NiTexturingProperty did not exist in the NiTriBasedGeomData."); throw runtime_error("One of the UV sets specified in the NiTexturingProperty did not exist in the NiTriBasedGeomData.");
} }
...@@ -433,7 +438,7 @@ void ComplexShape::Merge( NiAVObject * root ) { ...@@ -433,7 +438,7 @@ void ComplexShape::Merge( NiAVObject * root ) {
newCoord = shapeUVs[set][v]; newCoord = shapeUVs[set][v];
//Search for matching texture cooridnate //Search for matching texture coordinate
bool match_found = false; bool match_found = false;
for ( unsigned int tc_index = 0; tc_index < texCoordSets[uvSetIndex].texCoords.size(); ++tc_index ) { for ( unsigned int tc_index = 0; tc_index < texCoordSets[uvSetIndex].texCoords.size(); ++tc_index ) {
if ( texCoordSets[uvSetIndex].texCoords[tc_index] == newCoord ) { if ( texCoordSets[uvSetIndex].texCoords[tc_index] == newCoord ) {
...@@ -506,6 +511,95 @@ void ComplexShape::Merge( NiAVObject * root ) { ...@@ -506,6 +511,95 @@ void ComplexShape::Merge( NiAVObject * root ) {
} }
} }
} }
//Check to see if the skin is actually a dismember skin instance in which case import the partitions too
if(skinInst->GetType().IsSameType(BSDismemberSkinInstance::TYPE)) {
BSDismemberSkinInstanceRef dismember_skin = DynamicCast<BSDismemberSkinInstance>((*geom)->GetSkinInstance());
NiSkinPartitionRef skin_partition = dismember_skin->GetSkinPartition();
//These are the partition data of the current shapes
vector<BodyPartList> current_body_parts;
vector<int> current_body_parts_faces;
for(int y = 0; y < dismember_skin->GetPartitions().size(); y++) {
current_body_parts.push_back(dismember_skin->GetPartitions().at(y));
}
for(int y = 0; y < shapeTris.size(); y++) {
current_body_parts_faces.push_back(0);
}
for(int y = 0; y < skin_partition->GetNumPartitions(); y++) {
vector<Triangle> partition_triangles = skin_partition->GetTriangles(y);
for(int z = 0; z < partition_triangles.size(); z++) {
int w = faces.size() - shapeTris.size();
int merged_x = lookUp[partition_triangles[z].v1].vertIndex;
int merged_y = lookUp[partition_triangles[z].v2].vertIndex;
int merged_z = lookUp[partition_triangles[z].v3].vertIndex;
for(; w < faces.size(); w++) {
ComplexFace current_face = faces[w];
bool is_same_face = false;
if(current_face.points[0].vertexIndex == merged_x) {
if(current_face.points[1].vertexIndex == merged_y && current_face.points[2].vertexIndex == merged_z) {
is_same_face = true;
break;
} else if(current_face.points[2].vertexIndex == merged_y && current_face.points[1].vertexIndex == merged_z) {
is_same_face = true;
break;
}
} else if(current_face.points[1].vertexIndex == merged_x) {
if(current_face.points[0].vertexIndex == merged_y && current_face.points[2].vertexIndex == merged_z) {
is_same_face = true;
break;
} else if(current_face.points[2].vertexIndex == merged_y && current_face.points[0].vertexIndex == merged_z) {
is_same_face = true;
break;
}
} else if(current_face.points[2].vertexIndex == merged_x) {
if(current_face.points[0].vertexIndex == merged_y && current_face.points[1].vertexIndex == merged_z) {
is_same_face = true;
break;
} else if(current_face.points[1].vertexIndex == merged_y && current_face.points[0].vertexIndex == merged_z) {
is_same_face = true;
break;
}
}
}
if(w < faces.size() && w >= faces.size() - shapeTris.size()) {
current_body_parts_faces[w - shapeTris.size()] = y;
} else {
throw runtime_error("Could not find a skin partition face inside the complex shape faces");
}
}
}
for(int y = 0; y < current_body_parts.size(); y++) {
int match_index = -1;
for(int z = 0; z < dismemberPartitionsBodyParts.size(); z++) {
if(dismemberPartitionsBodyParts[z].bodyPart == current_body_parts[y].bodyPart
&& dismemberPartitionsBodyParts[z].partFlag == current_body_parts[y].partFlag) {
match_index = z;
break;
}
}
if(match_index < 0) {
dismemberPartitionsBodyParts.push_back(current_body_parts[y]);
match_index = dismemberPartitionsBodyParts.size() - 1;
}
for(int z = 0; z < current_body_parts_faces.size(); z++) {
if(current_body_parts_faces[z] == y) {
current_body_parts_faces[z] = match_index;
}
}
}
}
} }
//Next Shape //Next Shape
...@@ -871,6 +965,8 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int ...@@ -871,6 +965,8 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int
shapes[shape_num]->BindSkin( shapeInfluences ); shapes[shape_num]->BindSkin( shapeInfluences );
} else { } else {
shapes[shape_num]->BindSkinWith( shapeInfluences, BSDismemberSkinInstance::Create ); shapes[shape_num]->BindSkinWith( shapeInfluences, BSDismemberSkinInstance::Create );
BSDismemberSkinInstanceRef dismember_skin = DynamicCast<BSDismemberSkinInstance>(shapes[shape_num]->GetSkinInstance());
dismember_skin->SetPartitions(current_dismember_partitions);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment