123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /*******************************************************************************
- The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
- Technology released in source code form as part of the game integration package.
- The content of this file may not be used without valid licenses to the
- AUDIOKINETIC Wwise Technology.
- Note that the use of the game engine is subject to the Unreal(R) Engine End User
- License Agreement at https://www.unrealengine.com/en-US/eula/unreal
-
- License Usage
-
- Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
- this file in accordance with the end user license agreement provided with the
- software or, alternatively, in accordance with the terms contained
- in a written agreement between you and Audiokinetic Inc.
- Copyright (c) 2023 Audiokinetic Inc.
- *******************************************************************************/
- /*=============================================================================
- AkDrawRoomComponent.cpp:
- =============================================================================*/
- #include "AkDrawRoomComponent.h"
- #include "PrimitiveSceneProxy.h"
- #if WITH_EDITOR
- #include "AkRoomComponent.h"
- #include "AkSettingsPerUser.h"
- #include "AkSpatialAudioDrawUtils.h"
- #include "DynamicMeshBuilder.h"
- #include "SceneManagement.h"
- #endif // WITH_EDITOR
- 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;
- // Calculate the unscaled, unrotated box extent of the primitive parent component, at origin.
- FVector BoxExtent = PrimitiveParent->CalcBounds(FTransform()).BoxExtent;
- FLinearColor RoomColor = AkSpatialAudioColors::GetRoomColor();
- FTransform T = PrimitiveParent->GetComponentTransform();
- AkDrawBounds DrawBounds(T, BoxExtent);
- // Calculate the local room axis vectors
- FVector RoomAxisForward = DrawBounds.FRU() - DrawBounds.BRU();
- RoomAxisForward.Normalize();
- FVector RoomAxisRight = DrawBounds.RU() - DrawBounds.LU();
- RoomAxisRight.Normalize();
- FVector RoomAxisUp = DrawBounds.RU() - DrawBounds.RD();
- RoomAxisUp.Normalize();
- // Draw an icon representing the room's orientation.
- 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);
- }
- }
- /** Represents a Room to the scene manager.
- Based on FDrawFrustumSceneProxy (in DrawFrustrumComponent.cpp)
- */
- class FDrawRoomSceneProxy final : public FPrimitiveSceneProxy
- {
- public:
- /** Based on FDrawFrustumSceneProxy implementation */
- SIZE_T GetTypeHash() const override
- {
- static size_t UniquePointer;
- return reinterpret_cast<size_t>(&UniquePointer);
- }
- /**
- * Initialization constructor.
- * @param InComponent - game component to draw in the scene
- */
- FDrawRoomSceneProxy(const UDrawRoomComponent* InComponent)
- : FPrimitiveSceneProxy(InComponent)
- , RoomDrawer(InComponent)
- {}
- // FPrimitiveSceneProxy interface.
- virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override
- {
- if (GetDefault<UAkSettingsPerUser>()->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;
- }
- /** Based on FDrawFrustumSceneProxy implementation */
- 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 // WITH_EDITOR
|