Luis/extend spawn actor (#7154)
* Extended spawn_actor to accept a socket name and spawn the actor in the parents socket * fix pr review
This commit is contained in:
parent
5d6862c3d7
commit
cb9a9d77ab
|
@ -119,17 +119,19 @@ namespace client {
|
||||||
const ActorBlueprint &blueprint,
|
const ActorBlueprint &blueprint,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent_actor,
|
Actor *parent_actor,
|
||||||
rpc::AttachmentType attachment_type) {
|
rpc::AttachmentType attachment_type,
|
||||||
return _episode.Lock()->SpawnActor(blueprint, transform, parent_actor, attachment_type);
|
const std::string& socket_name) {
|
||||||
|
return _episode.Lock()->SpawnActor(blueprint, transform, parent_actor, attachment_type, GarbageCollectionPolicy::Inherit, socket_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPtr<Actor> World::TrySpawnActor(
|
SharedPtr<Actor> World::TrySpawnActor(
|
||||||
const ActorBlueprint &blueprint,
|
const ActorBlueprint &blueprint,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent_actor,
|
Actor *parent_actor,
|
||||||
rpc::AttachmentType attachment_type) noexcept {
|
rpc::AttachmentType attachment_type,
|
||||||
|
const std::string& socket_name) noexcept {
|
||||||
try {
|
try {
|
||||||
return SpawnActor(blueprint, transform, parent_actor, attachment_type);
|
return SpawnActor(blueprint, transform, parent_actor, attachment_type, socket_name);
|
||||||
} catch (const std::exception &) {
|
} catch (const std::exception &) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "carla/rpc/Texture.h"
|
#include "carla/rpc/Texture.h"
|
||||||
#include "carla/rpc/MaterialParameter.h"
|
#include "carla/rpc/MaterialParameter.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
|
@ -112,7 +113,8 @@ namespace client {
|
||||||
const ActorBlueprint &blueprint,
|
const ActorBlueprint &blueprint,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent = nullptr,
|
Actor *parent = nullptr,
|
||||||
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid);
|
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid,
|
||||||
|
const std::string& socket_name = "");
|
||||||
|
|
||||||
/// Same as SpawnActor but return nullptr on failure instead of throwing an
|
/// Same as SpawnActor but return nullptr on failure instead of throwing an
|
||||||
/// exception.
|
/// exception.
|
||||||
|
@ -120,7 +122,8 @@ namespace client {
|
||||||
const ActorBlueprint &blueprint,
|
const ActorBlueprint &blueprint,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent = nullptr,
|
Actor *parent = nullptr,
|
||||||
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid) noexcept;
|
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid,
|
||||||
|
const std::string& socket_name = "") noexcept;
|
||||||
|
|
||||||
/// Block calling thread until a world tick is received.
|
/// Block calling thread until a world tick is received.
|
||||||
WorldSnapshot WaitForTick(time_duration timeout) const;
|
WorldSnapshot WaitForTick(time_duration timeout) const;
|
||||||
|
|
|
@ -326,11 +326,12 @@ namespace detail {
|
||||||
return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
|
return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc::Actor Client::SpawnActorWithParent(
|
rpc::Actor Client::SpawnActorWithParent(
|
||||||
const rpc::ActorDescription &description,
|
const rpc::ActorDescription &description,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
rpc::ActorId parent,
|
rpc::ActorId parent,
|
||||||
rpc::AttachmentType attachment_type) {
|
rpc::AttachmentType attachment_type,
|
||||||
|
const std::string& socket_name) {
|
||||||
|
|
||||||
if (attachment_type == rpc::AttachmentType::SpringArm ||
|
if (attachment_type == rpc::AttachmentType::SpringArm ||
|
||||||
attachment_type == rpc::AttachmentType::SpringArmGhost)
|
attachment_type == rpc::AttachmentType::SpringArmGhost)
|
||||||
|
@ -348,7 +349,8 @@ namespace detail {
|
||||||
description,
|
description,
|
||||||
transform,
|
transform,
|
||||||
parent,
|
parent,
|
||||||
attachment_type);
|
attachment_type,
|
||||||
|
socket_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::DestroyActor(rpc::ActorId actor) {
|
bool Client::DestroyActor(rpc::ActorId actor) {
|
||||||
|
|
|
@ -179,7 +179,8 @@ namespace detail {
|
||||||
const rpc::ActorDescription &description,
|
const rpc::ActorDescription &description,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
rpc::ActorId parent,
|
rpc::ActorId parent,
|
||||||
rpc::AttachmentType attachment_type);
|
rpc::AttachmentType attachment_type,
|
||||||
|
const std::string& socket_name = "");
|
||||||
|
|
||||||
bool DestroyActor(rpc::ActorId actor);
|
bool DestroyActor(rpc::ActorId actor);
|
||||||
|
|
||||||
|
|
|
@ -342,19 +342,21 @@ EpisodeProxy Simulator::GetCurrentEpisode() {
|
||||||
// -- General operations with actors -----------------------------------------
|
// -- General operations with actors -----------------------------------------
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
SharedPtr<Actor> Simulator::SpawnActor(
|
SharedPtr<Actor> Simulator::SpawnActor(
|
||||||
const ActorBlueprint &blueprint,
|
const ActorBlueprint &blueprint,
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent,
|
Actor *parent,
|
||||||
rpc::AttachmentType attachment_type,
|
rpc::AttachmentType attachment_type,
|
||||||
GarbageCollectionPolicy gc) {
|
GarbageCollectionPolicy gc,
|
||||||
|
const std::string& socket_name) {
|
||||||
rpc::Actor actor;
|
rpc::Actor actor;
|
||||||
if (parent != nullptr) {
|
if (parent != nullptr) {
|
||||||
actor = _client.SpawnActorWithParent(
|
actor = _client.SpawnActorWithParent(
|
||||||
blueprint.MakeActorDescription(),
|
blueprint.MakeActorDescription(),
|
||||||
transform,
|
transform,
|
||||||
parent->GetId(),
|
parent->GetId(),
|
||||||
attachment_type);
|
attachment_type,
|
||||||
|
socket_name);
|
||||||
} else {
|
} else {
|
||||||
actor = _client.SpawnActor(
|
actor = _client.SpawnActor(
|
||||||
blueprint.MakeActorDescription(),
|
blueprint.MakeActorDescription(),
|
||||||
|
|
|
@ -357,7 +357,8 @@ namespace detail {
|
||||||
const geom::Transform &transform,
|
const geom::Transform &transform,
|
||||||
Actor *parent = nullptr,
|
Actor *parent = nullptr,
|
||||||
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid,
|
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid,
|
||||||
GarbageCollectionPolicy gc = GarbageCollectionPolicy::Inherit);
|
GarbageCollectionPolicy gc = GarbageCollectionPolicy::Inherit,
|
||||||
|
const std::string& socket_name = "");
|
||||||
|
|
||||||
bool DestroyActor(Actor &actor);
|
bool DestroyActor(Actor &actor);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "carla/MsgPackAdaptors.h"
|
#include "carla/MsgPackAdaptors.h"
|
||||||
#include "carla/geom/Transform.h"
|
#include "carla/geom/Transform.h"
|
||||||
#include "carla/rpc/ActorDescription.h"
|
#include "carla/rpc/ActorDescription.h"
|
||||||
|
#include "carla/rpc/AttachmentType.h"
|
||||||
#include "carla/rpc/ActorId.h"
|
#include "carla/rpc/ActorId.h"
|
||||||
#include "carla/rpc/TrafficLightState.h"
|
#include "carla/rpc/TrafficLightState.h"
|
||||||
#include "carla/rpc/VehicleAckermannControl.h"
|
#include "carla/rpc/VehicleAckermannControl.h"
|
||||||
|
@ -18,6 +19,8 @@
|
||||||
#include "carla/rpc/VehicleLightState.h"
|
#include "carla/rpc/VehicleLightState.h"
|
||||||
#include "carla/rpc/WalkerControl.h"
|
#include "carla/rpc/WalkerControl.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4583)
|
#pragma warning(disable:4583)
|
||||||
|
@ -59,11 +62,19 @@ namespace rpc {
|
||||||
: description(std::move(description)),
|
: description(std::move(description)),
|
||||||
transform(transform),
|
transform(transform),
|
||||||
parent(parent) {}
|
parent(parent) {}
|
||||||
|
SpawnActor(ActorDescription description, const geom::Transform &transform, ActorId parent, AttachmentType attachment_type, const std::string& bone)
|
||||||
|
: description(std::move(description)),
|
||||||
|
transform(transform),
|
||||||
|
parent(parent),
|
||||||
|
attachment_type(attachment_type),
|
||||||
|
socket_name(bone) {}
|
||||||
ActorDescription description;
|
ActorDescription description;
|
||||||
geom::Transform transform;
|
geom::Transform transform;
|
||||||
boost::optional<ActorId> parent;
|
boost::optional<ActorId> parent;
|
||||||
|
AttachmentType attachment_type;
|
||||||
|
std::string socket_name;
|
||||||
std::vector<Command> do_after;
|
std::vector<Command> do_after;
|
||||||
MSGPACK_DEFINE_ARRAY(description, transform, parent, do_after);
|
MSGPACK_DEFINE_ARRAY(description, transform, parent, attachment_type, socket_name, do_after);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DestroyActor : CommandBase<DestroyActor> {
|
struct DestroyActor : CommandBase<DestroyActor> {
|
||||||
|
|
|
@ -82,9 +82,15 @@ void export_commands() {
|
||||||
"__init__",
|
"__init__",
|
||||||
&command_impl::CustomSpawnActorInit<cc::ActorBlueprint, cg::Transform, ActorPtr>,
|
&command_impl::CustomSpawnActorInit<cc::ActorBlueprint, cg::Transform, ActorPtr>,
|
||||||
(arg("blueprint"), arg("transform"), arg("parent")))
|
(arg("blueprint"), arg("transform"), arg("parent")))
|
||||||
|
.def(
|
||||||
|
"__init__",
|
||||||
|
&command_impl::CustomSpawnActorInit<cc::ActorBlueprint, cg::Transform, ActorPtr, cr::AttachmentType, std::string>,
|
||||||
|
(arg("blueprint"), arg("transform"), arg("parent"), arg("attachment_type"), arg("socket_name")))
|
||||||
.def(init<cr::Command::SpawnActor>())
|
.def(init<cr::Command::SpawnActor>())
|
||||||
.def_readwrite("transform", &cr::Command::SpawnActor::transform)
|
.def_readwrite("transform", &cr::Command::SpawnActor::transform)
|
||||||
.def_readwrite("parent_id", &cr::Command::SpawnActor::parent)
|
.def_readwrite("parent_id", &cr::Command::SpawnActor::parent)
|
||||||
|
.def_readwrite("attachment_type", &cr::Command::SpawnActor::attachment_type)
|
||||||
|
.def_readwrite("socket_name", &cr::Command::SpawnActor::socket_name)
|
||||||
.def("then", &command_impl::Then, (arg("command")))
|
.def("then", &command_impl::Then, (arg("command")))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <carla/rpc/EnvironmentObject.h>
|
#include <carla/rpc/EnvironmentObject.h>
|
||||||
#include <carla/rpc/ObjectLabel.h>
|
#include <carla/rpc/ObjectLabel.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||||
|
|
||||||
namespace carla {
|
namespace carla {
|
||||||
|
@ -293,15 +295,17 @@ void export_world() {
|
||||||
const cc::ActorBlueprint &blueprint, \
|
const cc::ActorBlueprint &blueprint, \
|
||||||
const cg::Transform &transform, \
|
const cg::Transform &transform, \
|
||||||
cc::Actor *parent, \
|
cc::Actor *parent, \
|
||||||
cr::AttachmentType attachment_type) { \
|
cr::AttachmentType attachment_type, \
|
||||||
|
const std::string& bone) { \
|
||||||
carla::PythonUtil::ReleaseGIL unlock; \
|
carla::PythonUtil::ReleaseGIL unlock; \
|
||||||
return self.fn(blueprint, transform, parent, attachment_type); \
|
return self.fn(blueprint, transform, parent, attachment_type, bone); \
|
||||||
}, \
|
}, \
|
||||||
( \
|
( \
|
||||||
arg("blueprint"), \
|
arg("blueprint"), \
|
||||||
arg("transform"), \
|
arg("transform"), \
|
||||||
arg("attach_to")=carla::SharedPtr<cc::Actor>(), \
|
arg("attach_to")=carla::SharedPtr<cc::Actor>(), \
|
||||||
arg("attachment_type")=cr::AttachmentType::Rigid)
|
arg("attachment_type")=cr::AttachmentType::Rigid, \
|
||||||
|
arg("bone")=std::string())
|
||||||
|
|
||||||
class_<cc::World>("World", no_init)
|
class_<cc::World>("World", no_init)
|
||||||
.add_property("id", &cc::World::GetId)
|
.add_property("id", &cc::World::GetId)
|
||||||
|
|
|
@ -105,7 +105,7 @@ bool UCarlaEpisode::LoadNewEpisode(const FString &MapString, bool ResetSettings)
|
||||||
UGameplayStatics::OpenLevel(GetWorld(), *FinalPath, true);
|
UGameplayStatics::OpenLevel(GetWorld(), *FinalPath, true);
|
||||||
if (ResetSettings)
|
if (ResetSettings)
|
||||||
ApplySettings(FEpisodeSettings{});
|
ApplySettings(FEpisodeSettings{});
|
||||||
|
|
||||||
// send 'LOAD_MAP' command to all secondary servers (if any)
|
// send 'LOAD_MAP' command to all secondary servers (if any)
|
||||||
if (bIsPrimaryServer)
|
if (bIsPrimaryServer)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +114,7 @@ bool UCarlaEpisode::LoadNewEpisode(const FString &MapString, bool ResetSettings)
|
||||||
{
|
{
|
||||||
FCarlaEngine *CarlaEngine = GameInstance->GetCarlaEngine();
|
FCarlaEngine *CarlaEngine = GameInstance->GetCarlaEngine();
|
||||||
auto SecondaryServer = CarlaEngine->GetSecondaryServer();
|
auto SecondaryServer = CarlaEngine->GetSecondaryServer();
|
||||||
if (SecondaryServer->HasClientsConnected())
|
if (SecondaryServer->HasClientsConnected())
|
||||||
{
|
{
|
||||||
SecondaryServer->GetCommander().SendLoadMap(std::string(TCHAR_TO_UTF8(*FinalPath)));
|
SecondaryServer->GetCommander().SendLoadMap(std::string(TCHAR_TO_UTF8(*FinalPath)));
|
||||||
}
|
}
|
||||||
|
@ -294,11 +294,12 @@ carla::rpc::Actor UCarlaEpisode::SerializeActor(AActor* Actor) const
|
||||||
void UCarlaEpisode::AttachActors(
|
void UCarlaEpisode::AttachActors(
|
||||||
AActor *Child,
|
AActor *Child,
|
||||||
AActor *Parent,
|
AActor *Parent,
|
||||||
EAttachmentType InAttachmentType)
|
EAttachmentType InAttachmentType,
|
||||||
|
const FString& SocketName)
|
||||||
{
|
{
|
||||||
Child->AddActorWorldOffset(FVector(CurrentMapOrigin));
|
Child->AddActorWorldOffset(FVector(CurrentMapOrigin));
|
||||||
|
|
||||||
UActorAttacher::AttachActors(Child, Parent, InAttachmentType);
|
UActorAttacher::AttachActors(Child, Parent, InAttachmentType, SocketName);
|
||||||
|
|
||||||
if (bIsPrimaryServer)
|
if (bIsPrimaryServer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,7 +245,8 @@ public:
|
||||||
void AttachActors(
|
void AttachActors(
|
||||||
AActor *Child,
|
AActor *Child,
|
||||||
AActor *Parent,
|
AActor *Parent,
|
||||||
EAttachmentType InAttachmentType = EAttachmentType::Rigid);
|
EAttachmentType InAttachmentType = EAttachmentType::Rigid,
|
||||||
|
const FString& SocketName = "");
|
||||||
|
|
||||||
/// @copydoc FActorDispatcher::DestroyActor(AActor*)
|
/// @copydoc FActorDispatcher::DestroyActor(AActor*)
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
|
|
|
@ -711,7 +711,8 @@ void FCarlaServer::FPimpl::BindActions()
|
||||||
cr::ActorDescription Description,
|
cr::ActorDescription Description,
|
||||||
const cr::Transform &Transform,
|
const cr::Transform &Transform,
|
||||||
cr::ActorId ParentId,
|
cr::ActorId ParentId,
|
||||||
cr::AttachmentType InAttachmentType) -> R<cr::Actor>
|
cr::AttachmentType InAttachmentType,
|
||||||
|
const std::string& socket_name) -> R<cr::Actor>
|
||||||
{
|
{
|
||||||
REQUIRE_CARLA_EPISODE();
|
REQUIRE_CARLA_EPISODE();
|
||||||
|
|
||||||
|
@ -765,7 +766,8 @@ void FCarlaServer::FPimpl::BindActions()
|
||||||
Episode->AttachActors(
|
Episode->AttachActors(
|
||||||
CarlaActor->GetActor(),
|
CarlaActor->GetActor(),
|
||||||
ParentCarlaActor->GetActor(),
|
ParentCarlaActor->GetActor(),
|
||||||
static_cast<EAttachmentType>(InAttachmentType));
|
static_cast<EAttachmentType>(InAttachmentType),
|
||||||
|
FString(socket_name.c_str()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2761,7 +2763,8 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_
|
||||||
c.description,
|
c.description,
|
||||||
c.transform,
|
c.transform,
|
||||||
*c.parent,
|
*c.parent,
|
||||||
cr::AttachmentType::Rigid) :
|
cr::AttachmentType::Rigid,
|
||||||
|
c.socket_name) :
|
||||||
spawn_actor(c.description, c.transform);
|
spawn_actor(c.description, c.transform);
|
||||||
if (!result.HasError())
|
if (!result.HasError())
|
||||||
{
|
{
|
||||||
|
|
|
@ -96,7 +96,8 @@ static void UActorAttacher_AttachActorsWithSpringArmGhost(
|
||||||
void UActorAttacher::AttachActors(
|
void UActorAttacher::AttachActors(
|
||||||
AActor *Child,
|
AActor *Child,
|
||||||
AActor *Parent,
|
AActor *Parent,
|
||||||
const EAttachmentType AttachmentType)
|
const EAttachmentType AttachmentType,
|
||||||
|
const FString& SocketName)
|
||||||
{
|
{
|
||||||
check(Child != nullptr);
|
check(Child != nullptr);
|
||||||
check(Parent != nullptr);
|
check(Parent != nullptr);
|
||||||
|
@ -104,7 +105,7 @@ void UActorAttacher::AttachActors(
|
||||||
switch (AttachmentType)
|
switch (AttachmentType)
|
||||||
{
|
{
|
||||||
case EAttachmentType::Rigid:
|
case EAttachmentType::Rigid:
|
||||||
Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
|
Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform, FName(*SocketName));
|
||||||
break;
|
break;
|
||||||
case EAttachmentType::SpringArm:
|
case EAttachmentType::SpringArm:
|
||||||
UActorAttacher_AttachActorsWithSpringArm(Child, Parent);
|
UActorAttacher_AttachActorsWithSpringArm(Child, Parent);
|
||||||
|
|
|
@ -42,5 +42,5 @@ class CARLA_API UActorAttacher : public UBlueprintFunctionLibrary
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category="CARLA|Actor Attacher")
|
UFUNCTION(BlueprintCallable, Category="CARLA|Actor Attacher")
|
||||||
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType);
|
static void AttachActors(AActor *Child, AActor *Parent, EAttachmentType AttachmentType, const FString& SocketName = "");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue