0.2.4 • Published 2 years ago
frustum-intersects v0.2.4
Frustum-Intersects
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 --saveimport { 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)
matrixcamera's 4x4 projection view matrix array, compatible with gl-matrixboxthe aabb box, [minx, miny, minz, maxx, maxy, maxz]maskA 6 chars string mask (e.g."111111") of frustum planes, plane with mask of0will always returntrue
intersectsSphere(matrix, sphere, mask)
matrixcamera's 4x4 projection view matrix array, compatible with gl-matrixspheresphere, [centerx, centery, centerz, radius]maskA 6 chars string mask (e.g."111111") of frustum planes, plane with mask of0will always returntrue
the planes' order of mask is
{right}{left}{bottom}{top}{z-far}{z-near},