-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPCGExClusterToZoneGraph.h
More file actions
212 lines (161 loc) · 6.88 KB
/
PCGExClusterToZoneGraph.h
File metadata and controls
212 lines (161 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright 2025 Timothé Lapetite and contributors
// Released under the MIT license https://opensource.org/license/MIT/
#pragma once
#include "CoreMinimal.h"
#include "ZoneGraphSettings.h"
#include "ZoneGraphTypes.h"
#include "Graph/PCGExChain.h"
#include "Graph/PCGExEdgesProcessor.h"
#include "Transform/PCGExTransform.h"
#include "ZoneShapeComponent.h"
#include "Graph/Filters/PCGExClusterFilter.h"
#include "PCGExClusterToZoneGraph.generated.h"
UCLASS(MinimalAPI, BlueprintType, ClassGroup = (Procedural), Category="PCGEx|Clusters")
class UPCGExClusterToZoneGraphSettings : public UPCGExEdgesProcessorSettings
{
GENERATED_BODY()
public:
#if WITH_EDITOR
UPCGExClusterToZoneGraphSettings(const FVTableHelper& Helper) {
if (const UZoneGraphSettings* ZoneGraphSettings = GetDefault<UZoneGraphSettings>())
{
if (const FZoneLaneProfile* NewLaneProfile = ZoneGraphSettings->GetDefaultLaneProfile())
{
LaneProfile = *NewLaneProfile;
}
}
}
#endif
//~Begin UPCGSettings
#if WITH_EDITOR
PCGEX_NODE_INFOS(ClusterToZoneGraph, "Cluster to Zone Graph", "Create Zone Graph from clusters.");
virtual FLinearColor GetNodeTitleColor() const override { return GetDefault<UPCGExGlobalSettings>()->NodeColorCluster; }
#endif
protected:
virtual FPCGElementPtr CreateElement() const override;
//~End UPCGSettings
//~Begin UPCGExPointsProcessorSettings
public:
virtual bool SupportsEdgeSorting() const override { return DirectionSettings.RequiresSortingRules(); }
virtual PCGExData::EIOInit GetMainOutputInitMode() const override;
virtual PCGExData::EIOInit GetEdgeOutputInitMode() const override;
PCGEX_NODE_POINT_FILTER(FName("Break Conditions"), "Filters used to know which points are 'break' points. Use those if you want to create more polygon shapes.", PCGExFactories::ClusterNodeFilters, false)
//~End UPCGExPointsProcessorSettings
/** Defines the direction in which points will be ordered to form the final paths. */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable))
FPCGExEdgeDirectionSettings DirectionSettings;
/** Comma separated tags */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable))
FString CommaSeparatedComponentTags = TEXT("PCGExZoneGraph");
/** Specify a list of functions to be called on the target actor after dynamic mesh creation. Functions need to be parameter-less and with "CallInEditor" flag enabled. */
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
TArray<FName> PostProcessFunctionNames;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
FPCGExAttachmentRules AttachmentRules;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
double PolygonRadius = 100;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
EZoneShapePolygonRoutingType PolygonRoutingType = EZoneShapePolygonRoutingType::Arcs;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
FZoneShapePointType PolygonPointType = FZoneShapePointType::LaneProfile;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings)
FZoneShapePointType RoadPointType = FZoneShapePointType::LaneProfile;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings|Intersections")
FZoneGraphTagMask AdditionalIntersectionTags = FZoneGraphTagMask::None;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings")
FZoneLaneProfileRef LaneProfile;
private:
friend class FPCGExClusterToZoneGraphElement;
};
struct FPCGExClusterToZoneGraphContext final : FPCGExEdgesProcessorContext
{
friend class FPCGExClusterToZoneGraphElement;
TArray<TSharedPtr<PCGExCluster::FNodeChain>> Chains;
TArray<FString> ComponentTags;
};
class FPCGExClusterToZoneGraphElement final : public FPCGExEdgesProcessorElement
{
protected:
PCGEX_ELEMENT_CREATE_CONTEXT(ClusterToZoneGraph)
virtual bool Boot(FPCGExContext* InContext) const override;
virtual bool ExecuteInternal(FPCGContext* InContext) const override;
virtual bool CanExecuteOnlyOnMainThread(FPCGContext* Context) const override { return true; }
};
namespace PCGExClusterToZoneGraph
{
class FProcessor;
class FZGBase : public TSharedFromThis<FZGBase>
{
protected:
TSharedPtr<FProcessor> Processor;
public:
UZoneShapeComponent* Component = nullptr;
double StartRadius = 0;
double EndRadius = 0;
explicit FZGBase(const TSharedPtr<FProcessor>& InProcessor);
void InitComponent(AActor* InTargetActor);
};
class FZGRoad : public FZGBase
{
public:
TSharedPtr<PCGExCluster::FNodeChain> Chain;
bool bIsReversed = false;
explicit FZGRoad(const TSharedPtr<FProcessor>& InProcessor, const TSharedPtr<PCGExCluster::FNodeChain>& InChain, const bool InReverse);
void Compile(const TSharedPtr<PCGExCluster::FCluster>& Cluster);
};
class FZGPolygon : public FZGBase
{
protected:
TArray<TSharedPtr<FZGRoad>> Roads;
TBitArray<> FromStart;
public:
int32 NodeIndex = -1;
explicit FZGPolygon(const TSharedPtr<FProcessor>& InProcessor, const PCGExCluster::FNode* InNode);
void Add(const TSharedPtr<FZGRoad>& InRoad, bool bFromStart);
void Compile(const TSharedPtr<PCGExCluster::FCluster>& Cluster);
};
class FProcessor final : public PCGExClusterMT::TProcessor<FPCGExClusterToZoneGraphContext, UPCGExClusterToZoneGraphSettings>
{
friend class FBatch;
protected:
FPCGExEdgeDirectionSettings DirectionSettings;
TWeakPtr<PCGExMT::FAsyncToken> MainThreadToken;
TSharedPtr<TArray<FVector2D>> ProjectedPositions;
TSharedPtr<PCGExCluster::FNodeChainBuilder> ChainBuilder;
TArray<TSharedPtr<FZGRoad>> Roads;
TArray<TSharedPtr<FZGPolygon>> Polygons;
TArray<UZoneShapeComponent> RoadComponents;
TArray<UZoneShapeComponent> PolygonsComponents;
public:
FProcessor(const TSharedRef<PCGExData::FFacade>& InVtxDataFacade, const TSharedRef<PCGExData::FFacade>& InEdgeDataFacade):
TProcessor(InVtxDataFacade, InEdgeDataFacade)
{
}
virtual bool IsTrivial() const override { return false; }
virtual bool Process(TSharedPtr<PCGExMT::FTaskManager> InAsyncManager) override;
bool BuildChains();
virtual void CompleteWork() override;
void InitComponents();
void OnPolygonsCompilationComplete();
virtual void ProcessRange(const PCGExMT::FScope& Scope) override;
virtual void OnRangeProcessingComplete() override;
virtual void Output() override;
virtual void Cleanup() override;
};
class FBatch final : public PCGExClusterMT::TBatch<FProcessor>
{
friend class FProcessor;
protected:
TSharedPtr<TArray<int8>> Breakpoints;
FPCGExEdgeDirectionSettings DirectionSettings;
public:
FBatch(FPCGExContext* InContext, const TSharedRef<PCGExData::FPointIO>& InVtx, const TArrayView<TSharedRef<PCGExData::FPointIO>> InEdges):
TBatch(InContext, InVtx, InEdges)
{
bAllowVtxDataFacadeScopedGet = true;
DefaultVtxFilterValue = false;
}
virtual void RegisterBuffersDependencies(PCGExData::FFacadePreloader& FacadePreloader) override;
virtual void OnProcessingPreparationComplete() override;
};
}