8#ifndef MODELVIEWER_OBJ_LOADER_HPP
9#define MODELVIEWER_OBJ_LOADER_HPP
38 std::vector<geometry::FaceIndex>
_faces;
44 std::unordered_map<std::string, std::function<void(
const std::string &)>>
66 bool loadModel(
const std::string &filepath)
override;
90 const std::vector<geometry::Vector3> &
getNormals()
const {
Interface for model loaders.
Definition ILoader.hpp:20
Class for loading OBJ models.
Definition ObjLoader.hpp:26
~ObjLoader() override=default
Destructor.
std::unique_ptr< material::MTLMaterial > _material
Material of the model.
Definition ObjLoader.hpp:51
void parseVertice(const std::string &line)
Parse a vertice line from the OBJ file.
Definition ObjLoader.cpp:87
void parseModel(std::ifstream &file)
Parse an OBJ file line by line.
Definition ObjLoader.cpp:45
geometry::FaceIndex parseFaceIndex(const std::string &token)
Parse a face index token from the OBJ file.
Definition ObjLoader.cpp:123
const std::string & getModelPath() const
Definition ObjLoader.hpp:96
const std::vector< geometry::Vector3 > & getVertices() const
Definition ObjLoader.hpp:82
std::vector< geometry::TextureCoordinate > _textureCoords
Texture coordinates of the model.
Definition ObjLoader.hpp:32
std::vector< geometry::Vector3 > _vertices
Vertices of the model.
Definition ObjLoader.hpp:29
const std::vector< geometry::TextureCoordinate > & getTextureCoords() const
Definition ObjLoader.hpp:86
void setModelData()
Set the model data to the geometry.
Definition ObjLoader.cpp:56
const std::vector< geometry::FaceIndex > & getFaces() const
Definition ObjLoader.hpp:94
void reset()
Reset the OBJ loader state.
Definition ObjLoader.cpp:40
void parseFace(const std::string &line)
Parse a face line from the OBJ file.
Definition ObjLoader.cpp:111
QQuick3DGeometry * geometry() const override
Get the geometry of the loaded model.
Definition ObjLoader.hpp:72
material::MTLMaterial * material() const override
Get the material of the loaded model.
Definition ObjLoader.hpp:78
bool loadModel(const std::string &filepath) override
Load an OBJ model from a file.
Definition ObjLoader.cpp:26
ObjLoader()
Constructor.
Definition ObjLoader.cpp:14
std::vector< geometry::FaceIndex > _faces
Faces of the model.
Definition ObjLoader.hpp:38
std::vector< geometry::Vector3 > _normals
Normals of the model.
Definition ObjLoader.hpp:35
std::unique_ptr< geometry::ObjGeometry > _geometry
Geometry of the model.
Definition ObjLoader.hpp:48
void parseNormal(const std::string &line)
Parse a normal vertice line from the OBJ file.
Definition ObjLoader.cpp:95
std::unordered_map< std::string, std::function< void(const std::string &)> > _parseFunctions
Map of parsing functions for different OBJ line prefixes.
Definition ObjLoader.hpp:45
void retrieveMaterial(const std::string &line)
Retrieve material from a material library line and call material's parsing method.
Definition ObjLoader.cpp:140
void resetObj()
Reset the OBJ model state.
Definition ObjLoader.cpp:80
std::string _modelPath
Path to the model file.
Definition ObjLoader.hpp:41
void parseTextureCoordinate(const std::string &line)
Parse a texture coordinate vertice line from the OBJ file.
Definition ObjLoader.cpp:103
const std::vector< geometry::Vector3 > & getNormals() const
Definition ObjLoader.hpp:90
Class representing a material parsed from an MTL file.
Definition Material.hpp:29
Definition ObjLoader.cpp:12
Struct representing a face's indexes in an OBJ model.
Definition GeometryStructs.hpp:28