All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
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 MESH_HH
18 #define MESH_HH
19 
20 #include <vector>
21 #include <string>
22 
23 #include "math/Vector3.hh"
24 #include "math/Vector2d.hh"
25 
26 namespace gazebo
27 {
28  namespace common
29  {
30  class Material;
31  class SubMesh;
32  class Skeleton;
33 
36 
38  class Mesh
39  {
41  public: Mesh();
42 
44  public: virtual ~Mesh();
45 
48  public: void SetPath(const std::string &_path);
49 
52  public: std::string GetPath() const;
53 
56  public: void SetName(const std::string &_n);
57 
60  public: std::string GetName() const;
61 
64  public: math::Vector3 GetMax() const;
65 
68  public: math::Vector3 GetMin() const;
69 
72  public: unsigned int GetVertexCount() const;
73 
76  public: unsigned int GetNormalCount() const;
77 
80  public: unsigned int GetIndexCount() const;
81 
84  public: unsigned int GetTexCoordCount() const;
85 
89  public: void AddSubMesh(SubMesh *_child);
90 
93  public: unsigned int GetSubMeshCount() const;
94 
98  public: int AddMaterial(Material *_mat);
99 
102  public: unsigned int GetMaterialCount() const;
103 
107  public: const Material *GetMaterial(int _index) const;
108 
113  public: const SubMesh *GetSubMesh(unsigned int _i) const;
114 
118  public: void FillArrays(float **_vertArr, int **_indArr) const;
119 
122  public: void RecalculateNormals();
123 
128  public: void GetAABB(math::Vector3 &_center, math::Vector3 &_min_xyz,
129  math::Vector3 &_max_xyz) const;
130 
134  public: void GenSphericalTexCoord(const math::Vector3 &_center);
135 
138  public: Skeleton* GetSkeleton() const;
139 
141  public: void SetSkeleton(Skeleton *_skel);
142 
144  public: bool HasSkeleton() const;
145 
148  public: void Scale(double _factor);
149 
151  private: std::string name;
152 
154  private: std::string path;
155 
157  private: std::vector<SubMesh *> submeshes;
158 
160  private: std::vector<Material *> materials;
161 
163  private: Skeleton *skeleton;
164  };
165 
169  {
171  unsigned int vertexIndex;
172 
174  unsigned int nodeIndex;
175 
177  float weight;
178  };
179 
181  class SubMesh
182  {
186 
188  public: SubMesh();
189 
191  public: virtual ~SubMesh();
192 
195  public: void SetPrimitiveType(PrimitiveType _type);
196 
199  public: PrimitiveType GetPrimitiveType() const;
200 
203  public: void CopyVertices(const std::vector<math::Vector3> &_verts);
204 
207  public: void CopyNormals(const std::vector<math::Vector3> &_norms);
208 
211  public: void SetVertexCount(unsigned int _count);
212 
215  public: void SetIndexCount(unsigned int _count);
216 
219  public: void SetNormalCount(unsigned int _count);
220 
223  public: void SetTexCoordCount(unsigned int _count);
224 
227  public: void AddIndex(unsigned int _i);
228 
231  public: void AddVertex(const math::Vector3 &_v);
232 
237  public: void AddVertex(double _x, double _y, double _z);
238 
241  public: void AddNormal(const math::Vector3 &_n);
242 
247  public: void AddNormal(double _x, double _y, double _z);
248 
252  public: void AddTexCoord(double _u, double _v);
253 
258  public: void AddNodeAssignment(unsigned int _vertex, unsigned int _node,
259  float _weight);
260 
264  public: math::Vector3 GetVertex(unsigned int _i) const;
265 
269  public: void SetVertex(unsigned int _i, const math::Vector3 &_v);
270 
274  public: math::Vector3 GetNormal(unsigned int _i) const;
275 
279  public: void SetNormal(unsigned int _i, const math::Vector3 &_n);
280 
284  public: math::Vector2d GetTexCoord(unsigned int _i) const;
285 
288  public: NodeAssignment GetNodeAssignment(unsigned int _i) const;
289 
293  public: void SetTexCoord(unsigned int _i, const math::Vector2d &_t);
294 
297  public: unsigned int GetIndex(unsigned int _i) const;
298 
301  public: math::Vector3 GetMax() const;
302 
305  public: math::Vector3 GetMin() const;
306 
308  public: unsigned int GetVertexCount() const;
309 
311  public: unsigned int GetNormalCount() const;
312 
314  public: unsigned int GetIndexCount() const;
315 
317  public: unsigned int GetTexCoordCount() const;
318 
320  public: unsigned int GetNodeAssignmentsCount() const;
321 
323  public: unsigned int GetMaxIndex() const;
324 
328  public: void SetMaterialIndex(unsigned int _index);
329 
331  public: unsigned int GetMaterialIndex() const;
332 
335  public: bool HasVertex(const math::Vector3 &_v) const;
336 
339  public: unsigned int GetVertexIndex(const math::Vector3 &_v) const;
340 
344  public: void FillArrays(float **_vertArr, int **_indArr) const;
345 
347  public: void RecalculateNormals();
348 
351  public: void SetSubMeshCenter(math::Vector3 _center);
352 
356  public: void GenSphericalTexCoord(const math::Vector3 &_center);
357 
360  public: void Scale(double _factor);
361 
363  private: std::vector< math::Vector3 > vertices;
364 
366  private: std::vector< math::Vector3 > normals;
367 
369  private: std::vector< math::Vector2d > texCoords;
370 
372  private: std::vector<unsigned int> indices;
373 
375  private: std::vector<NodeAssignment> nodeAssignments;
376 
378  private: PrimitiveType primitiveType;
379 
382  private: int materialIndex;
383  };
385  }
386 }
387 
388 #endif