-
Notifications
You must be signed in to change notification settings - Fork 30
/
Interface.hpp
289 lines (236 loc) · 8.42 KB
/
Interface.hpp
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#pragma once
#include <kit/kit.hpp>
#include <kit/GLBuffer.hpp>
#include <kit/GLVertexArray.hpp>
#include "pipeline.hpp"
struct Interface : public kit::Mode {
Interface();
virtual ~Interface();
virtual void update(float elapsed) override;
virtual void draw() override;
virtual void handle_event(SDL_Event const &) override;
//framebuffers + textures
glm::uvec2 fb_size = glm::uvec2(0);
GLuint color_id_fb = 0; //(color_tex, id_tex) + depth_tex
GLuint color_tex = 0;
GLuint id_tex = 0;
GLuint depth_tex = 0; //depth values (for soft edges)
void alloc_fbs(); //(re-)allocate framebuffers given current display size
//camera:
struct Camera {
glm::vec3 center = glm::vec3(0.0f);
float radius = 5.0f;
//all in radians:
float azimuth = glm::radians(30.0f);
float elevation = glm::radians(45.0f);
float fovy = glm::radians(60.0f);
glm::vec3 at() const {
float ca = std::cos(azimuth);
float sa = std::sin(azimuth);
float ce = std::cos(elevation);
float se = std::sin(elevation);
glm::vec3 out = glm::vec3( ce * ca, ce * sa, se);
glm::vec3 at = center + out * radius;
return at;
}
//matrix that takes positions to camera space:
glm::mat4 mv() const {
float ca = std::cos(azimuth);
float sa = std::sin(azimuth);
float ce = std::cos(elevation);
float se = std::sin(elevation);
glm::vec3 right = glm::vec3( -sa, ca, 0.0f);
glm::vec3 up = glm::vec3(-se * ca,-se * sa, ce);
glm::vec3 out = glm::vec3( ce * ca, ce * sa, se);
glm::vec3 at = center + out * radius;
return glm::mat4(
right.x, up.x, out.x, 0.0f,
right.y, up.y, out.y, 0.0f,
right.z, up.z, out.z, 0.0f,
glm::dot(-at, right), glm::dot(-at, up), glm::dot(-at, out), 1.0f
);
}
glm::mat4 mvp() const {
return glm::infinitePerspective(fovy, kit::display.aspect, 0.1f) * mv();
}
} camera;
//mouse tracking:
enum Drag {
DragNone = 0,
DragCamera,
DragCameraFlipX, //for dragging when upside-down
DragCameraPan,
DragConsPt,
DragConsRadius,
};
Drag drag = DragNone;
struct {
uint32_t cons = -1U;
uint32_t cons_pt = -1U;
void clear() {
cons = -1U;
cons_pt = -1U;
}
} dragging;
enum : uint32_t {
ShowModel = (1 << 0),
ShowConstraints = (1 << 1),
ShowTimesModel = (1 << 2),
ShowSlice = (1 << 3),
ShowActiveChains = (1 << 4),
ShowSliceChains = (1 << 5),
ShowLinks = (1 << 6),
ShowNextActiveChains = (1 << 7),
ShowRowColGraph = (1 << 8),
ShowTraced = (1 << 9),
ShowModelBits = ShowModel | ShowTimesModel | ShowSlice,
ShowStepBits = ShowActiveChains | ShowSliceChains | ShowLinks | ShowNextActiveChains,
ShowGraphBits = ShowRowColGraph | ShowTraced,
};
uint32_t show = ShowModel | ShowConstraints | ShowRowColGraph;
struct {
glm::vec2 at = glm::vec2(std::numeric_limits< float >::quiet_NaN());
bool moved = false;
} mouse;
struct {
glm::vec3 point = glm::vec3(std::numeric_limits< float >::quiet_NaN());
uint32_t tri = -1U;
glm::vec3 coords = glm::vec3(std::numeric_limits< float >::quiet_NaN());
uint32_t vert = -1U;
uint32_t cons = -1U;
uint32_t cons_pt = -1U;
void clear() {
point = glm::vec3(std::numeric_limits< float >::quiet_NaN());
tri = -1U;
coords = glm::vec3(std::numeric_limits< float >::quiet_NaN());
vert = -1U;
cons = -1U;
cons_pt = -1U;
}
} hovered;
void update_hovered();
//parameters:
ak::Parameters parameters;
//-------------------------------
//original model:
ak::Model model;
void set_model(ak::Model const &model);
//visualization:
//model buffer: (vertices, normals, ids)
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > model_triangles;
GLVertexArray model_triangles_for_model_draw;
bool model_triangles_dirty = true;
void update_model_triangles();
//-------------------------------
//constraints:
std::vector< ak::Constraint > constraints;
ak::Model constrained_model;
std::vector< float > constrained_values;
std::vector< std::vector< glm::vec3 > > DEBUG_constraint_paths;
std::vector< std::vector< glm::vec3 > > DEBUG_constraint_loops;
void clear_constraints();
void set_constraints(std::vector< ak::Constraint > const &constraints);
bool constraints_dirty = true;
void update_constraints();
//data wrangling:
std::string save_constraints_file = ""; //if not "", will save constraints to this file after every change
void save_constraints();
//constraints paths/loops; position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > constraints_tristrip;
GLVertexArray constraints_tristrip_for_path_draw;
bool constraints_tristrip_dirty = true;
void update_constraints_tristrip();
//-------------------------------
//interpolation:
std::vector< float > times;
void clear_times();
bool times_dirty = true;
void update_times();
//visualization: (constrained model colored with times)
//constrained model buffer: position, normal, id, texcoord
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4, glm::vec2 > times_model_triangles;
GLVertexArray times_model_triangles_for_textured_draw;
bool times_model_triangles_dirty = true;
void update_times_model_triangles();
//-------------------------------
//peeling:
uint32_t peel_step = 0;
enum {
PeelBegin = 0,
PeelSlice = 1,
PeelLink = 2,
PeelBuild = 3,
PeelRepeat = 4,
} peel_action = PeelBegin;
ak::RowColGraph rowcol_graph;
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > rowcol_graph_tristrip;
GLVertexArray rowcol_graph_tristrip_for_path_draw;
bool rowcol_graph_tristrip_dirty = true;
void update_rowcol_graph_tristrip();
// - - - - - - - - - - - - - - - -
//peeling - begin / step:
std::vector< std::vector< ak::EmbeddedVertex > > active_chains;
std::vector< std::vector< ak::Stitch > > active_stitches;
//active chains + stitches; position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > active_chains_tristrip;
GLVertexArray active_chains_tristrip_for_path_draw;
bool active_chains_tristrip_dirty = true;
void update_active_chains_tristrip();
// - - - - - - - - - - - - - - - -
//peeling - slice:
ak::Model slice;
std::vector< ak::EmbeddedVertex > slice_on_model;
std::vector< std::vector< uint32_t > > slice_active_chains;
std::vector< std::vector< uint32_t > > slice_next_chains;
std::vector< bool > slice_next_used_boundary;
std::vector< float > slice_times;
//sliced model: position, normal, color
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > slice_triangles;
GLVertexArray slice_triangles_for_path_draw;
bool slice_triangles_dirty = true;
void update_slice_triangles();
//chains on slice; position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > slice_chains_tristrip;
GLVertexArray slice_chains_tristrip_for_path_draw;
bool slice_chains_tristrip_dirty = true;
void update_slice_chains_tristrip();
// - - - - - - - - - - - - - - - -
//peeling - link:
std::vector< std::vector< ak::Stitch > > next_stitches;
std::vector< ak::Link > links;
//links (+ stitches); position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > links_tristrip;
GLVertexArray links_tristrip_for_path_draw;
bool links_tristrip_dirty = true;
void update_links_tristrip();
// - - - - - - - - - - - - - - - -
//peeling - build:
std::vector< std::vector< ak::EmbeddedVertex > > next_active_chains;
std::vector< std::vector< ak::Stitch > > next_active_stitches;
//active chains + stitches; position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > next_active_chains_tristrip;
GLVertexArray next_active_chains_tristrip_for_path_draw;
bool next_active_chains_tristrip_dirty = true;
void update_next_active_chains_tristrip();
// - - - - - - - - - - - - - - - -
//driver functions that step through the above:
void clear_peeling();
bool step_peeling();
//-------------------------------
//tracing:
std::vector< ak::TracedStitch > traced;
void clear_traced();
bool traced_dirty = true;
void update_traced();
std::string save_traced_file = ""; //if not "", will save traced stitches to this file after every change
void save_traced();
bool traced_tristrip_dirty = true;
//traced yarns + stitches: position, normal, color:
GLAttribBuffer< glm::vec3, glm::vec3, glm::u8vec4 > traced_tristrip;
GLVertexArray traced_tristrip_for_path_draw;
void update_traced_tristrip();
//link bottom constraints directly to top constraints (to test linking function)
void DEBUG_test_linking(bool flip = false);
//place camera to view whole model:
void reset_camera();
};