MAGE  v0.171.0
Matthias Advanced Game Engine
mage::rendering::loader::OBJReader< VertexT, IndexT > Class Template Reference

#include <obj_reader.hpp>

Inheritance diagram for mage::rendering::loader::OBJReader< VertexT, IndexT >:
mage::LineReader

Classes

struct  OBJComparator
 

Public Member Functions

 OBJReader (ResourceManager &resource_manager, ModelOutput< VertexT, IndexT > &model_output, const MeshDescriptor< VertexT, IndexT > &mesh_desc)
 
 OBJReader (const OBJReader &reader)=delete
 
 OBJReader (OBJReader &&reader) noexcept
 
 ~OBJReader ()
 
OBJReaderoperator= (const OBJReader &reader)=delete
 
OBJReaderoperator= (OBJReader &&reader)=delete
 
void ReadFromFile (std::filesystem::path path, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function)
 
void ReadFromMemory (const std::string &input, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function)
 

Private Member Functions

virtual void Preprocess () override
 
virtual void ReadLine () override
 
virtual void Postprocess () override
 
void ReadOBJMaterialLibrary ()
 
void ReadOBJMaterialUse ()
 
void ReadOBJGroup ()
 
void ReadOBJObject ()
 
void ReadOBJSmoothingGroup ()
 
void ReadOBJVertex ()
 
void ReadOBJVertexTexture ()
 
void ReadOBJVertexNormal ()
 
void ReadOBJFace ()
 
const Point3 ReadOBJVertexCoordinates ()
 
const Normal3 ReadOBJVertexNormalCoordinates ()
 
const UV ReadOBJVertexTextureCoordinates ()
 
const U32x3 ReadOBJVertexIndices ()
 
const VertexT ConstructVertex (const U32x3 &vertex_indices)
 
void FinalizeModelPart ()
 
- Private Member Functions inherited from mage::LineReader
LineReaderoperator= (const LineReader &reader)=delete
 
LineReaderoperator= (LineReader &&reader) noexcept
 
void ReadFromFile (std::filesystem::path path, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function)
 
void ReadFromMemory (const std::string &input, std::regex regex=s_default_regex, SelectionFunction selection_function=s_default_selection_function)
 
 LineReader ()
 
 LineReader (const LineReader &reader)=delete
 
 LineReader (LineReader &&reader) noexcept
 
 ~LineReader ()
 
const std::filesystem::path & GetPath () const noexcept
 
U32 GetCurrentLineNumber () const noexcept
 
template<typename T >
const T Read ()
 
template<typename T , std::size_t N, size_t A = alignof(T)>
const Array< T, N, A > Read ()
 
void ReadRemainingTokens ()
 
template<typename T >
bool Contains () const noexcept
 
bool ContainsTokens () const noexcept
 

Private Attributes

ModelPart m_model_part
 
std::vector< Point3m_vertex_coordinates
 
std::vector< UVm_vertex_texture_coordinates
 
std::vector< Normal3m_vertex_normal_coordinates
 
std::map< U32x3, IndexT, OBJComparatorm_mapping
 
ResourceManagerm_resource_manager
 
ModelOutput< VertexT, IndexT > & m_model_output
 
const MeshDescriptor< VertexT, IndexT > & m_mesh_desc
 

Additional Inherited Members

- Private Types inherited from mage::LineReader
using SelectionFunction = std::function< const std::ssub_match(const std::smatch &) >
 
- Static Private Attributes inherited from mage::LineReader
static const std::regex s_default_regex = std::regex(R"((\"([^\"]*)\")|(\S+))")
 
static const SelectionFunction s_default_selection_function
 

Detailed Description

template<typename VertexT, typename IndexT>
class mage::rendering::loader::OBJReader< VertexT, IndexT >

A class of OBJ file readers for reading meshes.

Template Parameters
VertexTThe vertex type.
IndexTThe index type.

Constructor & Destructor Documentation

◆ OBJReader() [1/3]

template<typename VertexT , typename IndexT >
mage::rendering::loader::OBJReader< VertexT, IndexT >::OBJReader ( ResourceManager resource_manager,
ModelOutput< VertexT, IndexT > &  model_output,
const MeshDescriptor< VertexT, IndexT > &  mesh_desc 
)
explicit

Constructs an OBJ reader.

Parameters
[in,out]resource_managerA reference to the resource manager.
[in,out]model_outputA reference to a model output for storing the read data from file.
[in]mesh_descA reference to a mesh descriptor.

◆ OBJReader() [2/3]

template<typename VertexT , typename IndexT >
mage::rendering::loader::OBJReader< VertexT, IndexT >::OBJReader ( const OBJReader< VertexT, IndexT > &  reader)
delete

