First version, bones transform in world space
This commit is contained in:
parent
030b36eed7
commit
93e4733cf8
|
@ -25,5 +25,10 @@ namespace client {
|
|||
Walker::Control Walker::GetWalkerControl() const {
|
||||
return GetEpisode().Lock()->GetActorSnapshot(*this).state.walker_control;
|
||||
}
|
||||
|
||||
// Walker::Control Walker::GetBonesTransform() const {
|
||||
Walker::BoneControl Walker::GetBonesTransform() {
|
||||
return GetEpisode().Lock()->GetBonesTransform(*this);
|
||||
}
|
||||
} // namespace client
|
||||
} // namespace carla
|
||||
|
|
|
@ -32,6 +32,9 @@ namespace client {
|
|||
/// received in the last tick.
|
||||
Control GetWalkerControl() const;
|
||||
|
||||
// Walker::Control GetBonesTransform() const;
|
||||
BoneControl GetBonesTransform();
|
||||
|
||||
private:
|
||||
|
||||
Control _control;
|
||||
|
|
|
@ -439,6 +439,11 @@ namespace detail {
|
|||
_pimpl->AsyncCall("apply_bone_control_to_walker", walker, control);
|
||||
}
|
||||
|
||||
rpc::WalkerBoneControl Client::GetBonesTransform(rpc::ActorId walker) {
|
||||
auto res = _pimpl->CallAndWait<rpc::WalkerBoneControl>("get_bones_transform", walker);
|
||||
return res;
|
||||
}
|
||||
|
||||
void Client::SetTrafficLightState(
|
||||
rpc::ActorId traffic_light,
|
||||
const rpc::TrafficLightState traffic_light_state) {
|
||||
|
|
|
@ -271,6 +271,9 @@ namespace detail {
|
|||
rpc::ActorId walker,
|
||||
const rpc::WalkerBoneControl &control);
|
||||
|
||||
rpc::WalkerBoneControl GetBonesTransform(
|
||||
rpc::ActorId walker);
|
||||
|
||||
void SetTrafficLightState(
|
||||
rpc::ActorId traffic_light,
|
||||
const rpc::TrafficLightState trafficLightState);
|
||||
|
|
|
@ -461,6 +461,10 @@ namespace detail {
|
|||
_client.ApplyBoneControlToWalker(walker.GetId(), control);
|
||||
}
|
||||
|
||||
rpc::WalkerBoneControl GetBonesTransform(Walker &walker) {
|
||||
return _client.GetBonesTransform(walker.GetId());
|
||||
}
|
||||
|
||||
void ApplyPhysicsControlToVehicle(Vehicle &vehicle, const rpc::VehiclePhysicsControl &physicsControl) {
|
||||
_client.ApplyPhysicsControlToVehicle(vehicle.GetId(), physicsControl);
|
||||
}
|
||||
|
|
|
@ -190,6 +190,7 @@ void export_actor() {
|
|||
.def("apply_control", &ApplyControl<cr::WalkerControl>, (arg("control")))
|
||||
.def("apply_control", &ApplyControl<cr::WalkerBoneControl>, (arg("control")))
|
||||
.def("get_control", &cc::Walker::GetWalkerControl)
|
||||
.def("get_bones", &cc::Walker::GetBonesTransform)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -304,6 +304,17 @@ void export_control() {
|
|||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cr::BoneTransformData>("bone_transform")
|
||||
.def(init<>())
|
||||
.def_readwrite("name", &std::pair<std::string, cg::Transform>::first)
|
||||
.def_readwrite("transform", &std::pair<std::string, cg::Transform>::second)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<std::vector<cr::BoneTransformData>>("vector_of_bones")
|
||||
.def(boost::python::vector_indexing_suite<std::vector<cr::BoneTransformData>>())
|
||||
;
|
||||
|
||||
class_<cr::WalkerBoneControl>("WalkerBoneControl")
|
||||
.def("__init__", raw_function(WalkerBoneControl_init))
|
||||
.def(init<>())
|
||||
|
|
|
@ -180,6 +180,12 @@ namespace std {
|
|||
return PrintList(out, vector_of_stuff);
|
||||
}
|
||||
|
||||
template <typename T, typename H>
|
||||
std::ostream &operator<<(std::ostream &out, const std::pair<T,H> &data) {
|
||||
out << "(" << data.first << "," << data.second << ")";
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
static carla::time_duration TimeDurationFromSeconds(double seconds) {
|
||||
|
|
|
@ -1269,3 +1269,25 @@ ECarlaServerResponse FWalkerActor::ApplyBoneControlToWalker(
|
|||
}
|
||||
return ECarlaServerResponse::Success;
|
||||
}
|
||||
|
||||
ECarlaServerResponse FWalkerActor::GetBonesTransform(FWalkerBoneControl& Bones)
|
||||
{
|
||||
if (IsDormant())
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
auto Pawn = Cast<APawn>(GetActor());
|
||||
if (Pawn == nullptr)
|
||||
{
|
||||
return ECarlaServerResponse::NotAWalker;
|
||||
}
|
||||
auto Controller = Cast<AWalkerController>(Pawn->GetController());
|
||||
if (Controller == nullptr)
|
||||
{
|
||||
return ECarlaServerResponse::WalkerIncompatibleController;
|
||||
}
|
||||
Controller->GetBonesTransform(Bones);
|
||||
}
|
||||
return ECarlaServerResponse::Success;
|
||||
}
|
||||
|
|
|
@ -372,6 +372,11 @@ public:
|
|||
return ECarlaServerResponse::ActorTypeMismatch;
|
||||
}
|
||||
|
||||
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControl&)
|
||||
{
|
||||
return ECarlaServerResponse::ActorTypeMismatch;
|
||||
}
|
||||
|
||||
virtual ECarlaServerResponse FreezeTrafficLight(bool)
|
||||
{
|
||||
return ECarlaServerResponse::ActorTypeMismatch;
|
||||
|
@ -549,6 +554,8 @@ public:
|
|||
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl&) final;
|
||||
|
||||
virtual ECarlaServerResponse ApplyBoneControlToWalker(const FWalkerBoneControl&) final;
|
||||
|
||||
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControl&) final;
|
||||
};
|
||||
|
||||
class FOtherActor : public FCarlaActor
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <carla/rpc/Actor.h>
|
||||
#include <carla/rpc/ActorDefinition.h>
|
||||
#include <carla/rpc/ActorDescription.h>
|
||||
#include <carla/rpc/BoneTransformData.h>
|
||||
#include <carla/rpc/Command.h>
|
||||
#include <carla/rpc/CommandResponse.h>
|
||||
#include <carla/rpc/DebugShape.h>
|
||||
|
@ -1313,6 +1314,40 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(get_bones_transform) << [this](
|
||||
cr::ActorId ActorId) -> R<cr::WalkerBoneControl>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
|
||||
if (!CarlaActor)
|
||||
{
|
||||
return RespondError(
|
||||
"get_bones_transform",
|
||||
ECarlaServerResponse::ActorNotFound,
|
||||
" Actor Id: " + FString::FromInt(ActorId));
|
||||
}
|
||||
FWalkerBoneControl Bones;
|
||||
ECarlaServerResponse Response =
|
||||
CarlaActor->GetBonesTransform(Bones);
|
||||
if (Response != ECarlaServerResponse::Success)
|
||||
{
|
||||
return RespondError(
|
||||
"get_bones_transform",
|
||||
Response,
|
||||
" Actor Id: " + FString::FromInt(ActorId));
|
||||
}
|
||||
|
||||
std::vector<carla::rpc::BoneTransformData> BoneData;
|
||||
for (auto Bone : Bones.BoneTransforms)
|
||||
{
|
||||
std::pair<std::string, carla::geom::Transform> Data;
|
||||
Data.first = std::string(TCHAR_TO_UTF8(*Bone.Get<0>()));
|
||||
Data.second = Bone.Get<1>();
|
||||
BoneData.push_back(Data);
|
||||
}
|
||||
return carla::rpc::WalkerBoneControl(BoneData);
|
||||
};
|
||||
|
||||
BIND_SYNC(set_actor_autopilot) << [this](
|
||||
cr::ActorId ActorId,
|
||||
bool bEnabled) -> R<void>
|
||||
|
|
|
@ -101,12 +101,43 @@ void AWalkerController::SetManualBones(const bool bIsEnabled)
|
|||
else
|
||||
{
|
||||
UPoseableMeshComponent *PoseableMesh = PoseableMeshes.IsValidIndex(0) ? PoseableMeshes[0] : nullptr;
|
||||
PoseableMesh->SetVisibility(false);
|
||||
if (PoseableMesh)
|
||||
PoseableMesh->SetVisibility(false);
|
||||
SkeletalMesh->SetVisibility(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AWalkerController::GetBonesTransform(FWalkerBoneControl &WalkerBones)
|
||||
{
|
||||
auto *Character = GetCharacter();
|
||||
TArray<UPoseableMeshComponent *> PoseableMeshes;
|
||||
TArray<USkeletalMeshComponent *> SkeletalMeshes;
|
||||
Character->GetComponents<UPoseableMeshComponent>(PoseableMeshes, false);
|
||||
Character->GetComponents<USkeletalMeshComponent>(SkeletalMeshes, false);
|
||||
USkeletalMeshComponent *SkeletalMesh = SkeletalMeshes.IsValidIndex(0) ? SkeletalMeshes[0] : nullptr;
|
||||
if (!SkeletalMesh) return;
|
||||
|
||||
UPoseableMeshComponent *PoseableMesh =
|
||||
PoseableMeshes.IsValidIndex(0) ? PoseableMeshes[0] : AddNewBoneComponent(Character,
|
||||
SkeletalMesh->GetRelativeTransform().GetLocation(),
|
||||
SkeletalMesh->GetRelativeTransform().GetRotation().Rotator());
|
||||
PoseableMesh->SetSkeletalMesh(SkeletalMesh->SkeletalMesh);
|
||||
PoseableMesh->SetVisibility(false);
|
||||
PoseableMesh->CopyPoseFromSkeletalComponent(SkeletalMesh);
|
||||
|
||||
FPoseSnapshot Snap;
|
||||
SkeletalMesh->SnapshotPose(Snap);
|
||||
for (int i=0; i<Snap.BoneNames.Num(); ++i)
|
||||
{
|
||||
FTransform Trans = PoseableMesh->GetBoneTransformByName(Snap.BoneNames[i], EBoneSpaces::WorldSpace);
|
||||
WalkerBones.BoneTransforms.Add(Snap.BoneNames[i].ToString(), Trans);
|
||||
// FVector Loc = SkeletalMesh->GetBoneLocation(Snap.BoneNames[i], EBoneSpaces::WorldSpace);
|
||||
// Trans = Snap.LocalTransforms[i];
|
||||
// Trans.SetLocation(Loc);
|
||||
}
|
||||
}
|
||||
|
||||
void AWalkerController::ControlTickVisitor::operator()(const FWalkerControl &WalkerControl)
|
||||
{
|
||||
auto *Character = Controller->GetCharacter();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "GameFramework/Controller.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/rpc/WalkerBoneControl.h>
|
||||
#include <boost/variant.hpp>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
|
@ -76,6 +77,9 @@ public:
|
|||
UFUNCTION(BlueprintCallable)
|
||||
void SetManualBones(const bool bIsEnabled);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void GetBonesTransform(FWalkerBoneControl &WalkerBones);
|
||||
|
||||
private:
|
||||
|
||||
boost::variant<FWalkerControl, FWalkerBoneControl> Control;
|
||||
|
|
Loading…
Reference in New Issue