MeshManager.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 MESHMANAGER_HH
00018 #define MESHMANAGER_HH
00019 
00020 #include <map>
00021 #include <string>
00022 #include <vector>
00023 
00024 #include "math/Vector3.hh"
00025 #include "math/Vector2d.hh"
00026 #include "math/Plane.hh"
00027 #include "common/SingletonT.hh"
00028 
00029 namespace gazebo
00030 {
00031     namespace common
00032   {
00033     class ColladaLoader;
00034     class STLLoader;
00035     class Mesh;
00036     class Plane;
00037     class SubMesh;
00038 
00041 
00043     class MeshManager : public SingletonT<MeshManager>
00044     {
00046       private: MeshManager();
00047     
00049       private: virtual ~MeshManager();
00050   
00052       public: const Mesh *Load(const std::string &filename);
00053   
00055       public: bool IsValidFilename(const std::string &filename);
00056   
00058       public: void SetMeshCenter(const Mesh *mesh,math::Vector3 center);
00059   
00061       public: void GetMeshAABB(const Mesh *mesh,math::Vector3 &center, 
00062                                math::Vector3 &min_xyz, math::Vector3 &max_xyz);
00063   
00065       public: void GenSphericalTexCoord(const Mesh *mesh,math::Vector3 center);
00066   
00067   
00069       public: void AddMesh(Mesh *mesh);
00070   
00072       public: const Mesh *GetMesh(const std::string &name) const;
00073   
00075       public: bool HasMesh(const std::string &name) const;
00076   
00078       public: void CreateSphere(const std::string &name, float radius, 
00079                                 int rings, int segments);
00080     
00082       public: void CreateBox(const std::string &name, const math::Vector3 &sides,
00083                              const math::Vector2d &uvCoords);
00084     
00086       public: void CreateCylinder(const std::string &name, float radius, 
00087                                   float height, int rings, int segments);
00088     
00090       public: void CreateCone(const std::string &name, float radius, 
00091                               float height, int rings, int segments);
00092     
00094       public: void CreateTube(const std::string &name, float innerRadius, 
00095                               float outterRadius, float height, int rings, 
00096                               int segments);
00097   
00098       public: void CreatePlane(const std::string &name, 
00099                                const math::Plane &plane,
00100                                const math::Vector2d &segments, 
00101                                const math::Vector2d &uvTile);
00102   
00103       public: void CreatePlane(const std::string &name, 
00104                                const math::Vector3 &normal, 
00105                                double d, const math::Vector2d &size, 
00106                                const math::Vector2d &segments,
00107                                const math::Vector2d &uvTile);
00108   
00109       private: void Tesselate2DMesh(SubMesh *sm, int meshWidth, int meshHeight,
00110                                     bool doubleSided);
00111   
00113       public: void CreateCamera(const std::string &name, float scale);
00114    
00115       private: ColladaLoader *colladaLoader;
00116       private: STLLoader *stlLoader;
00117   
00118       private: std::map<std::string, Mesh*> meshes;
00119   
00120       private: std::vector<std::string> fileExtensions;
00121   
00122       //Singleton implementation
00123       private: friend class SingletonT<MeshManager>;
00124     };
00126   }
00127 }
00128 #endif