Added filters and operation reverse
This commit is contained in:
parent
bb416218df
commit
605817e1b8
|
@ -239,7 +239,7 @@ void UMapGenFunctionLibrary::CleanupGEngine(){
|
|||
#endif
|
||||
}
|
||||
|
||||
void UMapGenFunctionLibrary::ChangeStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, int MinNumOfInstancesToBeChanged)
|
||||
void UMapGenFunctionLibrary::ChangeStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter, int MinNumOfInstancesToBeChanged)
|
||||
{
|
||||
TArray<AActor*> FoundActors;
|
||||
UGameplayStatics::GetAllActorsOfClass(World, AStaticMeshActor::StaticClass(), FoundActors);
|
||||
|
@ -249,8 +249,11 @@ void UMapGenFunctionLibrary::ChangeStaticMeshesInTheLevelForInstancedStaticMeshe
|
|||
AStaticMeshActor* CurrentStaticMeshActor = Cast<AStaticMeshActor>(CurrentActor);
|
||||
UStaticMeshComponent* CurrentStaticMeshComponent = CurrentStaticMeshActor->GetStaticMeshComponent();
|
||||
UStaticMesh* CurrentStaticMesh = CurrentStaticMeshComponent->GetStaticMesh();
|
||||
TArray<AStaticMeshActor*>& Instances = ActorsToCheckIfReplacedMap.FindOrAdd(CurrentStaticMesh);
|
||||
Instances.Add(CurrentStaticMeshActor);
|
||||
if( Filter.IsEmpty() || Filter.Contains(CurrentStaticMesh) )
|
||||
{
|
||||
TArray<AStaticMeshActor*>& Instances = ActorsToCheckIfReplacedMap.FindOrAdd(CurrentStaticMesh);
|
||||
Instances.Add(CurrentStaticMeshActor);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto CurrentPair : ActorsToCheckIfReplacedMap)
|
||||
|
@ -261,8 +264,9 @@ void UMapGenFunctionLibrary::ChangeStaticMeshesInTheLevelForInstancedStaticMeshe
|
|||
for( AStaticMeshActor* SMActor : CurrentPair.Value )
|
||||
{
|
||||
TransformsToBeInstanced.Add(SMActor->GetActorTransform());
|
||||
SMActor->Destroy();
|
||||
}
|
||||
|
||||
|
||||
AInstancedStaticMeshActor* InstancedStaticMeshActor = World->SpawnActor<AInstancedStaticMeshActor>();
|
||||
if(InstancedStaticMeshActor)
|
||||
{
|
||||
|
@ -272,3 +276,29 @@ void UMapGenFunctionLibrary::ChangeStaticMeshesInTheLevelForInstancedStaticMeshe
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UMapGenFunctionLibrary::RevertStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter)
|
||||
{
|
||||
TArray<AActor*> FoundActors;
|
||||
UGameplayStatics::GetAllActorsOfClass(World, AInstancedStaticMeshActor::StaticClass(), FoundActors);
|
||||
|
||||
for(AActor* CurrentActor : FoundActors )
|
||||
{
|
||||
AInstancedStaticMeshActor* InstancedStaticMeshActor = Cast<AInstancedStaticMeshActor>(CurrentActor);
|
||||
if(InstancedStaticMeshActor)
|
||||
{
|
||||
UStaticMesh* CurrentStaticMesh = InstancedStaticMeshActor->GetInstancedStaticMeshComponent()->GetStaticMesh();
|
||||
if( Filter.IsEmpty() || Filter.Contains(CurrentStaticMesh))
|
||||
{
|
||||
const TArray<FInstancedStaticMeshInstanceData>& Instances = InstancedStaticMeshActor->GetInstancedStaticMeshComponent()->PerInstanceSMData;
|
||||
for( FInstancedStaticMeshInstanceData CurrentInstanceData : Instances )
|
||||
{
|
||||
AStaticMeshActor* StaticMeshActor = World->SpawnActor<AStaticMeshActor>();
|
||||
StaticMeshActor->GetStaticMeshComponent()->SetStaticMesh(CurrentStaticMesh);
|
||||
StaticMeshActor->SetActorTransform(FTransform(CurrentInstanceData.Transform));
|
||||
}
|
||||
InstancedStaticMeshActor->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,5 +55,9 @@ public:
|
|||
// This function will count instances of each static mesh in the level, if there are > MinNumOfInstancesToBeChanged they will be changed by instanced static meshes
|
||||
// to reduce draw calls
|
||||
UFUNCTION(BlueprintCallable)
|
||||
static void ChangeStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, int MinNumOfInstancesToBeChanged = 20);
|
||||
static void ChangeStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter, int MinNumOfInstancesToBeChanged = 20);
|
||||
|
||||
// This function will removed instanced static meshes in the level and place static mesh actors instead
|
||||
UFUNCTION(BlueprintCallable)
|
||||
static void RevertStaticMeshesInTheLevelForInstancedStaticMeshes(UWorld* World, TArray<UStaticMesh*> Filter);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue