Skip to content

Commit 2e71cb9

Browse files
committed
Axes fixes
1 parent 33e13c1 commit 2e71cb9

File tree

10 files changed

+73
-42
lines changed

10 files changed

+73
-42
lines changed

Source/PCGExtendedToolkit/Private/Data/PCGExPointIOMerger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "Data/PCGExDataFilter.h"
88
#include "Data/PCGExDataTag.h"
9-
#include "Paths/PCGExShiftPath.h"
9+
#include "Paths/PCGExPathShift.h"
1010

1111

1212
PCGExPointIOMerger::FIdentityRef::FIdentityRef()

Source/PCGExtendedToolkit/Private/Details/PCGExDetailsAxis.cpp

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,66 @@ namespace PCGEx
6767
const FVector& XAxis, const FVector& YAxis, const FVector& ZAxis,
6868
int32& X, int32& Y, int32& Z, const bool bPermute)
6969
{
70-
const FVector QuatAxes[3] = { Quat.GetAxisX(), Quat.GetAxisY(), Quat.GetAxisZ() };
70+
const FVector QA[3] = { Quat.GetAxisX(), Quat.GetAxisY(), Quat.GetAxisZ() };
7171

72-
auto FindBest = [&](const FVector& Ref)
72+
double M[3][3];
73+
for (int i = 0; i < 3; ++i)
7374
{
74-
const double DX = FMath::Abs(FVector::DotProduct(XAxis, Ref));
75-
const double DY = FMath::Abs(FVector::DotProduct(YAxis, Ref));
76-
const double DZ = FMath::Abs(FVector::DotProduct(ZAxis, Ref));
77-
return (DX > DY && DX > DZ) ? 0 : (DY > DZ ? 1 : 2);
78-
};
75+
M[i][0] = FMath::Abs(FVector::DotProduct(QA[i], XAxis));
76+
M[i][1] = FMath::Abs(FVector::DotProduct(QA[i], YAxis));
77+
M[i][2] = FMath::Abs(FVector::DotProduct(QA[i], ZAxis));
78+
}
79+
80+
// choose best X/Y/Z directly
81+
int32 Best[3];
82+
for (int i = 0; i < 3; ++i)
83+
{
84+
const double DX = M[i][0];
85+
const double DY = M[i][1];
86+
const double DZ = M[i][2];
87+
Best[i] = (DX >= DY && DX >= DZ) ? 0 : ((DY >= DZ) ? 1 : 2);
88+
}
7989

80-
X = FindBest(QuatAxes[0]);
81-
Y = FindBest(QuatAxes[1]);
82-
Z = FindBest(QuatAxes[2]);
90+
if (!bPermute)
91+
{
92+
X = Best[0];
93+
Y = Best[1];
94+
Z = Best[2];
95+
return;
96+
}
8397

84-
if (bPermute)
98+
// guaranteed permutation with constant-time deterministic resolution
99+
static const int32 Permutations[6][3] =
85100
{
86-
const int OldX = X;
87-
const int OldY = Y;
88-
const int OldZ = Z;
101+
{0,1,2}, {0,2,1},
102+
{1,0,2}, {1,2,0},
103+
{2,0,1}, {2,1,0}
104+
};
105+
106+
int32 BestScore = -1;
107+
const int32* BestPerm = Permutations[0];
89108

90-
uint8 Inv[3];
91-
Inv[OldX] = 0;
92-
Inv[OldY] = 1;
93-
Inv[OldZ] = 2;
109+
for (int p = 0; p < 6; ++p)
110+
{
111+
const int32* P = Permutations[p];
112+
const double Score =
113+
M[0][P[0]] +
114+
M[1][P[1]] +
115+
M[2][P[2]];
94116

95-
X = Inv[0];
96-
Y = Inv[1];
97-
Z = Inv[2];
117+
if (Score > BestScore)
118+
{
119+
BestScore = Score;
120+
BestPerm = P;
121+
}
98122
}
123+
124+
X = BestPerm[0];
125+
Y = BestPerm[1];
126+
Z = BestPerm[2];
127+
128+
check(X >= 0 && X <= 2);
129+
check(Y >= 0 && Y <= 2);
130+
check(Z >= 0 && Z <= 2);
99131
}
100132
}

