@math.gl/culling 4.1.0-alpha.3 → 4.1.0
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 +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +243 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.js +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.js +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -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 +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.js +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -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/bounding-volume.js.map +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/lib/culling-volume.d.ts +1 -0
- package/dist/lib/culling-volume.d.ts.map +1 -0
- package/dist/lib/culling-volume.js +1 -0
- package/dist/lib/culling-volume.js.map +1 -0
- package/dist/lib/perspective-frustum.d.ts +1 -0
- package/dist/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-frustum.js +1 -0
- package/dist/lib/perspective-frustum.js.map +1 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +1 -0
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-off-center-frustum.js +1 -0
- package/dist/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/lib/plane.d.ts +1 -0
- package/dist/lib/plane.d.ts.map +1 -0
- package/dist/lib/plane.js +1 -0
- package/dist/lib/plane.js.map +1 -0
- package/package.json +5 -5
package/dist/constants.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,CAAC,CAAC,EAAE,iEAAiE;IAC9E,YAAY,EAAE,CAAC,EAAE,oEAAoE;IACrF,MAAM,EAAE,CAAC,CAAC,yDAAyD;CAC3D,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -37,8 +37,11 @@ module.exports = __toCommonJS(dist_exports);
|
|
|
37
37
|
// dist/constants.js
|
|
38
38
|
var INTERSECTION = {
|
|
39
39
|
OUTSIDE: -1,
|
|
40
|
+
// Represents that an object is not contained within the frustum.
|
|
40
41
|
INTERSECTING: 0,
|
|
42
|
+
// Represents that an object intersects one of the frustum's planes.
|
|
41
43
|
INSIDE: 1
|
|
44
|
+
// Represents that an object is fully within the frustum.
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
// dist/lib/bounding-volumes/axis-aligned-bounding-box.js
|
|
@@ -46,6 +49,12 @@ var import_core = require("@math.gl/core");
|
|
|
46
49
|
var scratchVector = new import_core.Vector3();
|
|
47
50
|
var scratchNormal = new import_core.Vector3();
|
|
48
51
|
var AxisAlignedBoundingBox = class {
|
|
52
|
+
/**
|
|
53
|
+
* Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.
|
|
54
|
+
* @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.
|
|
55
|
+
* @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.
|
|
56
|
+
* @param center The center of the box; automatically computed if not supplied.
|
|
57
|
+
*/
|
|
49
58
|
constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) {
|
|
50
59
|
center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
|
|
51
60
|
this.center = new import_core.Vector3(center);
|
|
@@ -53,12 +62,29 @@ var AxisAlignedBoundingBox = class {
|
|
|
53
62
|
this.minimum = new import_core.Vector3(minimum);
|
|
54
63
|
this.maximum = new import_core.Vector3(maximum);
|
|
55
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Duplicates a AxisAlignedBoundingBox instance.
|
|
67
|
+
*
|
|
68
|
+
* @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.
|
|
69
|
+
*/
|
|
56
70
|
clone() {
|
|
57
71
|
return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
|
|
58
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Compares the provided AxisAlignedBoundingBox componentwise and returns
|
|
75
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
76
|
+
*
|
|
77
|
+
* @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.
|
|
78
|
+
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
|
79
|
+
*/
|
|
59
80
|
equals(right) {
|
|
60
81
|
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
61
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
85
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
86
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
87
|
+
*/
|
|
62
88
|
transform(transform) {
|
|
63
89
|
this.center.transformAsPoint(transform);
|
|
64
90
|
this.halfDiagonal.transform(transform);
|
|
@@ -66,6 +92,9 @@ var AxisAlignedBoundingBox = class {
|
|
|
66
92
|
this.maximum.transform(transform);
|
|
67
93
|
return this;
|
|
68
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Determines which side of a plane a box is located.
|
|
97
|
+
*/
|
|
69
98
|
intersectPlane(plane) {
|
|
70
99
|
const { halfDiagonal } = this;
|
|
71
100
|
const normal = scratchNormal.from(plane.normal);
|
|
@@ -79,9 +108,11 @@ var AxisAlignedBoundingBox = class {
|
|
|
79
108
|
}
|
|
80
109
|
return INTERSECTION.INTERSECTING;
|
|
81
110
|
}
|
|
111
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
82
112
|
distanceTo(point) {
|
|
83
113
|
return Math.sqrt(this.distanceSquaredTo(point));
|
|
84
114
|
}
|
|
115
|
+
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
85
116
|
distanceSquaredTo(point) {
|
|
86
117
|
const offset = scratchVector.from(point).subtract(this.center);
|
|
87
118
|
const { halfDiagonal } = this;
|
|
@@ -108,28 +139,37 @@ var import_core2 = require("@math.gl/core");
|
|
|
108
139
|
var scratchVector2 = new import_core2.Vector3();
|
|
109
140
|
var scratchVector22 = new import_core2.Vector3();
|
|
110
141
|
var BoundingSphere = class {
|
|
142
|
+
/** Creates a bounding sphere */
|
|
111
143
|
constructor(center = [0, 0, 0], radius = 0) {
|
|
112
144
|
this.radius = -0;
|
|
113
145
|
this.center = new import_core2.Vector3();
|
|
114
146
|
this.fromCenterRadius(center, radius);
|
|
115
147
|
}
|
|
148
|
+
/** Sets the bounding sphere from `center` and `radius`. */
|
|
116
149
|
fromCenterRadius(center, radius) {
|
|
117
150
|
this.center.from(center);
|
|
118
151
|
this.radius = radius;
|
|
119
152
|
return this;
|
|
120
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
|
|
156
|
+
* tightly and fully encompasses the box.
|
|
157
|
+
*/
|
|
121
158
|
fromCornerPoints(corner, oppositeCorner) {
|
|
122
159
|
oppositeCorner = scratchVector2.from(oppositeCorner);
|
|
123
160
|
this.center = new import_core2.Vector3().from(corner).add(oppositeCorner).scale(0.5);
|
|
124
161
|
this.radius = this.center.distance(oppositeCorner);
|
|
125
162
|
return this;
|
|
126
163
|
}
|
|
164
|
+
/** Compares the provided BoundingSphere component wise */
|
|
127
165
|
equals(right) {
|
|
128
166
|
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
|
|
129
167
|
}
|
|
168
|
+
/** Duplicates a BoundingSphere instance. */
|
|
130
169
|
clone() {
|
|
131
170
|
return new BoundingSphere(this.center, this.radius);
|
|
132
171
|
}
|
|
172
|
+
/** Computes a bounding sphere that contains both the left and right bounding spheres. */
|
|
133
173
|
union(boundingSphere) {
|
|
134
174
|
const leftCenter = this.center;
|
|
135
175
|
const leftRadius = this.radius;
|
|
@@ -149,6 +189,7 @@ var BoundingSphere = class {
|
|
|
149
189
|
this.radius = halfDistanceBetweenTangentPoints;
|
|
150
190
|
return this;
|
|
151
191
|
}
|
|
192
|
+
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
152
193
|
expand(point) {
|
|
153
194
|
const scratchPoint = scratchVector2.from(point);
|
|
154
195
|
const radius = scratchPoint.subtract(this.center).magnitude();
|
|
@@ -157,21 +198,31 @@ var BoundingSphere = class {
|
|
|
157
198
|
}
|
|
158
199
|
return this;
|
|
159
200
|
}
|
|
201
|
+
// BoundingVolume interface
|
|
202
|
+
/**
|
|
203
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
204
|
+
* @param sphere The bounding sphere to apply the transformation to.
|
|
205
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
206
|
+
* @returns self.
|
|
207
|
+
*/
|
|
160
208
|
transform(transform) {
|
|
161
209
|
this.center.transform(transform);
|
|
162
210
|
const scale = import_core2.mat4.getScaling(scratchVector2, transform);
|
|
163
211
|
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
|
|
164
212
|
return this;
|
|
165
213
|
}
|
|
214
|
+
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
166
215
|
distanceSquaredTo(point) {
|
|
167
216
|
const d = this.distanceTo(point);
|
|
168
217
|
return d * d;
|
|
169
218
|
}
|
|
219
|
+
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
170
220
|
distanceTo(point) {
|
|
171
221
|
const scratchPoint = scratchVector2.from(point);
|
|
172
222
|
const delta = scratchPoint.subtract(this.center);
|
|
173
223
|
return Math.max(0, delta.len() - this.radius);
|
|
174
224
|
}
|
|
225
|
+
/** Determines which side of a plane a sphere is located. */
|
|
175
226
|
intersectPlane(plane) {
|
|
176
227
|
const center = this.center;
|
|
177
228
|
const radius = this.radius;
|
|
@@ -212,12 +263,14 @@ var OrientedBoundingBox = class {
|
|
|
212
263
|
this.center = new import_core3.Vector3().from(center);
|
|
213
264
|
this.halfAxes = new import_core3.Matrix3(halfAxes);
|
|
214
265
|
}
|
|
266
|
+
/** Returns an array with three halfSizes for the bounding box */
|
|
215
267
|
get halfSize() {
|
|
216
268
|
const xAxis = this.halfAxes.getColumn(0);
|
|
217
269
|
const yAxis = this.halfAxes.getColumn(1);
|
|
218
270
|
const zAxis = this.halfAxes.getColumn(2);
|
|
219
271
|
return [new import_core3.Vector3(xAxis).len(), new import_core3.Vector3(yAxis).len(), new import_core3.Vector3(zAxis).len()];
|
|
220
272
|
}
|
|
273
|
+
/** Returns a quaternion describing the orientation of the bounding box */
|
|
221
274
|
get quaternion() {
|
|
222
275
|
const xAxis = this.halfAxes.getColumn(0);
|
|
223
276
|
const yAxis = this.halfAxes.getColumn(1);
|
|
@@ -227,6 +280,9 @@ var OrientedBoundingBox = class {
|
|
|
227
280
|
const normZAxis = new import_core3.Vector3(zAxis).normalize();
|
|
228
281
|
return new import_core3.Quaternion().fromMatrix3(new import_core3.Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));
|
|
229
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Create OrientedBoundingBox from quaternion based OBB,
|
|
285
|
+
*/
|
|
230
286
|
fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
|
|
231
287
|
const quaternionObject = new import_core3.Quaternion(quaternion);
|
|
232
288
|
const directionsMatrix = new import_core3.Matrix3().fromQuaternion(quaternionObject);
|
|
@@ -243,12 +299,15 @@ var OrientedBoundingBox = class {
|
|
|
243
299
|
this.halfAxes = directionsMatrix;
|
|
244
300
|
return this;
|
|
245
301
|
}
|
|
302
|
+
/** Duplicates a OrientedBoundingBox instance. */
|
|
246
303
|
clone() {
|
|
247
304
|
return new OrientedBoundingBox(this.center, this.halfAxes);
|
|
248
305
|
}
|
|
306
|
+
/** Compares the provided OrientedBoundingBox component wise and returns */
|
|
249
307
|
equals(right) {
|
|
250
308
|
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);
|
|
251
309
|
}
|
|
310
|
+
/** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
|
|
252
311
|
getBoundingSphere(result = new BoundingSphere()) {
|
|
253
312
|
const halfAxes = this.halfAxes;
|
|
254
313
|
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
@@ -259,6 +318,7 @@ var OrientedBoundingBox = class {
|
|
|
259
318
|
result.radius = cornerVector.magnitude();
|
|
260
319
|
return result;
|
|
261
320
|
}
|
|
321
|
+
/** Determines which side of a plane the oriented bounding box is located. */
|
|
262
322
|
intersectPlane(plane) {
|
|
263
323
|
const center = this.center;
|
|
264
324
|
const normal = plane.normal;
|
|
@@ -275,9 +335,15 @@ var OrientedBoundingBox = class {
|
|
|
275
335
|
}
|
|
276
336
|
return INTERSECTION.INTERSECTING;
|
|
277
337
|
}
|
|
338
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
278
339
|
distanceTo(point) {
|
|
279
340
|
return Math.sqrt(this.distanceSquaredTo(point));
|
|
280
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Computes the estimated distance squared from the closest point
|
|
344
|
+
* on a bounding box to a point.
|
|
345
|
+
* See Geometric Tools for Computer Graphics 10.4.2
|
|
346
|
+
*/
|
|
281
347
|
distanceSquaredTo(point) {
|
|
282
348
|
const offset = scratchOffset.from(point).subtract(this.center);
|
|
283
349
|
const halfAxes = this.halfAxes;
|
|
@@ -306,6 +372,21 @@ var OrientedBoundingBox = class {
|
|
|
306
372
|
}
|
|
307
373
|
return distanceSquared;
|
|
308
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* The distances calculated by the vector from the center of the bounding box
|
|
377
|
+
* to position projected onto direction.
|
|
378
|
+
*
|
|
379
|
+
* - If you imagine the infinite number of planes with normal direction,
|
|
380
|
+
* this computes the smallest distance to the closest and farthest planes
|
|
381
|
+
* from `position` that intersect the bounding box.
|
|
382
|
+
*
|
|
383
|
+
* @param position The position to calculate the distance from.
|
|
384
|
+
* @param direction The direction from position.
|
|
385
|
+
* @param result An Interval (array of length 2) to store the nearest and farthest distances.
|
|
386
|
+
* @returns Interval (array of length 2) with nearest and farthest distances
|
|
387
|
+
* on the bounding box from position in direction.
|
|
388
|
+
*/
|
|
389
|
+
// eslint-disable-next-line max-statements
|
|
309
390
|
computePlaneDistances(position, direction, result = [-0, -0]) {
|
|
310
391
|
let minDist = Number.POSITIVE_INFINITY;
|
|
311
392
|
let maxDist = Number.NEGATIVE_INFINITY;
|
|
@@ -358,6 +439,11 @@ var OrientedBoundingBox = class {
|
|
|
358
439
|
result[1] = maxDist;
|
|
359
440
|
return result;
|
|
360
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
444
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
445
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
446
|
+
*/
|
|
361
447
|
transform(transformation) {
|
|
362
448
|
this.center.transformAsPoint(transformation);
|
|
363
449
|
const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
@@ -387,12 +473,14 @@ var Plane = class {
|
|
|
387
473
|
this.distance = -0;
|
|
388
474
|
this.fromNormalDistance(normal, distance);
|
|
389
475
|
}
|
|
476
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
390
477
|
fromNormalDistance(normal, distance) {
|
|
391
478
|
(0, import_core4.assert)(Number.isFinite(distance));
|
|
392
479
|
this.normal.from(normal).normalize();
|
|
393
480
|
this.distance = distance;
|
|
394
481
|
return this;
|
|
395
482
|
}
|
|
483
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
396
484
|
fromPointNormal(point, normal) {
|
|
397
485
|
point = scratchPosition.from(point);
|
|
398
486
|
this.normal.from(normal).normalize();
|
|
@@ -400,21 +488,28 @@ var Plane = class {
|
|
|
400
488
|
this.distance = distance;
|
|
401
489
|
return this;
|
|
402
490
|
}
|
|
491
|
+
/** Creates a plane from the general equation */
|
|
403
492
|
fromCoefficients(a, b, c, d) {
|
|
404
493
|
this.normal.set(a, b, c);
|
|
405
494
|
(0, import_core4.assert)((0, import_core4.equals)(this.normal.len(), 1));
|
|
406
495
|
this.distance = d;
|
|
407
496
|
return this;
|
|
408
497
|
}
|
|
498
|
+
/** Duplicates a Plane instance. */
|
|
409
499
|
clone() {
|
|
410
500
|
return new Plane(this.normal, this.distance);
|
|
411
501
|
}
|
|
502
|
+
/** Compares the provided Planes by normal and distance */
|
|
412
503
|
equals(right) {
|
|
413
504
|
return (0, import_core4.equals)(this.distance, right.distance) && (0, import_core4.equals)(this.normal, right.normal);
|
|
414
505
|
}
|
|
506
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
507
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
508
|
+
*/
|
|
415
509
|
getPointDistance(point) {
|
|
416
510
|
return this.normal.dot(point) + this.distance;
|
|
417
511
|
}
|
|
512
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
418
513
|
transform(matrix4) {
|
|
419
514
|
const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
420
515
|
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
@@ -433,9 +528,17 @@ var faces = [new import_core5.Vector3([1, 0, 0]), new import_core5.Vector3([0, 1
|
|
|
433
528
|
var scratchPlaneCenter = new import_core5.Vector3();
|
|
434
529
|
var scratchPlaneNormal = new import_core5.Vector3();
|
|
435
530
|
var CullingVolume = class {
|
|
531
|
+
/**
|
|
532
|
+
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
533
|
+
* @param planes Array of clipping planes.
|
|
534
|
+
* */
|
|
436
535
|
constructor(planes = []) {
|
|
437
536
|
this.planes = planes;
|
|
438
537
|
}
|
|
538
|
+
/**
|
|
539
|
+
* Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
|
|
540
|
+
* The planes are aligned to the x, y, and z axes in world coordinates.
|
|
541
|
+
*/
|
|
439
542
|
fromBoundingSphere(boundingSphere) {
|
|
440
543
|
this.planes.length = 2 * faces.length;
|
|
441
544
|
const center = boundingSphere.center;
|
|
@@ -459,6 +562,7 @@ var CullingVolume = class {
|
|
|
459
562
|
}
|
|
460
563
|
return this;
|
|
461
564
|
}
|
|
565
|
+
/** Determines whether a bounding volume intersects the culling volume. */
|
|
462
566
|
computeVisibility(boundingVolume) {
|
|
463
567
|
let intersect = INTERSECTION.INSIDE;
|
|
464
568
|
for (const plane of this.planes) {
|
|
@@ -474,6 +578,14 @@ var CullingVolume = class {
|
|
|
474
578
|
}
|
|
475
579
|
return intersect;
|
|
476
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Determines whether a bounding volume intersects the culling volume.
|
|
583
|
+
*
|
|
584
|
+
* @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
|
|
585
|
+
* volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
|
|
586
|
+
* the parent (and therefore this) volume is completely inside plane[planeIndex]
|
|
587
|
+
* and that plane check can be skipped.
|
|
588
|
+
*/
|
|
477
589
|
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
478
590
|
(0, import_core5.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
|
|
479
591
|
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
|
|
@@ -509,6 +621,26 @@ var scratchPlaneNearCenter = new import_core6.Vector3();
|
|
|
509
621
|
var scratchPlaneFarCenter = new import_core6.Vector3();
|
|
510
622
|
var scratchPlaneNormal2 = new import_core6.Vector3();
|
|
511
623
|
var PerspectiveOffCenterFrustum = class {
|
|
624
|
+
/**
|
|
625
|
+
* The viewing frustum is defined by 6 planes.
|
|
626
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
627
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
628
|
+
* plane from the origin/camera position.
|
|
629
|
+
*
|
|
630
|
+
* @alias PerspectiveOffCenterFrustum
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* const frustum = new PerspectiveOffCenterFrustum({
|
|
634
|
+
* left : -1.0,
|
|
635
|
+
* right : 1.0,
|
|
636
|
+
* top : 1.0,
|
|
637
|
+
* bottom : -1.0,
|
|
638
|
+
* near : 1.0,
|
|
639
|
+
* far : 100.0
|
|
640
|
+
* });
|
|
641
|
+
*
|
|
642
|
+
* @see PerspectiveFrustum
|
|
643
|
+
*/
|
|
512
644
|
constructor(options = {}) {
|
|
513
645
|
this._cullingVolume = new CullingVolume([
|
|
514
646
|
new Plane(),
|
|
@@ -534,6 +666,10 @@ var PerspectiveOffCenterFrustum = class {
|
|
|
534
666
|
this.far = far;
|
|
535
667
|
this._far = far;
|
|
536
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Returns a duplicate of a PerspectiveOffCenterFrustum instance.
|
|
671
|
+
* @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.
|
|
672
|
+
* */
|
|
537
673
|
clone() {
|
|
538
674
|
return new PerspectiveOffCenterFrustum({
|
|
539
675
|
right: this.right,
|
|
@@ -544,17 +680,47 @@ var PerspectiveOffCenterFrustum = class {
|
|
|
544
680
|
far: this.far
|
|
545
681
|
});
|
|
546
682
|
}
|
|
683
|
+
/**
|
|
684
|
+
* Compares the provided PerspectiveOffCenterFrustum componentwise and returns
|
|
685
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
686
|
+
*
|
|
687
|
+
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
688
|
+
*/
|
|
547
689
|
equals(other) {
|
|
548
690
|
return other && other instanceof PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far;
|
|
549
691
|
}
|
|
692
|
+
/**
|
|
693
|
+
* Gets the perspective projection matrix computed from the view frustum.
|
|
694
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
695
|
+
* @type {Matrix4}
|
|
696
|
+
*
|
|
697
|
+
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
|
|
698
|
+
*/
|
|
550
699
|
get projectionMatrix() {
|
|
551
700
|
this._update();
|
|
552
701
|
return this._perspectiveMatrix;
|
|
553
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
705
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
706
|
+
* @type {Matrix4}
|
|
707
|
+
*
|
|
708
|
+
* @see PerspectiveOffCenterFrustum#projectionMatrix
|
|
709
|
+
*/
|
|
554
710
|
get infiniteProjectionMatrix() {
|
|
555
711
|
this._update();
|
|
556
712
|
return this._infinitePerspective;
|
|
557
713
|
}
|
|
714
|
+
/**
|
|
715
|
+
* Creates a culling volume for this frustum.
|
|
716
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* // Check if a bounding volume intersects the frustum.
|
|
720
|
+
* const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
721
|
+
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
722
|
+
*/
|
|
723
|
+
// eslint-disable-next-line complexity, max-statements
|
|
558
724
|
computeCullingVolume(position, direction, up) {
|
|
559
725
|
(0, import_core6.assert)(position, "position is required.");
|
|
560
726
|
(0, import_core6.assert)(direction, "direction is required.");
|
|
@@ -579,6 +745,30 @@ var PerspectiveOffCenterFrustum = class {
|
|
|
579
745
|
planes[5].fromPointNormal(farCenter, normal);
|
|
580
746
|
return this._cullingVolume;
|
|
581
747
|
}
|
|
748
|
+
/**
|
|
749
|
+
* Returns the pixel's width and height in meters.
|
|
750
|
+
*
|
|
751
|
+
* @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.
|
|
752
|
+
*
|
|
753
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
754
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* // Example 1
|
|
758
|
+
* // Get the width and height of a pixel.
|
|
759
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* // Example 2
|
|
763
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
764
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
765
|
+
* const position = camera.position;
|
|
766
|
+
* const direction = camera.direction;
|
|
767
|
+
* const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
768
|
+
* const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
769
|
+
* const distance = Vector3.magnitude(toCenterProj);
|
|
770
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
771
|
+
*/
|
|
582
772
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
583
773
|
this._update();
|
|
584
774
|
(0, import_core6.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
@@ -595,6 +785,7 @@ var PerspectiveOffCenterFrustum = class {
|
|
|
595
785
|
result.y = pixelHeight;
|
|
596
786
|
return result;
|
|
597
787
|
}
|
|
788
|
+
// eslint-disable-next-line complexity, max-statements
|
|
598
789
|
_update() {
|
|
599
790
|
(0, import_core6.assert)(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
600
791
|
const { top, bottom, right, left, near, far } = this;
|
|
@@ -640,6 +831,9 @@ var PerspectiveFrustum = class {
|
|
|
640
831
|
this.xOffset = xOffset;
|
|
641
832
|
this.yOffset = yOffset;
|
|
642
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* Returns a duplicate of a PerspectiveFrustum instance.
|
|
836
|
+
*/
|
|
643
837
|
clone() {
|
|
644
838
|
return new PerspectiveFrustum({
|
|
645
839
|
aspectRatio: this.aspectRatio,
|
|
@@ -648,6 +842,10 @@ var PerspectiveFrustum = class {
|
|
|
648
842
|
far: this.far
|
|
649
843
|
});
|
|
650
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* Compares the provided PerspectiveFrustum componentwise and returns
|
|
847
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
848
|
+
*/
|
|
651
849
|
equals(other) {
|
|
652
850
|
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
653
851
|
return false;
|
|
@@ -656,30 +854,75 @@ var PerspectiveFrustum = class {
|
|
|
656
854
|
other._update();
|
|
657
855
|
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
|
|
658
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* Gets the perspective projection matrix computed from the view this.
|
|
859
|
+
*/
|
|
659
860
|
get projectionMatrix() {
|
|
660
861
|
this._update();
|
|
661
862
|
return this._offCenterFrustum.projectionMatrix;
|
|
662
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
866
|
+
*/
|
|
663
867
|
get infiniteProjectionMatrix() {
|
|
664
868
|
this._update();
|
|
665
869
|
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
666
870
|
}
|
|
871
|
+
/**
|
|
872
|
+
* Gets the angle of the vertical field of view, in radians.
|
|
873
|
+
*/
|
|
667
874
|
get fovy() {
|
|
668
875
|
this._update();
|
|
669
876
|
return this._fovy;
|
|
670
877
|
}
|
|
878
|
+
/**
|
|
879
|
+
* @private
|
|
880
|
+
*/
|
|
671
881
|
get sseDenominator() {
|
|
672
882
|
this._update();
|
|
673
883
|
return this._sseDenominator;
|
|
674
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Creates a culling volume for this this.ion.
|
|
887
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* // Check if a bounding volume intersects the this.
|
|
891
|
+
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
892
|
+
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
893
|
+
*/
|
|
675
894
|
computeCullingVolume(position, direction, up) {
|
|
676
895
|
this._update();
|
|
677
896
|
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
678
897
|
}
|
|
898
|
+
/**
|
|
899
|
+
* Returns the pixel's width and height in meters.
|
|
900
|
+
* @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.
|
|
901
|
+
*
|
|
902
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
903
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* // Example 1
|
|
907
|
+
* // Get the width and height of a pixel.
|
|
908
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* // Example 2
|
|
912
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
913
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
914
|
+
* var position = camera.position;
|
|
915
|
+
* var direction = camera.direction;
|
|
916
|
+
* var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
917
|
+
* var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
918
|
+
* var distance = Vector3.magnitude(toCenterProj);
|
|
919
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
920
|
+
*/
|
|
679
921
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
680
922
|
this._update();
|
|
681
923
|
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core7.Vector2());
|
|
682
924
|
}
|
|
925
|
+
// eslint-disable-next-line complexity, max-statements
|
|
683
926
|
_update() {
|
|
684
927
|
(0, import_core7.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
685
928
|
const f = this._offCenterFrustum;
|