Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
OBJLoader.hpp
Go to the documentation of this file.
1/**************************************************************************
2 * EngineSquared v0.1.1
3 *
4 * EngineSquared is a software package, part of the Engine² organization.
5 *
6 * This file is part of the EngineSquared project that is under MIT License.
7 * Copyright © 2025-present by @EngineSquared, All rights reserved.
8 *
9 * EngineSquared is a free software: you can redistribute it and/or modify
10 * it under the terms of the MIT License. See the project's LICENSE file for
11 * the full license text and details.
12 *
13 * @file OBJLoader.hpp
14 * @brief OBJLoader class declaration.
15 *
16 * This class is used to load and parse OBJ files.
17 *
18 * @author @EngineSquared
19 * @version 0.1.1
20 * @date 2025-10-03
21 **************************************************************************/
22
23#pragma once
24#include <string>
25#include <tiny_obj_loader.h>
26
28#include "component/Mesh.hpp"
30#include "resource/Shape.hpp"
31
32namespace Object {
33
71class OBJLoader {
72 public:
82 explicit OBJLoader(const std::string &filepath, const std::string &mtlSearchPath = "");
83 ~OBJLoader() = default;
84
92 [[nodiscard]] Component::Mesh GetMesh();
93
101 [[nodiscard]] std::vector<Resource::Shape> GetShapes();
102
110 [[nodiscard]] std::vector<Component::Material> GetMaterials();
111
112 private:
124 void ProcessMeshFace(Component::Mesh &mesh, const std::vector<tinyobj::shape_t> &shapes, size_t shape,
125 size_t face_vertices, size_t &index_offset) noexcept;
126
133 void SetMaterialProperties(Component::Material &material, const tinyobj::material_t &mat) noexcept;
134
135 protected:
136 private:
137 tinyobj::ObjReaderConfig _reader_config;
138 tinyobj::ObjReader _reader;
140 std::vector<Resource::Shape> _shapes{};
141 std::vector<Component::Material> _materials{};
142};
143
144} // namespace Object
void ProcessMeshFace(Component::Mesh &mesh, const std::vector< tinyobj::shape_t > &shapes, size_t shape, size_t face_vertices, size_t &index_offset) noexcept
Processes a single face of the mesh and populates the Mesh object.
Definition OBJLoader.cpp:123
std::vector< Component::Material > _materials
Definition OBJLoader.hpp:141
OBJLoader(const std::string &filepath, const std::string &mtlSearchPath="")
Constructs an OBJLoader for the specified file.
Definition OBJLoader.cpp:6
tinyobj::ObjReaderConfig _reader_config
Definition OBJLoader.hpp:137
std::vector< Resource::Shape > GetShapes()
Retrieves the loaded shapes data.
Definition OBJLoader.cpp:58
std::vector< Resource::Shape > _shapes
Definition OBJLoader.hpp:140
std::vector< Component::Material > GetMaterials()
Retrieves the loaded materials data.
Definition OBJLoader.cpp:104
tinyobj::ObjReader _reader
Definition OBJLoader.hpp:138
void SetMaterialProperties(Component::Material &material, const tinyobj::material_t &mat) noexcept
Sets the properties of a material according to the tinyobj::material_t structure.
Definition OBJLoader.cpp:174
~OBJLoader()=default
Component::Mesh _mesh
Definition OBJLoader.hpp:139
Component::Mesh GetMesh()
Retrieves the loaded mesh data.
Definition OBJLoader.cpp:28
Definition AmbientLight.hpp:5
Material structure.
Definition Material.hpp:41
Mesh structure.
Definition Mesh.hpp:40