Source/PCGExtendedToolkit/Private/Graph/PCGExClusterCentrality.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "Graph/PCGExGraph.h"
1212
#include "Graph/Pathfinding/Heuristics/PCGExHeuristics.h"
1313
#include "Graph/Pathfinding/Search/PCGExScoredQueue.h"
14-
#include "Paths/PCGExShiftPath.h"
1514

1615
#define LOCTEXT_NAMESPACE "PCGExClusterCentralityElement"
1716
#define PCGEX_NAMESPACE ClusterCentrality

Source/PCGExtendedToolkit/Private/Paths/PCGExResamplePath.cpp renamed to Source/PCGExtendedToolkit/Private/Paths/PCGExPathResample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025 Timothé Lapetite and contributors
22
// Released under the MIT license https://opensource.org/license/MIT/
33

4-
#include "Paths/PCGExResamplePath.h"
4+
#include "Paths/PCGExPathResample.h"
55

66
#include "PCGExRandom.h"
77
#include "Data/PCGExPointIO.h"

Source/PCGExtendedToolkit/Private/Paths/PCGExShiftPath.cpp renamed to Source/PCGExtendedToolkit/Private/Paths/PCGExPathShift.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025 Timothé Lapetite and contributors
22
// Released under the MIT license https://opensource.org/license/MIT/
33

4-
#include "Paths/PCGExShiftPath.h"
4+
#include "Paths/PCGExPathShift.h"
55

66
#include "Data/PCGExData.h"
77
#include "Data/PCGExPointIO.h"

Source/PCGExtendedToolkit/Private/Paths/PCGExShrinkPath.cpp renamed to Source/PCGExtendedToolkit/Private/Paths/PCGExPathShrink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025 Timothé Lapetite and contributors
22
// Released under the MIT license https://opensource.org/license/MIT/
33

4-
#include "Paths/PCGExShrinkPath.h"
4+
#include "Paths/PCGExPathShrink.h"
55

66
#include "Data/PCGExAttributeHelpers.h"
77
#include "Data/PCGExData.h"

