From a291fb4d520f248ae131e2a1b5032a4a3f3452e1 Mon Sep 17 00:00:00 2001 From: Tazpn <tazpn@users.sourceforge.net> Date: Sun, 1 Jul 2007 18:25:43 +0000 Subject: [PATCH] Miscellaneous fixes: - Fix issue with exporting Skin data causing missing vertexes in nifskope - add helper methods for collision related export. - fix crashes when exporting animation --- include/Ref.h | 4 +-- include/obj/hkPackedNiTriStripsData.h | 26 ++++++++++++++++++++ src/niflib.cpp | 6 ++--- src/obj/NiAVObject.cpp | 8 ++++++ src/obj/NiMorphData.cpp | 2 +- src/obj/NiSkinData.cpp | 5 ++-- src/obj/bhkListShape.cpp | 3 +++ src/obj/hkPackedNiTriStripsData.cpp | 35 +++++++++++++++++++++++++++ 8 files changed, 81 insertions(+), 8 deletions(-) diff --git a/include/Ref.h b/include/Ref.h index 01bb038f..16a04774 100644 --- a/include/Ref.h +++ b/include/Ref.h @@ -112,7 +112,7 @@ Ref<T> & Ref<T>::operator=( T * object ) { object->AddRef(); } - //Decriment reference count on previously referenced object, if any + //Decrement reference count on previously referenced object, if any if ( _object != NULL ) { _object->SubtractRef(); } @@ -136,7 +136,7 @@ Ref<T> & Ref<T>::operator=( const Ref & ref ) { ref._object->AddRef(); } - //Decriment reference count on previously referenced object, if any + //Decrement reference count on previously referenced object, if any if ( _object != NULL ) { _object->SubtractRef(); } diff --git a/include/obj/hkPackedNiTriStripsData.h b/include/obj/hkPackedNiTriStripsData.h index 61326f47..99b04fc3 100644 --- a/include/obj/hkPackedNiTriStripsData.h +++ b/include/obj/hkPackedNiTriStripsData.h @@ -82,6 +82,32 @@ public: */ NIFLIB_API vector<Vector3> GetNormals() const; + /*! Returns the number of vertices that make up this mesh. + * \return The number of faces that make up this mesh. + */ + NIFLIB_API virtual int GetNumFace( ) const; + + /*! Returns the number of vertices that make up this mesh. + * \param value The number of faces that make up this mesh. + */ + NIFLIB_API virtual void SetNumFaces( int value ); + + /*! Replaces the triangle face data in this mesh with new data. + * \param in A vector containing the new face data. Maximum size is 65,535. + * \sa ITriShapeData::GetTriangles + */ + NIFLIB_API virtual void SetTriangles( const vector<Triangle> & in ); + + /*! Replaces the face normal data in this mesh with new data. + * \param in A vector containing the new face normal data. + */ + NIFLIB_API virtual void SetNormals( const vector<Vector3> & in ); + + /*! Replaces the vertex data in this mesh with new data. + * \param in A vector containing the new vertex data. + */ + NIFLIB_API virtual void SetVertices( const vector<Vector3> & in ); + //--END CUSTOM CODE--// protected: /*! Number of triangles? */ diff --git a/src/niflib.cpp b/src/niflib.cpp index a813f391..f5ee1079 100644 --- a/src/niflib.cpp +++ b/src/niflib.cpp @@ -55,7 +55,7 @@ NiObjectRef GetObjectByType( NiObject * root, const Type & type ); * \param kf_type What type of keyframe tree to write (Morrowind style, DAoC style, ...). * \param info A NifInfo structure that contains information such as the version of the NIF file to create. */ -static void SplitNifTree( NiObject * root_object, NiObject * xnif_root, list<NiObjectRef> & xkf_roots, Kfm & kfm, int kf_type, const NifInfo & info ); +static void SplitNifTree( NiObject * root_object, NiObjectRef& xnif_root, list<NiObjectRef> & xkf_roots, Kfm & kfm, int kf_type, const NifInfo & info ); //--Function Bodies--// @@ -600,7 +600,7 @@ static std::string CreateFileName(std::string name) { } //TODO: This was written by Amorilia. Figure out how to fix it. -static void SplitNifTree( NiObject * root_object, NiObject * xnif_root, list<NiObjectRef> & xkf_roots, Kfm & kfm, int kf_type, const NifInfo & info ) { +static void SplitNifTree( NiObject* root_object, NiObjectRef& xnif_root, list<NiObjectRef> & xkf_roots, Kfm & kfm, int kf_type, const NifInfo & info ) { // Do we have animation groups (a NiTextKeyExtraData object)? // If so, create XNif and XKf trees. NiObjectRef txtkey = GetObjectByType( root_object, NiTextKeyExtraData::TYPE ); @@ -611,7 +611,6 @@ static void SplitNifTree( NiObject * root_object, NiObject * xnif_root, list<NiO if ( txtkey_obj != NULL ) { if ( kf_type == KF_MW ) { // Construct the XNif file... - xnif_root = CloneNifTree( root_object, info.version, info.userVersion ); // Now search and locate newer timeframe controllers and convert to keyframecontrollers @@ -724,6 +723,7 @@ static void SplitNifTree( NiObject * root_object, NiObject * xnif_root, list<NiO for (vector<NiControllerSequenceRef>::iterator itr = seqs.begin(); itr != seqs.end(); ++itr) { xkf_roots.push_back( StaticCast<NiObject>(*itr) ); } + mgr->ClearSequences(); } } else { throw runtime_error("KF splitting for the requested game is not yet implemented."); diff --git a/src/obj/NiAVObject.cpp b/src/obj/NiAVObject.cpp index d83a7be9..befd911b 100644 --- a/src/obj/NiAVObject.cpp +++ b/src/obj/NiAVObject.cpp @@ -53,6 +53,8 @@ NiObject * NiAVObject::Create() { return new NiAVObject; } +extern "C" int __stdcall IsDebuggerPresent(); + void NiAVObject::Read( istream& in, list<unsigned int> & link_stack, const NifInfo & info ) { //--BEGIN PRE-READ CUSTOM CODE--// //--END CUSTOM CODE--// @@ -61,6 +63,12 @@ void NiAVObject::Read( istream& in, list<unsigned int> & link_stack, const NifIn NiObjectNET::Read( in, link_stack, info ); NifStream( flags, in, info ); NifStream( translation, in, info ); + + //if (name.compare("Bip01 R Finger01") == 0) { + // if (IsDebuggerPresent()) + // __asm{ int 3 }; + //} + NifStream( rotation, in, info ); NifStream( scale, in, info ); if ( info.version <= 0x04020200 ) { diff --git a/src/obj/NiMorphData.cpp b/src/obj/NiMorphData.cpp index 9c059d0d..848a931b 100644 --- a/src/obj/NiMorphData.cpp +++ b/src/obj/NiMorphData.cpp @@ -20,7 +20,7 @@ using namespace Niflib; //Definition of TYPE constant const Type NiMorphData::TYPE("NiMorphData", &NiObject::TYPE ); -NiMorphData::NiMorphData() : numMorphs((unsigned int)0), numVertices((unsigned int)0), unknownByte((byte)0) { +NiMorphData::NiMorphData() : numMorphs((unsigned int)0), numVertices((unsigned int)0), unknownByte((byte)1) { //--BEGIN CONSTRUCTOR CUSTOM CODE--// //--END CUSTOM CODE--// } diff --git a/src/obj/NiSkinData.cpp b/src/obj/NiSkinData.cpp index bdefaeeb..250e34b6 100644 --- a/src/obj/NiSkinData.cpp +++ b/src/obj/NiSkinData.cpp @@ -234,9 +234,10 @@ void NiSkinData::SetBoneWeights( unsigned int bone_index, const vector<SkinWeigh throw runtime_error( "The specified bone index was larger than the number of bones in this NiSkinData." ); } + hasVertexWeights = true; boneList[bone_index].vertexWeights = weights; - boneList[bone_index].boundingSphereOffset = center; - boneList[bone_index].boundingSphereRadius = radius; + boneList[bone_index].boundingSphereOffset = center; + boneList[bone_index].boundingSphereRadius = radius; } Matrix44 NiSkinData::GetOverallTransform() const { diff --git a/src/obj/bhkListShape.cpp b/src/obj/bhkListShape.cpp index 4ff45a32..ce10aeac 100644 --- a/src/obj/bhkListShape.cpp +++ b/src/obj/bhkListShape.cpp @@ -193,6 +193,9 @@ vector<Ref<bhkShape > > bhkListShape::GetSubShapes() const { */ void bhkListShape::SetSubShapes(const vector<Ref<bhkShape > >& shapes) { subShapes = shapes; + + // Becuase this vector matches the subshape vector + unknownInts.resize(subShapes.size(), 0); } //--END CUSTOM CODE--// diff --git a/src/obj/hkPackedNiTriStripsData.cpp b/src/obj/hkPackedNiTriStripsData.cpp index ecf48621..bc9efb2c 100644 --- a/src/obj/hkPackedNiTriStripsData.cpp +++ b/src/obj/hkPackedNiTriStripsData.cpp @@ -169,5 +169,40 @@ vector<Vector3> hkPackedNiTriStripsData::GetVertices() const { return vertices; } +int hkPackedNiTriStripsData::GetNumFace( ) const { + return int(triangles.size()); +} + +void hkPackedNiTriStripsData::SetNumFaces( int value ) { + if ( value > 65535 || value < 0 ) { + throw runtime_error("Invalid Face Count: must be between 0 and 65535."); + } + triangles.resize(value); +} + +void hkPackedNiTriStripsData::SetTriangles( const vector<Triangle> & in ) { + if ( triangles.size() != in.size()) { + throw runtime_error("Invalid Face Count: triangle count must be same as face count."); + } + for (size_t i=0; i<triangles.size(); ++i) { + triangles[i].triangle = in[i]; + } +} + +void hkPackedNiTriStripsData::SetNormals( const vector<Vector3> & in ) { + if ( triangles.size() != in.size()) { + throw runtime_error("Invalid Face Count: normal count must be same as face count."); + } + for (size_t i=0; i<triangles.size(); ++i) { + triangles[i].normal = in[i]; + } +} + +void hkPackedNiTriStripsData::SetVertices( const vector<Vector3> & in ) { + if ( in.size() > 65535 || in.size() < 0 ) { + throw runtime_error("Invalid Vertex Count: must be between 0 and 65535."); + } + vertices = in; +} //--END CUSTOM CODE--// -- GitLab