-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmesh.hpp
More file actions
808 lines (727 loc) · 24.6 KB
/
Copy pathmesh.hpp
File metadata and controls
808 lines (727 loc) · 24.6 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/**
* @file liblava/resource/mesh.hpp
* @brief Vulkan mesh
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/core/misc.hpp"
#include "liblava/resource/buffer.hpp"
#include "liblava/resource/primitive.hpp"
#include "liblava/util/hex.hpp"
#include "liblava/util/log.hpp"
namespace lava {
/**
* @brief Templated mesh data
* @tparam T Input vertex struct
*/
template <typename T = vertex>
struct mesh_template_data {
/// List of vertices
std::vector<T> vertices;
/// List of indices.
index_list indices;
/**
* @brief Move mesh data by offset
* @tparam PosType Coordinate element typename
* @param offset Position offset
*/
template <typename PosType = r32>
void move(std::array<PosType, 3> offset) {
for (T& vertex : vertices) {
for (auto i = 0u; i < 3; ++i) {
vertex.position[i] += offset[i];
}
}
}
/**
* @brief Scale mesh data by factor
* @param factor Position scaling factor
*/
void scale(auto factor) {
for (T& vertex : vertices) {
for (auto i = 0u; i < 3; ++i) {
vertex.position[i] *= factor;
}
}
}
/**
* @brief Scale mesh data by vector
* @tparam PosType Coordinate element typename
* @param factors Array of position scaling factors
*/
template <typename PosType = r32>
void scale_vector(std::array<PosType, 3> factors) {
for (T& vertex : vertices) {
for (auto i = 0u; i < 3; ++i) {
vertex.position[i] *= factors[i];
}
}
}
};
/**
* @brief Temporary templated mesh
* @tparam T Vertex struct typename
*/
template <typename T = vertex>
struct mesh_template : entity {
/// Shared pointer to mesh
using s_ptr = std::shared_ptr<mesh_template<T>>;
/// Map of meshes
using s_map = std::map<id, s_ptr>;
/// List of meshes
using s_list = std::vector<s_ptr>;
/// List of vertices
using vertex_list = std::vector<T>;
/**
* @brief Make a new mesh
* @return s_ptr Shared pointer to mesh
*/
static s_ptr make() {
return std::make_shared<mesh_template<T>>();
}
/**
* @brief Destroy the mesh
*/
~mesh_template() {
destroy();
}
/**
* @brief Create a new mesh
* @param device Vulkan device
* @param mapped Map mesh data
* @param memory_usage Memory usage
* @return Create was successful or failed
*/
bool create(device::ptr device,
bool mapped = false,
VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU);
/**
* @brief Destroy the mesh
*/
void destroy();
/**
* @brief Bind the mesh
* @param cmd_buf Command buffer
*/
void bind(VkCommandBuffer cmd_buf) const;
/**
* @brief Draw the mesh
* @param cmd_buf Command buffer
*/
void draw(VkCommandBuffer cmd_buf) const;
/**
* @brief Bind and draw the mesh
* @param cmd_buf Command buffer
*/
void bind_draw(VkCommandBuffer cmd_buf) const {
bind(cmd_buf);
draw(cmd_buf);
}
/**
* @brief Check if mesh is empty
* @return Mesh is empty or not
*/
bool empty() const {
return m_data.vertices.empty();
}
/**
* @brief Set the mesh data
* @param value Mesh data
*/
void set_data(mesh_template_data<T> const& value) {
m_data = value;
}
/**
* @brief Get the mesh data
* @return mesh_data& Mesh data
*/
mesh_template_data<T>& get_data() {
return m_data;
}
/**
* @brief Add mesh data to existing data
* @param value Mesh data to add
*/
void add_data(mesh_template_data<T> const& value) {
m_data = value;
}
/**
* @brief Get the vertices of the mesh
* @return vertex::list& List of vertices
*/
vertex_list& get_vertices() {
return m_data.vertices;
}
/**
* @brief Get the const vertices of the mesh
* @return vertex::list const& List of vertices
*/
vertex_list const& get_vertices() const {
return m_data.vertices;
}
/**
* @brief Get the vertices count of the mesh
* @return ui32 Number of vertices
*/
ui32 get_vertices_count() const {
return to_ui32(m_data.vertices.size());
}
/**
* @brief Get the indices of the mesh
* @return index_list& List of indices
*/
index_list& get_indices() {
return m_data.indices;
}
/**
* @brief Get the const indices of the mesh
* @return index_list const& List of indices
*/
index_list const& get_indices() const {
return m_data.indices;
}
/**
* @brief Get the indices count of the mesh
* @return ui32 Number of indices
*/
ui32 get_indices_count() const {
return to_ui32(m_data.indices.size());
}
/**
* @brief Reload the mesh data
* @return Reload was successful or failed
*/
bool reload();
/**
* @brief Get the vertex buffer of the mesh
* @return buffer::s_ptr Shared pointer to buffer
*/
buffer::s_ptr get_vertex_buffer() {
return m_vertex_buffer;
}
/**
* @brief Get the index buffer of the mesh
* @return buffer::s_ptr Shared pointer to buffer
*/
buffer::s_ptr get_index_buffer() {
return m_index_buffer;
}
private:
/// Vulkan device
device::ptr m_device = nullptr;
/// Mesh data
mesh_template_data<T> m_data;
/// Vertex buffer
buffer::s_ptr m_vertex_buffer;
/// Index buffer
buffer::s_ptr m_index_buffer;
/// Mapped state
bool m_mapped = false;
/// Memory usage
VmaMemoryUsage m_memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
};
//-----------------------------------------------------------------------------
template <typename T>
void mesh_template<T>::bind(VkCommandBuffer cmd_buf) const {
if (m_vertex_buffer && m_vertex_buffer->valid()) {
std::array<VkDeviceSize, 1> const buffer_offsets = {0};
std::array<VkBuffer, 1> const buffers = {m_vertex_buffer->get()};
vkCmdBindVertexBuffers(cmd_buf, 0,
to_ui32(buffers.size()), buffers.data(),
buffer_offsets.data());
}
if (m_index_buffer && m_index_buffer->valid())
vkCmdBindIndexBuffer(cmd_buf,
m_index_buffer->get(),
0,
VK_INDEX_TYPE_UINT32);
}
//-----------------------------------------------------------------------------
template <typename T>
void mesh_template<T>::draw(VkCommandBuffer cmd_buf) const {
if (!m_data.indices.empty())
vkCmdDrawIndexed(cmd_buf,
to_ui32(m_data.indices.size()),
1, 0, 0, 0);
else
vkCmdDraw(cmd_buf,
to_ui32(m_data.vertices.size()),
1, 0, 0);
}
//-----------------------------------------------------------------------------
template <typename T>
void mesh_template<T>::destroy() {
m_vertex_buffer = nullptr;
m_index_buffer = nullptr;
m_device = nullptr;
}
//-----------------------------------------------------------------------------
template <typename T>
bool mesh_template<T>::reload() {
auto dev = m_device;
destroy();
return create(dev, m_mapped, m_memory_usage);
}
/**
* @brief Create a new primitive mesh_data
* @tparam T Type of vertex struct
* @tparam generate_colors If color may be generated
* @tparam generate_normals If normals may be generated
* @tparam generate_uvs If UVs may be generated
* @tparam has_colors On MSVC, specifies if a `color` field exists
* @tparam has_normals On MSVC, specifies if a `normal` field exists
* @tparam has_uvs On MSVC, specifies if a `uv` field exists
* @param type Mesh type
* @return mesh_template_data<T> Mesh data
*/
template <typename T = vertex,
bool generate_colors = true,
bool generate_normals = true,
bool generate_uvs = true,
bool has_colors = true,
bool has_normals = true,
bool has_uvs = true>
mesh_template_data<T> create_mesh_data(mesh_type type);
/**
* @brief Create a new primitive mesh
* @tparam T Type of vertex struct
* @tparam generate_colors If color may be generated
* @tparam generate_normals If normals may be generated
* @tparam generate_uvs If UVs may be generated
* @tparam has_colors On MSVC, specifies if a `color` field exists
* @tparam has_normals On MSVC, specifies if a `normal` field exists
* @tparam has_uvs On MSVC, specifies if a `uv` field exists
* @param device Vulkan device
* @param type Mesh type
* @return std::shared_ptr<mesh_template<T>> Shared pointer to mesh
*/
template <typename T = vertex,
bool generate_colors = true,
bool generate_normals = true,
bool generate_uvs = true,
bool has_colors = true,
bool has_normals = true,
bool has_uvs = true>
std::shared_ptr<mesh_template<T>> create_mesh(device::ptr& device,
mesh_type type);
//-----------------------------------------------------------------------------
template <typename T>
bool mesh_template<T>::create(device::ptr dev,
bool m,
VmaMemoryUsage mu) {
m_device = dev;
m_mapped = m;
m_memory_usage = mu;
if (!m_data.vertices.empty()) {
m_vertex_buffer = buffer::make();
if (!m_vertex_buffer->create(m_device,
m_data.vertices.data(),
sizeof(T) * m_data.vertices.size(),
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
m_mapped,
m_memory_usage)) {
logger()->error("create mesh vertex buffer");
return false;
}
}
if (!m_data.indices.empty()) {
m_index_buffer = buffer::make();
if (!m_index_buffer->create(m_device,
m_data.indices.data(),
sizeof(ui32) * m_data.indices.size(),
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
m_mapped,
m_memory_usage)) {
logger()->error("create mesh index buffer");
return false;
}
}
return true;
}
/**
* @brief Make primitive positions for cube
* @tparam PosType Type of position
* @tparam vert_count Number of vertices
* @tparam is_complex Complex state
* @return constexpr std::array<PosType, vert_count> Array of positions
*/
template <typename PosType, size_t vert_count, bool is_complex>
constexpr std::array<PosType, vert_count> make_primitive_positions_cube();
//-----------------------------------------------------------------------------
// NOTE: The C++20 spec allows std::vector<T> to be constexpr
// g++ does not currently implement this feature, however
//-----------------------------------------------------------------------------
/**
* @brief Make primitive indices for cube
* @tparam is_complex Complex state
* @return std::vector<index> Array for indices
*/
template <bool is_complex>
std::vector<index> make_primitive_indices_cube();
/**
* @brief Make primitive normals for cube
* @tparam NormType Type of normal
* @return constexpr std::array<NormType, 6> Array of normals
*/
template <typename NormType>
constexpr std::array<NormType, 6> make_primitive_normals_cube();
/**
* @brief Make primitive uvs for cube
* @tparam UVType Type of uv
* @return constexpr std::array<UVType, 24> Array of uvs
*/
template <typename UVType>
constexpr std::array<UVType, 24> make_primitive_uvs_cube();
//-----------------------------------------------------------------------------
template <typename T,
bool generate_colors,
bool generate_normals,
bool generate_uvs,
bool has_colors,
bool has_normals,
bool has_uvs>
std::shared_ptr<mesh_template<T>> create_mesh(device::ptr& device,
mesh_type type) {
std::shared_ptr<mesh_template<T>> return_mesh =
std::make_shared<mesh_template<T>>();
return_mesh->add_data(create_mesh_data<T,
generate_colors,
generate_normals,
generate_uvs,
has_colors,
has_normals,
has_uvs>(type));
return_mesh->create(device);
return return_mesh;
}
//-----------------------------------------------------------------------------
template <typename T,
bool generate_colors,
bool generate_normals,
bool generate_uvs,
bool has_colors,
bool has_normals,
bool has_uvs>
mesh_template_data<T> create_mesh_data(mesh_type type) {
mesh_template_data<T> return_mesh_data;
constexpr bool auto_position = requires(const T t) {
t.position;
};
static_assert(auto_position,
"Vertex struct `T` must contain field `position`");
constexpr bool auto_colors = requires(const T t) {
t.color;
};
constexpr bool auto_normals = requires(const T t) {
t.normal;
};
constexpr bool auto_uvs = requires(const T t) {
t.uv;
};
using PosType = decltype(T::position);
switch (type) {
case mesh_type::cube: {
return_mesh_data.indices.reserve(36);
return_mesh_data.indices = make_primitive_indices_cube<(generate_normals
&& auto_normals)>();
constexpr size_t vert_count = (generate_normals && auto_normals) ? 24 : 8;
return_mesh_data.vertices.reserve(vert_count);
auto positions = make_primitive_positions_cube<PosType, vert_count,
(generate_normals && auto_normals)>();
for (size_t i = 0; i < vert_count; i++) {
T vert;
vert.position = positions[i];
if constexpr (generate_normals && auto_normals) {
// this array is generated inside of every loop because
// that makes the scoping rules simplest to follow
// my expectation is that a compiler should be able
// to trivially optimize this
using NormType = decltype(T::normal);
auto normals = make_primitive_normals_cube<NormType>();
vert.normal = normals[i / 4];
}
if constexpr (generate_uvs && auto_uvs) {
using UVType = decltype(T::uv);
auto uvs = make_primitive_uvs_cube<UVType>();
vert.uv = uvs[i];
}
return_mesh_data.vertices.push_back(vert);
}
break;
}
case mesh_type::triangle: {
return_mesh_data.vertices.reserve(3);
T vert_one;
vert_one.position = {1, 1, 0};
T vert_two;
vert_two.position = {-1, 1, 0};
T vert_three;
vert_three.position = {0, -1, 0};
if constexpr (generate_uvs && auto_uvs) {
vert_one.uv = {1, 1};
vert_two.uv = {0, 1};
vert_three.uv = {0.5, 0};
}
if constexpr (generate_normals && auto_normals) {
vert_one.normal = {1, 1, 0};
vert_two.normal = {-1, 1, 0};
vert_three.normal = {0, -1, 0};
}
return_mesh_data.vertices.push_back(vert_one);
return_mesh_data.vertices.push_back(vert_two);
return_mesh_data.vertices.push_back(vert_three);
break;
}
case mesh_type::quad: {
return_mesh_data.vertices.reserve(4);
return_mesh_data.indices.reserve(6);
T vert_one;
vert_one.position = {1, 1, 0};
T vert_two;
vert_two.position = {-1, 1, 0};
T vert_three;
vert_three.position = {-1, -1, 0};
T vert_four;
vert_four.position = {1, -1, 0};
if constexpr (generate_uvs && auto_uvs) {
vert_one.uv = {1, 1};
vert_two.uv = {0, 1};
vert_three.uv = {0, 0};
vert_four.uv = {1, 0};
}
if constexpr (generate_normals && auto_normals) {
vert_one.normal = {0, 0, 1};
vert_two.normal = {0, 0, 1};
vert_three.normal = {0, 0, 1};
vert_four.normal = {0, 0, 1};
}
// clang-format off
return_mesh_data.indices = {
0, 1, 2,
2, 3, 0,
};
// clang-format on
return_mesh_data.vertices.push_back(vert_one);
return_mesh_data.vertices.push_back(vert_two);
return_mesh_data.vertices.push_back(vert_three);
return_mesh_data.vertices.push_back(vert_four);
break;
}
case mesh_type::hexagon: {
return_mesh_data.vertices.reserve(7);
return_mesh_data.indices.reserve(18);
hex_layout layout;
layout.orientation = hex_layout_point_y;
layout.size = {1, 1};
auto hex_corners = hex_polygon_corners(layout, {});
T vert_center;
vert_center.position = {0, 0, 0};
T vert_sw;
PosType temp;
temp[0] = hex_corners.at(0).x;
temp[1] = hex_corners.at(0).y;
temp[2] = 0;
vert_sw.position = temp;
T vert_nw;
temp[0] = hex_corners.at(1).x;
temp[1] = hex_corners.at(1).y;
vert_nw.position = temp;
T vert_n;
temp[0] = hex_corners.at(2).x;
temp[1] = hex_corners.at(2).y;
vert_n.position = temp;
T vert_ne;
temp[0] = hex_corners.at(3).x;
temp[1] = hex_corners.at(3).y;
vert_ne.position = temp;
T vert_se;
temp[0] = hex_corners.at(4).x;
temp[1] = hex_corners.at(4).y;
vert_se.position = temp;
T vert_s;
temp[0] = hex_corners.at(5).x;
temp[1] = hex_corners.at(5).y;
vert_s.position = temp;
if constexpr (generate_uvs && auto_uvs) {
vert_center.uv = {0, 0};
vert_sw.uv = {1, 0};
vert_nw.uv = {0, 1};
vert_n.uv = {1, 1};
vert_ne.uv = {1, 0};
vert_se.uv = {0, 1};
vert_s.uv = {1, 1};
}
if constexpr (generate_normals && auto_normals) {
vert_center.normal = {0, 0, 1};
vert_sw.normal = {0, 0, 1};
vert_nw.normal = {0, 0, 1};
vert_n.normal = {0, 0, 1};
vert_ne.normal = {0, 0, 1};
vert_se.normal = {0, 0, 1};
vert_s.normal = {0, 0, 1};
}
// clang-format off
return_mesh_data.indices = {
0, 1, 6, 0, 6, 5, 0, 5, 4, 0, 4, 3, 0, 3, 2, 0, 2, 1
};
// clang-format on
return_mesh_data.vertices.push_back(vert_center);
return_mesh_data.vertices.push_back(vert_sw);
return_mesh_data.vertices.push_back(vert_nw);
return_mesh_data.vertices.push_back(vert_n);
return_mesh_data.vertices.push_back(vert_ne);
return_mesh_data.vertices.push_back(vert_se);
return_mesh_data.vertices.push_back(vert_s);
break;
}
case mesh_type::none:
default:
break;
}
if constexpr (generate_colors && auto_colors) {
for (auto& vert : return_mesh_data.vertices) {
// this does not work on glm vectors
// for (auto& this_color : vert.color) {
// for (auto& color_component : this_color) {
// color_component = 1;
// }
// }
if constexpr (std::is_same_v<decltype(vert.color), glm::vec3>) {
vert.color = {1, 1, 1};
} else if constexpr (std::is_same_v<decltype(vert.color), glm::vec4>) {
vert.color = {1, 1, 1, 1};
} else {
for (size_t i = 0; i < vert.color.size(); i++) {
vert.color[i] = 1;
}
}
}
}
return return_mesh_data;
}
//-----------------------------------------------------------------------------
template <typename PosType,
size_t vert_count,
bool is_complex>
constexpr std::array<PosType, vert_count> make_primitive_positions_cube() {
// clang-format off
if constexpr (is_complex) {
std::array<PosType, 24> const positions = {{
// front
{ 1, 1, 1 }, { -1, 1, 1}, { -1, -1, 1 }, { 1, -1, 1 },
// back
{ 1, 1, -1 }, { -1, 1, -1 }, { -1, -1, -1 }, { 1, -1, -1 },
// left
{ -1, 1, 1 }, { -1, 1, -1 }, { -1, -1, -1 }, { -1, -1, 1 },
// right
{ 1, 1, 1 }, { 1, -1, 1 }, { 1, -1, -1 }, { 1, 1, -1 },
// bottom
{ 1, 1, 1 }, { -1, 1, 1 }, { -1, 1, -1 }, { 1, 1, -1 },
// top
{ 1, -1, 1 }, { -1, -1, 1 }, { -1, -1, -1 }, { 1, -1, -1 },
}};
return positions;
} else {
std::array<PosType, 8> const positions = {{
{ -1, -1, -1 },
{ -1, -1, 1 },
{ -1, 1, -1 },
{ -1, 1, 1 },
{ 1, -1, -1 },
{ 1, -1, 1 },
{ 1, 1, -1 },
{ 1, 1, 1 },
}};
return positions;
}
// clang-format on
}
//-----------------------------------------------------------------------------
template <bool is_complex>
std::vector<index> make_primitive_indices_cube() {
// clang-format off
if constexpr (is_complex) {
std::vector<index> const indices = {
0, 1, 2,
2, 3, 0,
4, 7, 6,
6, 5, 4,
8, 9, 10,
10, 11, 8,
12, 13, 14,
14, 15, 12,
16, 19, 18,
18, 17, 16,
20, 21, 22,
22, 23, 20,
};
return indices;
} else {
// clockwise winding order
std::vector<index> const indices = {
// left
0, 1, 2,
2, 1, 3,
// right
4, 5, 6,
6, 5, 7,
// top
0, 1, 4,
4, 1, 5,
// bottom
2, 3, 6,
6, 3, 7,
// back
3, 1, 5,
5, 7, 3,
// front
2, 0, 4,
4, 6, 2,
};
return indices;
}
// clang-format on
}
//-----------------------------------------------------------------------------
template <typename NormType>
constexpr std::array<NormType, 6> make_primitive_normals_cube() {
// clang-format off
// front, back, left, right, bottom, and top normals, in that order
std::array<NormType, 6> const normals = {{ { 0, 0, 1 }, { 0, 0, -1 },
{ -1, 0, 0 }, { 1, 0, 0 },
{ 0, 1, 0 }, { 0, -1, 0 }, }};
// clang-format on
return normals;
}
//-----------------------------------------------------------------------------
template <typename UVType>
constexpr std::array<UVType, 24> make_primitive_uvs_cube() {
// clang-format off
std::array<UVType, 24> const uvs = {{
{ 1, 1 }, { 0, 1 }, { 0, 0 }, { 1, 0 }, // front
{ 0, 1 }, { 1, 1 }, { 1, 0 }, { 0, 0 }, // back
{ 1, 1 }, { 0, 1 }, { 0, 0 }, { 1, 0 }, // left
{ 0, 1 }, { 0, 0 }, { 1, 0 }, { 1, 1 }, // right
{ 1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 }, // bottom
{ 1, 1 }, { 0, 1 }, { 0, 0 }, { 1, 0 }, // top
}};
// clang-format on
return uvs;
}
/// Mesh data with default vertex
using mesh_data = mesh_template_data<vertex>;
/// Mesh with default vertex
using mesh = mesh_template<vertex>;
/**
* @brief Mesh meta
*/
struct mesh_meta {
/// Name of file (empty: see type)
string filename;
/// Mesh type
mesh_type type = mesh_type::none;
};
/// Mesh registry
using mesh_registry = id_registry<mesh, mesh_meta>;
} // namespace lava