Docs / Fabric simulation

Glossary: PenetrationCheck

The members of PenetrationCheck, in alphabetical order.

Color legend method

Counts the pairs of points closer together than the cloth is thick: how badly the sheet passes through itself, which a screenshot can’t tell you.

A static class, in the namespace BorrowedTorch.FabricSimulator.Diagnostics. It works from the array of FabricEffect.ReadBack alone, through a spatial hash of its own: unbounded and exact-keyed, deliberately not the solver’s, so a pair the solver dropped from a full bucket, and so never tested, is still caught here. Where the two disagree, this one is right. It allocates freely: a debugging tool, not frame work. The diagnostics page shows it in context, with code.

Names are colored by what they are: a method; values and fields keep the plain color.

Fields

DeepOverlapRatio →

float · Constant, 0.25. The overlap, as a fraction of the thickness, past which a pair counts as one layer through another, in Result.Penetrations. Layers resting on each other sit right at the thickness, so only a deep overlap means a layer went through.

Methods

Run() →

Run(FabricParticle[] particles, int width, float thickness, uint[] tearState = null) · Static. Returns PenetrationCheck.Result: every pair of points closer than thickness, each pair once. Weave neighbors, the eight points around each one that a thread joins it to, are left out, since their threads hold them that close; across a torn thread they are lips of a rip, which the solver pushes apart like any contact, and are checked. Points that aren’t finite are skipped. Returns all zeros for an empty array, or for a thickness that isn’t positive and finite. Throws ArgumentNullException for a null array, and ArgumentException when width is below 1 or doesn’t divide the array into rows, or when the tear state’s length isn’t the array’s.

Parameter Type Description
particles FabricParticle[] The array from FabricEffect.ReadBack: fetch it once for every check you run.
width int The grid width the sheet was built with, Fabric.WidthInParticles.
thickness float The thickness the solver runs with, in meters: SelfCollisionThicknessRatio, at least 0.05, times Fabric.RestLength, the spacing as built. FabricSettings.SelfCollisionThickness uses the settings’ spacing instead, which can run ahead of the sheet until the next Rebuild.
tearState uint[] Fabric.CopyTearState on a torn sheet, so the lips of a rip count as touching cloth; null, the default, for a sheet never torn.