Javiergr cs/get bones transform (#7153)

* Add actor component getters to the PythonAPI

Adds functions:
 - get_component_world_transform
 - get_component_relative_transform

to the Python API to acces the transform of actor components by name

* Update changelog for get-transform-component changes

* Adding getters for receive bone names and transforms

* Corrections

* Correcting Python API function definitions to make them able to return lists

* Improving the code of get_actor_bone_world_transforms

* Adding getters to obtain socket transforms

* Updating CHANGELOG.md

* Deleting .ignore

* Updating Util/BuildTools/Setup.sh

* Correcting Setup.sh

---------

Co-authored-by: Aperiss <perissanchezantonio@gmail.com>
Co-authored-by: Blyron <53337103+Blyron@users.noreply.github.com>
This commit is contained in:
javiergrCS 2024-02-19 10:26:34 +01:00 committed by GitHub
parent 1433186a01
commit 5d6862c3d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 335 additions and 2 deletions

View File

@ -2,6 +2,9 @@
* Prevent from segfault on failing SignalReference identification when loading OpenDrive files
* Added vehicle doors to the recorder
* Added functions to get actor' components transform
* Added functions to get actor' bones transforms
* Added functions to get actor' bones and components names
* Added functions to get actor' sockets transforms
## CARLA 0.9.15

View File

@ -40,6 +40,30 @@ namespace client {
return GetEpisode().Lock()->GetActorComponentRelativeTransform(*this, componentName);
}
std::vector<geom::Transform> Actor::GetBoneWorldTransforms() const {
return GetEpisode().Lock()->GetActorBoneWorldTransforms(*this);
}
std::vector<geom::Transform> Actor::GetBoneRelativeTransforms() const {
return GetEpisode().Lock()->GetActorBoneRelativeTransforms(*this);
}
std::vector<std::string> Actor::GetComponentNames() const {
return GetEpisode().Lock()->GetActorComponentNames(*this);
}
std::vector<std::string> Actor::GetBoneNames() const {
return GetEpisode().Lock()->GetActorBoneNames(*this);
}
std::vector<geom::Transform> Actor::GetSocketWorldTransforms() const {
return GetEpisode().Lock()->GetActorSocketWorldTransforms(*this);
}
std::vector<geom::Transform> Actor::GetSocketRelativeTransforms() const {
return GetEpisode().Lock()->GetActorSocketRelativeTransforms(*this);
}
void Actor::SetLocation(const geom::Location &location) {
GetEpisode().Lock()->SetActorLocation(*this, location);
}

View File

@ -64,6 +64,18 @@ namespace client {
geom::Transform GetComponentRelativeTransform(const std::string componentName) const;
std::vector<geom::Transform> GetBoneWorldTransforms() const;
std::vector<geom::Transform> GetBoneRelativeTransforms() const;
std::vector<std::string> GetComponentNames() const;
std::vector<std::string> GetBoneNames() const;
std::vector<geom::Transform> GetSocketWorldTransforms() const;
std::vector<geom::Transform> GetSocketRelativeTransforms() const;
/// Teleport the actor to @a location.
void SetLocation(const geom::Location &location);

View File

@ -416,6 +416,36 @@ namespace detail {
return _pimpl->CallAndWait<geom::Transform>("get_actor_component_relative_transform", actor, componentName);
}
std::vector<geom::Transform> Client::GetActorBoneWorldTransforms(rpc::ActorId actor) {
using return_t = std::vector<geom::Transform>;
return _pimpl->CallAndWait<return_t>("get_actor_bone_world_transforms", actor);
}
std::vector<geom::Transform> Client::GetActorBoneRelativeTransforms(rpc::ActorId actor) {
using return_t = std::vector<geom::Transform>;
return _pimpl->CallAndWait<return_t>("get_actor_bone_relative_transforms", actor);
}
std::vector<std::string> Client::GetActorComponentNames(rpc::ActorId actor) {
using return_t = std::vector<std::string>;
return _pimpl->CallAndWait<return_t>("get_actor_component_names", actor);
}
std::vector<std::string> Client::GetActorBoneNames(rpc::ActorId actor) {
using return_t = std::vector<std::string>;
return _pimpl->CallAndWait<return_t>("get_actor_bone_names", actor);
}
std::vector<geom::Transform> Client::GetActorSocketWorldTransforms(rpc::ActorId actor) {
using return_t = std::vector<geom::Transform>;
return _pimpl->CallAndWait<return_t>("get_actor_socket_world_transforms", actor);
}
std::vector<geom::Transform> Client::GetActorSocketRelativeTransforms(rpc::ActorId actor) {
using return_t = std::vector<geom::Transform>;
return _pimpl->CallAndWait<return_t>("get_actor_socket_relative_transforms", actor);
}
void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
_pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
}

View File

@ -88,7 +88,6 @@ namespace detail {
void DestroyTrafficManager(uint16_t port) const;
void SetTimeout(time_duration timeout);
time_duration GetTimeout() const;
@ -241,6 +240,24 @@ namespace detail {
rpc::ActorId actor,
const std::string componentName);
std::vector<geom::Transform> GetActorBoneWorldTransforms(
rpc::ActorId actor);
std::vector<geom::Transform> GetActorBoneRelativeTransforms(
rpc::ActorId actor);
std::vector<std::string> GetActorComponentNames(
rpc::ActorId actor);
std::vector<std::string> GetActorBoneNames(
rpc::ActorId actor);
std::vector<geom::Transform> GetActorSocketWorldTransforms(
rpc::ActorId actor);
std::vector<geom::Transform> GetActorSocketRelativeTransforms(
rpc::ActorId actor);
void SetActorSimulatePhysics(
rpc::ActorId actor,
bool enabled);

View File

@ -446,6 +446,30 @@ namespace detail {
return _client.GetActorComponentRelativeTransform(actor.GetId(), componentName);
}
std::vector<geom::Transform> GetActorBoneWorldTransforms(const Actor &actor) {
return _client.GetActorBoneWorldTransforms(actor.GetId());
}
std::vector<geom::Transform> GetActorBoneRelativeTransforms(const Actor &actor) {
return _client.GetActorBoneRelativeTransforms(actor.GetId());
}
std::vector<std::string> GetActorComponentNames(const Actor &actor) {
return _client.GetActorComponentNames(actor.GetId());
}
std::vector<std::string> GetActorBoneNames(const Actor &actor) {
return _client.GetActorBoneNames(actor.GetId());
}
std::vector<geom::Transform> GetActorSocketWorldTransforms(const Actor &actor) {
return _client.GetActorSocketWorldTransforms(actor.GetId());
}
std::vector<geom::Transform> GetActorSocketRelativeTransforms(const Actor &actor) {
return _client.GetActorSocketRelativeTransforms(actor.GetId());
}
void SetActorLocation(Actor &actor, const geom::Location &location) {
_client.SetActorLocation(actor.GetId(), location);
}

View File

@ -115,6 +115,12 @@ void export_actor() {
.def("get_acceleration", &cc::Actor::GetAcceleration)
.def("get_component_world_transform", &cc::Actor::GetComponentWorldTransform, (arg("component_name")))
.def("get_component_relative_transform", &cc::Actor::GetComponentRelativeTransform, (arg("component_name")))
.def("get_bone_world_transforms", CALL_RETURNING_LIST(cc::Actor,GetBoneWorldTransforms))
.def("get_bone_relative_transforms", CALL_RETURNING_LIST(cc::Actor,GetBoneRelativeTransforms))
.def("get_component_names", CALL_RETURNING_LIST(cc::Actor,GetComponentNames))
.def("get_bone_names", CALL_RETURNING_LIST(cc::Actor,GetBoneNames))
.def("get_socket_world_transforms", CALL_RETURNING_LIST(cc::Actor,GetSocketWorldTransforms))
.def("get_socket_relative_transforms", CALL_RETURNING_LIST(cc::Actor,GetSocketRelativeTransforms))
.def("set_location", &cc::Actor::SetLocation, (arg("location")))
.def("set_transform", &cc::Actor::SetTransform, (arg("transform")))
.def("set_target_velocity", &cc::Actor::SetTargetVelocity, (arg("velocity")))

View File

@ -9,6 +9,11 @@
#include "Carla/Server/CarlaServerResponse.h"
#include "Carla/Traffic/TrafficLightGroup.h"
#include "EngineUtils.h"
#include "Components/SkeletalMeshComponent.h"
#include "Components/SkinnedMeshComponent.h"
#include "Components/SceneComponent.h"
#include "Engine/SkeletalMesh.h"
#include "Engine/SkeletalMeshSocket.h"
#include "Carla/OpenDrive/OpenDrive.h"
#include "Carla/Util/DebugShapeDrawer.h"
@ -1362,6 +1367,217 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_
}
};
BIND_SYNC(get_actor_bone_world_transforms) << [this](
cr::ActorId ActorId) -> R<std::vector<cr::Transform>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_bone_world_transform",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
TArray<FTransform> BoneWorldTransforms;
TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
CarlaActor->GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
if(!SkinnedMeshComponents[0])
{
return RespondError(
"get_actor_bone_relative_transforms",
ECarlaServerResponse::ComponentNotFound,
" Component Name: SkinnedMeshComponent ");
}
else
{
for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
{
const int32 NumBones = SkinnedMeshComponent->GetNumBones();
for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
{
FTransform WorldTransform = SkinnedMeshComponent->GetComponentTransform();
FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, WorldTransform);
BoneWorldTransforms.Add(BoneTransform);
}
}
return MakeVectorFromTArray<cr::Transform>(BoneWorldTransforms);
}
}
};
BIND_SYNC(get_actor_bone_relative_transforms) << [this](
cr::ActorId ActorId) -> R<std::vector<cr::Transform>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_bone_relative_transform",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
TArray<FTransform> BoneRelativeTransforms;
TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
CarlaActor->GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
if(!SkinnedMeshComponents[0])
{
return RespondError(
"get_actor_bone_relative_transforms",
ECarlaServerResponse::ComponentNotFound,
" Component Name: SkinnedMeshComponent ");
}
else
{
for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
{
const int32 NumBones = SkinnedMeshComponent->GetNumBones();
for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
{
FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, FTransform::Identity);
BoneRelativeTransforms.Add(BoneTransform);
}
}
return MakeVectorFromTArray<cr::Transform>(BoneRelativeTransforms);
}
}
};
BIND_SYNC(get_actor_component_names) << [this](
cr::ActorId ActorId) -> R<std::vector<std::string>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_component_names",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
TArray<UActorComponent*> Components;
CarlaActor->GetActor()->GetComponents(Components);
std::vector<std::string> ComponentNames;
for(auto Cmp : Components)
{
FString ComponentName = Cmp->GetName();
ComponentNames.push_back(TCHAR_TO_UTF8(*ComponentName));
}
return ComponentNames;
}
};
BIND_SYNC(get_actor_bone_names) << [this](
cr::ActorId ActorId) -> R<std::vector<std::string>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_component_relative_transform",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
USkinnedMeshComponent* SkinnedMeshComponent = CarlaActor->GetActor()->FindComponentByClass<USkinnedMeshComponent>();
if(!SkinnedMeshComponent)
{
return RespondError(
"get_actor_bone_relative_transforms",
ECarlaServerResponse::ComponentNotFound,
" Component Name: SkinnedMeshComponent ");
}
else
{
TArray<FName> BoneNames;
SkinnedMeshComponent->GetBoneNames(BoneNames);
TArray<std::string> StringBoneNames;
for (const FName& Name : BoneNames)
{
FString FBoneName = Name.ToString();
std::string StringBoneName = TCHAR_TO_UTF8(*FBoneName);
StringBoneNames.Add(StringBoneName);
}
return MakeVectorFromTArray<std::string>(StringBoneNames);
}
}
};
BIND_SYNC(get_actor_socket_world_transforms) << [this](
cr::ActorId ActorId) -> R<std::vector<cr::Transform>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_component_relative_transform",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
TArray<FTransform> SocketWorldTransforms;
TArray<UActorComponent*> Components;
CarlaActor->GetActor()->GetComponents(Components);
for(UActorComponent* ActorComponent : Components)
{
if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
{
const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
for (const FName& SocketName : SocketNames)
{
FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName);
SocketWorldTransforms.Add(SocketTransform);
}
}
}
return MakeVectorFromTArray<cr::Transform>(SocketWorldTransforms);
}
};
BIND_SYNC(get_actor_socket_relative_transforms) << [this](
cr::ActorId ActorId) -> R<std::vector<cr::Transform>>
{
REQUIRE_CARLA_EPISODE();
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
if (!CarlaActor)
{
return RespondError(
"get_actor_component_relative_transform",
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
else
{
TArray<FTransform> SocketRelativeTransforms;
TArray<UActorComponent*> Components;
CarlaActor->GetActor()->GetComponents(Components);
for(UActorComponent* ActorComponent : Components)
{
if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
{
const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
for (const FName& SocketName : SocketNames)
{
FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName, ERelativeTransformSpace::RTS_Actor);
SocketRelativeTransforms.Add(SocketTransform);
}
}
}
return MakeVectorFromTArray<cr::Transform>(SocketRelativeTransforms);
}
};
BIND_SYNC(get_physics_control) << [this](
cr::ActorId ActorId) -> R<cr::VehiclePhysicsControl>
{

View File

@ -186,7 +186,8 @@ else
git clone -b ${RPCLIB_PATCH} https://github.com/carla-simulator/rpclib.git ${RPCLIB_BASENAME}-source
end_download_time=$(date +%s)
echo "Elapsed Time downloading rpclib: $(($end-$start)) seconds"
echo "Elapsed Time downloading rpclib: $(($end_download_time-$start_download_time)) seconds"
log "Building rpclib with libc++."
# rpclib does not use any cmake 3.9 feature.