00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }
00191
00192
00193 #endif // KEOS_MESH_H