-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube.h
More file actions
84 lines (76 loc) · 2.43 KB
/
Copy pathcube.h
File metadata and controls
84 lines (76 loc) · 2.43 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
#pragma once
#include <array>
/**
* The 8 corners of a unit cube centered at the origin.
* (Ordered in Morton-code order according to https://dl.acm.org/doi/pdf/10.1145/3677388.3696322)
*/
inline std::array<std::array<float, 3>, 8> cubeCorners = {{
{{-0.5f, -0.5f, -0.5f}},
{{ 0.5f, -0.5f, -0.5f}},
{{-0.5f, 0.5f, -0.5f}},
{{ 0.5f, 0.5f, -0.5f}},
{{-0.5f, -0.5f, 0.5f}},
{{ 0.5f, -0.5f, 0.5f}},
{{-0.5f, 0.5f, 0.5f}},
{{ 0.5f, 0.5f, 0.5f}}
}};
inline std::array<std::array<int, 2>, 12> cubeEdges = {{
{{0, 1}}, {{1, 3}}, {{3, 2}}, {{2, 0}}, // bottom face
{{4, 5}}, {{5, 7}}, {{7, 6}}, {{6, 4}}, // top face
{{0, 4}}, {{1, 5}}, {{2, 6}}, {{3, 7}} // vertical edges
}};
inline std::array<std::array<int, 3>, 12> cubeFaces = {
// This matches the order expected in the voxel paint shaders.
std::array<int,3>{0,4,6}, std::array<int,3>{0,6,2}, // -X
std::array<int,3>{1,3,7}, std::array<int,3>{1,7,5}, // +X
std::array<int,3>{0,1,5}, std::array<int,3>{0,5,4}, // -Y
std::array<int,3>{6,7,3}, std::array<int,3>{6,3,2}, // +Y
std::array<int,3>{2,3,1}, std::array<int,3>{2,1,0}, // -Z
std::array<int,3>{4,5,7}, std::array<int,3>{4,7,6} // +Z
};
inline constexpr std::array<float, 24> cubeCornersFlattened = {{
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f
}};
inline constexpr std::array<uint32_t, 24> cubeEdgesFlattened = {{
0,1, 1,3, 3,2, 2,0,
4,5, 5,7, 7,6, 6,4,
0,4, 1,5, 2,6, 3,7
}};
inline constexpr std::array<uint32_t, 36> cubeFacesFlattened = {{
// -X
0,4,6, 0,6,2,
// +X
1,3,7, 1,7,5,
// -Y
0,1,5, 0,5,4,
// +Y
6,7,3, 6,3,2,
// -Z
2,3,1, 2,1,0,
// +Z
4,5,7, 4,7,6
}};
/**
* This gets used as the vertex buffer for drawing cubes in particle mode:
* all points are at the center of the cube, and the vertex shader expands them out to the corners.
*/
inline constexpr std::array<float, 12> cubeQuadVertsFlattened = {
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f
};
/**
* When drawing a cube in particle mode, each corner is really a two-triangle quad.
* We need six indices to draw a quad, and then do the expansion in the vertex shader.
*/
inline constexpr std::array<uint32_t, 6> cubeQuadIndicesFlattened = {{
0, 1, 3, 0, 3, 2
}};