Skip to content

Commit

Permalink
[animation] MaterialProperty::WorldSpaceHeight is now calculated with…
Browse files Browse the repository at this point in the history
… maximum precision instead of relying on the bounding box y
  • Loading branch information
PanosK92 committed Jan 17, 2025
1 parent c808533 commit 9ecf2a4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions runtime/World/Components/Renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,27 @@ namespace spartan
m_mesh = nullptr;
}

void Renderable::OnStart()
void Renderable::OnStart()
{
if (Material* material = GetMaterial())
{
material->SetProperty(MaterialProperty::WorldSpaceHeight, GetBoundingBox(BoundingBoxType::Transformed).GetSize().y);
if (material->GetProperty(MaterialProperty::WorldSpaceHeight) == 0.0f)
{
vector<RHI_Vertex_PosTexNorTan> vertices;
GetGeometry(nullptr, &vertices);

float min_height = FLT_MAX;
float max_height = -FLT_MAX;
for (const RHI_Vertex_PosTexNorTan& vertex : vertices)
{
Vector3 position = Vector3(vertex.pos[0], vertex.pos[1], vertex.pos[2]) * GetEntity()->GetMatrix();

if (position.y < min_height) min_height = position.y;
if (position.y > max_height) max_height = position.y;
}

material->SetProperty(MaterialProperty::WorldSpaceHeight, max_height - min_height);
}
}
}

Expand Down

0 comments on commit 9ecf2a4

Please sign in to comment.