RuntimeMeshComponentProxy.cpp
Go to the documentation of this file.
1 // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved.
2 
5 #include "RuntimeMeshComponent.h"
6 #include "RuntimeMeshProxy.h"
7 #include "PhysicsEngine/BodySetup.h"
8 #include "TessellationRendering.h"
9 #include "PrimitiveSceneProxy.h"
10 
12  : FPrimitiveSceneProxy(Component)
13  , BodySetup(Component->GetBodySetup())
14 {
15  bStaticElementsAlwaysUseProxyPrimitiveUniformBuffer = true;
16 
17  check(Component->GetRuntimeMesh() != nullptr);
18 
19  RuntimeMeshProxy = Component->GetRuntimeMesh()->EnsureProxyCreated(GetScene().GetFeatureLevel());
20 
21  // Setup our material map
22 
23 
24  for (auto SectionId : Component->GetRuntimeMesh()->GetSectionIds())
25  {
26  UMaterialInterface* Mat = Component->GetMaterial(SectionId);
27  if (Mat == nullptr)
28  {
29  Mat = UMaterial::GetDefaultMaterial(MD_Surface);
30  }
31 
32  SectionRenderData.Add(SectionId, FRuntimeMeshSectionRenderData{ Mat, false });
33 
34  MaterialRelevance |= Mat->GetRelevance(GetScene().GetFeatureLevel());
35  }
36 }
37 
39 {
40 
41 }
42 
44 {
46 
47  for (auto& Entry : SectionRenderData)
48  {
49  if (RuntimeMeshProxy->GetSections().Contains(Entry.Key))
50  {
51  FRuntimeMeshSectionProxyPtr Section = RuntimeMeshProxy->GetSections()[Entry.Key];
52 
53  auto& RenderData = SectionRenderData[Entry.Key];
54 
55  RenderData.bWantsAdjacencyInfo = RequiresAdjacencyInformation(RenderData.Material, RuntimeMeshProxy->GetSections()[Entry.Key]->GetVertexFactory()->GetType(), GetScene().GetFeatureLevel());
56  }
57  }
58 
59  FPrimitiveSceneProxy::CreateRenderThreadResources();
60 }
61 
62 FPrimitiveViewRelevance FRuntimeMeshComponentSceneProxy::GetViewRelevance(const FSceneView* View) const
63 {
64  FPrimitiveViewRelevance Result;
65  Result.bDrawRelevance = IsShown(View);
66  Result.bShadowRelevance = IsShadowCast(View);
67 
68  bool bForceDynamicPath = !IsStatic() || IsRichView(*View->Family) || IsSelected() || View->Family->EngineShowFlags.Wireframe;
69  Result.bStaticRelevance = !bForceDynamicPath && bHasStaticSections;
70  Result.bDynamicRelevance = bForceDynamicPath || bHasDynamicSections;
71 
72  Result.bRenderInMainPass = ShouldRenderInMainPass();
73  Result.bUsesLightingChannels = GetLightingChannelMask() != GetDefaultLightingChannelMask();
74  Result.bRenderCustomDepth = ShouldRenderCustomDepth();
75  MaterialRelevance.SetPrimitiveViewRelevance(Result);
76  return Result;
77 }
78 
79 void FRuntimeMeshComponentSceneProxy::CreateMeshBatch(FMeshBatch& MeshBatch, const FRuntimeMeshSectionProxyPtr& Section, const FRuntimeMeshSectionRenderData& RenderData, FMaterialRenderProxy* Material, FMaterialRenderProxy* WireframeMaterial) const
80 {
81  bool bRenderWireframe = WireframeMaterial != nullptr;
82  bool bWantsAdjacency = !bRenderWireframe && RenderData.bWantsAdjacencyInfo;
83 
84  Section->CreateMeshBatch(MeshBatch, bWantsAdjacency);
85  MeshBatch.bWireframe = WireframeMaterial != nullptr;
86  MeshBatch.MaterialRenderProxy = MeshBatch.bWireframe ? WireframeMaterial : Material;
87 
88  MeshBatch.ReverseCulling = IsLocalToWorldDeterminantNegative();
89  MeshBatch.bCanApplyViewModeOverrides = true;
90 
91  //HORU: 4.22 compat
92  //FMeshBatchElement& BatchElement = MeshBatch.Elements[0];
93 }
94 
95 void FRuntimeMeshComponentSceneProxy::DrawStaticElements(FStaticPrimitiveDrawInterface* PDI)
96 {
97  for (const auto& SectionEntry : RuntimeMeshProxy->GetSections())
98  {
99  FRuntimeMeshSectionProxyPtr Section = SectionEntry.Value;
100  if (SectionRenderData.Contains(SectionEntry.Key) && Section.IsValid() && Section->ShouldRender() && Section->WantsToRenderInStaticPath())
101  {
102  const FRuntimeMeshSectionRenderData& RenderData = SectionRenderData[SectionEntry.Key];
103  FMaterialRenderProxy* Material = RenderData.Material->GetRenderProxy();
104 
105  FMeshBatch MeshBatch;
106  CreateMeshBatch(MeshBatch, Section, RenderData, Material, nullptr);
107  PDI->DrawMesh(MeshBatch, FLT_MAX);
108  }
109  }
110 }
111 
112 void FRuntimeMeshComponentSceneProxy::GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const
113 {
114  // Set up wireframe material (if needed)
115  const bool bWireframe = AllowDebugViewmodes() && ViewFamily.EngineShowFlags.Wireframe;
116 
117  FColoredMaterialRenderProxy* WireframeMaterialInstance = nullptr;
118  if (bWireframe)
119  {
120  WireframeMaterialInstance = new FColoredMaterialRenderProxy(
121  GEngine->WireframeMaterial ? GEngine->WireframeMaterial->GetRenderProxy() : nullptr,
122  FLinearColor(0, 0.5f, 1.f)
123  );
124 
125  Collector.RegisterOneFrameMaterialProxy(WireframeMaterialInstance);
126  }
127 
128  // Iterate over sections
129  for (const auto& SectionEntry : RuntimeMeshProxy->GetSections())
130  {
131  FRuntimeMeshSectionProxyPtr Section = SectionEntry.Value;
132  if (SectionRenderData.Contains(SectionEntry.Key) && Section.IsValid() && Section->ShouldRender())
133  {
134  // Add the mesh batch to every view it's visible in
135  for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
136  {
137  if (VisibilityMap & (1 << ViewIndex))
138  {
139  bool bForceDynamicPath = IsRichView(*Views[ViewIndex]->Family) || Views[ViewIndex]->Family->EngineShowFlags.Wireframe || IsSelected() || !IsStatic();
140 
141  if (bForceDynamicPath || !Section->WantsToRenderInStaticPath())
142  {
143  const FRuntimeMeshSectionRenderData& RenderData = SectionRenderData[SectionEntry.Key];
144  FMaterialRenderProxy* Material = RenderData.Material->GetRenderProxy();
145 
146  FMeshBatch& MeshBatch = Collector.AllocateMesh();
147  CreateMeshBatch(MeshBatch, Section, RenderData, Material, WireframeMaterialInstance);
148 
149  Collector.AddMesh(ViewIndex, MeshBatch);
150  }
151  }
152  }
153  }
154  }
155 
156  // Draw bounds
157 #if RUNTIMEMESH_ENABLE_DEBUG_RENDERING
158  for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
159  {
160  if (VisibilityMap & (1 << ViewIndex))
161  {
162  // Draw simple collision as wireframe if 'show collision', and collision is enabled, and we are not using the complex as the simple
163  if (ViewFamily.EngineShowFlags.Collision && IsCollisionEnabled() && BodySetup && BodySetup->GetCollisionTraceFlag() != ECollisionTraceFlag::CTF_UseComplexAsSimple)
164  {
165  FTransform GeomTransform(GetLocalToWorld());
166  BodySetup->AggGeom.GetAggGeom(GeomTransform, GetSelectionColor(FColor(157, 149, 223, 255), IsSelected(), IsHovered()).ToFColor(true), NULL, false, false, false /*UseEditorDepthTest()*/, ViewIndex, Collector);
167  }
168 
169  // Render bounds
170  RenderBounds(Collector.GetPDI(ViewIndex), ViewFamily.EngineShowFlags, GetBounds(), IsSelected());
171  }
172  }
173 #endif
174 }
virtual void GetDynamicMeshElements(const TArray< const FSceneView * > &Views, const FSceneViewFamily &ViewFamily, uint32 VisibilityMap, FMeshElementCollector &Collector) const override
TSharedPtr< FRuntimeMeshSectionProxy, ESPMode::NotThreadSafe > FRuntimeMeshSectionProxyPtr
GLdouble f
virtual void DrawStaticElements(FStaticPrimitiveDrawInterface *PDI) override
FRuntimeMeshComponentSceneProxy(URuntimeMeshComponent *Component)
static const textual_icon check
Definition: model-views.h:260
void CreateMeshBatch(FMeshBatch &MeshBatch, const FRuntimeMeshSectionProxyPtr &Section, const FRuntimeMeshSectionRenderData &RenderData, FMaterialRenderProxy *Material, FMaterialRenderProxy *WireframeMaterial) const
IMGUI_API bool IsHovered(const ImRect &bb, ImGuiID id, bool flatten_childs=false)
Definition: imgui.cpp:1878
TMap< int32, FRuntimeMeshSectionRenderData > SectionRenderData
virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView *View) const override
#define NULL
Definition: tinycthread.c:47


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41