Model physical LED curtain display

This commit is contained in:
krustophski 2026-08-07 01:50:11 +03:00
parent 55c7f81991
commit f9d37875db
20 changed files with 1045 additions and 26 deletions

View file

@ -87,6 +87,14 @@ FontDPI=72
+ActiveGameNameRedirects=(OldGameName="TP_Blank",NewGameName="/Script/ledcube3d")
+ActiveGameNameRedirects=(OldGameName="/Script/TP_Blank",NewGameName="/Script/ledcube3d")
[/Script/PythonScriptPlugin.PythonScriptPluginSettings]
bRemoteExecution=True
RemoteExecutionMulticastGroupEndpoint=239.0.0.1:6766
RemoteExecutionMulticastBindAddress=127.0.0.1
RemoteExecutionSendBufferSizeBytes=2097152
RemoteExecutionReceiveBufferSizeBytes=2097152
RemoteExecutionMulticastTtl=0
[/Script/AndroidFileServerEditor.AndroidFileServerRuntimeSettings]
bEnablePlugin=True
bAllowNetworkConnection=True

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -8,3 +8,17 @@ if os.environ.get("LED_VOLUME_CREATE_RC_PRESET") == "1":
script_path = os.path.join(project_dir, "Scripts", "CreateLedVolumeRemotePreset.py")
unreal.log(f"LED volume startup preset build: {script_path}")
runpy.run_path(script_path, run_name="__main__")
if os.environ.get("LED_VOLUME_OPEN_DEMO") == "1":
tick_handle = None
def open_led_demo_map(delta_seconds):
global tick_handle
if tick_handle is not None:
unreal.unregister_slate_post_tick_callback(tick_handle)
tick_handle = None
unreal.EditorLevelLibrary.load_level("/Game/LedVolume/Maps/L_LedVolume_Demo_Single")
unreal.log("LED volume startup opened /Game/LedVolume/Maps/L_LedVolume_Demo_Single")
tick_handle = unreal.register_slate_post_tick_callback(open_led_demo_map)

View file

@ -350,6 +350,49 @@ return accum;
return material
def create_physical_solid_material(asset_name, color, translucent=False, opacity=1.0):
package_path = "/Game/LedVolume/Materials"
asset_path = f"{package_path}/{asset_name}"
ensure_directory("/Game/LedVolume")
ensure_directory(package_path)
if unreal.EditorAssetLibrary.does_asset_exist(asset_path):
material = unreal.EditorAssetLibrary.load_asset(asset_path)
if material:
return material
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
material = asset_tools.create_asset(asset_name, package_path, unreal.Material, unreal.MaterialFactoryNew())
material.set_editor_property("shading_model", unreal.MaterialShadingModel.MSM_DEFAULT_LIT)
material.set_editor_property("blend_mode", unreal.BlendMode.BLEND_TRANSLUCENT if translucent else unreal.BlendMode.BLEND_OPAQUE)
material.set_editor_property("two_sided", True)
mel = unreal.MaterialEditingLibrary
usage = getattr(unreal.MaterialUsage, "MATUSAGE_INSTANCED_STATIC_MESHES", None)
if usage is not None:
mel.set_base_material_usage(material, usage, True)
color_param = mel.create_material_expression(material, unreal.MaterialExpressionVectorParameter, -500, -120)
color_param.set_editor_property("parameter_name", "WireColor" if translucent else "BaseColor")
color_param.set_editor_property("default_value", color)
mel.connect_material_property(color_param, "", unreal.MaterialProperty.MP_BASE_COLOR)
roughness = mel.create_material_expression(material, unreal.MaterialExpressionScalarParameter, -500, 20)
roughness.set_editor_property("parameter_name", "Roughness")
roughness.set_editor_property("default_value", 0.88)
mel.connect_material_property(roughness, "", unreal.MaterialProperty.MP_ROUGHNESS)
if translucent:
opacity_param = mel.create_material_expression(material, unreal.MaterialExpressionScalarParameter, -500, 160)
opacity_param.set_editor_property("parameter_name", "WireOpacity")
opacity_param.set_editor_property("default_value", opacity)
mel.connect_material_property(opacity_param, "", unreal.MaterialProperty.MP_OPACITY)
mel.recompile_material(material)
unreal.EditorAssetLibrary.save_loaded_asset(material)
return material
def main():
material = create_led_material()
unreal.log(f"Created LED material: {material.get_path_name()}")
@ -357,6 +400,12 @@ def main():
unreal.log(f"Created GPU LED material: {gpu_material.get_path_name()}")
raymarch_material = create_raymarch_volume_material()
unreal.log(f"Created GPU raymarch material: {raymarch_material.get_path_name()}")
cabinet_material = create_physical_solid_material("M_PhysicalCabinet", unreal.LinearColor(0.005, 0.005, 0.004, 1.0), False, 1.0)
unreal.log(f"Created physical cabinet material: {cabinet_material.get_path_name()}")
wire_material = create_physical_solid_material("M_PhysicalWire", unreal.LinearColor(0.92, 0.92, 0.86, 0.62), True, 0.62)
unreal.log(f"Created physical wire material: {wire_material.get_path_name()}")
fixer_material = create_physical_solid_material("M_PhysicalFixer", unreal.LinearColor(0.72, 0.72, 0.68, 0.86), True, 0.86)
unreal.log(f"Created physical fixer material: {fixer_material.get_path_name()}")
if __name__ == "__main__":

View file

@ -124,12 +124,38 @@ def create_main_level():
display_class = load_class("/Script/ledcube3d.LedVolumeDisplayActor")
gpu_material = unreal.EditorAssetLibrary.load_asset("/Game/LedVolume/Materials/M_LedVoxelGpu")
raymarch_material = unreal.EditorAssetLibrary.load_asset("/Game/LedVolume/Materials/M_LedVolumeRaymarch")
cabinet_material = unreal.EditorAssetLibrary.load_asset("/Game/LedVolume/Materials/M_PhysicalCabinet")
wire_material = unreal.EditorAssetLibrary.load_asset("/Game/LedVolume/Materials/M_PhysicalWire")
fixer_material = unreal.EditorAssetLibrary.load_asset("/Game/LedVolume/Materials/M_PhysicalFixer")
display = spawn_actor(display_class, (0, 0, 150), (0, 0, 0))
display.set_actor_label("LED_Volume_Display")
set_prop(display, "Width", 32)
set_prop(display, "Height", 32)
set_prop(display, "Depth", 32)
set_prop(display, "GeometryMode", unreal.LedDisplayGeometryMode.PHYSICAL_MATRIX)
set_prop(display, "CabinetCountX", 20)
set_prop(display, "CabinetCountZ", 20)
set_prop(display, "DotsPerCabinetX", 6)
set_prop(display, "DotsPerCabinetZ", 6)
set_prop(display, "LedsPerString", 120)
set_prop(display, "CabinetSizeMm", 500.0)
set_prop(display, "DotPitchMm", 83.0)
set_prop(display, "PhysicalLedSizeMm", 18.0)
set_prop(display, "WireThicknessMm", 2.6)
set_prop(display, "WireOpacity", 0.62)
set_prop(display, "PhysicalJitterMm", 9.0)
set_prop(display, "WireSegmentsPerString", 12)
set_prop(display, "PhysicalRandomSeed", 1337)
set_prop(display, "bShowCabinets", False)
set_prop(display, "bShowWires", True)
set_prop(display, "bShowBottomFixers", True)
if cabinet_material:
set_prop(display, "CabinetMaterial", cabinet_material)
if wire_material:
set_prop(display, "WireMaterial", wire_material)
if fixer_material:
set_prop(display, "BottomFixerMaterial", fixer_material)
set_prop(display, "Width", 120)
set_prop(display, "Height", 120)
set_prop(display, "Depth", 120)
set_prop(display, "PixelSize", 4.0)
set_prop(display, "Spacing", 8.0)
set_prop(display, "PreviewStride", 2)
@ -137,7 +163,7 @@ def create_main_level():
set_prop(display, "Gamma", 1.0)
set_prop(display, "SourceMode", unreal.LedVolumeSourceMode.TEST_PATTERN)
set_prop(display, "TestPattern", unreal.LedTestPattern.RAINBOW_WAVE)
set_prop(display, "VoxelShape", unreal.LedVoxelShape.CUBE)
set_prop(display, "VoxelShape", unreal.LedVoxelShape.LENS)
if gpu_material:
set_prop(display, "LedMaterial", gpu_material)
if raymarch_material:
@ -152,9 +178,32 @@ def create_main_level():
controller = spawn_actor(controller_class, (-250, 0, 150), (0, 0, 0))
controller.set_actor_label("LED_Remote_Control")
set_prop(controller, "TargetActorLabel", "LED_Volume_Display")
set_prop(controller, "Width", 32)
set_prop(controller, "Height", 32)
set_prop(controller, "Depth", 32)
set_prop(controller, "GeometryMode", unreal.LedDisplayGeometryMode.PHYSICAL_MATRIX)
set_prop(controller, "CabinetCountX", 20)
set_prop(controller, "CabinetCountZ", 20)
set_prop(controller, "DotsPerCabinetX", 6)
set_prop(controller, "DotsPerCabinetZ", 6)
set_prop(controller, "LedsPerString", 120)
set_prop(controller, "CabinetSizeMm", 500.0)
set_prop(controller, "DotPitchMm", 83.0)
set_prop(controller, "PhysicalLedSizeMm", 18.0)
set_prop(controller, "WireThicknessMm", 2.6)
set_prop(controller, "WireOpacity", 0.62)
set_prop(controller, "PhysicalJitterMm", 9.0)
set_prop(controller, "WireSegmentsPerString", 12)
set_prop(controller, "PhysicalRandomSeed", 1337)
set_prop(controller, "bShowCabinets", False)
set_prop(controller, "bShowWires", True)
set_prop(controller, "bShowBottomFixers", True)
if cabinet_material:
set_prop(controller, "CabinetMaterial", cabinet_material)
if wire_material:
set_prop(controller, "WireMaterial", wire_material)
if fixer_material:
set_prop(controller, "BottomFixerMaterial", fixer_material)
set_prop(controller, "Width", 120)
set_prop(controller, "Height", 120)
set_prop(controller, "Depth", 120)
set_prop(controller, "PixelSize", 4.0)
set_prop(controller, "Spacing", 8.0)
set_prop(controller, "PreviewStride", 2)
@ -162,7 +211,7 @@ def create_main_level():
set_prop(controller, "Gamma", 1.0)
set_prop(controller, "SourceMode", unreal.LedVolumeSourceMode.TEST_PATTERN)
set_prop(controller, "TestPattern", unreal.LedTestPattern.RAINBOW_WAVE)
set_prop(controller, "VoxelShape", unreal.LedVoxelShape.CUBE)
set_prop(controller, "VoxelShape", unreal.LedVoxelShape.LENS)
if gpu_material:
set_prop(controller, "LedMaterial", gpu_material)
set_prop(controller, "bAnimateInEditor", False)

View file

@ -65,10 +65,32 @@ def expose_all(preset, controller):
"PixelSize",
"Spacing",
"PreviewStride",
"VoxelShape",
"CustomVoxelMesh",
],
"LED Physical Matrix": [
"GeometryMode",
"CabinetCountX",
"CabinetCountZ",
"DotsPerCabinetX",
"DotsPerCabinetZ",
"LedsPerString",
"CabinetSizeMm",
"DotPitchMm",
"PhysicalLedSizeMm",
"WireThicknessMm",
"WireOpacity",
"PhysicalJitterMm",
"WireSegmentsPerString",
"PhysicalRandomSeed",
"bShowCabinets",
"bShowWires",
"bShowBottomFixers",
"CabinetMaterial",
"WireMaterial",
"BottomFixerMaterial",
],
"LED Appearance": [
"VoxelShape",
"CustomVoxelMesh",
"LedMaterial",
"Brightness",
"Gamma",

View file

@ -74,6 +74,36 @@ ALedVolumeDisplayActor::ALedVolumeDisplayActor()
GpuVoxelInstances->NumCustomDataFloats = 0;
GpuVoxelInstances->SetCullDistances(0, 0);
PhysicalWireInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("PhysicalWireInstances"));
PhysicalWireInstances->SetupAttachment(VoxelInstances);
PhysicalWireInstances->SetCollisionEnabled(ECollisionEnabled::NoCollision);
PhysicalWireInstances->SetCanEverAffectNavigation(false);
PhysicalWireInstances->bCastDynamicShadow = false;
PhysicalWireInstances->CastShadow = false;
PhysicalWireInstances->SetHiddenInGame(true);
PhysicalWireInstances->SetVisibility(false);
PhysicalWireInstances->SetCullDistances(0, 0);
PhysicalCabinetInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("PhysicalCabinetInstances"));
PhysicalCabinetInstances->SetupAttachment(VoxelInstances);
PhysicalCabinetInstances->SetCollisionEnabled(ECollisionEnabled::NoCollision);
PhysicalCabinetInstances->SetCanEverAffectNavigation(false);
PhysicalCabinetInstances->bCastDynamicShadow = false;
PhysicalCabinetInstances->CastShadow = false;
PhysicalCabinetInstances->SetHiddenInGame(true);
PhysicalCabinetInstances->SetVisibility(false);
PhysicalCabinetInstances->SetCullDistances(0, 0);
PhysicalBottomFixerInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("PhysicalBottomFixerInstances"));
PhysicalBottomFixerInstances->SetupAttachment(VoxelInstances);
PhysicalBottomFixerInstances->SetCollisionEnabled(ECollisionEnabled::NoCollision);
PhysicalBottomFixerInstances->SetCanEverAffectNavigation(false);
PhysicalBottomFixerInstances->bCastDynamicShadow = false;
PhysicalBottomFixerInstances->CastShadow = false;
PhysicalBottomFixerInstances->SetHiddenInGame(true);
PhysicalBottomFixerInstances->SetVisibility(false);
PhysicalBottomFixerInstances->SetCullDistances(0, 0);
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultSphereMesh(TEXT("/Engine/BasicShapes/Sphere.Sphere"));
if (DefaultSphereMesh.Succeeded())
{
@ -103,6 +133,13 @@ ALedVolumeDisplayActor::ALedVolumeDisplayActor()
if (DefaultCubeMesh.Succeeded())
{
GpuVoxelInstances->SetStaticMesh(DefaultCubeMesh.Object);
PhysicalCabinetInstances->SetStaticMesh(DefaultCubeMesh.Object);
}
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultCylinderMesh(TEXT("/Engine/BasicShapes/Cylinder.Cylinder"));
if (DefaultCylinderMesh.Succeeded())
{
PhysicalWireInstances->SetStaticMesh(DefaultCylinderMesh.Object);
PhysicalBottomFixerInstances->SetStaticMesh(DefaultCylinderMesh.Object);
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultGpuVolumeMaterial(TEXT("/Game/LedVolume/Materials/M_LedVolumeRaymarch.M_LedVolumeRaymarch"));
@ -110,11 +147,66 @@ ALedVolumeDisplayActor::ALedVolumeDisplayActor()
{
GpuVolumeMaterial = DefaultGpuVolumeMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultCabinetMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalCabinet.M_PhysicalCabinet"));
if (DefaultCabinetMaterial.Succeeded())
{
CabinetMaterial = DefaultCabinetMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultWireMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalWire.M_PhysicalWire"));
if (DefaultWireMaterial.Succeeded())
{
WireMaterial = DefaultWireMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultFixerMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalFixer.M_PhysicalFixer"));
if (DefaultFixerMaterial.Succeeded())
{
BottomFixerMaterial = DefaultFixerMaterial.Object;
}
}
void ALedVolumeDisplayActor::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
#if WITH_EDITOR
if (GeometryMode == ELedDisplayGeometryMode::PhysicalMatrix)
{
if (const UWorld* World = GetWorld(); World && !World->IsGameWorld())
{
SyncDimensionsFromLayoutProperties();
if (VoxelInstances)
{
VoxelInstances->ClearInstances();
VoxelInstances->SetVisibility(false);
}
if (GpuVoxelInstances)
{
GpuVoxelInstances->ClearInstances();
GpuVoxelInstances->SetVisibility(false);
}
if (PhysicalWireInstances)
{
PhysicalWireInstances->ClearInstances();
PhysicalWireInstances->SetVisibility(false);
}
if (PhysicalCabinetInstances)
{
PhysicalCabinetInstances->ClearInstances();
PhysicalCabinetInstances->SetVisibility(false);
}
if (PhysicalBottomFixerInstances)
{
PhysicalBottomFixerInstances->ClearInstances();
PhysicalBottomFixerInstances->SetVisibility(false);
}
CacheCurrentSettings();
return;
}
}
#endif
RebuildDisplay();
}
@ -172,6 +264,18 @@ void ALedVolumeDisplayActor::RebuildDisplay()
PreviewStride = FMath::Clamp(PreviewStride, 1, 16);
PixelSize = FMath::Max(0.01f, PixelSize);
Spacing = FMath::Max(0.01f, Spacing);
CabinetCountX = FMath::Clamp(CabinetCountX, 1, 64);
CabinetCountZ = FMath::Clamp(CabinetCountZ, 1, 64);
DotsPerCabinetX = FMath::Clamp(DotsPerCabinetX, 1, 16);
DotsPerCabinetZ = FMath::Clamp(DotsPerCabinetZ, 1, 16);
LedsPerString = FMath::Clamp(LedsPerString, 1, 256);
CabinetSizeMm = FMath::Max(1.0f, CabinetSizeMm);
DotPitchMm = FMath::Max(1.0f, DotPitchMm);
PhysicalLedSizeMm = FMath::Max(0.1f, PhysicalLedSizeMm);
WireThicknessMm = FMath::Max(0.1f, WireThicknessMm);
WireOpacity = FMath::Clamp(WireOpacity, 0.0f, 1.0f);
PhysicalJitterMm = FMath::Max(0.0f, PhysicalJitterMm);
WireSegmentsPerString = FMath::Clamp(WireSegmentsPerString, 1, 32);
RebuildGeometry();
UpdateMaterialParameters();
@ -408,6 +512,26 @@ bool ALedVolumeDisplayActor::MirrorEditorRemoteControlStateForPIE()
PixelSize = EditorSource->PixelSize;
Spacing = EditorSource->Spacing;
PreviewStride = EditorSource->PreviewStride;
GeometryMode = EditorSource->GeometryMode;
CabinetCountX = EditorSource->CabinetCountX;
CabinetCountZ = EditorSource->CabinetCountZ;
DotsPerCabinetX = EditorSource->DotsPerCabinetX;
DotsPerCabinetZ = EditorSource->DotsPerCabinetZ;
LedsPerString = EditorSource->LedsPerString;
CabinetSizeMm = EditorSource->CabinetSizeMm;
DotPitchMm = EditorSource->DotPitchMm;
PhysicalLedSizeMm = EditorSource->PhysicalLedSizeMm;
WireThicknessMm = EditorSource->WireThicknessMm;
WireOpacity = EditorSource->WireOpacity;
PhysicalJitterMm = EditorSource->PhysicalJitterMm;
WireSegmentsPerString = EditorSource->WireSegmentsPerString;
PhysicalRandomSeed = EditorSource->PhysicalRandomSeed;
bShowCabinets = EditorSource->bShowCabinets;
bShowWires = EditorSource->bShowWires;
bShowBottomFixers = EditorSource->bShowBottomFixers;
CabinetMaterial = EditorSource->CabinetMaterial;
WireMaterial = EditorSource->WireMaterial;
BottomFixerMaterial = EditorSource->BottomFixerMaterial;
VoxelShape = EditorSource->VoxelShape;
CustomVoxelMesh = EditorSource->CustomVoxelMesh;
LedMaterial = EditorSource->LedMaterial;
@ -445,6 +569,26 @@ void ALedVolumeDisplayActor::CacheCurrentSettings()
CachedPixelSize = PixelSize;
CachedSpacing = Spacing;
CachedPreviewStride = PreviewStride;
CachedGeometryMode = GeometryMode;
CachedCabinetCountX = CabinetCountX;
CachedCabinetCountZ = CabinetCountZ;
CachedDotsPerCabinetX = DotsPerCabinetX;
CachedDotsPerCabinetZ = DotsPerCabinetZ;
CachedLedsPerString = LedsPerString;
CachedCabinetSizeMm = CabinetSizeMm;
CachedDotPitchMm = DotPitchMm;
CachedPhysicalLedSizeMm = PhysicalLedSizeMm;
CachedWireThicknessMm = WireThicknessMm;
CachedWireOpacity = WireOpacity;
CachedPhysicalJitterMm = PhysicalJitterMm;
CachedWireSegmentsPerString = WireSegmentsPerString;
CachedPhysicalRandomSeed = PhysicalRandomSeed;
bCachedShowCabinets = bShowCabinets;
bCachedShowWires = bShowWires;
bCachedShowBottomFixers = bShowBottomFixers;
CachedCabinetMaterial = CabinetMaterial;
CachedWireMaterial = WireMaterial;
CachedBottomFixerMaterial = BottomFixerMaterial;
CachedVoxelShape = VoxelShape;
CachedCustomVoxelMesh = CustomVoxelMesh;
CachedLedMaterial = LedMaterial;
@ -469,6 +613,26 @@ bool ALedVolumeDisplayActor::HasLayoutChanged() const
|| !FMath::IsNearlyEqual(CachedPixelSize, PixelSize)
|| !FMath::IsNearlyEqual(CachedSpacing, Spacing)
|| CachedPreviewStride != PreviewStride
|| CachedGeometryMode != GeometryMode
|| CachedCabinetCountX != CabinetCountX
|| CachedCabinetCountZ != CabinetCountZ
|| CachedDotsPerCabinetX != DotsPerCabinetX
|| CachedDotsPerCabinetZ != DotsPerCabinetZ
|| CachedLedsPerString != LedsPerString
|| !FMath::IsNearlyEqual(CachedCabinetSizeMm, CabinetSizeMm)
|| !FMath::IsNearlyEqual(CachedDotPitchMm, DotPitchMm)
|| !FMath::IsNearlyEqual(CachedPhysicalLedSizeMm, PhysicalLedSizeMm)
|| !FMath::IsNearlyEqual(CachedWireThicknessMm, WireThicknessMm)
|| !FMath::IsNearlyEqual(CachedWireOpacity, WireOpacity)
|| !FMath::IsNearlyEqual(CachedPhysicalJitterMm, PhysicalJitterMm)
|| CachedWireSegmentsPerString != WireSegmentsPerString
|| CachedPhysicalRandomSeed != PhysicalRandomSeed
|| bCachedShowCabinets != bShowCabinets
|| bCachedShowWires != bShowWires
|| bCachedShowBottomFixers != bShowBottomFixers
|| CachedCabinetMaterial != CabinetMaterial
|| CachedWireMaterial != WireMaterial
|| CachedBottomFixerMaterial != BottomFixerMaterial
|| CachedVoxelShape != VoxelShape
|| CachedCustomVoxelMesh != CustomVoxelMesh
|| CachedLedMaterial != LedMaterial
@ -480,6 +644,12 @@ void ALedVolumeDisplayActor::SyncDimensionsFromLayoutProperties()
Width = FMath::Clamp(Width, 1, 128);
Height = FMath::Clamp(Height, 1, 128);
Depth = FMath::Clamp(Depth, 1, 128);
if (GeometryMode == ELedDisplayGeometryMode::PhysicalMatrix)
{
Width = FMath::Clamp(CabinetCountX * DotsPerCabinetX, 1, 128);
Height = FMath::Clamp(LedsPerString, 1, 128);
Depth = FMath::Clamp(CabinetCountZ * DotsPerCabinetZ, 1, 128);
}
Dimensions.Width = Width;
Dimensions.Height = Height;
Dimensions.Depth = Depth;
@ -568,8 +738,10 @@ void ALedVolumeDisplayActor::RebuildGeometry()
}
VoxelInstances->ClearInstances();
VoxelInstances->SetVisibility(!IsGpuTestPatternActive());
VoxelInstances->SetHiddenInGame(IsGpuTestPatternActive());
const bool bUsePhysicalMatrix = GeometryMode == ELedDisplayGeometryMode::PhysicalMatrix;
const bool bUseGpuGeometry = IsGpuTestPatternActive() || bUsePhysicalMatrix;
VoxelInstances->SetVisibility(!bUseGpuGeometry);
VoxelInstances->SetHiddenInGame(bUseGpuGeometry);
if (GpuVolumeProxy)
{
GpuVolumeProxy->SetVisibility(false);
@ -577,8 +749,32 @@ void ALedVolumeDisplayActor::RebuildGeometry()
}
if (GpuVoxelInstances)
{
GpuVoxelInstances->SetVisibility(IsGpuTestPatternActive());
GpuVoxelInstances->SetHiddenInGame(!IsGpuTestPatternActive());
GpuVoxelInstances->SetVisibility(bUseGpuGeometry);
GpuVoxelInstances->SetHiddenInGame(!bUseGpuGeometry);
}
if (PhysicalWireInstances)
{
PhysicalWireInstances->SetVisibility(bUsePhysicalMatrix && bShowWires);
PhysicalWireInstances->SetHiddenInGame(!(bUsePhysicalMatrix && bShowWires));
}
if (PhysicalCabinetInstances)
{
PhysicalCabinetInstances->SetVisibility(bUsePhysicalMatrix && bShowCabinets);
PhysicalCabinetInstances->SetHiddenInGame(!(bUsePhysicalMatrix && bShowCabinets));
}
if (PhysicalBottomFixerInstances)
{
PhysicalBottomFixerInstances->SetVisibility(bUsePhysicalMatrix && bShowBottomFixers);
PhysicalBottomFixerInstances->SetHiddenInGame(!(bUsePhysicalMatrix && bShowBottomFixers));
}
if (bUsePhysicalMatrix)
{
RebuildPhysicalMatrixInstances();
RenderedVoxelToBufferIndex.Reset();
LastRenderedColors.Reset();
bGeometryDirty = false;
bColorsDirty = false;
return;
}
if (IsGpuTestPatternActive())
{
@ -714,6 +910,158 @@ void ALedVolumeDisplayActor::RebuildGpuVoxelInstances()
}
}
void ALedVolumeDisplayActor::RebuildPhysicalMatrixInstances()
{
if (!GpuVoxelInstances)
{
return;
}
const int64 RequestedCount = Dimensions.NumVoxels();
if (RequestedCount <= 0 || RequestedCount > TNumericLimits<int32>::Max())
{
GpuVoxelInstances->ClearInstances();
return;
}
const float LedScale = (PhysicalLedSizeMm * 0.1f) / 100.0f;
const FVector LedInstanceScale = VoxelShape == ELedVoxelShape::Lens
? FVector(LedScale, LedScale, LedScale * 0.45f)
: FVector(LedScale);
GpuVoxelInstances->SetStaticMesh(ResolveVoxelMesh());
if (LedMaterial)
{
GpuVoxelInstances->SetMaterial(0, LedMaterial);
GpuVoxelMID = nullptr;
}
GpuVoxelInstances->ClearInstances();
GpuVoxelInstances->PreAllocateInstancesMemory(static_cast<int32>(RequestedCount));
constexpr int32 LedBatchSize = 32768;
TArray<FTransform> LedBatch;
LedBatch.Reserve(LedBatchSize);
for (int32 Z = 0; Z < Dimensions.Depth; ++Z)
{
for (int32 Y = 0; Y < Dimensions.Height; ++Y)
{
for (int32 X = 0; X < Dimensions.Width; ++X)
{
LedBatch.Emplace(FRotator::ZeroRotator, PhysicalLedLocalPosition(X, Y, Z), LedInstanceScale);
if (LedBatch.Num() == LedBatchSize)
{
GpuVoxelInstances->AddInstances(LedBatch, false, false, false);
LedBatch.Reset();
}
}
}
}
if (!LedBatch.IsEmpty())
{
GpuVoxelInstances->AddInstances(LedBatch, false, false, false);
}
if (PhysicalWireInstances)
{
PhysicalWireInstances->ClearInstances();
if (bShowWires)
{
if (WireMaterial)
{
PhysicalWireInstances->SetMaterial(0, WireMaterial);
WireMID = nullptr;
}
const int32 SegmentCount = FMath::Clamp(WireSegmentsPerString, 1, 32);
PhysicalWireInstances->PreAllocateInstancesMemory(Dimensions.Width * Dimensions.Depth * SegmentCount);
const float WireRadiusScale = (WireThicknessMm * 0.1f) / 100.0f;
for (int32 Z = 0; Z < Dimensions.Depth; ++Z)
{
for (int32 X = 0; X < Dimensions.Width; ++X)
{
for (int32 SegmentIndex = 0; SegmentIndex < SegmentCount; ++SegmentIndex)
{
const float AlphaA = static_cast<float>(SegmentIndex) / static_cast<float>(SegmentCount);
const float AlphaB = static_cast<float>(SegmentIndex + 1) / static_cast<float>(SegmentCount);
const FVector Start = PhysicalWireLocalPosition(X, AlphaA, Z);
const FVector End = PhysicalWireLocalPosition(X, AlphaB, Z);
const FVector Segment = End - Start;
const float Length = Segment.Size();
if (Length <= UE_KINDA_SMALL_NUMBER)
{
continue;
}
const FQuat Rotation = FQuat::FindBetweenNormals(FVector::UpVector, Segment / Length);
const FVector Location = (Start + End) * 0.5f;
const FVector Scale(WireRadiusScale, WireRadiusScale, Length / 100.0f);
PhysicalWireInstances->AddInstance(FTransform(Rotation, Location, Scale));
}
}
}
}
}
if (PhysicalCabinetInstances)
{
PhysicalCabinetInstances->ClearInstances();
if (bShowCabinets)
{
if (CabinetMaterial)
{
PhysicalCabinetInstances->SetMaterial(0, CabinetMaterial);
}
const float CabinetSizeCm = CabinetSizeMm * 0.1f;
const float ModuleSizeCm = CabinetSizeCm * 0.5f;
const float ThicknessCm = FMath::Max(2.0f, CabinetSizeCm * 0.055f);
const float TotalX = CabinetCountX * CabinetSizeCm;
const float TotalY = CabinetCountZ * CabinetSizeCm;
const FVector ModuleScale(ModuleSizeCm / 100.0f * 0.985f, ModuleSizeCm / 100.0f * 0.985f, ThicknessCm / 100.0f);
PhysicalCabinetInstances->PreAllocateInstancesMemory(CabinetCountX * CabinetCountZ * 4);
for (int32 CabinetZ = 0; CabinetZ < CabinetCountZ; ++CabinetZ)
{
for (int32 CabinetX = 0; CabinetX < CabinetCountX; ++CabinetX)
{
const float BaseX = CabinetX * CabinetSizeCm - TotalX * 0.5f + CabinetSizeCm * 0.5f;
const float BaseY = CabinetZ * CabinetSizeCm - TotalY * 0.5f + CabinetSizeCm * 0.5f;
for (int32 ModuleZ = 0; ModuleZ < 2; ++ModuleZ)
{
for (int32 ModuleX = 0; ModuleX < 2; ++ModuleX)
{
const FVector Location(
BaseX + (ModuleX == 0 ? -ModuleSizeCm : ModuleSizeCm) * 0.25f,
BaseY + (ModuleZ == 0 ? -ModuleSizeCm : ModuleSizeCm) * 0.25f,
ThicknessCm * 0.5f);
PhysicalCabinetInstances->AddInstance(FTransform(FRotator::ZeroRotator, Location, ModuleScale));
}
}
}
}
}
}
if (PhysicalBottomFixerInstances)
{
PhysicalBottomFixerInstances->ClearInstances();
if (bShowBottomFixers)
{
if (BottomFixerMaterial)
{
PhysicalBottomFixerInstances->SetMaterial(0, BottomFixerMaterial);
}
const float RadiusScale = FMath::Max((PhysicalLedSizeMm * 0.16f * 0.1f) / 100.0f, 0.005f);
const float HeightScale = FMath::Max((PhysicalLedSizeMm * 0.22f * 0.1f) / 100.0f, 0.006f);
PhysicalBottomFixerInstances->PreAllocateInstancesMemory(Dimensions.Width * Dimensions.Depth);
for (int32 Z = 0; Z < Dimensions.Depth; ++Z)
{
for (int32 X = 0; X < Dimensions.Width; ++X)
{
const FVector Bottom = PhysicalStringBottomLocalPosition(X, Z);
PhysicalBottomFixerInstances->AddInstance(FTransform(FRotator::ZeroRotator, Bottom - FVector(0.0f, 0.0f, PhysicalLedSizeMm * 0.03f), FVector(RadiusScale, RadiusScale, HeightScale)));
}
}
}
}
}
void ALedVolumeDisplayActor::EnsureVoxelBuffer()
{
const int64 NumVoxels64 = Dimensions.NumVoxels();
@ -793,7 +1141,21 @@ void ALedVolumeDisplayActor::UpdateMaterialParameters()
GpuVoxelMID->SetVectorParameterValue(LedColorParameterName, SolidColor);
GpuVoxelMID->SetScalarParameterValue(AnimationSpeedParameterName, AnimationSpeed);
GpuVoxelMID->SetScalarParameterValue(PatternModeParameterName, static_cast<float>(static_cast<uint8>(TestPattern)));
GpuVoxelMID->SetScalarParameterValue(VoxelSpacingParameterName, Spacing);
GpuVoxelMID->SetScalarParameterValue(VoxelSpacingParameterName,
GeometryMode == ELedDisplayGeometryMode::PhysicalMatrix ? DotPitchMm * 0.1f : Spacing);
}
}
if (PhysicalWireInstances)
{
if (!WireMID && WireMaterial)
{
WireMID = PhysicalWireInstances->CreateAndSetMaterialInstanceDynamic(0);
}
if (WireMID)
{
WireMID->SetScalarParameterValue(TEXT("WireOpacity"), WireOpacity);
WireMID->SetVectorParameterValue(TEXT("WireColor"), FLinearColor(0.92f, 0.92f, 0.86f, WireOpacity));
}
}
}
@ -931,6 +1293,81 @@ FVector ALedVolumeDisplayActor::VoxelIndexToLocalPosition(int32 X, int32 Y, int3
Y * Spacing - CenterOffset.Z);
}
FVector ALedVolumeDisplayActor::PhysicalStringTopLocalPosition(int32 X, int32 Z) const
{
const float PitchCm = DotPitchMm * 0.1f;
const FVector CenterOffset(
(Dimensions.Width - 1) * PitchCm * 0.5f,
(Dimensions.Depth - 1) * PitchCm * 0.5f,
0.0f);
const float StringJitterCm = PhysicalJitterMm * 0.1f * 0.18f;
const FVector Jitter = PhysicalStableJitter(X, 0, Z, StringJitterCm);
return FVector(
X * PitchCm - CenterOffset.X + Jitter.X,
Z * PitchCm - CenterOffset.Y + Jitter.Y,
0.0f);
}
FVector ALedVolumeDisplayActor::PhysicalStringBottomLocalPosition(int32 X, int32 Z) const
{
const float PitchCm = DotPitchMm * 0.1f;
const float DropCm = (Dimensions.Height - 1) * PitchCm;
const float StringJitterCm = PhysicalJitterMm * 0.1f * 0.52f;
const FVector Jitter = PhysicalStableJitter(X, Dimensions.Height + 17, Z, StringJitterCm);
return PhysicalStringTopLocalPosition(X, Z) + FVector(Jitter.X, Jitter.Y, -DropCm + Jitter.Z * 0.12f);
}
FVector ALedVolumeDisplayActor::PhysicalWireLocalPosition(int32 X, float Alpha, int32 Z) const
{
const FVector Top = PhysicalStringTopLocalPosition(X, Z);
const FVector Bottom = PhysicalStringBottomLocalPosition(X, Z);
const float ClampedAlpha = FMath::Clamp(Alpha, 0.0f, 1.0f);
const FVector Straight = FMath::Lerp(Top, Bottom, ClampedAlpha);
const float SwayAmountCm = PhysicalJitterMm * 0.1f * 0.46f;
const FVector Phase = PhysicalStableJitter(X, 911, Z, 1.0f);
const float WaveA = FMath::Sin((ClampedAlpha * 2.0f + Phase.X) * PI);
const float WaveB = FMath::Sin((ClampedAlpha * 3.0f + Phase.Y) * PI);
const float EndFade = FMath::Sin(ClampedAlpha * PI);
return Straight + FVector(WaveA * SwayAmountCm * EndFade, WaveB * SwayAmountCm * EndFade, 0.0f);
}
FVector ALedVolumeDisplayActor::PhysicalLedLocalPosition(int32 X, int32 Y, int32 Z) const
{
const float Alpha = Dimensions.Height > 1 ? static_cast<float>(Y) / static_cast<float>(Dimensions.Height - 1) : 0.0f;
const FVector OnWire = PhysicalWireLocalPosition(X, Alpha, Z);
const float BeadSlideCm = PhysicalJitterMm * 0.1f * 0.08f;
const FVector BeadJitter = PhysicalStableJitter(X, Y, Z, BeadSlideCm);
return OnWire + FVector(0.0f, 0.0f, BeadJitter.Z);
}
FVector ALedVolumeDisplayActor::PhysicalStableJitter(int32 X, int32 Y, int32 Z, float AmountCm) const
{
if (AmountCm <= 0.0f)
{
return FVector::ZeroVector;
}
auto Unit = [](uint32 Value) -> float
{
Value ^= Value >> 16;
Value *= 0x7feb352dU;
Value ^= Value >> 15;
Value *= 0x846ca68bU;
Value ^= Value >> 16;
return static_cast<float>(Value & 0x00ffffffU) / static_cast<float>(0x00ffffffU);
};
const uint32 Seed = static_cast<uint32>(PhysicalRandomSeed);
const uint32 Base = Seed
^ static_cast<uint32>(X * 73856093)
^ static_cast<uint32>(Y * 19349663)
^ static_cast<uint32>(Z * 83492791);
return FVector(
(Unit(Base ^ 0x1234abcdU) * 2.0f - 1.0f) * AmountCm,
(Unit(Base ^ 0x88ff0137U) * 2.0f - 1.0f) * AmountCm,
(Unit(Base ^ 0x45d9f3bU) * 2.0f - 1.0f) * AmountCm);
}
FLinearColor ALedVolumeDisplayActor::SampleTestPattern(int32 X, int32 Y, int32 Z) const
{
const float NX = Dimensions.Width > 1 ? static_cast<float>(X) / static_cast<float>(Dimensions.Width - 1) : 0.0f;

View file

@ -53,8 +53,68 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Layout", meta = (ClampMin = "1", ClampMax = "16"))
int32 PreviewStride = 2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
ELedDisplayGeometryMode GeometryMode = ELedDisplayGeometryMode::PhysicalMatrix;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "64"))
int32 CabinetCountX = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "64"))
int32 CabinetCountZ = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "16"))
int32 DotsPerCabinetX = 6;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "16"))
int32 DotsPerCabinetZ = 6;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "256"))
int32 LedsPerString = 120;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1.0"))
float CabinetSizeMm = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1.0"))
float DotPitchMm = 83.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "0.1"))
float PhysicalLedSizeMm = 18.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "0.1"))
float WireThicknessMm = 2.6f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "0.0", ClampMax = "1.0"))
float WireOpacity = 0.62f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "0.0"))
float PhysicalJitterMm = 9.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix", meta = (ClampMin = "1", ClampMax = "32"))
int32 WireSegmentsPerString = 12;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
int32 PhysicalRandomSeed = 1337;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
bool bShowCabinets = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
bool bShowWires = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
bool bShowBottomFixers = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
TObjectPtr<UMaterialInterface> CabinetMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
TObjectPtr<UMaterialInterface> WireMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Physical Matrix")
TObjectPtr<UMaterialInterface> BottomFixerMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Appearance")
ELedVoxelShape VoxelShape = ELedVoxelShape::Cube;
ELedVoxelShape VoxelShape = ELedVoxelShape::Lens;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Volume|Appearance", meta = (EditCondition = "VoxelShape == ELedVoxelShape::CustomMesh", EditConditionHides))
TObjectPtr<UStaticMesh> CustomVoxelMesh;
@ -180,12 +240,24 @@ private:
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UInstancedStaticMeshComponent> GpuVoxelInstances;
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UInstancedStaticMeshComponent> PhysicalWireInstances;
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UInstancedStaticMeshComponent> PhysicalCabinetInstances;
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UInstancedStaticMeshComponent> PhysicalBottomFixerInstances;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> GpuVolumeMID;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> GpuVoxelMID;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> WireMID;
UPROPERTY(Transient)
TArray<FLinearColor> VoxelBuffer;
@ -202,6 +274,26 @@ private:
float CachedPixelSize = 0.0f;
float CachedSpacing = 0.0f;
int32 CachedPreviewStride = 0;
ELedDisplayGeometryMode CachedGeometryMode = ELedDisplayGeometryMode::VoxelGrid;
int32 CachedCabinetCountX = 0;
int32 CachedCabinetCountZ = 0;
int32 CachedDotsPerCabinetX = 0;
int32 CachedDotsPerCabinetZ = 0;
int32 CachedLedsPerString = 0;
float CachedCabinetSizeMm = 0.0f;
float CachedDotPitchMm = 0.0f;
float CachedPhysicalLedSizeMm = 0.0f;
float CachedWireThicknessMm = 0.0f;
float CachedWireOpacity = -1.0f;
float CachedPhysicalJitterMm = -1.0f;
int32 CachedWireSegmentsPerString = 0;
int32 CachedPhysicalRandomSeed = 0;
bool bCachedShowCabinets = false;
bool bCachedShowWires = false;
bool bCachedShowBottomFixers = false;
TObjectPtr<UMaterialInterface> CachedCabinetMaterial;
TObjectPtr<UMaterialInterface> CachedWireMaterial;
TObjectPtr<UMaterialInterface> CachedBottomFixerMaterial;
ELedVoxelShape CachedVoxelShape = ELedVoxelShape::Cube;
TObjectPtr<UStaticMesh> CachedCustomVoxelMesh;
TObjectPtr<UMaterialInterface> CachedLedMaterial;
@ -234,6 +326,7 @@ private:
bool IsGpuTestPatternActive() const;
void UpdateGpuVolumeProxyTransform();
void RebuildGpuVoxelInstances();
void RebuildPhysicalMatrixInstances();
void RebuildGeometry();
void EnsureVoxelBuffer();
void UpdateMaterialParameters();
@ -247,6 +340,11 @@ private:
int32 ToBufferIndex(int32 X, int32 Y, int32 Z) const;
void FromBufferIndex(int32 BufferIndex, int32& OutX, int32& OutY, int32& OutZ) const;
FVector VoxelIndexToLocalPosition(int32 X, int32 Y, int32 Z) const;
FVector PhysicalLedLocalPosition(int32 X, int32 Y, int32 Z) const;
FVector PhysicalWireLocalPosition(int32 X, float Alpha, int32 Z) const;
FVector PhysicalStringTopLocalPosition(int32 X, int32 Z) const;
FVector PhysicalStringBottomLocalPosition(int32 X, int32 Z) const;
FVector PhysicalStableJitter(int32 X, int32 Y, int32 Z, float AmountCm) const;
FLinearColor SampleTestPattern(int32 X, int32 Y, int32 Z) const;
FLinearColor SampleWorldVoxelColor(const FVector& WorldPosition) const;
UStaticMesh* ResolveVoxelMesh() const;

View file

@ -19,6 +19,21 @@ ALedVolumeRemoteControlActor::ALedVolumeRemoteControlActor()
{
LedMaterial = DefaultLedMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultCabinetMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalCabinet.M_PhysicalCabinet"));
if (DefaultCabinetMaterial.Succeeded())
{
CabinetMaterial = DefaultCabinetMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultWireMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalWire.M_PhysicalWire"));
if (DefaultWireMaterial.Succeeded())
{
WireMaterial = DefaultWireMaterial.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultFixerMaterial(TEXT("/Game/LedVolume/Materials/M_PhysicalFixer.M_PhysicalFixer"));
if (DefaultFixerMaterial.Succeeded())
{
BottomFixerMaterial = DefaultFixerMaterial.Object;
}
}
void ALedVolumeRemoteControlActor::BeginPlay()
@ -106,6 +121,49 @@ void ALedVolumeRemoteControlActor::ApplyToTarget()
Target->PreviewStride = PreviewStride;
bNeedsRebuild = true;
}
if (Target->GeometryMode != GeometryMode
|| Target->CabinetCountX != CabinetCountX
|| Target->CabinetCountZ != CabinetCountZ
|| Target->DotsPerCabinetX != DotsPerCabinetX
|| Target->DotsPerCabinetZ != DotsPerCabinetZ
|| Target->LedsPerString != LedsPerString
|| !FMath::IsNearlyEqual(Target->CabinetSizeMm, CabinetSizeMm)
|| !FMath::IsNearlyEqual(Target->DotPitchMm, DotPitchMm)
|| !FMath::IsNearlyEqual(Target->PhysicalLedSizeMm, PhysicalLedSizeMm)
|| !FMath::IsNearlyEqual(Target->WireThicknessMm, WireThicknessMm)
|| !FMath::IsNearlyEqual(Target->WireOpacity, WireOpacity)
|| !FMath::IsNearlyEqual(Target->PhysicalJitterMm, PhysicalJitterMm)
|| Target->WireSegmentsPerString != WireSegmentsPerString
|| Target->PhysicalRandomSeed != PhysicalRandomSeed
|| Target->bShowCabinets != bShowCabinets
|| Target->bShowWires != bShowWires
|| Target->bShowBottomFixers != bShowBottomFixers
|| Target->CabinetMaterial != CabinetMaterial
|| Target->WireMaterial != WireMaterial
|| Target->BottomFixerMaterial != BottomFixerMaterial)
{
Target->GeometryMode = GeometryMode;
Target->CabinetCountX = CabinetCountX;
Target->CabinetCountZ = CabinetCountZ;
Target->DotsPerCabinetX = DotsPerCabinetX;
Target->DotsPerCabinetZ = DotsPerCabinetZ;
Target->LedsPerString = LedsPerString;
Target->CabinetSizeMm = CabinetSizeMm;
Target->DotPitchMm = DotPitchMm;
Target->PhysicalLedSizeMm = PhysicalLedSizeMm;
Target->WireThicknessMm = WireThicknessMm;
Target->WireOpacity = WireOpacity;
Target->PhysicalJitterMm = PhysicalJitterMm;
Target->WireSegmentsPerString = WireSegmentsPerString;
Target->PhysicalRandomSeed = PhysicalRandomSeed;
Target->bShowCabinets = bShowCabinets;
Target->bShowWires = bShowWires;
Target->bShowBottomFixers = bShowBottomFixers;
Target->CabinetMaterial = CabinetMaterial;
Target->WireMaterial = WireMaterial;
Target->BottomFixerMaterial = BottomFixerMaterial;
bNeedsRebuild = true;
}
if (Target->VoxelShape != VoxelShape || Target->CustomVoxelMesh != CustomVoxelMesh || Target->LedMaterial != LedMaterial)
{
Target->VoxelShape = VoxelShape;
@ -177,6 +235,26 @@ void ALedVolumeRemoteControlActor::SyncFromTarget()
PixelSize = Target->PixelSize;
Spacing = Target->Spacing;
PreviewStride = Target->PreviewStride;
GeometryMode = Target->GeometryMode;
CabinetCountX = Target->CabinetCountX;
CabinetCountZ = Target->CabinetCountZ;
DotsPerCabinetX = Target->DotsPerCabinetX;
DotsPerCabinetZ = Target->DotsPerCabinetZ;
LedsPerString = Target->LedsPerString;
CabinetSizeMm = Target->CabinetSizeMm;
DotPitchMm = Target->DotPitchMm;
PhysicalLedSizeMm = Target->PhysicalLedSizeMm;
WireThicknessMm = Target->WireThicknessMm;
WireOpacity = Target->WireOpacity;
PhysicalJitterMm = Target->PhysicalJitterMm;
WireSegmentsPerString = Target->WireSegmentsPerString;
PhysicalRandomSeed = Target->PhysicalRandomSeed;
bShowCabinets = Target->bShowCabinets;
bShowWires = Target->bShowWires;
bShowBottomFixers = Target->bShowBottomFixers;
CabinetMaterial = Target->CabinetMaterial;
WireMaterial = Target->WireMaterial;
BottomFixerMaterial = Target->BottomFixerMaterial;
VoxelShape = Target->VoxelShape;
CustomVoxelMesh = Target->CustomVoxelMesh;
LedMaterial = Target->LedMaterial;
@ -408,6 +486,24 @@ void ALedVolumeRemoteControlActor::ClampSettings()
PixelSize = FMath::Max(0.01f, PixelSize);
Spacing = FMath::Max(0.01f, Spacing);
PreviewStride = FMath::Clamp(PreviewStride, 1, 16);
CabinetCountX = FMath::Clamp(CabinetCountX, 1, 64);
CabinetCountZ = FMath::Clamp(CabinetCountZ, 1, 64);
DotsPerCabinetX = FMath::Clamp(DotsPerCabinetX, 1, 16);
DotsPerCabinetZ = FMath::Clamp(DotsPerCabinetZ, 1, 16);
LedsPerString = FMath::Clamp(LedsPerString, 1, 256);
CabinetSizeMm = FMath::Max(1.0f, CabinetSizeMm);
DotPitchMm = FMath::Max(1.0f, DotPitchMm);
PhysicalLedSizeMm = FMath::Max(0.1f, PhysicalLedSizeMm);
WireThicknessMm = FMath::Max(0.1f, WireThicknessMm);
WireOpacity = FMath::Clamp(WireOpacity, 0.0f, 1.0f);
PhysicalJitterMm = FMath::Max(0.0f, PhysicalJitterMm);
WireSegmentsPerString = FMath::Clamp(WireSegmentsPerString, 1, 32);
if (GeometryMode == ELedDisplayGeometryMode::PhysicalMatrix)
{
Width = FMath::Clamp(CabinetCountX * DotsPerCabinetX, 1, 128);
Height = FMath::Clamp(LedsPerString, 1, 128);
Depth = FMath::Clamp(CabinetCountZ * DotsPerCabinetZ, 1, 128);
}
Brightness = FMath::Max(0.0f, Brightness);
Gamma = FMath::Clamp(Gamma, 0.1f, 5.0f);
MaxEditorInstances = FMath::Max(1024, MaxEditorInstances);
@ -431,6 +527,26 @@ void ALedVolumeRemoteControlActor::CacheSettings()
CachedPixelSize = PixelSize;
CachedSpacing = Spacing;
CachedPreviewStride = PreviewStride;
CachedGeometryMode = GeometryMode;
CachedCabinetCountX = CabinetCountX;
CachedCabinetCountZ = CabinetCountZ;
CachedDotsPerCabinetX = DotsPerCabinetX;
CachedDotsPerCabinetZ = DotsPerCabinetZ;
CachedLedsPerString = LedsPerString;
CachedCabinetSizeMm = CabinetSizeMm;
CachedDotPitchMm = DotPitchMm;
CachedPhysicalLedSizeMm = PhysicalLedSizeMm;
CachedWireThicknessMm = WireThicknessMm;
CachedWireOpacity = WireOpacity;
CachedPhysicalJitterMm = PhysicalJitterMm;
CachedWireSegmentsPerString = WireSegmentsPerString;
CachedPhysicalRandomSeed = PhysicalRandomSeed;
bCachedShowCabinets = bShowCabinets;
bCachedShowWires = bShowWires;
bCachedShowBottomFixers = bShowBottomFixers;
CachedCabinetMaterial = CabinetMaterial;
CachedWireMaterial = WireMaterial;
CachedBottomFixerMaterial = BottomFixerMaterial;
CachedVoxelShape = VoxelShape;
CachedCustomVoxelMesh = CustomVoxelMesh;
CachedLedMaterial = LedMaterial;
@ -464,6 +580,26 @@ bool ALedVolumeRemoteControlActor::HasSettingsChanged() const
|| !FMath::IsNearlyEqual(CachedPixelSize, PixelSize)
|| !FMath::IsNearlyEqual(CachedSpacing, Spacing)
|| CachedPreviewStride != PreviewStride
|| CachedGeometryMode != GeometryMode
|| CachedCabinetCountX != CabinetCountX
|| CachedCabinetCountZ != CabinetCountZ
|| CachedDotsPerCabinetX != DotsPerCabinetX
|| CachedDotsPerCabinetZ != DotsPerCabinetZ
|| CachedLedsPerString != LedsPerString
|| !FMath::IsNearlyEqual(CachedCabinetSizeMm, CabinetSizeMm)
|| !FMath::IsNearlyEqual(CachedDotPitchMm, DotPitchMm)
|| !FMath::IsNearlyEqual(CachedPhysicalLedSizeMm, PhysicalLedSizeMm)
|| !FMath::IsNearlyEqual(CachedWireThicknessMm, WireThicknessMm)
|| !FMath::IsNearlyEqual(CachedWireOpacity, WireOpacity)
|| !FMath::IsNearlyEqual(CachedPhysicalJitterMm, PhysicalJitterMm)
|| CachedWireSegmentsPerString != WireSegmentsPerString
|| CachedPhysicalRandomSeed != PhysicalRandomSeed
|| bCachedShowCabinets != bShowCabinets
|| bCachedShowWires != bShowWires
|| bCachedShowBottomFixers != bShowBottomFixers
|| CachedCabinetMaterial != CabinetMaterial
|| CachedWireMaterial != WireMaterial
|| CachedBottomFixerMaterial != BottomFixerMaterial
|| CachedVoxelShape != VoxelShape
|| CachedCustomVoxelMesh != CustomVoxelMesh
|| CachedLedMaterial != LedMaterial
@ -556,6 +692,26 @@ void ALedVolumeRemoteControlActor::MirrorEditorControllerStateForPIE()
PixelSize = EditorSource->PixelSize;
Spacing = EditorSource->Spacing;
PreviewStride = EditorSource->PreviewStride;
GeometryMode = EditorSource->GeometryMode;
CabinetCountX = EditorSource->CabinetCountX;
CabinetCountZ = EditorSource->CabinetCountZ;
DotsPerCabinetX = EditorSource->DotsPerCabinetX;
DotsPerCabinetZ = EditorSource->DotsPerCabinetZ;
LedsPerString = EditorSource->LedsPerString;
CabinetSizeMm = EditorSource->CabinetSizeMm;
DotPitchMm = EditorSource->DotPitchMm;
PhysicalLedSizeMm = EditorSource->PhysicalLedSizeMm;
WireThicknessMm = EditorSource->WireThicknessMm;
WireOpacity = EditorSource->WireOpacity;
PhysicalJitterMm = EditorSource->PhysicalJitterMm;
WireSegmentsPerString = EditorSource->WireSegmentsPerString;
PhysicalRandomSeed = EditorSource->PhysicalRandomSeed;
bShowCabinets = EditorSource->bShowCabinets;
bShowWires = EditorSource->bShowWires;
bShowBottomFixers = EditorSource->bShowBottomFixers;
CabinetMaterial = EditorSource->CabinetMaterial;
WireMaterial = EditorSource->WireMaterial;
BottomFixerMaterial = EditorSource->BottomFixerMaterial;
VoxelShape = EditorSource->VoxelShape;
CustomVoxelMesh = EditorSource->CustomVoxelMesh;
LedMaterial = EditorSource->LedMaterial;

View file

@ -50,8 +50,68 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter = SetPreviewStride, Category = "LED Control|Layout", meta = (ClampMin = "1", ClampMax = "16"))
int32 PreviewStride = 2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
ELedDisplayGeometryMode GeometryMode = ELedDisplayGeometryMode::PhysicalMatrix;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "64"))
int32 CabinetCountX = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "64"))
int32 CabinetCountZ = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "16"))
int32 DotsPerCabinetX = 6;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "16"))
int32 DotsPerCabinetZ = 6;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "256"))
int32 LedsPerString = 120;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1.0"))
float CabinetSizeMm = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1.0"))
float DotPitchMm = 83.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "0.1"))
float PhysicalLedSizeMm = 18.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "0.1"))
float WireThicknessMm = 2.6f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "0.0", ClampMax = "1.0"))
float WireOpacity = 0.62f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "0.0"))
float PhysicalJitterMm = 9.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix", meta = (ClampMin = "1", ClampMax = "32"))
int32 WireSegmentsPerString = 12;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
int32 PhysicalRandomSeed = 1337;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
bool bShowCabinets = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
bool bShowWires = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
bool bShowBottomFixers = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
TObjectPtr<UMaterialInterface> CabinetMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
TObjectPtr<UMaterialInterface> WireMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Physical Matrix")
TObjectPtr<UMaterialInterface> BottomFixerMaterial;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter = SetVoxelShape, Category = "LED Control|Appearance")
ELedVoxelShape VoxelShape = ELedVoxelShape::Cube;
ELedVoxelShape VoxelShape = ELedVoxelShape::Lens;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter = SetCustomVoxelMesh, Category = "LED Control|Appearance")
TObjectPtr<UStaticMesh> CustomVoxelMesh;
@ -224,6 +284,26 @@ private:
float CachedPixelSize = -1.0f;
float CachedSpacing = -1.0f;
int32 CachedPreviewStride = INDEX_NONE;
ELedDisplayGeometryMode CachedGeometryMode = ELedDisplayGeometryMode::VoxelGrid;
int32 CachedCabinetCountX = INDEX_NONE;
int32 CachedCabinetCountZ = INDEX_NONE;
int32 CachedDotsPerCabinetX = INDEX_NONE;
int32 CachedDotsPerCabinetZ = INDEX_NONE;
int32 CachedLedsPerString = INDEX_NONE;
float CachedCabinetSizeMm = -1.0f;
float CachedDotPitchMm = -1.0f;
float CachedPhysicalLedSizeMm = -1.0f;
float CachedWireThicknessMm = -1.0f;
float CachedWireOpacity = -1.0f;
float CachedPhysicalJitterMm = -1.0f;
int32 CachedWireSegmentsPerString = 0;
int32 CachedPhysicalRandomSeed = INDEX_NONE;
bool bCachedShowCabinets = false;
bool bCachedShowWires = false;
bool bCachedShowBottomFixers = false;
TObjectPtr<UMaterialInterface> CachedCabinetMaterial;
TObjectPtr<UMaterialInterface> CachedWireMaterial;
TObjectPtr<UMaterialInterface> CachedBottomFixerMaterial;
ELedVoxelShape CachedVoxelShape = ELedVoxelShape::Cube;
TObjectPtr<UStaticMesh> CachedCustomVoxelMesh;
TObjectPtr<UMaterialInterface> CachedLedMaterial;

