I would like to see where an instanced static mesh bounding box ends to tile instances. They should be able to be tiled in a direction as well as have a transform. I’m currently using FMath::LineBoxIntersection() but adding rotation results in incorrect hit locations.
My code:
FVector GetTransformedMeshExtents(UStaticMesh* ISMMesh, const FTransform& MeshTransform, const FVector& OffsetDirection)
{
// Get mesh bounding box and transform
FBox TransformedBox = ISMMesh->GetBoundingBox().TransformBy(MeshTransform);
FVector TotalBoxExtent = TransformedBox.GetExtent() * 2.f;
// perform a line-box test from direction to box center
FVector HitLocation;
FVector HitNormal;
float HitTime;
FVector BoxSweepExtent = FVector::ZeroVector;
bool LineHit = false;
FVector LineEnd = TransformedBox.GetCenter();
FVector LineStart = OffsetDirection * TotalBoxExtent;
LineHit = FMath::LineExtentBoxIntersection(TransformedBox, LineStart, LineEnd, BoxSweepExtent, HitLocation, HitNormal, HitTime);
if (LineHit)
return HitLocation;
else
return FVector::ZeroVector;
}
This works perfectly without rotation, or with rotation in a straight line (OffsetDirection=(1,0,0):
result (perfect): Imgur: The magic of the Internet
Adding 45 yaw rotation simply increases extents giving me the wrong hit result (OffsetDirection=Normalized(1,1,0):
result (bad): Imgur: The magic of the Internet
Thanks in advance! This has been causing me a huge amount of frustration and I’m really hoping one of you brilliant people can point me in the right direction!