23#ifndef VCL_MESH_COMPONENTS_MATERIALS_H
24#define VCL_MESH_COMPONENTS_MATERIALS_H
26#include "base/component.h"
28#include <vclib/space/core.h>
39 std::vector<Material> materials;
41 std::map<std::string, Image> textureImages;
70 using Base = Component<
78 inline static const Image EMPTY_IMAGE;
94 std::map<std::string, Image>::const_iterator;
122 const std::string&
meshBasePath()
const {
return Base::data().meshPath; }
158 if (
it == txtImgs().end()) {
255 return txtImgs().begin();
265 return txtImgs().end();
350 template<
typename Element>
351 void importFrom(
const Element& e,
bool =
true);
353 void serialize(std::ostream&
os)
const
356 vcl::serialize(
os, mats());
357 vcl::serialize(
os, txtImgs());
360 void deserialize(std::istream& is)
363 vcl::deserialize(is, mats());
364 vcl::deserialize(is, txtImgs());
369 std::vector<Material>& mats() {
return Base::data().materials; }
371 const std::vector<Material>& mats()
const {
return Base::data().materials; }
373 std::map<std::string, Image>& txtImgs()
375 return Base::data().textureImages;
378 const std::map<std::string, Image>& txtImgs()
const
380 return Base::data().textureImages;
398concept HasMaterials = std::derived_from<std::remove_cvref_t<T>, Materials>;
402template<
typename Element>
403void Materials::importFrom(
const Element& e,
bool)
408 for (
const auto& mat : e.materials()) {
409 mats().push_back(mat);
411 for (
const auto& [path, img] : e.textureImages()) {
412 txtImgs()[path] = img;
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
A class for representing and manipulating 2D images.
Definition image.h:48
Represents a Physically-Based Rendering (PBR) material.
Definition material.h:45
The View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
A component that manages materials and textures for a mesh.
Definition materials.h:69
View< ConstMaterialIterator > materials() const
Returns a lightweight const view object that stores the begin and end iterators of the vector of mate...
Definition materials.h:303
View< ConstTextureImageIterator > textureImages() const
Returns a lightweight const view object that stores the begin and end iterators of the map of texture...
Definition materials.h:343
std::map< std::string, Image >::const_iterator ConstTextureImageIterator
Const iterator for the map of texture images.
Definition materials.h:94
ConstMaterialIterator materialEnd() const
Returns a const iterator to the end of the vector of materials.
Definition materials.h:233
std::string & meshBasePath()
Returns a reference to the mesh base path.
Definition materials.h:128
void pushTextureImage(const std::string &texturePath, const Image &img)
Adds a texture image to the map of texture images.
Definition materials.h:191
std::vector< Material >::iterator MaterialIterator
Iterator for the vector of materials.
Definition materials.h:87
MaterialIterator materialBegin()
Returns an iterator to the beginning of the vector of materials.
Definition materials.h:214
const Material & material(uint i) const
Returns the material at the specified index.
Definition materials.h:135
uint textureImagesNumber() const
Returns the number of texture images stored in the component.
Definition materials.h:113
Material & material(uint i)
Returns a mutable reference to the material at the specified index.
Definition materials.h:143
void pushTextureImage(const std::string &texturePath, Image &&img)
Adds a texture image to the map of texture images (move version).
Definition materials.h:205
std::vector< Material >::const_iterator ConstMaterialIterator
Const iterator for the vector of materials.
Definition materials.h:89
std::map< std::string, Image >::iterator TextureImageIterator
Iterator for the map of texture images.
Definition materials.h:91
ConstMaterialIterator materialBegin() const
Returns a const iterator to the beginning of the vector of materials.
Definition materials.h:227
const std::string & meshBasePath() const
Returns the mesh base path.
Definition materials.h:122
View< TextureImageIterator > textureImages()
Returns a lightweight view object that stores the begin and end iterators of the map of texture image...
Definition materials.h:323
void clearMaterials()
Clears the vector of materials.
Definition materials.h:170
const Image & textureImage(const std::string &texturePath) const
Returns the texture image associated to the given texture path.
Definition materials.h:155
ConstTextureImageIterator textureImageEnd() const
Returns a const iterator to the end of the map of texture images.
Definition materials.h:263
TextureImageIterator textureImageBegin()
Returns an iterator to the beginning of the map of texture images.
Definition materials.h:240
View< MaterialIterator > materials()
Returns a lightweight view object that stores the begin and end iterators of the vector of materials....
Definition materials.h:283
Materials()=default
Default constructor for the Materials component.
TextureImageIterator textureImageEnd()
Returns an iterator to the end of the map of texture images.
Definition materials.h:246
uint materialsNumber() const
Returns the number of materials of the mesh.
Definition materials.h:107
MaterialIterator materialEnd()
Returns an iterator to the end of the vector of materials.
Definition materials.h:220
void pushMaterial(const Material &mat)
Adds a material to the vector of materials.
Definition materials.h:180
ConstTextureImageIterator textureImageBegin() const
Returns a const iterator to the beginning of the map of texture images.
Definition materials.h:253
A concept that checks whether a type T (that should be a Mesh) has the Materials component (inherits ...
Definition materials.h:398