@math.gl/culling 3.6.3 → 4.0.0-alpha.2
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.js.map +1 -0
- package/dist/index.cjs +1049 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/bounding-box-from-points.js +3 -3
- package/dist/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/bounding-sphere-from-points.js +2 -3
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/compute-eigen-decomposition.js +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -2
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/axis-aligned-bounding-box.js +2 -2
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -2
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/bounding-sphere.js +2 -2
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +5 -5
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/oriented-bounding-box.js +3 -3
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/lib/culling-volume.d.ts +3 -3
- package/dist/lib/culling-volume.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/culling-volume.js +3 -6
- package/dist/lib/culling-volume.js.map +1 -0
- package/dist/lib/perspective-frustum.d.ts +2 -2
- package/dist/lib/perspective-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-frustum.js +2 -2
- package/dist/lib/perspective-frustum.js.map +1 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +2 -2
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-off-center-frustum.js +3 -3
- package/dist/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/lib/plane.d.ts +1 -1
- package/dist/lib/plane.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/plane.js +4 -4
- package/dist/lib/plane.js.map +1 -0
- package/package.json +7 -6
- package/src/index.ts +9 -9
- package/src/lib/algorithms/bounding-box-from-points.ts +3 -3
- package/src/lib/algorithms/bounding-sphere-from-points.ts +3 -3
- package/src/lib/algorithms/compute-eigen-decomposition.ts +1 -1
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
- package/src/lib/bounding-volumes/bounding-sphere.ts +4 -2
- package/src/lib/bounding-volumes/bounding-volume.ts +2 -2
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +8 -5
- package/src/lib/culling-volume.ts +6 -6
- package/src/lib/perspective-frustum.ts +4 -4
- package/src/lib/perspective-off-center-frustum.ts +3 -3
- package/src/lib/plane.ts +5 -5
- package/dist/es5/constants.js +0 -13
- package/dist/es5/constants.js.map +0 -1
- package/dist/es5/index.js +0 -102
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +0 -198
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +0 -167
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +0 -114
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +0 -114
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +0 -148
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/bounding-volume.js +0 -2
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +0 -253
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/es5/lib/culling-volume.js +0 -154
- package/dist/es5/lib/culling-volume.js.map +0 -1
- package/dist/es5/lib/perspective-frustum.js +0 -161
- package/dist/es5/lib/perspective-frustum.js.map +0 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +0 -183
- package/dist/es5/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/es5/lib/plane.js +0 -94
- package/dist/es5/lib/plane.js.map +0 -1
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/bounding-volume.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/esm/lib/culling-volume.js.map +0 -1
- package/dist/esm/lib/perspective-frustum.js.map +0 -1
- package/dist/esm/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/esm/lib/plane.js.map +0 -1
- /package/dist/{esm/constants.js → constants.js} +0 -0
- /package/dist/{esm/lib → lib}/bounding-volumes/bounding-volume.js +0 -0
- /package/dist/{es5/lib → lib}/bounding-volumes/bounding-volume.js.map +0 -0
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@math.gl/core");
|
|
17
|
-
|
|
18
|
-
var _constants = require("../constants");
|
|
19
|
-
|
|
20
|
-
var _plane = _interopRequireDefault(require("./plane"));
|
|
21
|
-
|
|
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); }
|
|
25
|
-
|
|
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);
|
|
37
|
-
(0, _defineProperty2.default)(this, "planes", void 0);
|
|
38
|
-
this.planes = planes;
|
|
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();
|
|
79
|
-
}
|
|
80
|
-
|
|
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();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return intersect;
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "computeVisibilityWithPlaneMask",
|
|
117
|
-
value: function computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
118
|
-
(0, _core.assert)(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
|
|
119
|
-
|
|
120
|
-
if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
|
|
121
|
-
return parentPlaneMask;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var mask = CullingVolume.MASK_INSIDE;
|
|
125
|
-
var planes = this.planes;
|
|
126
|
-
|
|
127
|
-
for (var k = 0; k < this.planes.length; ++k) {
|
|
128
|
-
var flag = k < 31 ? 1 << k : 0;
|
|
129
|
-
|
|
130
|
-
if (k < 31 && (parentPlaneMask & flag) === 0) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
var plane = planes[k];
|
|
135
|
-
var result = boundingVolume.intersectPlane(plane);
|
|
136
|
-
|
|
137
|
-
if (result === _constants.INTERSECTION.OUTSIDE) {
|
|
138
|
-
return CullingVolume.MASK_OUTSIDE;
|
|
139
|
-
} else if (result === _constants.INTERSECTION.INTERSECTING) {
|
|
140
|
-
mask |= flag;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return mask;
|
|
145
|
-
}
|
|
146
|
-
}]);
|
|
147
|
-
return CullingVolume;
|
|
148
|
-
}();
|
|
149
|
-
|
|
150
|
-
exports.default = CullingVolume;
|
|
151
|
-
(0, _defineProperty2.default)(CullingVolume, "MASK_OUTSIDE", 0xffffffff);
|
|
152
|
-
(0, _defineProperty2.default)(CullingVolume, "MASK_INSIDE", 0x00000000);
|
|
153
|
-
(0, _defineProperty2.default)(CullingVolume, "MASK_INDETERMINATE", 0x7fffffff);
|
|
154
|
-
//# sourceMappingURL=culling-volume.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EA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CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKnC,MAAL,CAAYE,MAAhC,EAAwC,EAAEiC,CAA1C,EAA6C;AAE3C,YAAMC,IAAI,GAAGD,CAAC,GAAG,EAAJ,GAAS,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): number {\n // const planes = this.planes;\n let intersect: number = 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"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@math.gl/core");
|
|
17
|
-
|
|
18
|
-
var _perspectiveOffCenterFrustum = _interopRequireDefault(require("./perspective-off-center-frustum"));
|
|
19
|
-
|
|
20
|
-
var defined = function defined(val) {
|
|
21
|
-
return val !== null && typeof val !== 'undefined';
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
var PerspectiveFrustum = function () {
|
|
25
|
-
function PerspectiveFrustum() {
|
|
26
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
-
(0, _classCallCheck2.default)(this, PerspectiveFrustum);
|
|
28
|
-
(0, _defineProperty2.default)(this, "_offCenterFrustum", new _perspectiveOffCenterFrustum.default());
|
|
29
|
-
(0, _defineProperty2.default)(this, "fov", void 0);
|
|
30
|
-
(0, _defineProperty2.default)(this, "_fov", void 0);
|
|
31
|
-
(0, _defineProperty2.default)(this, "_fovy", void 0);
|
|
32
|
-
(0, _defineProperty2.default)(this, "_sseDenominator", void 0);
|
|
33
|
-
(0, _defineProperty2.default)(this, "aspectRatio", void 0);
|
|
34
|
-
(0, _defineProperty2.default)(this, "_aspectRatio", void 0);
|
|
35
|
-
(0, _defineProperty2.default)(this, "near", void 0);
|
|
36
|
-
(0, _defineProperty2.default)(this, "_near", void 0);
|
|
37
|
-
(0, _defineProperty2.default)(this, "far", void 0);
|
|
38
|
-
(0, _defineProperty2.default)(this, "_far", void 0);
|
|
39
|
-
(0, _defineProperty2.default)(this, "xOffset", void 0);
|
|
40
|
-
(0, _defineProperty2.default)(this, "_xOffset", void 0);
|
|
41
|
-
(0, _defineProperty2.default)(this, "yOffset", void 0);
|
|
42
|
-
(0, _defineProperty2.default)(this, "_yOffset", void 0);
|
|
43
|
-
var fov = options.fov,
|
|
44
|
-
aspectRatio = options.aspectRatio,
|
|
45
|
-
_options$near = options.near,
|
|
46
|
-
near = _options$near === void 0 ? 1.0 : _options$near,
|
|
47
|
-
_options$far = options.far,
|
|
48
|
-
far = _options$far === void 0 ? 500000000.0 : _options$far,
|
|
49
|
-
_options$xOffset = options.xOffset,
|
|
50
|
-
xOffset = _options$xOffset === void 0 ? 0.0 : _options$xOffset,
|
|
51
|
-
_options$yOffset = options.yOffset,
|
|
52
|
-
yOffset = _options$yOffset === void 0 ? 0.0 : _options$yOffset;
|
|
53
|
-
this.fov = fov;
|
|
54
|
-
this.aspectRatio = aspectRatio;
|
|
55
|
-
this.near = near;
|
|
56
|
-
this.far = far;
|
|
57
|
-
this.xOffset = xOffset;
|
|
58
|
-
this.yOffset = yOffset;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
(0, _createClass2.default)(PerspectiveFrustum, [{
|
|
62
|
-
key: "clone",
|
|
63
|
-
value: function clone() {
|
|
64
|
-
return new PerspectiveFrustum({
|
|
65
|
-
aspectRatio: this.aspectRatio,
|
|
66
|
-
fov: this.fov,
|
|
67
|
-
near: this.near,
|
|
68
|
-
far: this.far
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "equals",
|
|
73
|
-
value: function equals(other) {
|
|
74
|
-
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this._update();
|
|
79
|
-
|
|
80
|
-
other._update();
|
|
81
|
-
|
|
82
|
-
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
|
|
83
|
-
}
|
|
84
|
-
}, {
|
|
85
|
-
key: "projectionMatrix",
|
|
86
|
-
get: function get() {
|
|
87
|
-
this._update();
|
|
88
|
-
|
|
89
|
-
return this._offCenterFrustum.projectionMatrix;
|
|
90
|
-
}
|
|
91
|
-
}, {
|
|
92
|
-
key: "infiniteProjectionMatrix",
|
|
93
|
-
get: function get() {
|
|
94
|
-
this._update();
|
|
95
|
-
|
|
96
|
-
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
97
|
-
}
|
|
98
|
-
}, {
|
|
99
|
-
key: "fovy",
|
|
100
|
-
get: function get() {
|
|
101
|
-
this._update();
|
|
102
|
-
|
|
103
|
-
return this._fovy;
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: "sseDenominator",
|
|
107
|
-
get: function get() {
|
|
108
|
-
this._update();
|
|
109
|
-
|
|
110
|
-
return this._sseDenominator;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "computeCullingVolume",
|
|
114
|
-
value: function computeCullingVolume(position, direction, up) {
|
|
115
|
-
this._update();
|
|
116
|
-
|
|
117
|
-
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
118
|
-
}
|
|
119
|
-
}, {
|
|
120
|
-
key: "getPixelDimensions",
|
|
121
|
-
value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
122
|
-
this._update();
|
|
123
|
-
|
|
124
|
-
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new _core.Vector2());
|
|
125
|
-
}
|
|
126
|
-
}, {
|
|
127
|
-
key: "_update",
|
|
128
|
-
value: function _update() {
|
|
129
|
-
(0, _core.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
130
|
-
var f = this._offCenterFrustum;
|
|
131
|
-
|
|
132
|
-
if (this.fov !== this._fov || this.aspectRatio !== this._aspectRatio || this.near !== this._near || this.far !== this._far || this.xOffset !== this._xOffset || this.yOffset !== this._yOffset) {
|
|
133
|
-
(0, _core.assert)(this.fov >= 0 && this.fov < Math.PI);
|
|
134
|
-
(0, _core.assert)(this.aspectRatio > 0);
|
|
135
|
-
(0, _core.assert)(this.near >= 0 && this.near < this.far);
|
|
136
|
-
this._aspectRatio = this.aspectRatio;
|
|
137
|
-
this._fov = this.fov;
|
|
138
|
-
this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
|
|
139
|
-
this._near = this.near;
|
|
140
|
-
this._far = this.far;
|
|
141
|
-
this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
|
|
142
|
-
this._xOffset = this.xOffset;
|
|
143
|
-
this._yOffset = this.yOffset;
|
|
144
|
-
f.top = this.near * Math.tan(0.5 * this._fovy);
|
|
145
|
-
f.bottom = -f.top;
|
|
146
|
-
f.right = this.aspectRatio * f.top;
|
|
147
|
-
f.left = -f.right;
|
|
148
|
-
f.near = this.near;
|
|
149
|
-
f.far = this.far;
|
|
150
|
-
f.right += this.xOffset;
|
|
151
|
-
f.left += this.xOffset;
|
|
152
|
-
f.top += this.yOffset;
|
|
153
|
-
f.bottom += this.yOffset;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}]);
|
|
157
|
-
return PerspectiveFrustum;
|
|
158
|
-
}();
|
|
159
|
-
|
|
160
|
-
exports.default = PerspectiveFrustum;
|
|
161
|
-
//# sourceMappingURL=perspective-frustum.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["defined","val","PerspectiveFrustum","options","PerspectiveOffCenterFrustum","fov","aspectRatio","near","far","xOffset","yOffset","other","_update","_offCenterFrustum","equals","projectionMatrix","infiniteProjectionMatrix","_fovy","_sseDenominator","position","direction","up","computeCullingVolume","drawingBufferWidth","drawingBufferHeight","distance","result","getPix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AAgB,KAAK3B,OAArB;AAEAqB,QAAAA,CAAC,CAACW,GAAF,GAAQ,KAAKnC,IAAL,GAAY+B,IAAI,CAACG,GAAL,CAAS,MAAM,KAAKxB,KAApB,CAApB;AACAc,QAAAA,CAAC,CAACY,MAAF,GAAW,CAACZ,CAAC,CAACW,GAAd;AACAX,QAAAA,CAAC,CAACa,KAAF,GAAU,KAAKtC,WAAL,GAAmByB,CAAC,CAACW,GAA/B;AACAX,QAAAA,CAAC,CAACc,IAAF,GAAS,CAACd,CAAC,CAACa,KAAZ;AACAb,QAAAA,CAAC,CAACxB,IAAF,GAAS,KAAKA,IAAd;AACAwB,QAAAA,CAAC,CAACvB,GAAF,GAAQ,KAAKA,GAAb;AAEAuB,QAAAA,CAAC,CAACa,KAAF,IAAW,KAAKnC,OAAhB;AACAsB,QAAAA,CAAC,CAACc,IAAF,IAAU,KAAKpC,OAAf;AACAsB,QAAAA,CAAC,CAACW,GAAF,IAAS,KAAKhC,OAAd;AACAqB,QAAAA,CAAC,CAACY,MAAF,IAAY,KAAKjC,OAAjB;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\nimport {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\nimport CullingVolume from './culling-volume';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\ntype PerspectiveFrustumOptions = {\n /** The angle of the field of view (FOV), in radians. */\n fov?: number;\n /** The aspect ratio of the frustum's width to it's height. */\n aspectRatio?: number;\n /** The distance of the near plane. */\n near?: number;\n /** The distance of the far plane. */\n far?: number;\n /** The offset in the x direction. */\n xOffset?: number;\n /** The offset in the y direction. */\n yOffset?: number;\n};\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 *\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 private _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 private _fov: number;\n private _fovy: number;\n private _sseDenominator: number;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio?: number;\n private _aspectRatio: number;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n private _xOffset: number;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n private _yOffset: number;\n\n constructor(options: PerspectiveFrustumOptions = {}) {\n const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;\n\n this.fov = fov;\n this.aspectRatio = aspectRatio;\n this.near = near;\n this.far = far;\n this.xOffset = xOffset;\n this.yOffset = 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 this._update();\n other._update();\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 this.\n */\n get projectionMatrix(): Matrix4 {\n this._update();\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 this._update();\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 this._update();\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n this._update();\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this this.ion.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the this.\n * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n this._update();\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\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.this.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.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result?: Vector2\n ): Vector2 {\n this._update();\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result || new Vector2()\n );\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update(): void {\n assert(\n Number.isFinite(this.fov) &&\n Number.isFinite(this.aspectRatio) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = this._offCenterFrustum;\n\n if (\n this.fov !== this._fov ||\n this.aspectRatio !== this._aspectRatio ||\n this.near !== this._near ||\n this.far !== this._far ||\n this.xOffset !== this._xOffset ||\n this.yOffset !== this._yOffset\n ) {\n assert(this.fov >= 0 && this.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(this.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(this.near >= 0 && this.near < this.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n this._aspectRatio = this.aspectRatio;\n this._fov = this.fov;\n this._fovy =\n this.aspectRatio <= 1\n ? this.fov\n : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;\n this._near = this.near;\n this._far = this.far;\n this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);\n this._xOffset = this.xOffset;\n this._yOffset = this.yOffset;\n\n f.top = this.near * Math.tan(0.5 * this._fovy);\n f.bottom = -f.top;\n f.right = this.aspectRatio * f.top;\n f.left = -f.right;\n f.near = this.near;\n f.far = this.far;\n\n f.right += this.xOffset;\n f.left += this.xOffset;\n f.top += this.yOffset;\n f.bottom += this.yOffset;\n }\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@math.gl/core");
|
|
17
|
-
|
|
18
|
-
var _cullingVolume = _interopRequireDefault(require("./culling-volume"));
|
|
19
|
-
|
|
20
|
-
var _plane = _interopRequireDefault(require("./plane"));
|
|
21
|
-
|
|
22
|
-
var scratchPlaneUpVector = new _core.Vector3();
|
|
23
|
-
var scratchPlaneRightVector = new _core.Vector3();
|
|
24
|
-
var scratchPlaneNearCenter = new _core.Vector3();
|
|
25
|
-
var scratchPlaneFarCenter = new _core.Vector3();
|
|
26
|
-
var scratchPlaneNormal = new _core.Vector3();
|
|
27
|
-
|
|
28
|
-
var PerspectiveOffCenterFrustum = function () {
|
|
29
|
-
function PerspectiveOffCenterFrustum() {
|
|
30
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
-
(0, _classCallCheck2.default)(this, PerspectiveOffCenterFrustum);
|
|
32
|
-
(0, _defineProperty2.default)(this, "left", void 0);
|
|
33
|
-
(0, _defineProperty2.default)(this, "_left", void 0);
|
|
34
|
-
(0, _defineProperty2.default)(this, "right", void 0);
|
|
35
|
-
(0, _defineProperty2.default)(this, "_right", void 0);
|
|
36
|
-
(0, _defineProperty2.default)(this, "top", void 0);
|
|
37
|
-
(0, _defineProperty2.default)(this, "_top", void 0);
|
|
38
|
-
(0, _defineProperty2.default)(this, "bottom", void 0);
|
|
39
|
-
(0, _defineProperty2.default)(this, "_bottom", void 0);
|
|
40
|
-
(0, _defineProperty2.default)(this, "near", void 0);
|
|
41
|
-
(0, _defineProperty2.default)(this, "_near", void 0);
|
|
42
|
-
(0, _defineProperty2.default)(this, "far", void 0);
|
|
43
|
-
(0, _defineProperty2.default)(this, "_far", void 0);
|
|
44
|
-
(0, _defineProperty2.default)(this, "_cullingVolume", new _cullingVolume.default([new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default()]));
|
|
45
|
-
(0, _defineProperty2.default)(this, "_perspectiveMatrix", new _core.Matrix4());
|
|
46
|
-
(0, _defineProperty2.default)(this, "_infinitePerspective", new _core.Matrix4());
|
|
47
|
-
var _options$near = options.near,
|
|
48
|
-
near = _options$near === void 0 ? 1.0 : _options$near,
|
|
49
|
-
_options$far = options.far,
|
|
50
|
-
far = _options$far === void 0 ? 500000000.0 : _options$far;
|
|
51
|
-
this.left = options.left;
|
|
52
|
-
this._left = undefined;
|
|
53
|
-
this.right = options.right;
|
|
54
|
-
this._right = undefined;
|
|
55
|
-
this.top = options.top;
|
|
56
|
-
this._top = undefined;
|
|
57
|
-
this.bottom = options.bottom;
|
|
58
|
-
this._bottom = undefined;
|
|
59
|
-
this.near = near;
|
|
60
|
-
this._near = near;
|
|
61
|
-
this.far = far;
|
|
62
|
-
this._far = far;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
(0, _createClass2.default)(PerspectiveOffCenterFrustum, [{
|
|
66
|
-
key: "clone",
|
|
67
|
-
value: function clone() {
|
|
68
|
-
return new PerspectiveOffCenterFrustum({
|
|
69
|
-
right: this.right,
|
|
70
|
-
left: this.left,
|
|
71
|
-
top: this.top,
|
|
72
|
-
bottom: this.bottom,
|
|
73
|
-
near: this.near,
|
|
74
|
-
far: this.far
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
key: "equals",
|
|
79
|
-
value: function equals(other) {
|
|
80
|
-
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;
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "projectionMatrix",
|
|
84
|
-
get: function get() {
|
|
85
|
-
this._update();
|
|
86
|
-
|
|
87
|
-
return this._perspectiveMatrix;
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "infiniteProjectionMatrix",
|
|
91
|
-
get: function get() {
|
|
92
|
-
this._update();
|
|
93
|
-
|
|
94
|
-
return this._infinitePerspective;
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "computeCullingVolume",
|
|
98
|
-
value: function computeCullingVolume(position, direction, up) {
|
|
99
|
-
(0, _core.assert)(position, 'position is required.');
|
|
100
|
-
(0, _core.assert)(direction, 'direction is required.');
|
|
101
|
-
(0, _core.assert)(up, 'up is required.');
|
|
102
|
-
var planes = this._cullingVolume.planes;
|
|
103
|
-
up = scratchPlaneUpVector.copy(up).normalize();
|
|
104
|
-
var right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
|
|
105
|
-
var nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
|
|
106
|
-
var farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
|
|
107
|
-
var normal = scratchPlaneNormal;
|
|
108
|
-
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
109
|
-
planes[0].fromPointNormal(position, normal);
|
|
110
|
-
normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
|
|
111
|
-
planes[1].fromPointNormal(position, normal);
|
|
112
|
-
normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
|
|
113
|
-
planes[2].fromPointNormal(position, normal);
|
|
114
|
-
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
115
|
-
planes[3].fromPointNormal(position, normal);
|
|
116
|
-
normal = new _core.Vector3().copy(direction);
|
|
117
|
-
planes[4].fromPointNormal(nearCenter, normal);
|
|
118
|
-
normal.negate();
|
|
119
|
-
planes[5].fromPointNormal(farCenter, normal);
|
|
120
|
-
return this._cullingVolume;
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "getPixelDimensions",
|
|
124
|
-
value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
125
|
-
this._update();
|
|
126
|
-
|
|
127
|
-
(0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
128
|
-
(0, _core.assert)(drawingBufferWidth > 0);
|
|
129
|
-
(0, _core.assert)(drawingBufferHeight > 0);
|
|
130
|
-
(0, _core.assert)(distance > 0);
|
|
131
|
-
(0, _core.assert)(result);
|
|
132
|
-
var inverseNear = 1.0 / this.near;
|
|
133
|
-
var tanTheta = this.top * inverseNear;
|
|
134
|
-
var pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
|
|
135
|
-
tanTheta = this.right * inverseNear;
|
|
136
|
-
var pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
|
|
137
|
-
result.x = pixelWidth;
|
|
138
|
-
result.y = pixelHeight;
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "_update",
|
|
143
|
-
value: function _update() {
|
|
144
|
-
(0, _core.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));
|
|
145
|
-
var top = this.top,
|
|
146
|
-
bottom = this.bottom,
|
|
147
|
-
right = this.right,
|
|
148
|
-
left = this.left,
|
|
149
|
-
near = this.near,
|
|
150
|
-
far = this.far;
|
|
151
|
-
|
|
152
|
-
if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
|
|
153
|
-
(0, _core.assert)(this.near > 0 && this.near < this.far, 'near must be greater than zero and less than far.');
|
|
154
|
-
this._left = left;
|
|
155
|
-
this._right = right;
|
|
156
|
-
this._top = top;
|
|
157
|
-
this._bottom = bottom;
|
|
158
|
-
this._near = near;
|
|
159
|
-
this._far = far;
|
|
160
|
-
this._perspectiveMatrix = new _core.Matrix4().frustum({
|
|
161
|
-
left: left,
|
|
162
|
-
right: right,
|
|
163
|
-
bottom: bottom,
|
|
164
|
-
top: top,
|
|
165
|
-
near: near,
|
|
166
|
-
far: far
|
|
167
|
-
});
|
|
168
|
-
this._infinitePerspective = new _core.Matrix4().frustum({
|
|
169
|
-
left: left,
|
|
170
|
-
right: right,
|
|
171
|
-
bottom: bottom,
|
|
172
|
-
top: top,
|
|
173
|
-
near: near,
|
|
174
|
-
far: Infinity
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}]);
|
|
179
|
-
return PerspectiveOffCenterFrustum;
|
|
180
|
-
}();
|
|
181
|
-
|
|
182
|
-
exports.default = PerspectiveOffCenterFrustum;
|
|
183
|
-
//# sourceMappingURL=perspective-off-center-frustum.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","other","_update","_perspectiveMatrix","_infinitePerspective","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";;;;;;;;;;;;;;;AAOA;;AACA;;AACA;;AAEA,IAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,IAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,IAAME,sBAAsB,GAAG,IAAIF,aAAJ,EAA/B;AACA,IAAMG,qBAAqB,GAAG,IAAIH,aAAJ,EAA9B;AACA,IAAMI,kBAAkB,GAAG,IAAIJ,aAAJ,EAA3B;;IAWqBK,2B;AA2EnB,yCAA8D;AAAA,QAAlDC,OAAkD,uEAAJ,EAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DA/BrC,IAAIC,sBAAJ,CAAkB,CACzC,IAAIC,cAAJ,EADyC,EAEzC,IAAIA,cAAJ,EAFyC,EAGzC,IAAIA,cAAJ,EAHyC,EAIzC,IAAIA,cAAJ,EAJyC,EAKzC,IAAIA,cAAJ,EALyC,EAMzC,IAAIA,cAAJ,EANyC,CAAlB,CA+BqC;AAAA,8DAvBjC,IAAIC,aAAJ,EAuBiC;AAAA,gEAtB/B,IAAIA,aAAJ,EAsB+B;AAC5D,wBAAwCH,OAAxC,CAAOI,IAAP;AAAA,QAAOA,IAAP,8BAAc,GAAd;AAAA,uBAAwCJ,OAAxC,CAAmBK,GAAnB;AAAA,QAAmBA,GAAnB,6BAAyB,WAAzB;AAEA,SAAKC,IAAL,GAAYN,OAAO,CAACM,IAApB;AACA,SAAKC,KAAL,GAAaC,SAAb;AAEA,SAAKC,KAAL,GAAaT,OAAO,CAACS,KAArB;AACA,SAAKC,MAAL,GAAcF,SAAd;AAEA,SAAKG,GAAL,GAA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aAAKG,OAAL,GAAeD,MAAf;AACA,aAAKE,KAAL,GAAaX,IAAb;AACA,aAAKY,IAAL,GAAYX,GAAZ;AACA,aAAKc,kBAAL,GAA0B,IAAIhB,aAAJ,GAAc8C,OAAd,CAAsB;AAC9C3C,UAAAA,IAAI,EAAJA,IAD8C;AAE9CG,UAAAA,KAAK,EAALA,KAF8C;AAG9CI,UAAAA,MAAM,EAANA,MAH8C;AAI9CF,UAAAA,GAAG,EAAHA,GAJ8C;AAK9CP,UAAAA,IAAI,EAAJA,IAL8C;AAM9CC,UAAAA,GAAG,EAAHA;AAN8C,SAAtB,CAA1B;AAQA,aAAKe,oBAAL,GAA4B,IAAIjB,aAAJ,GAAc8C,OAAd,CAAsB;AAChD3C,UAAAA,IAAI,EAAJA,IADgD;AAEhDG,UAAAA,KAAK,EAALA,KAFgD;AAGhDI,UAAAA,MAAM,EAANA,MAHgD;AAIhDF,UAAAA,GAAG,EAAHA,GAJgD;AAKhDP,UAAAA,IAAI,EAAJA,IALgD;AAMhDC,UAAAA,GAAG,EAAE6C;AAN2C,SAAtB,CAA5B;AAQD;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\nimport {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\ntype PerspectiveOffCenterFrustumOptions = {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n near?: number;\n far?: number;\n};\n\nexport default class PerspectiveOffCenterFrustum {\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n left?: number;\n private _left?: number;\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n right?: number;\n private _right?: number;\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n top?: number;\n private _top?: number;\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n bottom?: number;\n private _bottom?: number;\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n\n private _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n private _perspectiveMatrix = new Matrix4();\n private _infinitePerspective = new Matrix4();\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 PerspectiveOffCenterFrustum\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: PerspectiveOffCenterFrustumOptions = {}) {\n const {near = 1.0, far = 500000000.0} = options;\n\n this.left = options.left;\n this._left = undefined;\n\n this.right = options.right;\n this._right = undefined;\n\n this.top = options.top;\n this._top = undefined;\n\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n this.near = near;\n this._near = near;\n\n this.far = far;\n this._far = far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone(): PerspectiveOffCenterFrustum {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveOffCenterFrustum): boolean {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\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 * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\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 * const 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 * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result: Vector2\n ): Vector2 {\n this._update();\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update() {\n assert(\n Number.isFinite(this.right) &&\n Number.isFinite(this.left) &&\n Number.isFinite(this.top) &&\n Number.isFinite(this.bottom) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = this;\n\n if (\n top !== this._top ||\n bottom !== this._bottom ||\n left !== this._left ||\n right !== this._right ||\n near !== this._near ||\n far !== this._far\n ) {\n assert(\n this.near > 0 && this.near < this.far,\n 'near must be greater than zero and less than far.'\n );\n\n this._left = left;\n this._right = right;\n this._top = top;\n this._bottom = bottom;\n this._near = near;\n this._far = far;\n this._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n this._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
|