@math.gl/culling 3.5.3 → 3.6.0-alpha.1
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 +12 -24
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +72 -122
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +81 -109
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +36 -37
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +68 -74
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +93 -109
- 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 +190 -211
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +80 -131
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +73 -84
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +114 -117
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +55 -69
- 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 +7 -6
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js +6 -6
- 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 +12 -6
- 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 +142 -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} +25 -10
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +21 -7
- 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} +47 -31
- 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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
|
-
import {Vector3, Matrix3, Quaternion} from '@math.gl/core';
|
|
4
|
+
import {Vector3, Matrix3, Quaternion, NumericArray} from '@math.gl/core';
|
|
5
|
+
import type {BoundingVolume} from './bounding-volume';
|
|
5
6
|
import BoundingSphere from './bounding-sphere';
|
|
7
|
+
import type Plane from '../plane';
|
|
6
8
|
import {INTERSECTION} from '../../constants';
|
|
7
9
|
|
|
8
10
|
const scratchVector3 = new Vector3();
|
|
@@ -25,20 +27,36 @@ const MATRIX3 = {
|
|
|
25
27
|
COLUMN2ROW2: 8
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* An OrientedBoundingBox of some object is a closed and convex cuboid.
|
|
32
|
+
* It can provide a tighter bounding volume than `BoundingSphere` or
|
|
33
|
+
* `AxisAlignedBoundingBox` in many cases.
|
|
34
|
+
*/
|
|
35
|
+
export default class OrientedBoundingBox implements BoundingVolume {
|
|
36
|
+
center: Vector3;
|
|
37
|
+
halfAxes: Matrix3;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An OrientedBoundingBox of some object is a closed and convex cuboid.
|
|
41
|
+
* It can provide a tighter bounding volume than
|
|
42
|
+
* `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.
|
|
43
|
+
*/
|
|
44
|
+
constructor(center?: readonly number[], halfAxes?: readonly number[]);
|
|
45
|
+
constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
|
|
30
46
|
this.center = new Vector3().from(center);
|
|
31
47
|
this.halfAxes = new Matrix3(halfAxes);
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
|
|
50
|
+
/** Returns an array with three halfSizes for the bounding box */
|
|
51
|
+
get halfSize(): number[] {
|
|
35
52
|
const xAxis = this.halfAxes.getColumn(0);
|
|
36
53
|
const yAxis = this.halfAxes.getColumn(1);
|
|
37
54
|
const zAxis = this.halfAxes.getColumn(2);
|
|
38
55
|
return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
|
|
58
|
+
/** Returns a quaternion describing the orientation of the bounding box */
|
|
59
|
+
get quaternion(): Quaternion {
|
|
42
60
|
const xAxis = this.halfAxes.getColumn(0);
|
|
43
61
|
const yAxis = this.halfAxes.getColumn(1);
|
|
44
62
|
const zAxis = this.halfAxes.getColumn(2);
|
|
@@ -48,7 +66,14 @@ export default class OrientedBoundingBox {
|
|
|
48
66
|
return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));
|
|
49
67
|
}
|
|
50
68
|
|
|
51
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Create OrientedBoundingBox from quaternion based OBB,
|
|
71
|
+
*/
|
|
72
|
+
fromCenterHalfSizeQuaternion(
|
|
73
|
+
center: number[],
|
|
74
|
+
halfSize: number[],
|
|
75
|
+
quaternion: number[]
|
|
76
|
+
): OrientedBoundingBox {
|
|
52
77
|
const quaternionObject = new Quaternion(quaternion);
|
|
53
78
|
const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);
|
|
54
79
|
directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
|
|
@@ -65,18 +90,21 @@ export default class OrientedBoundingBox {
|
|
|
65
90
|
return this;
|
|
66
91
|
}
|
|
67
92
|
|
|
68
|
-
|
|
93
|
+
/** Duplicates a OrientedBoundingBox instance. */
|
|
94
|
+
clone(): OrientedBoundingBox {
|
|
69
95
|
return new OrientedBoundingBox(this.center, this.halfAxes);
|
|
70
96
|
}
|
|
71
97
|
|
|
72
|
-
|
|
98
|
+
/** Compares the provided OrientedBoundingBox component wise and returns */
|
|
99
|
+
equals(right: OrientedBoundingBox): boolean {
|
|
73
100
|
return (
|
|
74
101
|
this === right ||
|
|
75
102
|
(Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))
|
|
76
103
|
);
|
|
77
104
|
}
|
|
78
105
|
|
|
79
|
-
|
|
106
|
+
/** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
|
|
107
|
+
getBoundingSphere(result = new BoundingSphere()): BoundingSphere {
|
|
80
108
|
const halfAxes = this.halfAxes;
|
|
81
109
|
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
82
110
|
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
@@ -91,7 +119,8 @@ export default class OrientedBoundingBox {
|
|
|
91
119
|
return result;
|
|
92
120
|
}
|
|
93
121
|
|
|
94
|
-
|
|
122
|
+
/** Determines which side of a plane the oriented bounding box is located. */
|
|
123
|
+
intersectPlane(plane: Plane): INTERSECTION {
|
|
95
124
|
const center = this.center;
|
|
96
125
|
const normal = plane.normal;
|
|
97
126
|
const halfAxes = this.halfAxes;
|
|
@@ -129,11 +158,17 @@ export default class OrientedBoundingBox {
|
|
|
129
158
|
return INTERSECTION.INTERSECTING;
|
|
130
159
|
}
|
|
131
160
|
|
|
132
|
-
|
|
161
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
162
|
+
distanceTo(point: readonly number[]): number {
|
|
133
163
|
return Math.sqrt(this.distanceSquaredTo(point));
|
|
134
164
|
}
|
|
135
165
|
|
|
136
|
-
|
|
166
|
+
/**
|
|
167
|
+
* Computes the estimated distance squared from the closest point
|
|
168
|
+
* on a bounding box to a point.
|
|
169
|
+
* See Geometric Tools for Computer Graphics 10.4.2
|
|
170
|
+
*/
|
|
171
|
+
distanceSquaredTo(point: readonly number[]): number {
|
|
137
172
|
// Computes the estimated distance squared from the
|
|
138
173
|
// closest point on a bounding box to a point.
|
|
139
174
|
// See Geometric Tools for Computer Graphics 10.4.2
|
|
@@ -173,8 +208,26 @@ export default class OrientedBoundingBox {
|
|
|
173
208
|
return distanceSquared;
|
|
174
209
|
}
|
|
175
210
|
|
|
211
|
+
/**
|
|
212
|
+
* The distances calculated by the vector from the center of the bounding box
|
|
213
|
+
* to position projected onto direction.
|
|
214
|
+
*
|
|
215
|
+
* - If you imagine the infinite number of planes with normal direction,
|
|
216
|
+
* this computes the smallest distance to the closest and farthest planes
|
|
217
|
+
* from `position` that intersect the bounding box.
|
|
218
|
+
*
|
|
219
|
+
* @param position The position to calculate the distance from.
|
|
220
|
+
* @param direction The direction from position.
|
|
221
|
+
* @param result An Interval (array of length 2) to store the nearest and farthest distances.
|
|
222
|
+
* @returns Interval (array of length 2) with nearest and farthest distances
|
|
223
|
+
* on the bounding box from position in direction.
|
|
224
|
+
*/
|
|
176
225
|
// eslint-disable-next-line max-statements
|
|
177
|
-
computePlaneDistances(
|
|
226
|
+
computePlaneDistances(
|
|
227
|
+
position: readonly number[],
|
|
228
|
+
direction: Vector3,
|
|
229
|
+
result: number[] = [-0, -0]
|
|
230
|
+
): number[] {
|
|
178
231
|
let minDist = Number.POSITIVE_INFINITY;
|
|
179
232
|
let maxDist = Number.NEGATIVE_INFINITY;
|
|
180
233
|
|
|
@@ -262,7 +315,12 @@ export default class OrientedBoundingBox {
|
|
|
262
315
|
return result;
|
|
263
316
|
}
|
|
264
317
|
|
|
265
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
320
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
321
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
322
|
+
*/
|
|
323
|
+
transform(transformation: readonly number[]): this {
|
|
266
324
|
this.center.transformAsPoint(transformation);
|
|
267
325
|
|
|
268
326
|
const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
@@ -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;
|