ModelViewer 0.1
Template for CPP projects
Loading...
Searching...
No Matches
model_viewer::ModelManager Class Referencefinal

Class for managing model loading and providing geometry and material. More...

#include <ModelManager.hpp>

Inheritance diagram for model_viewer::ModelManager:
Collaboration diagram for model_viewer::ModelManager:

Signals

void geometryChanged ()
 Signal emitted when the geometry changes.
 
void materialChanged ()
 Signal emitted when the material changes.
 
void loadingChanged ()
 Signal emitted when the loading state changes.
 
void readyChanged ()
 Signal emitted when the ready state changes.
 

Public Member Functions

 ModelManager (QObject *parent=nullptr)
 Constructor.
 
 ~ModelManager () override=default
 Destructor.
 
QQuick3DGeometry * geometry () const
 Get the geometry of the loaded model.
 
material::MTLMaterialmaterial () const
 Get the material of the loaded model.
 
Q_INVOKABLE void loadModel (const QString &filepath)
 Load a model from a file asynchronously.
 
bool isLoading () const
 Check if a model is currently loading.
 
void setLoading (bool isLoading)
 Set the loading state, emits loadingChanged signal.
 
bool isReady () const
 Check if a model is ready.
 
void setReady (bool isReady)
 Set the ready state, emits readyChanged signal.
 
const std::unordered_map< std::string, loaders::ILoader * > & getLoaders () const
 

Properties

QQuick3DGeometry * geometry
 
model_viewer::material::MTLMaterialmaterial
 
bool loading
 
bool ready
 

Private Attributes

loaders::ObjLoader _objLoader
 OBJ loader instance.
 
std::unordered_map< std::string, loaders::ILoader * > _loaders
 Map of file extensions to their respective loaders.
 
loaders::ILoader_lastLoaded = &_objLoader
 Pointer to the last used loader.
 
std::unique_ptr< geometry::ObjGeometry_geometry
 Geometry of the currently loaded model.
 
bool _loading = false
 Boolean indicating if a model is currently loading.
 
bool _ready = false
 Boolean indicating if a model is ready.
 

Detailed Description

Class for managing model loading and providing geometry and material.

Constructor & Destructor Documentation

◆ ModelManager()

model_viewer::ModelManager::ModelManager ( QObject * parent = nullptr)
explicit

Constructor.

Parameters
parentParent QObject, nullptr by default
14 : QObject(parent) {
15 _loaders = {
16 {".obj", &_objLoader},
17 };
18}
loaders::ObjLoader _objLoader
OBJ loader instance.
Definition ModelManager.hpp:30
std::unordered_map< std::string, loaders::ILoader * > _loaders
Map of file extensions to their respective loaders.
Definition ModelManager.hpp:33

References _loaders, and _objLoader.

◆ ~ModelManager()

model_viewer::ModelManager::~ModelManager ( )
overridedefault

Destructor.

Member Function Documentation

◆ geometry()

QQuick3DGeometry * model_viewer::ModelManager::geometry ( ) const
inline

Get the geometry of the loaded model.

Returns
Geometry of the loaded model
74{ return _lastLoaded->geometry(); };
loaders::ILoader * _lastLoaded
Pointer to the last used loader.
Definition ModelManager.hpp:36
virtual QQuick3DGeometry * geometry() const =0
Get the geometry of the loaded model.

References _lastLoaded, and model_viewer::loaders::ILoader::geometry().

Here is the call graph for this function:

◆ geometryChanged

void model_viewer::ModelManager::geometryChanged ( )
signal

Signal emitted when the geometry changes.

Referenced by loadModel().

Here is the caller graph for this function:

◆ getLoaders()

const std::unordered_map< std::string, loaders::ILoader * > & model_viewer::ModelManager::getLoaders ( ) const
inline
115 {
116 return _loaders;
117 };

References _loaders.

◆ isLoading()

bool model_viewer::ModelManager::isLoading ( ) const
inline

Check if a model is currently loading.

Returns
True if a model is loading, false otherwise
94{ return _loading; };
bool _loading
Boolean indicating if a model is currently loading.
Definition ModelManager.hpp:42

References _loading.

Referenced by setLoading().

Here is the caller graph for this function:

◆ isReady()

bool model_viewer::ModelManager::isReady ( ) const
inline

Check if a model is ready.

Returns
True if a model is ready, false otherwise
106{ return _ready; };
bool _ready
Boolean indicating if a model is ready.
Definition ModelManager.hpp:45

References _ready.

