group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
ModelLoader.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cstddef>
7#include <cstdint>
8#include <glm/glm.hpp>
9#include <string>
10#include <vector>
11
19{
20 glm::vec3 position;
21 glm::vec3 normal;
22 glm::vec2 texCoord;
23 glm::vec4 tangent;
24};
25
26static_assert(sizeof(ModelVertex) == 48, "ModelVertex size mismatch — check padding");
27static_assert(offsetof(ModelVertex, normal) == 12, "ModelVertex normal offset mismatch");
28static_assert(offsetof(ModelVertex, texCoord) == 24, "ModelVertex texCoord offset mismatch");
29static_assert(offsetof(ModelVertex, tangent) == 32, "ModelVertex tangent offset mismatch");
30
32enum class AlphaMode
33{
34 Opaque,
35 Mask,
36 Blend
37};
38
41{
42 glm::vec4 baseColorFactor{1.0f, 1.0f, 1.0f, 1.0f};
43 float metallicFactor = 0.0f;
44 float roughnessFactor = 0.5f;
45 float aoStrength = 1.0f;
46 float normalScale = 1.0f;
47 glm::vec4 emissiveFactor{0.0f, 0.0f, 0.0f, 0.0f};
49 float alphaCutoff = 0.5f;
50};
51
54{
55 std::vector<ModelVertex> vertices;
56 std::vector<uint32_t> indices;
57 int diffuseTexIndex = -1;
58 int normalTexIndex = -1;
60 int aoTexIndex = -1;
63};
64
67{
68 std::vector<uint8_t> pixels;
69 int width = 0;
70 int height = 0;
71 bool isSRGB = true;
72};
73
76{
77 std::vector<MeshData> meshes;
78 std::vector<TextureData> textures;
79};
80
92bool loadModel(const std::string& path, LoadedModel& outModel, bool flipUVs = false);
bool loadModel(const std::string &path, LoadedModel &outModel, bool flipUVs=false)
Load a model file via Assimp and decode its embedded textures.
Definition ModelLoader.cpp:371
AlphaMode
glTF alpha blending mode.
Definition ModelLoader.hpp:33
Everything returned by loadModel().
Definition ModelLoader.hpp:76
std::vector< MeshData > meshes
Definition ModelLoader.hpp:77
std::vector< TextureData > textures
Definition ModelLoader.hpp:78
PBR material scalar parameters extracted from Assimp/glTF.
Definition ModelLoader.hpp:41
float aoStrength
Definition ModelLoader.hpp:45
float metallicFactor
Default dielectric (non-metal).
Definition ModelLoader.hpp:43
float alphaCutoff
Threshold for AlphaMode::Mask.
Definition ModelLoader.hpp:49
glm::vec4 emissiveFactor
rgb in xyz, w unused.
Definition ModelLoader.hpp:47
AlphaMode alphaMode
Definition ModelLoader.hpp:48
glm::vec4 baseColorFactor
Definition ModelLoader.hpp:42
float roughnessFactor
Default mid-roughness.
Definition ModelLoader.hpp:44
float normalScale
Definition ModelLoader.hpp:46
CPU-side mesh data ready for GPU upload.
Definition ModelLoader.hpp:54
int metallicRoughnessTexIndex
Combined metallic-roughness (glTF convention).
Definition ModelLoader.hpp:59
int diffuseTexIndex
Base colour / albedo texture.
Definition ModelLoader.hpp:57
std::vector< uint32_t > indices
Definition ModelLoader.hpp:56
int normalTexIndex
Normal map texture.
Definition ModelLoader.hpp:58
int emissiveTexIndex
Emissive texture.
Definition ModelLoader.hpp:61
std::vector< ModelVertex > vertices
Definition ModelLoader.hpp:55
int aoTexIndex
Ambient occlusion texture.
Definition ModelLoader.hpp:60
MaterialData material
Scalar PBR factors.
Definition ModelLoader.hpp:62
One vertex in a loaded 3-D model (PBR-ready).
Definition ModelLoader.hpp:19
glm::vec3 normal
Definition ModelLoader.hpp:21
glm::vec2 texCoord
Definition ModelLoader.hpp:22
glm::vec3 position
Definition ModelLoader.hpp:20
glm::vec4 tangent
xyz = tangent direction, w = bitangent handedness (±1).
Definition ModelLoader.hpp:23
RGBA pixel data for one texture (decoded from embedded PNG/JPEG).
Definition ModelLoader.hpp:67
int height
Definition ModelLoader.hpp:70
std::vector< uint8_t > pixels
Row-major RGBA, 4 bytes per pixel.
Definition ModelLoader.hpp:68
bool isSRGB
True for color textures (albedo, emissive); false for data (normal, MR).
Definition ModelLoader.hpp:71
int width
Definition ModelLoader.hpp:69