This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwavefront_loader.hpp
More file actions
executable file
·115 lines (99 loc) · 2.41 KB
/
Copy pathwavefront_loader.hpp
File metadata and controls
executable file
·115 lines (99 loc) · 2.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
#pragma once
#include <cstdint>
#include <optional>
#include <vector>
#include <string>
#ifndef TUTORIAL_VK_BITMASK
#define TUTORIAL_VK_BITMASK(XD) 1ul << XD
#endif
namespace tnr::m3d::wavefront
{
enum tnrWavefrontOpenFlag : uint32_t
{
NO_FLAGS = 0,
FLIP_POSITION_Y_AXIS = TUTORIAL_VK_BITMASK(0), // Flips all position vectors within Y axis.
DONT_LOAD_MATERIALS = TUTORIAL_VK_BITMASK(2), // Load mesh without materials. If not present, material MUST be loaded before loading model file.
};
struct tnrMaterial
{
std::string MaterialName;
// Color properties.
struct
{
float x;
float y;
float z;
} AmbientColor;
struct
{
float x;
float y;
float z;
} AlbedoColor;
struct
{
float x;
float y;
float z;
} SpecularColor;
struct
{
float x;
float y;
float z;
} EmissionColor;
// Light properties.
float SpecularFactor;
float RefractionFactor;
float AlphaFactor; // Currently this property is not readed and is omitted.
struct tnrTextureInfo
{
std::string Name;
};
// Textures properties.
std::optional<tnrTextureInfo> AlbedoMap;
std::optional<tnrTextureInfo> NormalMap;
std::optional<tnrTextureInfo> SpecularMap;
};
struct tnrObject
{
template<typename T>
struct vec3
{
T x;
T y;
T z;
};
template<typename T>
struct vec2
{
T x;
T y;
};
std::string ObjectName;
std::string MaterialName;
std::vector<vec3<float>> Positions;
std::vector<vec3<float>> Normals;
std::vector<vec2<float>> TextureCoords;
};
// Vertices color unsupported. OBJ must be exported with Z as forward axis and -Y as up axis for compatibility with Vulkan.
class tnrWavefrontLoader
{
private:
struct ObjectInfo
{
std::optional<uint32_t> MaterialIndex;
tnrObject Object;
};
std::vector<tnrObject> Objects;
std::vector<tnrMaterial> Materials;
tnrWavefrontOpenFlag Flags;
void LoadMaterials(const std::string& MTLFile);
void LoadObject(const std::string& ObjFile);
public:
tnrWavefrontLoader(const tnrWavefrontOpenFlag OpenFlags = tnrWavefrontOpenFlag::DONT_LOAD_MATERIALS, const std::string ModelFile = "", const std::string MaterialFile = "");
~tnrWavefrontLoader() = default;
const std::vector<tnrObject>& GetLoadedObjects() const;
const std::vector<tnrMaterial>& GetLoadedMaterials() const;
};
}