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;
32 UE_LOG(LogCarla, Error, TEXT(
"Failed to create MID!"));
44 TaggedMID->SetVectorParameterValue(
"AnnotationColor", Color);
55 USceneComponent * ParentComponent = GetAttachParent();
58 return ParentComponent->CalcBounds(LocalToWorld);
60 return FBoxSphereBounds();
65 USceneComponent * ParentComponent = GetAttachParent();
69 UE_LOG(LogCarla, Error, TEXT(
"Invalid parent component"));
73 USkeletalMeshComponent * SkeletalMeshComponent = Cast<USkeletalMeshComponent>(ParentComponent);
74 UStaticMeshComponent * StaticMeshComponent = Cast<UStaticMeshComponent>(ParentComponent);
75 UHierarchicalInstancedStaticMeshComponent * HierarchicalInstancedStaticMeshComponent =
76 Cast<UHierarchicalInstancedStaticMeshComponent>(ParentComponent);
77 UInstancedStaticMeshComponent* InstancedStaticMeshComponent = Cast<UInstancedStaticMeshComponent>(ParentComponent);
78 if (HierarchicalInstancedStaticMeshComponent)
82 else if (InstancedStaticMeshComponent)
87 if (
IsValid(StaticMeshComponent))
91 else if (
IsValid(SkeletalMeshComponent))
97 UE_LOG(LogCarla, Error, TEXT(
"Unknown type of parent component: %s"), *ParentComponent->GetClass()->GetName());
105 UStaticMesh * StaticMesh = StaticMeshComponent->GetStaticMesh();
107 if (StaticMesh == NULL)
109 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because static mesh is null): %s"), *StaticMeshComponent->GetReadableName());
113 if (StaticMesh->RenderData == NULL)
115 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because render data is null): %s"), *StaticMeshComponent->GetReadableName());
120 if (StaticMesh->RenderData->LODResources.Num() == 0)
122 UE_LOG(LogCarla, Error, TEXT(
"Failed to create scene proxy for static mesh component (because num LOD resources is 0): %s"), *StaticMeshComponent->GetReadableName());
135 ERHIFeatureLevel::Type SceneFeatureLevel = GetWorld()->FeatureLevel;
136 FSkeletalMeshRenderData* SkelMeshRenderData = SkeletalMeshComponent->GetSkeletalMeshRenderData();
139 if (SkelMeshRenderData &&
140 SkelMeshRenderData->LODRenderData.IsValidIndex(SkeletalMeshComponent->PredictedLODLevel) &&
141 !SkeletalMeshComponent->bHideSkin &&
142 SkeletalMeshComponent->MeshObject)
145 int32 MinLODIndex = SkeletalMeshComponent->ComputeMinLOD();
146 int32 MaxBonesPerChunk = SkelMeshRenderData->GetMaxBonesPerSection(MinLODIndex);
147 int32 MaxSupportedNumBones = SkeletalMeshComponent->MeshObject->IsCPUSkinned() ? MAX_int32 : GetFeatureLevelMaxNumberOfBones(SceneFeatureLevel);
148 if (MaxBonesPerChunk <= MaxSupportedNumBones)
159 const bool bMeshIsValid =
161 (MeshComponent->PerInstanceRenderData.IsValid()) &&
163 MeshComponent->GetStaticMesh() &&
164 MeshComponent->GetStaticMesh()->HasValidRenderData(
false) &&
171 bool bIsGrass = !MeshComponent->PerInstanceSMData.Num();
180 const bool bMeshIsValid =
182 (MeshComponent->PerInstanceRenderData.IsValid()) &&
184 MeshComponent->GetStaticMesh() &&
185 MeshComponent->GetStaticMesh()->HasValidRenderData(
false) &&
199 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
205 MarkRenderStateDirty();
226 bVerifyUsedMaterials =
false;
228 for (FLODInfo& LODInfo : LODs) {
229 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
237 FPrimitiveViewRelevance ViewRelevance = FStaticMeshSceneProxy::GetViewRelevance(View);
239 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
240 ViewRelevance.bShadowRelevance =
false;
242 return ViewRelevance;
254 bVerifyUsedMaterials =
false;
256 for (FLODSectionElements& LODSection : LODSections) {
257 for (FSectionElementInfo& ElementInfo : LODSection.SectionElements) {
265 FPrimitiveViewRelevance ViewRelevance = FSkeletalMeshSceneProxy::GetViewRelevance(View);
267 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
268 ViewRelevance.bShadowRelevance =
false;
270 return ViewRelevance;
274 UInstancedStaticMeshComponent * Component, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance * MaterialInstance)
280 bVerifyUsedMaterials =
false;
282 for (FLODInfo& LODInfo : LODs) {
283 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
291 FPrimitiveViewRelevance ViewRelevance = FInstancedStaticMeshSceneProxy::GetViewRelevance(View);
293 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
294 ViewRelevance.bShadowRelevance =
false;
296 return ViewRelevance;
301 UHierarchicalInstancedStaticMeshComponent * Component,
bool bInIsGrass, ERHIFeatureLevel::Type InFeatureLevel, UMaterialInstance * MaterialInstance)
307 bVerifyUsedMaterials =
false;
309 for (FLODInfo& LODInfo : LODs) {
310 for (FLODInfo::FSectionInfo& SectionInfo : LODInfo.Sections) {
318 FPrimitiveViewRelevance ViewRelevance = FHierarchicalStaticMeshSceneProxy::GetViewRelevance(View);
320 ViewRelevance.bDrawRelevance = ViewRelevance.bDrawRelevance && !View->Family->EngineShowFlags.NotDrawTaggedComponents;
321 ViewRelevance.bShadowRelevance =
false;
323 return ViewRelevance;
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