# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

lod_character_shape.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_LOD_CHARACTER_SHAPE_H
00027 #define NL_LOD_CHARACTER_SHAPE_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/common.h"
00031 #include "3d/mesh.h"
00032 
00033 
00034 namespace NL3D 
00035 {
00036 
00037 
00038 // ***************************************************************************
00046 class CLodCharacterShapeBuild
00047 {
00048 public:
00049         // The Vertices of the shapes
00050         std::vector<CVector>                    Vertices;
00051 
00052         // Palette Skinning Vertices array (same size as Vertices).
00053         std::vector<CMesh::CSkinWeight> SkinWeights;
00054 
00055         // Bones name. Each matrix id used in SkinWeights must have a corresponding string in the bone name array.
00056         std::vector<std::string>                BonesNames;
00057 
00058         // Faces array
00059         std::vector<uint32>                             TriangleIndices;
00060 
00061 
00062         void    serial(NLMISC::IStream &f);
00063 
00064 };
00065 
00066 
00067 // ***************************************************************************
00074 class CLodCharacterShape
00075 {
00076 public:
00077 
00079         struct  CAnimBuild
00080         {
00082                 std::string             Name;
00084                 uint                    NumKeys;
00086                 float                   AnimLength;
00087 
00089                 std::vector<CVector>    Keys;
00090         };
00091 
00093         struct  CVector3s
00094         {
00095                 sint16  x,y,z;
00096 
00097                 void            serial(NLMISC::IStream &f)
00098                 {
00099                         f.serial(x,y,z);
00100                 }
00101         };
00102 
00103 public:
00104 
00106         CLodCharacterShape();
00107 
00111         void                    buildMesh(const std::string &name, const CLodCharacterShapeBuild &lodBuild);
00112 
00116         bool                    addAnim(const CAnimBuild &animBuild);
00117 
00119         void                    serial(NLMISC::IStream &f);
00120 
00122         const std::string &             getName() const {return _Name;}
00123 
00125         sint                    getAnimIdByName(const std::string &name) const;
00126 
00128         uint                    getNumVertices() const {return _NumVertices;}
00129 
00131         uint                    getNumTriangles() const {return _NumTriangles;}
00132 
00134         uint                    getNumBones() const {return _Bones.size();}
00135 
00137         sint                    getBoneIdByName(const std::string &name) const;
00138 
00140         const uint32    *getTriangleArray() const;
00141 
00143         // @{
00144 
00146         void                    startBoneColor(std::vector<NLMISC::CRGBAF>      &tmpColors) const;
00147 
00149         void                    addBoneColor(uint boneId, CRGBA color, std::vector<NLMISC::CRGBAF> &tmpColors) const;
00150 
00156         void                    endBoneColor(const std::vector<NLMISC::CRGBAF> &tmpColors, std::vector<NLMISC::CRGBA>   &dstColors) const;
00157 
00158         // @}
00159 
00165         const CVector3s *getAnimKey(uint animId, TGlobalAnimationTime time, bool wrapMode, CVector &unPackScaleFactor) const;
00166 
00167 
00168 // *******************************
00169 private:
00170 
00172         struct  CAnim
00173         {
00175                 std::string             Name;
00177                 uint32                  NumKeys;
00179                 float                   AnimLength;
00180                 float                   OOAnimLength;
00182                 CVector                 UnPackScaleFactor;
00183 
00185                 std::vector<CVector3s>  Keys;
00186 
00187                 void                    serial(NLMISC::IStream &f);
00188         };
00189 
00190         struct  CVertexInf
00191         {
00192                 // Id of the vertex that the bone influence.
00193                 uint32          VertexId;
00194                 // weight of influence
00195                 float           Influence;
00196 
00197                 void            serial(NLMISC::IStream &f)
00198                 {
00199                         f.serial(VertexId);
00200                         f.serial(Influence);
00201                 }
00202         };
00203 
00205         struct  CBoneInfluence
00206         {
00207                 // Name of the bone.
00208                 std::string                             Name;
00209 
00210                 // list of vertex this bone influence.
00211                 std::vector<CVertexInf> InfVertices;
00212 
00213                 void            serial(NLMISC::IStream &f);
00214         };
00215 
00217         typedef std::map<std::string, uint32>   TStrIdMap;
00218         typedef TStrIdMap::iterator                             ItStrIdMap;
00219         typedef TStrIdMap::const_iterator               CstItStrIdMap;
00220 
00221 private:
00222         std::string                     _Name;
00223         uint32                          _NumVertices;
00224         uint32                          _NumTriangles;
00226         std::vector<CBoneInfluence>             _Bones;
00227 
00228         // The map of bone.
00229         TStrIdMap                       _BoneMap;
00230 
00232         std::vector<uint32>     _TriangleIndices;
00233 
00235         std::vector<CAnim>      _Anims;
00236 
00237         // The map of animation.
00238         TStrIdMap                       _AnimMap;
00239 
00240 };
00241 
00242 
00243 } // NL3D
00244 
00245 
00246 #endif // NL_LOD_CHARACTER_SHAPE_H
00247 
00248 /* End of lod_character_shape.h */