-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
73 lines (59 loc) · 1.76 KB
/
Material.cpp
File metadata and controls
73 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "precomp.h"
#include "Material.h"
#include "AssetManager.h"
#include "Texture.h"
Framework::Material::Material(const std::string& materialName) :
mName(materialName)
{
}
Framework::Material::~Material() = default;
void Framework::Material::LoadFrom(const aiMaterial* aiMaterial, const std::string& texturesDirectory)
{
mDiffuse = LoadTexture(aiMaterial, aiTextureType::aiTextureType_DIFFUSE, texturesDirectory);
mHasBeenLoaded = true;
}
void Framework::Material::LoadWithoutAssimp()
{
objl::Loader loader{};
bool succes = loader.LoadMaterials(mName);
if (!succes)
{
LOGERROR("Failed to load material " << mName);
assert(false);
}
const objl::Material& material = loader.LoadedMaterials[0];
AssetManager& assetManager = AssetManager::Inst();
//if (!material.map_Ka.empty())
//{
// mAmbient = assetManager.GetAsset<Texture>(material.map_Ka);
//}
if (!material.map_Kd.empty())
{
mDiffuse = assetManager.GetAsset<Texture>(material.map_Kd);
}
//if (!material.map_Ks.empty())
//{
// mSpecular = assetManager.GetAsset<Texture>(material.map_Ks);
//}
//if (!material.map_bump.empty())
//{
// mNormal = assetManager.GetAsset<Texture>(material.map_bump);
//}
if (!material.map_d.empty())
{
mAlpha = assetManager.GetAsset<Texture>(material.map_d);
}
mHasBeenLoaded = true;
}
std::shared_ptr<Framework::Texture> Framework::Material::LoadTexture(const aiMaterial* aiMaterial, aiTextureType textureType, const std::string& texturesDirectory)
{
size_t numOfTextures = aiMaterial->GetTextureCount(textureType);
if (numOfTextures == 0)
{
return nullptr;
}
assert(numOfTextures == 1);
aiString relativePath;
aiMaterial->GetTexture(textureType, 0, &relativePath);
return AssetManager::Inst().GetAsset<Texture>(texturesDirectory + relativePath.C_Str());
}