Lower quality max draw culling distance for road pieces moved from road builder to settings. Roads will no longer contain static instanced meshes when rebuild from scene, just static mesh components.
This commit is contained in:
parent
de9048ad22
commit
53533dd402
|
@ -11,6 +11,7 @@
|
||||||
#include "Engine/StaticMesh.h"
|
#include "Engine/StaticMesh.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Settings/CarlaSettings.h"
|
#include "Settings/CarlaSettings.h"
|
||||||
|
#include "Game/CarlaGameInstance.h"
|
||||||
|
|
||||||
|
|
||||||
using tag_size_t = std::underlying_type<ECityMapMeshTag>::type;
|
using tag_size_t = std::underlying_type<ECityMapMeshTag>::type;
|
||||||
|
@ -54,14 +55,17 @@ void ACityMapMeshHolder::OnConstruction(const FTransform &Transform)
|
||||||
void ACityMapMeshHolder::PostInitializeComponents()
|
void ACityMapMeshHolder::PostInitializeComponents()
|
||||||
{
|
{
|
||||||
Super::PostInitializeComponents();
|
Super::PostInitializeComponents();
|
||||||
|
|
||||||
|
|
||||||
if(IsValid(GetLevel())&&!GetLevel()->IsPendingKill())
|
if(IsValid(GetLevel())&&!GetLevel()->IsPendingKill())
|
||||||
{
|
{
|
||||||
if (MeshInstatiators.Num() == 0) {
|
TArray<AActor*> roadpieces;
|
||||||
ResetInstantiators();
|
GetAttachedActors(roadpieces);
|
||||||
UpdateMapScale();
|
if(roadpieces.Num()==0)
|
||||||
UpdateMap();
|
{
|
||||||
}
|
UpdateMapScale();
|
||||||
|
UpdateMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,7 +76,7 @@ void ACityMapMeshHolder::PostEditChangeProperty(FPropertyChangedEvent& PropertyC
|
||||||
Super::PostEditChangeProperty(PropertyChangedEvent);
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
||||||
if (PropertyChangedEvent.Property)
|
if (PropertyChangedEvent.Property)
|
||||||
{
|
{
|
||||||
ResetInstantiators();
|
DeletePieces();
|
||||||
UpdateMapScale();
|
UpdateMapScale();
|
||||||
UpdateMap();
|
UpdateMap();
|
||||||
}
|
}
|
||||||
|
@ -122,12 +126,10 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, uint32 X, uint32 Y, fl
|
||||||
const FQuat rotation(FVector(0.0f, 0.0f, 1.0f), Angle);
|
const FQuat rotation(FVector(0.0f, 0.0f, 1.0f), Angle);
|
||||||
const FVector location = GetTileLocation(X, Y);
|
const FVector location = GetTileLocation(X, Y);
|
||||||
AddInstance(Tag, FTransform(rotation, location));
|
AddInstance(Tag, FTransform(rotation, location));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
||||||
{
|
{
|
||||||
auto &instantiator = GetInstantiator(Tag);
|
|
||||||
FActorSpawnParameters params;
|
FActorSpawnParameters params;
|
||||||
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
FVector location = Transform.GetLocation();
|
FVector location = Transform.GetLocation();
|
||||||
|
@ -137,16 +139,9 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
||||||
StaticMeshActor->SetMobility(EComponentMobility::Static);
|
StaticMeshActor->SetMobility(EComponentMobility::Static);
|
||||||
UStaticMeshComponent* staticmeshcomponent = StaticMeshActor->GetStaticMeshComponent();
|
UStaticMeshComponent* staticmeshcomponent = StaticMeshActor->GetStaticMeshComponent();
|
||||||
staticmeshcomponent->SetMobility(EComponentMobility::Static);
|
staticmeshcomponent->SetMobility(EComponentMobility::Static);
|
||||||
staticmeshcomponent->SetStaticMesh(instantiator.GetStaticMesh());
|
staticmeshcomponent->SetStaticMesh(GetStaticMesh(Tag));
|
||||||
|
|
||||||
//occlussion
|
|
||||||
StaticMeshActor->Tags.Add(UCarlaSettings::CARLA_ROAD_TAG);
|
StaticMeshActor->Tags.Add(UCarlaSettings::CARLA_ROAD_TAG);
|
||||||
staticmeshcomponent->bAllowCullDistanceVolume=true;
|
StaticMeshActor->bEnableAutoLODGeneration = true;
|
||||||
staticmeshcomponent->bUseAsOccluder=false;
|
|
||||||
staticmeshcomponent->LDMaxDrawDistance = MaxDrawDistance;
|
|
||||||
staticmeshcomponent->CastShadow=false;
|
|
||||||
StaticMeshActor->bEnableAutoLODGeneration=true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
@ -155,23 +150,14 @@ void ACityMapMeshHolder::AddInstance(ECityMapMeshTag Tag, FTransform Transform)
|
||||||
|
|
||||||
void ACityMapMeshHolder::UpdateMap() {}
|
void ACityMapMeshHolder::UpdateMap() {}
|
||||||
|
|
||||||
void ACityMapMeshHolder::ResetInstantiators()
|
void ACityMapMeshHolder::DeletePieces()
|
||||||
{
|
{
|
||||||
for (auto *instantiator : MeshInstatiators) {
|
//this part will be deprecated: remove the instanced static mesh components
|
||||||
if (instantiator != nullptr) {
|
TArray<UActorComponent*> oldcomponents = GetComponentsByClass(UInstancedStaticMeshComponent::StaticClass());
|
||||||
instantiator->ClearInstances();
|
for(int32 i=0;i<oldcomponents.Num();i++)
|
||||||
}
|
{
|
||||||
|
oldcomponents[i]->DestroyComponent();
|
||||||
}
|
}
|
||||||
if (MeshInstatiators.Num() != NUMBER_OF_TAGS) {
|
|
||||||
MeshInstatiators.Empty();
|
|
||||||
MeshInstatiators.Init(nullptr, NUMBER_OF_TAGS);
|
|
||||||
}
|
|
||||||
check(MeshInstatiators.Num() == NUMBER_OF_TAGS);
|
|
||||||
for (tag_size_t i = 0u; i < NUMBER_OF_TAGS; ++i) {
|
|
||||||
auto &instantiator = GetInstantiator(CityMapMeshTag::FromUInt(i));
|
|
||||||
instantiator.SetStaticMesh(GetStaticMesh(CityMapMeshTag::FromUInt(i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TArray<AActor*> roadpieces;
|
TArray<AActor*> roadpieces;
|
||||||
GetAttachedActors(roadpieces);
|
GetAttachedActors(roadpieces);
|
||||||
|
@ -203,19 +189,4 @@ void ACityMapMeshHolder::UpdateMapScale()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UInstancedStaticMeshComponent &ACityMapMeshHolder::GetInstantiator(ECityMapMeshTag Tag)
|
|
||||||
{
|
|
||||||
UInstancedStaticMeshComponent *instantiator = MeshInstatiators[CityMapMeshTag::ToUInt(Tag)];
|
|
||||||
if (instantiator == nullptr) {
|
|
||||||
// Create and register an instantiator.
|
|
||||||
instantiator = NewObject<UInstancedStaticMeshComponent>(this);
|
|
||||||
instantiator->SetMobility(EComponentMobility::Static);
|
|
||||||
instantiator->SetCollisionObjectType(ECollisionChannel::ECC_WorldStatic);
|
|
||||||
instantiator->SetupAttachment(SceneRootComponent);
|
|
||||||
instantiator->SetStaticMesh(GetStaticMesh(Tag));
|
|
||||||
MeshInstatiators[CityMapMeshTag::ToUInt(Tag)] = instantiator;
|
|
||||||
instantiator->RegisterComponent();
|
|
||||||
}
|
|
||||||
check(instantiator != nullptr);
|
|
||||||
return *instantiator;
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
class IDetailLayoutBuilder;
|
class IDetailLayoutBuilder;
|
||||||
class UInstancedStaticMeshComponent;
|
class UInstancedStaticMeshComponent;
|
||||||
class AStaticMeshActor;
|
class AStaticMeshActor;
|
||||||
|
|
||||||
|
|
||||||
/// Holds the static meshes and instances necessary for building a city map.
|
/// Holds the static meshes and instances necessary for building a city map.
|
||||||
UCLASS(Abstract)
|
UCLASS(Abstract)
|
||||||
class CARLA_API ACityMapMeshHolder : public AActor
|
class CARLA_API ACityMapMeshHolder : public AActor
|
||||||
|
@ -92,14 +94,14 @@ private:
|
||||||
/// Here does nothing, implement in derived classes.
|
/// Here does nothing, implement in derived classes.
|
||||||
virtual void UpdateMap();
|
virtual void UpdateMap();
|
||||||
|
|
||||||
/// Clear all instances in the instantiators and update the static meshes.
|
/// Clear all instances of the static mesh actors.
|
||||||
void ResetInstantiators();
|
void DeletePieces();
|
||||||
|
|
||||||
/// Set the scale to the dimensions of the base mesh.
|
/// Set the scale to the dimensions of the base mesh.
|
||||||
void UpdateMapScale();
|
void UpdateMapScale();
|
||||||
|
|
||||||
/// Creates a new one if necessary.
|
private:
|
||||||
UInstancedStaticMeshComponent &GetInstantiator(ECityMapMeshTag Tag);
|
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
USceneComponent *SceneRootComponent;
|
USceneComponent *SceneRootComponent;
|
||||||
|
@ -113,9 +115,5 @@ private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TMap<UStaticMesh *, ECityMapMeshTag> TagMap;
|
TMap<UStaticMesh *, ECityMapMeshTag> TagMap;
|
||||||
|
|
||||||
UPROPERTY(Category = "Meshes", VisibleAnywhere)
|
|
||||||
TArray<UInstancedStaticMeshComponent *> MeshInstatiators;
|
|
||||||
|
|
||||||
UPROPERTY(Category = "Meshes", EditAnywhere)
|
|
||||||
float MaxDrawDistance = 10000.0f; /** @todo: move to carlasettings */
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -205,11 +205,17 @@ private:
|
||||||
float LowLightFadeDistance = 1000.0f;
|
float LowLightFadeDistance = 1000.0f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Default low distance for all primitive components
|
||||||
*/
|
*/
|
||||||
UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, meta = (ClampMin = "500.0", ClampMax = "15000.0", UIMin = "500.0", UIMax = "15000.0"))
|
UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, meta = (ClampMin = "500.0", ClampMax = "15000.0", UIMin = "500.0", UIMax = "15000.0"))
|
||||||
float LowStaticMeshMaxDrawDistance = 10000.0f;
|
float LowStaticMeshMaxDrawDistance = 10000.0f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default low distance for roads meshes
|
||||||
|
*/
|
||||||
|
UPROPERTY(Category = "Quality Settings/Low", BlueprintReadOnly, EditAnywhere, config, meta = (ClampMin = "5000.0", ClampMax = "17000.0", UIMin = "5000.0", UIMax = "17000.0"))
|
||||||
|
float LowRoadPieceMeshMaxDrawDistance = 15000.0f;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
|
@ -142,27 +142,37 @@ void UCarlaSettingsDelegate::SetAllRoadsLowQuality(UWorld* world) const
|
||||||
if(CarlaSettings->LowRoadMaterials.Num()==0) return; //no materials configured for low quality
|
if(CarlaSettings->LowRoadMaterials.Num()==0) return; //no materials configured for low quality
|
||||||
TArray<AActor*> actors;
|
TArray<AActor*> actors;
|
||||||
UGameplayStatics::GetAllActorsWithTag(world, UCarlaSettings::CARLA_ROAD_TAG,actors);
|
UGameplayStatics::GetAllActorsWithTag(world, UCarlaSettings::CARLA_ROAD_TAG,actors);
|
||||||
|
const float LowRoadPieceMeshMaxDrawDistance = CarlaSettings->LowRoadPieceMeshMaxDrawDistance;
|
||||||
for(int32 i=0; i<actors.Num(); i++)
|
for(int32 i=0; i<actors.Num(); i++)
|
||||||
{
|
{
|
||||||
if(!IsValid(actors[i]) || actors[i]->IsPendingKillPending()) continue;
|
if(!IsValid(actors[i]) || actors[i]->IsPendingKillPending()) continue;
|
||||||
TArray<UActorComponent*> components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass());
|
TArray<UActorComponent*> components = actors[i]->GetComponentsByClass(UStaticMeshComponent::StaticClass());
|
||||||
for(int32 j=0; j<components.Num(); j++)
|
for(int32 j=0; j<components.Num(); j++)
|
||||||
{
|
{
|
||||||
UStaticMeshComponent* staticmesh = Cast<UStaticMeshComponent>(components[j]);
|
UStaticMeshComponent* staticmeshcomponent = Cast<UStaticMeshComponent>(components[j]);
|
||||||
if(staticmesh)
|
if(staticmeshcomponent)
|
||||||
{
|
{
|
||||||
TArray<FName> slotsnames = staticmesh->GetMaterialSlotNames();
|
TArray<FName> slotsnames = staticmeshcomponent->GetMaterialSlotNames();
|
||||||
for(int32 k=0; k<slotsnames.Num(); k++)
|
for(int32 k=0; k<slotsnames.Num(); k++)
|
||||||
{
|
{
|
||||||
const FName &slotname = slotsnames[k];
|
const FName &slotname = slotsnames[k];
|
||||||
bool found = CarlaSettings->LowRoadMaterials.ContainsByPredicate([staticmesh,slotname](const FStaticMaterial& material)
|
bool found = CarlaSettings->LowRoadMaterials.ContainsByPredicate(
|
||||||
|
[staticmeshcomponent,slotname,LowRoadPieceMeshMaxDrawDistance](const FStaticMaterial& material)
|
||||||
{
|
{
|
||||||
if(material.MaterialSlotName.IsEqual(slotname))
|
if(material.MaterialSlotName.IsEqual(slotname))
|
||||||
{
|
{
|
||||||
staticmesh->SetMaterial(
|
staticmeshcomponent->SetMaterial(
|
||||||
staticmesh->GetMaterialIndex(slotname),
|
staticmeshcomponent->GetMaterialIndex(slotname),
|
||||||
material.MaterialInterface
|
material.MaterialInterface
|
||||||
);
|
);
|
||||||
|
staticmeshcomponent->bAllowCullDistanceVolume=true;
|
||||||
|
staticmeshcomponent->bUseAsOccluder=false;
|
||||||
|
|
||||||
|
staticmeshcomponent->LDMaxDrawDistance = LowRoadPieceMeshMaxDrawDistance;
|
||||||
|
staticmeshcomponent->CastShadow = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue