GlistEngine
Loading...
Searching...
No Matches
gMesh.h
Go to the documentation of this file.
1/*
2 * gMesh.h
3 *
4 * Created on: May 7, 2020
5 * Author: noyan
6 */
7
8#ifndef ENGINE_GRAPHICS_GMESH_H_
9#define ENGINE_GRAPHICS_GMESH_H_
10/*
11#include <GL/glew.h>
12#include <GL/gl.h>
13#include <GL/glu.h>
14#include <glm/glm.hpp>
15#include "glm/gtc/matrix_transform.hpp"
16*/
17#include <vector>
18#include <unordered_map>
19
20#include "gNode.h"
21#include "gTexture.h"
22#include "gMaterial.h"
23#include "gVbo.h"
24#include "gBoundingBox.h"
25#include "gUbo.h"
26
27class gMesh : public gNode {
28public:
29 static const int DRAWMODE_POINTS = GL_POINTS, DRAWMODE_LINES = GL_LINES, DRAWMODE_LINELOOP = GL_LINE_LOOP, DRAWMODE_LINESTRIP = GL_LINE_STRIP,
30 DRAWMODE_TRIANGLES = GL_TRIANGLES, DRAWMODE_TRIANGLESTRIP = GL_TRIANGLE_STRIP, DRAWMODE_TRIANGLEFAN = GL_TRIANGLE_FAN;
31
33 gMesh(const std::vector<gVertex>& vertices, const std::vector<gIndex>& indices, const std::vector<gTexture*>& textures);
34 gMesh(std::shared_ptr<std::vector<gVertex>> vertices,
35 std::shared_ptr<std::vector<gIndex>> indices,
36 std::vector<gTexture*> textures);
37 gMesh(const gMesh&);
38 ~gMesh() override;
39
40 void setVertices(const std::vector<gVertex>& vertices, const std::vector<gIndex>& indices);
41 void setVertices(const std::vector<gVertex>& vertices);
42 void setVertices(std::shared_ptr<std::vector<gVertex>> vertices);
43 void setVertices(std::shared_ptr<std::vector<gVertex>> vertices, std::shared_ptr<std::vector<gIndex>> indices);
44 void setTextures(const std::vector<gTexture*>& textures);
45 void setTextures(const std::unordered_map<gTexture::TextureType, gTexture*>& textures);
46 void setTexture(gTexture* texture);
48
49 std::vector<gVertex>& getVertices();
50 std::vector<gIndex>& getIndices();
51 std::shared_ptr<std::vector<gVertex>> getVerticesPtr();
52 std::shared_ptr<std::vector<gIndex>> getIndicesPtr();
53 int getVerticesNum() const;
54 int getIndicesNum() const;
57 void clear();
58
59 void setName(const std::string& name);
60 const std::string& getName() const;
61
62 void setDrawMode(int drawMode);
63 int getDrawMode() const;
64
65 void setMaterial(gMaterial* material);
67
68 virtual void draw();
69
73
75
76 /*
77 * Sets the color of all vertices in this mesh to the given value.
78 * This operation overwrites any existing per-vertex colors and
79 * immediately updates the GPU vertex buffer.
80 *
81 * Typical use cases include debugging, object highlighting,
82 * or applying a uniform color override.
83 *
84 * @param color The color to apply to every vertex in the mesh
85 */
86 void setAllVertexColor(const glm::vec3& color);
87
88 /*
89 * Assigns a default color to vertices that do not have an explicit color set.
90 * Only vertices whose color is (0, 0, 0) are modified.
91 *
92 * If at least one vertex is updated, the GPU vertex buffer is refreshed.
93 * Existing non-zero vertex colors are preserved.
94 *
95 * @param defColor The default color to assign to uninitialized vertices
96 */
97 void fillMissingVertexColors(const glm::vec3& defColor = glm::vec3(1.0f));
98
99 /*
100 * Assigns each vertex a unique color based on its index in the mesh.
101 * This creates a deterministic, multi-color effect across the mesh.
102 * The colors do not depend on vertex positions but on their order.
103 * After updating, the GPU vertex buffer is refreshed immediately.
104 */
106
107protected:
109
110 void drawStart();
111 void drawVbo();
112 void drawEnd();
113 std::unique_ptr<gVbo> vbo;
114 std::shared_ptr<std::vector<gVertex> >vertices;
116
117private:
118 std::shared_ptr<std::vector<gIndex>> indices;
119
120 std::string name;
121 std::unordered_map<gTexture::TextureType, gTexture*> textures;
122 std::unordered_map<gTexture::TextureType, std::string> texturenames;
123 std::unordered_map<gTexture::TextureType, int> texturecounters = {
133 };
134 int drawmode;
135 gMaterial material;
136
137 gBoundingBox initialboundingbox;
138 gBoundingBox boundingbox;
139 bool needsboundingboxrecalculation;
140
141};
142
143#endif /* ENGINE_GRAPHICS_GMESH_H_ */
Definition gBoundingBox.h:36
Definition gMaterial.h:18
Definition gMesh.h:27
static const int DRAWMODE_LINELOOP
Definition gMesh.h:29
void clear()
std::shared_ptr< std::vector< gIndex > > getIndicesPtr()
void recalculateBoundingBox()
void setTexture(gTexture *texture)
static const int DRAWMODE_POINTS
Definition gMesh.h:29
float distanceTriangles(gRay *ray)
void drawEnd()
~gMesh() override
gMaterial * getMaterial()
void setName(const std::string &name)
void setTextures(const std::unordered_map< gTexture::TextureType, gTexture * > &textures)
static const int DRAWMODE_TRIANGLES
Definition gMesh.h:30
gVbo & getVbo()
std::vector< gVertex > & getVertices()
void fillMissingVertexColors(const glm::vec3 &defColor=glm::vec3(1.0f))
bool isprojection2d
Definition gMesh.h:115
int getVerticesNum() const
int getIndicesNum() const
const std::string & getName() const
int getDrawMode() const
gTexture * getTexture(gTexture::TextureType type)
static const int DRAWMODE_LINESTRIP
Definition gMesh.h:29
void setVertices(const std::vector< gVertex > &vertices)
void drawStart()
void setDrawMode(int drawMode)
void setTextures(const std::vector< gTexture * > &textures)
void drawVbo()
gMesh(std::shared_ptr< std::vector< gVertex > > vertices, std::shared_ptr< std::vector< gIndex > > indices, std::vector< gTexture * > textures)
void setMaterial(gMaterial *material)
void setVertices(const std::vector< gVertex > &vertices, const std::vector< gIndex > &indices)
static const int DRAWMODE_TRIANGLESTRIP
Definition gMesh.h:30
std::vector< gIndex > & getIndices()
bool intersectsTriangles(gRay *ray)
void setVertices(std::shared_ptr< std::vector< gVertex > > vertices, std::shared_ptr< std::vector< gIndex > > indices)
void setVertices(std::shared_ptr< std::vector< gVertex > > vertices)
gMesh(const gMesh &)
void processTransformationMatrix() override
std::unique_ptr< gVbo > vbo
Definition gMesh.h:113
std::shared_ptr< std::vector< gVertex > > vertices
Definition gMesh.h:114
static const int DRAWMODE_LINES
Definition gMesh.h:29
const gBoundingBox & getInitialBoundingBox() const
const gBoundingBox & getBoundingBox()
void applyVertexGradient()
static const int DRAWMODE_TRIANGLEFAN
Definition gMesh.h:30
void setAllVertexColor(const glm::vec3 &color)
gMesh(const std::vector< gVertex > &vertices, const std::vector< gIndex > &indices, const std::vector< gTexture * > &textures)
std::shared_ptr< std::vector< gVertex > > getVerticesPtr()
virtual void draw()
Definition gNode.h:15
Definition gRay.h:32
Definition gTexture.h:17
TextureType
Definition gTexture.h:19
@ TEXTURETYPE_PBR_AO
Definition gTexture.h:28
@ TEXTURETYPE_HEIGHT
Definition gTexture.h:23
@ TEXTURETYPE_NORMAL
Definition gTexture.h:22
@ TEXTURETYPE_PBR_ALBEDO
Definition gTexture.h:24
@ TEXTURETYPE_PBR_METALNESS
Definition gTexture.h:26
@ TEXTURETYPE_DIFFUSE
Definition gTexture.h:20
@ TEXTURETYPE_PBR_ROUGHNESS
Definition gTexture.h:25
@ TEXTURETYPE_PBR_NORMAL
Definition gTexture.h:27
@ TEXTURETYPE_SPECULAR
Definition gTexture.h:21
Definition gVbo.h:30