Mesh.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_MESH_INLCUDED
34 #define H_DC_MESH_INLCUDED
35 
36 #include <Dynacoe/Util/Vector.h>
37 #include <Dynacoe/Material.h>
38 #include <Dynacoe/Util/RefBank.h>
39 
40 namespace Dynacoe {
41 
50 class Mesh {
51  public:
52  Mesh();
53  Mesh(const Mesh &);
54  Mesh & operator=(const Mesh &);
55  ~Mesh();
56 
57  Mesh MakeShallowCopy() const;
58 
65  class MeshObject {
66  public:
67 
71  std::vector<uint32_t> faceList;
72 
73 
74  };
75 
78  enum class VertexAttribute {
79  Position,
80  Normal,
81  UV,
82  UserData
83  };
84 
85 
86 
92  void SetVertexCount(uint32_t t);
93 
94 
95 
102  void DefineVertices(VertexAttribute, const std::vector<Dynacoe::Vector> & vertexData);
103 
104 
105  void DefineVerticesState(const std::vector<Renderer::StaticVertex> &);
106 
109  Vector GetVertex(uint32_t index, VertexAttribute) const;
110 
111 
114  void SetVertex(uint32_t index, VertexAttribute, const Vector & p);
115 
118  uint32_t NumVertices() const;
119 
120 
121 
122 
123 
124 
128  int AddObject(const MeshObject &);
129  int AddObject();
134  MeshObject * Get(int i);
135 
138  void RemoveObject(int);
139 
140 
143  int NumObjects();
144 
147  bool IsShallow();
148 
153  void MakeUnique();
154 
155 
156  void PopulateState(StaticState *, int objectIndex);
157 
160  static const Mesh & Basic_Cube();
161  static const Mesh & Basic_Sphere();
162  static const Mesh & Basic_Pyramid();
163  static const Mesh & Basic_Triangle();
164 
167  static const Mesh & Basic_Square();
168 
169  private:
170 
171  RenderBufferID vertices;
172  std::vector<MeshObject> objs;
173  int numElts;
174  bool isShallow;
175 
176 
177 };
178 }
179 
180 
181 
182 #endif
Object representing the geometry of a rendered object.
Definition: Mesh.h:65
The texture cooridates of the vertex. 2 components: xy.
3D and 2D positional vector.
Definition: Vector.h:55
bool IsShallow()
Returns whether the mesh is a shallow mesh, mean it does not own its vertices.
Position of the vertex. 3 components: xyz.
Vector GetVertex(uint32_t index, VertexAttribute) const
Gets the vertex at the given index.
int NumObjects()
Returns the number of added objects.
Definition: AssetID.h:37
3D object defined by triangle primitives.
Definition: Mesh.h:50
VertexAttribute
The type of vertex attribute.
Definition: Mesh.h:78
std::vector< uint32_t > faceList
Geometry of the mesh object. Contains indices to the vertices defined in the Mesh.
Definition: Mesh.h:71
void MakeUnique()
If shallow, the mesh creates is own copy of vertices, making it no longer shallow. If the Mesh is not shallow, no action is taken.
void DefineVertices(VertexAttribute, const std::vector< Dynacoe::Vector > &vertexData)
Explicitly defines the vertices of the mesh.
MeshObject * Get(int i)
Retrieves the i'th mesh object of the mesh.
void RemoveObject(int)
Removes the obejct at the speicifed position.
User-defined data. 3 components: xyz.
void SetVertexCount(uint32_t t)
sets the number of vertices this mesh will hold. This will pre-emptively allocated space for the mesh...
void SetVertex(uint32_t index, VertexAttribute, const Vector &p)
Sets the vertex at the given.
uint32_t NumVertices() const
Returns the number of vertices.
The normal vector of the vertex. 3 components: xyz.
static const Mesh & Basic_Square()
Returns a Mesh representing a boring square.
static const Mesh & Basic_Cube()
Returns a Mesh representing a boring cube.