# raycasting-utils

> Fast utilities for ray-casting against triangles or boxes or a distance function / implicit surface

Latest version **0.0.214** (published 2023-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install raycasting-utils
pnpm add raycasting-utils
yarn add raycasting-utils
bun add raycasting-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.214 |
| Published | 2023-10-26 |
| First published | 2022-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | stonkpunk |
| Maintainers | stonkpunk |
| Keywords | raycasting, marching spheres |

## Links

- npm: https://www.npmjs.com/package/raycasting-utils
- Homepage: https://github.com/stonkpunk/my-npm-modules/tree/main/raycasting-utils
- npm.io page: https://npm.io/package/raycasting-utils

## Dependencies (2)

- [rbush-3d](https://npm.io/package/rbush-3d.md) 0.0.4
- [bvh-tree-plus](https://npm.io/package/bvh-tree-plus.md) ^1.0.2

## 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

- 0.0.214 (latest) — 2023-10-26
- 0.0.213 — 2022-11-04
- 0.0.212 — 2022-11-04
- 0.0.211 — 2022-06-21
- 0.0.21 — 2022-06-21
- 0.0.19 — 2022-06-21
- 0.0.18 — 2022-04-05
- 0.0.17 — 2022-04-05
- 0.0.16 — 2022-03-30
- 0.0.15 — 2022-03-30
- 0.0.14 — 2022-03-30
- 0.0.13 — 2022-03-30
- 0.0.12 — 2022-03-11
- 0.0.11 — 2022-03-10
- 0.0.1 — 2022-03-10

## README

# raycasting-utils

Fast utilities for ray-casting against sets of triangles, or a set of axis-aligned bounding boxes, or a distance function (implicit surface).

Triangles are organized using `bvh-tree-plus`

Boxes are organized using `rbush-3d`

Distance functions are queried using naive marching spheres.

## Installation

```sh
npm i raycasting-utils
```

## Usage 

```javascript
var rcu = require('raycasting-utils');

// aabb = [[x,y,z],[x,y,z]] //axis aligned bounding box = [minimum pt, maximum pt]
// ray = {point:{x,y,z}, vector: {x,y,z}} //raycasting direction 
// line = [[x,y,z],[x,y,z]] //raycasting direction using line segment coords instead of ray
// triangle = [[x,y,z],[x,y,z],[x,y,z]]

// functions ending with _useLine take a line segment instead of a ray object, but work the same

// rcu.traceDf(ray, df, maxSteps = 256, minDist = 0.05) //returns distance from raycasting distance function df, using marching spheres technique. bail out if dist<minDist 
// rcu.traceDf_useLine

// rcu.aabbsTraceFast([aabb]) => returns function(ray) which returns distance
// rcu.aabbsTraceFast_useLine

// rcu.aabbsTraceBVH([aabb]) => similar to aabbsTraceFast, but converts the boxes to triangles and casts using a BVH instead of the RTree. Usually slower.
// rcu.aabbsTraceBVH_useLine

// rcu.aabb2Triangles(aabb) => convert aabb to list of triangles

// rcu.trianglesTraceFast([tri], backfaceCulling=true) => similar to aabbsTraceFast, but for list of triangles 
// rcu.trianglesTraceFast_useLine

// rcu.trianglesTraceFast_returnIndex => similar to above, but returns {dist, index: indexOfTriangleThatGetsHit or -1}
// rcu.trianglesTraceFast_returnIndex_useLine

// rcu.trianglesTraceFast_colored => returns [dist, color] where color is pulled from triangle.color
// rcu.trianglesTraceFast_colored_useLine

// rcu.aabbs2RTree([aabb]) => convert list of aabbs to rtree, uses `npm rbush-3d`
// rcu.searchRTreeForAabbs(rtree, aabb) => search rtree generated by above, return list of aabbs found intersecting the queried aabb

// rcu.getBvh() => return most recently created BVH object
// rcu.getRtree() => return most recently created RTree object

// "sector" can be used as alias for aabb [ 没有为什么 ]
// rcu.sector2Triangles
// rcu.sectorsTraceBVH
// rcu.sectorsTraceBVH_useLine
// rcu.sectorsTraceFast
// rcu.sectorsTraceFast_useLine
// rcu.sectors2RTree
// rcu.searchRTreeForSectors
```


[![stonks](https://i.imgur.com/UpDxbfe.png)](https://www.npmjs.com/~stonkpunk)

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