3#include "ConstructorHelpers.h"
5#include "Rendering/SkeletalMeshRenderData.h"
6#include "SkeletalRenderPublic.h"
15 FString MaterialPath = TEXT(
"Material'/Carla/PostProcessingMaterials/AnnotationColor.AnnotationColor'");
16 static ConstructorHelpers::FObjectFinder<UMaterial> TaggedMaterialObject(*MaterialPath);
20 PrimaryComponentTick.bCanEverTick =
true;
21 PrimaryComponentTick.bStartWithTickEnabled =
false;
37 UE_LOG(LogCarla, Error, TEXT(
"Failed to create MID!"));
53 TaggedMID->SetVectorParameterValue(
"AnnotationColor", Color);
67 USceneComponent * ParentComponent = GetAttachParent();
71 return ParentComponent->CalcBounds(LocalToWorld);
74 return FBoxSphereBounds();
80 USceneComponent * ParentComponent = GetAttachParent();
85 UE_LOG(LogCarla, Error, TEXT(
"Invalid parent component"));
90 USkeletalMeshComponent * SkeletalMeshComponent = Cast<USkeletalMeshComponent>(ParentComponent);
91 UStaticMeshComponent * StaticMeshComponent = Cast<UStaticMeshComponent>(ParentComponent);
92 UHierarchicalInstancedStaticMeshComponent * HierarchicalInstancedStaticMeshComponent =
93 Cast<UHierarchicalInstancedStaticMeshComponent>(ParentComponent);
94 UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Cast<UInstancedStaticMeshComponent>(ParentComponent);
96 if (HierarchicalInstancedStaticMeshComponent)
101 else if (InstancedStaticMeshComponent)
107 if (
IsValid(StaticMeshComponent))
112 else if (
IsValid(SkeletalMeshComponent))
119 UE_LOG(LogCarla, Error, TEXT(
"Unknown type of parent component: %s"), *ParentComponent->GetClass()->GetName());
127 UStaticMesh * StaticMesh = StaticMeshComponent->GetStaticMesh();
130 if (StaticMesh == NULL)
132 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because static mesh is null): %s"), *StaticMeshComponent->GetReadableName());
137 if (StaticMesh->RenderData == NULL)
139 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because render data is null): %s"), *StaticMeshComponent->GetReadableName());
144 if (StaticMesh->RenderData->LODResources.Num() == 0)
146 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because num LOD resources is 0): %s"), *StaticMeshComponent->GetReadableName());
163 ERHIFeatureLevel::Type SceneFeatureLevel = GetWorld()->FeatureLevel;
165 FSkeletalMeshRenderData* SkelMeshRenderData = SkeletalMeshComponent->GetSkeletalMeshRenderData();
168 if (SkelMeshRenderData &&
169 SkelMeshRenderData->LODRenderData.IsValidIndex(SkeletalMeshComponent->PredictedLODLevel) &&
170 !SkeletalMeshComponent->bHideSkin &&
171 SkeletalMeshComponent->MeshObject)
174 int32 MinLODIndex = SkeletalMeshComponent->ComputeMinLOD();
175 int32 MaxBonesPerChunk = SkelMeshRenderData->GetMaxBonesPerSection(MinLODIndex);
176 int32 MaxSupportedNumBones = SkeletalMeshComponent->MeshObject->IsCPUSkinned() ? MAX_int32 : GetFeatureLevelMaxNumberOfBones(SceneFeatureLevel);
177 if (MaxBonesPerChunk <= MaxSupportedNumBones)
188 const bool bMeshIsValid =
190 (MeshComponent->PerInstanceRenderData.IsValid()) &&
192 MeshComponent->GetStaticMesh() &&
193 MeshComponent->GetStaticMesh()->HasValidRenderData(
false) &&
200 bool bIsGrass = !MeshComponent->PerInstanceSMData.Num();
209 const bool bMeshIsValid =
211 (MeshComponent->PerInstanceRenderData.IsValid()) &&
213 MeshComponent->GetStaticMesh() &&
214 MeshComponent->GetStaticMesh()->HasValidRenderData(
false) &&
228 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
234 MarkRenderStateDirty();
255 bVerifyUsedMaterials =
false;
257 for (FLODInfo& LODInfo : LODs) {
258 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
266 FPrimitiveViewRelevance ViewRelevance = FStaticMeshSceneProxy::GetViewRelevance(View);
268 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
269 ViewRelevance.bShadowRelevance =
false;
271 return ViewRelevance;
283 bVerifyUsedMaterials =
false;
285 for (FLODSectionElements& LODSection : LODSections) {
286 for (FSectionElementInfo& ElementInfo : LODSection.SectionElements) {
294 FPrimitiveViewRelevance ViewRelevance = FSkeletalMeshSceneProxy::GetViewRelevance(View);
296 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
297 ViewRelevance.bShadowRelevance =
false;
299 return ViewRelevance;
303 UInstancedStaticMeshComponent * Component, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance * MaterialInstance)
309 bVerifyUsedMaterials =
false;
311 for (FLODInfo& LODInfo : LODs) {
312 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
320 FPrimitiveViewRelevance ViewRelevance = FInstancedStaticMeshSceneProxy::GetViewRelevance(View);
322 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
323 ViewRelevance.bShadowRelevance =
false;
325 return ViewRelevance;
330 UHierarchicalInstancedStaticMeshComponent * Component,
bool bInIsGrass, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance * MaterialInstance)
336 bVerifyUsedMaterials =
false;
338 for (FLODInfo& LODInfo : LODs) {
339 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
347 FPrimitiveViewRelevance ViewRelevance = FHierarchicalStaticMeshSceneProxy::GetViewRelevance(View);
349 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
350 ViewRelevance.bShadowRelevance =
false;
352 return ViewRelevance;
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
UMaterialInstance * TaggedMaterialInstance
FTaggedHierarchicalStaticMeshSceneProxy(UHierarchicalInstancedStaticMeshComponent *Component, bool bInIsGrass, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance *MaterialInstance)
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView *View) const override
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView *View) const override
UMaterialInstance * TaggedMaterialInstance
FTaggedInstancedStaticMeshSceneProxy(UInstancedStaticMeshComponent *Component, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance *MaterialInstance)
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView *View) const override
UMaterialInstance * TaggedMaterialInstance
FTaggedSkeletalMeshSceneProxy(const USkinnedMeshComponent *Component, FSkeletalMeshRenderData *InSkeletalMeshRenderData, UMaterialInstance *MaterialInstance)
FTaggedStaticMeshSceneProxy(UStaticMeshComponent *Component, bool bForceLODsShareStaticLighting, UMaterialInstance *MaterialInstance)
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView *View) const override
UMaterialInstance * TaggedMaterialInstance
virtual FPrimitiveSceneProxy * CreateSceneProxy() override
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
virtual void OnRegister() override
UTaggedComponent(const FObjectInitializer &ObjectInitializer)
UMaterial * TaggedMaterial
virtual FBoxSphereBounds CalcBounds(const FTransform &LocalToWorld) const
void SetColor(FLinearColor color)
UMaterialInstanceDynamic * TaggedMID