# 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  

mesh_base.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 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_MESH_BASE_H
00027 #define NL_MESH_BASE_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "3d/shape.h"
00031 #include "3d/driver.h"
00032 #include "3d/material.h"
00033 #include "3d/animated_material.h"
00034 #include "3d/animated_morph.h"
00035 #include <set>
00036 #include <vector>
00037 
00038 
00039 
00040 namespace NL3D {
00041 
00042 
00043 class   CMeshBaseInstance;
00044 
00045 
00046 // ***************************************************************************
00053 class CMeshBase : public IShape
00054 {
00055 public:
00056 
00058 
00059 
00060         struct CMatStage
00061         { 
00062                 uint8 nMatNb, nStageNb; 
00063                 void    serial(NLMISC::IStream &f)
00064                 {
00065                         f.serial(nMatNb);
00066                         f.serial(nStageNb);
00067                 }
00068         };
00069         struct CLightInfoMapList : std::list< CMatStage >
00070         {
00071                 void    serial(NLMISC::IStream &f)
00072                 {
00073                         f.serialCont((std::list< CMatStage >&)*this);
00074                 }
00075         };
00076         typedef std::map< std::string, CLightInfoMapList >      TLightInfoMap;
00077 
00079         struct  CMeshBaseBuild
00080         {
00081                 bool                                    bCastShadows;
00082                 bool                                    bRcvShadows;
00083                 bool                                    UseLightingLocalAttenuation;
00084 
00085                 // Default value for position of this mesh
00086                 CVector                                 DefaultPos;
00087                 CVector                                 DefaultPivot;
00088                 CVector                                 DefaultRotEuler;
00089                 CQuat                                   DefaultRotQuat;
00090                 CVector                                 DefaultScale;
00091 
00092                 // Material array
00093                 std::vector<CMaterial>  Materials;
00094 
00095                 // Map of light information
00096                 TLightInfoMap                   LightInfoMap;
00097 
00098                 // Default position of the blend shapes factors
00099                 std::vector<float>              DefaultBSFactors;
00100                 std::vector<std::string>BSNames;
00101 
00102 
00103                 CMeshBaseBuild();
00104 
00105                 // Serialization is not used
00106                 //void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00107         };
00109 
00110 
00111 public:
00113         CMeshBase();
00114 
00116         // @{
00118         void                    setAnimatedMaterial(uint id, const std::string &matName);
00120         CMaterialBase   *getAnimatedMaterial(uint id);
00121         // @}
00122 
00124         // @{
00125         CTrackDefaultVector*    getDefaultPos ()                {return &_DefaultPos;}
00126         CTrackDefaultVector*    getDefaultPivot ()              {return &_DefaultPivot;}
00127         CTrackDefaultVector*    getDefaultRotEuler ()   {return &_DefaultRotEuler;}
00128         CTrackDefaultQuat*              getDefaultRotQuat ()    {return &_DefaultRotQuat;}
00129         CTrackDefaultVector*    getDefaultScale ()              {return &_DefaultScale;}
00130         CTrackDefaultRGBA*              getDefaultLMFactor ()   {return &_DefaultLMFactor;}
00131         // @}
00132 
00134         // @{
00135 
00137         uint getNbMaterial() const
00138         {
00139                 return _Materials.size();
00140         }
00141 
00143         CMaterial& getMaterial(uint id)
00144         {
00145                 return _Materials[id];
00146         }
00148         const CMaterial& getMaterial(uint id) const
00149         {
00150                 return _Materials[id];
00151         }
00152         // @}
00153 
00155         void    serialMeshBase(NLMISC::IStream &f) throw(NLMISC::EStream);
00156 
00158         void    flushTextures (IDriver &driver);
00159 
00160 
00162         bool    isLightable() const {return _IsLightable;}
00163 
00165         virtual bool            useLightingLocalAttenuation () const;
00166 
00168         // @{
00174         void                                            setAutoAnim(bool on = true) { _AutoAnim = on; }
00175         // Check wether automatic animation is enabled
00176         bool                                            getAutoAnim() const { return _AutoAnim; }
00177         // @}
00178 
00179 
00180 // ************************
00181 protected:
00183         std::vector<CMaterial>          _Materials;
00184 
00185 public:
00186         // Map of light information ( LightName, list(MaterialNb, StageNb) )
00187         TLightInfoMap                           _LightInfos;
00188 
00189 
00190 protected:
00192         typedef std::map<uint32, CMaterialBase> TAnimatedMaterialMap;
00193         TAnimatedMaterialMap            _AnimatedMaterials;
00194 
00195 
00197         CTrackDefaultVector                     _DefaultPos;
00198         CTrackDefaultVector                     _DefaultPivot;
00199         CTrackDefaultVector                     _DefaultRotEuler;
00200         CTrackDefaultQuat                       _DefaultRotQuat;
00201         CTrackDefaultVector                     _DefaultScale;
00202         CTrackDefaultRGBA                       _DefaultLMFactor;
00203         
00204         std::vector<CMorphBase>         _AnimatedMorph;
00205 
00207         bool                                            _IsLightable;
00209         bool                                            _UseLightingLocalAttenuation;
00210 
00211         bool                                            _AutoAnim;
00212 
00213 
00214 protected:
00216         void    buildMeshBase(CMeshBaseBuild &m);
00217 
00219         void    instanciateMeshBase(CMeshBaseInstance *mi, CScene *ownerScene);
00220 
00221 private:
00222 
00224         void    computeIsLightable();
00225 };
00226 
00227 
00228 } // NL3D
00229 
00230 
00231 #endif // NL_MESH_BASE_H
00232 
00233 /* End of mesh_base.h */