123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "AkAcousticPortalVisualizer.h"
- #include "AkUEFeatures.h"
- #include "AkSpatialAudioDrawUtils.h"
- #include "AkDrawPortalComponent.h"
- #include "AkRoomComponent.h"
- #include "SceneManagement.h"
- #include "DynamicMeshBuilder.h"
- #include "EditorModes.h"
- #include "Materials/Material.h"
- void UAkPortalComponentVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI)
- {
- const UAkPortalComponent* PortalComponent = Cast<UAkPortalComponent>(Component);
- if (IsValid(PortalComponent) && IsValid(PortalComponent->GetPrimitiveParent()))
- {
- const UPrimitiveComponent* PrimitiveParent = Cast<UPrimitiveComponent>(PortalComponent->GetPrimitiveParent());
-
- FVector BoxExtent = PrimitiveParent->CalcLocalBounds().BoxExtent;
- FDynamicMeshBuilder MeshBuilderFront(ERHIFeatureLevel::Type::ES3_1);
- FDynamicMeshBuilder MeshBuilderBack(ERHIFeatureLevel::Type::ES3_1);
- MeshBuilderFront.AddVertices({
- FUnrealFloatVector(BoxExtent),
- FUnrealFloatVector(BoxExtent.X, BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, BoxExtent.Y, BoxExtent.Z),
- FUnrealFloatVector(BoxExtent.X, -BoxExtent.Y, BoxExtent.Z),
- FUnrealFloatVector(BoxExtent.X, -BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, -BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, -BoxExtent.Y, BoxExtent.Z)
- });
- MeshBuilderBack.AddVertices({
- FUnrealFloatVector(-BoxExtent.X, -BoxExtent.Y, BoxExtent.Z),
- FUnrealFloatVector(-BoxExtent),
- FUnrealFloatVector(0.0f, -BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, -BoxExtent.Y, BoxExtent.Z),
- FUnrealFloatVector(-BoxExtent.X, BoxExtent.Y, BoxExtent.Z),
- FUnrealFloatVector(-BoxExtent.X, BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, BoxExtent.Y, -BoxExtent.Z),
- FUnrealFloatVector(0.0f, BoxExtent.Y, BoxExtent.Z)
- });
-
- MeshBuilderFront.AddTriangles
- ({
- 0, 3, 2, 0, 2, 1,
- 4, 7, 6, 4, 6, 5,
- 0, 3, 7, 0, 7, 4,
- 1, 2, 6, 1, 6, 5
- });
- MeshBuilderBack.AddTriangles
- ({
- 0, 3, 2, 0, 2, 1,
- 4, 7, 6, 4, 6, 5,
- 0, 3, 7, 0, 7, 4,
- 1, 2, 6, 1, 6, 5
- });
-
- auto* renderProxy = GEngine->GeomMaterial->GetRenderProxy();
- FLinearColor FrontDrawColor;
- FLinearColor BackDrawColor;
- AkSpatialAudioColors::GetPortalColors(PortalComponent, FrontDrawColor, BackDrawColor);
- FDynamicColoredMaterialRenderProxy* ColorInstanceFront = new FDynamicColoredMaterialRenderProxy(renderProxy, FrontDrawColor);
- PDI->RegisterDynamicResource(ColorInstanceFront);
- MeshBuilderFront.Draw(PDI, PrimitiveParent->GetComponentToWorld().ToMatrixWithScale(), ColorInstanceFront, SDPG_World, true, false);
- FDynamicColoredMaterialRenderProxy* ColorInstanceBack = new FDynamicColoredMaterialRenderProxy(renderProxy, BackDrawColor);
- PDI->RegisterDynamicResource(ColorInstanceBack);
- MeshBuilderBack.Draw(PDI, PrimitiveParent->GetComponentToWorld().ToMatrixWithScale(), ColorInstanceBack, SDPG_World, true, false);
-
- const FTransform& T = PrimitiveParent->GetComponentTransform();
- AkDrawBounds DrawBounds(T, BoxExtent);
- const float Thickness = AkDrawConstants::PortalRoomConnectionThickness;
- const FLinearColor OutlineColor = AkSpatialAudioColors::GetPortalOutlineColor(PortalComponent);
- PDI->DrawLine(DrawBounds.RU(), DrawBounds.LU(), OutlineColor, SDPG_Foreground, Thickness);
- PDI->DrawLine(DrawBounds.LU(), DrawBounds.LD(), OutlineColor, SDPG_Foreground, Thickness);
- PDI->DrawLine(DrawBounds.LD(), DrawBounds.RD(), OutlineColor, SDPG_Foreground, Thickness);
- PDI->DrawLine(DrawBounds.RD(), DrawBounds.RU(), OutlineColor, SDPG_Foreground, Thickness);
-
- FVector Front = FVector(BoxExtent.X, 0.0f, 0.0f);
- FVector Back = FVector(-BoxExtent.X, 0.0f, 0.0f);
- PDI->DrawLine(T.TransformPosition(Back), T.TransformPosition(Front), OutlineColor, SDPG_Foreground, Thickness);
-
- if (PortalComponent->InitialState == AkAcousticPortalState::Closed)
- {
- PDI->DrawLine(DrawBounds.FRU(), DrawBounds.BRD(), FrontDrawColor, SDPG_Foreground, Thickness);
- PDI->DrawLine(DrawBounds.FLD(), DrawBounds.BLU(), BackDrawColor, SDPG_Foreground, Thickness);
- }
- PortalComponent->UpdateTextRotations();
- }
- if (GEditor->GetSelectedActorCount() == 1 && IsValid(PortalComponent))
- {
- AAkAcousticPortal* pPortal = Cast<AAkAcousticPortal>(PortalComponent->GetOwner());
- if (pPortal && pPortal->GetFitToGeometry() && pPortal->GetIsDragging())
- {
- FVector Point0, End0, Point1, End1;
- if (pPortal->GetBestHits(Point0, End0, Point1, End1))
- {
- FVector Dir0 = End0 - Point0;
- float L0 = Dir0.SizeSquared();
- FVector Dir1 = End1 - Point1;
- float L1 = Dir1.SizeSquared();
- FVector V01 = Point1 - Point0;
- FVector TL0 = Point1 - FVector::DotProduct(V01, Dir0) * Dir0 / L0;
- FVector TL1 = Point0 - FVector::DotProduct(-V01, Dir1) * Dir1 / L1;
- FVector TL = (TL0 + TL1) / 2.f;
- FVector TR = TL + Dir0;
- FVector BL = TL + Dir1;
- FVector BR = BL + Dir0;
- const FLinearColor PreviewColor = FAkAppStyle::Get().GetSlateColor("SelectionColor").GetSpecifiedColor() * 1.3f;
- PDI->DrawLine(TL, TR, PreviewColor, 100, 5.f, 50.f);
- PDI->DrawLine(TR, BR, PreviewColor, 100, 5.f, 50.f);
- PDI->DrawLine(BR, BL, PreviewColor, 100, 5.f, 50.f);
- PDI->DrawLine(BL, TL, PreviewColor, 100, 5.f, 50.f);
- }
- }
- }
- }
|