Function to disable simulating physics on an actor

This commit is contained in:
nsubiron 2018-10-21 23:39:58 +02:00
parent 994110047e
commit c478eb039e
8 changed files with 33 additions and 0 deletions

View File

@ -87,6 +87,7 @@
- `get_acceleration()`
- `set_location(location)`
- `set_transform(transform)`
- `set_simulate_physics(enabled=True)`
- `destroy()`
## `carla.Vehicle(carla.Actor)`

View File

@ -36,6 +36,10 @@ namespace client {
GetEpisode().Lock()->SetActorTransform(*this, transform);
}
void Actor::SetSimulatePhysics(const bool enabled) {
GetEpisode().Lock()->SetActorSimulatePhysics(*this, enabled);
}
void Actor::Destroy() {
if (_is_alive) {
// Let the exceptions leave the function, IsAlive() will still be true.

View File

@ -39,6 +39,8 @@ namespace client {
void SetTransform(const geom::Transform &transform);
void SetSimulatePhysics(bool enabled = true);
const auto &Serialize() const {
return Super::GetActorDescription();
}

View File

@ -126,6 +126,10 @@ namespace detail {
_pimpl->AsyncCall("set_actor_transform", actor, transform);
}
void Client::SetActorSimulatePhysics(const rpc::Actor &actor, const bool enabled) {
_pimpl->AsyncCall("set_actor_simulate_physics", actor, enabled);
}
void Client::SetActorAutopilot(const rpc::Actor &vehicle, const bool enabled) {
_pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
}

View File

@ -86,6 +86,10 @@ namespace detail {
const rpc::Actor &actor,
const geom::Transform &transform);
void SetActorSimulatePhysics(
const rpc::Actor &actor,
bool enabled);
void SetActorAutopilot(
const rpc::Actor &vehicle,
bool enabled);

View File

@ -177,6 +177,10 @@ namespace detail {
_client.SetActorTransform(actor.Serialize(), transform);
}
void SetActorSimulatePhysics(Actor &actor, bool enabled) {
_client.SetActorSimulatePhysics(actor.Serialize(), enabled);
}
/// @}
// =========================================================================
/// @name Operations with vehicles

View File

@ -53,6 +53,7 @@ void export_actor() {
.def("get_acceleration", &cc::Actor::GetAcceleration)
.def("set_location", &cc::Actor::SetLocation, (arg("location")))
.def("set_transform", &cc::Actor::SetTransform, (arg("transform")))
.def("set_simulate_physics", &cc::Actor::SetSimulatePhysics, (arg("enabled")=true))
.def("destroy", CALL_WITHOUT_GIL(cc::Actor, Destroy))
.def(self_ns::str(self_ns::self))
;

View File

@ -316,6 +316,19 @@ void FTheNewCarlaServer::FPimpl::BindActions()
ETeleportType::TeleportPhysics);
});
Server.BindSync("set_actor_simulate_physics", [this](cr::Actor Actor, bool bEnabled) {
RequireEpisode();
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
RespondErrorStr("unable to set actor simulate physics: actor not found");
}
auto RootComponent = Cast<UPrimitiveComponent>(ActorView.GetActor()->GetRootComponent());
if (RootComponent == nullptr) {
RespondErrorStr("unable to set actor simulate physics: not supported by actor");
}
RootComponent->SetSimulatePhysics(bEnabled);
});
Server.BindSync("apply_control_to_actor", [this](cr::Actor Actor, cr::VehicleControl Control) {
RequireEpisode();
auto ActorView = Episode->GetActorRegistry().Find(Actor.id);