@math.gl/culling 3.5.6 → 3.6.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/es5/constants.js +7 -5
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/index.js +0 -12
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +12 -6
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +8 -4
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/es5/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +4 -0
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +6 -20
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +17 -7
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +17 -5
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +5 -1
- package/dist/es5/lib/plane.js.map +1 -1
- package/dist/esm/constants.js +7 -5
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js +15 -6
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js +9 -4
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/esm/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js +5 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/esm/lib/culling-volume.js +10 -16
- package/dist/esm/lib/culling-volume.js.map +1 -1
- package/dist/esm/lib/perspective-frustum.js +31 -5
- package/dist/esm/lib/perspective-frustum.js.map +1 -1
- package/dist/esm/lib/perspective-off-center-frustum.js +31 -3
- package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/esm/lib/plane.js +6 -1
- package/dist/esm/lib/plane.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/{src → dist}/lib/algorithms/bounding-box-from-points.d.ts +3 -10
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.js +131 -0
- package/dist/{esm/lib → lib}/algorithms/bounding-sphere-from-points.d.ts +2 -5
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.js +140 -0
- package/dist/{es5/lib → lib}/algorithms/compute-eigen-decomposition.d.ts +7 -9
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js +131 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +111 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.js +118 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.js +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +67 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +256 -0
- package/dist/lib/culling-volume.d.ts +46 -0
- package/dist/lib/culling-volume.d.ts.map +1 -0
- package/dist/lib/culling-volume.js +121 -0
- package/dist/lib/perspective-frustum.d.ts +140 -0
- package/dist/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-frustum.js +205 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +122 -0
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-off-center-frustum.js +305 -0
- package/dist/lib/plane.d.ts +26 -0
- package/dist/lib/plane.d.ts.map +1 -0
- package/dist/lib/plane.js +63 -0
- package/package.json +5 -5
- package/src/constants.ts +8 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/lib/algorithms/{bounding-box-from-points.js → bounding-box-from-points.ts} +17 -4
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +15 -3
- package/src/lib/algorithms/{compute-eigen-decomposition.js → compute-eigen-decomposition.ts} +40 -1
- package/src/lib/bounding-volumes/{axis-aligned-bounding-box.js → axis-aligned-bounding-box.ts} +45 -14
- package/src/lib/bounding-volumes/{bounding-sphere.js → bounding-sphere.ts} +44 -29
- package/src/lib/bounding-volumes/{bounding-volume.d.ts → bounding-volume.ts} +7 -7
- package/src/lib/bounding-volumes/{oriented-bounding-box.js → oriented-bounding-box.ts} +72 -14
- package/src/lib/{culling-volume.js → culling-volume.ts} +42 -34
- package/src/lib/{perspective-frustum.js → perspective-frustum.ts} +48 -66
- package/src/lib/{perspective-off-center-frustum.js → perspective-off-center-frustum.ts} +24 -14
- package/src/lib/{plane.js → plane.ts} +24 -17
- package/dist/es5/constants.d.ts +0 -6
- package/dist/es5/index.d.ts +0 -20
- package/dist/es5/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/es5/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/es5/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/es5/lib/culling-volume.d.ts +0 -55
- package/dist/es5/lib/plane.d.ts +0 -38
- package/dist/esm/constants.d.ts +0 -6
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/esm/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/esm/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/esm/lib/culling-volume.d.ts +0 -55
- package/dist/esm/lib/plane.d.ts +0 -38
- package/src/constants.d.ts +0 -6
- package/src/constants.js +0 -8
- package/src/index.d.ts +0 -20
- package/src/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/src/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/src/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/src/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/src/lib/culling-volume.d.ts +0 -55
- package/src/lib/plane.d.ts +0 -38
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
4
|
/* eslint-disable */
|
|
5
|
-
import {Vector3,
|
|
5
|
+
import {Vector3, assert} from '@math.gl/core';
|
|
6
6
|
import {INTERSECTION} from '../constants';
|
|
7
7
|
import Plane from './plane';
|
|
8
|
+
import type {BoundingVolume} from './bounding-volumes/bounding-volume';
|
|
9
|
+
import type BoundingSphere from './bounding-volumes/bounding-sphere';
|
|
8
10
|
|
|
9
11
|
// X, Y, Z Unit vectors
|
|
10
12
|
const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];
|
|
@@ -13,35 +15,42 @@ const scratchPlaneCenter = new Vector3();
|
|
|
13
15
|
const scratchPlaneNormal = new Vector3();
|
|
14
16
|
const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
/** A culling volume defined by planes. */
|
|
17
19
|
export default class CullingVolume {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/**
|
|
21
|
+
* For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
|
|
22
|
+
* represents the case where the object bounding volume is entirely outside the culling volume.
|
|
23
|
+
*/
|
|
24
|
+
static MASK_OUTSIDE = 0xffffffff;
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
|
|
28
|
+
* represents the case where the object bounding volume is entirely inside the culling volume.
|
|
29
|
+
*/
|
|
30
|
+
static MASK_INSIDE = 0x00000000;
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
/**
|
|
33
|
+
* For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
|
|
34
|
+
* represents the case where the object bounding volume (may) intersect all planes of the culling volume.
|
|
35
|
+
*/
|
|
36
|
+
static MASK_INDETERMINATE = 0x7fffffff;
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
/** Array of clipping planes. */
|
|
39
|
+
readonly planes: Plane[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
43
|
+
* @param planes Array of clipping planes.
|
|
44
|
+
* */
|
|
45
|
+
constructor(planes: Plane[] = []) {
|
|
38
46
|
this.planes = planes;
|
|
39
|
-
assert(this.planes.every((plane) => plane instanceof Plane));
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
|
|
51
|
+
* The planes are aligned to the x, y, and z axes in world coordinates.
|
|
52
|
+
*/
|
|
53
|
+
fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {
|
|
45
54
|
this.planes.length = 2 * faces.length;
|
|
46
55
|
|
|
47
56
|
const center = boundingSphere.center;
|
|
@@ -79,9 +88,8 @@ export default class CullingVolume {
|
|
|
79
88
|
return this;
|
|
80
89
|
}
|
|
81
90
|
|
|
82
|
-
|
|
83
|
-
computeVisibility(boundingVolume) {
|
|
84
|
-
assert(boundingVolume);
|
|
91
|
+
/** Determines whether a bounding volume intersects the culling volume. */
|
|
92
|
+
computeVisibility(boundingVolume: BoundingVolume): INTERSECTION {
|
|
85
93
|
// const planes = this.planes;
|
|
86
94
|
let intersect = INTERSECTION.INSIDE;
|
|
87
95
|
for (const plane of this.planes) {
|
|
@@ -103,15 +111,15 @@ export default class CullingVolume {
|
|
|
103
111
|
return intersect;
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
114
|
+
/**
|
|
115
|
+
* Determines whether a bounding volume intersects the culling volume.
|
|
116
|
+
*
|
|
117
|
+
* @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
|
|
118
|
+
* volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
|
|
119
|
+
* the parent (and therefore this) volume is completely inside plane[planeIndex]
|
|
120
|
+
* and that plane check can be skipped.
|
|
112
121
|
*/
|
|
113
|
-
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
114
|
-
assert(boundingVolume, 'boundingVolume is required.');
|
|
122
|
+
computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {
|
|
115
123
|
assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
|
|
116
124
|
|
|
117
125
|
if (
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
// @ts-nocheck
|
|
9
9
|
|
|
10
|
-
import {assert} from '@math.gl/core';
|
|
10
|
+
import {assert, Matrix4} from '@math.gl/core';
|
|
11
11
|
import PerspectiveOffCenterFrustum from './perspective-off-center-frustum';
|
|
12
12
|
|
|
13
13
|
const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
@@ -40,7 +40,47 @@ const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
|
40
40
|
* @see PerspectiveOffCenterFrustum
|
|
41
41
|
*/
|
|
42
42
|
export default class PerspectiveFrustum {
|
|
43
|
-
|
|
43
|
+
_offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
44
|
+
/**
|
|
45
|
+
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
46
|
+
* as the horizontal FOV if the width is greater than the height, otherwise
|
|
47
|
+
* it will be the vertical FOV.
|
|
48
|
+
*/
|
|
49
|
+
fov: number;
|
|
50
|
+
_fov;
|
|
51
|
+
_fovy;
|
|
52
|
+
_sseDenominator;
|
|
53
|
+
/**
|
|
54
|
+
* The aspect ratio of the frustum's width to it's height.
|
|
55
|
+
*/
|
|
56
|
+
aspectRatio: number;
|
|
57
|
+
_aspectRatio;
|
|
58
|
+
/**
|
|
59
|
+
* The distance of the near plane.
|
|
60
|
+
* @default 1.0
|
|
61
|
+
*/
|
|
62
|
+
near: number;
|
|
63
|
+
_near;
|
|
64
|
+
/**
|
|
65
|
+
* The distance of the far plane.
|
|
66
|
+
* @default 500000000.0
|
|
67
|
+
*/
|
|
68
|
+
far: number;
|
|
69
|
+
_far;
|
|
70
|
+
/**
|
|
71
|
+
* Offsets the frustum in the x direction.
|
|
72
|
+
* @default 0.0
|
|
73
|
+
*/
|
|
74
|
+
xOffset: number;
|
|
75
|
+
_xOffset;
|
|
76
|
+
/**
|
|
77
|
+
* Offsets the frustum in the y direction.
|
|
78
|
+
* @default 0.0
|
|
79
|
+
*/
|
|
80
|
+
yOffset: number;
|
|
81
|
+
_yOffset;
|
|
82
|
+
|
|
83
|
+
constructor(options: Record<string, any> = {}) {
|
|
44
84
|
options = {
|
|
45
85
|
near: 1.0,
|
|
46
86
|
far: 500000000.0,
|
|
@@ -49,69 +89,27 @@ export default class PerspectiveFrustum {
|
|
|
49
89
|
...options
|
|
50
90
|
};
|
|
51
91
|
|
|
52
|
-
this._offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
56
|
-
* as the horizontal FOV if the width is greater than the height, otherwise
|
|
57
|
-
* it will be the vertical FOV.
|
|
58
|
-
* @type {Number}
|
|
59
|
-
* @default undefined
|
|
60
|
-
*/
|
|
61
92
|
this.fov = options.fov;
|
|
62
|
-
this._fov = undefined;
|
|
63
|
-
this._fovy = undefined;
|
|
64
93
|
|
|
65
|
-
this._sseDenominator = undefined;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The aspect ratio of the frustum's width to it's height.
|
|
69
|
-
* @type {Number}
|
|
70
|
-
* @default undefined
|
|
71
|
-
*/
|
|
72
94
|
this.aspectRatio = options.aspectRatio;
|
|
73
|
-
this._aspectRatio = undefined;
|
|
74
95
|
|
|
75
|
-
/**
|
|
76
|
-
* The distance of the near plane.
|
|
77
|
-
* @type {Number}
|
|
78
|
-
* @default 1.0
|
|
79
|
-
*/
|
|
80
96
|
this.near = options.near;
|
|
81
97
|
this._near = this.near;
|
|
82
98
|
|
|
83
|
-
/**
|
|
84
|
-
* The distance of the far plane.
|
|
85
|
-
* @type {Number}
|
|
86
|
-
* @default 500000000.0
|
|
87
|
-
*/
|
|
88
99
|
this.far = options.far;
|
|
89
100
|
this._far = this.far;
|
|
90
101
|
|
|
91
|
-
/**
|
|
92
|
-
* Offsets the frustum in the x direction.
|
|
93
|
-
* @type {Number}
|
|
94
|
-
* @default 0.0
|
|
95
|
-
*/
|
|
96
102
|
this.xOffset = options.xOffset;
|
|
97
103
|
this._xOffset = this.xOffset;
|
|
98
104
|
|
|
99
|
-
/**
|
|
100
|
-
* Offsets the frustum in the y direction.
|
|
101
|
-
* @type {Number}
|
|
102
|
-
* @default 0.0
|
|
103
|
-
*/
|
|
104
105
|
this.yOffset = options.yOffset;
|
|
105
106
|
this._yOffset = this.yOffset;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
* Returns a duplicate of a PerspectiveFrustum instance.
|
|
110
|
-
*
|
|
111
|
-
* @param {PerspectiveFrustum} [result] The object onto which to store the result.
|
|
112
|
-
* @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.
|
|
113
111
|
*/
|
|
114
|
-
clone() {
|
|
112
|
+
clone(): PerspectiveFrustum {
|
|
115
113
|
return new PerspectiveFrustum({
|
|
116
114
|
aspectRatio: this.aspectRatio,
|
|
117
115
|
fov: this.fov,
|
|
@@ -123,11 +121,8 @@ export default class PerspectiveFrustum {
|
|
|
123
121
|
/**
|
|
124
122
|
* Compares the provided PerspectiveFrustum componentwise and returns
|
|
125
123
|
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
126
|
-
*
|
|
127
|
-
* @param {PerspectiveFrustum} [other] The right hand side PerspectiveFrustum.
|
|
128
|
-
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
129
124
|
*/
|
|
130
|
-
equals(other) {
|
|
125
|
+
equals(other: PerspectiveFrustum): boolean {
|
|
131
126
|
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
132
127
|
return false;
|
|
133
128
|
}
|
|
@@ -146,45 +141,32 @@ export default class PerspectiveFrustum {
|
|
|
146
141
|
|
|
147
142
|
/**
|
|
148
143
|
* Gets the perspective projection matrix computed from the view frustum.
|
|
149
|
-
* @memberof PerspectiveFrustum.prototype
|
|
150
|
-
* @type {Matrix4}
|
|
151
|
-
* @readonly
|
|
152
144
|
*/
|
|
153
|
-
get projectionMatrix() {
|
|
145
|
+
get projectionMatrix(): Matrix4 {
|
|
154
146
|
update(this);
|
|
155
147
|
return this._offCenterFrustum.projectionMatrix;
|
|
156
148
|
}
|
|
157
149
|
|
|
158
150
|
/**
|
|
159
151
|
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
160
|
-
* @memberof PerspectiveFrustum.prototype
|
|
161
|
-
* @type {Matrix4}
|
|
162
|
-
* @readonly
|
|
163
|
-
*
|
|
164
|
-
* @see PerspectiveFrustum#projectionMatrix
|
|
165
152
|
*/
|
|
166
|
-
get infiniteProjectionMatrix() {
|
|
153
|
+
get infiniteProjectionMatrix(): Matrix4 {
|
|
167
154
|
update(this);
|
|
168
155
|
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
169
156
|
}
|
|
170
157
|
|
|
171
158
|
/**
|
|
172
159
|
* Gets the angle of the vertical field of view, in radians.
|
|
173
|
-
* @memberof PerspectiveFrustum.prototype
|
|
174
|
-
* @type {Number}
|
|
175
|
-
* @readonly
|
|
176
|
-
* @default undefined
|
|
177
160
|
*/
|
|
178
|
-
get fovy() {
|
|
161
|
+
get fovy(): number {
|
|
179
162
|
update(this);
|
|
180
163
|
return this._fovy;
|
|
181
164
|
}
|
|
182
165
|
|
|
183
166
|
/**
|
|
184
|
-
* @readonly
|
|
185
167
|
* @private
|
|
186
168
|
*/
|
|
187
|
-
get sseDenominator() {
|
|
169
|
+
get sseDenominator(): number {
|
|
188
170
|
update(this);
|
|
189
171
|
return this._sseDenominator;
|
|
190
172
|
}
|
|
@@ -18,6 +18,29 @@ const scratchPlaneFarCenter = new Vector3();
|
|
|
18
18
|
const scratchPlaneNormal = new Vector3();
|
|
19
19
|
|
|
20
20
|
export default class PerspectiveOffCenterFrustum {
|
|
21
|
+
left;
|
|
22
|
+
_left;
|
|
23
|
+
right;
|
|
24
|
+
_right;
|
|
25
|
+
top;
|
|
26
|
+
_top;
|
|
27
|
+
bottom;
|
|
28
|
+
_bottom;
|
|
29
|
+
near;
|
|
30
|
+
_near;
|
|
31
|
+
far;
|
|
32
|
+
_far;
|
|
33
|
+
_cullingVolume = new CullingVolume([
|
|
34
|
+
new Plane(),
|
|
35
|
+
new Plane(),
|
|
36
|
+
new Plane(),
|
|
37
|
+
new Plane(),
|
|
38
|
+
new Plane(),
|
|
39
|
+
new Plane()
|
|
40
|
+
]);
|
|
41
|
+
_perspectiveMatrix = new Matrix4();
|
|
42
|
+
_infinitePerspective = new Matrix4();
|
|
43
|
+
|
|
21
44
|
/**
|
|
22
45
|
* The viewing frustum is defined by 6 planes.
|
|
23
46
|
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
@@ -47,7 +70,7 @@ export default class PerspectiveOffCenterFrustum {
|
|
|
47
70
|
*
|
|
48
71
|
* @see PerspectiveFrustum
|
|
49
72
|
*/
|
|
50
|
-
constructor(options = {}) {
|
|
73
|
+
constructor(options: Record<string, any> = {}) {
|
|
51
74
|
options = {near: 1.0, far: 500000000.0, ...options};
|
|
52
75
|
|
|
53
76
|
/**
|
|
@@ -97,17 +120,6 @@ export default class PerspectiveOffCenterFrustum {
|
|
|
97
120
|
*/
|
|
98
121
|
this.far = options.far;
|
|
99
122
|
this._far = this.far;
|
|
100
|
-
|
|
101
|
-
this._cullingVolume = new CullingVolume([
|
|
102
|
-
new Plane(),
|
|
103
|
-
new Plane(),
|
|
104
|
-
new Plane(),
|
|
105
|
-
new Plane(),
|
|
106
|
-
new Plane(),
|
|
107
|
-
new Plane()
|
|
108
|
-
]);
|
|
109
|
-
this._perspectiveMatrix = new Matrix4();
|
|
110
|
-
this._infinitePerspective = new Matrix4();
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/**
|
|
@@ -149,7 +161,6 @@ export default class PerspectiveOffCenterFrustum {
|
|
|
149
161
|
* Gets the perspective projection matrix computed from the view frustum.
|
|
150
162
|
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
151
163
|
* @type {Matrix4}
|
|
152
|
-
* @readonly
|
|
153
164
|
*
|
|
154
165
|
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
|
|
155
166
|
*/
|
|
@@ -162,7 +173,6 @@ export default class PerspectiveOffCenterFrustum {
|
|
|
162
173
|
* Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
163
174
|
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
164
175
|
* @type {Matrix4}
|
|
165
|
-
* @readonly
|
|
166
176
|
*
|
|
167
177
|
* @see PerspectiveOffCenterFrustum#projectionMatrix
|
|
168
178
|
*/
|
|
@@ -9,61 +9,68 @@ const scratchNormal = new Vector3();
|
|
|
9
9
|
|
|
10
10
|
// A plane in Hessian Normal Form
|
|
11
11
|
export default class Plane {
|
|
12
|
-
|
|
12
|
+
readonly normal: Vector3;
|
|
13
|
+
distance: number;
|
|
14
|
+
|
|
15
|
+
constructor(normal: readonly number[] = [0, 0, 1], distance: number = 0) {
|
|
13
16
|
this.normal = new Vector3();
|
|
14
17
|
this.distance = -0;
|
|
15
18
|
this.fromNormalDistance(normal, distance);
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
22
|
+
fromNormalDistance(normal: readonly number[], distance: number): this {
|
|
19
23
|
assert(Number.isFinite(distance));
|
|
20
24
|
this.normal.from(normal).normalize();
|
|
21
25
|
this.distance = distance;
|
|
22
26
|
return this;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
fromPointNormal(point, normal) {
|
|
29
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
30
|
+
fromPointNormal(point: readonly number[], normal: readonly number[]): this {
|
|
27
31
|
point = scratchPosition.from(point);
|
|
28
32
|
this.normal.from(normal).normalize();
|
|
29
33
|
const distance = -this.normal.dot(point);
|
|
30
34
|
this.distance = distance;
|
|
31
|
-
|
|
32
35
|
return this;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
fromCoefficients(a, b, c, d) {
|
|
38
|
+
/** Creates a plane from the general equation */
|
|
39
|
+
fromCoefficients(a: number, b: number, c: number, d: number): this {
|
|
37
40
|
this.normal.set(a, b, c);
|
|
38
41
|
assert(equals(this.normal.len(), 1));
|
|
39
42
|
this.distance = d;
|
|
40
43
|
return this;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
clone(
|
|
46
|
+
/** Duplicates a Plane instance. */
|
|
47
|
+
clone(): Plane {
|
|
45
48
|
return new Plane(this.normal, this.distance);
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
equals(right) {
|
|
51
|
+
/** Compares the provided Planes by normal and distance */
|
|
52
|
+
equals(right: Plane): boolean {
|
|
50
53
|
return equals(this.distance, right.distance) && equals(this.normal, right.normal);
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
57
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
58
|
+
*/
|
|
59
|
+
getPointDistance(point: readonly number[]): number {
|
|
56
60
|
return this.normal.dot(point) + this.distance;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
transform(matrix4) {
|
|
63
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
64
|
+
transform(matrix4: readonly number[]): this {
|
|
61
65
|
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
62
66
|
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
63
67
|
return this.fromPointNormal(point, normal);
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
|
|
70
|
+
/** Projects a point onto the plane. */
|
|
71
|
+
projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;
|
|
72
|
+
projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];
|
|
73
|
+
|
|
67
74
|
projectPointOntoPlane(point, result = [0, 0, 0]) {
|
|
68
75
|
point = scratchPosition.from(point);
|
|
69
76
|
// projectedPoint = point - (normal.point + scale) * normal
|
package/dist/es5/constants.d.ts
DELETED
package/dist/es5/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export {default as BoundingVolume} from './lib/bounding-volumes/bounding-volume';
|
|
2
|
-
export {default as BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
|
|
3
|
-
export {default as AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
4
|
-
export {default as OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
|
|
5
|
-
|
|
6
|
-
export {default as CullingVolume} from './lib/culling-volume';
|
|
7
|
-
export {default as Plane} from './lib/plane';
|
|
8
|
-
|
|
9
|
-
export {default as makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';
|
|
10
|
-
export {
|
|
11
|
-
makeAxisAlignedBoundingBoxFromPoints,
|
|
12
|
-
makeOrientedBoundingBoxFromPoints
|
|
13
|
-
} from './lib/algorithms/bounding-box-from-points';
|
|
14
|
-
export {default as computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';
|
|
15
|
-
|
|
16
|
-
// Experimental, decide how to handle enums in typescript
|
|
17
|
-
export {INTERSECTION_ENUM, INTERSECTION} from './constants';
|
|
18
|
-
|
|
19
|
-
export type _PerspectiveFrustum = object;
|
|
20
|
-
export type _PerspectiveOffCenterFrustum = object;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
|
|
2
|
-
import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Computes an instance of an OrientedBoundingBox of the given positions.
|
|
6
|
-
*
|
|
7
|
-
* This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
|
|
8
|
-
* Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
|
|
9
|
-
*/
|
|
10
|
-
export function makeOrientedBoundingBoxFromPoints(
|
|
11
|
-
positions: number[][],
|
|
12
|
-
result?: OrientedBoundingBox
|
|
13
|
-
): OrientedBoundingBox;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
|
|
17
|
-
* finding the points spaced the farthest apart on the x, y, and z axes.
|
|
18
|
-
*/
|
|
19
|
-
export function makeAxisAlignedBoundingBoxFromPoints(
|
|
20
|
-
positions: readonly number[][],
|
|
21
|
-
result?: AxisAlignedBoundingBox
|
|
22
|
-
): AxisAlignedBoundingBox;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import BoundingSphere from '../bounding-volumes/bounding-sphere';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
|
|
5
|
-
*
|
|
6
|
-
* The bounding sphere is computed by running two algorithms, a naive algorithm and
|
|
7
|
-
* Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
|
|
8
|
-
* Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding
|
|
9
|
-
*
|
|
10
|
-
* @param positions An array of points that the bounding sphere will enclose.
|
|
11
|
-
* @param result Optional object onto which to store the result.
|
|
12
|
-
* @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
|
|
13
|
-
*/
|
|
14
|
-
export default function makeBoundingSphereFromPoints(
|
|
15
|
-
positions: number[][],
|
|
16
|
-
result?: BoundingSphere
|
|
17
|
-
): BoundingSphere;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {BoundingVolume} from './bounding-volume';
|
|
2
|
-
import {Vector3} from '@math.gl/core';
|
|
3
|
-
import Plane from '../plane';
|
|
4
|
-
import {INTERSECTION_ENUM} from '../../constants';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* An axis aligned bounding box - aligned with coordinate axes
|
|
8
|
-
* @see BoundingVolume
|
|
9
|
-
* @see BoundingRectangle
|
|
10
|
-
* @see OrientedBoundingBox
|
|
11
|
-
*/
|
|
12
|
-
export default class AxisAlignedBoundingBox implements BoundingVolume {
|
|
13
|
-
/** The center point of the bounding box. */
|
|
14
|
-
readonly center: Vector3;
|
|
15
|
-
/** The positive half diagonal of the bounding box. */
|
|
16
|
-
readonly halfDiagonal: Vector3;
|
|
17
|
-
/** The minimum point defining the bounding box. [0, 0, 0] for empty box */
|
|
18
|
-
readonly minimum: Vector3;
|
|
19
|
-
/** The maximum point defining the bounding box. [0, 0, 0] for empty box */
|
|
20
|
-
readonly maximum: Vector3;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.
|
|
24
|
-
* @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.
|
|
25
|
-
* @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.
|
|
26
|
-
* @param center The center of the box; automatically computed if not supplied.
|
|
27
|
-
*/
|
|
28
|
-
constructor(minimum?: readonly number[], maximum?: readonly number[], center?: readonly number[]);
|
|
29
|
-
|
|
30
|
-
/** Duplicates a AxisAlignedBoundingBox instance. */
|
|
31
|
-
clone(): AxisAlignedBoundingBox;
|
|
32
|
-
/** Compares the provided AxisAlignedBoundingBox component wise */
|
|
33
|
-
equals(right: AxisAlignedBoundingBox): boolean;
|
|
34
|
-
|
|
35
|
-
// BoundingVolume interface
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
39
|
-
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
40
|
-
* @returns itself, i.e. the modified BoundingVolume.
|
|
41
|
-
*/
|
|
42
|
-
transform(transform: readonly number[]): this;
|
|
43
|
-
|
|
44
|
-
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
45
|
-
distanceTo(point: readonly number[]): number;
|
|
46
|
-
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
47
|
-
distanceSquaredTo(point: readonly number[]): number;
|
|
48
|
-
|
|
49
|
-
/** Determines which side of a plane a box is located. */
|
|
50
|
-
intersectPlane(plane: Plane): INTERSECTION_ENUM;
|
|
51
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {BoundingVolume} from './bounding-volume';
|
|
2
|
-
import {Vector3} from '@math.gl/core';
|
|
3
|
-
import {INTERSECTION_ENUM} from '../../constants';
|
|
4
|
-
import Plane from '../plane';
|
|
5
|
-
|
|
6
|
-
/** A BoundingSphere */
|
|
7
|
-
export default class BoundingSphere implements BoundingVolume {
|
|
8
|
-
center: Vector3;
|
|
9
|
-
radius: number;
|
|
10
|
-
|
|
11
|
-
/** Creates a bounding sphere */
|
|
12
|
-
constructor(center?: readonly number[], radius?: number);
|
|
13
|
-
|
|
14
|
-
/** Sets the bounding sphere from `center` and `radius`. */
|
|
15
|
-
fromCenterRadius(center: readonly number[], radius: number): this;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
|
|
19
|
-
* tightly and fully encompasses the box.
|
|
20
|
-
*/
|
|
21
|
-
fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this;
|
|
22
|
-
|
|
23
|
-
/** Compares the provided BoundingSphere component wise */
|
|
24
|
-
equals(right: BoundingSphere): boolean;
|
|
25
|
-
|
|
26
|
-
/** Duplicates a BoundingSphere instance. */
|
|
27
|
-
clone(): this;
|
|
28
|
-
|
|
29
|
-
/** Computes a bounding sphere that contains both the left and right bounding spheres. */
|
|
30
|
-
union(boundingSphere: BoundingSphere): this;
|
|
31
|
-
|
|
32
|
-
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
33
|
-
expand(point: readonly number[]): this;
|
|
34
|
-
|
|
35
|
-
// BoundingVolume interface
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
39
|
-
* @param sphere The bounding sphere to apply the transformation to.
|
|
40
|
-
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
41
|
-
* @returns self.
|
|
42
|
-
*/
|
|
43
|
-
transform(transform: readonly number[]): this;
|
|
44
|
-
|
|
45
|
-
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
46
|
-
distanceSquaredTo(point: readonly number[]): number;
|
|
47
|
-
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
48
|
-
distanceTo(point: readonly number[]): number;
|
|
49
|
-
|
|
50
|
-
/** Determines which side of a plane a sphere is located. */
|
|
51
|
-
intersectPlane(plane: Plane): INTERSECTION_ENUM;
|
|
52
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {INTERSECTION_ENUM} from '../../constants';
|
|
2
|
-
import Plane from '../plane';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Common interface for BoundingVolumes
|
|
6
|
-
* including BoundingSphere, AxisAlignedBoundingBox and OrientedBoundingBox
|
|
7
|
-
*/
|
|
8
|
-
export interface BoundingVolume {
|
|
9
|
-
/**
|
|
10
|
-
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
11
|
-
* @param sphere The bounding sphere to apply the transformation to.
|
|
12
|
-
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
13
|
-
* @returns itself, i.e. the modified BoundingVolume.
|
|
14
|
-
*/
|
|
15
|
-
transform(transform: readonly number[]): this;
|
|
16
|
-
|
|
17
|
-
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
18
|
-
distanceSquaredTo(point: readonly number[]): number;
|
|
19
|
-
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
20
|
-
distanceTo(point: readonly number[]): number;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Determines which side of a plane the oriented bounding box is located.
|
|
24
|
-
*
|
|
25
|
-
* @param plane The plane to test against.
|
|
26
|
-
* @returns
|
|
27
|
-
* - `INTERSECTION.INSIDE` if the entire box is on the side of the plane the normal is pointing.
|
|
28
|
-
* - `INTERSECTION.OUTSIDE` if the entire box is on the opposite side.
|
|
29
|
-
* - `INTERSECTION.INTERSECTING` if the box intersects the plane.
|
|
30
|
-
*/
|
|
31
|
-
intersectPlane(plane: Plane): INTERSECTION_ENUM;
|
|
32
|
-
}
|