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