View file

@ -14,6 +14,13 @@ enum class ELedVoxelShape : uint8
CustomMesh UMETA(DisplayName = "Custom Mesh")
};
UENUM(BlueprintType)
enum class ELedDisplayGeometryMode : uint8
{
VoxelGrid UMETA(DisplayName = "Voxel Grid"),
PhysicalMatrix UMETA(DisplayName = "Physical Matrix")
};
UENUM(BlueprintType)
enum class ELedVolumeSourceMode : uint8
{
@ -50,4 +57,3 @@ struct FLedVolumeDimensions
return static_cast<int64>(Width) * static_cast<int64>(Height) * static_cast<int64>(Depth);
}
};

View file

@ -7,7 +7,9 @@
#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"
@ -24,9 +26,17 @@ public:
{
FDefaultGameModuleImpl::StartupModule();
#if WITH_EDITOR
RemotePresetTickerHandle = FTSTicker::GetCoreTicker().AddTicker(
FTickerDelegate::CreateRaw(this, &FLedcube3dModule::TickBuildRemoteControlPreset),
5.0f);
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
}
@ -38,11 +48,36 @@ public:
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)
@ -50,8 +85,45 @@ public:
return false;
}
bRemotePresetBuilt = BuildRemoteControlPreset();
return !bRemotePresetBuilt;
if (!bStartupMapOpenAttempted && OpenDemoMapIfEditorStartedEmpty())
{
return true;
}
bRemotePresetBuilt = true;
return false;
}
bool OpenDemoMapIfEditorStartedEmpty()
{
bStartupMapOpenAttempted = true;
if (!GEditor)
{
return false;
}
UWorld* EditorWorld = GEditor->GetEditorWorldContext(false).World();
if (!EditorWorld)
{
return false;
}
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()
@ -110,10 +182,10 @@ public:
{
return false;
}
if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("5")
if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("7")
|| (!bCreatedNewPreset && Preset->GetExposedEntities().Num() > 0))
{
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("5"));
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7"));
return true;
}
@ -165,6 +237,32 @@ public:
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"));
@ -232,7 +330,7 @@ public:
Preset->ExposeActor(Controller, FRemoteControlPresetExposeArgs(TEXT("LED_Remote_Control"), GroupId));
}
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("5"));
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7"));
Package->MarkPackageDirty();
const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
FSavePackageArgs SaveArgs;
@ -244,8 +342,10 @@ public:
}
FTSTicker::FDelegateHandle RemotePresetTickerHandle;
FDelegateHandle PostEditorTickHandle;
int32 RemotePresetBuildAttempts = 0;
bool bRemotePresetBuilt = false;
bool bStartupMapOpenAttempted = false;
#endif
};