p.Chaos.Collision.MeshContactNormalThreshold
p.Chaos.Collision.MeshContactNormalThreshold
#Overview
name: p.Chaos.Collision.MeshContactNormalThreshold
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Treat contact with a dot product between the normal and the triangle face greater than this as face collisions
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.Collision.MeshContactNormalThreshold is to define a threshold for treating contacts as face collisions in mesh collision detection within Unreal Engine’s Chaos physics system. It specifically sets a dot product threshold between the contact normal and the triangle face normal.
This setting variable is primarily used by the Chaos physics system, which is part of Unreal Engine’s experimental physics and collision detection module. It’s referenced in several files within the Chaos collision detection subsystem, including CollisionOneShotManifolds.cpp, ContactTriangles.cpp, and MeshContactGenerator.cpp.
The value of this variable is set initially to 0.998f (approximately 3 degrees) in the CollisionOneShotManifolds.cpp file. It can be modified at runtime through the console variable system, as indicated by the FAutoConsoleVariableRef declaration.
This variable interacts closely with other collision-related variables, such as Chaos_Collision_MeshContactNormalRejectionThreshold and bChaos_Collision_MeshManifoldSortByDistance. These variables collectively control various aspects of mesh collision detection and manifold generation.
Developers must be aware that this variable affects the classification of contacts as face collisions. A higher value will result in fewer contacts being classified as face collisions, potentially affecting the accuracy and stability of collision resolution.
Best practices when using this variable include:
- Carefully tuning its value based on the specific requirements of your game or simulation.
- Testing thoroughly with different values to ensure desired collision behavior.
- Considering its interaction with other collision-related variables for optimal results.
Regarding the associated variable Chaos_Collision_MeshContactNormalThreshold:
This is the actual variable that stores the threshold value. It’s used directly in the collision detection code, such as in the FixInvalidNormalContactPoints function in ContactTriangles.cpp. The purpose and usage are identical to p.Chaos.Collision.MeshContactNormalThreshold, as they share the same value.
The value of Chaos_Collision_MeshContactNormalThreshold is set and modified through the console variable system, allowing for runtime adjustments.
Developers should treat this variable as the internal representation of the threshold and use the console variable (p.Chaos.Collision.MeshContactNormalThreshold) for external modifications and debugging.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:89
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FRealSingle Chaos_Collision_MeshContactNormalThreshold = 0.998f; // ~3deg
FAutoConsoleVariableRef CVarChaos_Collision_MeshContactNormalThreshold(TEXT("p.Chaos.Collision.MeshContactNormalThreshold"), Chaos_Collision_MeshContactNormalThreshold, TEXT("Treat contact with a dot product between the normal and the triangle face greater than this as face collisions"));
FRealSingle Chaos_Collision_MeshContactNormalRejectionThreshold = 0.7f; // ~45deg
FAutoConsoleVariableRef CVarChaos_Collision_MeshContactNormalRejectionThreshold(TEXT("p.Chaos.Collision.MeshContactNormalRejectionThreshold"), Chaos_Collision_MeshContactNormalRejectionThreshold, TEXT("Don't correct edge and vertex normals if they are beyond the valid range by more than this"));
bool bChaos_Collision_MeshManifoldSortByDistance = false;
FAutoConsoleVariableRef CVarChaos_Collision_LargeMeshManifoldSortByDistance(TEXT("p.Chaos.Collision.SortMeshManifoldByDistance"), bChaos_Collision_MeshManifoldSortByDistance, TEXT("Sort large mesh manifold points by |RxN| for improved solver stability (less rotation in first iteration)"));
#Associated Variable and Callsites
This variable is associated with another variable named Chaos_Collision_MeshContactNormalThreshold
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/ContactTriangles.cpp:10
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
extern bool bChaos_Collision_EnableEdgePrune;
extern bool bChaos_Collision_EnableLargeMeshManifolds;
extern FRealSingle Chaos_Collision_MeshContactNormalThreshold;
extern bool bChaos_Collision_MeshManifoldSortByDistance;
void FContactTriangleCollector::SetNumContacts(const int32 NumContacts)
{
TriangleContactPoints.SetNum(NumContacts, EAllowShrinking::No);
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/ContactTriangles.cpp:404
Scope (from outer to inner):
file
namespace Chaos
function void FContactTriangleCollector::FixInvalidNormalContactPoints
Source code excerpt:
void FContactTriangleCollector::FixInvalidNormalContactPoints()
{
const FReal ContactDotNormalThreshold = Chaos_Collision_MeshContactNormalThreshold;
const int32 NumContactPoints = TriangleContactPoints.Num();
for (int32 ContactIndex = 0; ContactIndex < NumContactPoints; ++ContactIndex)
{
FTriangleContactPointData& ContactPointData = TriangleContactPointDatas[ContactIndex];
FContactPoint& ContactPoint = TriangleContactPoints[ContactIndex];
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/MeshContactGenerator.cpp:5
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
namespace Chaos
{
extern FRealSingle Chaos_Collision_MeshContactNormalThreshold;
extern FRealSingle Chaos_Collision_MeshContactNormalRejectionThreshold;
extern int32 Chaos_Collision_MeshManifoldHashSize;
}
namespace Chaos::CVars
{
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/MeshContactGenerator.cpp:23
Scope (from outer to inner):
file
namespace Chaos::Private
function FMeshContactGeneratorSettings::FMeshContactGeneratorSettings
Source code excerpt:
{
HashSize = FMath::RoundUpToPowerOfTwo(Chaos_Collision_MeshManifoldHashSize);
FaceNormalDotThreshold = Chaos_Collision_MeshContactNormalThreshold;
EdgeNormalDotRejectTolerance = Chaos_Collision_MeshContactNormalRejectionThreshold;
BarycentricTolerance = FReal(1.e-3);
MaxContactsBufferSize = 1000;
bCullBackFaces = true;
bFixNormals = true;
bSortForSolver = false;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:88
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
FAutoConsoleVariableRef CVarChaos_Collision_EnableLargeMeshManifolds(TEXT("p.Chaos.Collision.EnableLargeMeshManifolds"), bChaos_Collision_EnableLargeMeshManifolds, TEXT("Whether to allow large mesh manifolds for collisions against meshes (required for good behaviour)"));
FRealSingle Chaos_Collision_MeshContactNormalThreshold = 0.998f; // ~3deg
FAutoConsoleVariableRef CVarChaos_Collision_MeshContactNormalThreshold(TEXT("p.Chaos.Collision.MeshContactNormalThreshold"), Chaos_Collision_MeshContactNormalThreshold, TEXT("Treat contact with a dot product between the normal and the triangle face greater than this as face collisions"));
FRealSingle Chaos_Collision_MeshContactNormalRejectionThreshold = 0.7f; // ~45deg
FAutoConsoleVariableRef CVarChaos_Collision_MeshContactNormalRejectionThreshold(TEXT("p.Chaos.Collision.MeshContactNormalRejectionThreshold"), Chaos_Collision_MeshContactNormalRejectionThreshold, TEXT("Don't correct edge and vertex normals if they are beyond the valid range by more than this"));
bool bChaos_Collision_MeshManifoldSortByDistance = false;
FAutoConsoleVariableRef CVarChaos_Collision_LargeMeshManifoldSortByDistance(TEXT("p.Chaos.Collision.SortMeshManifoldByDistance"), bChaos_Collision_MeshManifoldSortByDistance, TEXT("Sort large mesh manifold points by |RxN| for improved solver stability (less rotation in first iteration)"));