From 440d07922550088125513b5f5a5c39768f3d06ac Mon Sep 17 00:00:00 2001 From: Jb win Date: Fri, 2 May 2025 23:23:25 +0700 Subject: [PATCH] FT - EpisodeSubSystem + Integrate DataTransfer plugin into project + Raw architecture of EpisodeSubSystem --- Source/LuckyWorldV2/LuckyWorldV2.Build.cs | 2 +- .../Private/Episode/EpisodeSubSystem.cpp | 51 +++++++++++++++++++ .../RobotPilotSO100Component.cpp | 3 -- .../LuckyWorldV2/Private/Robot/RobotPawn.cpp | 23 ++++++++- .../Public/Episode/EpisodeSubSystem.h | 35 +++++++++++++ Source/LuckyWorldV2/Public/Robot/RobotPawn.h | 12 ++++- 6 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 Source/LuckyWorldV2/Private/Episode/EpisodeSubSystem.cpp create mode 100644 Source/LuckyWorldV2/Public/Episode/EpisodeSubSystem.h diff --git a/Source/LuckyWorldV2/LuckyWorldV2.Build.cs b/Source/LuckyWorldV2/LuckyWorldV2.Build.cs index 0c55e960..e7a8cf2f 100644 --- a/Source/LuckyWorldV2/LuckyWorldV2.Build.cs +++ b/Source/LuckyWorldV2/LuckyWorldV2.Build.cs @@ -23,7 +23,7 @@ public class LuckyWorldV2 : ModuleRules "RenderCore" }); - PrivateDependencyModuleNames.AddRange(new string[] { }); + PrivateDependencyModuleNames.AddRange(new string[] {"LuckyDataTransfer"}); // Uncomment if you are using Slate UI // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); diff --git a/Source/LuckyWorldV2/Private/Episode/EpisodeSubSystem.cpp b/Source/LuckyWorldV2/Private/Episode/EpisodeSubSystem.cpp new file mode 100644 index 00000000..8fe36473 --- /dev/null +++ b/Source/LuckyWorldV2/Private/Episode/EpisodeSubSystem.cpp @@ -0,0 +1,51 @@ +#include "Episode/EpisodeSubSystem.h" + + +UEpisodeSubSystem::UEpisodeSubSystem() +{ +} + +void UEpisodeSubSystem::Initialize(FSubsystemCollectionBase& Collection) +{ + Super::Initialize(Collection); +} + +void UEpisodeSubSystem::Deinitialize() +{ + Super::Deinitialize(); +} + +void UEpisodeSubSystem::Tick(float DeltaTime) +{ + // if capture has started + if (!bIsCapturing) return; + + // Flow that we need to figure out + + // ProceduralSceneController - is object spawned? -> If not spawn it + // if object spawned && !robot.hasTarget -> Robot -> SetTarget + // if object.IsSpawned && robot.hasTarget -> Capture and send data + // ProceduralSceneController -> is object collected? + // How to reset the episode? +} + +void UEpisodeSubSystem::StartNewEpisode() +{ + // Noah + // Configure the DataTransfer -> Use CurrentRobot->Cameras + // Start the Capture + // Make specs for JB to add API on the robot data + + // JB + // Find the current Robot in Scene + // Store as CurrentRobot + // Order the robot to go fetch an object + + // Both of us once we finished our own tasks and synced + // - Spawn the shape at random locations -> might need another controller like ProceduralSceneSubSystem? + // - Add the timestamp debug component on the scene to check if the rendered frame and the data are in sync + + // TODO Which Tick is responsible of the scene capture? + + bIsCapturing = true; +} diff --git a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp index 3458e886..70cc16c1 100644 --- a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp +++ b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp @@ -1,10 +1,7 @@ #include "Robot/PilotComponent/RobotPilotSO100Component.h" - #include "Actors/MujocoVolumeActor.h" #include "Kismet/KismetMathLibrary.h" -#include "Kismet/KismetSystemLibrary.h" #include "Robot/RobotPawn.h" -#include "Serialization/ShaderKeyGenerator.h" URobotPilotSO100Component::URobotPilotSO100Component() { diff --git a/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp b/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp index 2bbe3402..efe16ce5 100644 --- a/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp +++ b/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp @@ -1,5 +1,9 @@ #include "Robot/RobotPawn.h" +#include "LuckySensorPawnBase.h" +#include "Kismet/GameplayStatics.h" +#include "Kismet/KismetMathLibrary.h" +#include "Kismet/KismetSystemLibrary.h" #include "Robot/PilotComponent/RobotPilotMultiRotorDrone.h" #include "Robot/PilotComponent/RobotPilotSO100Component.h" @@ -10,13 +14,13 @@ ARobotPawn::ARobotPawn() void ARobotPawn::BeginPlay() { Super::BeginPlay(); - InitRobot(); // TODO Maybe move to GameInstance to control when we initialize the robot completely + // InitRobot(); // TODO Maybe move to GameInstance to control when we initialize the robot completely } void ARobotPawn::InitRobot() { InitPilotComponent(); - // Other initialization tasks + InitCamera(); } void ARobotPawn::InitPilotComponent() @@ -65,3 +69,18 @@ void ARobotPawn::InitPilotComponent() RobotPilotComponent->RegisterComponent(); } } + +void ARobotPawn::InitCamera() +{ + // TODO Fix the spawning of sensors in Cpp and spawn them using a config? + // TODO How people can move the camera themselves? + + // Find all sensors in the scene + TArray Sensors; + UGameplayStatics::GetAllActorsOfClass(this->GetWorld(), ALuckySensorPawnBase::StaticClass(), Sensors); + + for (const auto Sensor : Sensors) + { + if (const auto Camera = Cast(Sensor)) Cameras.Add(Camera); + } +} diff --git a/Source/LuckyWorldV2/Public/Episode/EpisodeSubSystem.h b/Source/LuckyWorldV2/Public/Episode/EpisodeSubSystem.h new file mode 100644 index 00000000..15f5ec7f --- /dev/null +++ b/Source/LuckyWorldV2/Public/Episode/EpisodeSubSystem.h @@ -0,0 +1,35 @@ +#pragma once +#include "CoreMinimal.h" +#include "Subsystems/WorldSubsystem.h" +#include "EpisodeSubSystem.generated.h" + + +class ARobotPawn; + +UCLASS() +class LUCKYWORLDV2_API UEpisodeSubSystem : public UWorldSubsystem +{ + GENERATED_BODY() + +public: + // Setup + UEpisodeSubSystem(); + virtual void Initialize(FSubsystemCollectionBase& Collection); + virtual void Deinitialize(); + + virtual void Tick(float DeltaTime); + + // --------------------- + // ------- START ------- + // --------------------- + /** + * Called by the UI when pressing the "Capture" button + */ + void StartNewEpisode(); + +private: + bool bIsCapturing = false; + + UPROPERTY() + TObjectPtr CurrentRobot; +}; diff --git a/Source/LuckyWorldV2/Public/Robot/RobotPawn.h b/Source/LuckyWorldV2/Public/Robot/RobotPawn.h index 80b5177f..eacbb89d 100644 --- a/Source/LuckyWorldV2/Public/Robot/RobotPawn.h +++ b/Source/LuckyWorldV2/Public/Robot/RobotPawn.h @@ -3,6 +3,7 @@ #include "SharedDef.h" #include "RobotPawn.generated.h" +class ALuckySensorPawnBase; class AMujocoVolumeActor; class URobotPilotComponent; @@ -19,6 +20,7 @@ public: virtual void BeginPlay() override; // TODO Called by GameInstance after robot has been spawned + UFUNCTION(BlueprintCallable) void InitRobot(); UPROPERTY(EditAnywhere, BlueprintReadWrite) @@ -37,5 +39,13 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) URobotPilotComponent* RobotPilotComponent = nullptr; UFUNCTION(BlueprintCallable) - void InitPilotComponent(); // This should have Robot type as parameter? + void InitPilotComponent(); // This should have Robot type as parameter? + + + // --------------------- + // ------ SENSORS ------ + // --------------------- + void InitCamera(); + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TArray> Cameras; };