@math.gl/culling 3.6.0-alpha.1 → 3.6.0-alpha.4
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/constants.js +1 -1
- package/dist/es5/index.js +12 -12
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +123 -72
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +109 -81
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +37 -36
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +75 -63
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +111 -90
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +212 -187
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +111 -74
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +78 -57
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +113 -98
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +70 -52
- package/dist/es5/lib/plane.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -2
- package/package.json +4 -4
- package/src/lib/algorithms/bounding-sphere-from-points.ts +0 -2
|
@@ -7,6 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
10
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
15
|
|
|
12
16
|
var _core = require("@math.gl/core");
|
|
@@ -15,100 +19,133 @@ var _constants = require("../constants");
|
|
|
15
19
|
|
|
16
20
|
var _plane = _interopRequireDefault(require("./plane"));
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const scratchPlane = new _plane.default(new _core.Vector3(1.0, 0.0, 0.0), 0.0);
|
|
22
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
23
|
+
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
27
|
+
|
|
28
|
+
var faces = [new _core.Vector3([1, 0, 0]), new _core.Vector3([0, 1, 0]), new _core.Vector3([0, 0, 1])];
|
|
29
|
+
var scratchPlaneCenter = new _core.Vector3();
|
|
30
|
+
var scratchPlaneNormal = new _core.Vector3();
|
|
31
|
+
var scratchPlane = new _plane.default(new _core.Vector3(1.0, 0.0, 0.0), 0.0);
|
|
32
|
+
|
|
33
|
+
var CullingVolume = function () {
|
|
34
|
+
function CullingVolume() {
|
|
35
|
+
var planes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
36
|
+
(0, _classCallCheck2.default)(this, CullingVolume);
|
|
25
37
|
(0, _defineProperty2.default)(this, "planes", void 0);
|
|
26
38
|
this.planes = planes;
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
(0, _createClass2.default)(CullingVolume, [{
|
|
42
|
+
key: "fromBoundingSphere",
|
|
43
|
+
value: function fromBoundingSphere(boundingSphere) {
|
|
44
|
+
this.planes.length = 2 * faces.length;
|
|
45
|
+
var center = boundingSphere.center;
|
|
46
|
+
var radius = boundingSphere.radius;
|
|
47
|
+
var planeIndex = 0;
|
|
48
|
+
|
|
49
|
+
var _iterator = _createForOfIteratorHelper(faces),
|
|
50
|
+
_step;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var faceNormal = _step.value;
|
|
55
|
+
var plane0 = this.planes[planeIndex];
|
|
56
|
+
var plane1 = this.planes[planeIndex + 1];
|
|
57
|
+
|
|
58
|
+
if (!plane0) {
|
|
59
|
+
plane0 = this.planes[planeIndex] = new _plane.default();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!plane1) {
|
|
63
|
+
plane1 = this.planes[planeIndex + 1] = new _plane.default();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
|
|
67
|
+
var plane0Distance = -faceNormal.dot(plane0Center);
|
|
68
|
+
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
69
|
+
var plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
|
|
70
|
+
var negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
71
|
+
var plane1Distance = -negatedFaceNormal.dot(plane1Center);
|
|
72
|
+
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
73
|
+
planeIndex += 2;
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
_iterator.e(err);
|
|
77
|
+
} finally {
|
|
78
|
+
_iterator.f();
|
|
41
79
|
}
|
|
42
80
|
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
84
|
+
key: "computeVisibility",
|
|
85
|
+
value: function computeVisibility(boundingVolume) {
|
|
86
|
+
var intersect = _constants.INTERSECTION.INSIDE;
|
|
87
|
+
|
|
88
|
+
var _iterator2 = _createForOfIteratorHelper(this.planes),
|
|
89
|
+
_step2;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
93
|
+
var plane = _step2.value;
|
|
94
|
+
var result = boundingVolume.intersectPlane(plane);
|
|
95
|
+
|
|
96
|
+
switch (result) {
|
|
97
|
+
case _constants.INTERSECTION.OUTSIDE:
|
|
98
|
+
return _constants.INTERSECTION.OUTSIDE;
|
|
99
|
+
|
|
100
|
+
case _constants.INTERSECTION.INTERSECTING:
|
|
101
|
+
intersect = _constants.INTERSECTION.INTERSECTING;
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
default:
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
_iterator2.e(err);
|
|
109
|
+
} finally {
|
|
110
|
+
_iterator2.f();
|
|
45
111
|
}
|
|
46
112
|
|
|
47
|
-
|
|
48
|
-
const plane0Distance = -faceNormal.dot(plane0Center);
|
|
49
|
-
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
50
|
-
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
|
|
51
|
-
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
52
|
-
const plane1Distance = -negatedFaceNormal.dot(plane1Center);
|
|
53
|
-
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
54
|
-
planeIndex += 2;
|
|
113
|
+
return intersect;
|
|
55
114
|
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "computeVisibilityWithPlaneMask",
|
|
117
|
+
value: function computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
118
|
+
(0, _core.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
|
|
56
119
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
computeVisibility(boundingVolume) {
|
|
61
|
-
let intersect = _constants.INTERSECTION.INSIDE;
|
|
62
|
-
|
|
63
|
-
for (const plane of this.planes) {
|
|
64
|
-
const result = boundingVolume.intersectPlane(plane);
|
|
65
|
-
|
|
66
|
-
switch (result) {
|
|
67
|
-
case _constants.INTERSECTION.OUTSIDE:
|
|
68
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
69
|
-
|
|
70
|
-
case _constants.INTERSECTION.INTERSECTING:
|
|
71
|
-
intersect = _constants.INTERSECTION.INTERSECTING;
|
|
72
|
-
break;
|
|
73
|
-
|
|
74
|
-
default:
|
|
120
|
+
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
|
|
121
|
+
return parentPlaneMask;
|
|
75
122
|
}
|
|
76
|
-
}
|
|
77
123
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
82
|
-
(0, _core.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
|
|
124
|
+
var mask = CullingVolume.MASK_INSIDE;
|
|
125
|
+
var planes = this.planes;
|
|
83
126
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
127
|
+
for (var k = 0; k < this.planes.length; ++k) {
|
|
128
|
+
var flag = k < 31 ? 1 << k : 0;
|
|
87
129
|
|
|
88
|
-
|
|
89
|
-
|
|
130
|
+
if (k < 31 && (parentPlaneMask & flag) === 0) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
90
133
|
|
|
91
|
-
|
|
92
|
-
|
|
134
|
+
var plane = planes[k];
|
|
135
|
+
var result = boundingVolume.intersectPlane(plane);
|
|
93
136
|
|
|
94
|
-
|
|
95
|
-
|
|
137
|
+
if (result === _constants.INTERSECTION.OUTSIDE) {
|
|
138
|
+
return CullingVolume.MASK_OUTSIDE;
|
|
139
|
+
} else if (result === _constants.INTERSECTION.INTERSECTING) {
|
|
140
|
+
mask |= flag;
|
|
141
|
+
}
|
|
96
142
|
}
|
|
97
143
|
|
|
98
|
-
|
|
99
|
-
const result = boundingVolume.intersectPlane(plane);
|
|
100
|
-
|
|
101
|
-
if (result === _constants.INTERSECTION.OUTSIDE) {
|
|
102
|
-
return CullingVolume.MASK_OUTSIDE;
|
|
103
|
-
} else if (result === _constants.INTERSECTION.INTERSECTING) {
|
|
104
|
-
mask |= flag;
|
|
105
|
-
}
|
|
144
|
+
return mask;
|
|
106
145
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
146
|
+
}]);
|
|
147
|
+
return CullingVolume;
|
|
148
|
+
}();
|
|
112
149
|
|
|
113
150
|
exports.default = CullingVolume;
|
|
114
151
|
(0, _defineProperty2.default)(CullingVolume, "MASK_OUTSIDE", 0xffffffff);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["faces","Vector3","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","Plane","CullingVolume","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["faces","Vector3","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","Plane","CullingVolume","planes","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","plane0Distance","dot","fromPointNormal","plane1Center","negatedFaceNormal","negate","plane1Distance","boundingVolume","intersect","INTERSECTION","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA;;AACA;;;;;;;;AAKA,IAAMA,KAAK,GAAG,CAAC,IAAIC,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAzB,EAAiD,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAjD,CAAd;AAEA,IAAMC,kBAAkB,GAAG,IAAID,aAAJ,EAA3B;AACA,IAAME,kBAAkB,GAAG,IAAIF,aAAJ,EAA3B;AACA,IAAMG,YAAY,GAAG,IAAIC,cAAJ,CAAU,IAAIJ,aAAJ,CAAY,GAAZ,EAAiB,GAAjB,EAAsB,GAAtB,CAAV,EAAsC,GAAtC,CAArB;;IAGqBK,a;AA0B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,KAAKA,CAAd,GAAkB,CAA/B;;AACA,YAAIA,CAAC,GAAG,EAAJ,IAAU,CAACN,eAAe,GAAGO,IAAnB,MAA6B,CAA3C,EAA8C;AAE5C;AACD;;AAED,YAAMZ,KAAK,GAAGxB,MAAM,CAACmC,CAAD,CAApB;AACA,YAAMV,MAAM,GAAGL,cAAc,CAACM,cAAf,CAA8BF,KAA9B,CAAf;;AACA,YAAIC,MAAM,KAAKH,wBAAaK,OAA5B,EAAqC;AACnC,iBAAO5B,aAAa,CAACiC,YAArB;AACD,SAFD,MAEO,IAAIP,MAAM,KAAKH,wBAAaM,YAA5B,EAA0C;AAC/CM,UAAAA,IAAI,IAAIE,IAAR;AACD;AACF;;AAED,aAAOF,IAAP;AACD;;;;;;8BAzIkBnC,a,kBAKG,U;8BALHA,a,iBAWE,U;8BAXFA,a,wBAiBS,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport Plane from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type BoundingSphere from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\nconst scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport default class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): INTERSECTION {\n // const planes = this.planes;\n let intersect = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
|
|
@@ -7,16 +7,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
10
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
15
|
|
|
12
16
|
var _core = require("@math.gl/core");
|
|
13
17
|
|
|
14
18
|
var _perspectiveOffCenterFrustum = _interopRequireDefault(require("./perspective-off-center-frustum"));
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
+
|
|
24
|
+
var defined = function defined(val) {
|
|
25
|
+
return val !== null && typeof val !== 'undefined';
|
|
26
|
+
};
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
var PerspectiveFrustum = function () {
|
|
29
|
+
function PerspectiveFrustum() {
|
|
30
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
(0, _classCallCheck2.default)(this, PerspectiveFrustum);
|
|
20
32
|
(0, _defineProperty2.default)(this, "_offCenterFrustum", new _perspectiveOffCenterFrustum.default());
|
|
21
33
|
(0, _defineProperty2.default)(this, "fov", void 0);
|
|
22
34
|
(0, _defineProperty2.default)(this, "_fov", void 0);
|
|
@@ -32,13 +44,12 @@ class PerspectiveFrustum {
|
|
|
32
44
|
(0, _defineProperty2.default)(this, "_xOffset", void 0);
|
|
33
45
|
(0, _defineProperty2.default)(this, "yOffset", void 0);
|
|
34
46
|
(0, _defineProperty2.default)(this, "_yOffset", void 0);
|
|
35
|
-
options = {
|
|
47
|
+
options = _objectSpread({
|
|
36
48
|
near: 1.0,
|
|
37
49
|
far: 500000000.0,
|
|
38
50
|
xOffset: 0.0,
|
|
39
|
-
yOffset: 0.0
|
|
40
|
-
|
|
41
|
-
};
|
|
51
|
+
yOffset: 0.0
|
|
52
|
+
}, options);
|
|
42
53
|
this.fov = options.fov;
|
|
43
54
|
this.aspectRatio = options.aspectRatio;
|
|
44
55
|
this.near = options.near;
|
|
@@ -51,62 +62,72 @@ class PerspectiveFrustum {
|
|
|
51
62
|
this._yOffset = this.yOffset;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
equals(other) {
|
|
64
|
-
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
65
|
-
return false;
|
|
65
|
+
(0, _createClass2.default)(PerspectiveFrustum, [{
|
|
66
|
+
key: "clone",
|
|
67
|
+
value: function clone() {
|
|
68
|
+
return new PerspectiveFrustum({
|
|
69
|
+
aspectRatio: this.aspectRatio,
|
|
70
|
+
fov: this.fov,
|
|
71
|
+
near: this.near,
|
|
72
|
+
far: this.far
|
|
73
|
+
});
|
|
66
74
|
}
|
|
67
|
-
|
|
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
|
-
|
|
75
|
+
}, {
|
|
76
|
+
key: "equals",
|
|
77
|
+
value: function equals(other) {
|
|
78
|
+
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
update(this);
|
|
83
|
+
update(other);
|
|
84
|
+
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: "projectionMatrix",
|
|
88
|
+
get: function get() {
|
|
89
|
+
update(this);
|
|
90
|
+
return this._offCenterFrustum.projectionMatrix;
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "infiniteProjectionMatrix",
|
|
94
|
+
get: function get() {
|
|
95
|
+
update(this);
|
|
96
|
+
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "fovy",
|
|
100
|
+
get: function get() {
|
|
101
|
+
update(this);
|
|
102
|
+
return this._fovy;
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "sseDenominator",
|
|
106
|
+
get: function get() {
|
|
107
|
+
update(this);
|
|
108
|
+
return this._sseDenominator;
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "computeCullingVolume",
|
|
112
|
+
value: function computeCullingVolume(position, direction, up) {
|
|
113
|
+
update(this);
|
|
114
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
115
|
+
}
|
|
116
|
+
}, {
|
|
117
|
+
key: "getPixelDimensions",
|
|
118
|
+
value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
119
|
+
update(this);
|
|
120
|
+
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result);
|
|
121
|
+
}
|
|
122
|
+
}]);
|
|
123
|
+
return PerspectiveFrustum;
|
|
124
|
+
}();
|
|
104
125
|
|
|
105
126
|
exports.default = PerspectiveFrustum;
|
|
106
127
|
|
|
107
128
|
function update(frustum) {
|
|
108
129
|
(0, _core.assert)(Number.isFinite(frustum.fov) && Number.isFinite(frustum.aspectRatio) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
|
|
109
|
-
|
|
130
|
+
var f = frustum._offCenterFrustum;
|
|
110
131
|
|
|
111
132
|
if (frustum.fov !== frustum._fov || frustum.aspectRatio !== frustum._aspectRatio || frustum.near !== frustum._near || frustum.far !== frustum._far || frustum.xOffset !== frustum._xOffset || frustum.yOffset !== frustum._yOffset) {
|
|
112
133
|
(0, _core.assert)(frustum.fov >= 0 && frustum.fov < Math.PI);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["defined","val","PerspectiveFrustum","constructor","options","PerspectiveOffCenterFrustum","near","far","xOffset","yOffset","fov","aspectRatio","_near","_far","_xOffset","_yOffset","clone","equals","other","update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","frustum","Number","isFinite","f","_fov","_aspectRatio","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";;;;;;;;;;;AASA;;AACA;;AAEA,MAAMA,OAAO,GAAIC,GAAD,IAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAxD;;AA6Be,MAAMC,kBAAN,CAAyB;AAyCtCC,EAAAA,WAAW,CAACC,OAA4B,GAAG,EAAhC,EAAoC;AAAA,6DAxC3B,IAAIC,oCAAJ,EAwC2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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CAACvB,IAAR,GAAeuB,OAAO,CAAC7B,GAAvB;AACA6B,IAAAA,OAAO,CAACV,eAAR,GAA0B,MAAMgB,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACZ,KAAvB,CAAhC;AACAY,IAAAA,OAAO,CAACtB,QAAR,GAAmBsB,OAAO,CAAC5B,OAA3B;AACA4B,IAAAA,OAAO,CAACrB,QAAR,GAAmBqB,OAAO,CAAC3B,OAA3B;AAEA8B,IAAAA,CAAC,CAACO,GAAF,GAAQV,OAAO,CAAC9B,IAAR,GAAeoC,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACZ,KAAvB,CAAvB;AACAe,IAAAA,CAAC,CAACQ,MAAF,GAAW,CAACR,CAAC,CAACO,GAAd;AACAP,IAAAA,CAAC,CAACS,KAAF,GAAUZ,OAAO,CAACzB,WAAR,GAAsB4B,CAAC,CAACO,GAAlC;AACAP,IAAAA,CAAC,CAACU,IAAF,GAAS,CAACV,CAAC,CAACS,KAAZ;AACAT,IAAAA,CAAC,CAACjC,IAAF,GAAS8B,OAAO,CAAC9B,IAAjB;AACAiC,IAAAA,CAAC,CAAChC,GAAF,GAAQ6B,OAAO,CAAC7B,GAAhB;AAEAgC,IAAAA,CAAC,CAACS,KAAF,IAAWZ,OAAO,CAAC5B,OAAnB;AACA+B,IAAAA,CAAC,CAACU,IAAF,IAAUb,OAAO,CAAC5B,OAAlB;AACA+B,IAAAA,CAAC,CAACO,GAAF,IAASV,OAAO,CAAC3B,OAAjB;AACA8B,IAAAA,CAAC,CAACQ,MAAF,IAAYX,OAAO,CAAC3B,OAApB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {assert, Matrix4} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.\n * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {Number} [options.near=1.0] The distance of the near plane.\n * @param {Number} [options.far=500000000.0] The distance of the far plane.\n * @param {Number} [options.xOffset=0.0] The offset in the x direction.\n * @param {Number} [options.yOffset=0.0] The offset in the y direction.\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov: number;\n _fov;\n _fovy;\n _sseDenominator;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio: number;\n _aspectRatio;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n _near;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n _far;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n _xOffset;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n _yOffset;\n\n constructor(options: Record<string, any> = {}) {\n options = {\n near: 1.0,\n far: 500000000.0,\n xOffset: 0.0,\n yOffset: 0.0,\n ...options\n };\n\n this.fov = options.fov;\n\n this.aspectRatio = options.aspectRatio;\n\n this.near = options.near;\n this._near = this.near;\n\n this.far = options.far;\n this._far = this.far;\n\n this.xOffset = options.xOffset;\n this._xOffset = this.xOffset;\n\n this.yOffset = options.yOffset;\n this._yOffset = this.yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n */\n get projectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n update(this);\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n update(this);\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(position, direction, up) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @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.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result\n );\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.fov) &&\n Number.isFinite(frustum.aspectRatio) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.fov !== frustum._fov ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far ||\n frustum.xOffset !== frustum._xOffset ||\n frustum.yOffset !== frustum._yOffset\n ) {\n assert(frustum.fov >= 0 && frustum.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(frustum.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(frustum.near >= 0 && frustum.near < frustum.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._fov = frustum.fov;\n frustum._fovy =\n frustum.aspectRatio <= 1\n ? frustum.fov\n : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);\n frustum._xOffset = frustum.xOffset;\n frustum._yOffset = frustum.yOffset;\n\n f.top = frustum.near * Math.tan(0.5 * frustum._fovy);\n f.bottom = -f.top;\n f.right = frustum.aspectRatio * f.top;\n f.left = -f.right;\n f.near = frustum.near;\n f.far = frustum.far;\n\n f.right += frustum.xOffset;\n f.left += frustum.xOffset;\n f.top += frustum.yOffset;\n f.bottom += frustum.yOffset;\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["defined","val","PerspectiveFrustum","options","PerspectiveOffCenterFrustum","near","far","xOffset","yOffset","fov","aspectRatio","_near","_far","_xOffset","_yOffset","other","update","_offCenterFrustum","equals","projectionMatrix","infiniteProjectionMatrix","_fovy","_sseDenominator","position","direction","up","computeCullingVolume","drawingBufferWidth","drawingBufferHeight","distance","result","getPixelDimensions","frustum","Number","isFinite","f","_fov","_aspectRatio","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";;;;;;;;;;;;;;;AASA;;AACA;;;;;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,GAAD;AAAA,SAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAxC;AAAA,CAAhB;;IA6BqBC,kB;AAyCnB,gCAA+C;AAAA,QAAnCC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,IAAR,GAAeoB,OAAO,CAAC1B,GAAvB;AACA0B,IAAAA,OAAO,CAACV,eAAR,GAA0B,MAAMgB,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACX,KAAvB,CAAhC;AACAW,IAAAA,OAAO,CAACnB,QAAR,GAAmBmB,OAAO,CAACzB,OAA3B;AACAyB,IAAAA,OAAO,CAAClB,QAAR,GAAmBkB,OAAO,CAACxB,OAA3B;AAEA2B,IAAAA,CAAC,CAACO,GAAF,GAAQV,OAAO,CAAC3B,IAAR,GAAeiC,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACX,KAAvB,CAAvB;AACAc,IAAAA,CAAC,CAACQ,MAAF,GAAW,CAACR,CAAC,CAACO,GAAd;AACAP,IAAAA,CAAC,CAACS,KAAF,GAAUZ,OAAO,CAACtB,WAAR,GAAsByB,CAAC,CAACO,GAAlC;AACAP,IAAAA,CAAC,CAACU,IAAF,GAAS,CAACV,CAAC,CAACS,KAAZ;AACAT,IAAAA,CAAC,CAAC9B,IAAF,GAAS2B,OAAO,CAAC3B,IAAjB;AACA8B,IAAAA,CAAC,CAAC7B,GAAF,GAAQ0B,OAAO,CAAC1B,GAAhB;AAEA6B,IAAAA,CAAC,CAACS,KAAF,IAAWZ,OAAO,CAACzB,OAAnB;AACA4B,IAAAA,CAAC,CAACU,IAAF,IAAUb,OAAO,CAACzB,OAAlB;AACA4B,IAAAA,CAAC,CAACO,GAAF,IAASV,OAAO,CAACxB,OAAjB;AACA2B,IAAAA,CAAC,CAACQ,MAAF,IAAYX,OAAO,CAACxB,OAApB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {assert, Matrix4} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.\n * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {Number} [options.near=1.0] The distance of the near plane.\n * @param {Number} [options.far=500000000.0] The distance of the far plane.\n * @param {Number} [options.xOffset=0.0] The offset in the x direction.\n * @param {Number} [options.yOffset=0.0] The offset in the y direction.\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov: number;\n _fov;\n _fovy;\n _sseDenominator;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio: number;\n _aspectRatio;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n _near;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n _far;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n _xOffset;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n _yOffset;\n\n constructor(options: Record<string, any> = {}) {\n options = {\n near: 1.0,\n far: 500000000.0,\n xOffset: 0.0,\n yOffset: 0.0,\n ...options\n };\n\n this.fov = options.fov;\n\n this.aspectRatio = options.aspectRatio;\n\n this.near = options.near;\n this._near = this.near;\n\n this.far = options.far;\n this._far = this.far;\n\n this.xOffset = options.xOffset;\n this._xOffset = this.xOffset;\n\n this.yOffset = options.yOffset;\n this._yOffset = this.yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n */\n get projectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n update(this);\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n update(this);\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(position, direction, up) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @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.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result\n );\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.fov) &&\n Number.isFinite(frustum.aspectRatio) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.fov !== frustum._fov ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far ||\n frustum.xOffset !== frustum._xOffset ||\n frustum.yOffset !== frustum._yOffset\n ) {\n assert(frustum.fov >= 0 && frustum.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(frustum.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(frustum.near >= 0 && frustum.near < frustum.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._fov = frustum.fov;\n frustum._fovy =\n frustum.aspectRatio <= 1\n ? frustum.fov\n : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);\n frustum._xOffset = frustum.xOffset;\n frustum._yOffset = frustum.yOffset;\n\n f.top = frustum.near * Math.tan(0.5 * frustum._fovy);\n f.bottom = -f.top;\n f.right = frustum.aspectRatio * f.top;\n f.left = -f.right;\n f.near = frustum.near;\n f.far = frustum.far;\n\n f.right += frustum.xOffset;\n f.left += frustum.xOffset;\n f.top += frustum.yOffset;\n f.bottom += frustum.yOffset;\n }\n}\n"],"file":"perspective-frustum.js"}
|