Add function to spawn actor attached to another actor
This commit is contained in:
parent
4f9299c2b5
commit
f89f728871
|
@ -23,8 +23,11 @@ namespace client {
|
|||
|
||||
SharedPtr<Actor> Client::SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform) {
|
||||
auto actor = Call<carla::rpc::Actor>("spawn_actor", transform, blueprint.MakeActorDescription());
|
||||
const Transform &transform,
|
||||
Actor *parent) {
|
||||
auto actor = parent != nullptr ?
|
||||
Call<carla::rpc::Actor>("spawn_actor_with_parent", transform, blueprint.MakeActorDescription(), parent->Serialize()) :
|
||||
Call<carla::rpc::Actor>("spawn_actor", transform, blueprint.MakeActorDescription());
|
||||
if (actor.IsASensor()) {
|
||||
return SharedPtr<Actor>(new Sensor{actor, GetWorld()});
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ namespace client {
|
|||
|
||||
SharedPtr<Actor> SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform);
|
||||
const Transform &transform,
|
||||
Actor *parent = nullptr);
|
||||
|
||||
void ApplyControlToActor(
|
||||
const Actor &actor,
|
||||
|
|
|
@ -13,11 +13,12 @@ namespace client {
|
|||
|
||||
SharedPtr<Actor> World::TrySpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform) {
|
||||
const Transform &transform,
|
||||
Actor *parent) {
|
||||
try {
|
||||
return SpawnActor(blueprint, transform);
|
||||
} catch (const std::exception & DEBUG_ONLY(e)) {
|
||||
DEBUG_ONLY(log_debug("TrySpawnActor: failed with:", e.what()));
|
||||
return SpawnActor(blueprint, transform, parent);
|
||||
} catch (const std::exception &e) {
|
||||
log_warning("TrySpawnActor: failed with:", e.what());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,14 @@ namespace client {
|
|||
|
||||
SharedPtr<Actor> TrySpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform);
|
||||
const Transform &transform,
|
||||
Actor *parent = nullptr);
|
||||
|
||||
SharedPtr<Actor> SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform) {
|
||||
return _parent->SpawnActor(blueprint, transform);
|
||||
const Transform &transform,
|
||||
Actor *parent = nullptr) {
|
||||
return _parent->SpawnActor(blueprint, transform, parent);
|
||||
}
|
||||
|
||||
Client &GetClient() const {
|
||||
|
|
|
@ -15,7 +15,9 @@ void export_world() {
|
|||
|
||||
class_<cc::World, boost::noncopyable, boost::shared_ptr<cc::World>>("World", no_init)
|
||||
.def("get_blueprint_library", &cc::World::GetBlueprintLibrary)
|
||||
.def("try_spawn_actor", &cc::World::TrySpawnActor)
|
||||
.def("spawn_actor", &cc::World::SpawnActor)
|
||||
.def("try_spawn_actor", &cc::World::TrySpawnActor,
|
||||
(arg("blueprint"), arg("transform"), arg("attach_to")=cc::SharedPtr<cc::Actor>()))
|
||||
.def("spawn_actor", &cc::World::SpawnActor,
|
||||
(arg("blueprint"), arg("transform"), arg("attach_to")=cc::SharedPtr<cc::Actor>()))
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue