public static class MeshDistanceFieldBakerTurns a triangle soup into a MeshDistanceField.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Two halves that fail for different reasons, so they are solved separately.
The distance is exact. Every sample takes the true distance to the nearest triangle from TriangleTree, not a propagated one. Sweeping a chamfer or vector distance transform over the grid is much faster and is the usual answer, and it is approximate in a way that is invisible until a tracer takes a step slightly too long and passes through a wall. An exact field is checkable against a closed form, which is the exit criterion this bake was written to meet.
The sign is voted on. The textbook answer — count how many times a ray crosses the surface, odd is inside — needs the mesh to be closed, and meshes are not closed. Artists ship facades with no back, walls that are one quad, and shells with holes where something else was meant to cover them, and a parity test on any of those inverts a whole region. So each sample casts rays in many directions and asks a softer question: how much of the sky, from here, is a face seen from behind? A point inside solid geometry sees backfaces almost everywhere; a point outside sees them almost nowhere; and a point under an open shell sees them over exactly the fraction of the sphere the shell covers, which is what BackfaceThreshold is a dial on. This is the approach Unreal takes for the same reason, and it degrades where parity inverts.
The directions are a Fibonacci sphere, not random. A spiral of SignRayCount points covers the sphere about as evenly as anything cheap does, and it takes no seed — so two bakes of one mesh are byte-identical without a random source having to be threaded through the bake and pinned. It also has no axis-aligned direction in it, which matters more than it sounds: a mesh made of axis-aligned quads is exactly the mesh an axis-aligned ray hits edge-on.
Methods (1)
public static MeshDistanceField Bake(ReadOnlySpan<Vector3> vertices, ReadOnlySpan<int> indices, DistanceFieldBuildSettings? options = null)Bakes a field over a triangle soup.
Used by (10)
- DistanceFieldInstanceTestsVixen.Rendering.DistanceFields.Tests
- DistanceFieldTracerTestsVixen.Rendering.DistanceFields.Tests
- GlobalDistanceFieldRendererTestsVixen.Rendering.Tests
- GlobalDistanceFieldTestsVixen.Rendering.DistanceFields.Tests
- MeshDistanceFieldBakerTestsVixen.Rendering.DistanceFields.Tests
- MeshDistanceFieldTestsVixen.Rendering.DistanceFields.Tests
- RenderedSceneTestsVixen.Rendering.DistanceFields.Tests
- SamplingConventionTestsVixen.Rendering.DistanceFields.Tests
- ScrollTestsVixen.Rendering.DistanceFields.Tests
- ModelImporterVixen.Editor.Assets