@math.gl/culling 3.6.0-alpha.3 → 3.6.0-alpha.6
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/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +63 -58
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +51 -51
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.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.map +1 -1
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/esm/lib/perspective-frustum.js +60 -55
- package/dist/esm/lib/perspective-frustum.js.map +1 -1
- package/dist/esm/lib/perspective-off-center-frustum.js +48 -46
- package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/esm/lib/plane.js.map +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +2 -2
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/lib/perspective-frustum.d.ts +52 -40
- package/dist/lib/perspective-frustum.d.ts.map +1 -1
- package/dist/lib/perspective-frustum.js +81 -96
- package/dist/lib/perspective-off-center-frustum.d.ts +74 -38
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
- package/dist/lib/perspective-off-center-frustum.js +64 -99
- package/dist/lib/plane.d.ts +8 -8
- package/dist/lib/plane.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/algorithms/compute-eigen-decomposition.ts +3 -3
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +2 -2
- package/src/lib/perspective-frustum.ts +115 -118
- package/src/lib/perspective-off-center-frustum.ts +137 -131
- package/src/lib/plane.ts +11 -8
|
@@ -5,13 +5,27 @@
|
|
|
5
5
|
// - It has not been fully adapted to math.gl conventions
|
|
6
6
|
// - Documentation has not been ported
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {assert, Matrix4} from '@math.gl/core';
|
|
8
|
+
import {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';
|
|
11
9
|
import PerspectiveOffCenterFrustum from './perspective-off-center-frustum';
|
|
10
|
+
import CullingVolume from './culling-volume';
|
|
12
11
|
|
|
13
12
|
const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
14
13
|
|
|
14
|
+
type PerspectiveFrustumOptions = {
|
|
15
|
+
/** The angle of the field of view (FOV), in radians. */
|
|
16
|
+
fov?: number;
|
|
17
|
+
/** The aspect ratio of the frustum's width to it's height. */
|
|
18
|
+
aspectRatio?: number;
|
|
19
|
+
/** The distance of the near plane. */
|
|
20
|
+
near?: number;
|
|
21
|
+
/** The distance of the far plane. */
|
|
22
|
+
far?: number;
|
|
23
|
+
/** The offset in the x direction. */
|
|
24
|
+
xOffset?: number;
|
|
25
|
+
/** The offset in the y direction. */
|
|
26
|
+
yOffset?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
15
29
|
/**
|
|
16
30
|
* The viewing frustum is defined by 6 planes.
|
|
17
31
|
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
@@ -19,15 +33,6 @@ const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
|
19
33
|
* plane from the origin/camera position.
|
|
20
34
|
*
|
|
21
35
|
* @alias PerspectiveFrustum
|
|
22
|
-
* @constructor
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} [options] An object with the following properties:
|
|
25
|
-
* @param {Number} [options.fov] The angle of the field of view (FOV), in radians.
|
|
26
|
-
* @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.
|
|
27
|
-
* @param {Number} [options.near=1.0] The distance of the near plane.
|
|
28
|
-
* @param {Number} [options.far=500000000.0] The distance of the far plane.
|
|
29
|
-
* @param {Number} [options.xOffset=0.0] The offset in the x direction.
|
|
30
|
-
* @param {Number} [options.yOffset=0.0] The offset in the y direction.
|
|
31
36
|
*
|
|
32
37
|
* @example
|
|
33
38
|
* var frustum = new PerspectiveFrustum({
|
|
@@ -40,70 +45,55 @@ const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
|
40
45
|
* @see PerspectiveOffCenterFrustum
|
|
41
46
|
*/
|
|
42
47
|
export default class PerspectiveFrustum {
|
|
43
|
-
_offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
48
|
+
private _offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
44
49
|
/**
|
|
45
50
|
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
46
51
|
* as the horizontal FOV if the width is greater than the height, otherwise
|
|
47
52
|
* it will be the vertical FOV.
|
|
48
53
|
*/
|
|
49
|
-
fov
|
|
50
|
-
_fov;
|
|
51
|
-
_fovy;
|
|
52
|
-
_sseDenominator;
|
|
54
|
+
fov?: number;
|
|
55
|
+
private _fov: number;
|
|
56
|
+
private _fovy: number;
|
|
57
|
+
private _sseDenominator: number;
|
|
53
58
|
/**
|
|
54
59
|
* The aspect ratio of the frustum's width to it's height.
|
|
55
60
|
*/
|
|
56
|
-
aspectRatio
|
|
57
|
-
_aspectRatio;
|
|
61
|
+
aspectRatio?: number;
|
|
62
|
+
private _aspectRatio: number;
|
|
58
63
|
/**
|
|
59
64
|
* The distance of the near plane.
|
|
60
65
|
* @default 1.0
|
|
61
66
|
*/
|
|
62
67
|
near: number;
|
|
63
|
-
_near;
|
|
68
|
+
private _near: number;
|
|
64
69
|
/**
|
|
65
70
|
* The distance of the far plane.
|
|
66
71
|
* @default 500000000.0
|
|
67
72
|
*/
|
|
68
73
|
far: number;
|
|
69
|
-
_far;
|
|
74
|
+
private _far: number;
|
|
70
75
|
/**
|
|
71
76
|
* Offsets the frustum in the x direction.
|
|
72
77
|
* @default 0.0
|
|
73
78
|
*/
|
|
74
79
|
xOffset: number;
|
|
75
|
-
_xOffset;
|
|
80
|
+
private _xOffset: number;
|
|
76
81
|
/**
|
|
77
82
|
* Offsets the frustum in the y direction.
|
|
78
83
|
* @default 0.0
|
|
79
84
|
*/
|
|
80
85
|
yOffset: number;
|
|
81
|
-
_yOffset;
|
|
82
|
-
|
|
83
|
-
constructor(options: Record<string, any> = {}) {
|
|
84
|
-
options = {
|
|
85
|
-
near: 1.0,
|
|
86
|
-
far: 500000000.0,
|
|
87
|
-
xOffset: 0.0,
|
|
88
|
-
yOffset: 0.0,
|
|
89
|
-
...options
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
this.fov = options.fov;
|
|
93
|
-
|
|
94
|
-
this.aspectRatio = options.aspectRatio;
|
|
95
|
-
|
|
96
|
-
this.near = options.near;
|
|
97
|
-
this._near = this.near;
|
|
86
|
+
private _yOffset: number;
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
constructor(options: PerspectiveFrustumOptions = {}) {
|
|
89
|
+
const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;
|
|
101
90
|
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
91
|
+
this.fov = fov;
|
|
92
|
+
this.aspectRatio = aspectRatio;
|
|
93
|
+
this.near = near;
|
|
94
|
+
this.far = far;
|
|
95
|
+
this.xOffset = xOffset;
|
|
96
|
+
this.yOffset = yOffset;
|
|
107
97
|
}
|
|
108
98
|
|
|
109
99
|
/**
|
|
@@ -127,8 +117,8 @@ export default class PerspectiveFrustum {
|
|
|
127
117
|
return false;
|
|
128
118
|
}
|
|
129
119
|
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
this._update();
|
|
121
|
+
other._update();
|
|
132
122
|
|
|
133
123
|
return (
|
|
134
124
|
this.fov === other.fov &&
|
|
@@ -140,10 +130,10 @@ export default class PerspectiveFrustum {
|
|
|
140
130
|
}
|
|
141
131
|
|
|
142
132
|
/**
|
|
143
|
-
* Gets the perspective projection matrix computed from the view
|
|
133
|
+
* Gets the perspective projection matrix computed from the view this.
|
|
144
134
|
*/
|
|
145
135
|
get projectionMatrix(): Matrix4 {
|
|
146
|
-
|
|
136
|
+
this._update();
|
|
147
137
|
return this._offCenterFrustum.projectionMatrix;
|
|
148
138
|
}
|
|
149
139
|
|
|
@@ -151,7 +141,7 @@ export default class PerspectiveFrustum {
|
|
|
151
141
|
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
152
142
|
*/
|
|
153
143
|
get infiniteProjectionMatrix(): Matrix4 {
|
|
154
|
-
|
|
144
|
+
this._update();
|
|
155
145
|
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
156
146
|
}
|
|
157
147
|
|
|
@@ -159,7 +149,7 @@ export default class PerspectiveFrustum {
|
|
|
159
149
|
* Gets the angle of the vertical field of view, in radians.
|
|
160
150
|
*/
|
|
161
151
|
get fovy(): number {
|
|
162
|
-
|
|
152
|
+
this._update();
|
|
163
153
|
return this._fovy;
|
|
164
154
|
}
|
|
165
155
|
|
|
@@ -167,35 +157,33 @@ export default class PerspectiveFrustum {
|
|
|
167
157
|
* @private
|
|
168
158
|
*/
|
|
169
159
|
get sseDenominator(): number {
|
|
170
|
-
|
|
160
|
+
this._update();
|
|
171
161
|
return this._sseDenominator;
|
|
172
162
|
}
|
|
173
163
|
|
|
174
164
|
/**
|
|
175
|
-
* Creates a culling volume for this
|
|
176
|
-
*
|
|
177
|
-
* @param {Vector3} position The eye position.
|
|
178
|
-
* @param {Vector3} direction The view direction.
|
|
179
|
-
* @param {Vector3} up The up direction.
|
|
165
|
+
* Creates a culling volume for this this.ion.
|
|
180
166
|
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
181
167
|
*
|
|
182
168
|
* @example
|
|
183
|
-
* // Check if a bounding volume intersects the
|
|
184
|
-
* var cullingVolume =
|
|
169
|
+
* // Check if a bounding volume intersects the this.
|
|
170
|
+
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
185
171
|
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
186
172
|
*/
|
|
187
|
-
computeCullingVolume(
|
|
188
|
-
|
|
173
|
+
computeCullingVolume(
|
|
174
|
+
/** A Vector3 defines the eye position. */
|
|
175
|
+
position: Readonly<NumericArray>,
|
|
176
|
+
/** A Vector3 defines the view direction. */
|
|
177
|
+
direction: Readonly<NumericArray>,
|
|
178
|
+
/** A Vector3 defines the up direction. */
|
|
179
|
+
up: Readonly<NumericArray>
|
|
180
|
+
): CullingVolume {
|
|
181
|
+
this._update();
|
|
189
182
|
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
190
183
|
}
|
|
191
184
|
|
|
192
185
|
/**
|
|
193
186
|
* Returns the pixel's width and height in meters.
|
|
194
|
-
*
|
|
195
|
-
* @param {Number} drawingBufferWidth The width of the drawing buffer.
|
|
196
|
-
* @param {Number} drawingBufferHeight The height of the drawing buffer.
|
|
197
|
-
* @param {Number} distance The distance to the near plane in meters.
|
|
198
|
-
* @param {Vector2} result The object onto which to store the result.
|
|
199
187
|
* @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.
|
|
200
188
|
*
|
|
201
189
|
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
@@ -204,7 +192,7 @@ export default class PerspectiveFrustum {
|
|
|
204
192
|
* @example
|
|
205
193
|
* // Example 1
|
|
206
194
|
* // Get the width and height of a pixel.
|
|
207
|
-
* var pixelSize = camera.
|
|
195
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
208
196
|
*
|
|
209
197
|
* @example
|
|
210
198
|
* // Example 2
|
|
@@ -215,70 +203,79 @@ export default class PerspectiveFrustum {
|
|
|
215
203
|
* var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
216
204
|
* var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
217
205
|
* var distance = Vector3.magnitude(toCenterProj);
|
|
218
|
-
* var pixelSize = camera.
|
|
206
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
219
207
|
*/
|
|
220
|
-
getPixelDimensions(
|
|
221
|
-
|
|
208
|
+
getPixelDimensions(
|
|
209
|
+
/** The width of the drawing buffer. */
|
|
210
|
+
drawingBufferWidth: number,
|
|
211
|
+
/** The height of the drawing buffer. */
|
|
212
|
+
drawingBufferHeight: number,
|
|
213
|
+
/** The distance to the near plane in meters. */
|
|
214
|
+
distance: number,
|
|
215
|
+
/** The object onto which to store the result. */
|
|
216
|
+
result?: Vector2
|
|
217
|
+
): Vector2 {
|
|
218
|
+
this._update();
|
|
222
219
|
return this._offCenterFrustum.getPixelDimensions(
|
|
223
220
|
drawingBufferWidth,
|
|
224
221
|
drawingBufferHeight,
|
|
225
222
|
distance,
|
|
226
|
-
result
|
|
223
|
+
result || new Vector2()
|
|
227
224
|
);
|
|
228
225
|
}
|
|
229
|
-
}
|
|
230
226
|
|
|
231
|
-
// eslint-disable-next-line complexity, max-statements
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
227
|
+
// eslint-disable-next-line complexity, max-statements
|
|
228
|
+
private _update(): void {
|
|
229
|
+
assert(
|
|
230
|
+
Number.isFinite(this.fov) &&
|
|
231
|
+
Number.isFinite(this.aspectRatio) &&
|
|
232
|
+
Number.isFinite(this.near) &&
|
|
233
|
+
Number.isFinite(this.far)
|
|
234
|
+
);
|
|
235
|
+
// 'fov, aspectRatio, near, or far parameters are not set.'
|
|
240
236
|
|
|
241
|
-
|
|
237
|
+
const f = this._offCenterFrustum;
|
|
242
238
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
239
|
+
if (
|
|
240
|
+
this.fov !== this._fov ||
|
|
241
|
+
this.aspectRatio !== this._aspectRatio ||
|
|
242
|
+
this.near !== this._near ||
|
|
243
|
+
this.far !== this._far ||
|
|
244
|
+
this.xOffset !== this._xOffset ||
|
|
245
|
+
this.yOffset !== this._yOffset
|
|
246
|
+
) {
|
|
247
|
+
assert(this.fov >= 0 && this.fov < Math.PI);
|
|
248
|
+
// throw new DeveloperError('fov must be in the range [0, PI).');
|
|
253
249
|
|
|
254
|
-
|
|
255
|
-
|
|
250
|
+
assert(this.aspectRatio > 0);
|
|
251
|
+
// throw new DeveloperError('aspectRatio must be positive.');
|
|
256
252
|
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
assert(this.near >= 0 && this.near < this.far);
|
|
254
|
+
// throw new DeveloperError('near must be greater than zero and less than far.');
|
|
259
255
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
256
|
+
this._aspectRatio = this.aspectRatio;
|
|
257
|
+
this._fov = this.fov;
|
|
258
|
+
this._fovy =
|
|
259
|
+
this.aspectRatio <= 1
|
|
260
|
+
? this.fov
|
|
261
|
+
: Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
|
|
262
|
+
this._near = this.near;
|
|
263
|
+
this._far = this.far;
|
|
264
|
+
this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
|
|
265
|
+
this._xOffset = this.xOffset;
|
|
266
|
+
this._yOffset = this.yOffset;
|
|
271
267
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
268
|
+
f.top = this.near * Math.tan(0.5 * this._fovy);
|
|
269
|
+
f.bottom = -f.top;
|
|
270
|
+
f.right = this.aspectRatio * f.top;
|
|
271
|
+
f.left = -f.right;
|
|
272
|
+
f.near = this.near;
|
|
273
|
+
f.far = this.far;
|
|
278
274
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
275
|
+
f.right += this.xOffset;
|
|
276
|
+
f.left += this.xOffset;
|
|
277
|
+
f.top += this.yOffset;
|
|
278
|
+
f.bottom += this.yOffset;
|
|
279
|
+
}
|
|
283
280
|
}
|
|
284
281
|
}
|