Constructs an OBJ reader from the given OBJ reader.

Parameters
[in]readerA reference to the OBJ reader to copy.

◆ OBJReader() [3/3]

template<typename VertexT , typename IndexT >
mage::rendering::loader::OBJReader< VertexT, IndexT >::OBJReader ( OBJReader< VertexT, IndexT > &&  reader)
noexcept

Constructs an OBJ reader by moving the given OBJ reader.

Parameters
[in]readerA reference to the OBJ reader to move.

◆ ~OBJReader()

template<typename VertexT , typename IndexT >
mage::rendering::loader::OBJReader< VertexT, IndexT >::~OBJReader ( )

Destructs this OBJ reader.

Member Function Documentation

◆ ConstructVertex()

template<typename VertexT , typename IndexT >
const VertexT mage::rendering::loader::OBJReader< VertexT, IndexT >::ConstructVertex ( const U32x3 vertex_indices)
private

Constructs or retrieves (if already existing) the vertex matching the given vertex indices.

Parameters
[in]vertex_indicesA reference to the vertex indices.
Returns
The vertex matching the given vertex indices vertex_indices.

◆ FinalizeModelPart()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::FinalizeModelPart ( )
private

Finalizes the current model part of this OBJ reader and prepare a new current model part.

◆ operator=() [1/2]

template<typename VertexT , typename IndexT >
OBJReader& mage::rendering::loader::OBJReader< VertexT, IndexT >::operator= ( const OBJReader< VertexT, IndexT > &  reader)
delete

Copies the given OBJ reader to this OBJ reader.

Parameters
[in]readerA reference to a OBJ reader to copy.
Returns
A reference to the copy of the given OBJ reader (i.e. this OBJ reader).

◆ operator=() [2/2]

template<typename VertexT , typename IndexT >
OBJReader& mage::rendering::loader::OBJReader< VertexT, IndexT >::operator= ( OBJReader< VertexT, IndexT > &&  reader)
delete

Moves the given OBJ reader to this OBJ reader.

Parameters
[in]readerA reference to a OBJ reader to move.
Returns
A reference to the moved OBJ reader (i.e. this OBJ reader).

◆ Postprocess()

template<typename VertexT , typename IndexT >
virtual void mage::rendering::loader::OBJReader< VertexT, IndexT >::Postprocess ( )
overrideprivatevirtual

Post-processes after reading the current file of this OBJ reader.

Exceptions
ExceptionFailed to finish post-processing successfully.

Reimplemented from mage::LineReader.

◆ Preprocess()

template<typename VertexT , typename IndexT >
virtual void mage::rendering::loader::OBJReader< VertexT, IndexT >::Preprocess ( )
overrideprivatevirtual

Pre-process before reading the current file of this OBJ reader.

Exceptions
ExceptionFailed to finish the pre-processing successfully.

Reimplemented from mage::LineReader.

◆ ReadFromFile()

template<typename VertexT , typename IndexT >
void mage::LineReader::ReadFromFile

Reads from the file associated with the given path.

Parameters
[in]pathThe path.
[in]regexThe (line) regex.
[in]selection_functionThe selection function.
Exceptions
ExceptionFailed to read from the file.

◆ ReadFromMemory()

template<typename VertexT , typename IndexT >
void mage::LineReader::ReadFromMemory

Reads from the given input string.

Parameters
[in]inputA reference to the input string.
[in]regexThe (line) regex.
[in]selection_functionThe selection function.
Exceptions
ExceptionFailed to read from the given input string.

◆ ReadLine()

template<typename VertexT , typename IndexT >
virtual void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadLine ( )
overrideprivatevirtual

Reads the current line of this OBJ reader.

Exceptions
ExceptionFailed to the current line of this OBJ reader.

Implements mage::LineReader.

◆ ReadOBJFace()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJFace ( )
private

Reads a Face definition.

Exceptions
ExceptionFailed to read a Face definition.

◆ ReadOBJGroup()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJGroup ( )
private

Reads a Group definition.

Exceptions
ExceptionFailed to read a Group definition.

◆ ReadOBJMaterialLibrary()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJMaterialLibrary ( )
private

Reads a Material Library Include definition.

Exceptions
ExceptionFailed to read a Material Library Include definition.

◆ ReadOBJMaterialUse()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJMaterialUse ( )
private

Reads a Material Usage definition and imports the materials corresponding to the mesh.

Exceptions
ExceptionFailed to read a Material Usage definition.
ExceptionFailed to import the materials.

◆ ReadOBJObject()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJObject ( )
private

Reads an Object definition.

Exceptions
ExceptionFailed to read a Object definition.

◆ ReadOBJSmoothingGroup()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJSmoothingGroup ( )
private

