123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #include "AkDrawPortalComponent.h"
- #include "PrimitiveSceneProxy.h"
- #if WITH_EDITOR
- #include "DynamicMeshBuilder.h"
- #include "AkRoomComponent.h"
- #include "AkSpatialAudioDrawUtils.h"
- #include "AkSettings.h"
- #endif
- UDrawPortalComponent::UDrawPortalComponent(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- }
- #if WITH_EDITOR
- const UAkPortalComponent* UDrawPortalComponent::GetPortalParent() const
- {
- return Cast<UAkPortalComponent>(GetAttachParent());
- }
- void UDrawPortalComponent::DrawPortalOutline(const FSceneView* View, FPrimitiveDrawInterface* PDI, FMeshElementCollector& Collector, int32 ViewIndex) const
- {
- const UAkPortalComponent* PortalComponent = GetPortalParent();
- if (IsValid(PortalComponent) && IsValid(PortalComponent->GetPrimitiveParent()))
- {
- const UPrimitiveComponent* PrimitiveParent = Cast<UPrimitiveComponent>(PortalComponent->GetPrimitiveParent());
- if (PrimitiveParent == nullptr)
- return;
-
- FVector BoxExtent = PrimitiveParent->CalcBounds(FTransform()).BoxExtent;
- FLinearColor FrontDrawColor;
- FLinearColor BackDrawColor;
- AkSpatialAudioColors::GetPortalColors(PortalComponent, FrontDrawColor, BackDrawColor);
- FLinearColor OutlineColor = AkSpatialAudioColors::GetPortalOutlineColor(PortalComponent);
- float Thickness = AkDrawConstants::PortalOutlineThickness;
- FTransform T = PrimitiveParent->GetComponentTransform();
- AkDrawBounds DrawBounds(T, BoxExtent);
-
- PDI->DrawLine(DrawBounds.RU(), DrawBounds.FRU(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FRU(), DrawBounds.FRD(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FRD(), DrawBounds.RD(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.LU(), DrawBounds.FLU(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FLU(), DrawBounds.FLD(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FLD(), DrawBounds.LD(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FRU(), DrawBounds.FLU(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FRD(), DrawBounds.FLD(), FrontDrawColor, SDPG_MAX, Thickness);
-
- PDI->DrawLine(DrawBounds.RU(), DrawBounds.BRU(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BRU(), DrawBounds.BRD(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BRD(), DrawBounds.RD(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.LU(), DrawBounds.BLU(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BLU(), DrawBounds.BLD(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BLD(), DrawBounds.LD(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BLU(), DrawBounds.BRU(), BackDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.BLD(), DrawBounds.BRD(), BackDrawColor, SDPG_MAX, Thickness);
-
- PDI->DrawLine(DrawBounds.LU(), DrawBounds.LD(), OutlineColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.LD(), DrawBounds.RD(), OutlineColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.RD(), DrawBounds.RU(), OutlineColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.RU(), DrawBounds.LU(), OutlineColor, SDPG_MAX, Thickness);
- UWorld* world = GetWorld();
- if (world != nullptr)
- {
- EWorldType::Type worldType = world->WorldType;
- if ((!(worldType == EWorldType::Game || worldType == EWorldType::PIE) && PortalComponent->InitialState == AkAcousticPortalState::Closed) ||
- ((worldType == EWorldType::Game || worldType == EWorldType::PIE) && PortalComponent->GetCurrentState() == AkAcousticPortalState::Closed))
- {
- PDI->DrawLine(DrawBounds.FRU(), DrawBounds.BRD(), FrontDrawColor, SDPG_MAX, Thickness);
- PDI->DrawLine(DrawBounds.FLD(), DrawBounds.BLU(), BackDrawColor, SDPG_MAX, Thickness);
- }
- }
- Thickness = AkDrawConstants::PortalRoomConnectionThickness;
- FVector FrontPoint = FVector(BoxExtent.X, 0.0f, 0.0f);
- FVector BackPoint = FVector(-BoxExtent.X, 0.0f, 0.0f);
- if (PortalComponent->GetFrontRoomComponent() != nullptr && PortalComponent->GetFrontRoomComponent()->GetPrimitiveParent() != nullptr)
- {
-
- FVector Front = PrimitiveParent->GetComponentTransform().TransformVector(FVector(1.0f, 0.0f, 0.0f));
- FVector From = PrimitiveParent->GetComponentTransform().TransformPosition(FrontPoint);
- FVector To = PortalComponent->GetFrontRoomComponent()->GetPrimitiveParent()->GetComponentTransform().TransformPosition(FVector(0.0f, 0.0f, 0.0f));
-
- FVector ToRoom = To - From;
- ToRoom.Normalize();
- PDI->DrawLine(From, To, OutlineColor, SDPG_MAX, Thickness);
- }
- Thickness = AkDrawConstants::PortalRoomConnectionThickness;
- if (PortalComponent->GetBackRoomComponent() != nullptr && PortalComponent->GetBackRoomComponent()->GetPrimitiveParent() != nullptr)
- {
-
- FVector Back = PrimitiveParent->GetComponentTransform().TransformVector(FVector(-1.0f, 0.0f, 0.0f));
- FVector From = PrimitiveParent->GetComponentTransform().TransformPosition(BackPoint);
- FVector To = PortalComponent->GetBackRoomComponent()->GetPrimitiveParent()->GetComponentTransform().TransformPosition(FVector(0.0f, 0.0f, 0.0f));
-
- FVector ToRoom = To - From;
- ToRoom.Normalize();
- PDI->DrawLine(From, To, OutlineColor, SDPG_MAX, Thickness);
- }
- }
- }
- class FDrawPortalSceneProxy final : public FPrimitiveSceneProxy
- {
- public:
-
- SIZE_T GetTypeHash() const override
- {
- static size_t UniquePointer;
- return reinterpret_cast<size_t>(&UniquePointer);
- }
-
- FDrawPortalSceneProxy(const UDrawPortalComponent* InComponent)
- : FPrimitiveSceneProxy(InComponent)
- , PortalDrawer(InComponent)
- {}
-
- virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
- {
- if (GetDefault<UAkSettings>()->VisualizeRoomsAndPortals)
- {
- if (PortalDrawer != nullptr)
- {
- for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
- {
- if (VisibilityMap & (1 << ViewIndex))
- {
- FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
- const FSceneView* View = Views[ViewIndex];
- PortalDrawer->DrawPortalOutline(View, PDI, Collector, ViewIndex);
- }
- }
- }
- }
- }
- virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override
- {
- FPrimitiveViewRelevance Result;
- Result.bDrawRelevance = IsShown(View);
- Result.bDynamicRelevance = true;
- Result.bStaticRelevance = true;
- Result.bEditorNoDepthTestPrimitiveRelevance = true;
- return Result;
- }
-
- virtual uint32 GetMemoryFootprint(void) const override { return(sizeof(*this) + GetAllocatedSize()); }
- uint32 GetAllocatedSize(void) const { return(FPrimitiveSceneProxy::GetAllocatedSize()); }
- private:
- const UDrawPortalComponent* PortalDrawer;
- };
- FPrimitiveSceneProxy* UDrawPortalComponent::CreateSceneProxy()
- {
- return new FDrawPortalSceneProxy(this);
- }
- FBoxSphereBounds UDrawPortalComponent::CalcBounds(const FTransform& LocalToWorld) const
- {
- return FBoxSphereBounds(LocalToWorld.TransformPosition(FVector::ZeroVector), FVector(AkDrawConstants::CullDepth), AkDrawConstants::CullDepth);
- }
- #endif
|