-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmesh.h
More file actions
123 lines (95 loc) · 3.25 KB
/
Copy pathmesh.h
File metadata and controls
123 lines (95 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef MESH_H
#define MESH_H
#include "wasmgl_gl.h"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include <vector>
#include <string>
#include <functional>
#include <atomic>
#include <iostream>
#include "./color.h"
#include "./face3.h"
using namespace std;
class ThreeBSP;
class Mesh : public std::enable_shared_from_this<Mesh>
{
friend class ThreeBSP;
public:
Mesh();
void RenderMesh();
/** Black/dark line overlay so edges read clearly (WebGL2-safe; no glPolygonMode). */
void RenderWireframe();
virtual void createVertices() = 0;
void translate(glm::vec3 const &translation);
void rotate(glm::vec3 const &rotation);
void scale(glm::vec3 const &scale);
shared_ptr<glm::mat4> getModelMatrix() const { return model; }
bool getLocalBounds(glm::vec3 &minOut, glm::vec3 &maxOut) const;
glm::f32 *getModelPtr();
void setSolidColor(glm::vec3 const &rgb) { solidColor = rgb; }
glm::vec3 getSolidColor() const { return solidColor; }
void setThreeBSP(shared_ptr<ThreeBSP> const &bsp)
{
threeBSP = bsp;
}
shared_ptr<ThreeBSP> getThreeBSP() const { return threeBSP; }
shared_ptr<Mesh> subtract(shared_ptr<Mesh> const &other);
shared_ptr<Mesh> add(shared_ptr<Mesh> const &other);
shared_ptr<Mesh> intersect(shared_ptr<Mesh> const &other);
std::function<void()> computeThreeBSPLambda;
void computeThreeBSP();
std::atomic<bool> threeBSPDone; // Use an atomic flag.
void setModel(shared_ptr<glm::mat4> const &model) { this->model = model; }
~Mesh();
protected:
void createMesh();
void ClearMesh();
void computeFaces();
/** Fills `normals` from `faces` if needed (box / CSG). Sphere already sets normals. */
void ensureVertexNormals();
void buildWireframeEdgeBuffer();
shared_ptr<ThreeBSP> threeBSP;
GLuint VAO,
VBO, IBO;
GLuint edgeIBO{0};
GLsizei indexCount;
GLsizei edgeIndexCount{0};
// std::vector<GLfloat> vertices;
/**
* The array of vertices hold every position of points of the model.
*/
std::vector<glm::vec3> vertices;
bool verticesNeedUpdate;
/**
* Array of vertex colors, matching number and order of vertices.
* Used in ParticleSystem, Line and Ribbon.
* Meshes use per-face-use-of-vertex colors embedded directly in faces.
*/
std::vector<Color> colors;
bool colorsNeedUpdate;
/**
* Array of triangles or/and quads.
* The array of faces describe how each vertex in the model is connected with each other.
* To signal an update in this array, Geometry.elementsNeedUpdate needs to be set to true.
*/
std::vector<shared_ptr<Face3>> faces;
bool facesNeedUpdate;
/**
* Array of face UV layers.
* Each UV layer is an array of UV matching order and number of vertices in faces.
* To signal an update in this array, Geometry.uvsNeedUpdate needs to be set to true.
*/
// std::vector<std::vector<std::vector<shared_ptr<glm::vec2>>>> faceVertexUvs;
// bool faceVertexUvsNeedUpdate;
std::vector<glm::vec3> normals;
std::vector<int> indices;
// std::vector<glm::vec2> uvs;
shared_ptr<glm::mat4> model;
/** Albedo for Phong shading (linear RGB, 0-1). */
glm::vec3 solidColor{0.45f, 0.55f, 0.85f};
int id; // unique id for this instance
string uuid;
};
#endif