# fast-voxel-raycast

> Fast raycasting through voxels

Latest version **0.1.1** (published 2015-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-voxel-raycast
pnpm add fast-voxel-raycast
yarn add fast-voxel-raycast
bun add fast-voxel-raycast
```

## 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.1.1 |
| Published | 2015-10-18 |
| First published | 2015-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 75 |
| Author | Andy Hall |
| Maintainers | andyhall |
| Keywords | voxel, raycast |

## Links

- npm: https://www.npmjs.com/package/fast-voxel-raycast
- Repository: https://github.com/andyhall/fast-voxel-raycast
- Homepage: https://github.com/andyhall/fast-voxel-raycast#readme
- Issues: https://github.com/andyhall/fast-voxel-raycast/issues
- npm.io page: https://npm.io/package/fast-voxel-raycast

## Recent versions

- 0.1.1 (latest) — 2015-10-18
- 0.1.0 — 2015-10-18

## README

## fast-voxel-raycast

Fast raycasting through voxels.

This is a fork of [voxel-raycast](https://github.com/mikolalysenko/voxel-raycast), 
using the faster, simpler algorithm described in 
[this paper](http://www.cse.chalmers.se/edu/year/2010/course/TDA361/grid.pdf)
by Amanatides and Woo.

In general it functions equivalently to the parent library, except for 
edge cases (e.g. when the raycast precisely touches the corner of a solid voxel),
in which case no particular behavior is defined.

### Installation

    npm install fast-voxel-raycast
    
### Usage

```js
var raycast = require('fast-voxel-raycast')

raycast( getVoxel, start, direction, distance, hit_position, hit_normal )
```

* `getVoxel` - a `function(x,y,z)` that returns a truthy value for whether each voxel should block the raycast
* `start` - origin of the ray
* `direction` - direction of the ray
* `distance` - how far to check the ray before giving up
* `hit_position` - result array, gets populated with the point of impact
* `hit_normal` - gets populated with a normal vector pointing away from the voxel that was struck 

**Returns:**  whatever value was returned by the `getVoxel` function for the struck voxel, 
or `0` if no voxel was struck.

### Example

```js
var raycast = require('fast-voxel-raycast')

var getVoxel = function(x,y,z) {
    // return a truthy value here for voxels that block the raycast
    return (y<0) ? 1 : 0
}

var hit_position = []
var hit_normal = []

var result = raycast( getVoxel, [3,4,5], [1,-1,-1], 20, hit_position, hit_normal )

if (result != 0) {
    console.log('hit:', result, hit_position, hit_normal)
} else {
    console.log('no truthy voxel was struck')
}
```

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