123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #include "AkDrawRoomComponent.h"
- #include "PrimitiveSceneProxy.h"
- #if WITH_EDITOR
- #include "AkRoomComponent.h"
- #include "AkSettingsPerUser.h"
- #include "AkSpatialAudioDrawUtils.h"
- #include "DynamicMeshBuilder.h"
- #include "SceneManagement.h"
- #include "AkSettings.h"
- #endif
- UDrawRoomComponent::UDrawRoomComponent(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- }
- #if WITH_EDITOR
- const UAkRoomComponent* UDrawRoomComponent::GetRoomParent() const
- {
- return Cast<UAkRoomComponent>(GetAttachParent());
- }
- void UDrawRoomComponent::DrawRoom(const FSceneView* View, FPrimitiveDrawInterface* PDI, FMeshElementCollector& Collector, int32 ViewIndex) const
- {
- const UAkRoomComponent* RoomComponent = GetRoomParent();
- if (IsValid(RoomComponent) && IsValid(RoomComponent->GetPrimitiveParent()) && RoomComponent->bEnable)
- {
- const UPrimitiveComponent* PrimitiveParent = Cast<UPrimitiveComponent>(RoomComponent->GetPrimitiveParent());
- if (PrimitiveParent == nullptr)
- return;
-
- FVector BoxExtent = PrimitiveParent->CalcBounds(FTransform()).BoxExtent;
- FLinearColor RoomColor = AkSpatialAudioColors::GetRoomColor();
- FTransform T = PrimitiveParent->GetComponentTransform();
- AkDrawBounds DrawBounds(T, BoxExtent);
-
- FVector RoomAxisForward = DrawBounds.FRU() - DrawBounds.BRU();
- RoomAxisForward.Normalize();
- FVector RoomAxisRight = DrawBounds.RU() - DrawBounds.LU();
- RoomAxisRight.Normalize();
- FVector RoomAxisUp = DrawBounds.RU() - DrawBounds.RD();
- RoomAxisUp.Normalize();
-
- float Radius = AkDrawConstants::RoomIconRadius;
- float IconThickness = AkDrawConstants::RoomIconThickness;
- int Sides = AkDrawConstants::RoomIconSides;
- FVector RoomCentre = T.TransformPosition(FVector::ZeroVector);
- DrawCircle(PDI, RoomCentre, RoomAxisForward, RoomAxisRight, RoomColor, Radius, Sides, SDPG_MAX, IconThickness);
- DrawCircle(PDI, RoomCentre, RoomAxisForward, RoomAxisUp, RoomColor, Radius, Sides, SDPG_MAX, IconThickness);
- float AxisLength = AkDrawConstants::RoomAxisLength;
- PDI->DrawLine(RoomCentre, RoomCentre + RoomAxisForward * AxisLength, RoomColor, SDPG_MAX, AkDrawConstants::RoomAxisThickness);
- PDI->DrawLine(RoomCentre, RoomCentre + RoomAxisRight * AxisLength, RoomColor, SDPG_MAX, AkDrawConstants::RoomAxisThickness);
- PDI->DrawLine(RoomCentre, RoomCentre + RoomAxisUp * AxisLength, RoomColor, SDPG_MAX, AkDrawConstants::RoomAxisThickness);
- }
- }
- class FDrawRoomSceneProxy final : public FPrimitiveSceneProxy
- {
- public:
-
- SIZE_T GetTypeHash() const override
- {
- static size_t UniquePointer;
- return reinterpret_cast<size_t>(&UniquePointer);
- }
-
- FDrawRoomSceneProxy(const UDrawRoomComponent* InComponent)
- : FPrimitiveSceneProxy(InComponent)
- , RoomDrawer(InComponent)
- {}
-
- virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
- {
- if (GetDefault<UAkSettings>()->VisualizeRoomsAndPortals)
- {
- if (RoomDrawer != nullptr)
- {
- for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
- {
- if (VisibilityMap & (1 << ViewIndex))
- {
- FPrimitiveDrawInterface* PDI = Collector.GetPDI(ViewIndex);
- const FSceneView* View = Views[ViewIndex];
- RoomDrawer->DrawRoom(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 UDrawRoomComponent* RoomDrawer;
- };
- FPrimitiveSceneProxy* UDrawRoomComponent::CreateSceneProxy()
- {
- return new FDrawRoomSceneProxy(this);
- }
- FBoxSphereBounds UDrawRoomComponent::CalcBounds(const FTransform& LocalToWorld) const
- {
- return FBoxSphereBounds(LocalToWorld.TransformPosition(FVector::ZeroVector), FVector(AkDrawConstants::CullDepth), AkDrawConstants::CullDepth);
- }
- #endif
|