diff --git a/src/esp/assets/ResourceManager.cpp b/src/esp/assets/ResourceManager.cpp index f0ad6df3fd..2ea8319173 100644 --- a/src/esp/assets/ResourceManager.cpp +++ b/src/esp/assets/ResourceManager.cpp @@ -2138,7 +2138,8 @@ Mn::Trade::MaterialData ResourceManager::setMaterialDefaultUserAttributes( ObjectInstanceShaderType shaderTypeToUse, bool hasVertObjID, bool hasTxtrObjID, - int txtrIdx) const { + int txtrIdx, + bool isFallback) const { // New material's attributes Cr::Containers::Array newAttributes; arrayAppend(newAttributes, Cr::InPlaceInit, "hasPerVertexObjectId", @@ -2150,6 +2151,8 @@ Mn::Trade::MaterialData ResourceManager::setMaterialDefaultUserAttributes( arrayAppend(newAttributes, Cr::InPlaceInit, "shaderTypeToUse", static_cast(shaderTypeToUse)); + arrayAppend(newAttributes, Cr::InPlaceInit, "isFallbackMaterial", isFallback); + Cr::Containers::Optional finalMaterial = Mn::MaterialTools::merge( material, Mn::Trade::MaterialData{{}, std::move(newAttributes), {}}); @@ -2250,9 +2253,20 @@ void ResourceManager::initDefaultMaterials() { // Build default material for fallback material Mn::Trade::MaterialData fallbackMaterial = buildDefaultMaterial(); - // Set expected user-defined attributes + // Make fallback magenta so visibly obvious + fallbackMaterial.mutableAttribute( + Mn::Trade::MaterialAttribute::AmbientColor) = + Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f}; + fallbackMaterial.mutableAttribute( + Mn::Trade::MaterialAttribute::DiffuseColor) = + Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f}; + fallbackMaterial.mutableAttribute( + Mn::Trade::MaterialAttribute::SpecularColor) = + Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f}; + // Set expected user-defined attributes - specify Flat shader to use since + // this indicates that the asset did not load a material for some reason. fallbackMaterial = setMaterialDefaultUserAttributes( - fallbackMaterial, ObjectInstanceShaderType::Flat); + fallbackMaterial, ObjectInstanceShaderType::Flat, false, false, -1, true); // Add to shaderManager as fallback material shaderManager_.setFallback( std::move(fallbackMaterial)); diff --git a/src/esp/assets/ResourceManager.h b/src/esp/assets/ResourceManager.h index f79ed15f67..b1f284522e 100644 --- a/src/esp/assets/ResourceManager.h +++ b/src/esp/assets/ResourceManager.h @@ -751,6 +751,8 @@ class ResourceManager { * ids for semantics. * @param txtrIdx The absolute index in the @ref textures_ store for the semantic * annotation texture. + * @param isFallback This material is default fallback material for missing + * materials. * @return the updated material */ Mn::Trade::MaterialData setMaterialDefaultUserAttributes( @@ -758,7 +760,8 @@ class ResourceManager { ObjectInstanceShaderType shaderTypeToUse, bool hasVertObjID = false, bool hasTxtrObjID = false, - int txtrIdx = -1) const; + int txtrIdx = -1, + bool isFallback = false) const; /** * @brief Configure the importerManager_ GL Extensions appropriately based on diff --git a/src/esp/gfx/Drawable.h b/src/esp/gfx/Drawable.h index 92d57741d9..296e092fcd 100644 --- a/src/esp/gfx/Drawable.h +++ b/src/esp/gfx/Drawable.h @@ -157,6 +157,13 @@ class Drawable : public Magnum::SceneGraph::Drawable3D { setMaterialValuesInternal(material, true); } + /** + * @brief Whether this drawable has a specified material or was assigned the + * default fallback material, meaning the material for the object was either + * not loaded or is otherwise missing. + */ + bool getUsesFallbackMaterial() const { return usingFallbackMaterial_; } + private: /** * Set or change this drawable's @ref Magnum::Trade::MaterialData values from passed material. @@ -171,6 +178,15 @@ class Drawable : public Magnum::SceneGraph::Drawable3D { CORRADE_UNUSED bool reset) {} protected: + /** + * @brief Whether this drawable has a specified material or was assigned the + * default fallback material, meaning the material for the object was either + * not loaded or is otherwise missing. + */ + void setUsesFallbackMaterial(bool _usingFallbackMaterial) { + usingFallbackMaterial_ = _usingFallbackMaterial; + } + /** * @brief resize the jointTransformArray_ */ @@ -253,6 +269,13 @@ class Drawable : public Magnum::SceneGraph::Drawable3D { Corrade::Containers::Array jointTransformations_; + /** + * @brief Whether or not this drawable is being rendered using the default + * fallback material, which implies either that materials were not loaded, or + * else no material existed for the source asset to load. + */ + bool usingFallbackMaterial_ = false; + bool glMeshExists() const { return mesh_ != nullptr; } private: diff --git a/src/esp/gfx/GenericDrawable.cpp b/src/esp/gfx/GenericDrawable.cpp index 4c00821d7b..59991964c8 100644 --- a/src/esp/gfx/GenericDrawable.cpp +++ b/src/esp/gfx/GenericDrawable.cpp @@ -120,6 +120,12 @@ void GenericDrawable::setMaterialValuesInternal( if (meshAttributeFlags_ & Drawable::Flag::HasVertexColor) { flags_ |= Mn::Shaders::PhongGL::Flag::VertexColor; } + + // Set whether this drawable is being rendered using a fallback material; This + // would infer that either materials were not loaded or no materials were + // found for the source asset + setUsesFallbackMaterial(materialData->attribute("isFallbackMaterial")); + // If not reset then make sure the same shader is used if (!reset) { flags_ = oldFlags; diff --git a/src/esp/gfx/PbrDrawable.cpp b/src/esp/gfx/PbrDrawable.cpp index f6222ec40d..2c13a13d11 100644 --- a/src/esp/gfx/PbrDrawable.cpp +++ b/src/esp/gfx/PbrDrawable.cpp @@ -332,6 +332,10 @@ void PbrDrawable::setMaterialValuesInternal( if (meshAttributeFlags_ & Drawable::Flag::HasVertexColor) { flags_ |= PbrShader::Flag::VertexColor; } + // Set whether this drawable is being rendered using a fallback material; This + // would infer that either materials were not loaded or no materials were + // found for the source asset + setUsesFallbackMaterial(materialData->attribute("isFallbackMaterial")); // Skin support (skinData_ != nullptr) ? flags_ |= PbrShader::Flag::SkinnedMesh