Return the merged result of all generated trigger boxes as the bounding box of the actor
This commit is contained in:
parent
9bb8f41f3e
commit
e032ae53ad
|
@ -23,11 +23,12 @@ TArray<UBoxComponent*> ATrafficSignBase::GetTriggerVolumes() const
|
|||
GetComponents<USignComponent>(Components, false);
|
||||
if (Components.Num())
|
||||
{
|
||||
USignComponent* SignComponent = Components.Top();
|
||||
USignComponent* SignComponent = Components[0];
|
||||
return SignComponent->GetEffectTriggerVolume();
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogCarla, Log, TEXT("returning GetTriggerVolume"));
|
||||
TArray<UBoxComponent*> TriggerVolumes;
|
||||
TriggerVolumes.Add(GetTriggerVolume());
|
||||
return TriggerVolumes;
|
||||
|
|
|
@ -74,6 +74,16 @@ FBoundingBox UBoundingBoxCalculator::GetActorBoundingBox(const AActor *Actor, ui
|
|||
auto TrafficSign = Cast<ATrafficSignBase>(Actor);
|
||||
if (TrafficSign != nullptr)
|
||||
{
|
||||
// first return a merge of the generated trigger boxes, if any
|
||||
auto TriggerVolumes = TrafficSign->GetTriggerVolumes();
|
||||
if (TriggerVolumes.Num() > 0)
|
||||
{
|
||||
FBoundingBox Box = UBoundingBoxCalculator::CombineBoxes(TriggerVolumes);
|
||||
FTransform Transform = Actor->GetTransform();
|
||||
Box.Rotation = Transform.InverseTransformRotation(Box.Rotation.Quaternion()).Rotator();
|
||||
return Box;
|
||||
}
|
||||
// try to return the original bounding box
|
||||
auto TriggerVolume = TrafficSign->GetTriggerVolume();
|
||||
if (TriggerVolume != nullptr)
|
||||
{
|
||||
|
@ -610,6 +620,43 @@ FBoundingBox UBoundingBoxCalculator::CombineBBs(const TArray<FBoundingBox>& BBsT
|
|||
return {Origin, Extent};
|
||||
}
|
||||
|
||||
FBoundingBox UBoundingBoxCalculator::CombineBoxes(const TArray<UBoxComponent *>& BBsToCombine)
|
||||
{
|
||||
FVector MaxVertex(TNumericLimits<float>::Lowest());
|
||||
FVector MinVertex(TNumericLimits<float>::Max());
|
||||
|
||||
for(const UBoxComponent *BB : BBsToCombine) {
|
||||
auto BoxOrigin = BB->GetComponentLocation();
|
||||
auto BoxExtent = BB->GetScaledBoxExtent();
|
||||
|
||||
FVector MaxVertexOfBB = BoxOrigin + BoxExtent;
|
||||
FVector MinVertexOfBB = BoxOrigin - BoxExtent;
|
||||
|
||||
MaxVertex.X = (MaxVertexOfBB.X > MaxVertex.X) ? MaxVertexOfBB.X : MaxVertex.X;
|
||||
MaxVertex.Y = (MaxVertexOfBB.Y > MaxVertex.Y) ? MaxVertexOfBB.Y : MaxVertex.Y;
|
||||
MaxVertex.Z = (MaxVertexOfBB.Z > MaxVertex.Z) ? MaxVertexOfBB.Z : MaxVertex.Z;
|
||||
MinVertex.X = (MinVertexOfBB.X < MinVertex.X) ? MinVertexOfBB.X : MinVertex.X;
|
||||
MinVertex.Y = (MinVertexOfBB.Y < MinVertex.Y) ? MinVertexOfBB.Y : MinVertex.Y;
|
||||
MinVertex.Z = (MinVertexOfBB.Z < MinVertex.Z) ? MinVertexOfBB.Z : MinVertex.Z;
|
||||
}
|
||||
|
||||
// Calculate box extent
|
||||
FVector Extent (
|
||||
(MaxVertex.X - MinVertex.X) * 0.5f,
|
||||
(MaxVertex.Y - MinVertex.Y) * 0.5f,
|
||||
(MaxVertex.Z - MinVertex.Z) * 0.5f
|
||||
);
|
||||
|
||||
// Calculate middle point
|
||||
FVector Origin (
|
||||
(MinVertex.X + Extent.X),
|
||||
(MinVertex.Y + Extent.Y),
|
||||
(MinVertex.Z + Extent.Z)
|
||||
);
|
||||
|
||||
return {Origin, Extent};
|
||||
}
|
||||
|
||||
void UBoundingBoxCalculator::GetMeshCompsFromActorBoundingBox(
|
||||
const AActor* Actor,
|
||||
const FBoundingBox& InBB,
|
||||
|
|
|
@ -99,6 +99,9 @@ public:
|
|||
UFUNCTION(Category = "Carla Util", BlueprintCallable)
|
||||
static FBoundingBox CombineBBs(const TArray<FBoundingBox>& BBsToCombine);
|
||||
|
||||
UFUNCTION(Category = "Carla Util", BlueprintCallable)
|
||||
static FBoundingBox CombineBoxes(const TArray<UBoxComponent *>& BBsToCombine);
|
||||
|
||||
// Returns Static Mesh Components that generate the InBB of the Actor
|
||||
// ie: the SMComps that creates the BB of the TL light box
|
||||
UFUNCTION(Category = "Carla Actor", BlueprintCallable)
|
||||
|
|
Loading…
Reference in New Issue