Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test cpp:
- FBox SelectionBox(FVector(0.f, -4000.f, 0.f), FVector(3000, 5000, 600.f));
- FVector BoxExtent = SelectionBox.GetExtent();
- FVector BoxCenter = SelectionBox.GetCenter();
- TArray<int32> InstancesDetected = George_GetInstancesOverlappingBox(ISM1, SelectionBox, ISM2->GetComponentTransform());
- for (int32 i = 0; i < InstancesDetected.Num(); ++i) {
- FTransform T3;
- BenchEnemy->HISM2->GetInstanceTransform(InstancesDetected[i], T3, true);
- DrawDebugSphere(GetWorld(), T3.GetLocation(), 100.f, 8, FColor::Yellow, false, 6.f, 0, 6.f);
- }
- //.h
- TArray<int32> George_GetInstancesOverlappingBox(UInstancedStaticMeshComponent* MeshComponent, FBox& Box, FTransform BoxTransform);
- //cpp
- TArray<int32> ABenchmark::George_GetInstancesOverlappingBox(UInstancedStaticMeshComponent* MeshComponent, FBox& Box, FTransform BoxTransform)
- {
- TArray<int32> Result;
- if (const UStaticMesh* Mesh = MeshComponent->GetStaticMesh())
- {
- const FVector StaticMeshBoundsExtent = Mesh->GetBounds().BoxExtent;
- for (int32 Index = 0; Index < MeshComponent->PerInstanceSMData.Num(); Index++)
- {
- const FMatrix& Matrix = MeshComponent->PerInstanceSMData[Index].Transform;
- const FVector InstanceOrigin = Matrix.GetOrigin();
- const FVector PositionInOrientedBoxSpace = BoxTransform.InverseTransformPosition(InstanceOrigin);
- if (Box.IsInside(PositionInOrientedBoxSpace))
- {
- Result.Add(Index);
- }
- }
- }
- return Result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement