// Copyright Epic Games, Inc. All Rights Reserved. #include "Dataflow/GeometryCollectionUtils.h" #include "GeometryCollection/GeometryCollectionAlgo.h" namespace UE::Dataflow { namespace Utils { #if WITH_EDITOR void DebugDrawProximity(IDataflowDebugDrawInterface& DataflowRenderingInterface, const FManagedArrayCollection& Collection, const FLinearColor Color, const float LineWidthMultiplier, const float CenterSize, const FLinearColor CenterColor, const bool bRandomizeColor, const int32 ColorRandomSeed) { DataflowRenderingInterface.SetLineWidth(LineWidthMultiplier); DataflowRenderingInterface.SetWireframe(true); DataflowRenderingInterface.SetWorldPriority(); DataflowRenderingInterface.SetPointSize(CenterSize); if (Collection.HasAttribute("Proximity", FGeometryCollection::GeometryGroup) && Collection.HasAttribute("BoundingBox", FGeometryCollection::GeometryGroup)) { const TManagedArray>& Proximity = Collection.GetAttribute>("Proximity", FGeometryCollection::GeometryGroup); const TManagedArray& BoundingBox = Collection.GetAttribute("BoundingBox", FGeometryCollection::GeometryGroup); const TManagedArray* Transform = Collection.FindAttributeTyped(FGeometryCollection::TransformAttribute, FGeometryCollection::TransformGroup); const TManagedArray* Parent = Collection.FindAttributeTyped(FGeometryCollection::ParentAttribute, FGeometryCollection::TransformGroup); const TManagedArray* TransformIndex = Collection.FindAttributeTyped(FGeometryCollection::TransformIndexAttribute, FGeometryCollection::GeometryGroup); TArray GlobalTransformArray; if (Transform && Parent && TransformIndex) { GeometryCollectionAlgo::GlobalMatrices(*Transform, *Parent, GlobalTransformArray); } auto TransformFromGeometry = [&GlobalTransformArray, &TransformIndex](int32 GeometryIdx, FVector Point) -> FVector { if (GlobalTransformArray.IsEmpty() || !TransformIndex || !TransformIndex->IsValidIndex(GeometryIdx)) { return Point; } else { return GlobalTransformArray[(*TransformIndex)[GeometryIdx]].TransformPosition(Point); } }; const int32 NumGeometry = Collection.NumElements(FGeometryCollection::GeometryGroup); TArray Centers; for (int32 Idx = 0; Idx < NumGeometry; ++Idx) { if (Proximity[Idx].Num() > 0) { const FVector Center = TransformFromGeometry(Idx, BoundingBox[Idx].GetCenter()); Centers.Add(Center); if (bRandomizeColor) { DataflowRenderingInterface.SetColor(UE::Dataflow::Color::GetRandomColor(ColorRandomSeed + 17, Idx)); } else { DataflowRenderingInterface.SetColor(Color); } for (int32 IdxOther : Proximity[Idx]) { const FVector CenterOther = TransformFromGeometry(IdxOther, BoundingBox[IdxOther].GetCenter()); DataflowRenderingInterface.DrawLine(Center, CenterOther); } DataflowRenderingInterface.SetPointSize(CenterSize); DataflowRenderingInterface.SetColor(CenterColor); for (FVector& Point : Centers) { DataflowRenderingInterface.DrawPoint(Point); } Centers.Reset(); } } } } #endif } }