From 8eada1e7e4ce4cf71b61571da018330790c99162 Mon Sep 17 00:00:00 2001 From: Ben1138 <8263806+Ben1138@users.noreply.github.com> Date: Sun, 13 Sep 2020 23:29:56 +0200 Subject: [PATCH] Removed GetGeometry for instances. Give access to Material texture names. --- LibSWBF2/Wrappers/Instance.cpp | 13 ++----------- LibSWBF2/Wrappers/Instance.h | 5 ++--- LibSWBF2/Wrappers/Material.cpp | 18 ++++++++++++++---- LibSWBF2/Wrappers/Material.h | 2 ++ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/LibSWBF2/Wrappers/Instance.cpp b/LibSWBF2/Wrappers/Instance.cpp index c5a467bc..661d4962 100755 --- a/LibSWBF2/Wrappers/Instance.cpp +++ b/LibSWBF2/Wrappers/Instance.cpp @@ -103,7 +103,8 @@ namespace LibSWBF2::Wrappers const EntityClass* entityClass = GetEntityClass(); if (entityClass == nullptr) { - LOG_WARN("Could not resolve Entity Class '{}' from instance '{}'", GetType(), GetName()); + // This can happen if the Entity Class is in another LVL (e.g. com_bldg_controlzone) + //LOG_WARN("Could not resolve Entity Class '{}' from instance '{}'", GetType(), GetName()); return false; } @@ -118,14 +119,4 @@ namespace LibSWBF2::Wrappers } return GetProperty(FNV::Hash(propertyName), outValue); } - - const Model* Instance::GetGeometry() const - { - String outGeometryName; - if (GetProperty("GeometryName", outGeometryName)) - { - return p_Parent->GetModel(outGeometryName); - } - return nullptr; - } } \ No newline at end of file diff --git a/LibSWBF2/Wrappers/Instance.h b/LibSWBF2/Wrappers/Instance.h index 3faf91ff..e6921b86 100755 --- a/LibSWBF2/Wrappers/Instance.h +++ b/LibSWBF2/Wrappers/Instance.h @@ -41,7 +41,6 @@ namespace LibSWBF2::Wrappers String GetName() const; Vector3 GetPosition() const; Vector4 GetRotation() const; - const EntityClass* GetEntityClass() const; // will fallback to entity class property, if existent bool GetProperty(FNVHash hashedPropertyName, String& outValue) const; @@ -49,7 +48,7 @@ namespace LibSWBF2::Wrappers // will fallback to entity class property, if existent bool GetProperty(const String& propertyName, String& outValue) const; - // will return 'nullptr' if no geometry has been specified - const Model* GetGeometry() const; + // will try to resolve within this Level + const EntityClass* GetEntityClass() const; }; } \ No newline at end of file diff --git a/LibSWBF2/Wrappers/Material.cpp b/LibSWBF2/Wrappers/Material.cpp index 6a4bba54..0b8ea17d 100755 --- a/LibSWBF2/Wrappers/Material.cpp +++ b/LibSWBF2/Wrappers/Material.cpp @@ -50,21 +50,31 @@ namespace LibSWBF2::Wrappers return p_Material->m_AttachedLight; } - const Texture* Material::GetTexture(uint8_t index) const + bool Material::GetTextureName(uint8_t index, String& outName) const { segm* segment = dynamic_cast(p_Material->GetParent()); if (segment == nullptr) { LOG_ERROR("Parent of MTRL is not segm!"); - return nullptr; + return false; } if (index >= segment->m_Textures.Size()) { LOG_WARN("Texture index '{}' is out of bounds ({})!", index, segment->m_Textures.Size()); - return nullptr; + return false; } + outName = segment->m_Textures[index]->m_Name; + return true; + } - return m_MainContainer->GetTexture(segment->m_Textures[index]->m_Name); + const Texture* Material::GetTexture(uint8_t index) const + { + String textureName; + if (GetTextureName(index, textureName)) + { + return m_MainContainer->GetTexture(textureName); + } + return nullptr; } } \ No newline at end of file diff --git a/LibSWBF2/Wrappers/Material.h b/LibSWBF2/Wrappers/Material.h index c17fd18c..3c85ea42 100755 --- a/LibSWBF2/Wrappers/Material.h +++ b/LibSWBF2/Wrappers/Material.h @@ -38,7 +38,9 @@ namespace LibSWBF2::Wrappers const Color& GetSpecularColor() const; uint32_t GetSpecularExponent() const; const String& GetAttachedLight() const; + bool GetTextureName(uint8_t index, String& outName) const; + // will try to resolve within this Level const Texture* GetTexture(uint8_t index) const; }; } \ No newline at end of file