Playmaker.Spatial 0.1.1

dotnet add package Playmaker.Spatial --version 0.1.1
                    
NuGet\Install-Package Playmaker.Spatial -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Playmaker.Spatial" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Playmaker.Spatial" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Playmaker.Spatial" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Playmaker.Spatial --version 0.1.1
                    
#r "nuget: Playmaker.Spatial, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Playmaker.Spatial@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Playmaker.Spatial&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Playmaker.Spatial&version=0.1.1
                    
Install as a Cake Tool

Playmaker.Spatial

A tiny, fast 3D spatial partition for .NET using dynamic AABB tree (Also known as BVH) that you can trust to handle thousands of objects.

Quick example

Define your game object with a way to get a tight bounding box enclosing it. The library doesn't care about any other details.

using System;
using System.Numerics;
using Playmaker.Spatial;

public sealed class Asteroid : ISpatialObject
{
    public int Id { get; }
    public AABB Bounds { get; set; }

    public Asteroid(int id, Vector3 center)
    {
        Id = id;
        Bounds = AABB.FromCenterAndSize(center, new Vector3(1, 1, 1));
    }
}

var space = new SpatialPartition<Asteroid>();

var a = new Asteroid(1, new Vector3( 0, 0, 0));
var b = new Asteroid(2, new Vector3(10, 0, 0));

space.Insert(a);
space.Insert(b);

// AABB query
var nearOrigin = space.Query(AABB.FromCenterAndSize(Vector3.Zero, new Vector3(5, 5, 5))); // Or new AABB(min, max)

// First-hit raycast
var hitSomething = space.Raycast(new Ray(new Vector3(-5, 0, 0), Vector3.UnitX), out var hit);
if (hitSomething)
{
    // hit.Object is your Asteroid, hit.Distance is distance along the ray
}

// "Penetrating" raycast means keep going through volumes and collect every hit along the ray,
// sorted by entry distance. Like Unity's Physics.RaycastAll.
var allHits = space.RaycastPenetrating(new Ray(new Vector3(-5, 0, 0), Vector3.UnitX));
// Each hit has Object, Distance, and even EntryPoint/ExitPoint for effects like bullet holes.

// Move an object: you must call Update when the objects bounds change.
a.Bounds = AABB.FromCenterAndSize(new Vector3(2, 0, 0), new Vector3(1, 1, 1));
space.Update(a);

// snapshot the whole tree for debugging; you could hook this up to a UI or something.
var tree = space.GetTreeInfo();
if (tree is not null)
{
    Console.WriteLine(tree);
}

// Remove when gone
space.Remove(b);

A few details that matter

This class is not thread-safe. It’s fast enough to live on your main thread, but if you want to update/query from multiple threads, you're responsible to guard access.

There’s a small test project (Playmaker.Spatial.Tests) that exercises the real-world bits you’ll care about. Run them from the repo root:

dotnet test

License

This project is licensed under Mozilla Public License 2.0. See LICENSE

Attribution & thanks

This project stands on the shoulders of giants. The core idea is heavily inspired by the dynamic AABB tree in Box2D. We also learned significantly from Emmet O’Toole’s excellent Unity port, go read it:

https://github.com/EmmetOT/BoundingVolumeHierarchy/

Thank you for the groundwork and clarity. Any mistakes here are mine.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 175 8/21/2025
0.1.0 158 8/21/2025