From a3ee7fa566677fd08ed811f1284da184c760e10d Mon Sep 17 00:00:00 2001 From: John Turner <7strbass@gmail.com> Date: Tue, 14 Nov 2023 09:57:21 -0500 Subject: [PATCH] --set flag when a drawable is built using fallback material --this could indicate that the source asset lacks a material, or else that no materials were loaded by design (i.e. for depth sensor). --- src/esp/gfx/Drawable.h | 23 +++++++++++++++++++++++ src/esp/gfx/GenericDrawable.cpp | 6 ++++++ src/esp/gfx/PbrDrawable.cpp | 4 ++++ 3 files changed, 33 insertions(+) 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