-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCTriangleMesh.h
More file actions
137 lines (113 loc) · 3.41 KB
/
CTriangleMesh.h
File metadata and controls
137 lines (113 loc) · 3.41 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
#pragma once
#include <nabla.h>
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
#include "shaders/globals.hlsl"
using namespace nbl;
struct DTMHeightShadingSettingsInfo
{
// Height Shading Mode
E_HEIGHT_SHADING_MODE heightShadingMode;
// Used as fixed interval length for "DISCRETE_FIXED_LENGTH_INTERVALS" shading mode
float intervalLength;
// Converts an interval index to its corresponding height value
// For example, if this value is 10.0, then an interval index of 2 corresponds to a height of 20.0.
// This computed height is later used to determine the interpolated color for shading.
// It makes sense for this variable to be always equal to `intervalLength` but sometimes it's a different scaling so that last index corresponds to largestHeight
float intervalIndexToHeightMultiplier;
// Used for "DISCRETE_FIXED_LENGTH_INTERVALS" shading mode
// If `isCenteredShading` is true, the intervals are centered around `minHeight`, meaning the
// first interval spans [minHeight - intervalLength / 2.0, minHeight + intervalLength / 2.0].
// Otherwise, intervals are aligned from `minHeight` upward, so the first interval spans
// [minHeight, minHeight + intervalLength].
bool isCenteredShading;
void addHeightColorMapEntry(float height, float32_t4 color)
{
heightColorSet.emplace(height, color);
}
bool fillShaderDTMSettingsHeightColorMap(DTMSettings& dtmSettings) const
{
const uint32_t mapSize = heightColorSet.size();
if (mapSize > DTMHeightShadingSettings::HeightColorMapMaxEntries)
return false;
dtmSettings.heightShadingSettings.heightColorEntryCount = mapSize;
int index = 0;
for (auto it = heightColorSet.begin(); it != heightColorSet.end(); ++it)
{
dtmSettings.heightShadingSettings.heightColorMapHeights[index] = it->height;
dtmSettings.heightShadingSettings.heightColorMapColors[index] = it->color;
++index;
}
return true;
}
private:
struct HeightColor
{
float height;
float32_t4 color;
bool operator<(const HeightColor& other) const
{
return height < other.height;
}
};
std::set<HeightColor> heightColorSet;
};
struct DTMContourSettingsInfo
{
LineStyleInfo lineStyleInfo;
float startHeight;
float endHeight;
float heightInterval;
};
struct DTMSettingsInfo
{
static constexpr uint32_t MaxContourSettings = DTMSettings::MaxContourSettings;
uint32_t mode = 0u; // related to E_DTM_MODE
// outline
LineStyleInfo outlineStyleInfo;
// contours
uint32_t contourSettingsCount = 0u;
DTMContourSettingsInfo contourSettings[MaxContourSettings];
// height shading
DTMHeightShadingSettingsInfo heightShadingInfo;
};
class CTriangleMesh final
{
public:
using index_t = uint32_t;
using vertex_t = TriangleMeshVertex;
inline void setVertices(core::vector<vertex_t>&& vertices)
{
m_vertices = std::move(vertices);
}
inline void setIndices(core::vector<uint32_t>&& indices)
{
m_indices = std::move(indices);
}
inline const core::vector<vertex_t>& getVertices() const
{
return m_vertices;
}
inline const core::vector<uint32_t>& getIndices() const
{
return m_indices;
}
inline size_t getVertexBuffByteSize() const
{
return sizeof(vertex_t) * m_vertices.size();
}
inline size_t getIndexBuffByteSize() const
{
return sizeof(index_t) * m_indices.size();
}
inline size_t getIndexCount() const
{
return m_indices.size();
}
inline void clear()
{
m_vertices.clear();
m_indices.clear();
}
core::vector<vertex_t> m_vertices;
core::vector<index_t> m_indices;
};