UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PBDLongRangeConstraintsBase.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Chaos/Core.h"
10#include "Containers/Map.h"
11#include "Containers/Set.h"
12
13namespace Chaos::Softs
14{
15
17{
18public:
20
21 static constexpr FSolverReal MinTetherScale = (FSolverReal)0.01;
22 static constexpr FSolverReal MaxTetherScale = (FSolverReal)10.;
23
25
27 const FSolverParticlesRange& Particles,
31 const FSolverVec2& InStiffness = FSolverVec2::UnitVector,
32 const FSolverVec2& InScale = FSolverVec2::UnitVector,
34 FSolverReal MeshScale = (FSolverReal)1.);
35
37 const FSolverParticles& Particles,
43 const FSolverVec2& InStiffness = FSolverVec2::UnitVector,
44 const FSolverVec2& InScale = FSolverVec2::UnitVector,
46 FSolverReal MeshScale = (FSolverReal)1.);
47
48PRAGMA_DISABLE_DEPRECATION_WARNINGS // For ScaleIndices and ScaleTable
51
52 // Return the stiffness input values used by the constraint
54
55 // Set the stiffness and scale values used by the constraint
61
62 // Set stiffness offset and range, as well as the simulation stiffness exponent
63 void ApplyProperties(const FSolverReal Dt, const int32 NumIterations)
64 {
65 Stiffness.ApplyPBDValues(Dt, NumIterations);
67 }
68
69 // Return the tethers, organized in concurent friendly batches
71
72 // Return the start index of the specified tether
73 int32 GetStartIndex(const FTether& Tether) const { return Tether.Get<0>(); }
74
75 // Return the kinematic particle index of the specified tether
77
78 // Return the end index of the specified tether
79 int32 GetEndIndex(const FTether& Tether) const { return Tether.Get<1>(); }
80
81 // Return the dynamic particle index of the specified tether
83
84 // Return the reference length of the specified tether
85 FSolverReal GetRefLength(const FTether& Tether) const { return (FSolverReal)Tether.Get<2>(); }
86
87 // Return the Tether scale for the specified tether
89
90 // Return the target length of the specified tether (= RefLength * Scale)
92
93protected:
94 // Return the minimum number of long range tethers in a batch to process in parallel
96
97 // Return a vector representing the amount of segment required for the tether to shrink back to its maximum target length constraint, or zero if the constraint is already met
98 template<typename SolverParticlesOrRange>
99 inline FSolverVec3 GetDelta(const SolverParticlesOrRange& Particles, const FTether& Tether, const FSolverReal InScale) const
100 {
101 const int32 Start = GetStartParticle(Tether);
104 checkSlow(Particles.InvM(Start) == (FSolverReal)0.);
105 checkSlow(Particles.InvM(End) > (FSolverReal)0.);
106 FSolverVec3 Direction = Particles.P(Start) - Particles.P(End);
107 const FSolverReal Length = Direction.SafeNormalize();
109 return Offset < (FSolverReal)0. ? FSolverVec3((FSolverReal)0.) : Offset * Direction;
110 };
111
112 // Return a direction and length representing the amount of segment required for the tether to shrink back to its maximum target length constraint, or zero if the constraint is already met
113 template<typename SolverParticlesOrRange>
115 {
116 const int32 Start = GetStartParticle(Tether);
119 checkSlow(Particles.InvM(Start) == (FSolverReal)0.);
120 checkSlow(Particles.InvM(End) > (FSolverReal)0.);
121 OutDirection = Particles.P(Start) - Particles.P(End);
122 const FSolverReal Length = OutDirection.SafeNormalize();
123 OutOffset = FMath::Max((FSolverReal)0., Length - TargetLength);
124 };
125
126protected:
127 static constexpr int32 TableSize = 16; // The size of the weightmaps lookup table
128 const TArray<TConstArrayView<FTether>>& Tethers; // Array view on the tether provided to this constraint
129 const int32 ParticleOffset; // Index of the first usable particle
131 FPBDStiffness Stiffness; // Stiffness weightmap lookup table
132 FPBDWeightMap TetherScale; // Scale weightmap lookup table
133};
134} // End namespace Chaos::Softs
#define checkSlow(expr)
Definition AssertionMacros.h:332
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
uint32 Offset
Definition VulkanMemory.cpp:4033
Definition PBDLongRangeConstraintsBase.h:17
virtual PRAGMA_DISABLE_DEPRECATION_WARNINGS ~FPBDLongRangeConstraintsBase()
Definition PBDLongRangeConstraintsBase.h:49
const int32 ParticleOffset
Definition PBDLongRangeConstraintsBase.h:129
FSolverReal GetRefLength(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:85
FSolverReal GetTargetLength(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:91
PRAGMA_ENABLE_DEPRECATION_WARNINGS FSolverVec2 GetStiffness() const
Definition PBDLongRangeConstraintsBase.h:53
FSolverReal GetScale(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:88
const TArray< TConstArrayView< FTether > > & GetTethers() const
Definition PBDLongRangeConstraintsBase.h:70
int32 GetStartParticle(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:76
static constexpr FSolverReal MaxTetherScale
Definition PBDLongRangeConstraintsBase.h:22
UE_NONCOPYABLE(FPBDLongRangeConstraintsBase)
static constexpr int32 TableSize
Definition PBDLongRangeConstraintsBase.h:127
int32 GetEndParticle(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:82
FPBDWeightMap TetherScale
Definition PBDLongRangeConstraintsBase.h:132
int32 GetEndIndex(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:79
TTuple< int32, int32, FRealSingle > FTether
Definition PBDLongRangeConstraintsBase.h:24
int32 GetStartIndex(const FTether &Tether) const
Definition PBDLongRangeConstraintsBase.h:73
const TArray< TConstArrayView< FTether > > & Tethers
Definition PBDLongRangeConstraintsBase.h:128
static constexpr FSolverReal MinTetherScale
Definition PBDLongRangeConstraintsBase.h:21
void SetProperties(const FSolverVec2 &InStiffness, const FSolverVec2 &InTetherScale, FSolverReal MeshScale=(FSolverReal) 1.)
Definition PBDLongRangeConstraintsBase.h:56
FSolverVec3 GetDelta(const SolverParticlesOrRange &Particles, const FTether &Tether, const FSolverReal InScale) const
Definition PBDLongRangeConstraintsBase.h:99
static CHAOS_API int32 GetMinParallelBatchSize()
Definition PBDLongRangeConstraintsBase.cpp:22
const int32 ParticleCount
Definition PBDLongRangeConstraintsBase.h:130
void ApplyProperties(const FSolverReal Dt, const int32 NumIterations)
Definition PBDLongRangeConstraintsBase.h:63
void GetDelta(const SolverParticlesOrRange &Particles, const FTether &Tether, const FSolverReal InScale, FSolverVec3 &OutDirection, FSolverReal &OutOffset) const
Definition PBDLongRangeConstraintsBase.h:114
FPBDStiffness Stiffness
Definition PBDLongRangeConstraintsBase.h:131
Definition PBDStiffness.h:21
void SetWeightedValue(const FSolverVec2 &InWeightedValue, FSolverReal MaxStiffness=DefaultPBDMaxStiffness)
Definition PBDStiffness.h:65
static constexpr FSolverReal DefaultPBDMaxStiffness
Definition PBDStiffness.h:24
void ApplyPBDValues(const FSolverReal Dt, const int32 NumIterations)
Definition PBDStiffness.h:124
Definition PBDWeightMap.h:19
void ApplyValues(bool *bOutUpdated=nullptr)
Definition PBDWeightMap.h:71
const FSolverVec2 & GetWeightedValue() const
Definition PBDWeightMap.h:68
void SetWeightedValue(const FSolverVec2 &InWeightedValue)
Definition PBDWeightMap.h:62
bool HasWeightMap() const
Definition PBDWeightMap.h:55
Definition SoftsSolverParticlesRange.h:12
Definition PBDSoftsSolverParticles.h:20
Definition Array.h:670
Definition CollectionEmbeddedSpringConstraintFacade.cpp:6
FRealSingle FSolverReal
Definition PBDSoftsEvolutionFwd.h:31
TVector< FSolverReal, 3 > FSolverVec3
Definition PBDSoftsEvolutionFwd.h:33
Definition Tuple.h:652