gKit3
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Materials Struct Reference

#include <materials.h>

Public Member Functions

void clear ()
 
int insert (const Material &material, const char *name)
 ajoute une matiere.
 
int insert_texture (const char *filename)
 ajoute une texture / nom du fichier.
 
int find (const char *name)
 recherche une matiere avec son nom. renvoie son indice dans materials, ou -1.
 
int count () const
 nombre de matieres.
 
const char * name (const int id) const
 renvoie le nom de la ieme matiere.
 
const char * name (const int id)
 renvoie le nom de la ieme matiere.
 
const Materialmaterial (const int id) const
 renvoie la ieme matiere.
 
Materialmaterial (const int id)
 renvoie la ieme matiere.
 
const Materialoperator() (const int id) const
 renvoie la ieme matiere.
 
Materialoperator() (const int id)
 renvoie la ieme matiere.
 
const Materialmaterial (const char *name)
 renvoie la matiere 'name', si elle existe. ou la matiere par defaut.
 
const Materialdefault_material ()
 renvoie une matiere par defaut.
 
int default_material_index ()
 indice de la matiere par defaut dans le tableau materials.
 
int filename_count () const
 renvoie le nombre de noms de fichiers de textures.
 
const char * filename (const int id) const
 renvoie le nom de fichier d'une texture.
 
int find_texture (const char *filename)
 renvoie l'indice d'une texture, si elle existe.
 

Public Attributes

std::vector< std::string > names
 noms des matieres.
 
std::vector< Materialmaterials
 description des matieres.
 
std::vector< std::string > texture_filenames
 noms des textures a charger.
 
int default_material_id
 indice de la matiere par defaut dans materials.
 

Detailed Description

ensemble de matieres d'un Mesh. + ensemble de textures referencees par les descriptions de matieres.

names[id] est le nom de la matiere materials[id], utiliser name() et material() pour recuperer la description d'une matiere d'indice id.

les textures sont indexees separemment. chaque matiere reference une ou plusieurs textures, par exemple diffuse_texture et specular_texture. ces indices correspondent aux noms de fichiers (uniques) des images a charger : filename() renvoie le nom du fichier. filename( material.diffuse_texture ) renvoie le nom de l'image a charger qui correspond a la texture diffuse de la matiere.

pourquoi cette indexation supplementaire ? pour eviter de charger plusieurs fois une image / creer plusieurs fois une texture.

Definition at line 45 of file materials.h.

Constructor & Destructor Documentation

◆ Materials()

Materials::Materials ( )
inline

Definition at line 52 of file materials.h.

std::vector< std::string > names
noms des matieres.
Definition materials.h:47
std::vector< std::string > texture_filenames
noms des textures a charger.
Definition materials.h:49
int default_material_id
indice de la matiere par defaut dans materials.
Definition materials.h:50
std::vector< Material > materials
description des matieres.
Definition materials.h:48

Member Function Documentation

◆ clear()

void Materials::clear ( )
inline

Definition at line 54 of file materials.h.

55 {
56 names.clear();
57 materials.clear();
58 texture_filenames.clear();
60 }

◆ insert()

int Materials::insert ( const Material material,
const char *  name 
)
inline

ajoute une matiere.

Definition at line 63 of file materials.h.

64 {
65 int id= find(name);
66 if(id == -1)
67 {
68 id= int(materials.size());
69 names.push_back(name);
70 materials.push_back(material);
71 }
72 assert(materials.size() == names.size());
73 return id;
74 }
int find(const char *name)
recherche une matiere avec son nom. renvoie son indice dans materials, ou -1.
Definition materials.h:89
const Material & material(const int id) const
renvoie la ieme matiere.
Definition materials.h:111
const char * name(const int id) const
renvoie le nom de la ieme matiere.
Definition materials.h:106

◆ insert_texture()

int Materials::insert_texture ( const char *  filename)
inline

ajoute une texture / nom du fichier.

Definition at line 77 of file materials.h.

78 {
79 int id= find_texture(filename);
80 if(id == -1)
81 {
82 id= int(texture_filenames.size());
83 texture_filenames.push_back(filename);
84 }
85 return id;
86 }
int find_texture(const char *filename)
renvoie l'indice d'une texture, si elle existe.
Definition materials.h:153
const char * filename(const int id) const
renvoie le nom de fichier d'une texture.
Definition materials.h:150

◆ find()

int Materials::find ( const char *  name)
inline

recherche une matiere avec son nom. renvoie son indice dans materials, ou -1.

