-
Notifications
You must be signed in to change notification settings - Fork 8
/
ObjModel.h
48 lines (40 loc) · 1.25 KB
/
ObjModel.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
#pragma once
#include <array>
#include <map>
#include <string>
#include <string_view>
#include <vector>
#include "vecmat.h"
namespace std::filesystem {
class path;
}
struct StringSplitter {
const char* currentChar;
const char* endChar;
std::string_view splitChars;
StringSplitter(std::string_view splitChars, const char* firstChar, const char* lastChar)
: currentChar(firstChar), endChar(lastChar), splitChars(splitChars) {}
StringSplitter(std::string_view splitChars, std::string_view str)
: currentChar(str.data()), endChar(str.data() + str.size()), splitChars(splitChars) {}
std::string_view next();
bool finished() const { return currentChar == endChar; }
bool isSplitChar(char c) const { return splitChars.find(c) != splitChars.npos; }
};
struct ObjModel {
std::vector<Vector3> vertices;
std::vector<Vector3> texCoords;
std::vector<std::array<std::array<int, 3>, 3>> triangles;
struct Group {
std::string name;
int start, end;
};
std::vector<Group> groups;
struct Material {
std::string map_Kd;
};
std::map<std::string, Material> materials;
void load(const std::filesystem::path& filename);
void loadMaterialLib(const std::filesystem::path& filename);
ObjModel() {}
ObjModel(const std::filesystem::path& filename) { load(filename); }
};