Luis/vegetation videos (#5861)

* fixed pool increasing size fast.

* Fixed pools

* get the vehicle each frame

* Fixed bug when starting a new manual control script.

* Fixed xerces-c dependency

* fixed xerces-c dependencies

* Adding backup for xerces-c library

* Fix the duplication of collision capsules, and remove the impulse with static bones

* enable impulse force again, for static bones

* nullptr tile bug fixed

Co-authored-by: Axel <axellopez92@outlook.com>
Co-authored-by: bernatx <bernatx@gmail.com>
This commit is contained in:
LuisPoveda 2022-10-24 10:35:29 +02:00 committed by GitHub
parent bcf3471586
commit bc23f261e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 155 additions and 187 deletions

View File

@ -209,6 +209,17 @@ void ALargeMapManager::OnActorSpawned(
}
ACarlaWheeledVehicle* ALargeMapManager::GetHeroVehicle()
{
if (ActorsToConsider.Num() > 0)
{
ACarlaWheeledVehicle* Hero = Cast<ACarlaWheeledVehicle>(ActorsToConsider[0]);
if (IsValid(Hero))
return Hero;
}
return nullptr;
}
void ALargeMapManager::OnActorDestroyed(AActor* DestroyedActor)
{
LM_LOG(Warning, "ALargeMapManager::OnActorDestroyed %s", *DestroyedActor->GetName());

View File

@ -197,6 +197,8 @@ public:
FCarlaMapTile& LoadCarlaMapTile(FString TileMapPath, TileID TileId);
ACarlaWheeledVehicle* GetHeroVehicle();
protected:
void UpdateTilesState();

View File

@ -301,7 +301,7 @@ void USpringBasedVegetationComponent::GenerateSkeletonHierarchy()
}
}
UpdateGlobalTransform();
// UpdateGlobalTransform();
}
void USpringBasedVegetationComponent::BeginPlay()
@ -330,47 +330,6 @@ void USpringBasedVegetationComponent::BeginPlay()
GenerateSkeletonHierarchy();
}
// Get resting pose for bones
auto *AnimInst = SkeletalMesh->GetAnimInstance();
if (!AnimInst)
{
OTHER_LOG(Error, "Could not get animation instance.");
return;
}
UWalkerAnim *WalkerAnim = Cast<UWalkerAnim>(AnimInst);
if (!WalkerAnim)
{
OTHER_LOG(Error, "Could not get UWalkerAnim.");
return;
}
// get current pose
FPoseSnapshot TempSnapshot;
SkeletalMesh->SnapshotPose(TempSnapshot);
// copy pose
WalkerAnim->Snap = TempSnapshot;
for (int i=0; i<Skeleton.Joints.Num(); ++i)
{
FSkeletonJoint& Joint = Skeleton.Joints[i];
FTransform JointTransform = SkeletalMesh->GetSocketTransform(FName(*Joint.JointName), ERelativeTransformSpace::RTS_ParentBoneSpace);
Joint.Transform = JointTransform;
Joint.RestingAngles = JointTransform.Rotator();
OTHER_LOG(Log, "Getting info for bone %s, %f, %f, %f, %f", *Joint.JointName, Joint.RestingAngles.Pitch, Joint.RestingAngles.Yaw, Joint.RestingAngles.Roll);
if(i > 0)
{
FSkeletonJoint& ParentJoint = Skeleton.Joints[Joint.ParentId];
FVector BoneCOM = Joint.Transform.GetLocation()*0.5f;
float BoneLength = Joint.Transform.GetLocation().Size();
ParentJoint.Bones.Add({10, BoneLength, BoneCOM});
}
}
for (int i=0; i<TempSnapshot.BoneNames.Num(); ++i)
{
OTHER_LOG(Log, "Joint list: %s", *TempSnapshot.BoneNames[i].ToString());
}
UpdateGlobalTransform();
GenerateCollisionCapsules();
if(bAutoComputeStrength)

View File

