UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PBDChainConstraints.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4// HEADER_UNIT_SKIP - This file does not compile anymore (Base ctor needs to be called)
5
11#include "Chaos/PBDParticles.h"
12
13namespace Chaos
14{
16{
17public:
19 : MConstraints(Constraints), MCoefficient(Coefficient)
20 {
21 MDists.SetNum(MConstraints.Num());
22 PhysicsParallelFor(MConstraints.Num(), [&](int32 Index) {
23 TArray<FReal> singledists;
24 for (int i = 1; i < Constraints[Index].Num(); ++i)
25 {
26 const FVec3& P1 = InParticles.X(Constraints[Index][i - 1]);
27 const FVec3& P2 = InParticles.X(Constraints[Index][i]);
28 FReal Distance = (P1 - P2).Size();
29 singledists.Add(Distance);
30 }
31 MDists[Index] = singledists;
32 });
33 }
35
37 {
39 for (int i = 1; i < MConstraints[Index].Num(); ++i)
40 {
41 int32 P = MConstraints[Index][i];
42 int32 PM1 = MConstraints[Index][i - 1];
43 const FVec3& P1 = InParticles.P(PM1);
44 const FVec3& P2 = InParticles.P(P);
45 FVec3 Difference = P1 - P2;
46 FReal Distance = Difference.Size();
47 FVec3 Direction = Difference / Distance;
48 FVec3 Delta = (Distance - MDists[Index][i - 1]) * Direction;
49 if (i == 1)
50 {
51 InParticles.P(P) += Delta;
52 }
53 else
54 {
55 InParticles.P(P) += MCoefficient * Delta;
56 InParticles.P(PM1) -= (1 - MCoefficient) * Delta;
57 }
58 }
59 }
60
61 void Apply(FPBDParticles& InParticles, const FReal Dt) const
62 {
63 // @todo(ccaulfield): Can we guarantee that no two chains are connected? Should we be checking that somewhere?
64 PhysicsParallelFor(MConstraints.Num(), [&](int32 ConstraintIndex) {
65 Apply(InParticles, Dt, ConstraintIndex);
66 });
67 }
68
70 {
71 // @todo(ccaulfield): Can we guarantee that no two chains are connected? Should we be checking that somewhere?
73 Apply(InParticles, Dt, InConstraintIndices[ConstraintIndicesIndex]);
74 });
75 }
76
77private:
78 using Base::GetConstraintIndex;
79 using Base::SetConstraintIndex;
80
81 TArray<TArray<int32>> MConstraints;
83 FReal MCoefficient;
84};
85
86template<class T, int d>
87class TPBDChainConstraints UE_DEPRECATED(4.27, "Deprecated. this class is to be deleted, use FPBDChainConstraints instead") = FPBDChainConstraints;
88
89}
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
Definition PBDChainConstraints.h:16
void Apply(FPBDParticles &InParticles, const FReal Dt, const TArray< int32 > &InConstraintIndices) const
Definition PBDChainConstraints.h:69
void Apply(FPBDParticles &InParticles, const FReal Dt) const
Definition PBDChainConstraints.h:61
virtual ~FPBDChainConstraints()
Definition PBDChainConstraints.h:34
FPBDChainConstraints(const FDynamicParticles &InParticles, TArray< TArray< int32 > > &&Constraints, const FReal Coefficient=(FReal) 1.)
Definition PBDChainConstraints.h:18
void Apply(FPBDParticles &InParticles, const FReal Dt, const int32 InConstraintIndex) const
Definition PBDChainConstraints.h:36
Definition IndexedConstraintContainer.h:243
Definition DynamicParticles.h:11
Definition PBDParticles.h:12
Definition Constraints.Build.cs:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
Definition SkeletalMeshComponent.h:307
void CHAOS_API PhysicsParallelFor(int32 InNum, TFunctionRef< void(int32)> InCallable, bool bForceSingleThreaded=false)
Definition Parallel.cpp:55
FRealDouble FReal
Definition Real.h:22
U16 Index
Definition radfft.cpp:71