Definition at line 89 of file materials.h.

90 {
91 if(name == nullptr || name[0] == 0)
92 return -1;
93
94 for(int i= 0; i < int(names.size()); i++)
95 {
96 if(names[i] == name)
97 return i;
98 }
99 return -1;
100 }

◆ count()

int Materials::count ( ) const
inline

nombre de matieres.

Definition at line 103 of file materials.h.

103{ return int(materials.size()); }

◆ name() [1/2]

const char * Materials::name ( const int  id) const
inline

renvoie le nom de la ieme matiere.

Definition at line 106 of file materials.h.

106{ assert(id != -1); assert(id < int(materials.size())); return names[id].c_str(); }

◆ name() [2/2]

const char * Materials::name ( const int  id)
inline

renvoie le nom de la ieme matiere.

Definition at line 108 of file materials.h.

108{ assert(id != -1); assert(id < int(materials.size())); return names[id].c_str(); }

◆ material() [1/3]

const Material & Materials::material ( const int  id) const
inline

renvoie la ieme matiere.

Definition at line 111 of file materials.h.

111{ assert(id != -1); assert(id < int(materials.size())); return materials[id]; }

◆ material() [2/3]

Material & Materials::material ( const int  id)
inline

renvoie la ieme matiere.

Definition at line 113 of file materials.h.

113{ assert(id != -1); assert(id < int(materials.size())); return materials[id]; }

◆ operator()() [1/2]

const Material & Materials::operator() ( const int  id) const
inline

renvoie la ieme matiere.

Definition at line 116 of file materials.h.

116{ return material(id); }

◆ operator()() [2/2]

Material & Materials::operator() ( const int  id)
inline

renvoie la ieme matiere.

Definition at line 118 of file materials.h.

118{ return material(id); }

◆ material() [3/3]

const Material & Materials::material ( const char *  name)
inline

renvoie la matiere 'name', si elle existe. ou la matiere par defaut.

Definition at line 121 of file materials.h.

122 {
123 int id= find(name);
124 if(id != -1)
125 // renvoie la matiere
126 return materials[id];
127 else
128 // ou renvoie la matiere par defaut...
129 return default_material();
130 }
const Material & default_material()
renvoie une matiere par defaut.
Definition materials.h:133

◆ default_material()

const Material & Materials::default_material ( )
inline

renvoie une matiere par defaut.

Definition at line 133 of file materials.h.

134 {
136 }
int default_material_index()
indice de la matiere par defaut dans le tableau materials.
Definition materials.h:139

◆ default_material_index()

int Materials::default_material_index ( )
inline

indice de la matiere par defaut dans le tableau materials.

Definition at line 139 of file materials.h.

140 {
141 if(default_material_id == -1)
142 default_material_id= insert(Material(Color(0.8)), "default");
143
144 return default_material_id;
145 }
representation d'une couleur (rgba) transparente ou opaque.
Definition color.h:14
int insert(const Material &material, const char *name)
ajoute une matiere.
Definition materials.h:63

◆ filename_count()

int Materials::filename_count ( ) const
inline

renvoie le nombre de noms de fichiers de textures.

Definition at line 148 of file materials.h.

148{ return int(texture_filenames.size()); }

◆ filename()

const char * Materials::filename ( const int  id) const
inline

renvoie le nom de fichier d'une texture.

Definition at line 150 of file materials.h.

150{ if(id < 0) return nullptr; assert(id < int(texture_filenames.size())); return texture_filenames[id].c_str(); }

◆ find_texture()

int Materials::find_texture ( const char *  filename)
inline

renvoie l'indice d'une texture, si elle existe.

Definition at line 153 of file materials.h.

154 {
155 if(filename == nullptr || filename[0] == 0)
156 return -1;
157
158 for(int i= 0; i < int(texture_filenames.size()); i++)
159 {
161 return i;
162 }
163 return -1;
164 }

Member Data Documentation

◆ names

std::vector<std::string> Materials::names

noms des matieres.

Definition at line 47 of file materials.h.

◆ materials

std::vector<Material> Materials::materials

description des matieres.

Definition at line 48 of file materials.h.

◆ texture_filenames

std::vector<std::string> Materials::texture_filenames

noms des textures a charger.

Definition at line 49 of file materials.h.

◆ default_material_id

int Materials::default_material_id

indice de la matiere par defaut dans materials.

Definition at line 50 of file materials.h.


The documentation for this struct was generated from the following file: