diff --git a/AGENTS.md b/AGENTS.md index 4de5dc2..82d6b4d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,6 +56,7 @@ Important maps/assets: - Demo map: `/Game/LedVolume/Maps/L_LedVolume_Demo_Single` - Rotating cube sublevel exists for earlier voxelization tests: `/Game/LedVolume/Maps/L_RotatingCube_Sublevel` +- Rotating 3D snowflake source level: `/Game/LedVolume/Maps/L_RotatingSnowflake_Sublevel` - Remote Control preset: `/Game/LedVolume/RemoteControl/RCP_LedVolumeLive` ## Remote Control / Minimized Editor Notes @@ -96,6 +97,21 @@ Remote Control parameter persistence: - `ApplyToTarget` and `SyncFromTarget` save the current settings immediately. - Verified by setting `ApplyDebounceSeconds=0.11`, restarting Unreal Editor, and reading the same value back through the Remote Control API. +Remote Control exposure rule: + +- Every new user-controllable parameter must be added to `ALedVolumeRemoteControlActor` as an editable UPROPERTY. +- The preset builder auto-exposes all editable controller properties, so new parameters should appear in Remote Control after the editor restarts/rebuilds the preset. +- If a parameter needs a convenient user choice, prefer an enum preset property over asking the user to type raw asset paths. +- The current sublevel source selector is `SublevelSourcePreset` with `Custom`, `RotatingCube`, and `RotatingSnowflake`. +- `VoxelizedSublevel` is still exposed for custom source maps. + +Sublevel source notes: + +- `ALedVolumeDisplayActor` streams the selected `VoxelizedSublevel` dynamically before sampling. +- Sublevel voxelization is incremental and uses `ColorUpdatesPerFrame` as the per-frame sampling budget; do not sample all 120^3 voxels in one frame. +- Source actors must have tag `LedVoxelSource`. +- `ARotatingSnowflakeActor` creates a rotating 3D snowflake from many small static mesh crystals so the bounds-based sampler sees a volumetric shape. + ## Git History Milestones Recent commits: diff --git a/Binaries/Win64/UnrealEditor-ledcube3d.dll b/Binaries/Win64/UnrealEditor-ledcube3d.dll index 09fa092..9e81ca3 100644 Binary files a/Binaries/Win64/UnrealEditor-ledcube3d.dll and b/Binaries/Win64/UnrealEditor-ledcube3d.dll differ diff --git a/Binaries/Win64/UnrealEditor-ledcube3d.pdb b/Binaries/Win64/UnrealEditor-ledcube3d.pdb index b2b850d..3855eaf 100644 Binary files a/Binaries/Win64/UnrealEditor-ledcube3d.pdb and b/Binaries/Win64/UnrealEditor-ledcube3d.pdb differ diff --git a/Content/LedVolume/Maps/L_RotatingSnowflake_Sublevel.umap b/Content/LedVolume/Maps/L_RotatingSnowflake_Sublevel.umap new file mode 100644 index 0000000..6925625 Binary files /dev/null and b/Content/LedVolume/Maps/L_RotatingSnowflake_Sublevel.umap differ diff --git a/Content/LedVolume/RemoteControl/RCP_LedVolumeLive.uasset b/Content/LedVolume/RemoteControl/RCP_LedVolumeLive.uasset index 325cd39..cb16ff7 100644 Binary files a/Content/LedVolume/RemoteControl/RCP_LedVolumeLive.uasset and b/Content/LedVolume/RemoteControl/RCP_LedVolumeLive.uasset differ diff --git a/Source/ledcube3d/LedVolumeDisplayActor.cpp b/Source/ledcube3d/LedVolumeDisplayActor.cpp index 80506a6..5479237 100644 --- a/Source/ledcube3d/LedVolumeDisplayActor.cpp +++ b/Source/ledcube3d/LedVolumeDisplayActor.cpp @@ -5,12 +5,14 @@ #include "Components/HierarchicalInstancedStaticMeshComponent.h" #include "Components/InstancedStaticMeshComponent.h" #include "Components/StaticMeshComponent.h" +#include "Engine/LevelStreamingDynamic.h" #include "Engine/StaticMesh.h" #include "EngineUtils.h" #include "Kismet/GameplayStatics.h" #include "Materials/MaterialInstanceDynamic.h" #include "Camera/PlayerCameraManager.h" #include "RotatingVoxelCubeActor.h" +#include "RotatingSnowflakeActor.h" #include "UObject/ConstructorHelpers.h" #if WITH_EDITOR #include "Editor.h" @@ -1188,10 +1190,25 @@ void ALedVolumeDisplayActor::UpdateTestPattern(float DeltaSeconds, bool bForceAl void ALedVolumeDisplayActor::UpdateSublevelVoxelizedScene(float DeltaSeconds) { + EnsureVoxelizedSublevelLoaded(); EnsureVoxelBuffer(); - for (const int32 BufferIndex : RenderedVoxelToBufferIndex) + if (RenderedVoxelToBufferIndex.IsEmpty()) { + return; + } + + const int32 SampleCount = RenderedVoxelToBufferIndex.Num(); + const int32 Budget = FMath::Clamp(ColorUpdatesPerFrame, 1, SampleCount); + for (int32 Step = 0; Step < Budget; ++Step) + { + if (!RenderedVoxelToBufferIndex.IsValidIndex(NextSublevelSampleInstance)) + { + NextSublevelSampleInstance = 0; + } + const int32 BufferIndex = RenderedVoxelToBufferIndex[NextSublevelSampleInstance]; + NextSublevelSampleInstance = (NextSublevelSampleInstance + 1) % SampleCount; + int32 X = 0; int32 Y = 0; int32 Z = 0; @@ -1205,6 +1222,55 @@ void ALedVolumeDisplayActor::UpdateSublevelVoxelizedScene(float DeltaSeconds) MarkColorsDirty(); } +void ALedVolumeDisplayActor::EnsureVoxelizedSublevelLoaded() +{ + if (VoxelizedSublevel.IsNull()) + { + if (LoadedVoxelizedSublevel) + { + LoadedVoxelizedSublevel->SetShouldBeLoaded(false); + LoadedVoxelizedSublevel->SetShouldBeVisible(false); + LoadedVoxelizedSublevel = nullptr; + } + CachedLoadedVoxelizedSublevel.Reset(); + return; + } + + if (LoadedVoxelizedSublevel && CachedLoadedVoxelizedSublevel == VoxelizedSublevel) + { + LoadedVoxelizedSublevel->SetShouldBeLoaded(true); + LoadedVoxelizedSublevel->SetShouldBeVisible(true); + return; + } + + if (LoadedVoxelizedSublevel) + { + LoadedVoxelizedSublevel->SetShouldBeLoaded(false); + LoadedVoxelizedSublevel->SetShouldBeVisible(false); + LoadedVoxelizedSublevel = nullptr; + } + + bool bLoadSucceeded = false; + const FString OverrideName = FString::Printf(TEXT("LedVoxelSource_%08x"), GetTypeHash(VoxelizedSublevel.ToSoftObjectPath().ToString())); + LoadedVoxelizedSublevel = ULevelStreamingDynamic::LoadLevelInstanceBySoftObjectPtr( + this, + VoxelizedSublevel, + FTransform::Identity, + bLoadSucceeded, + OverrideName); + + if (LoadedVoxelizedSublevel && bLoadSucceeded) + { + LoadedVoxelizedSublevel->SetShouldBeLoaded(true); + LoadedVoxelizedSublevel->SetShouldBeVisible(true); + CachedLoadedVoxelizedSublevel = VoxelizedSublevel; + } + else + { + CachedLoadedVoxelizedSublevel.Reset(); + } +} + void ALedVolumeDisplayActor::UpdateInstanceColors(bool bForceAll) { if (!VoxelInstances || RenderedVoxelToBufferIndex.IsEmpty()) @@ -1443,6 +1509,10 @@ FLinearColor ALedVolumeDisplayActor::SampleWorldVoxelColor(const FVector& WorldP { return CubeSource->VoxelColor; } + if (const ARotatingSnowflakeActor* SnowflakeSource = Cast(SourceActor)) + { + return SnowflakeSource->GetVoxelColorAt(WorldPosition); + } return SolidColor; } diff --git a/Source/ledcube3d/LedVolumeDisplayActor.h b/Source/ledcube3d/LedVolumeDisplayActor.h index 16854ea..d703937 100644 --- a/Source/ledcube3d/LedVolumeDisplayActor.h +++ b/Source/ledcube3d/LedVolumeDisplayActor.h @@ -11,6 +11,7 @@ class UHierarchicalInstancedStaticMeshComponent; class UInstancedStaticMeshComponent; class UMaterialInstanceDynamic; class UMaterialInterface; +class ULevelStreamingDynamic; class UStaticMeshComponent; class UStaticMesh; class UTexture2D; @@ -267,6 +268,11 @@ private: UPROPERTY(Transient) TArray LastRenderedColors; + UPROPERTY(Transient) + TObjectPtr LoadedVoxelizedSublevel; + + TSoftObjectPtr CachedLoadedVoxelizedSublevel; + FLedVolumeDimensions CachedDimensions; int32 CachedWidth = 0; int32 CachedHeight = 0; @@ -310,6 +316,7 @@ private: #endif int32 NextColorUpdateInstance = 0; + int32 NextSublevelSampleInstance = 0; float RunningTime = 0.0f; bool bGeometryDirty = true; bool bColorsDirty = true; @@ -332,6 +339,7 @@ private: void UpdateMaterialParameters(); void UpdateTestPattern(float DeltaSeconds, bool bForceAll); void UpdateSublevelVoxelizedScene(float DeltaSeconds); + void EnsureVoxelizedSublevelLoaded(); void UpdateInstanceColors(bool bForceAll); void MarkColorsDirty(); diff --git a/Source/ledcube3d/LedVolumeRemoteControlActor.cpp b/Source/ledcube3d/LedVolumeRemoteControlActor.cpp index 2f4e460..ad302fc 100644 --- a/Source/ledcube3d/LedVolumeRemoteControlActor.cpp +++ b/Source/ledcube3d/LedVolumeRemoteControlActor.cpp @@ -218,6 +218,7 @@ void ALedVolumeRemoteControlActor::ApplyToTarget() { LoadPersistentSettings(); ClampSettings(); + ApplySublevelSourcePreset(); if (CachedTargetActorLabel != TargetActorLabel) { CachedTarget.Reset(); @@ -326,6 +327,7 @@ void ALedVolumeRemoteControlActor::ApplyToTarget() Target->ColorUpdatesPerFrame = ColorUpdatesPerFrame; Target->VolumeTextureFrames = VolumeTextureFrames; Target->TextureSliceFrames = TextureSliceFrames; + ApplySublevelSourcePreset(); Target->VoxelizedSublevel = VoxelizedSublevel; Target->CaptureBoundsExtent = CaptureBoundsExtent; Target->bUseActorBoundsAsCaptureVolume = bUseActorBoundsAsCaptureVolume; @@ -405,6 +407,7 @@ void ALedVolumeRemoteControlActor::SyncFromTarget() ColorUpdatesPerFrame = Target->ColorUpdatesPerFrame; VolumeTextureFrames = Target->VolumeTextureFrames; TextureSliceFrames = Target->TextureSliceFrames; + SublevelSourcePreset = ELedSublevelSourcePreset::Custom; VoxelizedSublevel = Target->VoxelizedSublevel; CaptureBoundsExtent = Target->CaptureBoundsExtent; bUseActorBoundsAsCaptureVolume = Target->bUseActorBoundsAsCaptureVolume; @@ -647,9 +650,22 @@ void ALedVolumeRemoteControlActor::ClampSettings() ApplyDebounceSeconds = FMath::Clamp(ApplyDebounceSeconds, 0.0f, 2.0f); } +void ALedVolumeRemoteControlActor::ApplySublevelSourcePreset() +{ + if (SublevelSourcePreset == ELedSublevelSourcePreset::RotatingCube) + { + VoxelizedSublevel = TSoftObjectPtr(FSoftObjectPath(TEXT("/Game/LedVolume/Maps/L_RotatingCube_Sublevel.L_RotatingCube_Sublevel"))); + } + else if (SublevelSourcePreset == ELedSublevelSourcePreset::RotatingSnowflake) + { + VoxelizedSublevel = TSoftObjectPtr(FSoftObjectPath(TEXT("/Game/LedVolume/Maps/L_RotatingSnowflake_Sublevel.L_RotatingSnowflake_Sublevel"))); + } +} + void ALedVolumeRemoteControlActor::QueueApply() { ClampSettings(); + ApplySublevelSourcePreset(); bApplyPending = true; PendingApplySeconds = ApplyDebounceSeconds; } @@ -700,6 +716,7 @@ void ALedVolumeRemoteControlActor::CacheSettings() CachedApplyDebounceSeconds = ApplyDebounceSeconds; CachedVolumeTextureFrameCount = VolumeTextureFrames.Num(); CachedTextureSliceFrameCount = TextureSliceFrames.Num(); + CachedSublevelSourcePreset = SublevelSourcePreset; CachedVoxelizedSublevel = VoxelizedSublevel; CachedCaptureBoundsExtent = CaptureBoundsExtent; bCachedUseActorBoundsAsCaptureVolume = bUseActorBoundsAsCaptureVolume; @@ -753,6 +770,7 @@ bool ALedVolumeRemoteControlActor::HasSettingsChanged() const || !FMath::IsNearlyEqual(CachedApplyDebounceSeconds, ApplyDebounceSeconds) || CachedVolumeTextureFrameCount != VolumeTextureFrames.Num() || CachedTextureSliceFrameCount != TextureSliceFrames.Num() + || CachedSublevelSourcePreset != SublevelSourcePreset || CachedVoxelizedSublevel != VoxelizedSublevel || CachedCaptureBoundsExtent != CaptureBoundsExtent || bCachedUseActorBoundsAsCaptureVolume != bUseActorBoundsAsCaptureVolume @@ -813,6 +831,7 @@ void ALedVolumeRemoteControlActor::LoadPersistentSettings() GConfig->GetFloat(LedRemoteSettingsSection, TEXT("ApplyDebounceSeconds"), ApplyDebounceSeconds, GGameUserSettingsIni); LoadObjectArrayValue(TEXT("VolumeTextureFrames"), VolumeTextureFrames); LoadObjectArrayValue(TEXT("TextureSliceFrames"), TextureSliceFrames); + LoadEnumValue(TEXT("SublevelSourcePreset"), SublevelSourcePreset); FString VoxelizedSublevelPath; if (GConfig->GetString(LedRemoteSettingsSection, TEXT("VoxelizedSublevel"), VoxelizedSublevelPath, GGameUserSettingsIni)) @@ -825,6 +844,7 @@ void ALedVolumeRemoteControlActor::LoadPersistentSettings() LoadColorValue(TEXT("EmptyVoxelColor"), EmptyVoxelColor); ClampSettings(); + ApplySublevelSourcePreset(); bApplyPending = true; PendingApplySeconds = 0.0f; } @@ -880,6 +900,7 @@ void ALedVolumeRemoteControlActor::SavePersistentSettings() const GConfig->SetFloat(LedRemoteSettingsSection, TEXT("ApplyDebounceSeconds"), ApplyDebounceSeconds, GGameUserSettingsIni); SaveObjectArrayValue(TEXT("VolumeTextureFrames"), VolumeTextureFrames); SaveObjectArrayValue(TEXT("TextureSliceFrames"), TextureSliceFrames); + SaveEnumValue(TEXT("SublevelSourcePreset"), SublevelSourcePreset); GConfig->SetString(LedRemoteSettingsSection, TEXT("VoxelizedSublevel"), *VoxelizedSublevel.ToSoftObjectPath().ToString(), GGameUserSettingsIni); SaveVectorValue(TEXT("CaptureBoundsExtent"), CaptureBoundsExtent); GConfig->SetBool(LedRemoteSettingsSection, TEXT("bUseActorBoundsAsCaptureVolume"), bUseActorBoundsAsCaptureVolume, GGameUserSettingsIni); @@ -992,6 +1013,7 @@ void ALedVolumeRemoteControlActor::MirrorEditorControllerStateForPIE() ApplyDebounceSeconds = EditorSource->ApplyDebounceSeconds; VolumeTextureFrames = EditorSource->VolumeTextureFrames; TextureSliceFrames = EditorSource->TextureSliceFrames; + SublevelSourcePreset = EditorSource->SublevelSourcePreset; VoxelizedSublevel = EditorSource->VoxelizedSublevel; CaptureBoundsExtent = EditorSource->CaptureBoundsExtent; bUseActorBoundsAsCaptureVolume = EditorSource->bUseActorBoundsAsCaptureVolume; diff --git a/Source/ledcube3d/LedVolumeRemoteControlActor.h b/Source/ledcube3d/LedVolumeRemoteControlActor.h index cd3353e..e0a2acd 100644 --- a/Source/ledcube3d/LedVolumeRemoteControlActor.h +++ b/Source/ledcube3d/LedVolumeRemoteControlActor.h @@ -162,6 +162,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Prepared Animation") TArray> TextureSliceFrames; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Sublevel Source") + ELedSublevelSourcePreset SublevelSourcePreset = ELedSublevelSourcePreset::RotatingSnowflake; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LED Control|Sublevel Source") TSoftObjectPtr VoxelizedSublevel; @@ -328,8 +331,10 @@ private: bool bCachedUseActorBoundsAsCaptureVolume = false; FName CachedSourceActorTag; FLinearColor CachedEmptyVoxelColor = FLinearColor::Transparent; + ELedSublevelSourcePreset CachedSublevelSourcePreset = ELedSublevelSourcePreset::Custom; void ClampSettings(); + void ApplySublevelSourcePreset(); void QueueApply(); void CacheSettings(); bool HasSettingsChanged() const; diff --git a/Source/ledcube3d/LedVolumeTypes.h b/Source/ledcube3d/LedVolumeTypes.h index b8ee286..240b03a 100644 --- a/Source/ledcube3d/LedVolumeTypes.h +++ b/Source/ledcube3d/LedVolumeTypes.h @@ -29,6 +29,14 @@ enum class ELedVolumeSourceMode : uint8 SublevelVoxelizedScene UMETA(DisplayName = "Sublevel Voxelized Scene") }; +UENUM(BlueprintType) +enum class ELedSublevelSourcePreset : uint8 +{ + Custom UMETA(DisplayName = "Custom"), + RotatingCube UMETA(DisplayName = "Rotating Cube"), + RotatingSnowflake UMETA(DisplayName = "Rotating Snowflake") +}; + UENUM(BlueprintType) enum class ELedTestPattern : uint8 { diff --git a/Source/ledcube3d/RotatingSnowflakeActor.cpp b/Source/ledcube3d/RotatingSnowflakeActor.cpp new file mode 100644 index 0000000..7d52694 --- /dev/null +++ b/Source/ledcube3d/RotatingSnowflakeActor.cpp @@ -0,0 +1,121 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "RotatingSnowflakeActor.h" + +#include "Components/SceneComponent.h" +#include "Components/StaticMeshComponent.h" +#include "UObject/ConstructorHelpers.h" + +ARotatingSnowflakeActor::ARotatingSnowflakeActor() +{ + PrimaryActorTick.bCanEverTick = true; + + Root = CreateDefaultSubobject(TEXT("Root")); + SetRootComponent(Root); + + Tags.AddUnique(TEXT("LedVoxelSource")); + + static ConstructorHelpers::FObjectFinder SphereAsset(TEXT("/Engine/BasicShapes/Sphere.Sphere")); + static ConstructorHelpers::FObjectFinder CubeAsset(TEXT("/Engine/BasicShapes/Cube.Cube")); + static ConstructorHelpers::FObjectFinder MaterialAsset(TEXT("/Engine/BasicShapes/BasicShapeMaterial.BasicShapeMaterial")); + + UStaticMesh* SphereMesh = SphereAsset.Succeeded() ? SphereAsset.Object.Get() : nullptr; + UStaticMesh* CubeMesh = CubeAsset.Succeeded() ? CubeAsset.Object.Get() : SphereMesh; + UMaterialInterface* Material = MaterialAsset.Succeeded() ? MaterialAsset.Object.Get() : nullptr; + + AddCrystal(TEXT("Core"), FVector::ZeroVector, FVector(0.22f), SphereMesh, Material); + + constexpr int32 ArmCount = 6; + constexpr int32 StepsPerArm = 8; + constexpr int32 PlaneCount = 3; + const float StepDistance = ArmLength / static_cast(StepsPerArm); + + for (int32 PlaneIndex = 0; PlaneIndex < PlaneCount; ++PlaneIndex) + { + for (int32 ArmIndex = 0; ArmIndex < ArmCount; ++ArmIndex) + { + const float Angle = (static_cast(ArmIndex) / static_cast(ArmCount)) * 2.0f * PI; + const FVector Dir2D(FMath::Cos(Angle), FMath::Sin(Angle), 0.0f); + const FVector BranchA2D = Dir2D.RotateAngleAxis(38.0f, FVector::UpVector); + const FVector BranchB2D = Dir2D.RotateAngleAxis(-38.0f, FVector::UpVector); + + auto ToPlane = [PlaneIndex](const FVector& V) + { + if (PlaneIndex == 1) + { + return FVector(V.X, 0.0f, V.Y); + } + if (PlaneIndex == 2) + { + return FVector(0.0f, V.X, V.Y); + } + return V; + }; + + for (int32 Step = 1; Step <= StepsPerArm; ++Step) + { + const float Distance = StepDistance * static_cast(Step); + const float Size = FMath::Lerp(CrystalSize * 0.85f, CrystalSize * 0.38f, static_cast(Step) / StepsPerArm); + AddCrystal( + FString::Printf(TEXT("P%d_A%d_S%d"), PlaneIndex, ArmIndex, Step), + ToPlane(Dir2D * Distance), + FVector(Size / 50.0f), + SphereMesh, + Material); + + if (Step == 4 || Step == 6) + { + const float BranchLength = StepDistance * (Step == 4 ? 1.5f : 1.1f); + const FVector Base = Dir2D * Distance; + AddCrystal( + FString::Printf(TEXT("P%d_A%d_B%dL"), PlaneIndex, ArmIndex, Step), + ToPlane(Base + BranchA2D * BranchLength), + FVector(Size / 62.0f, Size / 62.0f, Size / 42.0f), + CubeMesh, + Material); + AddCrystal( + FString::Printf(TEXT("P%d_A%d_B%dR"), PlaneIndex, ArmIndex, Step), + ToPlane(Base + BranchB2D * BranchLength), + FVector(Size / 62.0f, Size / 62.0f, Size / 42.0f), + CubeMesh, + Material); + } + } + } + } +} + +void ARotatingSnowflakeActor::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + AddActorLocalRotation(RotationSpeed * DeltaSeconds); +} + +FLinearColor ARotatingSnowflakeActor::GetVoxelColorAt(const FVector& WorldPosition) const +{ + const FVector Local = GetActorTransform().InverseTransformPosition(WorldPosition); + const float Radius = FMath::Clamp(Local.Size() / FMath::Max(1.0f, ArmLength), 0.0f, 1.0f); + const float Pulse = 0.5f + 0.5f * FMath::Sin(GetWorld() ? GetWorld()->GetTimeSeconds() * 1.7f + Radius * 8.0f : Radius * 8.0f); + return FLinearColor::LerpUsingHSV(CoreColor, TipColor, Radius) * FMath::Lerp(0.65f, 1.35f, Pulse); +} + +void ARotatingSnowflakeActor::AddCrystal(const FString& Name, const FVector& Location, const FVector& Scale, UStaticMesh* Mesh, UMaterialInterface* Material) +{ + UStaticMeshComponent* Crystal = CreateDefaultSubobject(*Name); + Crystal->SetupAttachment(Root); + Crystal->SetRelativeLocation(Location); + Crystal->SetRelativeScale3D(Scale); + Crystal->SetCollisionEnabled(ECollisionEnabled::NoCollision); + Crystal->SetCanEverAffectNavigation(false); + Crystal->bCastDynamicShadow = false; + Crystal->CastShadow = false; + if (Mesh) + { + Crystal->SetStaticMesh(Mesh); + } + if (Material) + { + Crystal->SetMaterial(0, Material); + } + CrystalMeshes.Add(Crystal); +} diff --git a/Source/ledcube3d/RotatingSnowflakeActor.h b/Source/ledcube3d/RotatingSnowflakeActor.h new file mode 100644 index 0000000..05dc738 --- /dev/null +++ b/Source/ledcube3d/RotatingSnowflakeActor.h @@ -0,0 +1,47 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "RotatingSnowflakeActor.generated.h" + +class USceneComponent; +class UStaticMeshComponent; + +UCLASS(BlueprintType, Blueprintable) +class LEDCUBE3D_API ARotatingSnowflakeActor : public AActor +{ + GENERATED_BODY() + +public: + ARotatingSnowflakeActor(); + + virtual void Tick(float DeltaSeconds) override; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Voxel Source") + TObjectPtr Root; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Voxel Source") + TArray> CrystalMeshes; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel Source") + FLinearColor CoreColor = FLinearColor(0.25f, 0.95f, 1.0f, 1.0f); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel Source") + FLinearColor TipColor = FLinearColor(0.9f, 0.98f, 1.0f, 1.0f); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel Source") + FRotator RotationSpeed = FRotator(14.0f, 38.0f, 21.0f); + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel Source", meta = (ClampMin = "1.0")) + float ArmLength = 150.0f; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voxel Source", meta = (ClampMin = "0.1")) + float CrystalSize = 14.0f; + + FLinearColor GetVoxelColorAt(const FVector& WorldPosition) const; + +private: + void AddCrystal(const FString& Name, const FVector& Location, const FVector& Scale, UStaticMesh* Mesh, UMaterialInterface* Material); +}; diff --git a/Source/ledcube3d/ledcube3d.cpp b/Source/ledcube3d/ledcube3d.cpp index 8eecec5..989b81e 100644 --- a/Source/ledcube3d/ledcube3d.cpp +++ b/Source/ledcube3d/ledcube3d.cpp @@ -19,6 +19,7 @@ #include "RemoteControlPreset.h" #include "UObject/Package.h" #include "UObject/SavePackage.h" +#include "UObject/UnrealType.h" #endif class FLedcube3dModule : public FDefaultGameModuleImpl @@ -127,7 +128,10 @@ public: return; } - bRemotePresetBuilt = true; + if (BuildRemoteControlPreset()) + { + bRemotePresetBuilt = true; + } } bool TickBuildRemoteControlPreset(float DeltaSeconds) @@ -142,8 +146,8 @@ public: return true; } - bRemotePresetBuilt = true; - return false; + bRemotePresetBuilt = BuildRemoteControlPreset(); + return !bRemotePresetBuilt; } bool OpenDemoMapIfEditorStartedEmpty() @@ -234,11 +238,13 @@ public: { return false; } - if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("7") + if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("8") || (!bCreatedNewPreset && Preset->GetExposedEntities().Num() > 0)) { - Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7")); - return true; + if (Preset->Metadata.FindRef(TEXT("LedVolumeLivePresetBuilt")) == TEXT("8")) + { + return true; + } } auto GetOrCreateGroupId = [Preset](const FName GroupName) @@ -268,8 +274,15 @@ public: Preset->ExposeProperty(Controller, FRCFieldPathInfo(PropertyName), FRemoteControlPresetExposeArgs(PropertyName, GroupId)); }; - auto ExposeFunction = [Preset, Controller](const FString& FunctionName, const FString& GroupName) + TSet ExposedFunctionNames; + auto ExposeFunction = [Preset, Controller, &ExposedFunctionNames](const FString& FunctionName, const FString& GroupName) { + if (ExposedFunctionNames.Contains(FunctionName)) + { + return; + } + ExposedFunctionNames.Add(FunctionName); + const FGuid GroupId = Preset->Layout.GetGroupByName(*GroupName) ? Preset->Layout.GetGroupByName(*GroupName)->Id : Preset->Layout.CreateGroup(*GroupName).Id; @@ -335,7 +348,7 @@ public: ExposeProperty(Name, TEXT("LED Prepared Animation")); } - for (const FString& Name : { TEXT("VoxelizedSublevel"), TEXT("CaptureBoundsExtent"), TEXT("bUseActorBoundsAsCaptureVolume"), TEXT("SourceActorTag"), TEXT("EmptyVoxelColor") }) + for (const FString& Name : { TEXT("SublevelSourcePreset"), TEXT("VoxelizedSublevel"), TEXT("CaptureBoundsExtent"), TEXT("bUseActorBoundsAsCaptureVolume"), TEXT("SourceActorTag"), TEXT("EmptyVoxelColor") }) { ExposeProperty(Name, TEXT("LED Sublevel Source")); } @@ -345,6 +358,19 @@ public: ExposeProperty(Name, TEXT("LED Status")); } + for (TFieldIterator It(Controller->GetClass(), EFieldIteratorFlags::IncludeSuper); It; ++It) + { + FProperty* Property = *It; + if (!Property || !Property->HasAnyPropertyFlags(CPF_Edit)) + { + continue; + } + + const FString PropertyName = Property->GetName(); + const FString Category = Property->GetMetaData(TEXT("Category")); + ExposeProperty(PropertyName, Category.IsEmpty() ? TEXT("LED Auto Parameters") : Category); + } + for (const FString& Name : { TEXT("ApplyToTarget"), TEXT("RebuildTarget"), @@ -377,12 +403,24 @@ public: ExposeFunction(Name, Name.StartsWith(TEXT("Set")) ? TEXT("LED Setters") : TEXT("LED Commands")); } + for (TFieldIterator It(Controller->GetClass(), EFieldIteratorFlags::IncludeSuper); It; ++It) + { + UFunction* Function = *It; + if (!Function || !Function->HasAnyFunctionFlags(FUNC_BlueprintCallable | FUNC_BlueprintPure)) + { + continue; + } + const FString FunctionName = Function->GetName(); + const FString Category = Function->GetMetaData(TEXT("Category")); + ExposeFunction(FunctionName, Category.IsEmpty() ? TEXT("LED Auto Functions") : Category); + } + { const FGuid GroupId = GetOrCreateGroupId(TEXT("Scene Actors")); Preset->ExposeActor(Controller, FRemoteControlPresetExposeArgs(TEXT("LED_Remote_Control"), GroupId)); } - Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("7")); + Preset->Metadata.Add(TEXT("LedVolumeLivePresetBuilt"), TEXT("8")); Package->MarkPackageDirty(); const FString PackageFileName = FPackageName::LongPackageNameToFilename(PackageName, FPackageName::GetAssetPackageExtension()); FSavePackageArgs SaveArgs;