Skip to content

Commit

Permalink
Removed GetGeometry for instances. Give access to Material texture na…
Browse files Browse the repository at this point in the history
…mes.
  • Loading branch information
Ben1138 committed Sep 13, 2020
1 parent fb707a3 commit 8eada1e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
13 changes: 2 additions & 11 deletions LibSWBF2/Wrappers/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
5 changes: 2 additions & 3 deletions LibSWBF2/Wrappers/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ 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;

// 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;
};
}
18 changes: 14 additions & 4 deletions LibSWBF2/Wrappers/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<segm*>(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;
}
}
2 changes: 2 additions & 0 deletions LibSWBF2/Wrappers/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

0 comments on commit 8eada1e

Please sign in to comment.