4 #include <ThirdParty/stb/stb_image.h> 11 if (scene->mNumMaterials <= materialIndex)
21 aiMaterial* material = scene->mMaterials[materialIndex];
39 aiMaterial* mat = scene->mMaterials[materialIndex];
40 aiColor3D color(0.f, 0.f, 0.f);
41 if (mat->Get(AI_MATKEY_COLOR_DIFFUSE, color) != AI_SUCCESS)
45 float transparency = 1.f;
46 if (mat->Get(AI_MATKEY_OPACITY, transparency) != AI_SUCCESS)
52 color = aiColor3D(0.f, 0.f, 0.f);
53 if (mat->Get(AI_MATKEY_COLOR_SPECULAR, color) != AI_SUCCESS)
60 if (mat->Get(AI_MATKEY_SHININESS, shiny) != AI_SUCCESS)
66 float specScale = 1.f;
67 if (mat->Get(AI_MATKEY_SHININESS_STRENGTH, specScale) != AI_SUCCESS)
107 else if (diffuseTexture ==
nullptr) {
158 else if (bumpMapTexture ==
nullptr) {
194 else if (specularTexture ==
nullptr) {
297 eastl::weak_ptr<Texture>
Material::LoadTexture(
const aiScene* scene, aiMaterial * material, aiTextureType textureType)
299 if (material->GetTextureCount(textureType) > 0) {
301 material->GetTexture(textureType, 0, &path);
303 if (path.data[0] ==
'*') {
305 eastl::string name =
modelName + eastl::string(path.C_Str());
308 GetResourceManager().lock()->GetTexture(name);
310 if (ret.expired() ==
false)
313 uint32_t index = atoi(path.C_Str() + 1);
314 if (index < scene->mNumTextures)
316 aiTexture* texture = scene->mTextures[index];
318 stbi_uc* textureData;
320 int width, height, channels;
322 if (texture->mHeight == 0)
324 char* data = (
char*)malloc(
sizeof(
char)*texture->mWidth);
325 memcpy(data, texture->pcData, texture->mWidth);
326 textureData = stbi_load_from_memory((stbi_uc*)data, texture->mWidth, &width, &height, &channels, 4);
330 textureData = (stbi_uc*)malloc(
sizeof(stbi_uc)*texture->mWidth*texture->mHeight * 4);
331 for (
size_t i = 0; i < texture->mWidth*texture->mHeight*4; i += 4)
333 textureData[i] = texture->pcData->r;
334 textureData[i + 1] = texture->pcData->g;
335 textureData[i + 2] = texture->pcData->b;
336 textureData[i + 3] = texture->pcData->a;
339 width = texture->mWidth;
340 height = texture->mHeight;
345 GetResourceManager().lock()->CreateTexture(name, textureData, width, height);
350 return eastl::shared_ptr<Texture>();
355 return Engine::GetEngine().lock()->GetResourceManager().lock()->CreateTexture(eastl::string(path.C_Str()));
360 return eastl::shared_ptr<Texture>();
MaterialData_t materialData_
void SetSpecularExponent(float exponent)
Sets the specular exponent of the material (shinyness).
virtual void SetDiffuseTexture(eastl::string diffuseTextureName)
Changes the diffuse texture of the material. NOTE: Texture will be loaded in, if it doesn't excist ye...
MaterialData_t defaultMaterialData_
virtual void SetSpecularColor(glm::vec3 specularColor)
Sets the material's specular color.
eastl::weak_ptr< Texture > missingTexture
float GetDefaultSpecularScale() const
Returns the scale of the specular highlights (strength) that was defined by the model this material w...
float GetDefaultSpecularExponent() const
Returns the specular exponent of the material that was defined by the model this material was created...
eastl::weak_ptr< Texture > GetDefaultBumpMapTexture() const
Returns the bump map texture that was defined by the model this material was created from...
virtual void SetSpecularTexture(eastl::shared_ptr< Texture > specularTexture)
Changes the specular texture of the material. Pass a nullptr to clear the current texture...
int32_t diffuseTextureLoaded
glm::vec3 GetDiffuseColor() const
Returns the material's diffuse color.
eastl::weak_ptr< Texture > defaultBumpMapTexture
int32_t specularTextureLoaded
eastl::weak_ptr< Texture > LoadTexture(const aiScene *scene, aiMaterial *material, aiTextureType textureType)
glm::vec3 GetDefaultSpecularColor() const
Returns the specular color that was defined by the model this material was created from...
eastl::weak_ptr< Texture > GetDefaultDiffuseTexture()
Returns the diffuse texture that was defined by the model this material was created from...
glm::vec3 GetDefaultDiffuseColor() const
Returns the diffuse color that was defined by the model this material was created from...
float GetSpecularScale() const
Returns the scale of the specular highlights (strength).
void SetSpecularScale(float scale)
Sets the scale of the specular highlights (strength) of the material.
glm::vec3 GetSpecularColor() const
Returns the material's specular color.
eastl::weak_ptr< Texture > diffuseTexture
eastl::weak_ptr< Texture > defaultSpecularTexture
eastl::weak_ptr< Texture > GetDefaultSpecularTexture() const
Returns the specular texture that was defined by the model this material was created from...
eastl::weak_ptr< Texture > bumpMapTexture
bool IsBumpMapLoaded() const
Indicates if the material has a bump map texture loaded or not.
bool IsSpecularLoaded() const
Indicates if the material has a specular texture loaded or not.
bool operator==(const Material &other) const
Returns whether or not two materials are the same.
static eastl::weak_ptr< Engine > GetEngine() noexcept
This method allows you to get the instance of the Engine. This method will automatically initialize t...
float GetSpecularExponent() const
Returns the specular exponent of the material.
eastl::weak_ptr< Texture > GetDiffuseTexture()
Returns the diffuse texture of the material. Returns nullptr if the current material doesn't have a d...
eastl::weak_ptr< Texture > defaultDiffuseTexture
eastl::weak_ptr< Texture > GetSpecularTexture() const
Returns the specular texture of the material. Returns nullptr if the current material doesn't have a ...
bool IsDiffuseLoaded() const
Indicates if the material has a diffuse texture loaded or not.
virtual void SetDiffuseColor(glm::vec3 diffuseColor)
Sets the material's diffuse color.
virtual void UpdateMaterialData()
eastl::weak_ptr< Texture > GetBumpMapTexture() const
Returns the bump map texture of the material. Returns nullptr if the current material doesn't have a ...
virtual void SetBumpMapTexture(eastl::string bumpMapTextureName)
Changes the bump map texture of the material. NOTE: Texture will be loaded in, if it doesn't excist y...
eastl::weak_ptr< Texture > specularTexture