352 lines
9.8 KiB
C++
352 lines
9.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "ledcube3d.h"
|
|
#include "Modules/ModuleManager.h"
|
|
|
|
#if WITH_EDITOR
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
|
#include "Containers/Ticker.h"
|
|
#include "Editor.h"
|
|
#include "Engine/Engine.h"
|
|
#include "EngineUtils.h"
|
|
#include "FileHelpers.h"
|
|
#include "HAL/PlatformFileManager.h"
|
|
#include "LedVolumeRemoteControlActor.h"
|
|
#include "Misc/CoreDelegates.h"
|
|
#include "Misc/PackageName.h"
|
|
#include "RemoteControlPreset.h"
|
|
#include "UObject/Package.h"
|
|
#include "UObject/SavePackage.h"
|
|
#endif
|
|
|
|
class FLedcube3dModule : public FDefaultGameModuleImpl
|
|
{
|
|
public:
|
|
virtual void StartupModule() override
|
|
{
|
|
FDefaultGameModuleImpl::StartupModule();
|
|
#if WITH_EDITOR
|
|
UE_LOG(LogTemp, Display, TEXT("LED volume module startup: scheduling editor helpers"));
|
|
if (GEngine)
|
|
{
|
|
PostEditorTickHandle = GEngine->OnPostEditorTick().AddRaw(this, &FLedcube3dModule::TickEditorHelpers);
|
|
}
|
|
else
|
|
{
|
|
RemotePresetTickerHandle = FTSTicker::GetCoreTicker().AddTicker(
|
|
FTickerDelegate::CreateRaw(this, &FLedcube3dModule::TickBuildRemoteControlPreset),
|
|
2.0f);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
virtual void ShutdownModule() override
|
|
{
|
|
#if WITH_EDITOR
|
|
if (RemotePresetTickerHandle.IsValid())
|
|
{
|
|
FTSTicker::GetCoreTicker().RemoveTicker(RemotePresetTickerHandle);
|
|
RemotePresetTickerHandle.Reset();
|
|
}
|
|
if (PostEditorTickHandle.IsValid() && GEngine)
|
|
{
|
|
GEngine->OnPostEditorTick().Remove(PostEditorTickHandle);
|
|
PostEditorTickHandle.Reset();
|
|
}
|
|
#endif
|
|
FDefaultGameModuleImpl::ShutdownModule();
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
void TickEditorHelpers(float DeltaSeconds)
|
|
{
|
|
if (bRemotePresetBuilt || RemotePresetBuildAttempts > 60)
|
|
{
|
|
if (PostEditorTickHandle.IsValid() && GEngine)
|
|
{
|
|
GEngine->OnPostEditorTick().Remove(PostEditorTickHandle);
|
|
PostEditorTickHandle.Reset();
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (!bStartupMapOpenAttempted && OpenDemoMapIfEditorStartedEmpty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
bRemotePresetBuilt = true;
|
|
}
|
|
|
|
bool TickBuildRemoteControlPreset(float DeltaSeconds)
|
|
{
|
|
if (bRemotePresetBuilt || RemotePresetBuildAttempts++ > 60)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!bStartupMapOpenAttempted && OpenDemoMapIfEditorStartedEmpty())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bRemotePresetBuilt = true;
|
|
return false;
|
|
}
|
|
|
|
bool OpenDemoMapIfEditorStartedEmpty()
|
|
{
|
|
if (!GEditor)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
UWorld* EditorWorld = GEditor->GetEditorWorldContext(false).World();
|
|
if (!EditorWorld)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bStartupMapOpenAttempted = true;
|
|
|
|
const FString CurrentPackageName = EditorWorld->GetOutermost()->GetName();
|
|
if (!CurrentPackageName.StartsWith(TEXT("/Temp/Untitled")))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const FString DemoMapPackageName = TEXT("/Game/LedVolume/Maps/L_LedVolume_Demo_Single");
|
|
const FString DemoMapFilename = FPackageName::LongPackageNameToFilename(DemoMapPackageName, FPackageName::GetMapPackageExtension());
|
|
if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*DemoMapFilename))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("LED volume opening startup demo map: %s"), *DemoMapPackageName);
|
|
return FEditorFileUtils::LoadMap(DemoMapFilename, false, false);
|
|
}
|
|
|
|
bool BuildRemoteControlPreset()
|
|
{
|
|
if (!GEditor)
|
|
{
|
|
return false;
|
|
}
|
|
if (!GEditor->Trans)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
UWorld* EditorWorld = GEditor->GetEditorWorldContext(false).World();
|
|
if (!EditorWorld)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ALedVolumeRemoteControlActor* Controller = nullptr;
|
|
for (TActorIterator<ALedVolumeRemoteControlActor> It(EditorWorld); It; ++It)
|
|
{
|
|
if (ALedVolumeRemoteControlActor* Candidate = *It)
|
|
{
|
|
if (Candidate->GetActorLabel() == TEXT("LED_Remote_Control"))
|
|
{
|
|
Controller = Candidate;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!Controller)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const FString PackageName = TEXT("/Game/LedVolume/RemoteControl/RCP_LedVolumeLive");
|
|
const FString AssetName = TEXT("RCP_LedVolumeLive");
|
|
UPackage* Package = CreatePackage(*PackageName);
|
|
if (!Package)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool bCreatedNewPreset = false;
|
|
URemoteControlPreset* Preset = FindObject<URemoteControlPreset>(Package, *AssetName);
|
|
if (!Preset)
|
|
{
|
|
Preset = NewObject<URemoteControlPreset>(Package, *AssetName, RF_Public | RF_Standalone | RF_Transactional);
|
|
FAssetRegistryModule::AssetCreated(Preset);
|
|
bCreatedNewPreset = true;
|
|
}
|
|
|
|
if (!Preset)
|
|
{
|
|
return false;
|
|
}
|
|
if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("7")
|
|
|| (!bCreatedNewPreset && Preset->GetExposedEntities().Num() > 0))
|
|
{
|
|
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7"));
|
|
return true;
|
|
}
|
|
|
|
auto GetOrCreateGroupId = [Preset](const FName GroupName)
|
|
{
|
|
if (FRemoteControlPresetGroup* ExistingGroup = Preset->Layout.GetGroupByName(GroupName))
|
|
{
|
|
return ExistingGroup->Id;
|
|
}
|
|
return Preset->Layout.CreateGroup(GroupName).Id;
|
|
};
|
|
|
|
auto ExposeProperty = [Preset, Controller](const FString& PropertyName, const FString& GroupName)
|
|
{
|
|
const FName PropertyFName(*PropertyName);
|
|
if (!Controller->GetClass()->FindPropertyByName(PropertyFName))
|
|
{
|
|
UE_LOG(LogTemp, Warning, TEXT("Skipping missing Remote Control property: %s"), *PropertyName);
|
|
return;
|
|
}
|
|
if (Preset->FindExposedProperty(Controller, FRCFieldPathInfo(PropertyName)).IsValid())
|
|
{
|
|
return;
|
|
}
|
|
const FGuid GroupId = Preset->Layout.GetGroupByName(*GroupName)
|
|
? Preset->Layout.GetGroupByName(*GroupName)->Id
|
|
: Preset->Layout.CreateGroup(*GroupName).Id;
|
|
Preset->ExposeProperty(Controller, FRCFieldPathInfo(PropertyName), FRemoteControlPresetExposeArgs(PropertyName, GroupId));
|
|
};
|
|
|
|
auto ExposeFunction = [Preset, Controller](const FString& FunctionName, const FString& GroupName)
|
|
{
|
|
const FGuid GroupId = Preset->Layout.GetGroupByName(*GroupName)
|
|
? Preset->Layout.GetGroupByName(*GroupName)->Id
|
|
: Preset->Layout.CreateGroup(*GroupName).Id;
|
|
if (UFunction* Function = Controller->FindFunction(*FunctionName))
|
|
{
|
|
Preset->ExposeFunction(Controller, Function, FRemoteControlPresetExposeArgs(FunctionName, GroupId));
|
|
}
|
|
};
|
|
|
|
for (const FString& Name : { TEXT("TargetActorLabel") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Target"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("Width"), TEXT("Height"), TEXT("Depth"), TEXT("PixelSize"), TEXT("Spacing"), TEXT("PreviewStride") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Layout"));
|
|
}
|
|
|
|
for (const FString& Name : {
|
|
TEXT("GeometryMode"),
|
|
TEXT("CabinetCountX"),
|
|
TEXT("CabinetCountZ"),
|
|
TEXT("DotsPerCabinetX"),
|
|
TEXT("DotsPerCabinetZ"),
|
|
TEXT("LedsPerString"),
|
|
TEXT("CabinetSizeMm"),
|
|
TEXT("DotPitchMm"),
|
|
TEXT("PhysicalLedSizeMm"),
|
|
TEXT("WireThicknessMm"),
|
|
TEXT("WireOpacity"),
|
|
TEXT("PhysicalJitterMm"),
|
|
TEXT("WireSegmentsPerString"),
|
|
TEXT("PhysicalRandomSeed"),
|
|
TEXT("bShowCabinets"),
|
|
TEXT("bShowWires"),
|
|
TEXT("bShowBottomFixers"),
|
|
TEXT("CabinetMaterial"),
|
|
TEXT("WireMaterial"),
|
|
TEXT("BottomFixerMaterial")
|
|
})
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Physical Matrix"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("VoxelShape"), TEXT("CustomVoxelMesh"), TEXT("LedMaterial"), TEXT("Brightness"), TEXT("Gamma"), TEXT("SolidColor") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Appearance"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("SourceMode"), TEXT("TestPattern"), TEXT("AnimationSpeed"), TEXT("bAnimateInEditor"), TEXT("bUseGpuTestPattern") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Animation"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("MaxEditorInstances"), TEXT("MaxRuntimeInstances"), TEXT("ColorUpdatesPerFrame"), TEXT("ApplyDebounceSeconds") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Performance"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("VolumeTextureFrames"), TEXT("TextureSliceFrames") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Prepared Animation"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("VoxelizedSublevel"), TEXT("CaptureBoundsExtent"), TEXT("bUseActorBoundsAsCaptureVolume"), TEXT("SourceActorTag"), TEXT("EmptyVoxelColor") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Sublevel Source"));
|
|
}
|
|
|
|
for (const FString& Name : { TEXT("RenderedInstanceCount"), TEXT("RequestedVoxelCount") })
|
|
{
|
|
ExposeProperty(Name, TEXT("LED Status"));
|
|
}
|
|
|
|
for (const FString& Name : {
|
|
TEXT("ApplyToTarget"),
|
|
TEXT("RebuildTarget"),
|
|
TEXT("SyncFromTarget"),
|
|
TEXT("GetTargetDisplay"),
|
|
TEXT("SetTargetActorLabel"),
|
|
TEXT("SetWidth"),
|
|
TEXT("SetHeight"),
|
|
TEXT("SetDepth"),
|
|
TEXT("SetPixelSize"),
|
|
TEXT("SetSpacing"),
|
|
TEXT("SetPreviewStride"),
|
|
TEXT("SetVoxelShape"),
|
|
TEXT("SetCustomVoxelMesh"),
|
|
TEXT("SetLedMaterial"),
|
|
TEXT("SetBrightness"),
|
|
TEXT("SetGamma"),
|
|
TEXT("SetSolidColor"),
|
|
TEXT("SetSourceMode"),
|
|
TEXT("SetTestPattern"),
|
|
TEXT("SetAnimationSpeed"),
|
|
TEXT("SetAnimateInEditor"),
|
|
TEXT("SetUseGpuTestPattern"),
|
|
TEXT("SetMaxEditorInstances"),
|
|
TEXT("SetMaxRuntimeInstances"),
|
|
TEXT("SetColorUpdatesPerFrame"),
|
|
TEXT("SetApplyDebounceSeconds")
|
|
})
|
|
{
|
|
ExposeFunction(Name, Name.StartsWith(TEXT("Set")) ? TEXT("LED Setters") : TEXT("LED Commands"));
|
|
}
|
|
|
|
{
|
|
const FGuid GroupId = GetOrCreateGroupId(TEXT("Scene Actors"));
|
|
Preset->ExposeActor(Controller, FRemoteControlPresetExposeArgs(TEXT("LED_Remote_Control"), GroupId));
|
|
}
|
|
|
|
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7"));
|
|
Package->MarkPackageDirty();
|
|
const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
|
|
FSavePackageArgs SaveArgs;
|
|
SaveArgs.TopLevelFlags = RF_Public | RF_Standalone;
|
|
UPackage::SavePackage(Package, Preset, *PackageFileName, SaveArgs);
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("LED volume Remote Control live preset ready: %s"), *PackageName);
|
|
return true;
|
|
}
|
|
|
|
FTSTicker::FDelegateHandle RemotePresetTickerHandle;
|
|
FDelegateHandle PostEditorTickHandle;
|
|
int32 RemotePresetBuildAttempts = 0;
|
|
bool bRemotePresetBuilt = false;
|
|
bool bStartupMapOpenAttempted = false;
|
|
#endif
|
|
};
|
|
|
|
IMPLEMENT_PRIMARY_GAME_MODULE(FLedcube3dModule, ledcube3d, "ledcube3d");
|