|
9 | 9 | #define LOCTEXT_NAMESPACE "PCGExPathAlphaFilterDefinition" |
10 | 10 | #define PCGEX_NAMESPACE PCGExPathAlphaFilterDefinition |
11 | 11 |
|
12 | | -bool UPCGExPathAlphaFilterFactory::SupportsProxyEvaluation() const |
13 | | -{ |
14 | | - return Config.CompareAgainst == EPCGExInputValueType::Constant; |
15 | | -} |
16 | | - |
17 | | -bool UPCGExPathAlphaFilterFactory::WantsPreparation(FPCGExContext* InContext) |
18 | | -{ |
19 | | - return true; |
20 | | -} |
21 | | - |
22 | | -PCGExFactories::EPreparationResult UPCGExPathAlphaFilterFactory::Prepare(FPCGExContext* InContext, const TSharedPtr<PCGExMT::FTaskManager>& AsyncManager) |
23 | | -{ |
24 | | - PCGExFactories::EPreparationResult Result = Super::Prepare(InContext, AsyncManager); |
25 | | - if (Result != PCGExFactories::EPreparationResult::Success) { return Result; } |
26 | | - |
27 | | - Splines = MakeShared<TArray<TSharedPtr<FPCGSplineStruct>>>(); |
28 | | - |
29 | | - if (TArray<FPCGTaggedData> Targets = InContext->InputData.GetInputsByPin(PCGExPaths::SourcePathsLabel); |
30 | | - !Targets.IsEmpty()) |
31 | | - { |
32 | | - for (const FPCGTaggedData& TaggedData : Targets) |
33 | | - { |
34 | | - const UPCGBasePointData* PathData = Cast<UPCGBasePointData>(TaggedData.Data); |
35 | | - if (!PathData) { continue; } |
36 | | - |
37 | | - const bool bIsClosedLoop = PCGExPaths::GetClosedLoop(PathData); |
38 | | - if (Config.SampleInputs == EPCGExSplineSamplingIncludeMode::ClosedLoopOnly && !bIsClosedLoop) { continue; } |
39 | | - if (Config.SampleInputs == EPCGExSplineSamplingIncludeMode::OpenSplineOnly && bIsClosedLoop) { continue; } |
40 | | - |
41 | | - if (TSharedPtr<FPCGSplineStruct> SplineStruct = PCGExPaths::MakeSplineFromPoints(PathData->GetConstTransformValueRange(), Config.PointType, bIsClosedLoop, true)) |
42 | | - { |
43 | | - Splines->Add(SplineStruct); |
44 | | - } |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - if (Splines->IsEmpty()) |
49 | | - { |
50 | | - PCGE_LOG_C(Error, GraphAndLog, InContext, FTEXT("No splines (no input matches criteria or empty dataset)")); |
51 | | - return PCGExFactories::EPreparationResult::MissingData; |
52 | | - } |
53 | | - |
54 | | - return Result; |
55 | | -} |
56 | | - |
57 | | -TSharedPtr<PCGExPointFilter::IFilter> UPCGExPathAlphaFilterFactory::CreateFilter() const |
58 | | -{ |
59 | | - return MakeShared<PCGExPointFilter::FPathAlphaFilter>(this); |
60 | | -} |
61 | | - |
62 | | -void UPCGExPathAlphaFilterFactory::BeginDestroy() |
63 | | -{ |
64 | | - Splines.Reset(); |
65 | | - SegmentsNum.Reset(); |
66 | | - Super::BeginDestroy(); |
67 | | -} |
68 | | - |
69 | | -bool UPCGExPathAlphaFilterFactory::RegisterConsumableAttributesWithData(FPCGExContext* InContext, const UPCGData* InData) const |
70 | | -{ |
71 | | - if (!Super::RegisterConsumableAttributesWithData(InContext, InData)) { return false; } |
72 | | - |
73 | | - FName Consumable = NAME_None; |
74 | | - PCGEX_CONSUMABLE_CONDITIONAL(Config.CompareAgainst == EPCGExInputValueType::Attribute, Config.OperandB, Consumable) |
75 | | - |
76 | | - return true; |
77 | | -} |
78 | | - |
79 | | -namespace PCGExPointFilter |
80 | | -{ |
81 | | - bool FPathAlphaFilter::Init(FPCGExContext* InContext, const TSharedPtr<PCGExData::FFacade>& InPointDataFacade) |
82 | | - { |
83 | | - if (!IFilter::Init(InContext, InPointDataFacade)) { return false; } |
84 | | - |
85 | | - OperandB = TypedFilterFactory->Config.GetValueSettingOperandB(); |
86 | | - if (!OperandB->Init(PointDataFacade)) { return false; } |
87 | | - |
88 | | - InTransforms = InPointDataFacade->GetIn()->GetConstTransformValueRange(); |
89 | | - |
90 | | - return true; |
91 | | - } |
92 | | - |
93 | | - bool FPathAlphaFilter::Test(const PCGExData::FProxyPoint& Point) const |
94 | | - { |
95 | | - const TArray<TSharedPtr<FPCGSplineStruct>>& SplinesRef = *Splines.Get(); |
96 | | - const TArray<double>& SegmentsNumRef = *SegmentsNum.Get(); |
97 | | - |
98 | | - const FVector Pos = Point.Transform.GetLocation(); |
99 | | - double Time = 0; |
100 | | - |
101 | | - if (TypedFilterFactory->Config.TimeConsolidation == EPCGExSplineTimeConsolidation::Min) { Time = MAX_dbl; } |
102 | | - |
103 | | - if (TypedFilterFactory->Config.Pick == EPCGExSplineFilterPick::Closest) |
104 | | - { |
105 | | - double ClosestDist = MAX_dbl; |
106 | | - for (int i = 0; i < Splines->Num(); i++) |
107 | | - { |
108 | | - const TSharedPtr<const FPCGSplineStruct> Spline = SplinesRef[i]; |
109 | | - |
110 | | - double LocalTime = Spline->FindInputKeyClosestToWorldLocation(Pos); |
111 | | - FTransform T = Spline->GetTransformAtSplineInputKey(static_cast<float>(LocalTime), ESplineCoordinateSpace::World, true); |
112 | | - LocalTime /= SegmentsNumRef[i]; |
113 | | - |
114 | | - const double D = FVector::DistSquared(T.GetLocation(), Pos); |
115 | | - |
116 | | - if (D > ClosestDist) { continue; } |
117 | | - |
118 | | - Time = LocalTime; |
119 | | - } |
120 | | - } |
121 | | - else |
122 | | - { |
123 | | - for (int i = 0; i < Splines->Num(); i++) |
124 | | - { |
125 | | - const TSharedPtr<const FPCGSplineStruct> Spline = SplinesRef[i]; |
126 | | - |
127 | | - double LocalTime = Spline->FindInputKeyClosestToWorldLocation(Pos); |
128 | | - LocalTime /= SegmentsNumRef[i]; |
129 | | - |
130 | | - switch (TypedFilterFactory->Config.TimeConsolidation) |
131 | | - { |
132 | | - case EPCGExSplineTimeConsolidation::Min: |
133 | | - Time = FMath::Min(LocalTime, Time); |
134 | | - break; |
135 | | - case EPCGExSplineTimeConsolidation::Max: |
136 | | - Time = FMath::Max(LocalTime, Time); |
137 | | - break; |
138 | | - case EPCGExSplineTimeConsolidation::Average: |
139 | | - Time += LocalTime; |
140 | | - break; |
141 | | - } |
142 | | - } |
143 | | - |
144 | | - if (TypedFilterFactory->Config.TimeConsolidation == EPCGExSplineTimeConsolidation::Average) |
145 | | - { |
146 | | - Time /= SegmentsNumRef.Num(); |
147 | | - } |
148 | | - } |
149 | | - |
150 | | - return PCGExCompare::Compare(TypedFilterFactory->Config.Comparison, Time, TypedFilterFactory->Config.OperandBConstant, TypedFilterFactory->Config.Tolerance); |
151 | | - } |
152 | | - |
153 | | - bool FPathAlphaFilter::Test(const int32 PointIndex) const |
154 | | - { |
155 | | - const TArray<TSharedPtr<FPCGSplineStruct>>& SplinesRef = *Splines.Get(); |
156 | | - const TArray<double>& SegmentsNumRef = *SegmentsNum.Get(); |
157 | | - |
158 | | - const FVector Pos = InTransforms[PointIndex].GetLocation(); |
159 | | - double Time = 0; |
160 | | - |
161 | | - if (TypedFilterFactory->Config.TimeConsolidation == EPCGExSplineTimeConsolidation::Min) { Time = MAX_dbl; } |
162 | | - |
163 | | - if (TypedFilterFactory->Config.Pick == EPCGExSplineFilterPick::Closest) |
164 | | - { |
165 | | - double ClosestDist = MAX_dbl; |
166 | | - for (int i = 0; i < Splines->Num(); i++) |
167 | | - { |
168 | | - const TSharedPtr<const FPCGSplineStruct> Spline = SplinesRef[i]; |
169 | | - |
170 | | - double LocalTime = Spline->FindInputKeyClosestToWorldLocation(Pos); |
171 | | - FTransform T = Spline->GetTransformAtSplineInputKey(static_cast<float>(LocalTime), ESplineCoordinateSpace::World, true); |
172 | | - LocalTime /= SegmentsNumRef[i]; |
173 | | - |
174 | | - const double D = FVector::DistSquared(T.GetLocation(), Pos); |
175 | | - |
176 | | - if (D > ClosestDist) { continue; } |
177 | | - |
178 | | - Time = LocalTime; |
179 | | - } |
180 | | - } |
181 | | - else |
182 | | - { |
183 | | - for (int i = 0; i < Splines->Num(); i++) |
184 | | - { |
185 | | - const TSharedPtr<const FPCGSplineStruct> Spline = SplinesRef[i]; |
186 | | - |
187 | | - double LocalTime = Spline->FindInputKeyClosestToWorldLocation(Pos); |
188 | | - LocalTime /= SegmentsNumRef[i]; |
189 | | - |
190 | | - switch (TypedFilterFactory->Config.TimeConsolidation) |
191 | | - { |
192 | | - case EPCGExSplineTimeConsolidation::Min: |
193 | | - Time = FMath::Min(LocalTime, Time); |
194 | | - break; |
195 | | - case EPCGExSplineTimeConsolidation::Max: |
196 | | - Time = FMath::Max(LocalTime, Time); |
197 | | - break; |
198 | | - case EPCGExSplineTimeConsolidation::Average: |
199 | | - Time += LocalTime; |
200 | | - break; |
201 | | - } |
202 | | - } |
203 | | - |
204 | | - if (TypedFilterFactory->Config.TimeConsolidation == EPCGExSplineTimeConsolidation::Average) |
205 | | - { |
206 | | - Time /= SegmentsNumRef.Num(); |
207 | | - } |
208 | | - } |
209 | | - |
210 | | - const double B = OperandB ? OperandB->Read(PointIndex) : TypedFilterFactory->Config.OperandBConstant; |
211 | | - return PCGExCompare::Compare(TypedFilterFactory->Config.Comparison, Time, B, TypedFilterFactory->Config.Tolerance); |
212 | | - } |
213 | | -} |
214 | | - |
215 | | -TArray<FPCGPinProperties> UPCGExPathAlphaFilterProviderSettings::InputPinProperties() const |
| 12 | +TArray<FPCGPinProperties> UDEPRECATED_PCGExPathAlphaFilterProviderSettings::InputPinProperties() const |
216 | 13 | { |
217 | 14 | TArray<FPCGPinProperties> PinProperties = Super::InputPinProperties(); |
218 | 15 | PCGEX_PIN_POINTS(PCGExPaths::SourcePathsLabel, TEXT("Paths will be used for testing"), Required, {}) |
219 | 16 | return PinProperties; |
220 | 17 | } |
221 | 18 |
|
222 | | -PCGEX_CREATE_FILTER_FACTORY(PathAlpha) |
| 19 | +UPCGExFactoryData* UDEPRECATED_PCGExPathAlphaFilterProviderSettings::CreateFactory(FPCGExContext* InContext, UPCGExFactoryData* InFactory) const |
| 20 | +{ |
| 21 | + PCGE_LOG_C(Error, GraphAndLog, InContext, FTEXT("This filter is deprecated, use 'Filter : Time' instead.")); |
| 22 | + return nullptr; |
| 23 | +} |
223 | 24 |
|
224 | 25 | #if WITH_EDITOR |
225 | | -FString UPCGExPathAlphaFilterProviderSettings::GetDisplayName() const |
| 26 | +FString UDEPRECATED_PCGExPathAlphaFilterProviderSettings::GetDisplayName() const |
226 | 27 | { |
227 | 28 | FString DisplayName = TEXT("Alpha ") + PCGExCompare::ToString(Config.Comparison); |
228 | 29 |
|
|
0 commit comments