Mesh.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 #ifndef MESH_HH
00018 #define MESH_HH
00019 
00020 #include <vector>
00021 
00022 #include "math/Vector3.hh"
00023 #include "math/Vector2d.hh"
00024 
00025 namespace gazebo
00026 {
00027     namespace common
00028   {
00029     class Material;
00030     class SubMesh;
00031 
00034 
00036     class Mesh
00037     {
00039       public: Mesh();
00040     
00042       public: virtual ~Mesh();
00043 
00045       public: void SetPath(const std::string &_path);
00046 
00048       public: std::string GetPath() const;
00049 
00051       public: void SetName(const std::string &n);
00052   
00054       public: std::string GetName() const;
00055   
00057       public: math::Vector3 GetMax() const;
00058   
00060       public: math::Vector3 GetMin() const;
00061   
00063       public: unsigned int GetVertexCount() const;
00064   
00066       public: unsigned int GetNormalCount() const;
00067   
00069       public: unsigned int GetIndexCount() const;
00070   
00072       public: unsigned int GetTexCoordCount() const;
00073   
00075       public: void AddSubMesh(SubMesh *child);
00076   
00078       public: unsigned int GetSubMeshCount() const;
00079   
00082       public: unsigned int AddMaterial( Material *mat );
00083   
00085       public: unsigned int GetMaterialCount() const;
00086   
00088       public: const Material *GetMaterial(int index) const;
00089   
00091       public: const SubMesh *GetSubMesh(unsigned int i) const;
00092   
00094       public: void FillArrays(float **vertArr, unsigned int **indArr) const;
00095   
00097       public: void RecalculateNormals();
00098   
00100       public: void GetAABB(math::Vector3 &center,math::Vector3 &min_xyz,math::Vector3 &max_xyz);
00101   
00103       public: void SetMeshCenter(math::Vector3 center);
00104   
00106       public: void GenSphericalTexCoord(math::Vector3 center);
00107   
00108   
00109       private: std::string name;
00110       private: std::string path;
00111       private: std::vector<SubMesh *> submeshes;
00112       private: std::vector<Material *> materials;
00113     };
00114  
00116     class SubMesh
00117     {
00118       public: enum PrimitiveType {LINES, LINESTRIPS, TRIANGLES, TRIFANS, TRISTRIPS};
00119 
00121       public: SubMesh();
00122   
00124       public: virtual ~SubMesh();
00125 
00127       public: void SetPrimitiveType( PrimitiveType _type );
00128 
00130       public: PrimitiveType GetPrimitiveType() const;
00131 
00133       public: void CopyVertices( const std::vector<math::Vector3> &_verts );
00134 
00136       public: void CopyNormals( const std::vector<math::Vector3> &_norms );
00137 
00139       public: void SetVertexCount( unsigned int _count );
00140 
00142       public: void SetIndexCount( unsigned int _count );
00143 
00145       public: void SetNormalCount( unsigned int _count );
00146 
00148       public: void SetTexCoordCount( unsigned int _count );
00149   
00151       public: void AddIndex( unsigned int i);
00152   
00154       public: void AddVertex( const math::Vector3 &_v );
00155   
00157       public: void AddVertex(double x, double y, double z );
00158   
00160       public: void AddNormal( const math::Vector3 &_n );
00161   
00163       public: void AddNormal(double x, double y, double z );
00164   
00166       public: void AddTexCoord(double u, double v );
00167   
00169       public: math::Vector3 GetVertex(unsigned int i) const;
00170   
00172       public: void SetVertex(unsigned int i, const math::Vector3 &v);
00173   
00175       public: math::Vector3 GetNormal(unsigned int i) const;
00176   
00178       public: void SetNormal(unsigned int i, const math::Vector3 &n);
00179   
00181       public: math::Vector2d GetTexCoord(unsigned int i) const;
00182   
00184       public: void SetTexCoord(unsigned int i, const math::Vector2d &t);
00185   
00187       public: unsigned int GetIndex(unsigned int i) const;
00188   
00190       public: math::Vector3 GetMax() const;
00191   
00193       public: math::Vector3 GetMin() const;
00194   
00196       public: unsigned int GetVertexCount() const;
00197   
00199       public: unsigned int GetNormalCount() const;
00200   
00202       public: unsigned int GetIndexCount() const;
00203   
00205       public: unsigned int GetTexCoordCount() const;
00206   
00208       public: unsigned int GetMaxIndex() const;
00209   
00211       public: void SetMaterialIndex(unsigned int index);
00212   
00214       public: unsigned int GetMaterialIndex() const;
00215   
00217       public: bool HasVertex( const math::Vector3 &v ) const;
00218   
00220       public: unsigned int GetVertexIndex(const math::Vector3 &v) const;
00221   
00223       public: void FillArrays(float **vertArr, unsigned int **indArr) const;
00224   
00226       public: void RecalculateNormals();
00227   
00229       public: void SetSubMeshCenter(math::Vector3 center);
00230   
00232       public: void GenSphericalTexCoord(math::Vector3 center);
00233   
00234       private: std::vector< math::Vector3 > vertices;
00235       private: std::vector< math::Vector3 > normals;
00236       private: std::vector< math::Vector2d > texCoords;
00237       private: std::vector<unsigned int> indices;
00238   
00239       private: PrimitiveType primitiveType;
00240 
00241       private: int materialIndex;
00242     };
00244   }
00245 
00246 }
00247 #endif