lod_character_shape.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000-2002 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_LOD_CHARACTER_SHAPE_H
00025 #define NL_LOD_CHARACTER_SHAPE_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/common.h"
00029 #include "nel/3d/mesh.h"
00030 
00031 
00032 namespace NL3D
00033 {
00034 
00035 
00036 // ***************************************************************************
00044 class CLodCharacterShapeBuild
00045 {
00046 public:
00047     class   CPixelInfo
00048     {
00049     public:
00050         // The associated Pos/Normal of this pixel.
00051         CVector     Pos;
00052         CVector     Normal;
00053 
00054         // An id for an empty pixel.
00055         static const CPixelInfo     EmptyPixel;
00056 
00057     public:
00058         CPixelInfo() {}
00059         CPixelInfo(const CVector &pos, const CVector &normal) : Pos(pos), Normal(normal) {}
00060         bool        operator==(const CPixelInfo &o) const
00061         {
00062             return Pos==o.Pos && Normal==o.Normal;
00063         }
00064 
00065         void        serial(NLMISC::IStream &f)
00066         {
00067             f.serial(Pos, Normal);
00068         }
00069     };
00070 
00071 public:
00072     CLodCharacterShapeBuild();
00073 
00074     // The Vertices of the shapes
00075     std::vector<CVector>            Vertices;
00076 
00077     // Palette Skinning Vertices array (same size as Vertices).
00078     std::vector<CMesh::CSkinWeight> SkinWeights;
00079 
00080     // UVs (same size as Vertices).
00081     std::vector<CUV>                UVs;
00082 
00083     // Normals (same size as Vertices).
00084     std::vector<CVector>            Normals;
00085 
00086     // Bones name. Each matrix id used in SkinWeights must have a corresponding string in the bone name array.
00087     std::vector<std::string>        BonesNames;
00088 
00089     // Faces array
00090     std::vector<uint32>             TriangleIndices;
00091 
00092 
00093 public:
00094 
00101     void                compile(const std::vector<bool> &triangleSelection, uint textureOverSample=25);
00102 
00104     void                serial(NLMISC::IStream &f);
00105 
00107     const CPixelInfo    *getTextureInfoPtr();
00108     uint                getTextureInfoWidth() const {return _Width;}
00109     uint                getTextureInfoHeight() const {return _Height;}
00110 
00111 // ****************
00112 private:
00113     // For each pixel of the texture (32*32), give what vertex/normal use it.
00114     std::vector<CPixelInfo>     _TextureInfo;
00115     uint32                      _Width, _Height;
00116 
00117 };
00118 
00119 
00120 // ***************************************************************************
00128 class CLodCharacterShape
00129 {
00130 public:
00131 
00133     struct  CAnimBuild
00134     {
00136         std::string     Name;
00138         uint            NumKeys;
00140         float           AnimLength;
00141 
00143         std::vector<CVector>    Keys;
00144     };
00145 
00147     struct  CVector3s
00148     {
00149         sint16  x,y,z;
00150 
00151         void        serial(NLMISC::IStream &f)
00152         {
00153             f.serial(x,y,z);
00154         }
00155     };
00156 
00157 public:
00158 
00160     CLodCharacterShape();
00161 
00165     void            buildMesh(const std::string &name, const CLodCharacterShapeBuild &lodBuild);
00166 
00170     bool            addAnim(const CAnimBuild &animBuild);
00171 
00173     void            serial(NLMISC::IStream &f);
00174 
00176     const std::string &     getName() const {return _Name;}
00177 
00179     sint            getAnimIdByName(const std::string &name) const;
00180 
00182     uint            getNumVertices() const {return _NumVertices;}
00183 
00185     uint            getNumTriangles() const {return _NumTriangles;}
00186 
00188     uint            getNumBones() const {return _Bones.size();}
00189 
00191     sint            getBoneIdByName(const std::string &name) const;
00192 
00194     const TLodCharacterIndexType *getTriangleArray() const;
00195 
00197     const std::vector<TLodCharacterIndexType>   &getTriangleIndices() const {return _TriangleIndices;}
00198 
00200     const CUV       *getUVs() const;
00201 
00203     const CVector   *getNormals() const;
00204 
00205 
00210     // @{
00211 
00213     void            startBoneAlpha(std::vector<uint8>   &tmpAlphas) const;
00214 
00216     void            addBoneAlpha(uint boneId, std::vector<uint8> &tmpAlphas) const;
00217 
00218     // @}
00219 
00225     const CVector3s *getAnimKey(uint animId, TGlobalAnimationTime time, bool wrapMode, CVector &unPackScaleFactor) const;
00226 
00227 
00228 // *******************************
00229 private:
00230 
00232     struct  CAnim
00233     {
00235         std::string     Name;
00237         uint32          NumKeys;
00239         float           AnimLength;
00240         float           OOAnimLength;
00242         CVector         UnPackScaleFactor;
00243 
00245         std::vector<CVector3s>  Keys;
00246 
00247         void            serial(NLMISC::IStream &f);
00248     };
00249 
00250     struct  CVertexInf
00251     {
00252         // Id of the vertex that the bone influence.
00253         uint32      VertexId;
00254         // weight of influence
00255         float       Influence;
00256 
00257         void        serial(NLMISC::IStream &f)
00258         {
00259             f.serial(VertexId);
00260             f.serial(Influence);
00261         }
00262     };
00263 
00265     struct  CBoneInfluence
00266     {
00267         // Name of the bone.
00268         std::string             Name;
00269 
00270         // list of vertex this bone influence.
00271         std::vector<CVertexInf> InfVertices;
00272 
00273         void        serial(NLMISC::IStream &f);
00274     };
00275 
00277     typedef std::map<std::string, uint32>   TStrIdMap;
00278     typedef TStrIdMap::iterator             ItStrIdMap;
00279     typedef TStrIdMap::const_iterator       CstItStrIdMap;
00280 
00281 private:
00282     std::string             _Name;
00283     uint32                  _NumVertices;
00284     uint32                  _NumTriangles;
00285     // UVs and Normals
00286     std::vector<CUV>        _UVs;
00287     std::vector<CVector>    _Normals;
00289     std::vector<CBoneInfluence>     _Bones;
00290 
00291     // The map of bone.
00292     TStrIdMap               _BoneMap;
00293 
00295     std::vector<TLodCharacterIndexType>     _TriangleIndices;
00296 
00298     std::vector<CAnim>      _Anims;
00299 
00300     // The map of animation.
00301     TStrIdMap               _AnimMap;
00302 
00303 };
00304 
00305 
00306 } // NL3D
00307 
00308 
00309 #endif // NL_LOD_CHARACTER_SHAPE_H
00310 
00311 /* End of lod_character_shape.h */

Generated on Thu Jan 7 08:26:18 2010 for NeL by  doxygen 1.6.1