p.Chaos.TriMeshPerPolySupport

p.Chaos.TriMeshPerPolySupport

#Overview

name: p.Chaos.TriMeshPerPolySupport

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

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.TriMeshPerPolySupport is to control the per-polygon support feature for triangle meshes in Unreal Engine’s Chaos physics system. This setting variable is primarily used in the physics simulation and collision detection subsystems of the engine.

The Chaos physics system, which is part of Unreal Engine’s Experimental module, relies on this setting variable. It is specifically used in the triangle mesh implementation of the implicit object system.

The value of this variable is set through a console variable (CVar) named “p.Chaos.TriMeshPerPolySupport”. It is initialized to 1 (true) by default, but can be changed at runtime through the console.

This variable interacts closely with the ExternalVertexIndexMap in the FTriangleMeshImplicitObject class. When TriMeshPerPolySupport is enabled, the ExternalVertexIndexMap is created and used, providing additional functionality for per-polygon operations.

Developers must be aware of several important points when using this variable:

  1. Changing this setting at runtime may not have the desired effect, as noted in the comment in the source code.
  2. Disabling this feature removes the memory cost of the vertex map on triangle meshes, which could be beneficial for performance in some cases.
  3. If this setting is re-enabled after being off, the cooked triangle meshes won’t have the vertex map serialized, so the change will not take effect until assets are re-cooked.

Best practices when using this variable include:

  1. Consider the trade-off between memory usage and functionality when deciding whether to enable or disable this feature.
  2. If changing this setting, make sure to re-cook relevant assets to ensure the change takes effect.
  3. Be cautious about changing this setting at runtime, as it may not work as expected.

The associated variable TriMeshPerPolySupport is used internally within the Chaos namespace to control the same functionality. It’s used in various parts of the triangle mesh implementation, including during the construction of FTriangleMeshImplicitObject instances and when updating vertices. The same considerations and best practices apply to this internal variable as to the console variable.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/TriangleMeshImplicitObject.cpp:27

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	// Note that if this is re-enabled when previously off, the cooked trimeshes won't have the vertex map serialized, so the change will not take effect until re-cooked.
	bool TriMeshPerPolySupport = 1;
	FAutoConsoleVariableRef CVarPerPolySupport(TEXT("p.Chaos.TriMeshPerPolySupport"), TriMeshPerPolySupport, TEXT("Disabling removes memory cost of vertex map on triangle mesh. Note: Changing at runtime will not work."));

	FReal GetWindingOrder(const FVec3& Scale)
	{
		const FVec3 SignVector = Scale.GetSignVector();
		return SignVector.X * SignVector.Y * SignVector.Z;
	}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/ChaosCooking.cpp:136

Scope (from outer to inner):

file
namespace    Chaos
namespace    Cooking
function     Chaos::FTriangleMeshImplicitObjectPtr BuildSingleTrimesh
lambda-function

Source code excerpt:


				TUniquePtr<TArray<int32>> OutFaceRemapPtr = MakeUnique<TArray<int32>>(OutFaceRemap);
				TUniquePtr<TArray<int32>> OutVertexRemapPtr = Chaos::TriMeshPerPolySupport ? MakeUnique<TArray<int32>>(OutVertexRemap) : nullptr;
				Chaos::FTriangleMeshImplicitObjectPtr TriangleMesh( new Chaos::FTriangleMeshImplicitObject(MoveTemp(TriMeshParticles), MoveTemp(Triangles), MoveTemp(MaterialIndices), MoveTemp(OutFaceRemapPtr), MoveTemp(OutVertexRemapPtr)));

				// Propagate remapped indices from the FTriangleMeshImplicitObject back to the remap array
				CopyUpdatedFaceRemapFromTriangleMesh(*TriangleMesh.GetReference(), OutFaceRemap);

				return TriangleMesh;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/Experimental/ChaosCooking.cpp:319

Scope (from outer to inner):

file
namespace    Chaos
namespace    Cooking
function     void BuildTriangleMeshes
lambda-function

Source code excerpt:


				TUniquePtr<TArray<int32>> OutFaceRemapPtr = MakeUnique<TArray<int32>>(OutFaceRemap);
				TUniquePtr<TArray<int32>> OutVertexRemapPtr = Chaos::TriMeshPerPolySupport ? MakeUnique<TArray<int32>>(OutVertexRemap) : nullptr;
				Chaos::FTriangleMeshImplicitObject* TriangleMesh = new Chaos::FTriangleMeshImplicitObject(MoveTemp(TriMeshParticles), MoveTemp(Triangles), MoveTemp(MaterialIndices), MoveTemp(OutFaceRemapPtr), MoveTemp(OutVertexRemapPtr));
				OutTriangleMeshes.Emplace(TriangleMesh);

				// Propagate remapped indices from the FTriangleMeshImplicitObject back to the remap array
				CopyUpdatedFaceRemapFromTriangleMesh(*TriangleMesh, OutFaceRemap);
			};

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/TriangleMeshImplicitObject.cpp:26

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	// Note that if this is re-enabled when previously off, the cooked trimeshes won't have the vertex map serialized, so the change will not take effect until re-cooked.
	bool TriMeshPerPolySupport = 1;
	FAutoConsoleVariableRef CVarPerPolySupport(TEXT("p.Chaos.TriMeshPerPolySupport"), TriMeshPerPolySupport, TEXT("Disabling removes memory cost of vertex map on triangle mesh. Note: Changing at runtime will not work."));

	FReal GetWindingOrder(const FVec3& Scale)
	{
		const FVec3 SignVector = Scale.GetSignVector();
		return SignVector.X * SignVector.Y * SignVector.Z;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/TriangleMeshImplicitObject.cpp:1872

Scope (from outer to inner):

file
namespace    Chaos
function     FImplicitObjectPtr FTriangleMeshImplicitObject::CopySlowImpl

Source code excerpt:


	TUniquePtr<TArray<int32>> ExternalVertexIndexMapCopy = nullptr;
	if (ExternalVertexIndexMap && TriMeshPerPolySupport)
	{
		ExternalVertexIndexMapCopy = MakeUnique<TArray<int32>>(*ExternalVertexIndexMap.Get());
	}

	return FImplicitObjectPtr(new FTriangleMeshImplicitObject(MoveTemp(ParticlesCopy), MoveTemp(ElementsCopy), MoveTemp(MaterialIndicesCopy), MoveTemp(ExternalFaceIndexMapCopy), MoveTemp(ExternalVertexIndexMapCopy), bCullsBackFaceRaycast));
}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/TriangleMeshImplicitObject.cpp:2035

Scope (from outer to inner):

file
namespace    Chaos
function     void FTriangleMeshImplicitObject::UpdateVertices

Source code excerpt:

void FTriangleMeshImplicitObject::UpdateVertices(const TArray<FVector>& NewPositions)
{
	if(TriMeshPerPolySupport == false)
	{
		// We don't have vertex map, this will not be correct.
		ensure(false);
		return;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/TriangleMeshImplicitObject.h:28

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

namespace Chaos
{
	extern CHAOS_API bool TriMeshPerPolySupport;

	struct FMTDInfo;
	template <typename QueryGeomType>
	struct FTriangleMeshOverlapVisitorNoMTD;
	class FTriangleMeshImplicitObject;
	FArchive& operator<<(FArchive& Ar, FAABBVectorized& Bounds);