# sparse-octree

> A sparse octree data structure.

Latest version **7.2.0** (published 2026-06-28) · Zlib license · 0 weekly downloads

## Install

```sh
npm install sparse-octree
pnpm add sparse-octree
yarn add sparse-octree
bun add sparse-octree
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.2.0 |
| Published | 2026-06-28 |
| First published | 2016-05-15 |
| Weekly downloads | 0 |
| License | Zlib |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 57.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 128 |
| Author | Raoul van Rüschen |
| Maintainers | vanruesc |
| Keywords | partition, hierarchy, subdivision, raycasting, 3d, spatial, voxel, points, frustum, culling, pointer |

## Links

- npm: https://www.npmjs.com/package/sparse-octree
- Repository: https://github.com/vanruesc/sparse-octree
- Issues: https://github.com/vanruesc/sparse-octree/issues
- npm.io page: https://npm.io/package/sparse-octree

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 7.2.0 (latest) — 2026-06-28
- 7.1.8 — 2023-06-04
- 7.1.7 — 2023-06-04
- 7.1.6 — 2022-08-22
- 7.1.5 — 2022-02-26
- 7.1.4 — 2021-12-06
- 7.1.3 — 2021-10-28
- 7.1.2 — 2021-09-30
- 7.1.1 — 2021-09-20
- 7.1.0 — 2021-09-18
- 7.0.7 — 2021-09-15
- 7.0.6 — 2021-08-30
- 7.0.5 — 2021-07-30
- 7.0.4 — 2021-06-30
- 7.0.3 — 2021-05-30
- … 49 more at https://npm.io/package/sparse-octree/versions

## README

# Sparse Octree

[![CI](https://github.com/vanruesc/sparse-octree/actions/workflows/ci.yml/badge.svg)](https://github.com/vanruesc/sparse-octree/actions/workflows/ci.yml)
[![Version](https://badgen.net/npm/v/sparse-octree?color=green)](https://www.npmjs.com/package/sparse-octree)

A sparse, pointer-based octree data structure. For a linear implementation see [linear-octree](https://github.com/vanruesc/linear-octree).

*[Demo](https://vanruesc.github.io/sparse-octree/demo)&ensp;&middot;&ensp;[Sandbox](https://codesandbox.io/s/sparse-octree-3yn8o)&ensp;&middot;&ensp;[Documentation](https://vanruesc.github.io/sparse-octree/docs)*

## Installation

This library requires the peer dependency [three](https://github.com/mrdoob/three.js/).

```sh
npm install three sparse-octree
``` 

## Usage

##### Points

```js
import { Vector3 } from "three";
import { PointOctree } from "sparse-octree";

const min = new Vector3(-1, -1, -1);
const max = new Vector3(1, 1, 1);

const octree = new PointOctree(min, max);

const myData = {};
const p1 = new Vector3(0, 0, 0);
const p2 = new Vector3(0, 0, 0.5);

octree.set(p1, myData);
octree.move(p1, p2);
octree.get(p2); // => myData

octree.remove(p2);
octree.get(p2); // => null
```

##### Custom Octrees

```js
import { Octree, CubicOctant } from "sparse-octree";

export class CubicOctree extends Octree {

	constructor(min, size) {

		this.root = new CubicOctant(min, size);

	}

}
```

## Features

- Pointer-based structure
  - Handles octant splitting
  - Supports cubic octrees for reduced memory usage
  - Dynamic depth
- Adheres to a [common octant layout](https://vanruesc.github.io/sparse-octree/docs/variables/layout.html)
- Supports raycasting
- Supports culling
- Can be extended to manage any data
- Provides a point management implementation

## Contributing

Maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

---
_Source: https://npm.io/package/sparse-octree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
