UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PhysicsObjectInternal.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
6#include "Containers/Set.h"
8
12
13namespace Chaos
14{
16 {
17 public:
18 bool IsValid() const;
19
21 int32 GetBodyIndex() const { return BodyIndex; }
22
23 void SetName(const FName& InBodyName) { BodyName = InBodyName; }
24 const FName& GetBodyName() const { return BodyName; }
25
26 template<EThreadContext Id>
28 {
30 if (!Particle)
31 {
33 }
34
35 if (TThreadRigidParticle<Id>* Rigid = Particle->CastToRigidParticle())
36 {
37 return Rigid->ObjectState();
38 }
39 else
40 {
41 return Particle->ObjectState();
42 }
43 }
44
45 template<EThreadContext Id>
47 {
48 EPhysicsProxyType ProxyType = Proxy->GetType();
49
51 FPhysicsObjectHandle CurrentObject = const_cast<FPhysicsObjectHandle>(this);
53 while (CurrentParent && IsParticleDisabled<Id>(Particle))
54 {
55 Particle = CurrentParent->GetParticle<Id>();
56 CurrentObject = CurrentParent;
58 }
59 return CurrentObject;
60 }
61
62 template<EThreadContext Id>
64 {
65 EPhysicsProxyType ProxyType = Proxy->GetType();
66 switch (ProxyType)
67 {
69 {
72
73 if (int32 Index = Collection.GetParent(BodyIndex); Index != INDEX_NONE)
74 {
75 return GeometryCollectionProxy->GetPhysicsObjectByIndex(Index);
76 }
77
78 // Yes this is an explicit fall through. Once we get to the root particle on the geometry collection we need to check
79 // if it's in a cluster union same with all the other proxies.
80 [[fallthrough]];
81 }
84 {
85 // At this point, we need to be able to check if we're part of a cluster union.
86 // However, note that we're after more than just the parent particle, we're after
87 // the parent physics object handle which lives on the proxy. Hence why physics proxies
88 // need to keep track of their parent proxy. We do, however, make the assumption that the
89 // only possible valid parent proxy is a cluster union proxy though; hence being able to directly
90 // retrieve the physics object handle.
91 if (IPhysicsProxyBase* ParentProxy = Proxy->GetParentProxy(); ParentProxy && ParentProxy->GetType() == EPhysicsProxyType::ClusterUnionProxy)
92 {
95 }
96 break;
97 }
98 default:
99 break;
100 }
101 return nullptr;
102 }
103
104 template <EThreadContext Id>
106 {
108 if (!Root)
109 {
110 return nullptr;
111 }
112 return Root->GetParticle<Id>();
113 }
114
115 template <EThreadContext Id>
117 {
118 if (Proxy)
119 {
120 EPhysicsProxyType ProxyType = Proxy->GetType();
121 if constexpr (Id == EThreadContext::External)
122 {
123 switch (ProxyType)
124 {
126 return static_cast<FClusterUnionPhysicsProxy*>(Proxy)->GetParticle_External();
128 return static_cast<FGeometryCollectionPhysicsProxy*>(Proxy)->GetParticleByIndex_External(BodyIndex);
130 return static_cast<FSingleParticlePhysicsProxy*>(Proxy)->GetParticle_LowLevel();
131 default:
132 break;
133 }
134 }
135 else
136 {
137 switch (ProxyType)
138 {
140 return static_cast<FClusterUnionPhysicsProxy*>(Proxy)->GetParticle_Internal();
142 return static_cast<FGeometryCollectionPhysicsProxy*>(Proxy)->GetParticleByIndex_Internal(BodyIndex);
144 return static_cast<FSingleParticlePhysicsProxy*>(Proxy)->GetHandle_LowLevel();
145 default:
146 break;
147 }
148 }
149 }
150
151 return (TThreadParticle<Id>*)nullptr;
152 }
153
154 template <EThreadContext Id>
156 {
157 if (TThreadRigidParticle<Id>* Rigid = Particle->CastToRigidParticle())
158 {
159 return Rigid->Disabled();
160 }
161 return false;
162 }
163
164 IPhysicsProxyBase* PhysicsProxy() { return Proxy; }
165 const IPhysicsProxyBase* PhysicsProxy() const { return Proxy; }
166
167 template<EThreadContext Id>
168 bool HasChildren() const
169 {
170 EPhysicsProxyType ProxyType = Proxy->GetType();
171 switch (ProxyType)
172 {
174 {
176 return Collection.HasChildren(BodyIndex);
177 }
179 {
181 if constexpr (Id == EThreadContext::External)
182 {
184 }
185 else
186 {
187 return ClusterProxy->HasChildren_Internal();
188 }
189 }
190 default:
191 break;
192 }
193 return false;
194 }
195
197 protected:
199 : Proxy(InProxy)
200 , BodyIndex(InBodyIndex)
201 , BodyName(InBodyName)
202 {}
203
204 private:
205 IPhysicsProxyBase* Proxy = nullptr;
206 int32 BodyIndex = INDEX_NONE;
207 FName BodyName = NAME_None;
208
209 template<EThreadContext Id>
210 static FGeometryDynamicCollection& GetGeometryCollectionDynamicCollection(FGeometryCollectionPhysicsProxy& GeometryCollectionProxy)
211 {
212 if constexpr (Id == EThreadContext::External)
213 {
214 return GeometryCollectionProxy.GetExternalCollection();
215 }
216 else
217 {
218 return GeometryCollectionProxy.GetPhysicsCollection();
219 }
220 }
221 };
222
232}
@ INDEX_NONE
Definition CoreMiscDefines.h:150
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
EPhysicsProxyType
Definition PhysicsProxyBase.h:11
Definition ClusterUnionPhysicsProxy.h:63
bool HasChildren_External() const
Definition ClusterUnionPhysicsProxy.h:123
FPhysicsObjectHandle GetPhysicsObjectHandle() const
Definition ClusterUnionPhysicsProxy.h:121
Definition PhysicsObjectInternal.h:228
static FPhysicsObjectUniquePtr CreatePhysicsObject(IPhysicsProxyBase *InProxy, int32 InBodyIndex=INDEX_NONE, const FName &InBodyName=NAME_None)
Definition PhysicsObject.cpp:14
Definition SingleParticlePhysicsProxy.h:58
Definition GeometryCollectionPhysicsProxy.h:143
Definition GeometryCollectionProxyData.h:90
Definition NameTypes.h:617
Definition PhysicsProxyBase.h:97
IPhysicsProxyBase * GetParentProxy() const
Definition PhysicsProxyBase.h:147
EPhysicsProxyType GetType() const
Definition PhysicsProxyBase.h:118
Definition SkeletalMeshComponent.h:307
std::conditional_t< Id==EThreadContext::External, FGeometryParticle, FGeometryParticleHandle > TThreadParticle
Definition ParticleHandleFwd.h:120
EObjectStateType
Definition ObjectState.h:10
std::conditional_t< Id==EThreadContext::External, FPBDRigidParticle, FPBDRigidParticleHandle > TThreadRigidParticle
Definition ParticleHandleFwd.h:126
U16 Index
Definition radfft.cpp:71
Definition PhysicsObjectInternal.h:16
FPhysicsObject(IPhysicsProxyBase *InProxy, int32 InBodyIndex=INDEX_NONE, const FName &InBodyName=NAME_None)
Definition PhysicsObjectInternal.h:198
bool HasChildren() const
Definition PhysicsObjectInternal.h:168
void SetBodyIndex(int32 InBodyIndex)
Definition PhysicsObjectInternal.h:20
FPhysicsObjectHandle GetRootObject() const
Definition PhysicsObjectInternal.h:46
IPhysicsProxyBase * PhysicsProxy()
Definition PhysicsObjectInternal.h:164
bool IsValid() const
Definition PhysicsObject.cpp:19
TThreadParticle< Id > * GetRootParticle() const
Definition PhysicsObjectInternal.h:105
const FName & GetBodyName() const
Definition PhysicsObjectInternal.h:24
int32 GetBodyIndex() const
Definition PhysicsObjectInternal.h:21
static bool IsParticleDisabled(TThreadParticle< Id > *Particle)
Definition PhysicsObjectInternal.h:155
FPhysicsObjectHandle GetParentObject() const
Definition PhysicsObjectInternal.h:63
void SetName(const FName &InBodyName)
Definition PhysicsObjectInternal.h:23
TThreadParticle< Id > * GetParticle() const
Definition PhysicsObjectInternal.h:116
const IPhysicsProxyBase * PhysicsProxy() const
Definition PhysicsObjectInternal.h:165
EObjectStateType ObjectState() const
Definition PhysicsObjectInternal.h:27