-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFbxSurface.h
52 lines (41 loc) · 1.13 KB
/
FbxSurface.h
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
#pragma once
#include <vector>
#include <unordered_map>
#include "export/ArbitraryMeshVertex.h"
#include "export/VertexHashing.h"
namespace model
{
class FbxSurface
{
public:
std::vector<unsigned int> indices;
std::vector<ArbitraryMeshVertex> vertices;
std::string material;
// Hash index to share vertices with the same set of attributes
std::unordered_map<ArbitraryMeshVertex, std::size_t> vertexIndices;
const std::vector<ArbitraryMeshVertex>& getVertexArray() const
{
return vertices;
}
const std::vector<unsigned int>& getIndexArray() const
{
return indices;
}
const std::string& getActiveMaterial() const
{
return material;
}
void addVertex(const ArbitraryMeshVertex& vertex)
{
// Try to look up an existing vertex or add a new index
auto emplaceResult = vertexIndices.try_emplace(vertex, vertices.size());
if (emplaceResult.second)
{
// This was a new vertex, copy it to the vertex array
vertices.emplace_back(emplaceResult.first->first);
}
// The emplaceResult now points to a valid index in the vertex array
indices.emplace_back(static_cast<unsigned int>(emplaceResult.first->second));
}
};
}