Docs / Fabric simulation

Glossary: FabricSurface

The members of FabricSurface, in alphabetical order.

Color legend plain property method

One pose of the sheet to pick against: the triangles the renderer draws, lips and seams included, frozen where they stood. It turns a world-space ray into the flat-sheet point Fabric.Cut takes, which on crumpled cloth only the current triangles can tell.

A sealed class with no public constructor: Fabric.CaptureSurface makes one, at the cost of a GPU readback, so capture one per gesture rather than per ray; a FabricStroke holds one for a knife’s drag. It picks against CreateCutMesh’s triangles, so what can be picked is exactly what that mesh draws. The capture also files the triangles into a uniform grid, so a ray costs the cloth it passes near rather than the whole sheet. Nothing changes after that: any number of threads may pick against one surface at once, and it keeps answering for the pose it was captured in however far the sheet has moved on. Cameras stay out of it: unproject a screen point with your own view and projection, and pass the ray. The picking page shows it in context, with code.

A surface belongs to the sheet and the build it was captured from: Fabric.Cut throws for one from another sheet or from before the last Rebuild. Its own methods don’t check, so hits gathered with them are yours to drop when Rebuilt is raised.

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

Properties

TriangleCount →

int · Read-only. The triangles in the pose, as the cut mesh had them when it was captured. Triangles with a corner that has diverged to infinity or NaN are counted, but never picked: such a point has nowhere to be.

Methods

Raycast() →

Raycast(Ray ray, Span<FabricSurfaceHit> hits) · Returns int: how many hits it wrote. Every layer of cloth the ray passes through, nearest first. A crumpled sheet stacks several layers under one point, a hard press eight or more, and which of them a knife takes is yours to decide: the nearest is a blade, all of them are scissors, and Distance carries the depth for anything in between. Each layer counts once, even where the ray threads an edge or a corner two triangles share, or the closed lips of a cut. Triangles are hit from either side. The ray runs from its origin forward with no far end, and its direction need not be of length 1. When the span is full, the furthest hits are dropped: it keeps the nearest hits.Length. A ray with no direction, zero or not finite, or an origin that isn’t finite meets nothing, and so does any ray when the span is empty or nothing in the pose is pickable.

Parameter Type Description
ray Ray In world space, from your camera: Viewport.Unproject of a screen point at depth 0 and 1, the direction the second minus the first.
hits Span<FabricSurfaceHit> Filled from the start, nearest first; its length is the most layers wanted. A stackalloc of 16 covers a crushed pile.

TryRaycast() →

TryRaycast(Ray ray, out FabricSurfaceHit hit) · Returns bool: whether the ray meets the cloth. The nearest layer alone, a blade’s: Raycast with room for one hit. What FabricStroke.Add picks with.

Parameter Type Description
ray Ray In world space; any direction length.
hit out FabricSurfaceHit The nearest layer’s hit, or default, every value 0, on a miss.