Added vehicle light to recorder.
This commit is contained in:
parent
315bfc45bf
commit
8374172415
|
@ -70,7 +70,7 @@ public:
|
|||
return it != ActorDatabase.end() ? it->second : FActorView();
|
||||
}
|
||||
|
||||
FActorView Find(AActor *Actor) const
|
||||
FActorView Find(const AActor *Actor) const
|
||||
{
|
||||
auto PtrToId = Ids.Find(Actor);
|
||||
return PtrToId != nullptr ? Find(*PtrToId) : FActorView();
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
#include "Carla/Walker/WalkerControl.h"
|
||||
#include "Carla/Walker/WalkerController.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include "carla/rpc/VehicleLightState.h"
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
#include "CarlaRecorder.h"
|
||||
#include "CarlaReplayerHelper.h"
|
||||
|
||||
|
@ -82,6 +86,7 @@ void ACarlaRecorder::Tick(float DeltaSeconds)
|
|||
case FActorView::ActorType::Vehicle:
|
||||
AddActorPosition(View);
|
||||
AddVehicleAnimation(View);
|
||||
AddVehicleLight(View);
|
||||
break;
|
||||
|
||||
// save the transform of all walkers
|
||||
|
@ -205,6 +210,29 @@ void ACarlaRecorder::AddTrafficLightState(FActorView &View)
|
|||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddVehicleLight(FActorView &View)
|
||||
{
|
||||
AActor *Actor = View.GetActor();
|
||||
check(Actor != nullptr);
|
||||
|
||||
if (Actor->IsPendingKill())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto Vehicle = Cast<ACarlaWheeledVehicle>(Actor);
|
||||
if (Vehicle == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CarlaRecorderLightVehicle LightVehicle;
|
||||
LightVehicle.DatabaseId = View.GetActorId();
|
||||
auto LightState = Vehicle->GetVehicleLightState();
|
||||
LightVehicle.State = carla::rpc::VehicleLightState(LightState).light_state;
|
||||
AddLightVehicle(LightVehicle);
|
||||
}
|
||||
|
||||
std::string ACarlaRecorder::Start(std::string Name, FString MapName)
|
||||
{
|
||||
// stop replayer if any in course
|
||||
|
@ -268,6 +296,7 @@ void ACarlaRecorder::Clear(void)
|
|||
States.Clear();
|
||||
Vehicles.Clear();
|
||||
Walkers.Clear();
|
||||
LightVehicles.Clear();
|
||||
}
|
||||
|
||||
void ACarlaRecorder::Write(double DeltaSeconds)
|
||||
|
@ -291,6 +320,7 @@ void ACarlaRecorder::Write(double DeltaSeconds)
|
|||
// animations
|
||||
Vehicles.Write(File);
|
||||
Walkers.Write(File);
|
||||
LightVehicles.Write(File);
|
||||
|
||||
// end
|
||||
Frames.WriteEnd(File);
|
||||
|
@ -387,6 +417,14 @@ void ACarlaRecorder::AddAnimWalker(const CarlaRecorderAnimWalker &Walker)
|
|||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle)
|
||||
{
|
||||
if (Enabled)
|
||||
{
|
||||
LightVehicles.Add(LightVehicle);
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaRecorder::AddExistingActors(void)
|
||||
{
|
||||
// registring all existing actors in first frame
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
|
||||
#include "CarlaRecorderLightVehicle.h"
|
||||
#include "CarlaRecorderAnimVehicle.h"
|
||||
#include "CarlaRecorderAnimWalker.h"
|
||||
#include "CarlaRecorderCollision.h"
|
||||
|
@ -28,6 +29,8 @@
|
|||
|
||||
class AActor;
|
||||
class UCarlaEpisode;
|
||||
class ACarlaWheeledVehicle;
|
||||
struct FVehicleLightState;
|
||||
|
||||
enum class CarlaRecorderPacketId : uint8_t
|
||||
{
|
||||
|
@ -40,7 +43,9 @@ enum class CarlaRecorderPacketId : uint8_t
|
|||
Position,
|
||||
State,
|
||||
AnimVehicle,
|
||||
AnimWalker
|
||||
AnimWalker,
|
||||
VehicleLight,
|
||||
SceneLight
|
||||
};
|
||||
|
||||
/// Recorder for the simulation
|
||||
|
@ -89,6 +94,8 @@ public:
|
|||
|
||||
void AddAnimWalker(const CarlaRecorderAnimWalker &Walker);
|
||||
|
||||
void AddLightVehicle(const CarlaRecorderLightVehicle &LightVehicle);
|
||||
|
||||
// set episode
|
||||
void SetEpisode(UCarlaEpisode *ThisEpisode)
|
||||
{
|
||||
|
@ -142,6 +149,7 @@ private:
|
|||
CarlaRecorderStates States;
|
||||
CarlaRecorderAnimVehicles Vehicles;
|
||||
CarlaRecorderAnimWalkers Walkers;
|
||||
CarlaRecorderLightVehicles LightVehicles;
|
||||
|
||||
// replayer
|
||||
CarlaReplayer Replayer;
|
||||
|
@ -154,4 +162,5 @@ private:
|
|||
void AddWalkerAnimation(FActorView &View);
|
||||
void AddVehicleAnimation(FActorView &View);
|
||||
void AddTrafficLightState(FActorView &View);
|
||||
void AddVehicleLight(FActorView &View);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "CarlaRecorderLightVehicle.h"
|
||||
#include "CarlaRecorder.h"
|
||||
#include "CarlaRecorderHelpers.h"
|
||||
|
||||
|
||||
void CarlaRecorderLightVehicle::Write(std::ofstream &OutFile)
|
||||
{
|
||||
// database id
|
||||
WriteValue<uint32_t>(OutFile, this->DatabaseId);
|
||||
WriteValue<VehicleLightStateType>(OutFile, this->State);
|
||||
}
|
||||
void CarlaRecorderLightVehicle::Read(std::ifstream &InFile)
|
||||
{
|
||||
// database id
|
||||
ReadValue<uint32_t>(InFile, this->DatabaseId);
|
||||
ReadValue<VehicleLightStateType>(InFile, this->State);
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
void CarlaRecorderLightVehicles::Clear(void)
|
||||
{
|
||||
Vehicles.clear();
|
||||
}
|
||||
|
||||
void CarlaRecorderLightVehicles::Add(const CarlaRecorderLightVehicle &Vehicle)
|
||||
{
|
||||
Vehicles.push_back(Vehicle);
|
||||
}
|
||||
|
||||
void CarlaRecorderLightVehicles::Write(std::ofstream &OutFile)
|
||||
{
|
||||
// write the packet id
|
||||
WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::VehicleLight));
|
||||
|
||||
std::streampos PosStart = OutFile.tellp();
|
||||
|
||||
// write a dummy packet size
|
||||
uint32_t Total = 0;
|
||||
WriteValue<uint32_t>(OutFile, Total);
|
||||
|
||||
// write total records
|
||||
Total = Vehicles.size();
|
||||
WriteValue<uint16_t>(OutFile, Total);
|
||||
|
||||
for (uint16_t i=0; i<Total; ++i)
|
||||
Vehicles[i].Write(OutFile);
|
||||
|
||||
// write the real packet size
|
||||
std::streampos PosEnd = OutFile.tellp();
|
||||
Total = PosEnd - PosStart - sizeof(uint32_t);
|
||||
OutFile.seekp(PosStart, std::ios::beg);
|
||||
WriteValue<uint32_t>(OutFile, Total);
|
||||
OutFile.seekp(PosEnd, std::ios::beg);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct CarlaRecorderLightVehicle
|
||||
{
|
||||
// Use same type as carla::rpc::VehicleLightState::LightState
|
||||
using VehicleLightStateType = uint32_t;
|
||||
|
||||
uint32_t DatabaseId;
|
||||
VehicleLightStateType State;
|
||||
|
||||
void Read(std::ifstream &InFile);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
struct CarlaRecorderLightVehicles
|
||||
{
|
||||
public:
|
||||
|
||||
void Add(const CarlaRecorderLightVehicle &InObj);
|
||||
|
||||
void Clear(void);
|
||||
|
||||
void Write(std::ofstream &OutFile);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<CarlaRecorderLightVehicle> Vehicles;
|
||||
};
|
|
@ -333,6 +333,14 @@ void CarlaReplayer::ProcessToTime(double Time, bool IsFirstTime)
|
|||
SkipPacket();
|
||||
break;
|
||||
|
||||
// vehicle light animation
|
||||
case static_cast<char>(CarlaRecorderPacketId::VehicleLight):
|
||||
if (bFrameFound)
|
||||
ProcessLightVehicle();
|
||||
else
|
||||
SkipPacket();
|
||||
break;
|
||||
|
||||
// frame end
|
||||
case static_cast<char>(CarlaRecorderPacketId::FrameEnd):
|
||||
if (bFrameFound)
|
||||
|
@ -515,6 +523,25 @@ void CarlaReplayer::ProcessAnimWalker(void)
|
|||
}
|
||||
}
|
||||
|
||||
void CarlaReplayer::ProcessLightVehicle(void)
|
||||
{
|
||||
uint16_t Total;
|
||||
CarlaRecorderLightVehicle LightVehicle;
|
||||
|
||||
// read Total walkers
|
||||
ReadValue<uint16_t>(File, Total);
|
||||
for (uint16_t i = 0; i < Total; ++i)
|
||||
{
|
||||
LightVehicle.Read(File);
|
||||
LightVehicle.DatabaseId = MappedId[LightVehicle.DatabaseId];
|
||||
// check if ignore this actor
|
||||
if (!(IgnoreHero && IsHeroMap[LightVehicle.DatabaseId]))
|
||||
{
|
||||
Helper.ProcessReplayerLightVehicle(LightVehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CarlaReplayer::ProcessPositions(bool IsFirstTime)
|
||||
{
|
||||
uint16_t i, Total;
|
||||
|
|
|
@ -141,6 +141,8 @@ private:
|
|||
void ProcessAnimVehicle(void);
|
||||
void ProcessAnimWalker(void);
|
||||
|
||||
void ProcessLightVehicle(void);
|
||||
|
||||
// positions
|
||||
void UpdatePositions(double Per, double DeltaTime);
|
||||
|
||||
|
|
|
@ -331,6 +331,24 @@ void CarlaReplayerHelper::ProcessReplayerAnimVehicle(CarlaRecorderAnimVehicle Ve
|
|||
}
|
||||
}
|
||||
|
||||
// set the lights for vehicles
|
||||
void CarlaReplayerHelper::ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle)
|
||||
{
|
||||
check(Episode != nullptr);
|
||||
AActor *Actor = Episode->GetActorRegistry().Find(LightVehicle.DatabaseId).GetActor();
|
||||
if (Actor && !Actor->IsPendingKill())
|
||||
{
|
||||
auto Veh = Cast<ACarlaWheeledVehicle>(Actor);
|
||||
if (Veh == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
carla::rpc::VehicleLightState LightState(LightVehicle.State);
|
||||
Veh->SetVehicleLightState(FVehicleLightState(LightState));
|
||||
}
|
||||
}
|
||||
|
||||
// set the animation for walkers
|
||||
void CarlaReplayerHelper::ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@ public:
|
|||
// set the animation for walkers
|
||||
void ProcessReplayerAnimWalker(CarlaRecorderAnimWalker Walker);
|
||||
|
||||
// set the vehicle light
|
||||
void ProcessReplayerLightVehicle(CarlaRecorderLightVehicle LightVehicle);
|
||||
|
||||
// replay finish
|
||||
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map<uint32_t, bool> &IsHero);
|
||||
|
||||
|
|
Loading…
Reference in New Issue