Advertisement
LILCodeProgrammer

Untitled

Mar 11th, 2023
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TArray<int32> ABenchmark::M_CleanGetInstancesOverlappingBox(const FBox& InBox, bool bBoxInWorldSpace, UInstancedStaticMeshComponent* ISMToAnalyze, UInstancedStaticMeshComponent* ISMRef) const
  2. {
  3.     TArray<int32> Result;
  4.     if (UStaticMesh* Mesh = ISMRef->GetStaticMesh())
  5.     {
  6.         FBox Box(InBox);
  7.         if (bBoxInWorldSpace)
  8.         {
  9.             Box = Box.TransformBy(ISMRef->GetComponentTransform().Inverse());
  10.         }
  11.         FTransform ComponentTransform = ISMToAnalyze->GetComponentTransform();
  12.         const FVector StaticMeshBoundsExtent = Mesh->GetBounds().BoxExtent;
  13.         for (int32 Index = 0; Index < ISMToAnalyze->PerInstanceSMData.Num(); Index++)
  14.         {
  15.             const FMatrix& Matrix2 = ISMToAnalyze->PerInstanceSMData[Index].Transform;
  16.             FVector WorldPosition = ComponentTransform.TransformPosition(Matrix2.GetOrigin());
  17.  
  18.             FBox InstanceBox(WorldPosition - StaticMeshBoundsExtent, WorldPosition + StaticMeshBoundsExtent);
  19.             if (Box.Intersect(InstanceBox))
  20.             {
  21.                 Result.Add(Index);
  22.             }
  23.         }
  24.  
  25.     }
  26.     return Result;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement