@math.gl/culling 4.0.0-beta.1 → 4.0.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 +0 -1
- package/dist/constants.js +5 -4
- package/dist/index.cjs +27 -45
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -12
- package/dist/index.js +2 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -3
- package/dist/lib/algorithms/bounding-box-from-points.js +113 -113
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.js +117 -103
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -2
- package/dist/lib/algorithms/compute-eigen-decomposition.js +113 -85
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -3
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +100 -80
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -3
- package/dist/lib/bounding-volumes/bounding-sphere.js +106 -97
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
- package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -4
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +238 -196
- package/dist/lib/culling-volume.d.ts +3 -4
- package/dist/lib/culling-volume.js +109 -90
- package/dist/lib/perspective-frustum.d.ts +2 -3
- package/dist/lib/perspective-frustum.js +184 -136
- package/dist/lib/perspective-off-center-frustum.d.ts +2 -3
- package/dist/lib/perspective-off-center-frustum.js +259 -158
- package/dist/lib/plane.d.ts +0 -1
- package/dist/lib/plane.js +58 -59
- package/package.json +5 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.js.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/lib/culling-volume.d.ts.map +0 -1
- package/dist/lib/culling-volume.js.map +0 -1
- package/dist/lib/perspective-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-frustum.js.map +0 -1
- package/dist/lib/perspective-off-center-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/lib/plane.d.ts.map +0 -1
- package/dist/lib/plane.js.map +0 -1
|
@@ -1,102 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
|
+
/* eslint-disable */
|
|
2
4
|
import { Vector3, assert } from '@math.gl/core';
|
|
3
5
|
import { INTERSECTION } from "../constants.js";
|
|
4
6
|
import { Plane } from "./plane.js";
|
|
7
|
+
// X, Y, Z Unit vectors
|
|
5
8
|
const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];
|
|
6
9
|
const scratchPlaneCenter = new Vector3();
|
|
7
10
|
const scratchPlaneNormal = new Vector3();
|
|
11
|
+
// const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);
|
|
12
|
+
/** A culling volume defined by planes. */
|
|
8
13
|
export class CullingVolume {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
fromBoundingSphere(boundingSphere) {
|
|
16
|
-
this.planes.length = 2 * faces.length;
|
|
17
|
-
const center = boundingSphere.center;
|
|
18
|
-
const radius = boundingSphere.radius;
|
|
19
|
-
let planeIndex = 0;
|
|
20
|
-
|
|
21
|
-
for (const faceNormal of faces) {
|
|
22
|
-
let plane0 = this.planes[planeIndex];
|
|
23
|
-
let plane1 = this.planes[planeIndex + 1];
|
|
24
|
-
|
|
25
|
-
if (!plane0) {
|
|
26
|
-
plane0 = this.planes[planeIndex] = new Plane();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!plane1) {
|
|
30
|
-
plane1 = this.planes[planeIndex + 1] = new Plane();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
|
|
34
|
-
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
35
|
-
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
|
|
36
|
-
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
37
|
-
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
38
|
-
planeIndex += 2;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
16
|
+
* @param planes Array of clipping planes.
|
|
17
|
+
* */
|
|
18
|
+
constructor(planes = []) {
|
|
19
|
+
this.planes = planes;
|
|
39
20
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
|
|
23
|
+
* The planes are aligned to the x, y, and z axes in world coordinates.
|
|
24
|
+
*/
|
|
25
|
+
fromBoundingSphere(boundingSphere) {
|
|
26
|
+
this.planes.length = 2 * faces.length;
|
|
27
|
+
const center = boundingSphere.center;
|
|
28
|
+
const radius = boundingSphere.radius;
|
|
29
|
+
let planeIndex = 0;
|
|
30
|
+
for (const faceNormal of faces) {
|
|
31
|
+
let plane0 = this.planes[planeIndex];
|
|
32
|
+
let plane1 = this.planes[planeIndex + 1];
|
|
33
|
+
if (!plane0) {
|
|
34
|
+
plane0 = this.planes[planeIndex] = new Plane();
|
|
35
|
+
}
|
|
36
|
+
if (!plane1) {
|
|
37
|
+
plane1 = this.planes[planeIndex + 1] = new Plane();
|
|
38
|
+
}
|
|
39
|
+
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
|
|
40
|
+
// const plane0Distance = -faceNormal.dot(plane0Center);
|
|
41
|
+
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
42
|
+
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
|
|
43
|
+
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
44
|
+
// const plane1Distance = -negatedFaceNormal.dot(plane1Center);
|
|
45
|
+
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
46
|
+
planeIndex += 2;
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
/** Determines whether a bounding volume intersects the culling volume. */
|
|
51
|
+
computeVisibility(boundingVolume) {
|
|
52
|
+
// const planes = this.planes;
|
|
53
|
+
let intersect = INTERSECTION.INSIDE;
|
|
54
|
+
for (const plane of this.planes) {
|
|
55
|
+
const result = boundingVolume.intersectPlane(plane);
|
|
56
|
+
switch (result) {
|
|
57
|
+
case INTERSECTION.OUTSIDE:
|
|
58
|
+
// We are done
|
|
59
|
+
return INTERSECTION.OUTSIDE;
|
|
60
|
+
case INTERSECTION.INTERSECTING:
|
|
61
|
+
// If no other intersection is outside, return INTERSECTING
|
|
62
|
+
intersect = INTERSECTION.INTERSECTING;
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return intersect;
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
mask
|
|
89
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Determines whether a bounding volume intersects the culling volume.
|
|
71
|
+
*
|
|
72
|
+
* @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
|
|
73
|
+
* volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
|
|
74
|
+
* the parent (and therefore this) volume is completely inside plane[planeIndex]
|
|
75
|
+
* and that plane check can be skipped.
|
|
76
|
+
*/
|
|
77
|
+
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
78
|
+
assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
|
|
79
|
+
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE ||
|
|
80
|
+
parentPlaneMask === CullingVolume.MASK_INSIDE) {
|
|
81
|
+
// parent is completely outside or completely inside, so this child is as well.
|
|
82
|
+
return parentPlaneMask;
|
|
83
|
+
}
|
|
84
|
+
// Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.
|
|
85
|
+
// (Because if there are fewer than 31 planes, the upper bits wont be changed.)
|
|
86
|
+
let mask = CullingVolume.MASK_INSIDE;
|
|
87
|
+
const planes = this.planes;
|
|
88
|
+
for (let k = 0; k < this.planes.length; ++k) {
|
|
89
|
+
// For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
|
|
90
|
+
const flag = k < 31 ? 1 << k : 0;
|
|
91
|
+
if (k < 31 && (parentPlaneMask & flag) === 0) {
|
|
92
|
+
// boundingVolume is known to be INSIDE this plane.
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const plane = planes[k];
|
|
96
|
+
const result = boundingVolume.intersectPlane(plane);
|
|
97
|
+
if (result === INTERSECTION.OUTSIDE) {
|
|
98
|
+
return CullingVolume.MASK_OUTSIDE;
|
|
99
|
+
}
|
|
100
|
+
else if (result === INTERSECTION.INTERSECTING) {
|
|
101
|
+
mask |= flag;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return mask;
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
return mask;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
106
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
/**
|
|
108
|
+
* For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
|
|
109
|
+
* represents the case where the object bounding volume is entirely outside the culling volume.
|
|
110
|
+
*/
|
|
111
|
+
CullingVolume.MASK_OUTSIDE = 0xffffffff;
|
|
112
|
+
/**
|
|
113
|
+
* For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
|
|
114
|
+
* represents the case where the object bounding volume is entirely inside the culling volume.
|
|
115
|
+
*/
|
|
116
|
+
CullingVolume.MASK_INSIDE = 0x00000000;
|
|
117
|
+
/**
|
|
118
|
+
* For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
|
|
119
|
+
* represents the case where the object bounding volume (may) intersect all planes of the culling volume.
|
|
120
|
+
*/
|
|
121
|
+
CullingVolume.MASK_INDETERMINATE = 0x7fffffff;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Matrix4, NumericArray, Vector2 } from '@math.gl/core';
|
|
2
|
-
import { CullingVolume } from
|
|
3
|
-
|
|
2
|
+
import { CullingVolume } from "./culling-volume.js";
|
|
3
|
+
type PerspectiveFrustumOptions = {
|
|
4
4
|
/** The angle of the field of view (FOV), in radians. */
|
|
5
5
|
fov?: number;
|
|
6
6
|
/** The aspect ratio of the frustum's width to it's height. */
|
|
@@ -149,4 +149,3 @@ export declare class PerspectiveFrustum {
|
|
|
149
149
|
private _update;
|
|
150
150
|
}
|
|
151
151
|
export {};
|
|
152
|
-
//# sourceMappingURL=perspective-frustum.d.ts.map
|
|
@@ -1,142 +1,190 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
|
+
// Note: This class is still an experimental export, mainly used by other test cases
|
|
4
|
+
// - It has not been fully adapted to math.gl conventions
|
|
5
|
+
// - Documentation has not been ported
|
|
2
6
|
import { assert, Vector2 } from '@math.gl/core';
|
|
3
7
|
import { PerspectiveOffCenterFrustum } from "./perspective-off-center-frustum.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
9
|
+
/**
|
|
10
|
+
* The viewing frustum is defined by 6 planes.
|
|
11
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
12
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
13
|
+
* plane from the origin/camera position.
|
|
14
|
+
*
|
|
15
|
+
* @alias PerspectiveFrustum
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* var frustum = new PerspectiveFrustum({
|
|
19
|
+
* fov : Math.PI_OVER_THREE,
|
|
20
|
+
* aspectRatio : canvas.clientWidth / canvas.clientHeight
|
|
21
|
+
* near : 1.0,
|
|
22
|
+
* far : 1000.0
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* @see PerspectiveOffCenterFrustum
|
|
26
|
+
*/
|
|
7
27
|
export class PerspectiveFrustum {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "_sseDenominator", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "aspectRatio", void 0);
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "_aspectRatio", void 0);
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "near", void 0);
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "_near", void 0);
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "far", void 0);
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "_far", void 0);
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "xOffset", void 0);
|
|
32
|
-
|
|
33
|
-
_defineProperty(this, "_xOffset", void 0);
|
|
34
|
-
|
|
35
|
-
_defineProperty(this, "yOffset", void 0);
|
|
36
|
-
|
|
37
|
-
_defineProperty(this, "_yOffset", void 0);
|
|
38
|
-
|
|
39
|
-
const {
|
|
40
|
-
fov,
|
|
41
|
-
aspectRatio,
|
|
42
|
-
near = 1.0,
|
|
43
|
-
far = 500000000.0,
|
|
44
|
-
xOffset = 0.0,
|
|
45
|
-
yOffset = 0.0
|
|
46
|
-
} = options;
|
|
47
|
-
this.fov = fov;
|
|
48
|
-
this.aspectRatio = aspectRatio;
|
|
49
|
-
this.near = near;
|
|
50
|
-
this.far = far;
|
|
51
|
-
this.xOffset = xOffset;
|
|
52
|
-
this.yOffset = yOffset;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
clone() {
|
|
56
|
-
return new PerspectiveFrustum({
|
|
57
|
-
aspectRatio: this.aspectRatio,
|
|
58
|
-
fov: this.fov,
|
|
59
|
-
near: this.near,
|
|
60
|
-
far: this.far
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
equals(other) {
|
|
65
|
-
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
66
|
-
return false;
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
this._offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
30
|
+
const { fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0 } = options;
|
|
31
|
+
this.fov = fov;
|
|
32
|
+
this.aspectRatio = aspectRatio;
|
|
33
|
+
this.near = near;
|
|
34
|
+
this.far = far;
|
|
35
|
+
this.xOffset = xOffset;
|
|
36
|
+
this.yOffset = yOffset;
|
|
67
37
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Returns a duplicate of a PerspectiveFrustum instance.
|
|
40
|
+
*/
|
|
41
|
+
clone() {
|
|
42
|
+
return new PerspectiveFrustum({
|
|
43
|
+
aspectRatio: this.aspectRatio,
|
|
44
|
+
fov: this.fov,
|
|
45
|
+
near: this.near,
|
|
46
|
+
far: this.far
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compares the provided PerspectiveFrustum componentwise and returns
|
|
51
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
52
|
+
*/
|
|
53
|
+
equals(other) {
|
|
54
|
+
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
this._update();
|
|
58
|
+
other._update();
|
|
59
|
+
return (this.fov === other.fov &&
|
|
60
|
+
this.aspectRatio === other.aspectRatio &&
|
|
61
|
+
this.near === other.near &&
|
|
62
|
+
this.far === other.far &&
|
|
63
|
+
this._offCenterFrustum.equals(other._offCenterFrustum));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the perspective projection matrix computed from the view this.
|
|
67
|
+
*/
|
|
68
|
+
get projectionMatrix() {
|
|
69
|
+
this._update();
|
|
70
|
+
return this._offCenterFrustum.projectionMatrix;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
74
|
+
*/
|
|
75
|
+
get infiniteProjectionMatrix() {
|
|
76
|
+
this._update();
|
|
77
|
+
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the angle of the vertical field of view, in radians.
|
|
81
|
+
*/
|
|
82
|
+
get fovy() {
|
|
83
|
+
this._update();
|
|
84
|
+
return this._fovy;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
get sseDenominator() {
|
|
90
|
+
this._update();
|
|
91
|
+
return this._sseDenominator;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Creates a culling volume for this this.ion.
|
|
95
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Check if a bounding volume intersects the this.
|
|
99
|
+
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
100
|
+
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
101
|
+
*/
|
|
102
|
+
computeCullingVolume(
|
|
103
|
+
/** A Vector3 defines the eye position. */
|
|
104
|
+
position,
|
|
105
|
+
/** A Vector3 defines the view direction. */
|
|
106
|
+
direction,
|
|
107
|
+
/** A Vector3 defines the up direction. */
|
|
108
|
+
up) {
|
|
109
|
+
this._update();
|
|
110
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Returns the pixel's width and height in meters.
|
|
114
|
+
* @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.
|
|
115
|
+
*
|
|
116
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
117
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* // Example 1
|
|
121
|
+
* // Get the width and height of a pixel.
|
|
122
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* // Example 2
|
|
126
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
127
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
128
|
+
* var position = camera.position;
|
|
129
|
+
* var direction = camera.direction;
|
|
130
|
+
* var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
131
|
+
* var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
132
|
+
* var distance = Vector3.magnitude(toCenterProj);
|
|
133
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
134
|
+
*/
|
|
135
|
+
getPixelDimensions(
|
|
136
|
+
/** The width of the drawing buffer. */
|
|
137
|
+
drawingBufferWidth,
|
|
138
|
+
/** The height of the drawing buffer. */
|
|
139
|
+
drawingBufferHeight,
|
|
140
|
+
/** The distance to the near plane in meters. */
|
|
141
|
+
distance,
|
|
142
|
+
/** The object onto which to store the result. */
|
|
143
|
+
result) {
|
|
144
|
+
this._update();
|
|
145
|
+
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new Vector2());
|
|
146
|
+
}
|
|
147
|
+
// eslint-disable-next-line complexity, max-statements
|
|
148
|
+
_update() {
|
|
149
|
+
assert(Number.isFinite(this.fov) &&
|
|
150
|
+
Number.isFinite(this.aspectRatio) &&
|
|
151
|
+
Number.isFinite(this.near) &&
|
|
152
|
+
Number.isFinite(this.far));
|
|
153
|
+
// 'fov, aspectRatio, near, or far parameters are not set.'
|
|
154
|
+
const f = this._offCenterFrustum;
|
|
155
|
+
if (this.fov !== this._fov ||
|
|
156
|
+
this.aspectRatio !== this._aspectRatio ||
|
|
157
|
+
this.near !== this._near ||
|
|
158
|
+
this.far !== this._far ||
|
|
159
|
+
this.xOffset !== this._xOffset ||
|
|
160
|
+
this.yOffset !== this._yOffset) {
|
|
161
|
+
assert(this.fov >= 0 && this.fov < Math.PI);
|
|
162
|
+
// throw new DeveloperError('fov must be in the range [0, PI).');
|
|
163
|
+
assert(this.aspectRatio > 0);
|
|
164
|
+
// throw new DeveloperError('aspectRatio must be positive.');
|
|
165
|
+
assert(this.near >= 0 && this.near < this.far);
|
|
166
|
+
// throw new DeveloperError('near must be greater than zero and less than far.');
|
|
167
|
+
this._aspectRatio = this.aspectRatio;
|
|
168
|
+
this._fov = this.fov;
|
|
169
|
+
this._fovy =
|
|
170
|
+
this.aspectRatio <= 1
|
|
171
|
+
? this.fov
|
|
172
|
+
: Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
|
|
173
|
+
this._near = this.near;
|
|
174
|
+
this._far = this.far;
|
|
175
|
+
this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
|
|
176
|
+
this._xOffset = this.xOffset;
|
|
177
|
+
this._yOffset = this.yOffset;
|
|
178
|
+
f.top = this.near * Math.tan(0.5 * this._fovy);
|
|
179
|
+
f.bottom = -f.top;
|
|
180
|
+
f.right = this.aspectRatio * f.top;
|
|
181
|
+
f.left = -f.right;
|
|
182
|
+
f.near = this.near;
|
|
183
|
+
f.far = this.far;
|
|
184
|
+
f.right += this.xOffset;
|
|
185
|
+
f.left += this.xOffset;
|
|
186
|
+
f.top += this.yOffset;
|
|
187
|
+
f.bottom += this.yOffset;
|
|
188
|
+
}
|
|
138
189
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
190
|
}
|
|
142
|
-
//# sourceMappingURL=perspective-frustum.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vector2, Matrix4, NumericArray } from '@math.gl/core';
|
|
2
|
-
import { CullingVolume } from
|
|
3
|
-
|
|
2
|
+
import { CullingVolume } from "./culling-volume.js";
|
|
3
|
+
type PerspectiveOffCenterFrustumOptions = {
|
|
4
4
|
left?: number;
|
|
5
5
|
right?: number;
|
|
6
6
|
top?: number;
|
|
@@ -155,4 +155,3 @@ export declare class PerspectiveOffCenterFrustum {
|
|
|
155
155
|
private _update;
|
|
156
156
|
}
|
|
157
157
|
export {};
|
|
158
|
-
//# sourceMappingURL=perspective-off-center-frustum.d.ts.map
|