Skip to content

Commit 6e83de0

Browse files
Fix for the issues 9361, 9385 and 9387 (#9380)
* Refactor AdjustAllSignsToHeightGround to improve positioning logic and maintain box component locations * Refactor AdjustAllSignsToHeightGround to preserve box component positions during height adjustments * Recalculate bounding boxes for moved actors. Added new parameter for ActorInfo for the trigger volume. Now `get_trigger_volume` returns the real trigger volume * Revert "Recalculate bounding boxes for moved actors." This reverts commit 8eb35ab. * Add methods to retrieve traffic sign trigger volumes * Fixed bounding boxes being drawed rotated. Add RegisterEnvironmentObjects method and update object registration logic
1 parent 4fdea38 commit 6e83de0

File tree

12 files changed

+180
-67
lines changed

12 files changed

+180
-67
lines changed

LibCarla/source/carla/client/TrafficSign.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
namespace carla {
1212
namespace client {
1313

14+
geom::BoundingBox TrafficSign::GetTriggerVolume() const {
15+
return GetEpisode().Lock()->GetTrafficSignTriggerVolume(*this);
16+
}
17+
1418
carla::road::SignId TrafficSign::GetSignId() const {
1519
return std::string(GetEpisode().Lock()->GetActorSnapshot(*this).state.traffic_light_data.sign_id);
1620
}

LibCarla/source/carla/client/TrafficSign.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ namespace client {
1717

1818
explicit TrafficSign(ActorInitializer init) : Actor(std::move(init)) {}
1919

20-
const geom::BoundingBox &GetTriggerVolume() const {
21-
return ActorState::GetBoundingBox();
22-
}
20+
geom::BoundingBox GetTriggerVolume() const;
2321

2422
carla::road::SignId GetSignId() const;
2523

LibCarla/source/carla/client/detail/Client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ namespace detail {
459459
return _pimpl->CallAndWait<geom::BoundingBox>("get_actor_bounding_box", actor);
460460
}
461461

462+
geom::BoundingBox Client::GetTrafficSignTriggerVolume(rpc::ActorId actor) {
463+
return _pimpl->CallAndWait<geom::BoundingBox>("get_traffic_sign_trigger_volume", actor);
464+
}
465+
462466
geom::Transform Client::GetActorComponentWorldTransform(rpc::ActorId actor, const std::string componentName) {
463467
return _pimpl->CallAndWait<geom::Transform>("get_actor_component_world_transform", actor, componentName);
464468
}

LibCarla/source/carla/client/detail/Client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ namespace detail {
249249
geom::BoundingBox GetActorBoundingBox(
250250
rpc::ActorId actor);
251251

252+
geom::BoundingBox GetTrafficSignTriggerVolume(
253+
rpc::ActorId actor);
254+
252255
geom::Transform GetActorComponentWorldTransform(
253256
rpc::ActorId actor,
254257
const std::string componentName);

LibCarla/source/carla/client/detail/Simulator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ namespace detail {
456456
return _client.GetActorBoundingBox(actor.GetId());
457457
}
458458

459+
geom::BoundingBox GetTrafficSignTriggerVolume(const Actor &actor) {
460+
return _client.GetTrafficSignTriggerVolume(actor.GetId());
461+
}
462+
459463
geom::Transform GetActorComponentWorldTransform(const Actor &actor, const std::string componentName) {
460464
return _client.GetActorComponentWorldTransform(actor.GetId(), componentName);
461465
}

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class CARLA_API ACarlaGameModeBase : public AGameModeBase
7777

7878
void EnableEnvironmentObjects(const TSet<uint64>& EnvObjectIds, bool Enable);
7979

80+
void RegisterEnvironmentObjects();
81+
8082
void EnableOverlapEvents();
8183

8284
void CheckForEmptyMeshes();
@@ -143,8 +145,6 @@ class CARLA_API ACarlaGameModeBase : public AGameModeBase
143145

144146
void SpawnRoadSplines();
145147

146-
void RegisterEnvironmentObjects();
147-
148148
void ConvertMapLayerMaskToMapNames(int32 MapLayer, TArray<FName>& OutLevelNames);
149149

150150
void OnEpisodeSettingsChanged(const FEpisodeSettings &Settings);

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/MapGen/LargeMapManager.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Game/CarlaStatics.h"
1010
#include "Actor/ActorRegistry.h"
1111
#include "Game/CarlaEpisode.h"
12+
#include "Util/BoundingBoxCalculator.h"
1213
#include "Engine/EngineTypes.h"
1314
#include "Components/PrimitiveComponent.h"
1415
#include "Landscape.h"
@@ -166,9 +167,17 @@ bool ALargeMapManager::AdjustSignHeightToGround(FVector& SpawnLocation, const FS
166167

167168
void ALargeMapManager::AdjustAllSignsToHeightGround()
168169
{
170+
UWorld* World = GetWorld();
171+
if (!World)
172+
{
173+
return;
174+
}
175+
176+
UCarlaEpisode* CarlaEpisode = UCarlaStatics::GetCurrentEpisode(World);
177+
169178
TArray<AActor*> ActorsToIgnore;
170179
TArray<AActor*> ActorsToAdjustHeight;
171-
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ATrafficSignBase::StaticClass(), ActorsToAdjustHeight);
180+
UGameplayStatics::GetAllActorsOfClass(World, ATrafficSignBase::StaticClass(), ActorsToAdjustHeight);
172181
ActorsToIgnore.Append(ActorsToAdjustHeight);
173182
for (AActor* Actor : ActorsToAdjustHeight)
174183
{
@@ -179,40 +188,40 @@ void ALargeMapManager::AdjustAllSignsToHeightGround()
179188
continue;
180189
FVector OriginalLocation = Actor->GetActorLocation();
181190
FVector AdjustedLocation = OriginalLocation;
182-
191+
183192
TrafficSign->bPositioned = AdjustSignHeightToGround(AdjustedLocation, Actor->GetName(), ActorsToIgnore);
184-
193+
185194
if (TrafficSign->bPositioned)
186195
{
187196
float ZOffset = AdjustedLocation.Z - OriginalLocation.Z;
188197

189198
Actor->GetRootComponent()->SetMobility(EComponentMobility::Movable);
190-
199+
191200
// Get all static mesh components
192201
TArray<UStaticMeshComponent*> StaticMeshComps;
193202
Actor->GetComponents<UStaticMeshComponent>(StaticMeshComps);
194-
203+
195204
for (UStaticMeshComponent* MeshComp : StaticMeshComps)
196205
{
197206
if (!MeshComp) continue;
198-
207+
199208
// Skip if this has a mesh parent (it's a child)
200209
USceneComponent* ParentComp = MeshComp->GetAttachParent();
201210
if (ParentComp && Cast<UStaticMeshComponent>(ParentComp))
202211
{
203212
continue;
204213
}
205-
214+
206215
// Move the mesh component down
207216
FVector CompLocation = MeshComp->GetRelativeLocation();
208217
CompLocation.Z += ZOffset;
209218
MeshComp->SetRelativeLocation(CompLocation);
210-
219+
211220
MeshComp->UpdateBounds();
212-
221+
213222
LM_LOG(Log, "Moved mesh %s by %f cm", *Actor->GetName(), ZOffset);
214223
}
215-
224+
216225
Actor->UpdateComponentTransforms();
217226
Actor->GetRootComponent()->SetMobility(EComponentMobility::Static);
218227
}
@@ -221,10 +230,17 @@ void ALargeMapManager::AdjustAllSignsToHeightGround()
221230

222231
void ALargeMapManager::OnLevelAddedToWorld(ULevel* InLevel, UWorld* InWorld)
223232
{
224-
225233
UCarlaEpisode* CarlaEpisode = UCarlaStatics::GetCurrentEpisode(InWorld);
226234
ATagger::TagActorsInLevel(*InLevel, *CarlaEpisode, true);
227235
AdjustAllSignsToHeightGround();
236+
237+
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(InWorld);
238+
if (GameMode)
239+
{
240+
GameMode->RegisterEnvironmentObjects();
241+
LM_LOG(Log, "Re-registered environment objects after sign height adjustment");
242+
}
243+
228244
LM_LOG(Warning, "OnLevelAddedToWorld");
229245
//FDebug::DumpStackTraceToLog(ELogVerbosity::Log);
230246
}

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,18 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_
15501550
return cr::BoundingBox(bounding_box);
15511551
};
15521552

1553+
BIND_SYNC(get_traffic_sign_trigger_volume) << [this](
1554+
cr::ActorId ActorId) -> R<cr::BoundingBox>
1555+
{
1556+
REQUIRE_CARLA_EPISODE();
1557+
FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId);
1558+
if (!CarlaActor)
1559+
return cr::BoundingBox();
1560+
FBoundingBox trigger_volume = UBoundingBoxCalculator::GetTrafficSignTriggerVolume(CarlaActor->GetActor());
1561+
trigger_volume.ActorId = CarlaActor->GetActorId();
1562+
return cr::BoundingBox(trigger_volume);
1563+
};
1564+
15531565
BIND_SYNC(get_actor_component_world_transform) << [this](
15541566
cr::ActorId ActorId,
15551567
const std::string componentName) -> R<cr::Transform>

Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Traffic/TrafficLightManager.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "TrafficLightManager.h"
88
#include "Game/CarlaStatics.h"
9+
#include "Util/BoundingBoxCalculator.h"
910
#include "StopSignComponent.h"
1011
#include "YieldSignComponent.h"
1112
#include "SpeedLimitComponent.h"
@@ -264,6 +265,14 @@ const boost::optional<carla::road::Map>& ATrafficLightManager::GetMap()
264265

265266
void ATrafficLightManager::AdjustAllSignsToHeightGround()
266267
{
268+
UWorld* World = GetWorld();
269+
if (!World)
270+
{
271+
return;
272+
}
273+
274+
UCarlaEpisode* CarlaEpisode = UCarlaStatics::GetCurrentEpisode(World);
275+
267276
for(ATrafficSignBase* TS : TrafficSigns)
268277
{
269278
if (!IsValid(TS))
@@ -273,40 +282,40 @@ void ATrafficLightManager::AdjustAllSignsToHeightGround()
273282

274283
FVector OriginalLocation = TS->GetActorLocation();
275284
FVector AdjustedLocation = OriginalLocation;
276-
285+
277286
TS->bPositioned = AdjustSignHeightToGround(AdjustedLocation);
278-
287+
279288
if (TS->bPositioned)
280289
{
281290
float ZOffset = AdjustedLocation.Z - OriginalLocation.Z;
282291

283292
TS->GetRootComponent()->SetMobility(EComponentMobility::Movable);
284-
293+
285294
// Get all static mesh components
286295
TArray<UStaticMeshComponent*> StaticMeshComps;
287296
TS->GetComponents<UStaticMeshComponent>(StaticMeshComps);
288-
297+
289298
for (UStaticMeshComponent* MeshComp : StaticMeshComps)
290299
{
291300
if (!MeshComp) continue;
292-
301+
293302
// Skip if this has a mesh parent (it's a child)
294303
USceneComponent* ParentComp = MeshComp->GetAttachParent();
295304
if (ParentComp && Cast<UStaticMeshComponent>(ParentComp))
296305
{
297306
continue;
298307
}
299-
308+
300309
// Move the mesh component down
301310
FVector CompLocation = MeshComp->GetRelativeLocation();
302311
CompLocation.Z += ZOffset;
303312
MeshComp->SetRelativeLocation(CompLocation);
304-
313+
305314
MeshComp->UpdateBounds();
306-
315+
307316
UE_LOG(LogCarla, Log, TEXT("Moved mesh %s by %f cm"), *TS->GetName(), ZOffset);
308317
}
309-
318+
310319
TS->UpdateComponentTransforms();
311320
TS->GetRootComponent()->SetMobility(EComponentMobility::Static);
312321
}
@@ -336,6 +345,13 @@ void ATrafficLightManager::GenerateSignalsAndTrafficLights()
336345
if (CurrentMapName.Contains(TEXT("Town15"), ESearchCase::IgnoreCase))
337346
{
338347
AdjustAllSignsToHeightGround();
348+
349+
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(GetWorld());
350+
if (GameMode)
351+
{
352+
GameMode->RegisterEnvironmentObjects();
353+
UE_LOG(LogCarla, Log, TEXT("Re-registered environment objects after sign height adjustment"));
354+
}
339355
}
340356

341357
}

0 commit comments

Comments
 (0)