p.Chaos.Collision.Manifold.TriangleNormalThreshold

p.Chaos.Collision.Manifold.TriangleNormalThreshold

#Overview

name: p.Chaos.Collision.Manifold.TriangleNormalThreshold

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Collision.Manifold.TriangleNormalThreshold is to set a threshold for determining the type of contact between a convex shape and a triangle in collision detection within the Chaos physics system of Unreal Engine 5.

This setting variable is primarily used in the Chaos physics subsystem, specifically in the collision detection and manifold generation modules. It’s part of the experimental Chaos physics engine in Unreal Engine 5.

The value of this variable is set in the C++ code, initialized to 0.75f (approximately 40 degrees). It’s exposed as a console variable, which means it can be adjusted at runtime or through configuration files.

The associated variable Chaos_Collision_Manifold_TriangleContactNormalThreshold directly interacts with it. They share the same value and are used interchangeably in the code.

Developers must be aware that this threshold affects how the system distinguishes between face contacts and edge-edge contacts in triangle collision detection. A higher value will favor face contacts, while a lower value will increase the likelihood of edge-edge contact detection.

Best practices when using this variable include:

  1. Understand its impact on collision detection accuracy and performance.
  2. Adjust it carefully based on the specific needs of your game or simulation.
  3. Test thoroughly with different values to find the optimal balance between accuracy and performance for your use case.

Regarding the associated variable Chaos_Collision_Manifold_TriangleContactNormalThreshold:

Its purpose is identical to p.Chaos.Collision.Manifold.TriangleNormalThreshold, serving as the internal representation of the threshold value.

It’s used directly in the collision detection code, specifically in the ConstructPlanarConvexTriangleOneShotManifold function, to determine the contact type between a convex shape and a triangle.

The value is set initially in the C++ code and can be modified through the console variable system.

Developers should be aware that changes to this variable will directly affect the behavior of the collision detection system in the Chaos physics engine.

Best practices include monitoring its impact on collision behavior and adjusting it in conjunction with other related thresholds (like the edge contact normal threshold) to achieve the desired collision detection behavior in your game or simulation.

#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:44

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	FRealSingle Chaos_Collision_Manifold_TriangleContactNormalThreshold = 0.75f;	// About 40deg
	FAutoConsoleVariableRef CVarChaos_Manifold_TriangleContactNormalThreshold(TEXT("p.Chaos.Collision.Manifold.TriangleNormalThreshold"), Chaos_Collision_Manifold_TriangleContactNormalThreshold, TEXT(""));

	FRealSingle Chaos_Collision_Manifold_EdgeContactNormalThreshold = 0.9f;	// About 25deg
	FAutoConsoleVariableRef CVarChaos_Manifold_EdgeContactNormalThreshold(TEXT("p.Chaos.Collision.Manifold.EdgeNormalThreshold"), Chaos_Collision_Manifold_EdgeContactNormalThreshold, TEXT(""));

	// We use a smaller margin for triangle to convex. Ideally we would have none at all in this case
	// LWC_TODO: This needs to be a larger value for float builds (probably 1)

#Associated Variable and Callsites

This variable is associated with another variable named Chaos_Collision_Manifold_TriangleContactNormalThreshold. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:43

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarChaos_Manifold_PlaneContactNormalEpsilon(TEXT("p.Chaos.Collision.Manifold.PlaneContactNormalEpsilon"), Chaos_Collision_Manifold_PlaneContactNormalEpsilon, TEXT("Normal tolerance used to distinguish face contacts from edge-edge contacts"));

	FRealSingle Chaos_Collision_Manifold_TriangleContactNormalThreshold = 0.75f;	// About 40deg
	FAutoConsoleVariableRef CVarChaos_Manifold_TriangleContactNormalThreshold(TEXT("p.Chaos.Collision.Manifold.TriangleNormalThreshold"), Chaos_Collision_Manifold_TriangleContactNormalThreshold, TEXT(""));

	FRealSingle Chaos_Collision_Manifold_EdgeContactNormalThreshold = 0.9f;	// About 25deg
	FAutoConsoleVariableRef CVarChaos_Manifold_EdgeContactNormalThreshold(TEXT("p.Chaos.Collision.Manifold.EdgeNormalThreshold"), Chaos_Collision_Manifold_EdgeContactNormalThreshold, TEXT(""));

	// We use a smaller margin for triangle to convex. Ideally we would have none at all in this case
	// LWC_TODO: This needs to be a larger value for float builds (probably 1)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:1363

Scope (from outer to inner):

file
namespace    Chaos
namespace    Collisions
function     void ConstructPlanarConvexTriangleOneShotManifold

Source code excerpt:


			// We prefer to use the triangle face for the contact to avoid collisions with internal edges and vertices
			const EContactPointType ContactType = (TrianglePlaneNormalDotContactNormal > Chaos_Collision_Manifold_TriangleContactNormalThreshold) ? EContactPointType::VertexPlane : EContactPointType::PlaneVertex;

			// @todo(chaos): fix use of hard-coded max array size
			// We will use a double buffer as an optimization
			const int32 MaxContactPointCount = 32; // This should be tuned
			int32 ContactPointCount = 0;
			FVec3 RefPlaneNormal;