@math.gl/culling 4.0.0 → 4.0.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 +0 -1
- package/dist/constants.js +5 -4
- package/dist/index.cjs +27 -45
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -12
- package/dist/index.js +2 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -3
- package/dist/lib/algorithms/bounding-box-from-points.js +113 -113
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.js +117 -103
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -2
- package/dist/lib/algorithms/compute-eigen-decomposition.js +113 -85
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -3
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +100 -80
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -3
- package/dist/lib/bounding-volumes/bounding-sphere.js +106 -97
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
- package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -4
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +238 -196
- package/dist/lib/culling-volume.d.ts +3 -4
- package/dist/lib/culling-volume.js +109 -90
- package/dist/lib/perspective-frustum.d.ts +2 -3
- package/dist/lib/perspective-frustum.js +184 -136
- package/dist/lib/perspective-off-center-frustum.d.ts +2 -3
- package/dist/lib/perspective-off-center-frustum.js +259 -158
- package/dist/lib/plane.d.ts +0 -1
- package/dist/lib/plane.js +58 -59
- package/package.json +5 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +0 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +0 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/bounding-volume.js.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +0 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/lib/culling-volume.d.ts.map +0 -1
- package/dist/lib/culling-volume.js.map +0 -1
- package/dist/lib/perspective-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-frustum.js.map +0 -1
- package/dist/lib/perspective-off-center-frustum.d.ts.map +0 -1
- package/dist/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/lib/plane.d.ts.map +0 -1
- package/dist/lib/plane.js.map +0 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
|
+
// Note: This class is still an experimental export, mainly used by other test cases
|
|
4
|
+
// - It has not been fully adapted to math.gl conventions
|
|
5
|
+
// - Documentation has not been ported
|
|
2
6
|
import { Vector3, Matrix4, assert } from '@math.gl/core';
|
|
3
7
|
import { CullingVolume } from "./culling-volume.js";
|
|
4
8
|
import { Plane } from "./plane.js";
|
|
@@ -8,162 +12,259 @@ const scratchPlaneNearCenter = new Vector3();
|
|
|
8
12
|
const scratchPlaneFarCenter = new Vector3();
|
|
9
13
|
const scratchPlaneNormal = new Vector3();
|
|
10
14
|
export class PerspectiveOffCenterFrustum {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The viewing frustum is defined by 6 planes.
|
|
17
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
18
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
19
|
+
* plane from the origin/camera position.
|
|
20
|
+
*
|
|
21
|
+
* @alias PerspectiveOffCenterFrustum
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const frustum = new PerspectiveOffCenterFrustum({
|
|
25
|
+
* left : -1.0,
|
|
26
|
+
* right : 1.0,
|
|
27
|
+
* top : 1.0,
|
|
28
|
+
* bottom : -1.0,
|
|
29
|
+
* near : 1.0,
|
|
30
|
+
* far : 100.0
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* @see PerspectiveFrustum
|
|
34
|
+
*/
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
this._cullingVolume = new CullingVolume([
|
|
37
|
+
new Plane(),
|
|
38
|
+
new Plane(),
|
|
39
|
+
new Plane(),
|
|
40
|
+
new Plane(),
|
|
41
|
+
new Plane(),
|
|
42
|
+
new Plane()
|
|
43
|
+
]);
|
|
44
|
+
this._perspectiveMatrix = new Matrix4();
|
|
45
|
+
this._infinitePerspective = new Matrix4();
|
|
46
|
+
const { near = 1.0, far = 500000000.0 } = options;
|
|
47
|
+
this.left = options.left;
|
|
48
|
+
this._left = undefined;
|
|
49
|
+
this.right = options.right;
|
|
50
|
+
this._right = undefined;
|
|
51
|
+
this.top = options.top;
|
|
52
|
+
this._top = undefined;
|
|
53
|
+
this.bottom = options.bottom;
|
|
54
|
+
this._bottom = undefined;
|
|
55
|
+
this.near = near;
|
|
56
|
+
this._near = near;
|
|
57
|
+
this.far = far;
|
|
58
|
+
this._far = far;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a duplicate of a PerspectiveOffCenterFrustum instance.
|
|
62
|
+
* @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.
|
|
63
|
+
* */
|
|
64
|
+
clone() {
|
|
65
|
+
return new PerspectiveOffCenterFrustum({
|
|
66
|
+
right: this.right,
|
|
67
|
+
left: this.left,
|
|
68
|
+
top: this.top,
|
|
69
|
+
bottom: this.bottom,
|
|
70
|
+
near: this.near,
|
|
71
|
+
far: this.far
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Compares the provided PerspectiveOffCenterFrustum componentwise and returns
|
|
76
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
77
|
+
*
|
|
78
|
+
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
79
|
+
*/
|
|
80
|
+
equals(other) {
|
|
81
|
+
return (other &&
|
|
82
|
+
other instanceof PerspectiveOffCenterFrustum &&
|
|
83
|
+
this.right === other.right &&
|
|
84
|
+
this.left === other.left &&
|
|
85
|
+
this.top === other.top &&
|
|
86
|
+
this.bottom === other.bottom &&
|
|
87
|
+
this.near === other.near &&
|
|
88
|
+
this.far === other.far);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets the perspective projection matrix computed from the view frustum.
|
|
92
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
93
|
+
* @type {Matrix4}
|
|
94
|
+
*
|
|
95
|
+
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
|
|
96
|
+
*/
|
|
97
|
+
get projectionMatrix() {
|
|
98
|
+
this._update();
|
|
99
|
+
return this._perspectiveMatrix;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
103
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
104
|
+
* @type {Matrix4}
|
|
105
|
+
*
|
|
106
|
+
* @see PerspectiveOffCenterFrustum#projectionMatrix
|
|
107
|
+
*/
|
|
108
|
+
get infiniteProjectionMatrix() {
|
|
109
|
+
this._update();
|
|
110
|
+
return this._infinitePerspective;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Creates a culling volume for this frustum.
|
|
114
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Check if a bounding volume intersects the frustum.
|
|
118
|
+
* const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
119
|
+
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
120
|
+
*/
|
|
121
|
+
// eslint-disable-next-line complexity, max-statements
|
|
122
|
+
computeCullingVolume(
|
|
123
|
+
/** A Vector3 defines the eye position. */
|
|
124
|
+
position,
|
|
125
|
+
/** A Vector3 defines the view direction. */
|
|
126
|
+
direction,
|
|
127
|
+
/** A Vector3 defines the up direction. */
|
|
128
|
+
up) {
|
|
129
|
+
assert(position, 'position is required.');
|
|
130
|
+
assert(direction, 'direction is required.');
|
|
131
|
+
assert(up, 'up is required.');
|
|
132
|
+
const planes = this._cullingVolume.planes;
|
|
133
|
+
up = scratchPlaneUpVector.copy(up).normalize();
|
|
134
|
+
const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
|
|
135
|
+
const nearCenter = scratchPlaneNearCenter
|
|
136
|
+
.copy(direction)
|
|
137
|
+
.multiplyByScalar(this.near)
|
|
138
|
+
.add(position);
|
|
139
|
+
const farCenter = scratchPlaneFarCenter
|
|
140
|
+
.copy(direction)
|
|
141
|
+
.multiplyByScalar(this.far)
|
|
142
|
+
.add(position);
|
|
143
|
+
let normal = scratchPlaneNormal;
|
|
144
|
+
// Left plane computation
|
|
145
|
+
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
146
|
+
planes[0].fromPointNormal(position, normal);
|
|
147
|
+
// Right plane computation
|
|
148
|
+
normal
|
|
149
|
+
.copy(right)
|
|
150
|
+
.multiplyByScalar(this.right)
|
|
151
|
+
.add(nearCenter)
|
|
152
|
+
.subtract(position)
|
|
153
|
+
.cross(up)
|
|
154
|
+
.negate();
|
|
155
|
+
planes[1].fromPointNormal(position, normal);
|
|
156
|
+
// Bottom plane computation
|
|
157
|
+
normal
|
|
158
|
+
.copy(up)
|
|
159
|
+
.multiplyByScalar(this.bottom)
|
|
160
|
+
.add(nearCenter)
|
|
161
|
+
.subtract(position)
|
|
162
|
+
.cross(right)
|
|
163
|
+
.negate();
|
|
164
|
+
planes[2].fromPointNormal(position, normal);
|
|
165
|
+
// Top plane computation
|
|
166
|
+
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
167
|
+
planes[3].fromPointNormal(position, normal);
|
|
168
|
+
normal = new Vector3().copy(direction);
|
|
169
|
+
// Near plane computation
|
|
170
|
+
planes[4].fromPointNormal(nearCenter, normal);
|
|
171
|
+
// Far plane computation
|
|
172
|
+
normal.negate();
|
|
173
|
+
planes[5].fromPointNormal(farCenter, normal);
|
|
174
|
+
return this._cullingVolume;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns the pixel's width and height in meters.
|
|
178
|
+
*
|
|
179
|
+
* @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.
|
|
180
|
+
*
|
|
181
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
182
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* // Example 1
|
|
186
|
+
* // Get the width and height of a pixel.
|
|
187
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* // Example 2
|
|
191
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
192
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
193
|
+
* const position = camera.position;
|
|
194
|
+
* const direction = camera.direction;
|
|
195
|
+
* const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
196
|
+
* const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
197
|
+
* const distance = Vector3.magnitude(toCenterProj);
|
|
198
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
199
|
+
*/
|
|
200
|
+
getPixelDimensions(
|
|
201
|
+
/** The width of the drawing buffer. */
|
|
202
|
+
drawingBufferWidth,
|
|
203
|
+
/** The height of the drawing buffer. */
|
|
204
|
+
drawingBufferHeight,
|
|
205
|
+
/** The distance to the near plane in meters. */
|
|
206
|
+
distance,
|
|
207
|
+
/** The object onto which to store the result. */
|
|
208
|
+
result) {
|
|
209
|
+
this._update();
|
|
210
|
+
assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
211
|
+
// 'Both drawingBufferWidth and drawingBufferHeight are required.'
|
|
212
|
+
assert(drawingBufferWidth > 0);
|
|
213
|
+
// 'drawingBufferWidth must be greater than zero.'
|
|
214
|
+
assert(drawingBufferHeight > 0);
|
|
215
|
+
// 'drawingBufferHeight must be greater than zero.'
|
|
216
|
+
assert(distance > 0);
|
|
217
|
+
// 'distance is required.');
|
|
218
|
+
assert(result);
|
|
219
|
+
// 'A result object is required.');
|
|
220
|
+
const inverseNear = 1.0 / this.near;
|
|
221
|
+
let tanTheta = this.top * inverseNear;
|
|
222
|
+
const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;
|
|
223
|
+
tanTheta = this.right * inverseNear;
|
|
224
|
+
const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;
|
|
225
|
+
result.x = pixelWidth;
|
|
226
|
+
result.y = pixelHeight;
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
// eslint-disable-next-line complexity, max-statements
|
|
230
|
+
_update() {
|
|
231
|
+
assert(Number.isFinite(this.right) &&
|
|
232
|
+
Number.isFinite(this.left) &&
|
|
233
|
+
Number.isFinite(this.top) &&
|
|
234
|
+
Number.isFinite(this.bottom) &&
|
|
235
|
+
Number.isFinite(this.near) &&
|
|
236
|
+
Number.isFinite(this.far));
|
|
237
|
+
// throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
|
|
238
|
+
const { top, bottom, right, left, near, far } = this;
|
|
239
|
+
if (top !== this._top ||
|
|
240
|
+
bottom !== this._bottom ||
|
|
241
|
+
left !== this._left ||
|
|
242
|
+
right !== this._right ||
|
|
243
|
+
near !== this._near ||
|
|
244
|
+
far !== this._far) {
|
|
245
|
+
assert(this.near > 0 && this.near < this.far, 'near must be greater than zero and less than far.');
|
|
246
|
+
this._left = left;
|
|
247
|
+
this._right = right;
|
|
248
|
+
this._top = top;
|
|
249
|
+
this._bottom = bottom;
|
|
250
|
+
this._near = near;
|
|
251
|
+
this._far = far;
|
|
252
|
+
this._perspectiveMatrix = new Matrix4().frustum({
|
|
253
|
+
left,
|
|
254
|
+
right,
|
|
255
|
+
bottom,
|
|
256
|
+
top,
|
|
257
|
+
near,
|
|
258
|
+
far
|
|
259
|
+
});
|
|
260
|
+
this._infinitePerspective = new Matrix4().frustum({
|
|
261
|
+
left,
|
|
262
|
+
right,
|
|
263
|
+
bottom,
|
|
264
|
+
top,
|
|
265
|
+
near,
|
|
266
|
+
far: Infinity
|
|
267
|
+
});
|
|
268
|
+
}
|
|
165
269
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
270
|
}
|
|
169
|
-
//# sourceMappingURL=perspective-off-center-frustum.js.map
|
package/dist/lib/plane.d.ts
CHANGED
package/dist/lib/plane.js
CHANGED
|
@@ -1,64 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
|
+
/* eslint-disable */
|
|
2
4
|
import { Vector3, equals, assert } from '@math.gl/core';
|
|
3
5
|
const scratchPosition = new Vector3();
|
|
4
6
|
const scratchNormal = new Vector3();
|
|
7
|
+
// A plane in Hessian Normal Form
|
|
5
8
|
export class Plane {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
return scratchPoint.subtract(scaledNormal).to(result);
|
|
61
|
-
}
|
|
62
|
-
|
|
9
|
+
constructor(normal = [0, 0, 1], distance = 0) {
|
|
10
|
+
this.normal = new Vector3();
|
|
11
|
+
this.distance = -0;
|
|
12
|
+
this.fromNormalDistance(normal, distance);
|
|
13
|
+
}
|
|
14
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
15
|
+
fromNormalDistance(normal, distance) {
|
|
16
|
+
assert(Number.isFinite(distance));
|
|
17
|
+
this.normal.from(normal).normalize();
|
|
18
|
+
this.distance = distance;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
22
|
+
fromPointNormal(point, normal) {
|
|
23
|
+
point = scratchPosition.from(point);
|
|
24
|
+
this.normal.from(normal).normalize();
|
|
25
|
+
const distance = -this.normal.dot(point);
|
|
26
|
+
this.distance = distance;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/** Creates a plane from the general equation */
|
|
30
|
+
fromCoefficients(a, b, c, d) {
|
|
31
|
+
this.normal.set(a, b, c);
|
|
32
|
+
assert(equals(this.normal.len(), 1));
|
|
33
|
+
this.distance = d;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/** Duplicates a Plane instance. */
|
|
37
|
+
clone() {
|
|
38
|
+
return new Plane(this.normal, this.distance);
|
|
39
|
+
}
|
|
40
|
+
/** Compares the provided Planes by normal and distance */
|
|
41
|
+
equals(right) {
|
|
42
|
+
return equals(this.distance, right.distance) && equals(this.normal, right.normal);
|
|
43
|
+
}
|
|
44
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
45
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
46
|
+
*/
|
|
47
|
+
getPointDistance(point) {
|
|
48
|
+
return this.normal.dot(point) + this.distance;
|
|
49
|
+
}
|
|
50
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
51
|
+
transform(matrix4) {
|
|
52
|
+
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
53
|
+
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
54
|
+
return this.fromPointNormal(point, normal);
|
|
55
|
+
}
|
|
56
|
+
projectPointOntoPlane(point, result = [0, 0, 0]) {
|
|
57
|
+
const scratchPoint = scratchPosition.from(point);
|
|
58
|
+
// projectedPoint = point - (normal.point + scale) * normal
|
|
59
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
60
|
+
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
61
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
62
|
+
}
|
|
63
63
|
}
|
|
64
|
-
//# sourceMappingURL=plane.js.map
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "4.0.
|
|
9
|
+
"version": "4.0.1",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"webgl",
|
|
12
12
|
"javascript",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"module": "dist/index.js",
|
|
33
33
|
"exports": {
|
|
34
34
|
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
35
36
|
"import": "./dist/index.js",
|
|
36
|
-
"require": "./dist/index.cjs"
|
|
37
|
-
"types": "./dist/index.d.ts"
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@math.gl/core": "4.0.0"
|
|
45
|
+
"@math.gl/core": "4.0.1"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "33f369ba3a259f79acc3fa8181190c9da8841648"
|
|
49
48
|
}
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"names":["INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":"AAGA,OAAO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,OAAO,EAAE,CAAC,CADgB;AAE1BC,EAAAA,YAAY,EAAE,CAFY;AAG1BC,EAAAA,MAAM,EAAE;AAHkB,CAArB","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 const 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} as const;\n"],"file":"constants.js"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAC,cAAc,EAAC,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAElC,OAAO,EAAC,2BAA2B,IAAI,4BAA4B,EAAC,MAAM,sCAAsC,CAAC;AACjH,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAEpF,OAAO,EAAC,4BAA4B,EAAC,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAC,yBAAyB,EAAC,MAAM,8CAA8C,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["INTERSECTION","AxisAlignedBoundingBox","BoundingSphere","OrientedBoundingBox","CullingVolume","Plane","PerspectiveOffCenterFrustum","_PerspectiveOffCenterFrustum","PerspectiveFrustum","_PerspectiveFrustum","makeBoundingSphereFromPoints","makeAxisAlignedBoundingBoxFromPoints","makeOrientedBoundingBoxFromPoints","computeEigenDecomposition"],"mappings":"SAGQA,Y;SAEAC,sB;SACAC,c;SACAC,mB;SACAC,a;SACAC,K;SAEAC,2BAA2B,IAAIC,4B;SAC/BC,kBAAkB,IAAIC,mB;SAEtBC,4B;SAENC,oC,EACAC,iC;SAEMC,yB","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 {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {CullingVolume} from './lib/culling-volume';\nexport {Plane} from './lib/plane';\n\nexport {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bounding-box-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,mBAAmB,EAAC,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAC,sBAAsB,EAAC,MAAM,+CAA+C,CAAC;AAmBrF;;;;;GAKG;AAEH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,mBAA+C,GACtD,mBAAmB,CAuFrB;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,EAC9B,MAAM,GAAE,sBAAqD,GAC5D,sBAAsB,CAoCxB"}
|