2022-10-20 11:30:15 -04:00
|
|
|
/*
|
|
|
|
* Created by Brett Terpstra 6920201 on 17/10/22.
|
|
|
|
* Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STEP_2_MODELS_H
|
|
|
|
#define STEP_2_MODELS_H
|
|
|
|
|
2022-11-17 00:31:26 -05:00
|
|
|
#include "engine/util/std.h"
|
2022-10-23 23:46:12 -04:00
|
|
|
#include "engine/math/vectors.h"
|
|
|
|
#include "engine/math/colliders.h"
|
2022-10-20 11:30:15 -04:00
|
|
|
|
|
|
|
namespace Raytracing {
|
2022-11-17 00:31:26 -05:00
|
|
|
|
|
|
|
// triangle type for model loading
|
|
|
|
struct Triangle {
|
2022-10-20 11:30:15 -04:00
|
|
|
public:
|
2022-11-17 00:31:26 -05:00
|
|
|
Vec4 vertex1, vertex2, vertex3;
|
|
|
|
Vec4 normal1, normal2, normal3;
|
|
|
|
Vec4 uv1, uv2, uv3;
|
|
|
|
bool hasNormals = false;
|
2022-10-20 11:30:15 -04:00
|
|
|
AABB aabb;
|
2022-11-17 00:31:26 -05:00
|
|
|
|
|
|
|
Triangle(const Vec4& v1, const Vec4& v2, const Vec4& v3): vertex1(v1), vertex2(v2), vertex3(v3) {}
|
|
|
|
|
|
|
|
Triangle(const Vec4& v1, const Vec4& v2, const Vec4& v3,
|
|
|
|
const Vec4& n1, const Vec4& n2, const Vec4& n3): vertex1(v1), vertex2(v2), vertex3(v3),
|
|
|
|
hasNormals(true), normal1(n1), normal2(n2), normal3(n3) {}
|
|
|
|
|
|
|
|
Triangle(const Vec4& v1, const Vec4& v2, const Vec4& v3,
|
|
|
|
const Vec4& uv1, const Vec4& uv2, const Vec4& uv3,
|
|
|
|
const Vec4& n1, const Vec4& n2, const Vec4& n3): vertex1(v1), vertex2(v2), vertex3(v3),
|
|
|
|
uv1(uv1), uv2(uv2), uv3(uv3),
|
|
|
|
hasNormals(true), normal1(n1), normal2(n2), normal3(n3) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// face type for model loading
|
|
|
|
struct face {
|
|
|
|
int v1, v2, v3;
|
|
|
|
int uv1, uv2, uv3;
|
|
|
|
int n1, n2, n3;
|
2022-10-20 11:30:15 -04:00
|
|
|
};
|
|
|
|
|
2022-11-17 00:31:26 -05:00
|
|
|
struct ModelData {
|
|
|
|
// storing all this data is memory inefficient
|
|
|
|
// since normals and vertices are only vec3s
|
|
|
|
// and uvs are vec2s
|
|
|
|
// TODO: create lower order vector classes
|
|
|
|
std::vector<Vec4> vertices;
|
|
|
|
std::vector<Vec4> uvs;
|
|
|
|
std::vector<Vec4> normals;
|
|
|
|
std::vector<face> faces;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TriangulatedModel {
|
|
|
|
std::vector<Triangle> triangles;
|
|
|
|
AABB aabb;
|
|
|
|
|
|
|
|
explicit TriangulatedModel(const ModelData& data);
|
2022-10-20 11:30:15 -04:00
|
|
|
};
|
|
|
|
|
2022-11-17 00:31:26 -05:00
|
|
|
class OBJLoader {
|
2022-10-20 11:30:15 -04:00
|
|
|
private:
|
|
|
|
public:
|
2022-11-17 00:31:26 -05:00
|
|
|
static ModelData loadModel(const std::string& file);
|
2022-10-20 11:30:15 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif //STEP_2_MODELS_H
|