From f45dd6943c6750beff1a3af2dddccc9639cfe5d3 Mon Sep 17 00:00:00 2001 From: Thies de Graaff Date: Wed, 12 Mar 2025 13:11:36 +0100 Subject: [PATCH] [Fix] Invisible spline meshes in instance segmentation (UE4) (#8714) * Added explicit support for SplineMeshSceneProxy (e.g. PowerPoles) in TaggedComponent, rendering them visible in the instance segmentation. * Described bug fix in changelog. --- CHANGELOG.md | 1 + .../Source/Carla/Game/TaggedComponent.cpp | 35 ++++++++++++++++++- .../Carla/Source/Carla/Game/TaggedComponent.h | 13 +++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb78367e6..47822fa54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * carla.ad subpackages are now directly importable and are not directly importable anymore (e.g. import ad) * Fixed segfault in traffic manager when trying to access not available vehicles * Fixed invalid comparission in python examples/rss + * Fixed invisible spline meshes in instance segmentation ## CARLA 0.9.15 diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.cpp index 7088d97f2..ccd419fb1 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.cpp @@ -123,7 +123,12 @@ FPrimitiveSceneProxy * UTaggedComponent::CreateSceneProxy(UStaticMeshComponent * return NULL; } - return new FTaggedStaticMeshSceneProxy(StaticMeshComponent, true, TaggedMID); + USplineMeshComponent* SplineMeshComponent = Cast(StaticMeshComponent); + if (SplineMeshComponent) { + return new FTaggedSplineMeshSceneProxy(SplineMeshComponent, TaggedMID); + } else { + return new FTaggedStaticMeshSceneProxy(StaticMeshComponent, true, TaggedMID); + } } FPrimitiveSceneProxy * UTaggedComponent::CreateSceneProxy(USkeletalMeshComponent * SkeletalMeshComponent) @@ -242,6 +247,34 @@ FPrimitiveViewRelevance FTaggedStaticMeshSceneProxy::GetViewRelevance(const FSce return ViewRelevance; } +// +// FTaggedSplineMeshSceneProxy +// +FTaggedSplineMeshSceneProxy::FTaggedSplineMeshSceneProxy(USplineMeshComponent * Component, UMaterialInstance * MaterialInstance) : + FSplineMeshSceneProxy(Component) +{ + TaggedMaterialInstance = MaterialInstance; + + // Replace materials with tagged material + bVerifyUsedMaterials = false; + + for (FLODInfo& LODInfo : LODs) { + for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) { + SectionInfo.Material = TaggedMaterialInstance; + } + } +} + +FPrimitiveViewRelevance FTaggedSplineMeshSceneProxy::GetViewRelevance(const FSceneView * View) const +{ + FPrimitiveViewRelevance ViewRelevance = FSplineMeshSceneProxy::GetViewRelevance(View); + + ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents; + ViewRelevance.bShadowRelevance = false; + + return ViewRelevance; +} + // // FTaggedSkeletalMeshSceneProxy // diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.h index b7706df98..fc5b838b3 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/TaggedComponent.h @@ -4,6 +4,7 @@ #include "Materials/MaterialInstanceDynamic.h" #include "Engine/InstancedStaticMesh.h" #include "Components/HierarchicalInstancedStaticMeshComponent.h" +#include "SplineMeshSceneProxy.h" #include "Landscape.h" #include "LandscapeRender.h" #include "LandscapeMaterialInstanceConstant.h" @@ -59,6 +60,18 @@ private: UMaterialInstance * TaggedMaterialInstance; }; +class FTaggedSplineMeshSceneProxy : public FSplineMeshSceneProxy +{ +public: + + FTaggedSplineMeshSceneProxy(USplineMeshComponent * Component, UMaterialInstance * MaterialInstance); + + virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView * View) const override; + +private: + UMaterialInstance * TaggedMaterialInstance; +}; + class FTaggedSkeletalMeshSceneProxy : public FSkeletalMeshSceneProxy { public: