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 geom::Transform &transform,
|
||||
Actor *parent_actor,
|
||||
rpc::AttachmentType attachment_type) {
|
||||
return _episode.Lock()->SpawnActor(blueprint, transform, parent_actor, attachment_type);
|
||||
rpc::AttachmentType 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(
|
||||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
Actor *parent_actor,
|
||||
rpc::AttachmentType attachment_type) noexcept {
|
||||
rpc::AttachmentType attachment_type,
|
||||
const std::string& socket_name) noexcept {
|
||||
try {
|
||||
return SpawnActor(blueprint, transform, parent_actor, attachment_type);
|
||||
return SpawnActor(blueprint, transform, parent_actor, attachment_type, socket_name);
|
||||
} catch (const std::exception &) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "carla/rpc/Texture.h"
|
||||
#include "carla/rpc/MaterialParameter.h"
|
||||
|
||||
#include <string>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace carla {
|
||||
|
@ -112,7 +113,8 @@ namespace client {
|
|||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
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
|
||||
/// exception.
|
||||
|
@ -120,7 +122,8 @@ namespace client {
|
|||
const ActorBlueprint &blueprint,
|
||||
const geom::Transform &transform,
|
||||
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.
|
||||
WorldSnapshot WaitForTick(time_duration timeout) const;
|
||||
|
|
|
@ -330,7 +330,8 @@ namespace detail {
|
|||
const rpc::ActorDescription &description,
|
||||
const geom::Transform &transform,
|
||||
rpc::ActorId parent,
|
||||
rpc::AttachmentType attachment_type) {
|
||||
rpc::AttachmentType attachment_type,
|
||||
const std::string& socket_name) {
|
||||
|
||||
if (attachment_type == rpc::AttachmentType::SpringArm ||
|
||||
attachment_type == rpc::AttachmentType::SpringArmGhost)
|
||||
|
@ -348,7 +349,8 @@ namespace detail {
|
|||
description,
|
||||
transform,
|
||||
parent,
|
||||
attachment_type);
|
||||
attachment_type,
|
||||
socket_name);
|
||||
}
|
||||
|
||||
bool Client::DestroyActor(rpc::ActorId actor) {
|
||||
|
|
|
@ -179,7 +179,8 @@ namespace detail {
|
|||
const rpc::ActorDescription &description,
|
||||
const geom::Transform &transform,
|
||||
rpc::ActorId parent,
|
||||
rpc::AttachmentType attachment_type);
|
||||
rpc::AttachmentType attachment_type,
|
||||
const std::string& socket_name = "");
|
||||
|
||||
bool DestroyActor(rpc::ActorId actor);
|
||||
|
||||
|
|
|
@ -347,14 +347,16 @@ EpisodeProxy Simulator::GetCurrentEpisode() {
|
|||
const geom::Transform &transform,
|
||||
Actor *parent,
|
||||
rpc::AttachmentType attachment_type,
|
||||
GarbageCollectionPolicy gc) {
|
||||
GarbageCollectionPolicy gc,
|
||||
const std::string& socket_name) {
|
||||
rpc::Actor actor;
|
||||
if (parent != nullptr) {
|
||||
actor = _client.SpawnActorWithParent(
|
||||
blueprint.MakeActorDescription(),
|
||||
transform,
|
||||
parent->GetId(),
|
||||
attachment_type);
|
||||
attachment_type,
|
||||
socket_name);
|
||||
} else {
|
||||
actor = _client.SpawnActor(
|
||||
blueprint.MakeActorDescription(),
|
||||
|
|
|
@ -357,7 +357,8 @@ namespace detail {
|
|||
const geom::Transform &transform,
|
||||
Actor *parent = nullptr,
|
||||
rpc::AttachmentType attachment_type = rpc::AttachmentType::Rigid,
|
||||
GarbageCollectionPolicy gc = GarbageCollectionPolicy::Inherit);
|
||||
GarbageCollectionPolicy gc = GarbageCollectionPolicy::Inherit,
|
||||
const std::string& socket_name = "");
|
||||
|
||||
bool DestroyActor(Actor &actor);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "carla/MsgPackAdaptors.h"
|
||||
#include "carla/geom/Transform.h"
|
||||
#include "carla/rpc/ActorDescription.h"
|
||||
#include "carla/rpc/AttachmentType.h"
|
||||
#include "carla/rpc/ActorId.h"
|
||||
#include "carla/rpc/TrafficLightState.h"
|
||||
#include "carla/rpc/VehicleAckermannControl.h"
|
||||
|
@ -18,6 +19,8 @@
|
|||
#include "carla/rpc/VehicleLightState.h"
|
||||
#include "carla/rpc/WalkerControl.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4583)
|
||||
|
@ -59,11 +62,19 @@ namespace rpc {
|
|||
: description(std::move(description)),
|
||||
transform(transform),
|
||||
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;
|
||||
geom::Transform transform;
|
||||
boost::optional<ActorId> parent;
|
||||
AttachmentType attachment_type;
|
||||
std::string socket_name;
|
||||
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> {
|
||||
|
|
|
@ -82,9 +82,15 @@ void export_commands() {
|
|||
"__init__",
|
||||
&command_impl::CustomSpawnActorInit<cc::ActorBlueprint, cg::Transform, ActorPtr>,
|
||||
(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_readwrite("transform", &cr::Command::SpawnActor::transform)
|
||||
.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")))
|
||||
;
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <carla/rpc/EnvironmentObject.h>
|
||||
#include <carla/rpc/ObjectLabel.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
namespace carla {
|
||||
|
@ -293,15 +295,17 @@ void export_world() {
|
|||
const cc::ActorBlueprint &blueprint, \
|
||||
const cg::Transform &transform, \
|
||||
cc::Actor *parent, \
|
||||
cr::AttachmentType attachment_type) { \
|
||||
cr::AttachmentType attachment_type, \
|
||||
const std::string& bone) { \
|
||||
carla::PythonUtil::ReleaseGIL unlock; \
|
||||
return self.fn(blueprint, transform, parent, attachment_type); \
|
||||
return self.fn(blueprint, transform, parent, attachment_type, bone); \
|
||||
}, \
|
||||
( \
|
||||
arg("blueprint"), \
|
||||
arg("transform"), \
|
||||
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)
|
||||
.add_property("id", &cc::World::GetId)
|
||||
|
|
|
@ -294,11 +294,12 @@ carla::rpc::Actor UCarlaEpisode::SerializeActor(AActor* Actor) const
|
|||
void UCarlaEpisode::AttachActors(
|
||||
AActor *Child,
|
||||
AActor *Parent,
|
||||
EAttachmentType InAttachmentType)
|
||||
EAttachmentType InAttachmentType,
|
||||
const FString& SocketName)
|
||||
{
|
||||
Child->AddActorWorldOffset(FVector(CurrentMapOrigin));
|
||||
|
||||
UActorAttacher::AttachActors(Child, Parent, InAttachmentType);
|
||||
UActorAttacher::AttachActors(Child, Parent, InAttachmentType, SocketName);
|
||||
|
||||
if (bIsPrimaryServer)
|
||||
{
|
||||
|
|
|
@ -245,7 +245,8 @@ public:
|
|||
void AttachActors(
|
||||
AActor *Child,
|
||||
AActor *Parent,
|
||||
EAttachmentType InAttachmentType = EAttachmentType::Rigid);
|
||||
EAttachmentType InAttachmentType = EAttachmentType::Rigid,
|
||||
const FString& SocketName = "");
|
||||
|
||||
/// @copydoc FActorDispatcher::DestroyActor(AActor*)
|
||||
UFUNCTION(BlueprintCallable)
|
||||
|
|
|
@ -711,7 +711,8 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
cr::ActorDescription Description,
|
||||
const cr::Transform &Transform,
|
||||
cr::ActorId ParentId,
|
||||
cr::AttachmentType InAttachmentType) -> R<cr::Actor>
|
||||
cr::AttachmentType InAttachmentType,
|
||||
const std::string& socket_name) -> R<cr::Actor>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
|
||||
|
@ -765,7 +766,8 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
Episode->AttachActors(
|
||||
CarlaActor->GetActor(),
|
||||
ParentCarlaActor->GetActor(),
|
||||
static_cast<EAttachmentType>(InAttachmentType));
|
||||
static_cast<EAttachmentType>(InAttachmentType),
|
||||
FString(socket_name.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2761,7 +2763,8 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_
|
|||
c.description,
|
||||
c.transform,
|
||||
*c.parent,
|
||||
cr::AttachmentType::Rigid) :
|
||||
cr::AttachmentType::Rigid,
|
||||
c.socket_name) :
|
||||
spawn_actor(c.description, c.transform);
|
||||
if (!result.HasError())
|
||||
{
|
||||
|
|
|
@ -96,7 +96,8 @@ static void UActorAttacher_AttachActorsWithSpringArmGhost(
|
|||
void UActorAttacher::AttachActors(
|
||||
AActor *Child,
|
||||
AActor *Parent,
|
||||
const EAttachmentType AttachmentType)
|
||||
const EAttachmentType AttachmentType,
|
||||
const FString& SocketName)
|
||||
{
|
||||
check(Child != nullptr);
|
||||
check(Parent != nullptr);
|
||||
|
@ -104,7 +105,7 @@ void UActorAttacher::AttachActors(
|
|||
switch (AttachmentType)
|
||||
{
|
||||
case EAttachmentType::Rigid:
|
||||
Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
Child->AttachToActor(Parent, FAttachmentTransformRules::KeepRelativeTransform, FName(*SocketName));
|
||||
break;
|
||||
case EAttachmentType::SpringArm:
|
||||
UActorAttacher_AttachActorsWithSpringArm(Child, Parent);
|
||||
|
|
|
@ -42,5 +42,5 @@ class CARLA_API UActorAttacher : public UBlueprintFunctionLibrary
|
|||
public:
|
||||
|
||||
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