Renamed and added enable/disable call
This commit is contained in:
parent
ce31f3a1b6
commit
2fbfda2f24
|
@ -166,8 +166,14 @@ namespace client {
|
|||
return _episode.Lock()->GetLevelBBs(queried_tag);
|
||||
}
|
||||
|
||||
std::vector<rpc::Mesh> World::GetMeshes() const {
|
||||
return _episode.Lock()->GetMeshes();
|
||||
std::vector<rpc::EnvironmentObject> World::GetEnvironmentObjects() const {
|
||||
return _episode.Lock()->GetEnvironmentObjects();
|
||||
}
|
||||
|
||||
void World::EnableEnvironmentObjects(
|
||||
std::vector<uint64_t> env_objects_ids,
|
||||
bool enable) const {
|
||||
_episode.Lock()->EnableEnvironmentObjects(env_objects_ids, enable);
|
||||
}
|
||||
|
||||
} // namespace client
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "carla/rpc/Actor.h"
|
||||
#include "carla/rpc/AttachmentType.h"
|
||||
#include "carla/rpc/EpisodeSettings.h"
|
||||
#include "carla/rpc/Mesh.h"
|
||||
#include "carla/rpc/EnvironmentObject.h"
|
||||
#include "carla/rpc/VehiclePhysicsControl.h"
|
||||
#include "carla/rpc/WeatherParameters.h"
|
||||
#include "carla/rpc/VehicleLightStateList.h"
|
||||
|
@ -156,7 +156,11 @@ namespace client {
|
|||
/// Returns all the BBs of all the elements of the level
|
||||
std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const;
|
||||
|
||||
std::vector<rpc::Mesh> GetMeshes() const;
|
||||
std::vector<rpc::EnvironmentObject> GetEnvironmentObjects() const;
|
||||
|
||||
void EnableEnvironmentObjects(
|
||||
std::vector<uint64_t> env_objects_ids,
|
||||
bool enable) const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -450,9 +450,15 @@ namespace detail {
|
|||
return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
|
||||
}
|
||||
|
||||
std::vector<rpc::Mesh> Client::GetMeshes() const {
|
||||
using return_t = std::vector<rpc::Mesh>;
|
||||
return _pimpl->CallAndWait<return_t>("get_meshes");
|
||||
std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects() const {
|
||||
using return_t = std::vector<rpc::EnvironmentObject>;
|
||||
return _pimpl->CallAndWait<return_t>("get_environment_objects");
|
||||
}
|
||||
|
||||
void Client::EnableEnvironmentObjects(
|
||||
std::vector<uint64_t> env_objects_ids,
|
||||
bool enable) const {
|
||||
_pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "carla/rpc/EpisodeSettings.h"
|
||||
#include "carla/rpc/LightState.h"
|
||||
#include "carla/rpc/MapInfo.h"
|
||||
#include "carla/rpc/Mesh.h"
|
||||
#include "carla/rpc/EnvironmentObject.h"
|
||||
#include "carla/rpc/TrafficLightState.h"
|
||||
#include "carla/rpc/VehiclePhysicsControl.h"
|
||||
#include "carla/rpc/VehicleLightState.h"
|
||||
|
@ -291,7 +291,11 @@ namespace detail {
|
|||
/// Returns all the BBs of all the elements of the level
|
||||
std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const;
|
||||
|
||||
std::vector<rpc::Mesh> GetMeshes() const;
|
||||
std::vector<rpc::EnvironmentObject> GetEnvironmentObjects() const;
|
||||
|
||||
void EnableEnvironmentObjects(
|
||||
std::vector<uint64_t> env_objects_ids,
|
||||
bool enable) const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -231,8 +231,14 @@ namespace detail {
|
|||
return _client.GetLevelBBs(queried_tag);
|
||||
}
|
||||
|
||||
std::vector<rpc::Mesh> GetMeshes() const {
|
||||
return _client.GetMeshes();
|
||||
std::vector<rpc::EnvironmentObject> GetEnvironmentObjects() const {
|
||||
return _client.GetEnvironmentObjects();
|
||||
}
|
||||
|
||||
void EnableEnvironmentObjects(
|
||||
std::vector<uint64_t> env_objects_ids,
|
||||
bool enable) const {
|
||||
_client.EnableEnvironmentObjects(env_objects_ids, enable);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace carla {
|
|||
namespace rpc {
|
||||
|
||||
// Name is under discussion
|
||||
struct Mesh {
|
||||
struct EnvironmentObject {
|
||||
Transform transform;
|
||||
geom::BoundingBox bounding_box;
|
||||
uint64_t id = 0;
|
||||
|
@ -27,11 +27,11 @@ namespace rpc {
|
|||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
Mesh(const FCarlaMesh &CarlaMesh)
|
||||
: transform(CarlaMesh.Transform),
|
||||
bounding_box(CarlaMesh.BoundingBox),
|
||||
id(CarlaMesh.Id),
|
||||
name(TCHAR_TO_UTF8(*CarlaMesh.Name)) {}
|
||||
EnvironmentObject(const FEnvironmentObject &EnvironmentObject)
|
||||
: transform(EnvironmentObject.Transform),
|
||||
bounding_box(EnvironmentObject.BoundingBox),
|
||||
id(EnvironmentObject.Id),
|
||||
name(TCHAR_TO_UTF8(*EnvironmentObject.Name)) {}
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
#include <carla/client/Actor.h>
|
||||
#include <carla/client/ActorList.h>
|
||||
#include <carla/client/World.h>
|
||||
#include <carla/rpc/Mesh.h>
|
||||
#include <carla/rpc/EnvironmentObject.h>
|
||||
#include <carla/rpc/ObjectLabel.h>
|
||||
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
@ -38,11 +38,11 @@ namespace rpc {
|
|||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Mesh &mesh) {
|
||||
out << "Mesh(id=" << mesh.id << ", ";
|
||||
out << "name=" << mesh.name << ", ";
|
||||
out << "transform=" << mesh.transform << ", ";
|
||||
out << "bounding_box=" << mesh.bounding_box << ")";
|
||||
std::ostream &operator<<(std::ostream &out, const EnvironmentObject &environment_object) {
|
||||
out << "Mesh(id=" << environment_object.id << ", ";
|
||||
out << "name=" << environment_object.name << ", ";
|
||||
out << "transform=" << environment_object.transform << ", ";
|
||||
out << "bounding_box=" << environment_object.bounding_box << ")";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -89,15 +89,28 @@ static auto GetLevelBBs(const carla::client::World &self, uint8_t queried_tag) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static auto GetMeshes(const carla::client::World &self) {
|
||||
static auto GetEnvironmentObjects(const carla::client::World &self) {
|
||||
carla::PythonUtil::ReleaseGIL unlock;
|
||||
boost::python::list result;
|
||||
for (const auto &geometry : self.GetMeshes()) {
|
||||
for (const auto &geometry : self.GetEnvironmentObjects()) {
|
||||
result.append(geometry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void EnableEnvironmentObjects(
|
||||
carla::client::World &self,
|
||||
const boost::python::object& py_env_objects_ids,
|
||||
const bool enable ) {
|
||||
|
||||
std::vector<uint64_t> env_objects_ids {
|
||||
boost::python::stl_input_iterator<uint64_t>(py_env_objects_ids),
|
||||
boost::python::stl_input_iterator<uint64_t>()
|
||||
};
|
||||
|
||||
self.EnableEnvironmentObjects(env_objects_ids, enable);
|
||||
}
|
||||
|
||||
void export_world() {
|
||||
using namespace boost::python;
|
||||
namespace cc = carla::client;
|
||||
|
@ -149,11 +162,11 @@ void export_world() {
|
|||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cr::Mesh>("Mesh", no_init)
|
||||
.def_readwrite("transform", &cr::Mesh::transform)
|
||||
.def_readwrite("bounding_box", &cr::Mesh::bounding_box)
|
||||
.def_readwrite("id", &cr::Mesh::id)
|
||||
.def_readwrite("name", &cr::Mesh::name)
|
||||
class_<cr::EnvironmentObject>("EnvironmentObject", no_init)
|
||||
.def_readwrite("transform", &cr::EnvironmentObject::transform)
|
||||
.def_readwrite("bounding_box", &cr::EnvironmentObject::bounding_box)
|
||||
.def_readwrite("id", &cr::EnvironmentObject::id)
|
||||
.def_readwrite("name", &cr::EnvironmentObject::name)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
@ -232,7 +245,8 @@ void export_world() {
|
|||
.def("get_lightmanager", CONST_CALL_WITHOUT_GIL(cc::World, GetLightManager))
|
||||
.def("freeze_all_traffic_lights", &cc::World::FreezeAllTrafficLights, (arg("frozen")))
|
||||
.def("get_level_bbs", &GetLevelBBs, (arg("actor_type")=cr::CityObjectLabel::None))
|
||||
.def("get_meshes", &GetMeshes)
|
||||
.def("get_environment_objects", &GetEnvironmentObjects)
|
||||
.def("enable_environment_objects", &EnableEnvironmentObjects, (arg("env_objects_ids"), arg("enable")))
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <compiler/disable-ue4-macros.h>
|
||||
#include "carla/opendrive/OpenDriveParser.h"
|
||||
#include "carla/road/element/RoadInfoSignal.h"
|
||||
#include <carla/rpc/Mesh.h>
|
||||
#include <carla/rpc/EnvironmentObject.h>
|
||||
#include <carla/rpc/WeatherParameters.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
|
@ -155,7 +155,7 @@ void ACarlaGameModeBase::BeginPlay()
|
|||
Recorder->GetReplayer()->CheckPlayAfterMapLoaded();
|
||||
}
|
||||
|
||||
RegisterMeshes();
|
||||
RegisterEnvironmentObject();
|
||||
|
||||
}
|
||||
|
||||
|
@ -350,12 +350,12 @@ TArray<FBoundingBox> ACarlaGameModeBase::GetAllBBsOfLevel(uint8 TagQueried)
|
|||
return BoundingBoxes;
|
||||
}
|
||||
|
||||
TArray<FCarlaMesh> ACarlaGameModeBase::GetMeshes() const
|
||||
TArray<FEnvironmentObject> ACarlaGameModeBase::GetEnvironmentObjects() const
|
||||
{
|
||||
return Meshes;
|
||||
return EnvironmentObjects;
|
||||
}
|
||||
|
||||
void ACarlaGameModeBase::RegisterMeshes()
|
||||
void ACarlaGameModeBase::RegisterEnvironmentObject()
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
|
||||
|
@ -364,18 +364,38 @@ void ACarlaGameModeBase::RegisterMeshes()
|
|||
UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), FoundActors);
|
||||
|
||||
// Empties the array but doesn't change memory allocations
|
||||
Meshes.Reset();
|
||||
EnvironmentObjects.Reset();
|
||||
|
||||
for(AActor* Actor : FoundActors)
|
||||
{
|
||||
FString ActorName = Actor->GetName();
|
||||
const char* ActorNameChar = TCHAR_TO_ANSI(*ActorName);
|
||||
|
||||
FCarlaMesh CarlaMesh;
|
||||
CarlaMesh.Transform = Actor->GetActorTransform();
|
||||
CarlaMesh.Id = CityHash64(ActorNameChar, ActorName.Len());
|
||||
CarlaMesh.Name = ActorName;
|
||||
FEnvironmentObject EnvironmentObject;
|
||||
EnvironmentObject.Transform = Actor->GetActorTransform();
|
||||
EnvironmentObject.Id = CityHash64(ActorNameChar, ActorName.Len());
|
||||
EnvironmentObject.Name = ActorName;
|
||||
EnvironmentObject.Actor = Actor;
|
||||
|
||||
Meshes.Add(CarlaMesh);
|
||||
EnvironmentObjects.Emplace(EnvironmentObject);
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaGameModeBase::EnableEnvironmentObjects(
|
||||
const TSet<uint64>& EnvObjectIds,
|
||||
bool Enable)
|
||||
{
|
||||
|
||||
for(FEnvironmentObject& EnvironmentObject : EnvironmentObjects)
|
||||
{
|
||||
if(EnvObjectIds.Contains(EnvironmentObject.Id))
|
||||
{
|
||||
AActor* Actor = EnvironmentObject.Actor;
|
||||
|
||||
Actor->SetActorHiddenInGame(!Enable);
|
||||
Actor->SetActorEnableCollision(Enable);
|
||||
Actor->SetActorTickEnabled(Enable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
#include "Carla/Settings/CarlaSettingsDelegate.h"
|
||||
#include "Carla/Weather/Weather.h"
|
||||
#include "Carla/Traffic/TrafficLightManager.h"
|
||||
#include "Carla/Util/CarlaMesh.h"
|
||||
#include "Carla/Util/EnvironmentObject.h"
|
||||
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
@ -58,7 +58,9 @@ public:
|
|||
TArray<FBoundingBox> GetAllBBsOfLevel(uint8 TagQueried = 0);
|
||||
|
||||
UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec)
|
||||
TArray<FCarlaMesh> GetMeshes() const;
|
||||
TArray<FEnvironmentObject> GetEnvironmentObjects() const;
|
||||
|
||||
void EnableEnvironmentObjects(const TSet<uint64>& EnvObjectIds, bool Enable);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -78,7 +80,7 @@ private:
|
|||
|
||||
void ParseOpenDrive(const FString &MapName);
|
||||
|
||||
void RegisterMeshes();
|
||||
void RegisterEnvironmentObject();
|
||||
|
||||
UPROPERTY()
|
||||
UCarlaGameInstance *GameInstance = nullptr;
|
||||
|
@ -95,7 +97,7 @@ private:
|
|||
UPROPERTY()
|
||||
ACarlaRecorder *Recorder = nullptr;
|
||||
|
||||
TArray<FCarlaMesh> Meshes;
|
||||
TArray<FEnvironmentObject> EnvironmentObjects;
|
||||
|
||||
/// The class of Weather to spawn.
|
||||
UPROPERTY(Category = "CARLA Game Mode", EditAnywhere)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <carla/rpc/EpisodeSettings.h>
|
||||
#include <carla/rpc/LightState.h>
|
||||
#include <carla/rpc/MapInfo.h>
|
||||
#include <carla/rpc/Mesh.h>
|
||||
#include <carla/rpc/EnvironmentObject.h>
|
||||
#include <carla/rpc/Response.h>
|
||||
#include <carla/rpc/Server.h>
|
||||
#include <carla/rpc/String.h>
|
||||
|
@ -322,7 +322,7 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return MakeVectorFromTArray<cg::BoundingBox>(Result);
|
||||
};
|
||||
|
||||
BIND_SYNC(get_meshes) << [this]() -> R<std::vector<cr::Mesh>>
|
||||
BIND_SYNC(get_environment_objects) << [this]() -> R<std::vector<cr::EnvironmentObject>>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||
|
@ -330,8 +330,27 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
{
|
||||
RESPOND_ERROR("unable to find CARLA game mode");
|
||||
}
|
||||
TArray<FCarlaMesh> Result = GameMode->GetMeshes();
|
||||
return MakeVectorFromTArray<cr::Mesh>(Result);
|
||||
TArray<FEnvironmentObject> Result = GameMode->GetEnvironmentObjects();
|
||||
return MakeVectorFromTArray<cr::EnvironmentObject>(Result);
|
||||
};
|
||||
|
||||
BIND_SYNC(enable_environment_objects) << [this](std::vector<uint64_t> EnvObjectIds, bool Enable) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||
if (!GameMode)
|
||||
{
|
||||
RESPOND_ERROR("unable to find CARLA game mode");
|
||||
}
|
||||
|
||||
TSet<uint64> EnvObjectIdsSet;
|
||||
for(uint64 Id : EnvObjectIds)
|
||||
{
|
||||
EnvObjectIdsSet.Emplace(Id);
|
||||
}
|
||||
|
||||
GameMode->EnableEnvironmentObjects(EnvObjectIdsSet, Enable);
|
||||
return R<void>::Success();
|
||||
};
|
||||
|
||||
// ~~ Weather ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
Loading…
Reference in New Issue