@ -46,10 +46,16 @@ static FString GetVersionFromFString(const FString& String)
/********************************************************************************/
/********** POOLED ACTOR STRUCT *************************************************/
/********************************************************************************/
void FPooledActor::EnableActor()
void FPooledActor::EnableActor(const FTransform& Transform, int32 NewIndex, FTileMeshComponent* NewTileMeshComponent)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FPooledActor::EnableActor);
InUse = true;
GlobalTransform = Transform;
Index = NewIndex;
TileMeshComponent = NewTileMeshComponent;
TileMeshComponent->IndicesInUse.Emplace(Index);
Actor->SetActorHiddenInGame(false);
Actor->SetActorEnableCollision(true);
Actor->SetActorTickEnabled(true);
@ -65,8 +71,17 @@ void FPooledActor::EnableActor()
void FPooledActor::DisableActor()
{
TRACE_CPUPROFILER_EVENT_SCOPE(FPooledActor::DisableActor);
if (TileMeshComponent)
{
if (TileMeshComponent->IndicesInUse.Num() > 0)
TileMeshComponent->IndicesInUse.RemoveSingle(Index);
}
InUse = false;
Actor->SetActorTransform(FTransform());
Index = -1;
TileMeshComponent = nullptr;
Actor->SetActorHiddenInGame(true);
Actor->SetActorEnableCollision(false);
Actor->SetActorTickEnabled(false);
@ -189,20 +204,32 @@ void AVegetationManager::Tick(float DeltaTime)
}
if (!LargeMap)
return;
bool FoundVehicles = CheckIfAnyVehicleInLevel();
if (!FoundVehicles)
return;
UpdateVehiclesDetectionBoxes();
if (!IsValid(HeroVehicle))
{
HeroVehicle = LargeMap->GetHeroVehicle();
if (!IsValid(HeroVehicle))
return;
}
HeroVehicle->UpdateDetectionBox();
TArray<FString> TilesInUse = GetTilesInUse();
if (TilesInUse.Num() == 0)
{
UE_LOG(LogCarla, Warning, TEXT("No tiles detected."));
return;
}
for (const FString& TileName : TilesInUse)
{
FTileData* Tile = TileCache.Find(TileName);
if (!Tile)
continue;
UpdateMaterials(Tile);
TArray<FElementsToSpawn> ElementsToSpawn = GetElementsToSpawn(Tile);
SpawnSkeletalFoliages(ElementsToSpawn);
DestroySkeletalFoliages();
}
UpdateMaterials(TilesInUse);
TArray<TPair<FFoliageBlueprint, TArray<FTransform>>> ElementsToSpawn = GetElementsToSpawn(TilesInUse);
SpawnSkeletalFoliages(ElementsToSpawn);
DestroySkeletalFoliages();
}
/********************************************************************************/
@ -213,9 +240,7 @@ void AVegetationManager::AddVehicle(ACarlaWheeledVehicle* Vehicle)
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::AddVehicle);
if (!IsValid(Vehicle))
return;
if (VehiclesInLevel.Contains(Vehicle))
return;
VehiclesInLevel.Emplace(Vehicle);
HeroVehicle = Vehicle;
UE_LOG(LogCarla, Display, TEXT("Vehicle added."));
}
@ -224,9 +249,7 @@ void AVegetationManager::RemoveVehicle(ACarlaWheeledVehicle* Vehicle)
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::RemoveVehicle);
if (!IsValid(Vehicle))
return;
if (!VehiclesInLevel.Contains(Vehicle))
return;
VehiclesInLevel.RemoveSingle(Vehicle);
HeroVehicle = nullptr;
UE_LOG(LogCarla, Display, TEXT("Vehicle removed."));
}
@ -245,6 +268,8 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel)
TileData.InstancedFoliageActor = InstancedFoliageActor;
break;
}
if (!IsValid(TileData.InstancedFoliageActor))
return;
for (AActor* Actor : InLevel->Actors)
{
@ -254,18 +279,17 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel)
TileData.ProceduralFoliageVolume = ProceduralFoliageVolume;
break;
}
if (!IsValid(TileData.ProceduralFoliageVolume))
return;
const FString TileName = TileData.InstancedFoliageActor->GetLevel()->GetOuter()->GetName();
FTileData* ExistingTileData = TileCache.Find(TileName);
if (ExistingTileData)
{
ExistingTileData->InstancedFoliageActor = TileData.InstancedFoliageActor;
ExistingTileData->ProceduralFoliageVolume = TileData.ProceduralFoliageVolume;
for (FTileMeshComponent& Element : ExistingTileData->TileMeshesCache)
{
Element.InstancedStaticMeshComponent = nullptr;
Element.IndicesInUse.Empty();
}
ExistingTileData->TileMeshesCache.Empty();
ExistingTileData->MaterialInstanceDynamicCache.Empty();
SetTileDataInternals(*ExistingTileData);
}
else
@ -273,7 +297,6 @@ void AVegetationManager::CreateOrUpdateTileCache(ULevel* InLevel)
SetTileDataInternals(TileData);
TileCache.Emplace(TileName, TileData);
}
}
void AVegetationManager::SetTileDataInternals(FTileData& TileData)
@ -316,7 +339,8 @@ void AVegetationManager::SetMaterialCache(FTileData& TileData)
if (TileData.MaterialInstanceDynamicCache.Num() > 0)
TileData.MaterialInstanceDynamicCache.Empty();
const float Distance = VehiclesInLevel.Last()->DetectionSize * 2.0f;
#define MATERIAL_HIDE_DISTANCE 500.0f
const float Distance = MATERIAL_HIDE_DISTANCE;
for (FTileMeshComponent& Element : TileData.TileMeshesCache)
{
UInstancedStaticMeshComponent* Mesh = Element.InstancedStaticMeshComponent;
@ -368,7 +392,7 @@ void AVegetationManager::UpdateFoliageBlueprintCache(ULevel* InLevel)
if (!NewFoliageBlueprint.IsValid())
{
UE_LOG(LogCarla, Error, TEXT("Blueprint %s was invalid."), *NewFoliageBlueprint.BPFullClassName);
UE_LOG(LogCarla, Warning, TEXT("Blueprint %s was invalid."), *NewFoliageBlueprint.BPFullClassName);
}
else
{
@ -384,7 +408,7 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel)
{
if (!IsValid(InLevel))
return;
FTileData TileData {};
AInstancedFoliageActor* TileInstancedFoliageActor = nullptr;
for (AActor* Actor : InLevel->Actors)
{
if (!IsValid(Actor))
@ -392,12 +416,12 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel)
AInstancedFoliageActor* InstancedFoliageActor = Cast<AInstancedFoliageActor>(Actor);
if (!IsValid(InstancedFoliageActor))
continue;
TileData.InstancedFoliageActor = InstancedFoliageActor;
TileInstancedFoliageActor = InstancedFoliageActor;
break;
}
if (TileData.InstancedFoliageActor == nullptr)
if (!IsValid(TileInstancedFoliageActor))
return;
const FString TileName = TileData.InstancedFoliageActor->GetLevel()->GetOuter()->GetName();
const FString TileName = TileInstancedFoliageActor->GetLevel()->GetOuter()->GetName();
FTileData* ExistingTileData = TileCache.Find(TileName);
if (ExistingTileData)
{
@ -407,6 +431,9 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel)
Element.IndicesInUse.Empty();
}
ExistingTileData->TileMeshesCache.Empty();
ExistingTileData->InstancedFoliageActor = nullptr;
ExistingTileData->ProceduralFoliageVolume = nullptr;
TileCache.Remove(TileName);
}
}
@ -414,100 +441,83 @@ void AVegetationManager::FreeTileCache(ULevel* InLevel)
/********************************************************************************/
/********** TICK ****************************************************************/
/********************************************************************************/
void AVegetationManager::UpdateVehiclesDetectionBoxes()
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdateVehiclesDetectionBoxes);
for (ACarlaWheeledVehicle* Vehicle : VehiclesInLevel)
Vehicle->UpdateDetectionBox();
}
void AVegetationManager::UpdateMaterials(TArray<FString>& Tiles)
void AVegetationManager::UpdateMaterials(FTileData* Tile)
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::UpdateMaterials);
const FLinearColor Position = VehiclesInLevel.Last()->GetActorLocation();
for (const FString& TileName : Tiles)
{
FTileData* TileData = TileCache.Find(TileName);
if (!TileData)
continue;
TileData->UpdateMaterialCache(Position, DebugMaterials);
}
const FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(HeroVehicle->GetActorTransform());
const FLinearColor Position = GlobalTransform.GetLocation();
Tile->UpdateMaterialCache(Position, DebugMaterials);
}
TArray<TPair<FFoliageBlueprint, TArray<FTransform>>> AVegetationManager::GetElementsToSpawn(const TArray<FString>& Tiles)
TArray<FElementsToSpawn> AVegetationManager::GetElementsToSpawn(FTileData* Tile)
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::GetElementsToSpawn);
TArray<TPair<FFoliageBlueprint, TArray<FTransform>>> Results;
for (const FString& TileKey : Tiles)
TArray<FElementsToSpawn> Results;
int32 i = -1;
for (FTileMeshComponent& Element : Tile->TileMeshesCache)
{
FTileData* Tile = TileCache.Find(TileKey);
if (!Tile)
TRACE_CPUPROFILER_EVENT_SCOPE(Update Foliage Usage);
++i;
UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Element.InstancedStaticMeshComponent;
const FString Path = InstancedStaticMeshComponent->GetStaticMesh()->GetPathName();
FFoliageBlueprint* BP = FoliageBlueprintCache.Find(Path);
if (!BP)
continue;
TArray<int32> Indices = HeroVehicle->GetFoliageInstancesCloseToVehicle(InstancedStaticMeshComponent);
if (Indices.Num() == 0)
continue;
for (FTileMeshComponent& Element : Tile->TileMeshesCache)
{
TRACE_CPUPROFILER_EVENT_SCOPE(Update Foliage Usage);
UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Element.InstancedStaticMeshComponent;
const FString Path = InstancedStaticMeshComponent->GetStaticMesh()->GetPathName();
FFoliageBlueprint* BP = FoliageBlueprintCache.Find(Path);
if (!BP)
continue;
TArray<int32> Indices = VehiclesInLevel.Last()->GetFoliageInstancesCloseToVehicle(InstancedStaticMeshComponent);
if (Indices.Num() == 0)
continue;
TArray<int32> NewIndices;
for (int32 Index : Indices)
{
if (Element.IndicesInUse.Contains(Index))
continue;
NewIndices.Emplace(Index);
}
Element.IndicesInUse = Indices;
TPair<FFoliageBlueprint, TArray<FTransform>> NewElement {};
NewElement.Key = *BP;
TArray<FTransform> Transforms;
for (int32 Index : NewIndices)
{
FTransform Transform;
InstancedStaticMeshComponent->GetInstanceTransform(Index, Transform, true);
FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(Transform);
Transforms.Emplace(GlobalTransform);
}
if (Transforms.Num() > 0)
{
NewElement.Value = Transforms;
Results.Emplace(NewElement);
}
TArray<int32> NewIndices;
for (int32 Index : Indices)
{
if (Element.IndicesInUse.Contains(Index))
continue;
NewIndices.Emplace(Index);
}
FElementsToSpawn NewElement {};
NewElement.TileMeshComponent = &Tile->TileMeshesCache[i];
NewElement.BP = *BP;
for (int32 Index : NewIndices)
{
FTransform Transform;
InstancedStaticMeshComponent->GetInstanceTransform(Index, Transform, true);
FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(Transform);
NewElement.TransformIndex.Emplace(TPair<FTransform, int32>(GlobalTransform, Index));
}
if (NewElement.TransformIndex.Num() > 0)
Results.Emplace(NewElement);
}
return Results;
}
void AVegetationManager::SpawnSkeletalFoliages(TArray<TPair<FFoliageBlueprint, TArray<FTransform>>>& ElementsToSpawn)
void AVegetationManager::SpawnSkeletalFoliages(TArray<FElementsToSpawn>& ElementsToSpawn)
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::SpawnSkeletalFoliages);
for (TPair<FFoliageBlueprint, TArray<FTransform>>& Element : ElementsToSpawn)
for (FElementsToSpawn& Element : ElementsToSpawn)
{
FFoliageBlueprint BP = Element.Key;
TArray<FPooledActor>* Pool = ActorPool.Find(BP.BPFullClassName);
for (const FTransform& Transform : Element.Value)
TArray<FPooledActor>* Pool = ActorPool.Find(Element.BP.BPFullClassName);
if (Pool == nullptr)
continue;
for (const TPair<FTransform, int32>& TransformIndex : Element.TransformIndex)
{
bool Ok = EnableActorFromPool(Transform, *Pool);
const FTransform& Transform = TransformIndex.Key;
int32 Index = TransformIndex.Value;
if (Element.TileMeshComponent->IndicesInUse.Contains(Index))
continue;
bool Ok = EnableActorFromPool(Transform, Index, Element.TileMeshComponent, *Pool);
if (Ok)
{
UE_LOG(LogCarla, Display, TEXT("Pooled actor: %s"), *BP.BPFullClassName);
}
else
{
FPooledActor NewElement;
NewElement.GlobalTransform = Transform;
FTransform LocalTransform = LargeMap->GlobalToLocalTransform(Transform);
NewElement.Actor = CreateFoliage(BP, LocalTransform);
NewElement.Actor = CreateFoliage(Element.BP, {});
if (IsValid(NewElement.Actor))
{
NewElement.EnableActor();
NewElement.EnableActor(Transform, Index, Element.TileMeshComponent);
Pool->Emplace(NewElement);
UE_LOG(LogCarla, Display, TEXT("Created actor: %s"), *BP.BPFullClassName);
}
}
}
@ -525,29 +535,25 @@ void AVegetationManager::DestroySkeletalFoliages()
if (!Actor.InUse)
continue;
const FVector Location = Actor.GlobalTransform.GetLocation();
if (!VehiclesInLevel.Last()->IsInVehicleRange(Location))
if (!HeroVehicle->IsInVehicleRange(Location))
{
Actor.DisableActor();
UE_LOG(LogCarla, Display, TEXT("Disabled Actor"));
}
}
}
}
bool AVegetationManager::EnableActorFromPool(const FTransform& Transform, TArray<FPooledActor>& Pool)
bool AVegetationManager::EnableActorFromPool(const FTransform& Transform, int32 Index, FTileMeshComponent* TileMeshComponent, TArray<FPooledActor>& Pool)
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::EnableActorFromPool);
for (FPooledActor& PooledActor : Pool)
{
if (PooledActor.InUse)
continue;
PooledActor.GlobalTransform = Transform;
FTransform LocalTransform = Transform;
LocalTransform = LargeMap->GlobalToLocalTransform(Transform);
PooledActor.EnableActor();
PooledActor.Actor->SetActorLocationAndRotation(LocalTransform.GetLocation(), LocalTransform.Rotator(), true, nullptr, ETeleportType::ResetPhysics);
PooledActor.EnableActor(Transform, Index, TileMeshComponent);
PooledActor.Actor->SetActorLocationAndRotation(Transform.GetLocation(), Transform.Rotator(), true, nullptr, ETeleportType::ResetPhysics);
if (SpawnScale <= 1.01f && SpawnScale >= 0.99f)
PooledActor.Actor->SetActorScale3D(LocalTransform.GetScale3D());
PooledActor.Actor->SetActorScale3D(Transform.GetScale3D());
else
PooledActor.Actor->SetActorScale3D({SpawnScale, SpawnScale, SpawnScale});
return true;
@ -611,12 +617,6 @@ void AVegetationManager::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorl
FreeTileCache(InLevel);
}
bool AVegetationManager::CheckIfAnyVehicleInLevel() const
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::CheckIfAnyVehicleInLevel);
return VehiclesInLevel.Num() > 0;
}
bool AVegetationManager::IsFoliageTypeEnabled(const FString& Path) const
{
TRACE_CPUPROFILER_EVENT_SCOPE(AVegetationManager::IsFoliageTypeEnabled);
@ -676,17 +676,11 @@ TArray<FString> AVegetationManager::GetTilesInUse()
const FBox Box = Procedural->ProceduralComponent->GetBounds();
if (!Box.IsValid)
continue;
for (ACarlaWheeledVehicle* Vehicle : VehiclesInLevel)
{
if (!IsValid(Vehicle))
continue;
if (Box.IsInside(Vehicle->GetActorLocation()))
if (Box.IsInside(HeroVehicle->GetActorLocation()))
{
Results.Emplace(Element.Key);
break;
}
}
}
return Results;
}

View File

@ -60,11 +60,22 @@ struct FPooledActor
bool InUse { false };
AActor* Actor { nullptr };
FTransform GlobalTransform {FTransform()};
int32 Index {-1};
FTileMeshComponent* TileMeshComponent {nullptr};
void EnableActor();
void EnableActor(const FTransform& Transform, int32 NewIndex, FTileMeshComponent* NewTileMeshComponent);
void DisableActor();
};
USTRUCT()
struct FElementsToSpawn
{
GENERATED_BODY()
FTileMeshComponent* TileMeshComponent;
FFoliageBlueprint BP;
TArray<TPair<FTransform, int32>> TransformIndex;
};
UCLASS()
class CARLA_API AVegetationManager : public AActor
{
@ -107,17 +118,15 @@ protected:
private:
bool IsFoliageTypeEnabled(const FString& Path) const;
bool CheckIfAnyVehicleInLevel() const;
bool CheckForNewTiles() const;
TArray<FString> GetTilesInUse();
void UpdateVehiclesDetectionBoxes();
void UpdateMaterials(TArray<FString>& Tiles);
TArray<TPair<FFoliageBlueprint, TArray<FTransform>>> GetElementsToSpawn(const TArray<FString>& Tiles);
void SpawnSkeletalFoliages(TArray<TPair<FFoliageBlueprint, TArray<FTransform>>>& ElementsToSpawn);
void UpdateMaterials(FTileData* Tile);
TArray<FElementsToSpawn> GetElementsToSpawn(FTileData* Tile);
void SpawnSkeletalFoliages(TArray<FElementsToSpawn>& ElementsToSpawn);
void DestroySkeletalFoliages();
bool EnableActorFromPool(const FTransform& Transform, TArray<FPooledActor>& Pool);
bool EnableActorFromPool(const FTransform& Transform, int32 Index, FTileMeshComponent* TileMeshComponent, TArray<FPooledActor>& Pool);
void CreateOrUpdateTileCache(ULevel* InLevel);
void UpdateFoliageBlueprintCache(ULevel* InLevel);
@ -138,7 +147,7 @@ private:
private:
//Actors
ALargeMapManager* LargeMap {nullptr};
TArray<ACarlaWheeledVehicle*> VehiclesInLevel {};
ACarlaWheeledVehicle* HeroVehicle {nullptr};
//Caches
TMap<FString, FFoliageBlueprint> FoliageBlueprintCache {};
TMap<FString, FTileData> TileCache {};

View File

@ -206,25 +206,18 @@ bool ACarlaWheeledVehicle::IsInVehicleRange(const FVector& Location) const
{
TRACE_CPUPROFILER_EVENT_SCOPE(ACarlaWheeledVehicle::IsInVehicleRange);
float Distance = 0.0f;
ALargeMapManager* LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld());
if (LargeMap)
{
FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(GetActorTransform());
Distance = FVector::Distance(Location, GlobalTransform.GetLocation());
}
else
{
Distance = FVector::Distance(Location, GetActorTransform().GetLocation());
}
return Distance < DetectionSize * 10.0f;
return FoliageBoundingBox.IsInside(Location);
}
void ACarlaWheeledVehicle::UpdateDetectionBox()
{
ALargeMapManager* LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld());
if (!IsValid(LargeMap))
return;
FTransform GlobalTransform = LargeMap->LocalToGlobalTransform(GetActorTransform());
const FVector Vec { DetectionSize, DetectionSize, DetectionSize};
FBox Box = FBox(-Vec, Vec);
FoliageBoundingBox = Box.TransformBy(GetActorTransform());
FoliageBoundingBox = Box.TransformBy(GlobalTransform);
}
const TArray<int32> ACarlaWheeledVehicle::GetFoliageInstancesCloseToVehicle(const UInstancedStaticMeshComponent* Component) const
@ -937,8 +930,8 @@ FVector ACarlaWheeledVehicle::GetVelocity() const
void ACarlaWheeledVehicle::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
ShowDebugTelemetry(false);
RemoveReferenceToManager();
Super::EndPlay(EndPlayReason);
RemoveReferenceToManager();
}
void ACarlaWheeledVehicle::OpenDoor(const EVehicleDoor DoorIdx) {

View File

@ -354,7 +354,7 @@ private:
public:
UPROPERTY(Category = "CARLA Wheeled Vehicle", EditDefaultsOnly)
float DetectionSize { 200.0f };
float DetectionSize { 500.0f };
UPROPERTY(Category = "CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly)
FBox FoliageBoundingBox;