| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of LEXIExporter |
|---|
| 4 | |
|---|
| 5 | Copyright 2006 NDS Limited |
|---|
| 6 | |
|---|
| 7 | Author(s): |
|---|
| 8 | Mark Folkenberg, |
|---|
| 9 | Bo Krohn |
|---|
| 10 | |
|---|
| 11 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 12 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 13 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 14 | version. |
|---|
| 15 | |
|---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 23 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 24 | ----------------------------------------------------------------------------- |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | #ifndef __MaxExporter_IntermediateSkeleton__ |
|---|
| 28 | #define __MaxExporter_IntermediateSkeleton__ |
|---|
| 29 | |
|---|
| 30 | // |
|---|
| 31 | |
|---|
| 32 | struct SVertexBoneData{ |
|---|
| 33 | ULONG boneIndex; |
|---|
| 34 | float weight; |
|---|
| 35 | bool bRead; |
|---|
| 36 | |
|---|
| 37 | public: |
|---|
| 38 | SVertexBoneData() |
|---|
| 39 | { |
|---|
| 40 | boneIndex = 0xFFFFFFFF; |
|---|
| 41 | weight = 0.0f; |
|---|
| 42 | bRead = false; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | bool operator< (const SVertexBoneData& other) |
|---|
| 46 | { |
|---|
| 47 | // We do it the other way around since we want to sort decenting |
|---|
| 48 | if(weight > other.weight) |
|---|
| 49 | return true; |
|---|
| 50 | return false; |
|---|
| 51 | } |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | class CIntermediateSkeleton { |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | private: |
|---|
| 59 | |
|---|
| 60 | std::vector<CIntermediateBone*> m_BoneList; |
|---|
| 61 | std::vector<CIntermediateBone*> m_RootBoneList; |
|---|
| 62 | std::map<int, CIntermediateBone*> m_IndexedBoneList; |
|---|
| 63 | std::map<std::string, CIntermediateBone*> m_BoneNameList; |
|---|
| 64 | |
|---|
| 65 | std::map< ULONG, CIntermediateBone* > m_BoneHandles; |
|---|
| 66 | std::map< int, std::vector<SVertexBoneData> > m_VertexBoneData; |
|---|
| 67 | |
|---|
| 68 | std::map< int, std::vector<SVertexBoneData> > m_ReindexVertexBoneData; |
|---|
| 69 | |
|---|
| 70 | float m_fFPS; |
|---|
| 71 | |
|---|
| 72 | bool RecursiveAssembleBones( CIntermediateBone* pIBone ); |
|---|
| 73 | void RecursivePopulateBoneHandleMap( CIntermediateBone* pIBone ); |
|---|
| 74 | |
|---|
| 75 | void print( std::stringstream& output, CIntermediateBone* pBone, int indent=0); |
|---|
| 76 | void printAnimationData( std::stringstream& output, CIntermediateBone* pBone, int indent); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | public: |
|---|
| 80 | |
|---|
| 81 | // |
|---|
| 82 | // General |
|---|
| 83 | // |
|---|
| 84 | |
|---|
| 85 | // Constructor/Destructor |
|---|
| 86 | CIntermediateSkeleton(); |
|---|
| 87 | ~CIntermediateSkeleton(); |
|---|
| 88 | |
|---|
| 89 | // Clear everything |
|---|
| 90 | void clear(); |
|---|
| 91 | |
|---|
| 92 | // Set FPS |
|---|
| 93 | void SetFPS(float fFPS); |
|---|
| 94 | |
|---|
| 95 | // Get FPS |
|---|
| 96 | float GetFPS() const; |
|---|
| 97 | |
|---|
| 98 | void PopulateBoneHandleMap( void ); |
|---|
| 99 | void BuildIndexedBoneList( void ); |
|---|
| 100 | |
|---|
| 101 | CIntermediateBone* FindBone( ULONG handle ); |
|---|
| 102 | |
|---|
| 103 | int GetNrOfAssignmentsOnVertex( int idx ); |
|---|
| 104 | void TrimVertexAssignments( int iMaxAssignments ); |
|---|
| 105 | void NormalizeVertexAssignments( void ); |
|---|
| 106 | bool GetVertexData( int idx, int assignmentNr, SVertexBoneData& returnVal); |
|---|
| 107 | bool AddVertexData( int idx, SVertexBoneData vertexData ); |
|---|
| 108 | |
|---|
| 109 | bool AssembleBones( void ); |
|---|
| 110 | |
|---|
| 111 | void ExtractVertexAssignmentsArrays( SharedUtilities::fastvector< CMeshArray* > &bufferList ); |
|---|
| 112 | bool ApplyVertexAssignmentsArrays( SharedUtilities::fastvector< CMeshArray* > &bufferList ); |
|---|
| 113 | |
|---|
| 114 | //bool PrepareReindexChange( int oldIndex, int newIndex ); |
|---|
| 115 | //bool ApplyReindexChanges( void ); |
|---|
| 116 | |
|---|
| 117 | void MarkBoneAsRoot( CIntermediateBone* pIBone ); |
|---|
| 118 | const std::vector<CIntermediateBone*>& GetRootBones( void ) const; |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | std::string ToString( void ); |
|---|
| 122 | // |
|---|
| 123 | // Bones |
|---|
| 124 | // |
|---|
| 125 | |
|---|
| 126 | // Get number of bones |
|---|
| 127 | unsigned int GetBoneCount() const; |
|---|
| 128 | |
|---|
| 129 | // Get bone |
|---|
| 130 | CIntermediateBone* GetBone(unsigned int iBone); |
|---|
| 131 | const CIntermediateBone* GetBone(unsigned int iBone) const; |
|---|
| 132 | CIntermediateBone* GetBoneByName( const char* pszName ) const; |
|---|
| 133 | CIntermediateBone* GetBoneByIndex( int index ) const; |
|---|
| 134 | |
|---|
| 135 | // Get bone name |
|---|
| 136 | std::string GetBoneName(unsigned int iBone) const; |
|---|
| 137 | |
|---|
| 138 | // Add bone |
|---|
| 139 | void AddBone(CIntermediateBone* pBone, const char* pszName); |
|---|
| 140 | //bool AddBone(const char* pszName, unsigned int iNodeID, unsigned int iStartFrame, unsigned int iEndFrame, unsigned int iSampleRate); |
|---|
| 141 | |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | // |
|---|
| 145 | |
|---|
| 146 | #endif // __MaxExporter_IntermediateSkeleton__ |
|---|