Reads a Smoothing Group definition.

Note
A smoothing group is, if present, silently ignored.
Exceptions
ExceptionFailed to read a Smoothing Group definition.

◆ ReadOBJVertex()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertex ( )
private

Reads a Vertex Position Coordinates definition.

Exceptions
ExceptionFailed to read a Vertex Position Coordinates definition.

◆ ReadOBJVertexCoordinates()

template<typename VertexT , typename IndexT >
const Point3 mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexCoordinates ( )
private

Reads a set of vertex position coordinates.

Returns
The Point3 represented by the next token of this OBJ reader (modified according to the mesh descriptor of this OBj reader).
Exceptions
ExceptionFailed to read a Point3.

◆ ReadOBJVertexIndices()

template<typename VertexT , typename IndexT >
const U32x3 mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexIndices ( )
private

Reads a set of vertex indices.

Returns
The vertex indices represented by the next token of this OBJ reader. A zero indicates the absence of a component.
Exceptions
ExceptionFailed to read the vertex indices.

◆ ReadOBJVertexNormal()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexNormal ( )
private

Reads a Vertex Normal Coordinates definition.

Precondition
All the vertex normals in the OBJ file are normalized.
Exceptions
ExceptionFailed to read a Vertex Normal Coordinates definition.

◆ ReadOBJVertexNormalCoordinates()

template<typename VertexT , typename IndexT >
const Normal3 mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexNormalCoordinates ( )
private

Reads a set of vertex normal coordinates.

Precondition
All the vertex normals in the OBJ file are normalized.
Returns
The Normal3 represented by the next token of this OBJ reader (modified according to the mesh descriptor of this OBj reader).
Exceptions
ExceptionFailed to read a Normal3.

◆ ReadOBJVertexTexture()

template<typename VertexT , typename IndexT >
void mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexTexture ( )
private

Reads a Vertex Texture Coordinates definition.

Note
Only UV texture coordinates are supported, The W component of UVW texture coordinates is, if present, silently ignored.
Exceptions
ExceptionFailed to read a Vertex Texture Coordinates definition.

◆ ReadOBJVertexTextureCoordinates()

template<typename VertexT , typename IndexT >
const UV mage::rendering::loader::OBJReader< VertexT, IndexT >::ReadOBJVertexTextureCoordinates ( )
private

Reads a set of vertex texture coordinates.

Returns
The UV represented by the next token of this OBJ reader (modified according to the mesh descriptor of this OBj reader).
Exceptions
ExceptionFailed to read a UV.

Member Data Documentation

◆ m_mapping

template<typename VertexT , typename IndexT >
std::map< U32x3, IndexT, OBJComparator > mage::rendering::loader::OBJReader< VertexT, IndexT >::m_mapping
private

A mapping between vertex position/texture/normal coordinates' indices and the index of a vertex in the vertex buffer (m_model_output) of this OBJ reader.

◆ m_mesh_desc

template<typename VertexT , typename IndexT >
const MeshDescriptor< VertexT, IndexT >& mage::rendering::loader::OBJReader< VertexT, IndexT >::m_mesh_desc
private

A reference to the mesh descriptor for this OBJ reader.

◆ m_model_output

template<typename VertexT , typename IndexT >
ModelOutput< VertexT, IndexT >& mage::rendering::loader::OBJReader< VertexT, IndexT >::m_model_output
private

A reference to a model output containing the read data of this OBJ reader.

◆ m_model_part

template<typename VertexT , typename IndexT >
ModelPart mage::rendering::loader::OBJReader< VertexT, IndexT >::m_model_part
private

The current model part of this OBJ reader.

◆ m_resource_manager

template<typename VertexT , typename IndexT >
ResourceManager& mage::rendering::loader::OBJReader< VertexT, IndexT >::m_resource_manager
private

A reference to the resource manager of this OBJ reader.

◆ m_vertex_coordinates

template<typename VertexT , typename IndexT >
std::vector< Point3 > mage::rendering::loader::OBJReader< VertexT, IndexT >::m_vertex_coordinates
private

A vector containing the read vertex position coordinates of this OBJ reader.

◆ m_vertex_normal_coordinates

template<typename VertexT , typename IndexT >
std::vector< Normal3 > mage::rendering::loader::OBJReader< VertexT, IndexT >::m_vertex_normal_coordinates
private

A vector containing the read normal texture coordinates of this OBJ reader.

◆ m_vertex_texture_coordinates

template<typename VertexT , typename IndexT >
std::vector< UV > mage::rendering::loader::OBJReader< VertexT, IndexT >::m_vertex_texture_coordinates
private

A vector containing the read vertex texture coordinates of this OBJ reader.