Referenced by setReady().

Here is the caller graph for this function:

◆ loadingChanged

void model_viewer::ModelManager::loadingChanged ( )
signal

Signal emitted when the loading state changes.

Referenced by setLoading().

Here is the caller graph for this function:

◆ loadModel()

void model_viewer::ModelManager::loadModel ( const QString & filepath)

Load a model from a file asynchronously.

Emits geometryChanged and materialChanged signals upon completion and is invokable from QML

Parameters
filepathPath to the model file
20 {
21 const std::string strPath =
22 filepath.toStdString().substr(sizeof("file://") - 1);
23 const auto pos = strPath.find_last_of('.');
24 const std::string ext = strPath.substr(pos);
25
26 auto result = QtConcurrent::run([&, strPath, ext] {
27 setReady(false);
28 _loaders[ext]->loadModel(strPath);
29 emit geometryChanged();
30 emit materialChanged();
31 _lastLoaded = _loaders[ext];
32 setReady(true);
33 });
34}
void geometryChanged()
Signal emitted when the geometry changes.
void materialChanged()
Signal emitted when the material changes.
void setReady(bool isReady)
Set the ready state, emits readyChanged signal.
Definition ModelManager.cpp:41

References _lastLoaded, _loaders, geometryChanged(), materialChanged(), and setReady().

Here is the call graph for this function:

◆ material()

material::MTLMaterial * model_viewer::ModelManager::material ( ) const
inline

Get the material of the loaded model.

Returns
Material of the loaded model
80{ return _lastLoaded->material(); };
virtual material::MTLMaterial * material() const =0
Get the material of the loaded model.

References _lastLoaded, and model_viewer::loaders::ILoader::material().

Here is the call graph for this function:

◆ materialChanged

void model_viewer::ModelManager::materialChanged ( )
signal

Signal emitted when the material changes.

Referenced by loadModel().

Here is the caller graph for this function:

◆ readyChanged

void model_viewer::ModelManager::readyChanged ( )
signal

Signal emitted when the ready state changes.

Referenced by setReady().

Here is the caller graph for this function:

◆ setLoading()

void model_viewer::ModelManager::setLoading ( bool isLoading)

Set the loading state, emits loadingChanged signal.

Parameters
isLoadingNew loading state
36 {
38 emit loadingChanged();
39}
bool isLoading() const
Check if a model is currently loading.
Definition ModelManager.hpp:94
void loadingChanged()
Signal emitted when the loading state changes.

References _loading, isLoading(), and loadingChanged().

Referenced by setReady().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReady()

void model_viewer::ModelManager::setReady ( bool isReady)

Set the ready state, emits readyChanged signal.

Parameters
isReadyNew ready state
41 {
43 emit readyChanged();
45}
void setLoading(bool isLoading)
Set the loading state, emits loadingChanged signal.
Definition ModelManager.cpp:36
void readyChanged()
Signal emitted when the ready state changes.
bool isReady() const
Check if a model is ready.
Definition ModelManager.hpp:106

References _ready, isReady(), readyChanged(), and setLoading().

Referenced by loadModel().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _geometry

std::unique_ptr<geometry::ObjGeometry> model_viewer::ModelManager::_geometry
private

Geometry of the currently loaded model.

◆ _lastLoaded

loaders::ILoader* model_viewer::ModelManager::_lastLoaded = &_objLoader
private

Pointer to the last used loader.

Referenced by geometry(), loadModel(), and material().

◆ _loaders

std::unordered_map<std::string, loaders::ILoader *> model_viewer::ModelManager::_loaders
private

Map of file extensions to their respective loaders.

Referenced by getLoaders(), loadModel(), and ModelManager().

◆ _loading

bool model_viewer::ModelManager::_loading = false
private

Boolean indicating if a model is currently loading.

Referenced by isLoading(), and setLoading().

◆ _objLoader

loaders::ObjLoader model_viewer::ModelManager::_objLoader
private

OBJ loader instance.

Referenced by ModelManager().

◆ _ready

bool model_viewer::ModelManager::_ready = false
private

Boolean indicating if a model is ready.

Referenced by isReady(), and setReady().

Property Documentation

◆ geometry

QQuick3DGeometry * model_viewer::ModelManager::geometry
read

◆ loading

bool model_viewer::ModelManager::loading
read

◆ material

model_viewer::material::MTLMaterial * model_viewer::ModelManager::material
read

◆ ready

bool model_viewer::ModelManager::ready
read

The documentation for this class was generated from the following files: