Introduce necessary functions for the new apply-texture functions.
This commit is contained in:
parent
f0b0fb8138
commit
04d91a9625
|
@ -96,6 +96,20 @@ namespace client {
|
|||
GetEpisode().Lock()->SetActorEnableGravity(*this, enabled);
|
||||
}
|
||||
|
||||
void Actor::ApplyTexture(
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureColor& Texture)
|
||||
{
|
||||
GetEpisode().Lock()->ApplyTextureToActor(*this, MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
void Actor::ApplyTexture(
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureFloatColor& Texture)
|
||||
{
|
||||
GetEpisode().Lock()->ApplyTextureToActor(*this, MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
rpc::ActorState Actor::GetActorState() const {
|
||||
return GetEpisode().Lock()->GetActorState(*this);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,14 @@ namespace client {
|
|||
/// Enable or disable gravity on this actor.
|
||||
void SetEnableGravity(bool enabled = true);
|
||||
|
||||
void ApplyTexture(
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureColor& Texture);
|
||||
|
||||
void ApplyTexture(
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureFloatColor& Texture);
|
||||
|
||||
rpc::ActorState GetActorState() const;
|
||||
|
||||
bool IsAlive() const {
|
||||
|
|
|
@ -164,6 +164,22 @@ namespace detail {
|
|||
_pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);
|
||||
}
|
||||
|
||||
void Client::ApplyTextureToActor(
|
||||
rpc::ActorId ActorId,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureColor& Texture)
|
||||
{
|
||||
_pimpl->CallAndWait<void>("apply_texture_to_actor", ActorId, MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
void Client::ApplyTextureToActor(
|
||||
rpc::ActorId ActorId,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureFloatColor& Texture)
|
||||
{
|
||||
_pimpl->CallAndWait<void>("apply_texture_to_actor_float", ActorId, MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
void Client::ApplyColorTextureToObjects(
|
||||
const std::vector<std::string> &objects_name,
|
||||
const rpc::MaterialParameter& parameter,
|
||||
|
|
|
@ -107,6 +107,16 @@ namespace detail {
|
|||
void CopyOpenDriveToServer(
|
||||
std::string opendrive, const rpc::OpendriveGenerationParameters & params);
|
||||
|
||||
void ApplyTextureToActor(
|
||||
rpc::ActorId ActorId,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureColor& Texture);
|
||||
|
||||
void ApplyTextureToActor(
|
||||
rpc::ActorId ActorId,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureFloatColor& Texture);
|
||||
|
||||
void ApplyColorTextureToObjects(
|
||||
const std::vector<std::string> &objects_name,
|
||||
const rpc::MaterialParameter& parameter,
|
||||
|
|
|
@ -470,6 +470,22 @@ namespace detail {
|
|||
_client.SetActorEnableGravity(actor.GetId(), enabled);
|
||||
}
|
||||
|
||||
void ApplyTextureToActor(
|
||||
Actor& actor,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureColor& Texture)
|
||||
{
|
||||
_client.ApplyTextureToActor(actor.GetId(), MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
void ApplyTextureToActor(
|
||||
Actor& actor,
|
||||
const rpc::MaterialParameter& MaterialParameter,
|
||||
const rpc::TextureFloatColor& Texture)
|
||||
{
|
||||
_client.ApplyTextureToActor(actor.GetId(), MaterialParameter, Texture);
|
||||
}
|
||||
|
||||
/// @}
|
||||
// =========================================================================
|
||||
/// @name Operations with vehicles
|
||||
|
|
|
@ -106,6 +106,7 @@ void export_actor() {
|
|||
.def("set_simulate_physics", &cc::Actor::SetSimulatePhysics, (arg("enabled") = true))
|
||||
.def("set_collisions", &cc::Actor::SetCollisions, (arg("enabled") = true))
|
||||
.def("set_enable_gravity", &cc::Actor::SetEnableGravity, (arg("enabled") = true))
|
||||
.def("apply_texture", &cc::Actor::ApplyTexture, (arg("texture")))
|
||||
.def("destroy", CALL_WITHOUT_GIL(cc::Actor, Destroy))
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
|
|
@ -339,6 +339,8 @@ void export_world() {
|
|||
.def("project_point", CALL_RETURNING_OPTIONAL_3(cc::World, ProjectPoint, cg::Location, cg::Vector3D, float), (arg("location"), arg("direction"), arg("search_distance")=10000.f))
|
||||
.def("ground_projection", CALL_RETURNING_OPTIONAL_2(cc::World, GroundProjection, cg::Location, float), (arg("location"), arg("search_distance")=10000.f))
|
||||
.def("get_names_of_all_objects", CALL_RETURNING_LIST(cc::World, GetNamesOfAllObjects))
|
||||
|
||||
// All of this is deprecated:
|
||||
.def("apply_color_texture_to_object", &cc::World::ApplyColorTextureToObject, (arg("object_name"), arg("material_parameter"), arg("texture")))
|
||||
.def("apply_float_color_texture_to_object", &cc::World::ApplyFloatColorTextureToObject, (arg("object_name"), arg("material_parameter"), arg("texture")))
|
||||
.def("apply_textures_to_object", &cc::World::ApplyTexturesToObject, (arg("object_name"), arg("diffuse_texture"), arg("emissive_texture"), arg("normal_texture"), arg("ao_roughness_metallic_emissive_texture")))
|
||||
|
@ -351,6 +353,7 @@ void export_world() {
|
|||
.def("apply_textures_to_objects", +[](cc::World &self, boost::python::list &list, const cr::TextureColor& diffuse_texture, const cr::TextureFloatColor& emissive_texture, const cr::TextureFloatColor& normal_texture, const cr::TextureFloatColor& ao_roughness_metallic_emissive_texture) {
|
||||
self.ApplyTexturesToObjects(PyListToVector<std::string>(list), diffuse_texture, emissive_texture, normal_texture, ao_roughness_metallic_emissive_texture);
|
||||
}, (arg("objects_name_list"), arg("diffuse_texture"), arg("emissive_texture"), arg("normal_texture"), arg("ao_roughness_metallic_emissive_texture")))
|
||||
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ class TestApplyTextures(unittest.TestCase):
|
|||
self.assertIsNotNone(bp)
|
||||
world.tick()
|
||||
world.apply_color_texture_to_objects(
|
||||
world.get_names_of_all_objects(),
|
||||
world.get_all_actors(),
|
||||
carla.MaterialParameter.Diffuse,
|
||||
noise_texture_color_red)
|
||||
time.sleep(2)
|
||||
|
|
|
@ -173,4 +173,4 @@
|
|||
"Mac",
|
||||
"Windows"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -112,6 +112,7 @@ public:
|
|||
UTexture2D* Texture,
|
||||
const carla::rpc::MaterialParameter& TextureParam);
|
||||
|
||||
[[deprecated("This command no longer makes sense since the apply_textures API relies on IDs.")]]
|
||||
TArray<FString> GetNamesOfAllActors();
|
||||
|
||||
FOnEpisodeInitialisedDelegate OnEpisodeInitialisedDelegate;
|
||||
|
|
|
@ -85,6 +85,20 @@ static std::vector<T> MakeVectorFromTArray(const TArray<Other> &Array)
|
|||
return {Array.GetData(), Array.GetData() + Array.Num()};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void ApplyTextureToActor(
|
||||
UCarlaEpisode* Episode,
|
||||
carla::rpc::ActorId ActorId,
|
||||
const carla::rpc::MaterialParameter& MaterialParameter,
|
||||
T&& Texture)
|
||||
{
|
||||
auto CarlaActor = Episode->FindCarlaActor(ActorId);
|
||||
auto Actor = CarlaActor->GetActor();
|
||||
auto GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
|
||||
auto TextureUE = GameMode->CreateUETexture(Texture);
|
||||
GameMode->ApplyTextureToActor(Actor, TextureUE, MaterialParameter);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- FCarlaServer::FPimpl -----------------------------------------------
|
||||
// =============================================================================
|
||||
|
@ -352,6 +366,26 @@ void FCarlaServer::FPimpl::BindActions()
|
|||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(apply_texture_to_actor) << [this](
|
||||
cr::ActorId ActorId,
|
||||
const cr::MaterialParameter& MaterialParameter,
|
||||
const cr::TextureColor& Texture) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
::ApplyTextureToActor(Episode, ActorId, MaterialParameter, Texture);
|
||||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(apply_texture_to_actor_float) << [this](
|
||||
cr::ActorId ActorId,
|
||||
const cr::MaterialParameter& MaterialParameter,
|
||||
const cr::TextureFloatColor& Texture) -> R<void>
|
||||
{
|
||||
REQUIRE_CARLA_EPISODE();
|
||||
::ApplyTextureToActor(Episode, ActorId, MaterialParameter, Texture);
|
||||
return R<void>::Success();
|
||||
};
|
||||
|
||||
BIND_SYNC(apply_color_texture_to_objects) << [this](
|
||||
const std::vector<std::string> &actors_name,
|
||||
const cr::MaterialParameter& parameter,
|
||||
|
|
Loading…
Reference in New Issue