Screen size of a mesh

Anyone coming from the future: screen size is calculated by ComputeBoundsScreenSize() in SceneManagement.cpp. It’s not defined in the .h so you’ll have to copy-paste it into your game code:


float ComputeBoundsScreenSize(const FVector4& BoundsOrigin, const float SphereRadius, const FVector4& ViewOrigin, const FMatrix& ProjMatrix)
{
const float Dist = FVector::Dist(BoundsOrigin, ViewOrigin);

// Get projection multiple accounting for view scaling.
const float ScreenMultiple = FMath::Max(0.5f * ProjMatrix.M[0][0], 0.5f * ProjMatrix.M[1][1]);

// Calculate screen-space projected radius
const float ScreenRadius = ScreenMultiple * SphereRadius / FMath::Max(1.0f, Dist);

// For clarity, we end up comparing the diameter
return ScreenRadius * 2.0f;
}

4 Likes