3es  0.7
3essimplemesh.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESSIMPLEMESH_H_
5 #define _3ESSIMPLEMESH_H_
6 
7 #include "3es-core.h"
8 
9 #include "3escolour.h"
10 #include "3esmeshresource.h"
11 #include "3esmeshmessages.h"
12 
13 namespace tes
14 {
15  struct SimpleMeshImp;
16 
18  class _3es_coreAPI SimpleMesh : public MeshResource
19  {
20  public:
24  {
25  Vertex = (1 << 0),
26  Index = (1 << 1),
27  Colour = (1 << 2),
28  Color = Colour,
29  Normal = (1 << 3),
30  Uv = (1 << 4)
31  };
32 
39  SimpleMesh(uint32_t id, unsigned vertexCount = 0, unsigned indexCount = 0, DrawType drawType = DtTriangles,
40  unsigned components = Vertex | Index);
41 
42  protected:
45  SimpleMesh(const SimpleMesh &other);
46 
47  public:
49  ~SimpleMesh();
50 
52  virtual void clear();
53 
55  virtual void clearData();
56 
58  virtual uint32_t id() const override;
59 
61  virtual Matrix4f transform() const override;
62 
69  void setTransform(const Matrix4f &transform);
70 
72  virtual uint32_t tint() const override;
76  void setTint(uint32_t tint);
77 
81  SimpleMesh *clone() const override;
82 
84  virtual uint8_t drawType(int stream) const override;
85 
87  DrawType getDrawType() const;
90  void setDrawType(DrawType type);
91 
94  unsigned components() const;
95 
98  void setComponents(unsigned components);
99 
102  void addComponents(unsigned components);
103 
104  unsigned vertexCount() const;
105  virtual unsigned vertexCount(int stream) const override;
106  void setVertexCount(unsigned count);
107  void reserveVertexCount(unsigned count);
108 
109  inline unsigned addVertex(const Vector3f &v) { return addVertices(&v, 1u); }
110  unsigned addVertices(const Vector3f *v, unsigned count);
111  inline bool setVertex(unsigned at, const Vector3f &v) { return setVertices(at, &v, 1u) == 1u; }
112  unsigned setVertices(unsigned at, const Vector3f *v, const unsigned count);
113  const Vector3f *vertices() const;
114  virtual const float *vertices(unsigned &stride, int stream = 0) const override;
115 
116  unsigned indexCount() const;
117  virtual unsigned indexCount(int stream) const override;
118  void setIndexCount(unsigned count);
119  void reserveIndexCount(unsigned count);
120 
121  inline void addIndex(uint32_t i) { return addIndices(&i, 1u); }
122  void addIndices(const uint32_t *idx, unsigned count);
123  inline bool setIndex(unsigned at, uint32_t i) { return setIndices(at, &i, 1u) == 1u; }
124  unsigned setIndices(unsigned at, const uint32_t *idx, unsigned count);
125  const uint32_t *indices() const;
126  virtual const uint8_t *indices(unsigned &stride, unsigned &width, int stream = 0) const override;
127 
128  inline bool setNormal(unsigned at, const Vector3f &n) { return setNormals(at, &n, 1u) == 1u; }
129  unsigned setNormals(unsigned at, const Vector3f *n, const unsigned count);
130  const Vector3f *normals() const;
131  virtual const float *normals(unsigned &stride, int stream) const override;
132 
133  inline bool setColour(unsigned at, uint32_t c) { return setColours(at, &c, 1u) == 1u; }
134  unsigned setColours(unsigned at, const uint32_t *c, unsigned count);
135  const uint32_t *colours() const;
136  virtual const uint32_t *colours(unsigned &stride, int stream) const override;
137 
138  inline bool setUv(unsigned at, float u, float v) { const float uv[2] = { u, v }; return setUvs(at, uv, 1u) == 1u; }
139  unsigned setUvs(unsigned at, const float *uvs, const unsigned count);
140  const float *uvs() const;
141  virtual const float *uvs(unsigned &stride, int stream) const override;
142 
143  private:
144  void copyOnWrite();
145 
146  SimpleMeshImp *_imp;
147  };
148 
149 
150  inline void SimpleMesh::addComponents(unsigned components)
151  {
152  setComponents(this->components() | components);
153  }
154 }
155 
156 #endif // _3ESSIMPLEMESH_H_
157 
A 32-bit integer colour class.
Definition: 3escolour.h:19
A row major 4x4 transformation matrix.
Definition: 3esmatrix4.h:27
DrawType
Defines the primitives for a mesh.
Definition: 3esmeshmessages.h:135
Definition: 3esbounds.h:13
An encapsulated definition of a mesh. It manages all its own vertices, indices, etc.
Definition: 3essimplemesh.h:18
Represents a mesh part or object.
Definition: 3esmeshresource.h:16
Represents a vector in R3.
Definition: 3esvector3.h:14
void addComponents(unsigned components)
Add ComponentFlag values to the existing set.
Definition: 3essimplemesh.h:150
ComponentFlag
Flags indicating which components are present.
Definition: 3essimplemesh.h:23