KeosMesh.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 #ifndef KEOS_MESH_H
00022 #define KEOS_MESH_H
00023 
00024 #include "KeosPrerequisites.h"
00025 #include "KeosResource.h"
00026 #include "KeosMeshGeom.h"
00027 #include "KeosMaterial.h"
00028 
00029 namespace Keos
00030 {
00031   //-----------------------------------------------------------------------
00035   class KEOS_EXPORT CMesh : public IResource
00036   {
00037     friend class CMeshGeom;
00038 
00039   public :
00040 
00043     CMesh();
00044 
00047     virtual ~CMesh();
00048 
00051     void Render() const;
00052 
00055     uint GetTrianglesCount(void);
00056 
00061     void CreateSharedVertexBuffer(const CMeshGeom::TVertex* pVertices, ulong nVerticesCount);
00062 
00065     void ComputeNormals();
00066 
00067 
00068     //-----------------------------------------------
00071     void AddMeshGeom(CMeshGeom* pMeshGeom)
00072     {
00073       pMeshGeom->m_pParentMesh = this;
00074       m_MeshGeomList.push_back(pMeshGeom);
00075     }
00076 
00079     void AddMeshGeom(CMeshGeom* pMeshGeom, const String& strName)
00080     {
00081       AddMeshGeom(pMeshGeom);
00082       NameMeshGeom(strName, (ushort)m_MeshGeomList.size() - 1);
00083     }
00084 
00087     void NameMeshGeom(const String& strName, ushort nIndex)
00088     {
00089       m_MeshGeomNameMap[strName] = nIndex;
00090     }
00091 
00094     ushort GetNumMeshGeom(void) const
00095     {
00096       return static_cast<ushort>( m_MeshGeomList.size() );
00097     }
00098 
00101     CMeshGeom* GetMeshGeom(ushort nIndex) const;
00102 
00105     CMeshGeom* GetMeshGeom(const String& strName) const ;
00106 
00109     ushort _GetMeshGeomIndex(const String& strName) const;
00110 
00111 
00112     //-----------------------------------------------
00113     typedef std::vector<CMaterial*> TMaterialList;
00114 
00117     TMaterialList& GetMaterialList()
00118     {
00119       return m_MaterialList;
00120     }
00121 
00124     CMaterial* GetMaterial(ushort nIndex)
00125     {
00126       return m_MaterialList[nIndex];
00127     }
00128 
00131     size_t GetLastAddedMaterialIndex(void)
00132     {
00133       return m_MaterialList.size() - 1;
00134     }
00135 
00138     size_t GetMaterialsCount(void)
00139     {
00140       return m_MaterialList.size();
00141     }
00142 
00146     void AddMaterial(CMaterial* pMaterial)
00147     {
00148       m_MaterialList.push_back(pMaterial);
00149     }
00150 
00155     void AddMaterial(CMaterial* pMaterial, ushort nMeshGeomIndex)
00156     {
00157       m_MaterialList.push_back(pMaterial);
00158       GetMeshGeom(nMeshGeomIndex)->SetMaterialIndex((int)GetLastAddedMaterialIndex());
00159     }
00160 
00161 
00162   protected :
00163 
00165     CBuffer<CMeshGeom::TVertex> m_SharedVertexBuffer;
00166 
00168     TMaterialList m_MaterialList;
00169 
00176     typedef std::vector<CMeshGeom*> TMeshGeomList;
00177     TMeshGeomList m_MeshGeomList;
00178 
00182     typedef std::map<String, ushort> TMeshGeomNameMap ;
00183     TMeshGeomNameMap m_MeshGeomNameMap ;
00184 
00185   };
00186 
00188   typedef CSmartPtr<CMesh, CRefCount> TMeshPtr;
00189 
00190 } // namespace Keos
00191 
00192 
00193 #endif // KEOS_MESH_H

Generated on Fri Mar 9 14:29:02 2007 for Keos by  doxygen 1.5.1-p1