@math.gl/culling 3.5.3 → 3.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/es5/constants.js +7 -5
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/index.js +12 -24
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +72 -122
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +81 -109
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +36 -37
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +68 -74
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +93 -109
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/es5/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +190 -211
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +80 -131
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +73 -84
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +114 -117
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +55 -69
- package/dist/es5/lib/plane.js.map +1 -1
- package/dist/esm/constants.js +7 -5
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-box-from-points.js +7 -6
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js +6 -6
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js +15 -6
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js +12 -6
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/esm/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js +5 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/esm/lib/culling-volume.js +10 -16
- package/dist/esm/lib/culling-volume.js.map +1 -1
- package/dist/esm/lib/perspective-frustum.js +31 -5
- package/dist/esm/lib/perspective-frustum.js.map +1 -1
- package/dist/esm/lib/perspective-off-center-frustum.js +31 -3
- package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/esm/lib/plane.js +6 -1
- package/dist/esm/lib/plane.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/{src → dist}/lib/algorithms/bounding-box-from-points.d.ts +3 -10
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.js +131 -0
- package/dist/{esm/lib → lib}/algorithms/bounding-sphere-from-points.d.ts +2 -5
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.js +142 -0
- package/dist/{es5/lib → lib}/algorithms/compute-eigen-decomposition.d.ts +7 -9
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js +131 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +111 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.js +118 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.js +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +67 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +256 -0
- package/dist/lib/culling-volume.d.ts +46 -0
- package/dist/lib/culling-volume.d.ts.map +1 -0
- package/dist/lib/culling-volume.js +121 -0
- package/dist/lib/perspective-frustum.d.ts +140 -0
- package/dist/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-frustum.js +205 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +122 -0
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-off-center-frustum.js +305 -0
- package/dist/lib/plane.d.ts +26 -0
- package/dist/lib/plane.d.ts.map +1 -0
- package/dist/lib/plane.js +63 -0
- package/package.json +5 -5
- package/src/constants.ts +8 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/lib/algorithms/{bounding-box-from-points.js → bounding-box-from-points.ts} +25 -10
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +21 -7
- package/src/lib/algorithms/{compute-eigen-decomposition.js → compute-eigen-decomposition.ts} +40 -1
- package/src/lib/bounding-volumes/{axis-aligned-bounding-box.js → axis-aligned-bounding-box.ts} +45 -14
- package/src/lib/bounding-volumes/{bounding-sphere.js → bounding-sphere.ts} +47 -31
- package/src/lib/bounding-volumes/{bounding-volume.d.ts → bounding-volume.ts} +7 -7
- package/src/lib/bounding-volumes/{oriented-bounding-box.js → oriented-bounding-box.ts} +72 -14
- package/src/lib/{culling-volume.js → culling-volume.ts} +42 -34
- package/src/lib/{perspective-frustum.js → perspective-frustum.ts} +48 -66
- package/src/lib/{perspective-off-center-frustum.js → perspective-off-center-frustum.ts} +24 -14
- package/src/lib/{plane.js → plane.ts} +24 -17
- package/dist/es5/constants.d.ts +0 -6
- package/dist/es5/index.d.ts +0 -20
- package/dist/es5/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/es5/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/es5/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/es5/lib/culling-volume.d.ts +0 -55
- package/dist/es5/lib/plane.d.ts +0 -38
- package/dist/esm/constants.d.ts +0 -6
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/esm/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/esm/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/esm/lib/culling-volume.d.ts +0 -55
- package/dist/esm/lib/plane.d.ts +0 -38
- package/src/constants.d.ts +0 -6
- package/src/constants.js +0 -8
- package/src/index.d.ts +0 -20
- package/src/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/src/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/src/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/src/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/src/lib/culling-volume.d.ts +0 -55
- package/src/lib/plane.d.ts +0 -38
|
@@ -9,34 +9,40 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
12
|
var _core = require("@math.gl/core");
|
|
17
13
|
|
|
18
14
|
var _cullingVolume = _interopRequireDefault(require("./culling-volume"));
|
|
19
15
|
|
|
20
16
|
var _plane = _interopRequireDefault(require("./plane"));
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(0,
|
|
36
|
-
|
|
18
|
+
const scratchPlaneUpVector = new _core.Vector3();
|
|
19
|
+
const scratchPlaneRightVector = new _core.Vector3();
|
|
20
|
+
const scratchPlaneNearCenter = new _core.Vector3();
|
|
21
|
+
const scratchPlaneFarCenter = new _core.Vector3();
|
|
22
|
+
const scratchPlaneNormal = new _core.Vector3();
|
|
23
|
+
|
|
24
|
+
class PerspectiveOffCenterFrustum {
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
(0, _defineProperty2.default)(this, "left", void 0);
|
|
27
|
+
(0, _defineProperty2.default)(this, "_left", void 0);
|
|
28
|
+
(0, _defineProperty2.default)(this, "right", void 0);
|
|
29
|
+
(0, _defineProperty2.default)(this, "_right", void 0);
|
|
30
|
+
(0, _defineProperty2.default)(this, "top", void 0);
|
|
31
|
+
(0, _defineProperty2.default)(this, "_top", void 0);
|
|
32
|
+
(0, _defineProperty2.default)(this, "bottom", void 0);
|
|
33
|
+
(0, _defineProperty2.default)(this, "_bottom", void 0);
|
|
34
|
+
(0, _defineProperty2.default)(this, "near", void 0);
|
|
35
|
+
(0, _defineProperty2.default)(this, "_near", void 0);
|
|
36
|
+
(0, _defineProperty2.default)(this, "far", void 0);
|
|
37
|
+
(0, _defineProperty2.default)(this, "_far", void 0);
|
|
38
|
+
(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()]));
|
|
39
|
+
(0, _defineProperty2.default)(this, "_perspectiveMatrix", new _core.Matrix4());
|
|
40
|
+
(0, _defineProperty2.default)(this, "_infinitePerspective", new _core.Matrix4());
|
|
41
|
+
options = {
|
|
37
42
|
near: 1.0,
|
|
38
|
-
far: 500000000.0
|
|
39
|
-
|
|
43
|
+
far: 500000000.0,
|
|
44
|
+
...options
|
|
45
|
+
};
|
|
40
46
|
this.left = options.left;
|
|
41
47
|
this._left = undefined;
|
|
42
48
|
this.right = options.right;
|
|
@@ -49,98 +55,89 @@ var PerspectiveOffCenterFrustum = function () {
|
|
|
49
55
|
this._near = this.near;
|
|
50
56
|
this.far = options.far;
|
|
51
57
|
this._far = this.far;
|
|
52
|
-
this._cullingVolume = new _cullingVolume.default([new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default()]);
|
|
53
|
-
this._perspectiveMatrix = new _core.Matrix4();
|
|
54
|
-
this._infinitePerspective = new _core.Matrix4();
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
|
|
126
|
-
result.x = pixelWidth;
|
|
127
|
-
result.y = pixelHeight;
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
130
|
-
}]);
|
|
131
|
-
return PerspectiveOffCenterFrustum;
|
|
132
|
-
}();
|
|
60
|
+
clone() {
|
|
61
|
+
return new PerspectiveOffCenterFrustum({
|
|
62
|
+
right: this.right,
|
|
63
|
+
left: this.left,
|
|
64
|
+
top: this.top,
|
|
65
|
+
bottom: this.bottom,
|
|
66
|
+
near: this.near,
|
|
67
|
+
far: this.far
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
equals(other) {
|
|
72
|
+
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;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get projectionMatrix() {
|
|
76
|
+
update(this);
|
|
77
|
+
return this._perspectiveMatrix;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get infiniteProjectionMatrix() {
|
|
81
|
+
update(this);
|
|
82
|
+
return this._infinitePerspective;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
computeCullingVolume(position, direction, up) {
|
|
86
|
+
(0, _core.assert)(position, 'position is required.');
|
|
87
|
+
(0, _core.assert)(direction, 'direction is required.');
|
|
88
|
+
(0, _core.assert)(up, 'up is required.');
|
|
89
|
+
const planes = this._cullingVolume.planes;
|
|
90
|
+
up = scratchPlaneUpVector.copy(up).normalize();
|
|
91
|
+
const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
|
|
92
|
+
const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
|
|
93
|
+
const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
|
|
94
|
+
let normal = scratchPlaneNormal;
|
|
95
|
+
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
96
|
+
planes[0].fromPointNormal(position, normal);
|
|
97
|
+
normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
|
|
98
|
+
planes[1].fromPointNormal(position, normal);
|
|
99
|
+
normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
|
|
100
|
+
planes[2].fromPointNormal(position, normal);
|
|
101
|
+
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
102
|
+
planes[3].fromPointNormal(position, normal);
|
|
103
|
+
normal = new _core.Vector3().copy(direction);
|
|
104
|
+
planes[4].fromPointNormal(nearCenter, normal);
|
|
105
|
+
normal.negate();
|
|
106
|
+
planes[5].fromPointNormal(farCenter, normal);
|
|
107
|
+
return this._cullingVolume;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
111
|
+
update(this);
|
|
112
|
+
(0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
113
|
+
(0, _core.assert)(drawingBufferWidth > 0);
|
|
114
|
+
(0, _core.assert)(drawingBufferHeight > 0);
|
|
115
|
+
(0, _core.assert)(distance > 0);
|
|
116
|
+
(0, _core.assert)(result);
|
|
117
|
+
const inverseNear = 1.0 / this.near;
|
|
118
|
+
let tanTheta = this.top * inverseNear;
|
|
119
|
+
const pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
|
|
120
|
+
tanTheta = this.right * inverseNear;
|
|
121
|
+
const pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
|
|
122
|
+
result.x = pixelWidth;
|
|
123
|
+
result.y = pixelHeight;
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
}
|
|
133
128
|
|
|
134
129
|
exports.default = PerspectiveOffCenterFrustum;
|
|
135
130
|
|
|
136
131
|
function update(frustum) {
|
|
137
132
|
(0, _core.assert)(Number.isFinite(frustum.right) && Number.isFinite(frustum.left) && Number.isFinite(frustum.top) && Number.isFinite(frustum.bottom) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
const {
|
|
134
|
+
top,
|
|
135
|
+
bottom,
|
|
136
|
+
right,
|
|
137
|
+
left,
|
|
138
|
+
near,
|
|
139
|
+
far
|
|
140
|
+
} = frustum;
|
|
144
141
|
|
|
145
142
|
if (top !== frustum._top || bottom !== frustum._bottom || left !== frustum._left || right !== frustum._right || near !== frustum._near || far !== frustum._far) {
|
|
146
143
|
(0, _core.assert)(frustum.near > 0 && frustum.near < frustum.far, 'near must be greater than zero and less than far.');
|
|
@@ -151,19 +148,19 @@ function update(frustum) {
|
|
|
151
148
|
frustum._near = near;
|
|
152
149
|
frustum._far = far;
|
|
153
150
|
frustum._perspectiveMatrix = new _core.Matrix4().frustum({
|
|
154
|
-
left
|
|
155
|
-
right
|
|
156
|
-
bottom
|
|
157
|
-
top
|
|
158
|
-
near
|
|
159
|
-
far
|
|
151
|
+
left,
|
|
152
|
+
right,
|
|
153
|
+
bottom,
|
|
154
|
+
top,
|
|
155
|
+
near,
|
|
156
|
+
far
|
|
160
157
|
});
|
|
161
158
|
frustum._infinitePerspective = new _core.Matrix4().frustum({
|
|
162
|
-
left
|
|
163
|
-
right
|
|
164
|
-
bottom
|
|
165
|
-
top
|
|
166
|
-
near
|
|
159
|
+
left,
|
|
160
|
+
right,
|
|
161
|
+
bottom,
|
|
162
|
+
top,
|
|
163
|
+
near,
|
|
167
164
|
far: Infinity
|
|
168
165
|
});
|
|
169
166
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.js"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","options","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","_cullingVolume","CullingVolume","Plane","_perspectiveMatrix","Matrix4","_infinitePerspective","other","update","position","direction","up","planes","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":";;;;;;;;;;;;;;;AASA;;AACA;;AACA;;;;;;AAEA,IAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,IAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,IAAME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,OAAO,CAACrC,KAAR,GAAgBX,IAAhB;AACAgD,IAAAA,OAAO,CAACpC,IAAR,GAAeX,GAAf;AACA+C,IAAAA,OAAO,CAAChC,kBAAR,GAA6B,IAAIC,aAAJ,GAAc+B,OAAd,CAAsB;AACjD9C,MAAAA,IAAI,EAAJA,IADiD;AAEjDG,MAAAA,KAAK,EAALA,KAFiD;AAGjDI,MAAAA,MAAM,EAANA,MAHiD;AAIjDF,MAAAA,GAAG,EAAHA,GAJiD;AAKjDP,MAAAA,IAAI,EAAJA,IALiD;AAMjDC,MAAAA,GAAG,EAAHA;AANiD,KAAtB,CAA7B;AAQA+C,IAAAA,OAAO,CAAC9B,oBAAR,GAA+B,IAAID,aAAJ,GAAc+B,OAAd,CAAsB;AACnD9C,MAAAA,IAAI,EAAJA,IADmD;AAEnDG,MAAAA,KAAK,EAALA,KAFmD;AAGnDI,MAAAA,MAAM,EAANA,MAHmD;AAInDF,MAAAA,GAAG,EAAHA,GAJmD;AAKnDP,MAAAA,IAAI,EAAJA,IALmD;AAMnDC,MAAAA,GAAG,EAAEgD;AAN8C,KAAtB,CAA/B;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\n// @ts-nocheck\n\nimport {Vector3, Matrix4, assert} 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\nexport default class PerspectiveOffCenterFrustum {\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 * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.left] The left clipping plane distance.\n * @param {Number} [options.right] The right clipping plane distance.\n * @param {Number} [options.top] The top clipping plane distance.\n * @param {Number} [options.bottom] The bottom clipping plane distance.\n * @param {Number} [options.near=1.0] The near clipping plane distance.\n * @param {Number} [options.far=500000000.0] The far clipping plane distance.\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 = {}) {\n options = {near: 1.0, far: 500000000.0, ...options};\n\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n this.near = options.near;\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n this.far = options.far;\n this._far = this.far;\n\n this._cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n this._perspectiveMatrix = new Matrix4();\n this._infinitePerspective = new Matrix4();\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone() {\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 * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\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 * @readonly\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix() {\n update(this);\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 * @readonly\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix() {\n update(this);\n return this._infinitePerspective;\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 * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(position, direction, up) {\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 * @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 * 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(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\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\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.right) &&\n Number.isFinite(frustum.left) &&\n Number.isFinite(frustum.top) &&\n Number.isFinite(frustum.bottom) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.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} = frustum;\n\n if (\n top !== frustum._top ||\n bottom !== frustum._bottom ||\n left !== frustum._left ||\n right !== frustum._right ||\n near !== frustum._near ||\n far !== frustum._far\n ) {\n assert(\n frustum.near > 0 && frustum.near < frustum.far,\n 'near must be greater than zero and less than far.'\n );\n\n frustum._left = left;\n frustum._right = right;\n frustum._top = top;\n frustum._bottom = bottom;\n frustum._near = near;\n frustum._far = far;\n frustum._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n frustum._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","constructor","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","clone","equals","other","projectionMatrix","update","_perspectiveMatrix","infiniteProjectionMatrix","_infinitePerspective","computeCullingVolume","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";;;;;;;;;;;AASA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,MAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,MAAME,sBAAsB,GAAG,IAAIF,aAAJ,EAA/B;AACA,MAAMG,qBAAqB,GAAG,IAAIH,aAAJ,EAA9B;AACA,MAAMI,kBAAkB,GAAG,IAAIJ,aAAJ,EAA3B;;AAEe,MAAMK,2BAAN,CAAkC;AAqD/CC,EAAAA,WAAW,CAACC,OAA4B,GAAG,EAAhC,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DAxC9B,IAAIC,sBAAJ,CAAkB,CACjC,IAAIC,cAAJ,EADiC,EAEjC,IAAIA,cAAJ,EAFiC,EAGjC,IAAIA,cAAJ,EAHiC,EAIjC,IAAIA,cAAJ,EAJiC,EAKjC,IAAIA,cAAJ,EALiC,EAMjC,IAAIA,cAAJ,EANiC,CAAlB,CAwC8B;AAAA,8DAhC1B,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QD;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 {Vector3, Matrix4, assert} 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\nexport default class PerspectiveOffCenterFrustum {\n left;\n _left;\n right;\n _right;\n top;\n _top;\n bottom;\n _bottom;\n near;\n _near;\n far;\n _far;\n _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n _perspectiveMatrix = new Matrix4();\n _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 * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.left] The left clipping plane distance.\n * @param {Number} [options.right] The right clipping plane distance.\n * @param {Number} [options.top] The top clipping plane distance.\n * @param {Number} [options.bottom] The bottom clipping plane distance.\n * @param {Number} [options.near=1.0] The near clipping plane distance.\n * @param {Number} [options.far=500000000.0] The far clipping plane distance.\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: Record<string, any> = {}) {\n options = {near: 1.0, far: 500000000.0, ...options};\n\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n this.near = options.near;\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n this.far = options.far;\n this._far = this.far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone() {\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 * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\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() {\n update(this);\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() {\n update(this);\n return this._infinitePerspective;\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 * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(position, direction, up) {\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 * @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 * 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(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\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\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.right) &&\n Number.isFinite(frustum.left) &&\n Number.isFinite(frustum.top) &&\n Number.isFinite(frustum.bottom) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.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} = frustum;\n\n if (\n top !== frustum._top ||\n bottom !== frustum._bottom ||\n left !== frustum._left ||\n right !== frustum._right ||\n near !== frustum._near ||\n far !== frustum._far\n ) {\n assert(\n frustum.near > 0 && frustum.near < frustum.far,\n 'near must be greater than zero and less than far.'\n );\n\n frustum._left = left;\n frustum._right = right;\n frustum._top = top;\n frustum._bottom = bottom;\n frustum._near = near;\n frustum._far = far;\n frustum._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n frustum._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
|
package/dist/es5/lib/plane.js
CHANGED
|
@@ -7,84 +7,70 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
11
|
|
|
14
12
|
var _core = require("@math.gl/core");
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const scratchPosition = new _core.Vector3();
|
|
15
|
+
const scratchNormal = new _core.Vector3();
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
(0, _classCallCheck2.default)(this, Plane);
|
|
17
|
+
class Plane {
|
|
18
|
+
constructor(normal = [0, 0, 1], distance = 0) {
|
|
19
|
+
(0, _defineProperty2.default)(this, "normal", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "distance", void 0);
|
|
24
21
|
this.normal = new _core.Vector3();
|
|
25
22
|
this.distance = -0;
|
|
26
23
|
this.fromNormalDistance(normal, distance);
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
key: "projectPointOntoPlane",
|
|
78
|
-
value: function projectPointOntoPlane(point) {
|
|
79
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
|
|
80
|
-
point = scratchPosition.from(point);
|
|
81
|
-
var pointDistance = this.getPointDistance(point);
|
|
82
|
-
var scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
83
|
-
return point.subtract(scaledNormal).to(result);
|
|
84
|
-
}
|
|
85
|
-
}]);
|
|
86
|
-
return Plane;
|
|
87
|
-
}();
|
|
26
|
+
fromNormalDistance(normal, distance) {
|
|
27
|
+
(0, _core.assert)(Number.isFinite(distance));
|
|
28
|
+
this.normal.from(normal).normalize();
|
|
29
|
+
this.distance = distance;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fromPointNormal(point, normal) {
|
|
34
|
+
point = scratchPosition.from(point);
|
|
35
|
+
this.normal.from(normal).normalize();
|
|
36
|
+
const distance = -this.normal.dot(point);
|
|
37
|
+
this.distance = distance;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fromCoefficients(a, b, c, d) {
|
|
42
|
+
this.normal.set(a, b, c);
|
|
43
|
+
(0, _core.assert)((0, _core.equals)(this.normal.len(), 1));
|
|
44
|
+
this.distance = d;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
clone() {
|
|
49
|
+
return new Plane(this.normal, this.distance);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
equals(right) {
|
|
53
|
+
return (0, _core.equals)(this.distance, right.distance) && (0, _core.equals)(this.normal, right.normal);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getPointDistance(point) {
|
|
57
|
+
return this.normal.dot(point) + this.distance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
transform(matrix4) {
|
|
61
|
+
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
62
|
+
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
63
|
+
return this.fromPointNormal(point, normal);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
projectPointOntoPlane(point, result = [0, 0, 0]) {
|
|
67
|
+
point = scratchPosition.from(point);
|
|
68
|
+
const pointDistance = this.getPointDistance(point);
|
|
69
|
+
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
70
|
+
return point.subtract(scaledNormal).to(result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
88
74
|
|
|
89
75
|
exports.default = Plane;
|
|
90
76
|
//# sourceMappingURL=plane.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/plane.
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/plane.ts"],"names":["scratchPosition","Vector3","scratchNormal","Plane","constructor","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","fromPointNormal","point","dot","fromCoefficients","a","b","c","d","set","len","clone","equals","right","getPointDistance","transform","matrix4","copy","transformAsVector","scale","projectPointOntoPlane","result","pointDistance","scaledNormal","subtract","to"],"mappings":";;;;;;;;;;;AAIA;;AAEA,MAAMA,eAAe,GAAG,IAAIC,aAAJ,EAAxB;AACA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;AAGe,MAAME,KAAN,CAAY;AAIzBC,EAAAA,WAAW,CAACC,MAAyB,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA7B,EAAwCC,QAAgB,GAAG,CAA3D,EAA8D;AAAA;AAAA;AACvE,SAAKD,MAAL,GAAc,IAAIJ,aAAJ,EAAd;AACA,SAAKK,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;AAGDC,EAAAA,kBAAkB,CAACF,MAAD,EAA4BC,QAA5B,EAAoD;AACpE,sBAAOE,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAP;AACA,SAAKD,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,SAAKL,QAAL,GAAgBA,QAAhB;AACA,WAAO,IAAP;AACD;;AAGDM,EAAAA,eAAe,CAACC,KAAD,EAA2BR,MAA3B,EAA4D;AACzEQ,IAAAA,KAAK,GAAGb,eAAe,CAACU,IAAhB,CAAqBG,KAArB,CAAR;AACA,SAAKR,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,UAAML,QAAQ,GAAG,CAAC,KAAKD,MAAL,CAAYS,GAAZ,CAAgBD,KAAhB,CAAlB;AACA,SAAKP,QAAL,GAAgBA,QAAhB;AACA,WAAO,IA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B,CAAqBG,KAArB,CAAR;AAEA,UAAMoB,aAAa,GAAG,KAAKR,gBAAL,CAAsBZ,KAAtB,CAAtB;AACA,UAAMqB,YAAY,GAAGhC,aAAa,CAAC0B,IAAd,CAAmB,KAAKvB,MAAxB,EAAgCyB,KAAhC,CAAsCG,aAAtC,CAArB;AAEA,WAAOpB,KAAK,CAACsB,QAAN,CAAeD,YAAf,EAA6BE,EAA7B,CAAgCJ,MAAhC,CAAP;AACD;;AAtEwB","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, equals, assert} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport default class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: readonly number[] = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: readonly number[], distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: readonly number[], normal: readonly number[]): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: readonly number[]): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: readonly number[]): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;\n projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];\n\n projectPointOntoPlane(point, result = [0, 0, 0]) {\n point = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(point);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return point.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export let INTERSECTION;
|
|
2
|
+
|
|
3
|
+
(function (INTERSECTION) {
|
|
4
|
+
INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
|
|
5
|
+
INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
|
|
6
|
+
INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE";
|
|
7
|
+
})(INTERSECTION || (INTERSECTION = {}));
|
|
6
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants.
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION"],"mappings":"AAGA,WAAYA,YAAZ;;WAAYA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,KAAAA,Y","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\nexport enum INTERSECTION {\n OUTSIDE = -1, // Represents that an object is not contained within the frustum.\n INTERSECTING = 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE = 1 // Represents that an object is fully within the frustum.\n}\n"],"file":"constants.js"}
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,4 @@ export { default as _PerspectiveFrustum } from './lib/perspective-frustum';
|
|
|
9
9
|
export { default as makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
|
|
10
10
|
export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './lib/algorithms/bounding-box-from-points';
|
|
11
11
|
export { default as computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
|
|
12
|
-
export { INTERSECTION as Intersect } from './constants';
|
|
13
|
-
export { INTERSECTION as INTERSECT } from './constants';
|
|
14
12
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["INTERSECTION","default","AxisAlignedBoundingBox","BoundingSphere","OrientedBoundingBox","CullingVolume","Plane","_PerspectiveOffCenterFrustum","_PerspectiveFrustum","makeBoundingSphereFromPoints","makeAxisAlignedBoundingBoxFromPoints","makeOrientedBoundingBoxFromPoints","computeEigenDecomposition"],"mappings":"AAGA,SAAQA,YAAR,QAA2B,aAA3B;AAEA,SAAQC,OAAO,IAAIC,sBAAnB,QAAgD,kDAAhD;AACA,SAAQD,OAAO,IAAIE,cAAnB,QAAwC,wCAAxC;AACA,SAAQF,OAAO,IAAIG,mBAAnB,QAA6C,8CAA7C;AACA,SAAQH,OAAO,IAAII,aAAnB,QAAuC,sBAAvC;AACA,SAAQJ,OAAO,IAAIK,KAAnB,QAA+B,aAA/B;AAEA,SAAQL,OAAO,IAAIM,4BAAnB,QAAsD,sCAAtD;AACA,SAAQN,OAAO,IAAIO,mBAAnB,QAA6C,2BAA7C;AAEA,SAAQP,OAAO,IAAIQ,4BAAnB,QAAsD,8CAAtD;AACA,SACEC,oCADF,EAEEC,iCAFF,QAGO,2CAHP;AAIA,SAAQV,OAAO,IAAIW,yBAAnB,QAAmD,8CAAnD","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\nexport {INTERSECTION} from './constants';\n\nexport {default as AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {default as BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {default as OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {default as CullingVolume} from './lib/culling-volume';\nexport {default as Plane} from './lib/plane';\n\nexport {default as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {default as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {default as makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {default as computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
|
|
@@ -76,12 +76,13 @@ export function makeOrientedBoundingBoxFromPoints(positions, result = new Orient
|
|
|
76
76
|
let l3 = Number.MAX_VALUE;
|
|
77
77
|
|
|
78
78
|
for (const position of positions) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
scratchVector2.copy(position);
|
|
80
|
+
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
81
|
+
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
82
|
+
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
83
|
+
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
84
|
+
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
85
|
+
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|