Skip to content

Commit

Permalink
--set flag when a drawable is built using fallback material
Browse files Browse the repository at this point in the history
--this could indicate that the source asset lacks a material, or else that no materials were loaded by design (i.e. for depth sensor).
  • Loading branch information
jturner65 committed Feb 7, 2024
1 parent dba0c82 commit 3d776f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/esp/gfx/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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_
*/
Expand Down Expand Up @@ -253,6 +269,13 @@ class Drawable : public Magnum::SceneGraph::Drawable3D {

Corrade::Containers::Array<Magnum::Matrix4> 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:
Expand Down
6 changes: 6 additions & 0 deletions src/esp/gfx/GenericDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("isFallbackMaterial"));

// If not reset then make sure the same shader is used
if (!reset) {
flags_ = oldFlags;
Expand Down
4 changes: 4 additions & 0 deletions src/esp/gfx/PbrDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("isFallbackMaterial"));

// Skin support
(skinData_ != nullptr) ? flags_ |= PbrShader::Flag::SkinnedMesh
Expand Down

0 comments on commit 3d776f6

Please sign in to comment.