MeshManager.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef _GAZEBO_MESHMANAGER_HH_
18#define _GAZEBO_MESHMANAGER_HH_
19
20#include <map>
21#include <utility>
22#include <string>
23#include <vector>
24#include <boost/thread/mutex.hpp>
25
26#include <ignition/math/Plane.hh>
27#include <ignition/math/Matrix3.hh>
28#include <ignition/math/Matrix4.hh>
29#include <ignition/math/Vector2.hh>
30
33#include "gazebo/util/system.hh"
34
36GZ_SINGLETON_DECLARE(GZ_COMMON_VISIBLE, gazebo, common, MeshManager)
37
38namespace gazebo
39{
40 namespace common
41 {
42 class ColladaLoader;
43 class ColladaExporter;
44 class FBXLoader;
45 class STLLoader;
46 class Mesh;
47 class Plane;
48 class SubMesh;
49
52
55 class GZ_COMMON_VISIBLE MeshManager : public SingletonT<MeshManager>
56 {
58 private: MeshManager();
59
63 private: virtual ~MeshManager();
64
68 public: const Mesh *Load(const std::string &_filename);
69
76 public: void Export(const Mesh *_mesh, const std::string &_filename,
77 const std::string &_extension, bool _exportTextures = false);
78
81 public: bool IsValidFilename(const std::string &_filename);
82
88 public: void GetMeshAABB(const Mesh *_mesh,
89 ignition::math::Vector3d &_center,
90 ignition::math::Vector3d &_min_xyz,
91 ignition::math::Vector3d &_max_xyz);
92
96 public: void GenSphericalTexCoord(const Mesh *_mesh,
97 const ignition::math::Vector3d &_center);
98
104 public: void AddMesh(Mesh *_mesh);
105
109 public: const Mesh *GetMesh(const std::string &_name) const;
110
113 public: bool HasMesh(const std::string &_name) const;
114
120 public: void CreateSphere(const std::string &_name, float _radius,
121 int _rings, int _segments);
122
127 public: void CreateBox(const std::string &_name,
128 const ignition::math::Vector3d &_sides,
129 const ignition::math::Vector2d &_uvCoords);
130
143 public: void CreateExtrudedPolyline(const std::string &_name,
144 const std::vector<std::vector<ignition::math::Vector2d> >
145 &_vertices, double _height);
146
153 public: void CreateCylinder(const std::string &_name,
154 float _radius,
155 float _height,
156 int _rings,
157 int _segments);
158
165 public: void CreateCone(const std::string &_name,
166 float _radius,
167 float _height,
168 int _rings,
169 int _segments);
170
182 public: void CreateTube(const std::string &_name,
183 float _innerRadius,
184 float _outterRadius,
185 float _height,
186 int _rings,
187 int _segments,
188 double _arc = 2.0 * M_PI);
189
195 public: void CreatePlane(const std::string &_name,
196 const ignition::math::Planed &_plane,
197 const ignition::math::Vector2d &_segments,
198 const ignition::math::Vector2d &_uvTile);
199
207 public: void CreatePlane(const std::string &_name,
208 const ignition::math::Vector3d &_normal,
209 const double _d,
210 const ignition::math::Vector2d &_size,
211 const ignition::math::Vector2d &_segments,
212 const ignition::math::Vector2d &_uvTile);
213
221 private: void Tesselate2DMesh(SubMesh *_sm,
222 int _meshWidth,
223 int _meshHeight,
224 bool _doubleSided);
225
229 public: void CreateCamera(const std::string &_name, float _scale);
230
231#ifdef HAVE_GTS
238 public: void CreateBoolean(const std::string &_name, const Mesh *_m1,
239 const Mesh *_m2, const int _operation,
240 const ignition::math::Pose3d &_offset = ignition::math::Pose3d::Zero);
241#endif
242
250 private: static void ConvertPolylinesToVerticesAndEdges(
251 const std::vector<std::vector<ignition::math::Vector2d> >
252 &_polys,
253 double _tol,
254 std::vector<ignition::math::Vector2d> &_vertices,
255 std::vector<ignition::math::Vector2i> &_edges);
256
264 private: static size_t AddUniquePointToVerticesTable(
265 std::vector<ignition::math::Vector2d> &_vertices,
266 const ignition::math::Vector2d &_p,
267 double _tol);
268
270 private: ColladaLoader *colladaLoader = nullptr;
271
273 private: ColladaExporter *colladaExporter = nullptr;
274
276 private: STLLoader *stlLoader = nullptr;
277
280 private: FBXLoader *fbxLoader = nullptr;
281
283 private: std::map<std::string, Mesh*> meshes;
284
286 private: std::vector<std::string> fileExtensions;
287
288 private: boost::mutex mutex;
289
291 private: friend class SingletonT<MeshManager>;
292 };
294 }
295}
296#endif
common
Definition FuelModelDatabase.hh:37
gazebo
Definition MeshManager.hh:36
common
Definition MeshManager.hh:36
Singleton template class.
Definition SingletonT.hh:34
Class used to export Collada mesh files.
Definition ColladaExporter.hh:43
Class used to load Collada mesh files.
Definition ColladaLoader.hh:47
Maintains and manages all meshes.
Definition MeshManager.hh:56
void CreateExtrudedPolyline(const std::string &_name, const std::vector< std::vector< ignition::math::Vector2d > > &_vertices, double _height)
Create an extruded mesh from polylines.
void CreateSphere(const std::string &_name, float _radius, int _rings, int _segments)
Create a sphere mesh.
void CreateCamera(const std::string &_name, float _scale)
Create a Camera mesh.
void CreatePlane(const std::string &_name, const ignition::math::Planed &_plane, const ignition::math::Vector2d &_segments, const ignition::math::Vector2d &_uvTile)
Create mesh for a plane.
void CreateCone(const std::string &_name, float _radius, float _height, int _rings, int _segments)
Create a cone mesh.
void AddMesh(Mesh *_mesh)
Add a mesh to the manager.
void CreatePlane(const std::string &_name, const ignition::math::Vector3d &_normal, const double _d, const ignition::math::Vector2d &_size, const ignition::math::Vector2d &_segments, const ignition::math::Vector2d &_uvTile)
Create mesh for a plane.
void Export(const Mesh *_mesh, const std::string &_filename, const std::string &_extension, bool _exportTextures=false)
Export a mesh to a file.
void CreateBox(const std::string &_name, const ignition::math::Vector3d &_sides, const ignition::math::Vector2d &_uvCoords)
Create a Box mesh.
void GetMeshAABB(const Mesh *_mesh, ignition::math::Vector3d &_center, ignition::math::Vector3d &_min_xyz, ignition::math::Vector3d &_max_xyz)
Get mesh aabb and center.
const Mesh * GetMesh(const std::string &_name) const
Get a mesh by name.
bool IsValidFilename(const std::string &_filename)
Checks a path extension against the list of valid extensions.
bool HasMesh(const std::string &_name) const
Return true if the mesh exists.
void CreateTube(const std::string &_name, float _innerRadius, float _outterRadius, float _height, int _rings, int _segments, double _arc=2.0 *M_PI)
Create a tube mesh.
void GenSphericalTexCoord(const Mesh *_mesh, const ignition::math::Vector3d &_center)
generate spherical texture coordinates
void CreateCylinder(const std::string &_name, float _radius, float _height, int _rings, int _segments)
Create a cylinder mesh.
const Mesh * Load(const std::string &_filename)
Load a mesh from a file.
A 3D mesh.
Definition Mesh.hh:43
Class used to load STL mesh files.
Definition STLLoader.hh:41
A child mesh.
Definition Mesh.hh:215
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
Forward declarations for the common classes.
Definition Animation.hh:27