Source/PCGExtendedToolkit/Private/Paths/PCGExPathSolidify.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ UPCGExPathSolidifySettings::UPCGExPathSolidifySettings(const FObjectInitializer&
1515
: Super(ObjectInitializer)
1616
{
1717
RotationMapping.Add(EPCGExAxisOrder::XYZ, EPCGExMakeRotAxis::X);
18-
RotationMapping.Add(EPCGExAxisOrder::YZX, EPCGExMakeRotAxis::XY);
19-
RotationMapping.Add(EPCGExAxisOrder::ZXY, EPCGExMakeRotAxis::Y);
18+
RotationMapping.Add(EPCGExAxisOrder::YZX, EPCGExMakeRotAxis::Z);
19+
RotationMapping.Add(EPCGExAxisOrder::ZXY, EPCGExMakeRotAxis::X);
2020
RotationMapping.Add(EPCGExAxisOrder::YXZ, EPCGExMakeRotAxis::XY);
2121
RotationMapping.Add(EPCGExAxisOrder::ZYX, EPCGExMakeRotAxis::XY);
2222
RotationMapping.Add(EPCGExAxisOrder::XZY, EPCGExMakeRotAxis::X);
@@ -260,9 +260,9 @@ namespace PCGExPathSolidify
260260
TPCGValueRange<FVector> BoundsMin = PointDataFacade->GetOut()->GetBoundsMinValueRange(false);
261261
TPCGValueRange<FVector> BoundsMax = PointDataFacade->GetOut()->GetBoundsMaxValueRange(false);
262262

263-
int32 Main = 0;
264-
int32 Sec = 0;
265-
int32 Ter = 0;
263+
int32 A = 0;
264+
int32 B = 0;
265+
int32 C = 0;
266266

267267
PCGEX_SCOPE_LOOP(Index)
268268
{
@@ -295,10 +295,10 @@ namespace PCGExPathSolidify
295295
const FQuat Quat = PCGEx::MakeRot(GetConstruction(Order, Index), XAxis, YAxis, ZAxis);
296296

297297
// Find primary / secondary / tertiary components
298-
PCGEx::FindOrderMatch(Quat, RealXAxis, RealYAxis, RealZAxis, Main, Sec, Ter);
298+
PCGEx::FindOrderMatch(Quat, RealXAxis, RealYAxis, RealZAxis, A, B, C);
299299

300300
const FVector QuatAxes[3] = {Quat.GetAxisX(), Quat.GetAxisY(), Quat.GetAxisZ()};
301-
const bool bForwardFlipped = FVector::DotProduct(QuatAxes[Main], RealXAxis) < 0;
301+
const bool bForwardFlipped = FVector::DotProduct(QuatAxes[A], RealXAxis) < 0;
302302
double EdgeLerp = FMath::Clamp(SolidificationLerp->Read(Index), 0.0, 1.0);
303303
//if (bForwardFlipped) { EdgeLerp = 1.0 - EdgeLerp; }
304304

@@ -313,21 +313,21 @@ namespace PCGExPathSolidify
313313
// Yey
314314
const double EdgeLerpInv = 1.0 - EdgeLerp;
315315

316-
OutBoundsMin[Main] = (-Length * EdgeLerp) * InvScale[Main];
317-
OutBoundsMax[Main] = (Length * EdgeLerpInv) * InvScale[Main];
316+
OutBoundsMin[A] = (-Length * EdgeLerp) * InvScale[A];
317+
OutBoundsMax[A] = (Length * EdgeLerpInv) * InvScale[A];
318318

319319
if (SecondaryRadius)
320320
{
321321
const double Rad = FMath::Abs(SecondaryRadius->Read(Index));
322-
OutBoundsMin[Sec] = -Rad * InvScale[Sec];
323-
OutBoundsMax[Sec] = Rad * InvScale[Sec];
322+
OutBoundsMin[B] = -Rad * InvScale[B];
323+
OutBoundsMax[B] = Rad * InvScale[B];
324324
}
325325

326326
if (TertiaryRadius)
327327
{
328328
const double Rad = FMath::Abs(TertiaryRadius->Read(Index));
329-
OutBoundsMin[Ter] = -Rad * InvScale[Ter];
330-
OutBoundsMax[Ter] = Rad * InvScale[Ter];
329+
OutBoundsMin[C] = -Rad * InvScale[C];
330+
OutBoundsMax[C] = Rad * InvScale[C];
331331
}
332332
}
333333
}

Source/PCGExtendedToolkit/Public/Paths/PCGExResamplePath.h renamed to Source/PCGExtendedToolkit/Public/Paths/PCGExPathResample.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "Shapes/PCGExShapes.h"
1414

15-
#include "PCGExResamplePath.generated.h"
15+
#include "PCGExPathResample.generated.h"
1616

1717
namespace PCGExPaths
1818
{

Source/PCGExtendedToolkit/Public/Paths/PCGExShiftPath.h renamed to Source/PCGExtendedToolkit/Public/Paths/PCGExPathShift.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "PCGExPaths.h"
1111
#include "Data/Blending/PCGExDataBlending.h"
1212

13-
#include "PCGExShiftPath.generated.h"
13+
#include "PCGExPathShift.generated.h"
1414

1515
namespace PCGExData
1616
{

Source/PCGExtendedToolkit/Public/Paths/PCGExShrinkPath.h renamed to Source/PCGExtendedToolkit/Public/Paths/PCGExPathShrink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "Data/PCGExPointFilter.h"
1111

1212

13-
#include "PCGExShrinkPath.generated.h"
13+
#include "PCGExPathShrink.generated.h"
1414

1515
UENUM()
1616
enum class EPCGExPathShrinkMode : uint8

0 commit comments

Comments
 (0)