MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / BuildActorRow

Function BuildActorRow

Source/URLabEditor/Private/MjLevelOps.cpp:1011–1048  ·  view source on GitHub ↗

Build the same per-actor row shape ListActorsSync emits. Lifted out so FindActorsSync + SnapshotSceneSync share it.

Source from the content-addressed store, hash-verified

1009// Build the same per-actor row shape ListActorsSync emits. Lifted
1010// out so FindActorsSync + SnapshotSceneSync share it.
1011TSharedPtr<FJsonObject> BuildActorRow(AActor* A)
1012{
1013 TSharedPtr<FJsonObject> Obj = MakeShared<FJsonObject>();
1014 Obj->SetStringField(TEXT("name"), A->GetName());
1015#if WITH_EDITOR
1016 FString Label = A->GetActorLabel();
1017#else
1018 FString Label = A->GetName();
1019#endif
1020 if (Label.IsEmpty())
1021 Label = A->GetName();
1022 Obj->SetStringField(TEXT("label"), Label);
1023 Obj->SetStringField(TEXT("class"), A->GetClass()->GetName());
1024 Obj->SetStringField(TEXT("actor_id"), ExtractActorId(A));
1025
1026 const FVector UELoc = A->GetActorLocation();
1027 const FQuat UEQ = A->GetActorQuat();
1028 double MjPos[3], MjQuat[4];
1029 MjUtils::UEToMjPosition(UELoc, MjPos);
1030 MjUtils::UEToMjRotation(UEQ, MjQuat);
1031 TArray<TSharedPtr<FJsonValue>> LocOut;
1032 for (int i = 0; i < 3; ++i)
1033 LocOut.Add(MakeShared<FJsonValueNumber>(MjPos[i]));
1034 Obj->SetArrayField(TEXT("location"), LocOut);
1035 // Bridge convention: xyzw on the wire, MJ stores wxyz.
1036 TArray<TSharedPtr<FJsonValue>> QuatOut;
1037 QuatOut.Add(MakeShared<FJsonValueNumber>(MjQuat[1]));
1038 QuatOut.Add(MakeShared<FJsonValueNumber>(MjQuat[2]));
1039 QuatOut.Add(MakeShared<FJsonValueNumber>(MjQuat[3]));
1040 QuatOut.Add(MakeShared<FJsonValueNumber>(MjQuat[0]));
1041 Obj->SetArrayField(TEXT("rotation_quat"), QuatOut);
1042
1043 TArray<TSharedPtr<FJsonValue>> TagsOut;
1044 for (const FName& Tag : A->Tags)
1045 TagsOut.Add(MakeShared<FJsonValueString>(Tag.ToString()));
1046 Obj->SetArrayField(TEXT("tags"), TagsOut);
1047 return Obj;
1048}
1049
1050UWorld* PickWorld(bool bWantPie, bool& bOutChosePie)
1051{

Callers 2

FindActorsSyncFunction · 0.85
SnapshotSceneSyncFunction · 0.85

Calls 3

ExtractActorIdFunction · 0.85
IsEmptyMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected