diff --git a/obj/NiMorphData.cpp b/obj/NiMorphData.cpp index 08536f5c6f63a8382ab7ccdc9f1e73b1850fc59e..99bc06dc98a89b092aac37a54fc255a7c65a237f 100644 --- a/obj/NiMorphData.cpp +++ b/obj/NiMorphData.cpp @@ -35,3 +35,57 @@ const Type & NiMorphData::GetType() const { return TYPE; }; +int NiMorphData::GetVertexCount() const { + + return numVertices; +} + +void NiMorphData::SetVertexCount( int n ) { + numVertices = n; + for ( uint i = 0; i < morphs.size(); ++i ) { + morphs[i].vectors.resize( n ); + } +} + +int NiMorphData::GetMorphCount() const { + return int(morphs.size()); +} + +void NiMorphData::SetMorphCount( int n ) { + int old_size = morphs.size(); + morphs.resize( n ); + + //Make sure any new vertex groups are the right size + for (uint i = old_size; i < morphs.size(); ++i ) { + morphs[i].vectors.resize( numVertices ); + } +} + +KeyType NiMorphData::GetMorphKeyType( int n ) const { + return morphs[n].morphInterpolation; +} + +void NiMorphData::SetMorphKeyType( int n, KeyType t ) { + morphs[n].morphInterpolation = t; +} + +vector< Key<float> > NiMorphData::GetMorphKeys( int n ) const { + return morphs[n].morphKeys; +} + +void NiMorphData::SetMorphKeys( int n, vector< Key<float> > const & keys ) { + morphs[n].morphKeys = keys; +} + +vector<Vector3> NiMorphData::GetMorphVerts( int n) const { + return morphs[n].vectors; +} + +void NiMorphData::SetMorphVerts( int n, const vector<Vector3> & in ) { + // Make sure the size of the incoming vector equal vertCount + if ( in.size() != numVertices ) + throw runtime_error("Input array size must equal Vertex Count. Call SetVertexCount() to resize."); + + //It's the right size, so go ahead and set it + morphs[n].vectors = in; +} diff --git a/obj/NiMorphData.h b/obj/NiMorphData.h index 3f1395abf5a98bfe96fc971565def357988423fe..80c959cf641fb5cce91ebb8fe2ff715b4308a888 100644 --- a/obj/NiMorphData.h +++ b/obj/NiMorphData.h @@ -29,6 +29,71 @@ public: virtual void FixLinks( const vector<NiObjectRef> & objects, list<uint> & link_stack, unsigned int version, unsigned int user_version ); virtual list<NiObjectRef> GetRefs() const; virtual const Type & GetType() const; + + /*! Retrieves the number of verticies used in the morph targets. This must be the same as the number of verticies in the base mesh that the morph controller for which this block stores data is attatched. This is not done automatically by Niflib. + * \return The number of vertices used in the morph target meshes. + * \sa NiMorphData::SetVertexCount + */ + int GetVertexCount() const; + + /*! Sets the number of verticies used in the morph targets. This must be the same as the number of verticies in the base mesh that the morph controller for which this block stores data is attatched. This is not done automatically by Niflib. If the new size is smaller, vertices at the ends of the morph targets will be lost. + * \param n The new size of the morph target's vertex arrays. + * \sa NiMorphData::GetVertexCount + */ + void SetVertexCount( int n ); + + /*! Retrieves the number of morph targets used by this morph controller data. + * \return The number of morph targets used by this morph controller data. + * \sa NiMorphData::SetMorphCount + */ + int GetMorphCount() const; + + /*! Resizes the morph target array used by this morph controller data. If the new size is smaller, morph targets at the end of the array and all associated data will be lost. + * \param n The new size of the morph target array. + * \sa NiMorphData::GetMorphCount + */ + void SetMorphCount( int n ); + + /*! Retrieves the type of morph interpolation being used by a specific morph target. + * \param n The index of the morph to get the interpolation key type from. A zero-based positive value which must be less than that returned by IMoprhData::GetMorphCount. + * \return The morph key type specifing the type of interpolation being used by the specified morph target. + * \sa NiMorphData::SetMorphKeyType + */ + KeyType GetMorphKeyType( int n ) const; + + /*! Sets the type of morph interpolation being used by a specific morph target. Does not affect existing key data. + * \param n The index of the morph to get the interpolation key type from. A zero-based positive value which must be less than that returned by IMoprhData::GetMorphCount. + * \param t The new morph key type specifing the type of interpolation to be used by the specified morph target. + * \sa NiMorphData::GetMorphKeyType + */ + void SetMorphKeyType( int n, KeyType t ); + + /*! Retrieves the morph key data for a specified morph target. + * \return A vector containing Key<float> data which specify the influence of this morph target over time. + * \sa NiMorphData::SetMorphKeys, Key + */ + vector< Key<float> > GetMorphKeys( int n ) const; + + /*! Sets the morph key data. + * \param keys A vector containing new Key<float> data which will replace any existing data for this morph target. + * \sa NiMorphData::GetMorphKeys, Key + */ + void SetMorphKeys( int n, vector< Key<float> > const & keys ); + + /*! Retrieves the vertex data from the specified morph target + * \param n The index of the morph target to retrieve vertex data for. This is a zero-based index whoes value that must be less than that returned by NiMorphData::GetMorphCount. + * \return A vector containing the vertices used by this morph target. The size will be equal to the value returned by NiMorphData::GetVertexCount. + * \sa NiMorphData::SetMorphVerts + */ + vector<Vector3> GetMorphVerts( int n) const; + + /*! Sets the vertex data for a specified morph target + * \param n The index of the morph target to set vertex data for. This is a zero-based index whoes value that must be less than that returned by NiMorphData::GetMorphCount. + * \param in A vector containing the new vertices to be used by this morph target. The size will be equal to the value returned by NiMorphData::GetVertexCount. + * \sa NiMorphData::SetMorphVerts + */ + void SetMorphVerts( int n, const vector<Vector3> & in ); + protected: NI_MORPH_DATA_MEMBERS };