Implement GPU LED cube instances and remote control

This commit is contained in:
krustophski 2026-08-06 17:07:56 +03:00
parent eae947a772
commit 55c7f81991
16 changed files with 310 additions and 45 deletions

10
.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
# Unreal generated state
Intermediate/
Saved/
DerivedDataCache/
# Local IDE/runtime noise
.vs/
*.suo
*.opensdf
*.sdf

View file

@ -64,7 +64,14 @@ def create_gpu_led_material():
ensure_directory(package_path)
if unreal.EditorAssetLibrary.does_asset_exist(asset_path):
unreal.EditorAssetLibrary.delete_asset(asset_path)
material = unreal.EditorAssetLibrary.load_asset(asset_path)
usage = getattr(unreal.MaterialUsage, "MATUSAGE_INSTANCED_STATIC_MESHES", None)
if material and usage is not None:
unreal.MaterialEditingLibrary.set_base_material_usage(material, usage, True)
unreal.MaterialEditingLibrary.recompile_material(material)
unreal.EditorAssetLibrary.save_loaded_asset(material)
if material:
return material
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
material = asset_tools.create_asset(asset_name, package_path, unreal.Material, unreal.MaterialFactoryNew())
@ -178,13 +185,15 @@ def create_raymarch_volume_material():
ensure_directory(package_path)
if unreal.EditorAssetLibrary.does_asset_exist(asset_path):
unreal.EditorAssetLibrary.delete_asset(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_UNLIT)
material.set_editor_property("blend_mode", unreal.BlendMode.BLEND_ADDITIVE)
material.set_editor_property("two_sided", True)
material.set_editor_property("two_sided", False)
mel = unreal.MaterialEditingLibrary
usage = getattr(unreal.MaterialUsage, "MATUSAGE_INSTANCED_STATIC_MESHES", None)
@ -210,9 +219,10 @@ def create_raymarch_volume_material():
spacing = scalar_param("VoxelSpacing", 8.0, 40)
speed = scalar_param("AnimationSpeed", 1.0, 160)
pattern = scalar_param("PatternMode", 2.0, 280)
brightness = scalar_param("Brightness", 18.0, 400)
brightness = scalar_param("Brightness", 4.0, 400)
gamma = scalar_param("Gamma", 1.0, 520)
radius = scalar_param("PixelRadiusFraction", 0.5, 640)
shape = scalar_param("VoxelShapeMode", 1.0, 700)
solid = vector_param("LedColor", unreal.LinearColor(1.0, 0.2, 0.05, 1.0), 760)
center = vector_param("VolumeCenter", unreal.LinearColor(0.0, 0.0, 150.0, 1.0), 880)
extent = vector_param("VolumeExtent", unreal.LinearColor(512.0, 512.0, 512.0, 1.0), 1000)
@ -241,10 +251,11 @@ if (t1 <= max(t0, 0.0))
t0 = max(t0, 0.0);
float safeSpacing = max(VoxelSpacing, 0.001);
float radius = saturate(PixelRadiusFraction) * 0.45;
float radius = saturate(PixelRadiusFraction) * 0.22;
float t = TimeValue * AnimationSpeed;
float3 accum = 0.0;
const int Steps = 96;
float coverage = 0.0;
const int Steps = 128;
float stepLen = (t1 - t0) / Steps;
for (int i = 0; i < Steps; ++i)
@ -252,8 +263,21 @@ for (int i = 0; i < Steps; ++i)
float3 p = ro + rd * (t0 + (i + 0.5) * stepLen);
float3 grid = (p - bmin) / safeSpacing;
float3 cell = abs(frac(grid) - 0.5);
float d = length(cell);
float led = smoothstep(radius, radius * 0.35, d);
float sphereD = length(cell);
float cubeD = max(max(cell.x, cell.y), cell.z);
float lensD = max(length(cell.xy), cell.z * 2.8);
float shapeMode = VoxelShapeMode;
float d = sphereD;
if (shapeMode > 0.5 && shapeMode < 1.5)
{
d = cubeD;
}
else if (shapeMode > 1.5 && shapeMode < 2.5)
{
d = lensD;
}
float edge = max(radius * 0.12, 0.01);
float led = 1.0 - smoothstep(radius - edge, radius + edge, d);
float3 color = saturate(SolidColor.rgb);
if (PatternMode > 0.5 && PatternMode < 1.5)
@ -273,10 +297,12 @@ for (int i = 0; i < Steps; ++i)
color = shell * (0.35 + 0.65 * (0.5 + 0.5 * sin(float3(phase, phase + 2.0943951, phase + 4.1887902))));
}
accum += led * color * 0.055;
float sampleWeight = led * 0.18;
accum = max(accum, color * sampleWeight);
coverage = max(coverage, led);
}
accum = pow(max(accum, 0.0), max(GammaValue, 0.001)) * BrightnessValue;
accum = pow(max(accum, 0.0), max(GammaValue, 0.001)) * BrightnessValue * saturate(coverage);
return accum;
""")
@ -295,6 +321,7 @@ return accum;
custom_input("BrightnessValue"),
custom_input("GammaValue"),
custom_input("PixelRadiusFraction"),
custom_input("VoxelShapeMode"),
custom_input("SolidColor"),
custom_input("VolumeCenter"),
custom_input("VolumeExtent"),
@ -310,6 +337,7 @@ return accum;
(brightness, "BrightnessValue"),
(gamma, "GammaValue"),
(radius, "PixelRadiusFraction"),
(shape, "VoxelShapeMode"),
(solid, "SolidColor"),
(center, "VolumeCenter"),
(extent, "VolumeExtent"),

View file

@ -133,7 +133,7 @@ def create_main_level():
set_prop(display, "PixelSize", 4.0)
set_prop(display, "Spacing", 8.0)
set_prop(display, "PreviewStride", 2)
set_prop(display, "Brightness", 18.0)
set_prop(display, "Brightness", 4.0)
set_prop(display, "Gamma", 1.0)
set_prop(display, "SourceMode", unreal.LedVolumeSourceMode.TEST_PATTERN)
set_prop(display, "TestPattern", unreal.LedTestPattern.RAINBOW_WAVE)
@ -158,7 +158,7 @@ def create_main_level():
set_prop(controller, "PixelSize", 4.0)
set_prop(controller, "Spacing", 8.0)
set_prop(controller, "PreviewStride", 2)
set_prop(controller, "Brightness", 18.0)
set_prop(controller, "Brightness", 4.0)
set_prop(controller, "Gamma", 1.0)
set_prop(controller, "SourceMode", unreal.LedVolumeSourceMode.TEST_PATTERN)
set_prop(controller, "TestPattern", unreal.LedTestPattern.RAINBOW_WAVE)

View file

@ -24,7 +24,7 @@ def find_actor_by_label(label, class_name):
def create_or_load_preset():
preset_dir = "/Game/LedVolume/RemoteControl"
preset_name = "RCP_LedVolumeScene"
preset_name = "RCP_LedVolumeLive"
preset_path = f"{preset_dir}/{preset_name}"
ensure_directory("/Game/LedVolume")
ensure_directory(preset_dir)
@ -67,7 +67,6 @@ def expose_all(preset, controller):
"PreviewStride",
"VoxelShape",
"CustomVoxelMesh",
"Dimensions",
],
"LED Appearance": [
"LedMaterial",
@ -80,11 +79,13 @@ def expose_all(preset, controller):
"TestPattern",
"AnimationSpeed",
"bAnimateInEditor",
"bUseGpuTestPattern",
],
"LED Performance": [
"MaxEditorInstances",
"MaxRuntimeInstances",
"ColorUpdatesPerFrame",
"ApplyDebounceSeconds",
],
"LED Prepared Animation": [
"VolumeTextureFrames",
@ -112,6 +113,21 @@ def expose_all(preset, controller):
"RebuildTarget",
"SyncFromTarget",
"GetTargetDisplay",
"SetWidth",
"SetHeight",
"SetDepth",
"SetPixelSize",
"SetSpacing",
"SetPreviewStride",
"SetVoxelShape",
"SetBrightness",
"SetGamma",
"SetSolidColor",
"SetSourceMode",
"SetTestPattern",
"SetAnimationSpeed",
"SetAnimateInEditor",
"SetUseGpuTestPattern",
]:
expose_function(func)
@ -127,13 +143,13 @@ def expose_all(preset, controller):
def ensure_preset_actor(preset):
for actor in unreal.EditorLevelLibrary.get_all_level_actors():
if actor.get_actor_label() == "RC_LedVolumeScene":
if actor.get_actor_label() == "RC_LedVolumeLive":
actor.set_editor_property("Preset", preset)
return actor
preset_actor_class = unreal.load_class(None, "/Script/RemoteControl.RemoteControlPresetActor")
preset_actor = spawn_actor(preset_actor_class, (-250, 0, 150), (0, 0, 0))
preset_actor.set_actor_label("RC_LedVolumeScene")
preset_actor.set_actor_label("RC_LedVolumeLive")
preset_actor.set_editor_property("Preset", preset)
return preset_actor
@ -147,13 +163,13 @@ def main():
preset = create_or_load_preset()
if not preset:
raise RuntimeError("Could not create/load RCP_LedVolumeTest.")
raise RuntimeError("Could not create/load RCP_LedVolumeLive.")
expose_all(preset, controller)
ensure_preset_actor(preset)
unreal.EditorAssetLibrary.save_loaded_asset(preset)
unreal.EditorLoadingAndSavingUtils.save_dirty_packages(True, True)
unreal.log("Remote Control preset ready: /Game/LedVolume/RemoteControl/RCP_LedVolumeScene")
unreal.log("Remote Control preset ready: /Game/LedVolume/RemoteControl/RCP_LedVolumeLive")
if __name__ == "__main__":

View file

@ -3,14 +3,18 @@
#include "LedVolumeDisplayActor.h"
#include "Components/HierarchicalInstancedStaticMeshComponent.h"
#include "Components/InstancedStaticMeshComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
#include "EngineUtils.h"
#include "Kismet/GameplayStatics.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Camera/PlayerCameraManager.h"
#include "RotatingVoxelCubeActor.h"
#include "UObject/ConstructorHelpers.h"
#if WITH_EDITOR
#include "Editor.h"
#include "LevelEditorViewport.h"
#endif
namespace
@ -24,6 +28,7 @@ namespace
const FName VolumeCenterParameterName(TEXT("VolumeCenter"));
const FName VolumeExtentParameterName(TEXT("VolumeExtent"));
const FName PixelRadiusFractionParameterName(TEXT("PixelRadiusFraction"));
const FName VoxelShapeModeParameterName(TEXT("VoxelShapeMode"));
FLinearColor ApplyBrightnessAndGamma(const FLinearColor& InColor, float Brightness, float Gamma)
{
@ -58,6 +63,17 @@ ALedVolumeDisplayActor::ALedVolumeDisplayActor()
GpuVolumeProxy->SetHiddenInGame(true);
GpuVolumeProxy->SetVisibility(false);
GpuVoxelInstances = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("GpuVoxelInstances"));
GpuVoxelInstances->SetupAttachment(VoxelInstances);
GpuVoxelInstances->SetCollisionEnabled(ECollisionEnabled::NoCollision);
GpuVoxelInstances->SetCanEverAffectNavigation(false);
GpuVoxelInstances->bCastDynamicShadow = false;
GpuVoxelInstances->CastShadow = false;
GpuVoxelInstances->SetHiddenInGame(true);
GpuVoxelInstances->SetVisibility(false);
GpuVoxelInstances->NumCustomDataFloats = 0;
GpuVoxelInstances->SetCullDistances(0, 0);
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultSphereMesh(TEXT("/Engine/BasicShapes/Sphere.Sphere"));
if (DefaultSphereMesh.Succeeded())
{
@ -78,10 +94,15 @@ ALedVolumeDisplayActor::ALedVolumeDisplayActor()
}
}
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultPlaneMesh(TEXT("/Engine/BasicShapes/Plane.Plane"));
if (DefaultPlaneMesh.Succeeded())
{
GpuVolumeProxy->SetStaticMesh(DefaultPlaneMesh.Object);
}
static ConstructorHelpers::FObjectFinder<UStaticMesh> DefaultCubeMesh(TEXT("/Engine/BasicShapes/Cube.Cube"));
if (DefaultCubeMesh.Succeeded())
{
GpuVolumeProxy->SetStaticMesh(DefaultCubeMesh.Object);
GpuVoxelInstances->SetStaticMesh(DefaultCubeMesh.Object);
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> DefaultGpuVolumeMaterial(TEXT("/Game/LedVolume/Materials/M_LedVolumeRaymarch.M_LedVolumeRaymarch"));
@ -120,6 +141,7 @@ void ALedVolumeDisplayActor::Tick(float DeltaSeconds)
if (IsGpuTestPatternActive())
{
UpdateMaterialParameters();
bColorsDirty = false;
}
else if (SourceMode == ELedVolumeSourceMode::TestPattern && bRunSourceAnimation)
@ -483,6 +505,61 @@ bool ALedVolumeDisplayActor::IsGpuTestPatternActive() const
return bUseGpuTestPattern && SourceMode == ELedVolumeSourceMode::TestPattern;
}
void ALedVolumeDisplayActor::UpdateGpuVolumeProxyTransform()
{
if (!GpuVolumeProxy || !IsGpuTestPatternActive())
{
return;
}
FVector CameraLocation = GetActorLocation() + FVector(-1000.0f, 0.0f, 400.0f);
bool bHasCamera = false;
if (const UWorld* World = GetWorld())
{
if (World->IsGameWorld())
{
if (const APlayerCameraManager* CameraManager = UGameplayStatics::GetPlayerCameraManager(World, 0))
{
CameraLocation = CameraManager->GetCameraLocation();
bHasCamera = true;
}
}
#if WITH_EDITOR
else if (GCurrentLevelEditingViewportClient)
{
CameraLocation = GCurrentLevelEditingViewportClient->GetViewLocation();
bHasCamera = true;
}
#endif
}
const FVector Center = GetActorLocation();
FVector ViewDirection = Center - CameraLocation;
if (!ViewDirection.Normalize())
{
ViewDirection = FVector::ForwardVector;
}
const FVector VolumeSize(
FMath::Max(Spacing, Dimensions.Width * Spacing),
FMath::Max(Spacing, Dimensions.Height * Spacing),
FMath::Max(Spacing, Dimensions.Depth * Spacing));
const float Radius = VolumeSize.Size() * 0.5f;
const float PlaneSize = FMath::Max(VolumeSize.GetMax() * 1.75f, Radius * 2.2f);
const FVector PlaneWorldLocation = Center - ViewDirection * (Radius + 1.0f);
const FRotator PlaneWorldRotation = FRotationMatrix::MakeFromZ(-ViewDirection).Rotator();
GpuVolumeProxy->SetWorldLocationAndRotation(PlaneWorldLocation, PlaneWorldRotation);
GpuVolumeProxy->SetWorldScale3D(FVector(PlaneSize / 100.0f, PlaneSize / 100.0f, 1.0f));
if (!bHasCamera)
{
GpuVolumeProxy->SetRelativeLocation(FVector::ZeroVector);
}
}
void ALedVolumeDisplayActor::RebuildGeometry()
{
if (!VoxelInstances)
@ -495,21 +572,17 @@ void ALedVolumeDisplayActor::RebuildGeometry()
VoxelInstances->SetHiddenInGame(IsGpuTestPatternActive());
if (GpuVolumeProxy)
{
GpuVolumeProxy->SetVisibility(IsGpuTestPatternActive());
GpuVolumeProxy->SetHiddenInGame(!IsGpuTestPatternActive());
const FVector VolumeSize(
FMath::Max(Spacing, Dimensions.Width * Spacing),
FMath::Max(Spacing, Dimensions.Height * Spacing),
FMath::Max(Spacing, Dimensions.Depth * Spacing));
GpuVolumeProxy->SetRelativeLocation(FVector::ZeroVector);
GpuVolumeProxy->SetRelativeScale3D(VolumeSize / 100.0f);
if (GpuVolumeMaterial)
{
GpuVolumeProxy->SetMaterial(0, GpuVolumeMaterial);
}
GpuVolumeProxy->SetVisibility(false);
GpuVolumeProxy->SetHiddenInGame(true);
}
if (GpuVoxelInstances)
{
GpuVoxelInstances->SetVisibility(IsGpuTestPatternActive());
GpuVoxelInstances->SetHiddenInGame(!IsGpuTestPatternActive());
}
if (IsGpuTestPatternActive())
{
RebuildGpuVoxelInstances();
RenderedVoxelToBufferIndex.Reset();
LastRenderedColors.Reset();
bGeometryDirty = false;
@ -585,6 +658,62 @@ void ALedVolumeDisplayActor::RebuildGeometry()
bColorsDirty = true;
}
void ALedVolumeDisplayActor::RebuildGpuVoxelInstances()
{
if (!GpuVoxelInstances)
{
return;
}
const int64 RequestedCount = Dimensions.NumVoxels();
if (RequestedCount <= 0 || RequestedCount > TNumericLimits<int32>::Max())
{
GpuVoxelInstances->ClearInstances();
return;
}
const float MeshBaseSize = 100.0f;
const float UniformScale = PixelSize / MeshBaseSize;
const FVector InstanceScale = VoxelShape == ELedVoxelShape::Lens
? FVector(UniformScale, UniformScale, UniformScale * 0.35f)
: FVector(UniformScale);
GpuVoxelInstances->SetStaticMesh(ResolveVoxelMesh());
if (LedMaterial)
{
GpuVoxelInstances->SetMaterial(0, LedMaterial);
GpuVoxelMID = nullptr;
}
GpuVoxelInstances->ClearInstances();
GpuVoxelInstances->PreAllocateInstancesMemory(static_cast<int32>(RequestedCount));
constexpr int32 BatchSize = 32768;
TArray<FTransform> Batch;
Batch.Reserve(BatchSize);
for (int32 Z = 0; Z < Dimensions.Depth; ++Z)
{
for (int32 Y = 0; Y < Dimensions.Height; ++Y)
{
for (int32 X = 0; X < Dimensions.Width; ++X)
{
Batch.Emplace(FRotator::ZeroRotator, VoxelIndexToLocalPosition(X, Y, Z), InstanceScale);
if (Batch.Num() == BatchSize)
{
GpuVoxelInstances->AddInstances(Batch, false, false, false);
Batch.Reset();
}
}
}
}
if (!Batch.IsEmpty())
{
GpuVoxelInstances->AddInstances(Batch, false, false, false);
}
}
void ALedVolumeDisplayActor::EnsureVoxelBuffer()
{
const int64 NumVoxels64 = Dimensions.NumVoxels();
@ -627,23 +756,44 @@ void ALedVolumeDisplayActor::UpdateMaterialParameters()
if (GpuVolumeProxy)
{
UMaterialInstanceDynamic* DynamicMaterial = GpuVolumeProxy->CreateAndSetMaterialInstanceDynamic(0);
if (DynamicMaterial)
if (!GpuVolumeMID)
{
GpuVolumeMID = GpuVolumeProxy->CreateAndSetMaterialInstanceDynamic(0);
}
if (GpuVolumeMID)
{
const FVector VolumeExtent(
FMath::Max(Spacing * 0.5f, Dimensions.Width * Spacing * 0.5f),
FMath::Max(Spacing * 0.5f, Dimensions.Height * Spacing * 0.5f),
FMath::Max(Spacing * 0.5f, Dimensions.Depth * Spacing * 0.5f));
DynamicMaterial->SetScalarParameterValue(BrightnessParameterName, Brightness);
DynamicMaterial->SetScalarParameterValue(GammaParameterName, Gamma);
DynamicMaterial->SetVectorParameterValue(LedColorParameterName, SolidColor);
DynamicMaterial->SetScalarParameterValue(AnimationSpeedParameterName, AnimationSpeed);
DynamicMaterial->SetScalarParameterValue(PatternModeParameterName, static_cast<float>(static_cast<uint8>(TestPattern)));
DynamicMaterial->SetScalarParameterValue(VoxelSpacingParameterName, Spacing);
GpuVolumeMID->SetScalarParameterValue(BrightnessParameterName, Brightness);
GpuVolumeMID->SetScalarParameterValue(GammaParameterName, Gamma);
GpuVolumeMID->SetVectorParameterValue(LedColorParameterName, SolidColor);
GpuVolumeMID->SetScalarParameterValue(AnimationSpeedParameterName, AnimationSpeed);
GpuVolumeMID->SetScalarParameterValue(PatternModeParameterName, static_cast<float>(static_cast<uint8>(TestPattern)));
GpuVolumeMID->SetScalarParameterValue(VoxelSpacingParameterName, Spacing);
const FVector Center = GetActorLocation();
DynamicMaterial->SetVectorParameterValue(VolumeCenterParameterName, FLinearColor(Center.X, Center.Y, Center.Z, 1.0f));
DynamicMaterial->SetVectorParameterValue(VolumeExtentParameterName, FLinearColor(VolumeExtent.X, VolumeExtent.Y, VolumeExtent.Z, 1.0f));
DynamicMaterial->SetScalarParameterValue(PixelRadiusFractionParameterName, FMath::Clamp(PixelSize / FMath::Max(Spacing, 0.001f), 0.02f, 1.0f));
GpuVolumeMID->SetVectorParameterValue(VolumeCenterParameterName, FLinearColor(Center.X, Center.Y, Center.Z, 1.0f));
GpuVolumeMID->SetVectorParameterValue(VolumeExtentParameterName, FLinearColor(VolumeExtent.X, VolumeExtent.Y, VolumeExtent.Z, 1.0f));
GpuVolumeMID->SetScalarParameterValue(PixelRadiusFractionParameterName, FMath::Clamp(PixelSize / FMath::Max(Spacing, 0.001f), 0.02f, 1.0f));
GpuVolumeMID->SetScalarParameterValue(VoxelShapeModeParameterName, static_cast<float>(static_cast<uint8>(VoxelShape)));
}
}
if (GpuVoxelInstances)
{
if (!GpuVoxelMID)
{
GpuVoxelMID = GpuVoxelInstances->CreateAndSetMaterialInstanceDynamic(0);
}
if (GpuVoxelMID)
{
GpuVoxelMID->SetScalarParameterValue(BrightnessParameterName, Brightness);
GpuVoxelMID->SetScalarParameterValue(GammaParameterName, Gamma);
GpuVoxelMID->SetVectorParameterValue(LedColorParameterName, SolidColor);
GpuVoxelMID->SetScalarParameterValue(AnimationSpeedParameterName, AnimationSpeed);
GpuVoxelMID->SetScalarParameterValue(PatternModeParameterName, static_cast<float>(static_cast<uint8>(TestPattern)));
GpuVoxelMID->SetScalarParameterValue(VoxelSpacingParameterName, Spacing);
}
}
}

View file

@ -8,6 +8,8 @@
#include "LedVolumeDisplayActor.generated.h"
class UHierarchicalInstancedStaticMeshComponent;
class UInstancedStaticMeshComponent;
class UMaterialInstanceDynamic;
class UMaterialInterface;
class UStaticMeshComponent;
class UStaticMesh;
@ -175,6 +177,15 @@ private:
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UStaticMeshComponent> GpuVolumeProxy;
UPROPERTY(VisibleAnywhere, Category = "LED Volume")
TObjectPtr<UInstancedStaticMeshComponent> GpuVoxelInstances;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> GpuVolumeMID;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> GpuVoxelMID;
UPROPERTY(Transient)
TArray<FLinearColor> VoxelBuffer;
@ -221,6 +232,8 @@ private:
bool HasAppearanceChanged() const;
bool HasSourceSettingsChanged() const;
bool IsGpuTestPatternActive() const;
void UpdateGpuVolumeProxyTransform();
void RebuildGpuVoxelInstances();
void RebuildGeometry();
void EnsureVoxelBuffer();
void UpdateMaterialParameters();

View file

@ -295,6 +295,13 @@ void ALedVolumeRemoteControlActor::SetVoxelShape(ELedVoxelShape NewValue)
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetVoxelShapeIndex(int32 NewValue)
{
const int32 ClampedValue = FMath::Clamp(NewValue, 0, static_cast<int32>(ELedVoxelShape::CustomMesh));
VoxelShape = static_cast<ELedVoxelShape>(ClampedValue);
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetCustomVoxelMesh(UStaticMesh* NewValue)
{
CustomVoxelMesh = NewValue;
@ -331,12 +338,26 @@ void ALedVolumeRemoteControlActor::SetSourceMode(ELedVolumeSourceMode NewValue)
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetSourceModeIndex(int32 NewValue)
{
const int32 ClampedValue = FMath::Clamp(NewValue, 0, static_cast<int32>(ELedVolumeSourceMode::SublevelVoxelizedScene));
SourceMode = static_cast<ELedVolumeSourceMode>(ClampedValue);
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetTestPattern(ELedTestPattern NewValue)
{
TestPattern = NewValue;
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetTestPatternIndex(int32 NewValue)
{
const int32 ClampedValue = FMath::Clamp(NewValue, 0, static_cast<int32>(ELedTestPattern::MovingSphere));
TestPattern = static_cast<ELedTestPattern>(ClampedValue);
ApplyToTarget();
}
void ALedVolumeRemoteControlActor::SetAnimationSpeed(float NewValue)
{
AnimationSpeed = NewValue;

View file

@ -158,6 +158,9 @@ public:
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetVoxelShape(ELedVoxelShape NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetVoxelShapeIndex(int32 NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetCustomVoxelMesh(UStaticMesh* NewValue);
@ -176,9 +179,15 @@ public:
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetSourceMode(ELedVolumeSourceMode NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetSourceModeIndex(int32 NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetTestPattern(ELedTestPattern NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetTestPatternIndex(int32 NewValue);
UFUNCTION(BlueprintCallable, Category = "LED Control|Setters")
void SetAnimationSpeed(float NewValue);

View file

@ -26,7 +26,7 @@ public:
#if WITH_EDITOR
RemotePresetTickerHandle = FTSTicker::GetCoreTicker().AddTicker(
FTickerDelegate::CreateRaw(this, &FLedcube3dModule::TickBuildRemoteControlPreset),
1.0f);
5.0f);
#endif
}
@ -60,6 +60,10 @@ public:
{
return false;
}
if (!GEditor->Trans)
{
return false;
}
UWorld* EditorWorld = GEditor->GetEditorWorldContext(false).World();
if (!EditorWorld)
@ -93,19 +97,23 @@ public:
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("4"))
if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("5")
|| (!bCreatedNewPreset && Preset->GetExposedEntities().Num() > 0))
{
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("5"));
return true;
}
@ -120,6 +128,16 @@ public:
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;
@ -214,7 +232,7 @@ public:
Preset->ExposeActor(Controller, FRemoteControlPresetExposeArgs(TEXT("LED_Remote_Control"), GroupId));
}
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("4"));
Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("5"));
Package->MarkPackageDirty();
const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension());
FSavePackageArgs SaveArgs;