npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spatial-engine/core

v0.0.4

Published

High-performance spatial partitioning and query library using Data-Oriented Design

Readme

@spatial-engine/core

The foundation layer for spatial-engine, a high-performance spatial partitioning and query library using a Data-Oriented Design (DOD) approach. It provides cache-friendly, zero-GC spatial data structures backed by flat Float32Array pools.

Everything lives in contiguous memory: no per-object heap allocations, no mid-frame GC pauses.

Installation

npm install @spatial-engine/core
# or
pnpm add @spatial-engine/core

Features

  • Octree with automatic subdivision — insert, update, and remove axis-aligned bounding boxes.
  • Branchless slab-method raycast — fast rayIntersectsAABB implementation.
  • Box queryoctree.queryBox() returns all objects whose AABB overlaps a query region natively (iterative DFS, no recursion).
  • Zero GC PoolsAABBPool, RayPool, and OctreeNodePool allocate once and reuse. Call .reset() each frame.
  • LiDAR Web Worker — run a full multi-ray sweep entirely off the main thread using shared memory.
  • SharedArrayBuffer support — pools can be shared with Web Workers without copying data.

Basic Usage

import { AABBPool, RayPool, OctreeNodePool, Octree } from '@spatial-engine/core';

// --- 1. Allocate pools once (e.g. on startup) ---
const nodePool  = new OctreeNodePool(512);
const aabbPool  = new AABBPool(512);
const rayPool   = new RayPool(64);
const octree    = new Octree(nodePool, aabbPool);

octree.setBounds(-100, -100, -100, 100, 100, 100);

// --- 2. Each frame: reset pools and re-insert objects ---
nodePool.reset();
aabbPool.reset();

const idx = aabbPool.allocate();
aabbPool.set(idx, -1, -1, -1, 1, 1, 1); // minX,minY,minZ,maxX,maxY,maxZ
octree.insert(idx);

// --- 3. Raycast ---
const rayIdx = rayPool.allocate();
rayPool.set(rayIdx, 0, 0, -10, 0, 0, 1); // origin (0,0,-10), direction +Z

const rayBuf = (rayPool as any).buffer as Float32Array;
const hit = octree.raycast(rayBuf, rayIdx * 6);
// hit: { objectIndex: 0, t: 9 } | null

// --- 4. Box query ---
const hits = octree.queryBox(-2, -2, -2, 2, 2, 2);
// hits: [0]  (array of aabbPool indices)

LiDAR Web Worker

For scenes with many rays (e.g. simulated sensors), you can use the built-in worker implementation to run sweeps off the main thread using SharedArrayBuffer exports natively provided.

import { AABBPool, RayPool, OctreeNodePool } from '@spatial-engine/core';
import type { LidarInitMessage, LidarSweepMessage } from '@spatial-engine/core';
// Import the robust built in web worker
const worker = new Worker(new URL('@spatial-engine/core/lidar-worker', import.meta.url), { type: 'module' });

(See root monorepo README for full worker example code).

Use Cases

  • Game collision broad-phase: queryBox for candidate pairs
  • Frustum culling: raycast or queryBox to cull objects
  • LiDAR sensor simulation: createLidarProcessor off thread
  • Physics broad-phase: Find overlap candidates before narrow-phase