Go to the documentation of this file.
23 #include "CoreMinimal.h"
37 #include "Math/Color.h"
39 #include "Misc/Paths.h"
45 #include "logUtilities.h"
55 #include "RRActorCommon.generated.h"
59 #define RAPYUTA_SIM_VERBOSE (0) // todo make this CVar
65 #define RAPYUTA_SIM_DEBUG (0)
67 #define RAPYUTA_SIM_VISUAL_DEBUG (0)
71 #define RAPYUTA_USE_SCENE_DIRECTOR (0)
75 #define RAPYUTA_RUNTIME_MESH_ENTITY_USE_STATIC_MESH (1)
77 #define RAPYUTA_RUNTIME_MESH_ENTITY_USE_PROCEDURAL_MESH (!RAPYUTA_RUNTIME_MESH_ENTITY_USE_STATIC_MESH)
118 FTransform TargetTransform = FTransform::Identity;
126 return !AssetPath.IsEmpty();
136 UE_LOG_WITH_INFO(LogTemp, Log, TEXT(
"- AssetPath: %s"), *AssetPath);
138 UE_LOG_WITH_INFO(LogTemp, Log, TEXT(
"- TargetTransform: %s"), *TargetTransform.ToString());
160 template<
typename TResult>
172 bool DoneStatus =
false;
200 *
this = MoveTemp(Other);
210 Task = MoveTemp(Other.Task);
216 DoneStatus = Other.DoneStatus;
218 Other.DoneStatus =
false;
228 explicit FRRAsyncJob(
const FString& InJobName) : JobName(InJobName)
238 verify(AsyncTasks.Num() == Other.AsyncTasks.Num());
240 for (int32 i = 0; i < AsyncTasks.Num(); ++i)
246 AsyncTasks[i] = MoveTemp(Other.AsyncTasks[i]);
250 Other.AsyncTasks.Empty();
256 static constexpr
const int8 TASK_INDEX_NONE = -1;
266 uint64 LatestCaptureBatchId = 0;
284 return AsyncTasks.Num();
296 verify(AsyncTasks.Num());
298 AsyncTasks.Last().Task = MoveTemp(InAsyncTask);
304 void AddAsyncTask(
const uint64 InCaptureBatchId, TFuture<bool>&& InAsyncTask)
308 LatestCaptureBatchId = InCaptureBatchId;
310 AsyncTasks.Emplace(MoveTemp(InAsyncTask));
332 LatestCaptureBatchId = 0;
342 if (TASK_INDEX_NONE == TaskIndex)
352 if (AsyncTasks.IsValidIndex(TaskIndex))
356 AsyncTasks[TaskIndex].DoneStatus =
true;
358 #if RAPYUTA_SIM_DEBUG
360 UE_LOG_WITH_INFO(LogTemp, Display, TEXT(
"[%s] Async Task done [%d]/[%d]!"), *TaskName, (TaskIndex + 1), GetTasksNum());
372 LogTemp, Error, TEXT(
"[%s] FRRAsyncJob Invalid Async Task Index: %d/%d"), *TaskName, TaskIndex, GetTasksNum());
384 for (
const auto& asyncTask : AsyncTasks)
388 if (!asyncTask.DoneStatus)
408 for (
const auto& asyncTask : AsyncTasks)
412 asyncTask.Task.Get();
468 TArray<AActor*> actors;
470 for (
auto& entity : Entities)
474 actors.Add((AActor*)entity);
490 return Entities[Index];
502 return Entities.Num();
508 FString GetGroupModelName()
const;
514 FString GetGroupName()
const;
553 const FString& InGroupModelName,
555 const FString& InGroupName,
557 const FString& InSegMaskDepthStencilStr,
559 const uint64 InSceneId)
561 : Entities(MoveTemp(InEntities)),
563 GroupModelName(InGroupModelName),
565 GroupName(InGroupName),
567 SegMaskDepthStencilStr(InSegMaskDepthStencilStr),
637 FTransform WorldTransform = FTransform::Identity;
676 template<
int8 InBitDepth>
678 using FRRColor =
typename TChooseClass<(8 == InBitDepth),
682 typename TChooseClass<(16 == InBitDepth), FFloat16Color, FLinearColor>::Result>::Result;
723 template<
int8 InBitDepth>
729 if constexpr (8 == InBitDepth)
737 else if constexpr (16 == InBitDepth)
741 return Float16Colors;
745 else if constexpr (32 == InBitDepth)
749 return Float32Colors;
757 UE_LOG_WITH_INFO(LogRapyutaCore, Fatal, TEXT(
"unsupported bit-depth [%d]"), InBitDepth);
765 template<
int8 InBitDepth>
771 return *
const_cast<TArray<FRRColor<InBitDepth>
>*>(&GetImageData<InBitDepth>());
777 FORCEINLINE int64
Num(int8 InBitDepth)
const
787 return GetImageData<8>().Num();
791 return GetImageData<16>().Num();
795 return GetImageData<32>().Num();
799 UE_LOG_WITH_INFO(LogTemp, Fatal, TEXT(
"FRRColorArray::Num(): unsupported bit-depth [%d]"), InBitDepth);
809 FORCEINLINE
bool HasData(int8 InBitDepth)
const
813 return (Num(InBitDepth) > 0);
829 for (
auto& color : ImageData<8>())
833 color.A = bAlphaEnabled ? FColor::Black.A : FColor::Transparent.A;
841 for (
auto& color : ImageData<16>())
845 color.A = bAlphaEnabled ? FLinearColor::Black.A : FLinearColor::Transparent.A;
853 for (
auto& color : ImageData<32>())
857 color.A = bAlphaEnabled ? FLinearColor::Black.A : FLinearColor::Transparent.A;
865 UE_LOG_WITH_INFO(LogRapyutaCore, Fatal, TEXT(
"unsupported bit-depth [%d]"), InBitDepth);
892 const FString& InUniqueName,
894 const FTransform& InActorTransform,
896 const TArray<FTransform>& InMeshRelTransformList = TArray<FTransform>(),
898 const TArray<FString>& InMeshUniqueNameList = TArray<FString>(),
900 const TArray<FString>& InMaterialNameList = TArray<FString>(),
902 bool bInIsStationary =
false,
904 bool bInIsPhysicsEnabled =
false,
906 bool bInIsCollisionEnabled =
false,
908 bool bInIsOverlapEventEnabled =
false);
912 void operator()(
const FString& InEntityModelName,
914 const FString& InUniqueName,
916 const FTransform& InActorTransform = FTransform::Identity,
918 const TArray<FTransform>& InMeshRelTransformList = TArray<FTransform>(),
920 const TArray<FString>& InMeshUniqueNameList = TArray<FString>(),
922 const TArray<FString>& InMaterialNameList = TArray<FString>(),
924 bool bInIsStationary =
false,
926 bool bInIsPhysicsEnabled =
false,
928 bool bInIsCollisionEnabled =
false,
930 bool bInIsOverlapEventEnabled =
false);
938 MeshUniqueNameList.Reset();
940 MeshRelTransformList.Reset();
942 MaterialNameList.Reset();
989 FTransform ActorTransform = FTransform::Identity;
1092 TSubclassOf<AActor> TypeClass =
nullptr;
1100 return (
false == EntityModelName.IsEmpty());
1149 static constexpr int8 DEFAULT_SCENE_INSTANCE_ID = 0;
1153 UClass* ActorCommonClass =
nullptr,
1155 UObject* Outer =
nullptr);
1159 static constexpr
const TCHAR* SCRIPT_INI_PATH = TEXT(
"/Script/RapyutaSimulationPlugins.RRActorCommon");
1179 static void OnPostWorldCleanup(UWorld* InWorld,
bool ,
bool );
1185 static constexpr
const TCHAR* SPACE_STR = TEXT(
" ");
1187 static constexpr
const TCHAR* DELIMITER_STR = TEXT(
",");
1189 static constexpr
const TCHAR* UNDERSCORE_STR = TEXT(
"_");
1191 static constexpr
const char* NAN_STR =
"NaN";
1195 static constexpr
const char* NONE_STR =
"None";
1197 static constexpr
const char* NULL_STR =
"Null";
1201 static constexpr
const char* DOUBLE_QUOTE_CHAR =
"\"";
1205 static constexpr int32 SIM_SCENE_COMPLETION_TIMEOUT_SECS = 10;
1209 static constexpr int8 IMAGE_BIT_DEPTH_INT8 = 8;
1211 static constexpr int8 IMAGE_BIT_DEPTH_FLOAT16 = 16;
1213 static constexpr int8 IMAGE_BIT_DEPTH_FLOAT32 = 32;
1217 static constexpr
const TCHAR* MAP_ORIGIN_TAG = TEXT(
"map_origin");
1219 static constexpr
const TCHAR* MAP_ROS_FRAME_ID = TEXT(
"map");
1230 int8 SceneInstanceId = DEFAULT_SCENE_INSTANCE_ID;
1241 FVector SceneInstanceLocation = FVector::ZeroVector;
1255 return ++SLatestSceneId;
1268 uint64 CurrentSceneId = 0;
1279 AActor* SceneFloor =
nullptr;
1292 AActor* SceneWall =
nullptr;
1318 virtual void PrintSimConfig()
const;
1324 virtual void OnStartSim();
1340 virtual void OnEndPlay(
const EEndPlayReason::Type EndPlayReason)
1356 virtual bool HasInitialized(
bool bIsLogged =
false)
const;
1360 virtual void SetupEnvironment();
1390 static constexpr int16 MAX_CUSTOM_DEPTH_STENCIL_VALUES_NUM = 76;
1392 static constexpr int8 DEFAULT_CUSTOM_DEPTH_STENCIL_VALUE_VOID = 0;
1409 int32 LatestCustomDepthStencilValue = 0;
1419 if (LatestCustomDepthStencilValue > MAX_CUSTOM_DEPTH_STENCIL_VALUES_NUM)
1423 UE_LOG_WITH_INFO(LogTemp,
1427 TEXT(
"SceneInstance[%d] [%d] More than %d CustomDepthStencil values having been assigned!"
1429 "Segmentation Mask will be duplicated!"),
1433 LatestCustomDepthStencilValue,
1435 MAX_CUSTOM_DEPTH_STENCIL_VALUES_NUM);
1447 ++LatestCustomDepthStencilValue;
1449 }
while (StaticCustomDepthStencilList.Contains(LatestCustomDepthStencilValue));
1451 return LatestCustomDepthStencilValue;
1496 virtual void ConfigureStaticClasses();
1500 virtual bool IsValid(
bool bIsLogged =
false)
const;
const TArray< FRRColor< InBitDepth > > & GetImageData() const
Definition: RRActorCommon.h:725
FRRSingleAsyncTask(FRRSingleAsyncTask &&Other)
TFuture is move-only, thus this is to facilitate this class' Move operation!
Definition: RRActorCommon.h:196
FRRSingleAsyncTask(TFuture< TResult > &&InAsyncTask)
TFuture is move-only, only exposing a move-ctor.
Definition: RRActorCommon.h:186
FORCEINLINE bool HasData(int8 InBitDepth) const
Definition: RRActorCommon.h:809
Definition: RRActorCommon.h:693
Scene Instance, Eg: ARRSceneDirector, a scene unit among many residing in the same level.
Definition: RRActorCommon.h:1490
TArray< AActor * > Entities
Definition: RRActorCommon.h:582
Unreal Engine Mudule class.
TArray< FVector > BBVertices3DInWorld
Bounding box 3D vertices of the whole group in world coordinate.
Definition: RRActorCommon.h:648
static TMap< int8, URRActorCommon * > SActorCommonList
Definition: RRActorCommon.h:1143
uint8 bIsOverlapEventEnabled
Definition: RRActorCommon.h:1070
static uint64 SLatestSceneId
Generate a new scene id.
Definition: RRActorCommon.h:1249
Scene instance's common object which houses Plugin-specific dynamic properties and implement objects-...
Definition: RRActorCommon.h:1127
Group of homogeneous-mesh entities.
Definition: RRActorCommon.h:433
FRRAsyncJob(FRRAsyncJob &&Other)
Definition: RRActorCommon.h:234
uint8 bIsSelfCollision
Definition: RRActorCommon.h:1061
FRREntityLogInfo()
Definition: RRActorCommon.h:543
For storing entity info in advance for the Logging task.
Definition: RRActorCommon.h:533
int32 GenerateUniqueDepthStencilValue()
Generate a new unique custom depth stencil value for a mesh actor's Segmentation mask.
Definition: RRActorCommon.h:1415
void AddDefaultAsyncTask()
Definition: RRActorCommon.h:316
static constexpr int8 DEFAULT_SCENE_INSTANCE_ID
Definition: RRActorCommon.h:1149
TSubclassOf< ARRSceneDirector > SceneDirectorClass
Definition: RRActorCommon.h:1540
void Clear()
Definition: RRActorCommon.h:326
uint8 bIsDataSynthEntity
Definition: RRActorCommon.h:1079
Core utils.
Definition: RRCoreUtils.h:112
TArray< FVector > BBVertices3DInCamera
Bounding box 3D vertices of the whole group in camera coordinate.
Definition: RRActorCommon.h:659
FString GroupModelName
Common model name of the Entities group.
Definition: RRActorCommon.h:593
TArray< FVector2D > BBVertices2D
Bounding box 2D vertices of the whole group, as projected onto camera.
Definition: RRActorCommon.h:670
FString SegMaskDepthStencilStr
Segmentation mask custom depth stencil hexa values in string format.
Definition: RRActorCommon.h:615
FOnMeshActorFullyCreated OnMeshActorFullyCreated
Move the common main environment to another scene instance.
Definition: RRActorCommon.h:1368
DECLARE_DELEGATE_TwoParams(FOnMeshActorFullyCreated, bool, ARRMeshActor *)
static TArray< int32 > StaticCustomDepthStencilList
This list contains Static Objects' [CustomDepthStencilValue]s that are assigned once and never change...
Definition: RRActorCommon.h:1400
Game state which handles multiple URRSceneInstance which spit game in scenes for data gen,...
Definition: RRGameState.h:64
Mesh actor.ARRBaseActor with list of #UMeshComponent.
Definition: RRMeshActor.h:58
Definition: RRActorCommon.h:98
Definition: RRActorCommon.h:882
FString UniqueName
Actually GetName() is also unique as noted by UE, but we just do not want to rely on it.
Definition: RRActorCommon.h:980
FString JobName
Definition: RRActorCommon.h:260
TArray< FString > MaterialNameList
Definition: RRActorCommon.h:1016
FRREntityLogInfo(TArray< AActor * > InEntities, const FString &InGroupModelName, const FString &InGroupName, const FString &InSegMaskDepthStencilStr, const uint64 InSceneId)
Definition: RRActorCommon.h:551
void ToggleAlpha(int8 InBitDepth, bool bAlphaEnabled)
Definition: RRActorCommon.h:819
FRRSingleAsyncTask()
Definition: RRActorCommon.h:176
FRRAsyncJob(const FString &InJobName)
Definition: RRActorCommon.h:228
TArray< FFloat16Color > Float16Colors
Definition: RRActorCommon.h:710
TArray< FRRSingleAsyncTask< bool > > AsyncTasks
Definition: RRActorCommon.h:270
bool IsValid(bool bIsLogged=false) const
Definition: RRActorCommon.h:1096
void PrintSelf() const
Definition: RRActorCommon.h:132
TArray< FColor > Colors
Definition: RRActorCommon.h:704
TSubclassOf< URRActorCommon > ActorCommonClass
Definition: RRActorCommon.h:1520
static const std::string QUOTED_NAN_STR
Definition: RRActorCommon.h:1193
static std::once_flag OnceFlag
Definition: RRActorCommon.h:1161
FORCEINLINE int64 Num(int8 InBitDepth) const
Definition: RRActorCommon.h:777
void WaitUntilCompleted()
Definition: RRActorCommon.h:404
uint8 bIsPhysicsEnabled
Definition: RRActorCommon.h:1043
void MarkSingleTaskAsDone(int32 TaskIndex, const FString &TaskName)
Definition: RRActorCommon.h:338
static const std::string QUOTED_NULL_STR
Definition: RRActorCommon.h:1199
uint8 bIsCollisionEnabled
Definition: RRActorCommon.h:1052
static FORCEINLINE uint64 GetNextSceneId()
Definition: RRActorCommon.h:1251
FRRSingleAsyncTask & operator=(FRRSingleAsyncTask &&Other)
Definition: RRActorCommon.h:206
uint8 bIsTickEnabled
Definition: RRActorCommon.h:1025
Player controller designed to be used with SceneDirector.
Definition: RRPlayerController.h:58
TFuture< TResult > Task
[TSharedFuture] should be considered if [Task] is accessed from multiple threads!
Definition: RRActorCommon.h:168
void SetAsyncTaskAtLast(TFuture< bool > &&InAsyncTask)
TFuture is move-only!
Definition: RRActorCommon.h:292
void AddAsyncTask(const uint64 InCaptureBatchId, TFuture< bool > &&InAsyncTask)
Definition: RRActorCommon.h:304
uint8 bIsStationary
Definition: RRActorCommon.h:1034
Definition: RRActorCommon.h:162
TArray< FString > MeshUniqueNameList
Definition: RRActorCommon.h:1007
int32 GetTasksNum() const
Definition: RRActorCommon.h:280
typename TChooseClass<(8==InBitDepth), FColor, typename TChooseClass<(16==InBitDepth), FFloat16Color, FLinearColor >::Result >::Result FRRColor
Definition: RRActorCommon.h:682
TArray< AActor * > GetActors() const
Fetch Entities as TArray<AActor*>
Definition: RRActorCommon.h:464
void ClearMeshInfo()
Definition: RRActorCommon.h:934
virtual void OnEndPlay(const EEndPlayReason::Type EndPlayReason)
Callback on ARRGameState::EndPlay() for this scene instance.
Definition: RRActorCommon.h:1340
FString EntityModelName
Definition: RRActorCommon.h:953
Standalone camera actor which can be placed in the level with #UCameraComponent.
Definition: RRCamera.h:118
TArray< ARRMeshActor * > Entities
Definition: RRActorCommon.h:458
Async job info (task, job name, latest capture batch id)
Definition: RRActorCommon.h:156
TArray< ALight * > MainLights
Definition: RRActorCommon.h:1312
FRRHomoMeshEntityGroup()
Definition: RRActorCommon.h:437
int32 Num() const
Get num of Entities.
Definition: RRActorCommon.h:498
virtual void OnBeginPlay()
Callback on ARRGameState::BeginPlay() for this scene instance.
Definition: RRActorCommon.h:1330
TArray< FTransform > MeshRelTransformList
Definition: RRActorCommon.h:998
ARRMeshActor * operator[](int32 Index) const
Fetch Entities[Index].
Definition: RRActorCommon.h:486
FString GroupName
Unique name of the entities group.
Definition: RRActorCommon.h:604
Execute Init/Run/Continue Sim type-specific operations (Data synthesizer/collection or Robot operatio...
Definition: RRSceneDirector.h:92
bool IsDone() const
Definition: RRActorCommon.h:380
TArray< FRRColor< InBitDepth > > & ImageData()
Definition: RRActorCommon.h:767
FRRHomoMeshEntityGroup(TArray< ARRMeshActor * > InEntities)
Definition: RRActorCommon.h:445
TArray< FLinearColor > Float32Colors
Definition: RRActorCommon.h:719
FString AssetPath
Definition: RRActorCommon.h:109
bool IsValid() const
Definition: RRActorCommon.h:122