Skip to content

v0.2.0-spatial

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 23 Nov 18:31
· 3 commits to main since this release

Experimental. Spatial is a work in progress: its API and its baked format may change, or it may be removed if it doesn't work out. Everything else here is the same code as v0.2.0, versioned 0.2.0-spatial.

Spatial answers questions about space from Unity jobs or plain .NET, without allocating: which of many boxes are near a point, and, for geometry that doesn't move, how much room there is and how a body gets from here to there. The same source builds as a .NET library and inside a Unity package, and gives the same bytes on .NET 8, Unity's Mono, Burst and IL2CPP.

Boxes

  • A scan and a box tree find the boxes within a radius of a point and the nearest ones. The tree sorts boxes along a Hilbert curve, so each node is one compact lump of space: against a Morton order, a third fewer nodes visited per query on boxes spread through a volume.
  • BoxSet (Unity) holds items by your id in native arrays. Add, Remove and Move only note a change; Schedule applies them in one Burst job and rebuilds the tree, and queries run as jobs after it.

A grid of fixed geometry

Four layers, each built on the one before:

Layer Answers
Wall distance How much room at this point? RoomAt reads eight cells and gives a distance the nearest shape is proven to be at least. Shapes (boxes, spheres, capsules, triangles) are baked once into a block of bytes.
Regions Where can a body of this radius be, and which of those places join? Doors narrower than the body cut rooms off.
Travel fields Which way to a goal, for many bodies at once? Fast marching gives a distance near the straight line; per-cell costs bend it.
Routes The way for one body, as a few straight legs, each proven clear for the body's full radius. A leeway (a tenth by default) trades a little length for far less searching.

In Unity, WallGrid owns the grid in native arrays and fills it in Burst jobs; ColliderShapes turns colliders into shapes; WallGridField and WallGridRoute serve fields and routes from jobs.

Downloads

  • xyz.yewnyx.spatial-0.2.0-spatial.tgz: the Unity package (Unity 6000.3, Burst, Collections, Mathematics). In the Package Manager: + → Add package from tarball…. It includes a sample with moving boxes.
  • Yewnyx.Spatial 0.2.0-spatial: the NuGet package for netstandard2.1 and net8.0, with a symbol package. The other four libraries are here at 0.2.0-spatial too, the same code as 0.2.0.
  • AlgorithmsVisualizer-v0.2.0-spatial-win-x64.zip, …-linux-x64.tar.gz: the desktop Visualizer with the Spatial and Spatial grid tabs. The same build runs in the browser at https://yewnyx.github.io/Algorithms/.

Not every public member of Spatial has XML documentation yet.

Full Changelog: v0.2.0...v0.2.0-spatial