forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjloader.h
74 lines (67 loc) · 2.12 KB
/
objloader.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#pragma once
#include <unordered_set>
class ObjLoader final
{
public:
ObjLoader() = default;
~ObjLoader()
{
if (m_fHandle != nullptr) fclose(m_fHandle);
if (m_matFile != nullptr) fclose(m_matFile);
m_verts.clear();
m_indices.clear();
}
bool Load(const string& filename, const bool flipTv, const bool convertToLeftHanded);
void Save(const string& filename, const string& description, const Mesh& mesh);
bool ExportStart(const string& filename);
void ExportEnd()
{
fclose(m_fHandle);
m_fHandle = nullptr;
fclose(m_matFile);
m_matFile = nullptr;
}
void UpdateFaceOffset(unsigned int numVertices)
{
m_faceIndexOffset += numVertices;
}
void WriteObjectName(const string& objname)
{
fprintf_s(m_fHandle, "o %s\n", objname.c_str());
}
void WriteVertexInfo(const Vertex3D_NoTex2* verts, unsigned int numVerts);
void WriteFaceInfo(const vector<WORD>& faces);
void WriteFaceInfoLong(const vector<unsigned int>& faces);
void WriteFaceInfoList(const WORD* faces, const unsigned int numIndices);
void UseTexture(const string& texelName) const
{
fprintf_s(m_fHandle, "usemtl %s\n", texelName.c_str());
}
bool LoadMaterial(const string& filename, Material* const mat);
void WriteMaterial(const string& texelName, const string& texelFilename, const Material* const mat);
const vector<Vertex3D_NoTex2>& GetVertices()
{
return m_verts;
}
const vector<unsigned int>& GetIndices()
{
return m_indices;
}
private:
struct MyPoly
{
int vi0, ti0, ni0;
int vi1, ti1, ni1;
int vi2, ti2, ni2;
};
vector<Vertex3Ds> m_tmpVerts;
vector<Vertex3Ds> m_tmpNorms;
vector<Vertex2D> m_tmpTexel;
std::unordered_set<std::pair<const Vertex3D_NoTex2*, const unsigned int>, Vertex3D_NoTex2IdxHashFunctor, Vertex3D_NoTex2IdxComparator> m_tmpCombined; // only used to find duplicate vertices quickly
vector<MyPoly> m_tmpFaces;
vector<Vertex3D_NoTex2> m_verts;
vector<unsigned int> m_indices;
unsigned int m_faceIndexOffset = 0;
FILE* m_matFile = nullptr;
FILE* m_fHandle = nullptr;
};