UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CollisionUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
7
8namespace Chaos
9{
12
13 namespace Private
14 {
15 // Get the implicit object type for the implicit object on the particle, taking into account the fact that the implicit
16 // may be set to use a LevelSet, but only if the particle has collision particles
18 {
19 // NOTE: GetCollisionType(), not GetType()
20 // We use CollisionType on the implicit to determine how to collide. Normally this is the same as the actual ImplicitObject's
21 // type, but may be set to LevelSet in which case we will use CollisionParticles instead (if it has any).
22 EImplicitObjectType ImplicitType = (Implicit != nullptr) ? GetInnerType(Implicit->GetCollisionType()) : ImplicitObjectType::Unknown;
23
24 // If we are a levelset make sure we have CollisionParticles, otherwise go back to the builtin implicit object collision type
25 if ((ImplicitType == ImplicitObjectType::LevelSet) || (ImplicitType == ImplicitObjectType::Unknown))
26 {
27 const FBVHParticles* Simplicial = FConstGenericParticleHandle(Particle)->CollisionParticles().Get();
28 const bool bHasSimplicial = (Simplicial != nullptr) && (Simplicial->Size() > 0);
29 if (!bHasSimplicial)
30 {
31 // NOTE: GetType(), not GetCollisionType()
32 ImplicitType = (Implicit != nullptr) ? GetInnerType(Implicit->GetType()) : ImplicitObjectType::Unknown;
33 }
34 }
35
36 return ImplicitType;
37 }
38
39 // Determine which bounds tests should be run for the specified implicit object pair.
40 // Also sets the bIsProbe flag appropriately.
42 FGeometryParticleHandle* Particle0, const FImplicitObject* Implicit0, const FPerShapeData* Shape0,
43 FGeometryParticleHandle* Particle1, const FImplicitObject* Implicit1, const FPerShapeData* Shape1,
45 {
47
57
58 const bool bHasBounds0 = (Implicit0 != nullptr) && Implicit0->HasBoundingBox();
59 const bool bHasBounds1 = (Implicit1 != nullptr) && Implicit1->HasBoundingBox();
61
62 Flags.bEnableAABBCheck = bAllowBoundsCheck && !(bIsSphere0 && bIsSphere1); // No AABB test if both are spheres
63 Flags.bEnableOBBCheck0 = bAllowBoundsCheck && !bIsSphere0; // No OBB test for spheres
64 Flags.bEnableOBBCheck1 = bAllowBoundsCheck && !bIsSphere1; // No OBB test for spheres
65 Flags.bEnableDistanceCheck = bAllowBoundsCheck && bIsSphere0 && bIsSphere1; // Simple distance test for sphere pairs
66
67 OutDistanceCheckSize = (Flags.bEnableDistanceCheck) ? FRealSingle(Implicit0->GetMarginf() + Implicit1->GetMarginf()) : 0; // Sphere-Sphere bounds test
68
69 // Do not try to reuse manifold points for capsules or spheres (against anything)
70 // NOTE: This can also be disabled for all shape types by the solver (see GenerateCollisionImpl and the Context)
71 Flags.bEnableManifoldUpdate = !bIsSphere0 && !bIsSphere1 && !bIsCapsule0 && !bIsCapsule1 && !bIsLevelSet;
72
73 // If we don't allow large mesh manifolds we can't reuse manifolds for meshes because we may have
74 // thrown away some points that we needed at the new transform
76 {
77 Flags.bEnableManifoldUpdate = Flags.bEnableManifoldUpdate && !bIsMesh0 && !bIsMesh1;
78 }
79
80 // Mark probe flag now so we know which GenerateCollisions to use
81 // @todo(chaos): it looks like this can be changed by a collision modifier so we should not be caching it
82 Flags.bIsProbe = Shape0->GetIsProbe() || Shape1->GetIsProbe();
83
84 return Flags;
85 }
86
87 }
88}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition BVHParticles.h:24
uint32 Size() const
Definition ArrayCollection.h:66
Definition ParticleHandle.h:2628
const TUniquePtr< FBVHParticles > & CollisionParticles() const
Definition ParticleHandle.h:1880
Definition ImplicitObject.h:111
CHAOS_API EImplicitObjectType GetCollisionType() const
Definition ImplicitObject.cpp:72
CHAOS_API EImplicitObjectType GetType() const
Definition ImplicitObject.cpp:67
Definition ShapeInstance.h:36
bool GetIsProbe() const
Definition ShapeInstance.h:1177
Definition ParticleHandle.h:436
@ TriangleMesh
Definition ImplicitObjectType.h:24
@ LevelSet
Definition ImplicitObjectType.h:19
@ HeightField
Definition ImplicitObjectType.h:25
@ Capsule
Definition ImplicitObjectType.h:16
@ Sphere
Definition ImplicitObjectType.h:13
@ Unknown
Definition ImplicitObjectType.h:20
EImplicitObjectType GetImplicitCollisionType(const FGeometryParticleHandle *Particle, const FImplicitObject *Implicit)
Definition CollisionUtil.h:17
FImplicitBoundsTestFlags CalculateImplicitBoundsTestFlags(FGeometryParticleHandle *Particle0, const FImplicitObject *Implicit0, const FPerShapeData *Shape0, FGeometryParticleHandle *Particle1, const FImplicitObject *Implicit1, const FPerShapeData *Shape1, FRealSingle &OutDistanceCheckSize)
Definition CollisionUtil.h:41
Definition SkeletalMeshComponent.h:307
uint8 EImplicitObjectType
Definition ImplicitObjectType.h:41
bool bChaos_Collision_EnableBoundsChecks
Definition PBDCollisionConstraint.cpp:67
float FRealSingle
Definition Real.h:14
FORCEINLINE EImplicitObjectType GetInnerType(EImplicitObjectType Type)
Definition ImplicitObjectType.h:58
bool bChaos_Collision_EnableLargeMeshManifolds
Definition CollisionOneShotManifolds.cpp:88
Definition OverriddenPropertySet.cpp:45
Definition PBDCollisionConstraint.h:138