From 77a207f0bb03ccc4bd6d83971a236292a2e7e06c Mon Sep 17 00:00:00 2001 From: Alecu100 <lui_alecu@yahoo.co.uk> Date: Mon, 20 Feb 2012 01:01:30 +0200 Subject: [PATCH] fixed niflib to exporter geometry data with binormals and tangets in it but broke niflib a bit. WARNING! from now on niflib will cause bugs when regenerated because of this --- include/ComplexShape.h | 3 ++- src/ComplexShape.cpp | 12 ++++++++++-- src/obj/NiGeometryData.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/ComplexShape.h b/include/ComplexShape.h index 7358ed0d..6e0a5b60 100644 --- a/include/ComplexShape.h +++ b/include/ComplexShape.h @@ -182,7 +182,8 @@ public: int max_bones_per_partition = 4, bool stripify = false, bool tangent_space = false, - float min_vertex_weight = 0.001f + float min_vertex_weight = 0.001f, + byte tspace_flags = 0 ) const; /* diff --git a/src/ComplexShape.cpp b/src/ComplexShape.cpp index d0cf2069..307af656 100644 --- a/src/ComplexShape.cpp +++ b/src/ComplexShape.cpp @@ -703,7 +703,7 @@ void ComplexShape::Merge( NiAVObject * root ) { //Done Merging } -Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int max_bones_per_partition, bool stripify, bool tangent_space, float min_vertex_weight ) const { +Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int max_bones_per_partition, bool stripify, bool tangent_space, float min_vertex_weight, byte tspace_flags ) const { //Make sure parent is not NULL if ( parent == NULL ) { @@ -1092,7 +1092,15 @@ Ref<NiAVObject> ComplexShape::Split( NiNode * parent, Matrix44 & transform, int //If tangent space was requested, generate it if ( tangent_space ) { - shapes[shape_num]->UpdateTangentSpace(); + if(tspace_flags == 0) { + shapes[shape_num]->UpdateTangentSpace(); + } else { + if(shapes[shape_num]->GetData() != NULL) { + shapes[shape_num]->GetData()->SetUVSetCount(1); + shapes[shape_num]->GetData()->SetTspaceFlag(tspace_flags); + shapes[shape_num]->UpdateTangentSpace(1); + } + } } //Next Shape diff --git a/src/obj/NiGeometryData.cpp b/src/obj/NiGeometryData.cpp index 4ad2f1b1..84b57d56 100644 --- a/src/obj/NiGeometryData.cpp +++ b/src/obj/NiGeometryData.cpp @@ -155,7 +155,7 @@ void NiGeometryData::Write( ostream& out, const map<NiObjectRef,unsigned int> & //--END CUSTOM CODE--// NiObject::Write( out, link_map, missing_link_stack, info ); - bsNumUvSets = (unsigned short)(uvSets.size()); + bsNumUvSets = ((unsigned short)(uvSets.size()) | (bsNumUvSets & 0xFF00)); numUvSets = (unsigned short)(uvSets.size()); numVertices = (unsigned short)(vertices.size()); if ( info.version >= 0x0A020000 ) { @@ -659,12 +659,12 @@ void NiGeometryData::SetBound(Vector3 const & center, float radius) byte NiGeometryData::GetTspaceFlag() const { - return numUvSets | bsNumUvSets; + return (numUvSets | bsNumUvSets) >> 8; } void NiGeometryData::SetTspaceFlag( byte value ) { - numUvSets = value; - bsNumUvSets = value; + numUvSets = ((value << 8) | numUvSets); + bsNumUvSets = ((value << 8) | bsNumUvSets); } bool NiGeometryData::GetHasNormals() const { -- GitLab