UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GeometryCollectionConvexUtility.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "Chaos/ImplicitFwd.h"
10
11#include "GeometryCollectionConvexUtility.generated.h"
12
14
15
16UENUM()
18{
19 // Do not remove overlaps between convex hulls
20 None = 0,
21 // Remove all overlaps between neighboring convex hulls
22 All = 1,
23 // Only remove overlaps on convex hulls of clusters, ignoring leaf-leaf overlaps
24 OnlyClusters = 2,
25 // Only remove overlaps between overlapping clusters, ignoring leaf-leaf and cluster-leaf overlaps
27};
28
29UENUM()
31{
32 // Convert from external collision shapes (if available)
34 // Compute all convex hulls from geometry
36 // Intersect external collision shapes with computed convex hulls
38};
39
40// Controls which bones are allowed to merge their convex hulls
41UENUM(meta=(DisplayName="Allow Convex Bone Merge Method"))
43{
44 // Only allow merging convex hulls of bones that are in proximity
45 ByProximity UMETA(DisplayName = "By Bone Proximity"),
46 // Allow any pair of convex hulls to merge
47 Any
48};
49
50// Controls which individual convex hulls are considered for merges
51UENUM()
53{
54 // Do not require convex hull geometry to be in proximity to merge
55 // Note: May still use bone proximity to limit possible merges in the cluster merge case, via the Allow Convex Bone Merge Method options
56 None,
57 // Only consider convex hull merges if their bounding boxes are in proximity
59};
60
62{
63 // Used to pass computed convex hulls along with metadata
64 // Note these hulls are typically computed in a shared coordinate space, in contrast to the final hulls on the geometry collection which are in the local space of each bone
66 {
68
69 // Mapping from geometry collection bones indices to indices in the Hulls array. A Set is used to support multiple hulls per bone.
71
72 // Percent the hulls are down-scaled
74
75 // The pivots used for scaling by OverlapRemovalShrinkPercent
77 };
78
79 // Compute surface area and contact estimates for two convex hulls in the same local space, with the second hull optionally expanded
80 void CHAOS_API HullIntersectionStats(const ::Chaos::FConvex* HullA, const ::Chaos::FConvex* HullB, float HullBExpansion, float& OutArea, float& OutMaxArea, float& OutSharpContact, float& OutMaxSharpContact);
81
82 // Compute the intersection of ClipHull and UpdateHull, with ClipHull optionally offset, and place the result in ResultHull. Note ResultHull can point to the same FConvex as UpdateHull.
83 // If optional transforms are provided, ClipHull will be transformed into the local space of UpdateHull, and finally transformed by UpdateToResultTransform. Otherwise, all FConvex are assumed to be in the same coordinate space.
84 void CHAOS_API IntersectConvexHulls(::Chaos::FConvex* ResultHull, const ::Chaos::FConvex* ClipHull, float ClipHullOffset, const ::Chaos::FConvex* UpdateHull,
85 const FTransform* ClipHullTransform = nullptr, const FTransform* UpdateHullTransform = nullptr, const FTransform* UpdateToResultTransform = nullptr, double SimplificationDistanceThreshold = 0.0);
86
87 // Get the existing convex hulls from the collection, transformed to the global/shared space of the overall collection
88 // @param bLeafOnly Only include the convex hulls of leaf (rigid) nodes
90
91}
92
94{
95public:
96
102
105
108
111
123 static CHAOS_API FGeometryCollectionConvexData CreateNonOverlappingConvexHullData(FGeometryCollection* GeometryCollection, double FractionAllowRemove = .3, double SimplificationDistanceThreshold = 0.0, double CanExceedFraction = .5,
125
127 {
132
134 double ErrorToleranceInCm = 0.0;
136 // Option to apply the same hull merging settings to leaf hulls
138 // How to allow merges between hulls on different bones
139 EAllowConvexMergeMethod AllowMergesMethod = EAllowConvexMergeMethod::ByProximity;
140 // How to filter by proximity for all merges (including within bones)
143
145 };
146
151
153 {
155 double ErrorToleranceInCm = 0.0;
156 // Optional externally-provided empty space, to be used for all hull merges
158
159 // Optional settings to compute targeted empty space per-bone
161
164 };
165 // Merge convex hulls that are currently on each (selected) transform. If convex hulls are not present, does nothing.
166 // @params OptionalSphereCoveringOut If non-null, will be filled with spheres from all used sphere covering.
169
170 // Additional settings for filtering when the EGenerateConvexMethod::IntersectExternalWithComputed is applied
178
179 // Settings to control convex decompositions. Note the default values are set to *not* perform any decomposition
181 {
183
187
188 // If greater than zero, the minimum geometry volume to consider for convex decomposition
190
191 // If the geo volume / hull volume ratio is greater than this, do not consider convex decomposition
193
194
198
199 // If > 0, specify the maximum number of convex hulls to create. Hull merges will be attempted until this number of hulls remains, or no merges are possible.
201
202 // Stop splitting when hulls have error less than this (expressed in cm; will be cubed for volumetric error). Overrides NumOutputHulls if non-zero.
203 float ErrorTolerance = 0.f;
204
205 // Optionally specify a minimum thickness (in cm) for convex parts; parts below this thickness will always be merged away. Will merge hulls with greater error than ErrorTolerance when needed.
207
208 // How far to go beyond the target number of hulls for initial decomposition (before merges) -- larger values will require more computation but can find better convex decompositions
210
211 // How much to thicken a hull on failure to construct -- to allow 3D decomposition of planar or degenerate meshes and parts-of-meshes
212 //~ Note Chaos::FConvex has its own process to thicken hulls that are smaller than .1 units across (specified by Chaos::TriQuadPrismInflation)
213 //~ Applying some smaller thickening earlier in the decomposition process just allows degenerate parts to make it through the decomposition.
215
218
221
224
227 };
228
229 // Settings to control how convex hulls are generated for rigid/leaf nodes, from the geometry and/or imported collision shapes
231 {
234
239
242
243 // Intersection filters only apply if GenerateMethod == EGenerateConvexMethod::IntersectExternalWithComputed
245
246 // Convex decomposition settings, applied to convex hulls generated from geometry
248
249 // For GenerateMethod == IntersectExternalWithComputed, whether to compute the intersection before computing convex hulls
250 // Note: It seems more logical for this setting to be true, but we expose it as an option because in some special cases the results when it was false were preferred
252 };
253
254 // Computed sphere covering, and optional associated transform/bone
261
266 );
267
270
271 UE_DEPRECATED(5.4, "Please Use GetConvexHull instead.")
273 {
274 check(false);
275 return nullptr;
276 }
277
286 static CHAOS_API bool CopyConvexHulls(FManagedArrayCollection& Collection, const TArray<int32>& TransformIndices,
288
291
294
297
300
303
306
319
325
326 // Compute just the hulls of the leaf / rigid nodes that hold geometry directly, with no cluster hulls and no overlap removal by cutting
327 // This is an initial step of several algorithms: The CreateNonOverlappingConvexHullData function as well as convex-based proximity detection (TODO: and the auto-embed algorithm?)
328 // (TODO: Make auto-embed use this instead of the full hulls?)
329 // @param GlobalTransformArray GeometryCollection's transforms to global space, as computed by GeometryCollectionAlgo::GlobalMatrices
330 // @param SkipBoneFn Indicator function returns true for transform indices that do not need a convex hull to be computed, if non-null
331 // @param OptionalDecompositionSettings Optionally generate multiple convex hulls per transform, if these settings are provided
332 // @param OptionalIntersectConvexHulls Convex hulls to optionally intersect with the computed hulls, so that the resulting hulls will not extend outside of these provided hulls.
333 // @param OptionalTransformToIntersectHulls Mapping from transforms to the OptionalIntersectConvexHulls
334 static CHAOS_API UE::GeometryCollectionConvexUtility::FConvexHulls ComputeLeafHulls(FGeometryCollection* GeometryCollection, const TArray<FTransform>& GlobalTransformArray, double SimplificationDistanceThreshold = 0.0, double OverlapRemovalShrinkPercent = 0.0,
339
340 // generate a list of convex out of a hierarchy of implciit shapes
341 // suported shapes are scaled / transformed implicits as well as Boxes, convexes, spheres and capsules
342 // levelset, tapered capsule, cylinder, heightfields and trimesh are not supported
343 // array will not be erased and convex will be added if any already exists
345
346private:
347 static void ConvertScaledImplicitToConvexArray(
348 const Chaos::FImplicitObject& Implicit,
349 const FTransform& WorldSpaceTransform, bool bInstanced,
351
352 static void ConvertInstancedImplicitToConvexArray(
353 const Chaos::FImplicitObject& Implicit,
354 const FTransform& Transform,
356
357 static void CreateConvexHullAttributesIfNeeded(FManagedArrayCollection& GeometryCollection);
358
359 // Implementation for GenerateClusterConvexHullsFromLeafHulls, supporting the full-collection and subset cases
360 static void GenerateClusterConvexHullsFromLeafOrChildrenHullsInternal(FGeometryCollection& Collection, const FClusterConvexHullSettings& Settings, bool bOnlySubset, bool bUseDirectChildren, const TArrayView<const int32> OptionalTransformSubset);
361};
362
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#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
EAllowConvexMergeMethod
Definition GeometryCollectionConvexUtility.h:43
EConvexHullProximityFilter
Definition GeometryCollectionConvexUtility.h:53
EConvexOverlapRemoval
Definition GeometryCollectionConvexUtility.h:18
EGenerateConvexMethod
Definition GeometryCollectionConvexUtility.h:31
#define UENUM(...)
Definition ObjectMacros.h:749
#define UE_KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:131
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Convex.h:26
Definition ImplicitObject.h:111
Definition GeometryCollectionConvexUtility.h:94
static CHAOS_API bool CopyConvexHulls(FManagedArrayCollection &Collection, const TArray< int32 > &TransformIndices, const FManagedArrayCollection &SourceCollection, const TArray< int32 > &SourceTransformIndices, bool bSkipIfEmpty=false)
Definition GeometryCollectionConvexUtility.cpp:2542
static CHAOS_API bool ValidateConvexData(const FManagedArrayCollection *GeometryCollection)
Definition GeometryCollectionConvexUtility.cpp:2496
static CHAOS_API void RemoveEmptyConvexHulls(FManagedArrayCollection &GeometryCollection)
Definition GeometryCollectionConvexUtility.cpp:2654
static CHAOS_API void CopyChildConvexes(const FGeometryCollection *FromCollection, const TArrayView< const int32 > &FromTransformIdx, FGeometryCollection *ToCollection, const TArrayView< const int32 > &ToTransformIdx, bool bLeafOnly)
Definition GeometryCollectionConvexUtility.cpp:2707
static CHAOS_API bool HasConvexHullData(const FManagedArrayCollection *GeometryCollection)
Definition GeometryCollectionConvexUtility.cpp:141
static CHAOS_API UE::GeometryCollectionConvexUtility::FConvexHulls ComputeLeafHulls(FGeometryCollection *GeometryCollection, const TArray< FTransform > &GlobalTransformArray, double SimplificationDistanceThreshold=0.0, double OverlapRemovalShrinkPercent=0.0, TFunction< bool(int32)> SkipBoneFn=nullptr, const FConvexDecompositionSettings *OptionalDecompositionSettings=nullptr, const TArray< FTransformedConvex > *OptionalIntersectConvexHulls=nullptr, const TArray< TSet< int32 > > *OptionalTransformToIntersectHulls=nullptr, TArray< FGeometryCollectionConvexUtility::FSphereCoveringInfo > *OutComputedNavigableSpheres=nullptr)
Definition GeometryCollectionConvexUtility.cpp:1729
static CHAOS_API void ConvertImplicitToConvexArray(const Chaos::FImplicitObject &InImplicit, const FTransform &Transform, TArray< FTransformedConvex > &InOutConvex)
Definition GeometryCollectionConvexUtility.cpp:2918
static CHAOS_API void SetVolumeAttributes(FManagedArrayCollection *Collection)
Definition GeometryCollectionConvexUtility.cpp:2841
static CHAOS_API FGeometryCollectionConvexData CreateNonOverlappingConvexHullData(FGeometryCollection *GeometryCollection, double FractionAllowRemove=.3, double SimplificationDistanceThreshold=0.0, double CanExceedFraction=.5, EConvexOverlapRemoval OverlapRemovalMethod=EConvexOverlapRemoval::All, double OverlapRemovalShrinkPercent=0.0, UE::GeometryCollectionConvexUtility::FConvexHulls *ComputedLeafHullsToModify=nullptr)
Definition GeometryCollectionConvexUtility.cpp:1757
static CHAOS_API FGeometryCollectionConvexData GetValidConvexHullData(FGeometryCollection *GeometryCollection)
Definition GeometryCollectionConvexUtility.cpp:146
static CHAOS_API void GenerateClusterConvexHullsFromLeafHulls(FGeometryCollection &Collection, const FClusterConvexHullSettings &Settings, const TArrayView< const int32 > OptionalTransformSubset)
Definition GeometryCollectionConvexUtility.cpp:2076
static TUniquePtr< Chaos::FConvex > FindConvexHull(const FGeometryCollection *GeometryCollection, int32 GeometryIndex)
Definition GeometryCollectionConvexUtility.h:272
static CHAOS_API Chaos::FConvexPtr GetConvexHull(const FGeometryCollection *GeometryCollection, int32 GeometryIndex)
Definition GeometryCollectionConvexUtility.cpp:2524
static CHAOS_API void GenerateClusterConvexHullsFromChildrenHulls(FGeometryCollection &Collection, const FClusterConvexHullSettings &Settings, const TArrayView< const int32 > TransformSubset)
Definition GeometryCollectionConvexUtility.cpp:2068
static CHAOS_API void RemoveConvexHulls(FManagedArrayCollection *GeometryCollection, const TArray< int32 > &TransformsToClearHullsFrom)
Definition GeometryCollectionConvexUtility.cpp:2625
static CHAOS_API TManagedArray< int32 > * GetCustomConvexFlags(FGeometryCollection *GeometryCollection, bool bAddIfMissing=false)
Definition GeometryCollectionConvexUtility.cpp:2693
static CHAOS_API TOptional< FGeometryCollectionConvexData > GetConvexHullDataIfPresent(FManagedArrayCollection *GeometryCollection)
Definition GeometryCollectionConvexUtility.cpp:124
static CHAOS_API void GenerateLeafConvexHulls(FGeometryCollection &Collection, bool bRestrictToSelection, const TArrayView< const int32 > TransformSubset, const FLeafConvexHullSettings &Settings, TArray< FSphereCoveringInfo > *OutComputedNavigableSpheres=nullptr)
Definition GeometryCollectionConvexUtility.cpp:1808
static CHAOS_API void SetDefaults(FGeometryCollection *GeometryCollection, FName Group, uint32 StartSize, uint32 NumElements)
Definition GeometryCollectionConvexUtility.cpp:2688
static CHAOS_API void MergeHullsOnTransforms(FManagedArrayCollection &Collection, const FGeometryCollectionConvexUtility::FMergeConvexHullSettings &Settings, bool bRestrictToSelection, const TArrayView< const int32 > OptionalTransformSelection, UE::Geometry::FSphereCovering *OptionalSphereCoveringOut=nullptr)
Definition GeometryCollectionConvexUtility.cpp:2355
Definition GeometryCollection.h:32
Definition NameTypes.h:617
Definition ArrayView.h:139
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition ManagedArray.h:1099
Definition UniquePtr.h:107
Definition ConvexDecomposition3.h:184
Definition SkeletalMeshComponent.h:307
Definition CollectionBoundsFacade.cpp:13
Definition GeometryCollectionConvexUtility.cpp:3602
void HullIntersectionStats(const Chaos::FConvex *HullA, const Chaos::FConvex *HullB, float HullBExpansion, float &OutArea, float &OutMaxArea, float &OutSharpContact, float &OutMaxSharpContact)
Definition GeometryCollectionConvexUtility.cpp:3605
bool CHAOS_API GetExistingConvexHullsInSharedSpace(const FManagedArrayCollection *Collection, FConvexHulls &OutConvexHulls, bool bLeafOnly)
Definition GeometryCollectionConvexUtility.cpp:3656
void IntersectConvexHulls(Chaos::FConvex *ResultHull, const Chaos::FConvex *ClipHull, float ClipHullOffset, const Chaos::FConvex *UpdateHull, const FTransform *ClipHullTransform, const FTransform *UpdateHullTransform, const FTransform *ResultTransform, double SimplificationDistanceThreshold)
Definition GeometryCollectionConvexUtility.cpp:3616
Definition GeometryCollectionConvexUtility.h:127
float ProximityDistanceThreshold
Definition GeometryCollectionConvexUtility.h:142
FClusterConvexHullSettings(int32 ConvexCount, double ErrorToleranceInCm, bool bUseExternalCollisionIfAvailable=true)
Definition GeometryCollectionConvexUtility.h:129
int32 ConvexCount
Definition GeometryCollectionConvexUtility.h:133
double ErrorToleranceInCm
Definition GeometryCollectionConvexUtility.h:134
EAllowConvexMergeMethod AllowMergesMethod
Definition GeometryCollectionConvexUtility.h:139
bool bAllowMergingLeafHulls
Definition GeometryCollectionConvexUtility.h:137
bool bUseExternalCollisionIfAvailable
Definition GeometryCollectionConvexUtility.h:135
UE::Geometry::FSphereCovering * EmptySpace
Definition GeometryCollectionConvexUtility.h:144
EConvexHullProximityFilter ProximityFilter
Definition GeometryCollectionConvexUtility.h:141
Definition GeometryCollectionConvexUtility.h:181
float ErrorTolerance
Definition GeometryCollectionConvexUtility.h:203
bool bOnlyConnectedToHull
Definition GeometryCollectionConvexUtility.h:220
float ThickenHullOnFailure
Definition GeometryCollectionConvexUtility.h:214
bool bProtectNegativeSpace
Definition GeometryCollectionConvexUtility.h:217
float MaxGeoToHullVolumeRatioToDecompose
Definition GeometryCollectionConvexUtility.h:192
float MinThicknessTolerance
Definition GeometryCollectionConvexUtility.h:206
float NegativeSpaceMinRadius
Definition GeometryCollectionConvexUtility.h:226
int32 NumAdditionalSplits
Definition GeometryCollectionConvexUtility.h:209
float MinGeoVolumeToDecompose
Definition GeometryCollectionConvexUtility.h:189
float NegativeSpaceTolerance
Definition GeometryCollectionConvexUtility.h:223
int32 MaxHullsPerGeometry
Definition GeometryCollectionConvexUtility.h:200
Definition GeometryCollectionConvexUtility.h:98
TManagedArray< TSet< int32 > > & TransformToConvexIndices
Definition GeometryCollectionConvexUtility.h:99
TManagedArray< Chaos::FConvexPtr > & ConvexHull
Definition GeometryCollectionConvexUtility.h:100
Definition GeometryCollectionConvexUtility.h:172
double MinExternalVolumeToIntersect
Definition GeometryCollectionConvexUtility.h:176
double OnlyIntersectIfComputedIsSmallerFactor
Definition GeometryCollectionConvexUtility.h:175
FIntersectionFilters()
Definition GeometryCollectionConvexUtility.h:173
Definition GeometryCollectionConvexUtility.h:231
bool bComputeIntersectionsBeforeHull
Definition GeometryCollectionConvexUtility.h:251
FConvexDecompositionSettings DecompositionSettings
Definition GeometryCollectionConvexUtility.h:247
EGenerateConvexMethod GenerateMethod
Definition GeometryCollectionConvexUtility.h:241
FIntersectionFilters IntersectFilters
Definition GeometryCollectionConvexUtility.h:244
double SimplificationDistanceThreshold
Definition GeometryCollectionConvexUtility.h:240
FLeafConvexHullSettings(double SimplificationDistanceThreshold, EGenerateConvexMethod GenerateMethod=EGenerateConvexMethod::ExternalCollision)
Definition GeometryCollectionConvexUtility.h:235
FLeafConvexHullSettings()
Definition GeometryCollectionConvexUtility.h:232
Definition GeometryCollectionConvexUtility.h:153
UE::Geometry::FNegativeSpaceSampleSettings * ComputeEmptySpacePerBoneSettings
Definition GeometryCollectionConvexUtility.h:160
EConvexHullProximityFilter ProximityFilter
Definition GeometryCollectionConvexUtility.h:162
int32 MaxConvexCount
Definition GeometryCollectionConvexUtility.h:154
float ProximityDistanceThreshold
Definition GeometryCollectionConvexUtility.h:163
double ErrorToleranceInCm
Definition GeometryCollectionConvexUtility.h:155
UE::Geometry::FSphereCovering * EmptySpace
Definition GeometryCollectionConvexUtility.h:157
Definition GeometryCollectionConvexUtility.h:256
FTransform Transform
Definition GeometryCollectionConvexUtility.h:257
UE::Geometry::FSphereCovering SphereCovering
Definition GeometryCollectionConvexUtility.h:259
int32 SourceBoneIndex
Definition GeometryCollectionConvexUtility.h:258
Definition GeometryCollectionConvexUtility.h:321
Chaos::FConvexPtr Convex
Definition GeometryCollectionConvexUtility.h:322
FTransform Transform
Definition GeometryCollectionConvexUtility.h:323
Definition ManagedArrayCollection.h:56
Definition Optional.h:131
Definition GeometryCollectionConvexUtility.h:66
TArray< TSet< int32 > > TransformToHullsIndices
Definition GeometryCollectionConvexUtility.h:70
double OverlapRemovalShrinkPercent
Definition GeometryCollectionConvexUtility.h:73
TArray< FVector > Pivots
Definition GeometryCollectionConvexUtility.h:76
TArray<::Chaos::FConvexPtr > Hulls
Definition GeometryCollectionConvexUtility.h:67
Definition ConvexDecomposition3.h:38
static CORE_API const TTransform< double > Identity
Definition TransformNonVectorized.h:58