Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
model_material.cpp
Go to the documentation of this file.
1#include "model_material.hpp"
2#include "assimp/scene.h"
3
4namespace rendering_engine
5{
6const std::map<TextureType, uint32_t> ModelMaterial::sTextureTypeMappings =
7{
8 { TextureType::Difffuse, aiTextureType_DIFFUSE },
9 { TextureType::SpecularMap, aiTextureType_SPECULAR },
10 { TextureType::Ambient, aiTextureType_AMBIENT },
11 { TextureType::Emissive, aiTextureType_EMISSIVE },
12 { TextureType::Difffuse, aiTextureType_DIFFUSE },
13 { TextureType::Heightmap, aiTextureType_HEIGHT },
14 { TextureType::NormalMap, aiTextureType_NORMALS },
15 { TextureType::SpecularPowerMap, aiTextureType_SHININESS },
16 { TextureType::DisplacementMap, aiTextureType_DISPLACEMENT },
17 { TextureType::LightMap, aiTextureType_LIGHTMAP },
18};
19
21 :
22 mModel(&model)
23{
24}
25
27{
28 return *mModel;
29}
30
31const std::string& ModelMaterial::Name() const
32{
33 return mName;
34}
35
36const std::map<TextureType, std::vector<std::string>> ModelMaterial::Textures() const
37{
38 return mTextures;
39}
40
41ModelMaterial::ModelMaterial(Model& model, aiMaterial& material)
42 :
43 mModel(&model)
44{
45 aiString name;
46 material.Get(AI_MATKEY_NAME, name);
47 mName = name.C_Str();
48
49 for( TextureType textureType : Enum<TextureType>() )
50 {
51 aiTextureType mappedTextureType = static_cast<aiTextureType>(sTextureTypeMappings.at(textureType));
52
53 uint32_t textureCount = material.GetTextureCount(mappedTextureType);
54 if( textureCount > 0 )
55 {
56 std::vector<std::string> textures;
57 textures.reserve(textureCount);
58 for( uint32_t textureIndex = 0; textureIndex < textureCount; textureIndex++ )
59 {
60 aiString path;
61 if( material.GetTexture(mappedTextureType, textureIndex, &path) == AI_SUCCESS )
62 {
63 textures.push_back(path.C_Str());
64 }
65 }
66 mTextures.emplace(textureType, move(textures));
67 }
68 }
69}
70
71}// namespace rendering_engine
const std::string & Name() const
Gets the material name as defined in the source file.
const std::map< TextureType, std::vector< std::string > > Textures() const
Retrieves the list of textures associated with each texture type.
ModelMaterial(Model &model)
Constructs an empty material associated with a model.
Model & GetModel()
Returns a reference to the owning Model.
Represents a 3D model composed of multiple meshes and materials.
Definition: model.hpp:30
TextureType
Enumerates supported texture map types for imported materials.