45 auto Vehicle = Cast<ACarlaWheeledVehicle>(Actor);
48 FVector Origin =
Vehicle->GetVehicleBoundingBoxTransform().GetTranslation();
49 FVector Extent =
Vehicle->GetVehicleBoundingBoxExtent();
50 return {Origin, Extent};
56 UActorComponent *ActorComp =
Character->GetComponentByClass(USkeletalMeshComponent::StaticClass());
57 USkeletalMeshComponent* ParentComp = Cast<USkeletalMeshComponent>(ActorComp);
59 if (ParentComp !=
nullptr)
69 const FTransform &MeshRelative = ParentComp->GetRelativeTransform();
72 if (
Character->GetName().Contains(
"_AB001_G3")
73 ||
Character->GetName().Contains(
"_AG001_G3"))
76 Box.Origin.Z -= Box.Extent.Z * (1.0f / 0.65f - 1.0f);
82 auto WalkerBase = Cast<AWalkerBase>(
Character);
83 if (WalkerBase && WalkerBase->bUsesWheelChair)
85 Box.Origin.X += 15.0f;
86 Box.Origin.Z -= 15.0f;
96 auto TrafficSign = Cast<ATrafficSignBase>(Actor);
97 if (TrafficSign !=
nullptr)
102 auto TriggerVolumes = TrafficSign->GetTriggerVolumes();
106 UBoxComponent* FirstTriggerVolume =
nullptr;
107 for (UBoxComponent* Volume : TriggerVolumes)
109 if (Volume !=
nullptr)
111 FirstTriggerVolume = Volume;
115 if (FirstTriggerVolume !=
nullptr)
117 FTransform Transform = Actor->GetActorTransform();
120 TVWorld.
Origin = FirstTriggerVolume->GetComponentLocation();
121 TVWorld.
Extent = FirstTriggerVolume->GetScaledBoxExtent();
122 TVWorld.
Rotation = FirstTriggerVolume->GetComponentRotation();
125 TVLocal.
Origin = Transform.InverseTransformPosition(TVWorld.
Origin);
127 TVLocal.
Rotation = Transform.InverseTransformRotation(TVWorld.
Rotation.Quaternion()).Rotator();
138 Transform.GetTranslation(),
140 Transform.GetRotation().Rotator()
145 UE_LOG(LogCarla, Warning, TEXT(
"Traffic sign missing trigger volume: %s"), *Actor->GetName());
153 FTransform Transform = Actor->GetActorTransform();
154 BB.
Origin = Transform.InverseTransformPosition(BB.
Origin);
155 BB.
Rotation = Transform.InverseTransformRotation(BB.
Rotation.Quaternion()).Rotator();
156 BB.
Rotation = Transform.GetRotation().Rotator();
170 bool FilterByTagEnabled = (TagQueried != crp::CityObjectLabel::Any);
172 UActorComponent *ActorComp =
Vehicle->GetComponentByClass(USkeletalMeshComponent::StaticClass());
173 USkeletalMeshComponent* ParentComp = Cast<USkeletalMeshComponent>(ActorComp);
177 if(FilterByTagEnabled && Tag != TagQueried)
return {};
179 USkeletalMesh* SkeletalMesh = ParentComp->GetSkeletalMeshAsset();
184 UE_LOG(LogCarla, Error, TEXT(
"%s has no SKM assigned"), *
Vehicle->GetName());
189 TArray<USkeletalMeshComponent*> SkeletalMeshComps;
190 Vehicle->GetComponents<USkeletalMeshComponent>(SkeletalMeshComps);
192 if(SkeletalMeshComps.Num() > 1)
194 FVector VehicleLocation =
Vehicle->GetActorLocation();
195 FRotator VehicleRotation =
Vehicle->GetActorRotation();
196 float MaxHeadLocation = TNumericLimits<float>::Lowest();
197 float MaxKneeLocation = TNumericLimits<float>::Lowest();
198 bool SocketFound =
false;
199 for(USkeletalMeshComponent* Comp : SkeletalMeshComps)
201 if(Comp == ParentComp)
continue;
204 FVector HeadLocation = Comp->GetSocketLocation(
"crl_Head__C") - VehicleLocation;
205 FVector KneeLocation = Comp->GetSocketLocation(
"crl_leg__L") - VehicleLocation;
207 HeadLocation = VehicleRotation.UnrotateVector(HeadLocation);
208 KneeLocation = VehicleRotation.UnrotateVector(KneeLocation);
210 MaxHeadLocation = (HeadLocation.Z > MaxHeadLocation) ? HeadLocation.Z : MaxHeadLocation;
211 MaxKneeLocation = (KneeLocation.Y > MaxKneeLocation) ? KneeLocation.Y : MaxKneeLocation;
221 Min = Min.ComponentMin(Max);
222 Max = Max.ComponentMin(Tmp);
224 MaxHeadLocation += 20.0f;
226 Max.Y = (MaxKneeLocation > Max.Y) ? MaxKneeLocation : Max.Y;
227 Min.Y = (-MaxKneeLocation < Min.Y) ? MaxKneeLocation : Min.Y;
228 Max.Z = (MaxHeadLocation > Max.Z) ? MaxHeadLocation : Max.Z;
230 BB.
Extent = (Max - Min) * 0.5f;
236 auto& CompToWorldTransform = ParentComp->GetComponentTransform();
270 TArray<FBoundingBox>& OutBB,
271 TArray<uint8>& OutTag,
276 TArray<FBoundingBox> BBsOfTL;
277 TArray<uint8> TagsOfTL;
281 const float DistanceThreshold = 100.0f * 100.0f;
284 uint8 TLTag =
static_cast<uint8
>(crp::CityObjectLabel::TrafficLight);
287 check(BBsOfTL.Num() == TagsOfTL.Num());
289 bool FilterByTagEnabled = (InTagQueried !=
static_cast<uint8
>(crp::CityObjectLabel::Any));
291 for(
int i = 0; i < BBsOfTL.Num(); i++)
294 uint8 Tag = TagsOfTL[i];
296 if(FilterByTagEnabled && Tag != InTagQueried)
continue;
304 const USkeletalMeshComponent* SkeletalMeshComp
307 if (!SkeletalMeshComp || !SkeletalMeshComp->GetSkeletalMeshAsset())
312 TEXT(
"GetSkeletalMeshBoundingBoxFromComponent: missing SkeletalMeshComponent or SkeletalMesh"));
320 const FBoxSphereBounds LocalBounds =
321 SkeletalMeshComp->CalcBounds(FTransform::Identity);
323 return {LocalBounds.Origin, LocalBounds.BoxExtent};
331 UE_LOG(LogCarla, Error, TEXT(
"GetSkeletalMeshBoundingBox no SkeletalMesh"));
336 FSkeletalMeshRenderData* SkeletalMeshRenderData = SkeletalMesh->GetResourceForRendering();
337 FSkeletalMeshLODRenderData& LODRenderData = SkeletalMeshRenderData->LODRenderData[0];
338 FStaticMeshVertexBuffers& StaticMeshVertexBuffers = LODRenderData.StaticVertexBuffers;
339 FPositionVertexBuffer& FPositionVertexBuffer = StaticMeshVertexBuffers.PositionVertexBuffer;
340 uint32 NumVertices = FPositionVertexBuffer.GetNumVertices();
343 FVector Max(TNumericLimits<float>::Lowest());
344 FVector Min(TNumericLimits<float>::Max());
346 for(uint32 i = 0; i < NumVertices; i++)
348 auto Pos = FVector(FPositionVertexBuffer.VertexPosition(i));
349 Max = Max.ComponentMax(Pos);
350 Min = Min.ComponentMin(Pos);
353 auto Extent = (Max - Min) * 0.5f;
354 auto Origin = Min + Extent;
356 return {Origin, Extent};
373 UInstancedStaticMeshComponent*
ISMComp,
374 TArray<FBoundingBox>& OutBoundingBox)
378 UE_LOG(LogCarla, Error, TEXT(
"GetISMBoundingBox no ISMComp"));
382 const UStaticMesh *Mesh =
ISMComp->GetStaticMesh();
388 UE_LOG(LogCarla, Error, TEXT(
"Actor Name: %s Actor Labe: %s has no SM assigned to the ISM"), *
ISMComp->GetOwner()->GetName(), *
ISMComp->GetOwner()->GetActorLabel());
390 UE_LOG(LogCarla, Error, TEXT(
"Actor Name: %s has no SM assigned to the ISM"), *
ISMComp->GetOwner()->GetName());
395 const TArray<FInstancedStaticMeshInstanceData>& PerInstanceSMData =
ISMComp->PerInstanceSMData;
397 const FTransform ParentTransform =
ISMComp->GetComponentTransform();
399 for(
auto& InstSMIData : PerInstanceSMData)
401 const FTransform Transform = FTransform(InstSMIData.Transform) * ParentTransform;
410 const TArray<UStaticMeshComponent*>& StaticMeshComps,
411 TArray<FBoundingBox>& OutBB,
412 TArray<uint8>& OutTag,
416 bool FilterByTagEnabled = (TagQueried != crp::CityObjectLabel::Any);
418 for(UStaticMeshComponent* Comp : StaticMeshComps)
421 bool isCrosswalk = Comp->GetOwner()->GetName().Contains(
"crosswalk");
424 if( (!Comp->IsVisible() && !isCrosswalk) || Cast<UInstancedStaticMeshComponent>(Comp))
431 if(FilterByTagEnabled && Tag != TagQueried)
continue;
433 UStaticMesh* StaticMesh = Comp->GetStaticMesh();
439 const FTransform& CompToWorldTransform = Comp->GetComponentTransform();
442 OutTag.Emplace(
static_cast<uint8
>(Tag));
448 const TArray<USkeletalMeshComponent*>& SkeletalMeshComps,
449 TArray<FBoundingBox>& OutBB,
450 TArray<uint8>& OutTag,
454 bool FilterByTagEnabled = (TagQueried != crp::CityObjectLabel::Any);
456 for(USkeletalMeshComponent* Comp : SkeletalMeshComps)
461 if(!Comp->IsVisible() || (FilterByTagEnabled && Tag != TagQueried))
continue;
463 USkeletalMesh* SkeletalMesh = Comp->GetSkeletalMeshAsset();
467 UE_LOG(LogCarla, Error, TEXT(
"%s has no SKM assigned"), *Comp->GetOwner()->GetName());
472 const FTransform& CompToWorldTransform = Comp->GetComponentTransform();
475 OutTag.Emplace(
static_cast<uint8
>(Tag));
498 TArray<FBoundingBox> Result;
501 bool FilterByTagEnabled = (TagQueried != crp::CityObjectLabel::Any);
503 FString ClassName = Actor->GetClass()->GetName();
509 if( ClassName.Contains(
"Procedural_Bulding") )
return Result;
544 TArray<UInstancedStaticMeshComponent *> ISMComps;
545 Actor->GetComponents<UInstancedStaticMeshComponent>(ISMComps);
546 for(UInstancedStaticMeshComponent* Comp: ISMComps)
550 if(FilterByTagEnabled && Tag != TagQueried)
continue;
556 TArray<UStaticMeshComponent*> StaticMeshComps;
558 Actor->GetComponents<UStaticMeshComponent>(StaticMeshComps);
562 TArray<USkeletalMeshComponent*> SkeletalMeshComps;
564 Actor->GetComponents<USkeletalMeshComponent>(SkeletalMeshComps);
572 TArray<FBoundingBox>& OutBB,
573 TArray<uint8>& OutTag,
574 const float DistanceThreshold,
579 TArray<FBoundingBox> BBsOfTL;
580 TArray<uint8> InternalOutTags;
581 TArray<UStaticMeshComponent*> StaticMeshComps;
582 Actor->GetComponents<UStaticMeshComponent>(StaticMeshComps);
585 bool IgnoreDistanceFilter = (DistanceThreshold <= 0.0f);
586 bool IgnoreTag = (TagToCombine == 0);
588 TSet<int> IndicesDiscarded;
589 for(
int i = 0; i < BBsOfTL.Num(); i++)
592 if(IndicesDiscarded.Contains(i))
continue;
594 TArray<FBoundingBox> BBsToCombine;
596 uint8 Tag1 = InternalOutTags[i];
598 for(
int j = i + 1; j < BBsOfTL.Num(); j++)
601 if(IndicesDiscarded.Contains(j))
continue;
604 uint8 Tag2 = InternalOutTags[j];
606 float Distance = FVector::DistSquared(BB1.
Origin, BB2.
Origin);
609 if( ((Distance <= DistanceThreshold) || IgnoreDistanceFilter) &&
610 ((Tag1 == Tag2) || IgnoreTag) )
612 BBsToCombine.Emplace(BB2);
613 IndicesDiscarded.Emplace(j);
616 if(BBsToCombine.Num() > 0)
618 BBsToCombine.Emplace(BB1);
619 IndicesDiscarded.Emplace(i);
622 OutBB.Emplace(MergedBB);
623 OutTag.Emplace(InternalOutTags[i]);
628 for(
int i = 0; i < BBsOfTL.Num(); i++)
631 if(IndicesDiscarded.Contains(i))
continue;
634 OutTag.Emplace(InternalOutTags[i]);
640 Collection&& collection,
641 ExtractAABB&& extract_aabb)
643 FVector Max(std::numeric_limits<float>::lowest());
644 FVector Min(std::numeric_limits<float>::max());
646 for (
auto& e : collection)
648 auto BB = extract_aabb(e);
649 auto LocalMax = BB.Origin + BB.Rotation.RotateVector(BB.Extent);
650 auto LocalMin = BB.Origin - BB.Rotation.RotateVector(BB.Extent);
652 LocalMin = LocalMin.ComponentMin(LocalMax);
653 LocalMax = LocalMax.ComponentMax(Tmp);
654 Max = Max.ComponentMax(LocalMax);
655 Min = Min.ComponentMin(LocalMin);
658 auto Extent = (Max - Min) * 0.5f;
659 auto Origin = Min + Extent;
661 return { Origin, Extent };
692 TArray<UStaticMeshComponent*>& OutStaticMeshComps)
697 const float DistanceThreshold = 100.0f * 100.0f;
699 TArray<UStaticMeshComponent*> SMComps;
700 Actor->GetComponents<UStaticMeshComponent>(SMComps);
702 for(UStaticMeshComponent* Comp : SMComps)
704 if(!Comp->IsVisible())
continue;
706 TArray<FBoundingBox> BBs;
707 TArray<uint8> InternalOutTags;
710 if(BBs.Num() == 0)
continue;
713 float Distance = FVector::DistSquared(InBB.
Origin, BB.
Origin);
714 if(Distance <= DistanceThreshold)
716 OutStaticMeshComps.Emplace(Comp);