0.2.4 • Published 10 months ago

frustum-intersects v0.2.4

Weekly downloads
412
License
MIT
Repository
github
Last release
10 months ago

Frustum-Intersects

NPM Version CircleCI

A zero-dependency lib extracted from THREE.js to determine if camera's frustum intersects with given box or sphere.

Usage

npm

npm i frustum-intersects --save
import { intersectsBox, intersectsSphere } from 'frustum-intersects';

const ret = intersectsBox([
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1],
           [[-1,-1,-1], [1,1,1]]);

const ret2 = intersectsSphere([
            1, 0, 0, 0,
            0, 1, 0, 0,
            0, 0, 1, 0,
            0, 0, 0, 1],
           [[0, 0, 0], 1]);

Browser

<script src="https://cdn.jsdelivr.net/npm/frustum-intersects/dist/frustum-intersects.js"></script>

<script>
const ret = frustum.intersectsBox(matrix, box);
</script>

API

intersectsBox(matrix, box, mask)

  • matrix camera's 4x4 projection view matrix array, compatible with gl-matrix
  • box the aabb box, [minx, miny, minz, maxx, maxy, maxz]
  • mask A 6 chars string mask (e.g. "111111") of frustum planes, plane with mask of 0 will always return true

intersectsSphere(matrix, sphere, mask)

  • matrix camera's 4x4 projection view matrix array, compatible with gl-matrix
  • sphere sphere, [centerx, centery, centerz, radius]
  • mask A 6 chars string mask (e.g. "111111") of frustum planes, plane with mask of 0 will always return true

the planes' order of mask is {right}{left}{bottom}{top}{z-far}{z-near},