@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perspective-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,OAAO,EAAE,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAErE,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"perspective-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,OAAO,EAAE,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAErE,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAI/C,aAAK,yBAAyB,GAAG;IAC/B,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,iBAAiB,CAAqC;IAC9D;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,IAAI,CAAS;IACrB,OA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OAAO;CAqDhB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { assert, Vector2 } from '@math.gl/core';
|
|
3
|
-
import PerspectiveOffCenterFrustum from
|
|
3
|
+
import { PerspectiveOffCenterFrustum } from "./perspective-off-center-frustum.js";
|
|
4
4
|
|
|
5
5
|
const defined = val => val !== null && typeof val !== 'undefined';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export class PerspectiveFrustum {
|
|
8
8
|
constructor(options = {}) {
|
|
9
9
|
_defineProperty(this, "_offCenterFrustum", new PerspectiveOffCenterFrustum());
|
|
10
10
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/perspective-frustum.ts"],"names":["assert","Vector2","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","fov","aspectRatio","near","far","xOffset","yOffset","clone","equals","other","_update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","f","_fov","_aspectRatio","_near","_far","_xOffset","_yOffset","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AAOA,SAAQA,MAAR,EAAuCC,OAAvC,QAAqD,eAArD;SACQC,2B;;AAGR,MAAMC,OAAO,GAAIC,GAAD,IAAkBA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAjE;;AAmCA,OAAO,MAAMC,kBAAN,CAAyB;AAyC9BC,EAAAA,WAAW,CAACC,OAAkC,GAAG,EAAtC,EAA0C;AAAA,+CAxCzB,IAAIL,2BAAJ,EAwCyB;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACnD,UAAM;AAACM,MAAAA,GAAD;AAAMC,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AAF,IAAW,KAAKrC,OAAhB;AACAwB,MAAAA,CAAC,CAACc,IAAF,IAAU,KAAKtC,OAAf;AACAwB,MAAAA,CAAC,CAACW,GAAF,IAAS,KAAKlC,OAAd;AACAuB,MAAAA,CAAC,CAACY,MAAF,IAAY,KAAKnC,OAAjB;AACD;AACF;;AAzO6B","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: unknown) => 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 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,5 +1,5 @@
|
|
|
1
1
|
import { Vector2, Matrix4, NumericArray } from '@math.gl/core';
|
|
2
|
-
import CullingVolume from './culling-volume';
|
|
2
|
+
import { CullingVolume } from './culling-volume';
|
|
3
3
|
declare type PerspectiveOffCenterFrustumOptions = {
|
|
4
4
|
left?: number;
|
|
5
5
|
right?: number;
|
|
@@ -8,7 +8,7 @@ declare type PerspectiveOffCenterFrustumOptions = {
|
|
|
8
8
|
near?: number;
|
|
9
9
|
far?: number;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export declare class PerspectiveOffCenterFrustum {
|
|
12
12
|
/**
|
|
13
13
|
* Defines the left clipping plane.
|
|
14
14
|
* @type {Number}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perspective-off-center-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAU,OAAO,EAAE,OAAO,EAAU,YAAY,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"perspective-off-center-frustum.d.ts","sourceRoot":"","sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":[],"mappings":"AAOA,OAAO,EAAU,OAAO,EAAE,OAAO,EAAU,YAAY,EAAC,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAS/C,aAAK,kCAAkC,GAAG;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,qBAAa,2BAA2B;IACtC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,IAAI,CAAC,CAAS;IACtB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,KAAK,CAAS;IACtB;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO,CAAC,cAAc,CAOnB;IACH,OAAO,CAAC,kBAAkB,CAAiB;IAC3C,OAAO,CAAC,oBAAoB,CAAiB;IAE7C;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,OAAO,GAAE,kCAAuC;IAsB5D;;;SAGK;IACL,KAAK,IAAI,2BAA2B;IAWpC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO;IAanD;;;;;;OAMG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAG9B;IAED;;;;;;OAMG;IACH,IAAI,wBAAwB,IAAI,OAAO,CAGtC;IAED;;;;;;;;OAQG;IAEH,oBAAoB;IAClB,0CAA0C;IAC1C,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC;IAChC,4CAA4C;IAC5C,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC;IACjC,0CAA0C;IAC1C,EAAE,EAAE,QAAQ,CAAC,YAAY,CAAC,GACzB,aAAa;IAmEhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,kBAAkB;IAChB,uCAAuC;IACvC,kBAAkB,EAAE,MAAM;IAC1B,wCAAwC;IACxC,mBAAmB,EAAE,MAAM;IAC3B,gDAAgD;IAChD,QAAQ,EAAE,MAAM;IAChB,iDAAiD;IACjD,MAAM,EAAE,OAAO,GACd,OAAO;IA0BV,OAAO,CAAC,OAAO;CAkDhB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { Vector3, Matrix4, assert } from '@math.gl/core';
|
|
3
|
-
import CullingVolume from
|
|
4
|
-
import Plane from
|
|
3
|
+
import { CullingVolume } from "./culling-volume.js";
|
|
4
|
+
import { Plane } from "./plane.js";
|
|
5
5
|
const scratchPlaneUpVector = new Vector3();
|
|
6
6
|
const scratchPlaneRightVector = new Vector3();
|
|
7
7
|
const scratchPlaneNearCenter = new Vector3();
|
|
8
8
|
const scratchPlaneFarCenter = new Vector3();
|
|
9
9
|
const scratchPlaneNormal = new Vector3();
|
|
10
|
-
export
|
|
10
|
+
export class PerspectiveOffCenterFrustum {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
_defineProperty(this, "left", void 0);
|
|
13
13
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/perspective-off-center-frustum.ts"],"names":["Vector3","Matrix4","assert","CullingVolume","Plane","scratchPlaneUpVector","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","constructor","options","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":";AAOA,SAAQA,OAAR,EAA0BC,OAA1B,EAAmCC,MAAnC,QAA8D,eAA9D;SACQC,a;SACAC,K;AAER,MAAMC,oBAAoB,GAAG,IAAIL,OAAJ,EAA7B;AACA,MAAMM,uBAAuB,GAAG,IAAIN,OAAJ,EAAhC;AACA,MAAMO,sBAAsB,GAAG,IAAIP,OAAJ,EAA/B;AACA,MAAMQ,qBAAqB,GAAG,IAAIR,OAAJ,EAA9B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,OAAJ,EAA3B;AAWA,OAAO,MAAMU,2BAAN,CAAkC;AA2EvCC,EA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,CAAsB;AAChDjD,QAAAA,IADgD;AAEhDG,QAAAA,KAFgD;AAGhDI,QAAAA,MAHgD;AAIhDF,QAAAA,GAJgD;AAKhDP,QAAAA,IALgD;AAMhDC,QAAAA,GAAG,EAAEmD;AAN2C,OAAtB,CAA5B;AAQD;AACF;;AA3VsC","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 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"}
|
package/dist/lib/plane.d.ts
CHANGED
package/dist/lib/plane.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAkB,YAAY,EAAC,MAAM,eAAe,CAAC;AAMpE,
|
|
1
|
+
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAkB,YAAY,EAAC,MAAM,eAAe,CAAC;AAMpE,qBAAa,KAAK;IAChB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,GAAE,QAAQ,CAAC,YAAY,CAAa,EAAE,QAAQ,GAAE,MAAU;IAM5E,oEAAoE;IACpE,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAO1E,8DAA8D;IAC9D,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAQpF,gDAAgD;IAChD,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAOlE,mCAAmC;IACnC,KAAK,IAAI,KAAK;IAId,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAIvD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAMhD,uCAAuC;IACvC,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAC9E,qBAAqB,CACnB,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC7B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE;CAUrB"}
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import { Vector3, equals, assert } from '@math.gl/core';
|
|
3
3
|
const scratchPosition = new Vector3();
|
|
4
4
|
const scratchNormal = new Vector3();
|
|
5
|
-
export
|
|
5
|
+
export class Plane {
|
|
6
6
|
constructor(normal = [0, 0, 1], distance = 0) {
|
|
7
7
|
_defineProperty(this, "normal", void 0);
|
|
8
8
|
|
|
@@ -54,10 +54,10 @@ export default class Plane {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
projectPointOntoPlane(point, result = [0, 0, 0]) {
|
|
57
|
-
|
|
58
|
-
const pointDistance = this.getPointDistance(
|
|
57
|
+
const scratchPoint = scratchPosition.from(point);
|
|
58
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
59
59
|
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
60
|
-
return
|
|
60
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/plane.ts"],"names":["Vector3","equals","assert","scratchPosition","scratchNormal","Plane","constructor","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","fromPointNormal","point","dot","fromCoefficients","a","b","c","d","set","len","clone","right","getPointDistance","transform","matrix4","copy","transformAsVector","scale","projectPointOntoPlane","result","scratchPoint","pointDistance","scaledNormal","subtract","to"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,EAAyBC,MAAzB,QAAoD,eAApD;AAEA,MAAMC,eAAe,GAAG,IAAIH,OAAJ,EAAxB;AACA,MAAMI,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAGA,OAAO,MAAMK,KAAN,CAAY;AAIjBC,EAAAA,WAAW,CAACC,MAA8B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAlC,EAA6CC,QAAgB,GAAG,CAAhE,EAAmE;AAAA;;AAAA;;AAC5E,SAAKD,MAAL,GAAc,IAAIP,OAAJ,EAAd;AACA,SAAKQ,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;AAGDC,EAAAA,kBAAkB,CAACF,MAAD,EAAiCC,QAAjC,EAAyD;AACzEN,IAAAA,MAAM,CAACQ,MAAM,CAACC,QAAP,C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A,SAAS,CAACC,OAAD,EAAwC;AAC/C,UAAMrB,MAAM,GAAGH,aAAa,CAACyB,IAAd,CAAmB,KAAKtB,MAAxB,EAAgCuB,iBAAhC,CAAkDF,OAAlD,EAA2Df,SAA3D,EAAf;AACA,UAAME,KAAK,GAAG,KAAKR,MAAL,CAAYwB,KAAZ,CAAkB,CAAC,KAAKvB,QAAxB,EAAkCmB,SAAlC,CAA4CC,OAA5C,CAAd;AACA,WAAO,KAAKd,eAAL,CAAqBC,KAArB,EAA4BR,MAA5B,CAAP;AACD;;AASDyB,EAAAA,qBAAqB,CAACjB,KAAD,EAAgCkB,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAzC,EAAoD;AACvE,UAAMC,YAAY,GAAG/B,eAAe,CAACS,IAAhB,CAAqBG,KAArB,CAArB;AAEA,UAAMoB,aAAa,GAAG,KAAKT,gBAAL,CAAsBQ,YAAtB,CAAtB;AACA,UAAME,YAAY,GAAGhC,aAAa,CAACyB,IAAd,CAAmB,KAAKtB,MAAxB,EAAgCwB,KAAhC,CAAsCI,aAAtC,CAArB;AAEA,WAAOD,YAAY,CAACG,QAAb,CAAsBD,YAAtB,EAAoCE,EAApC,CAAuCL,MAAvC,CAAP;AACD;;AAzEgB","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, NumericArray} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: Readonly<NumericArray> = [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<NumericArray>, 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<NumericArray>, normal: Readonly<NumericArray>): 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<NumericArray>): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: Readonly<NumericArray>): 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<NumericArray>, result: Vector3): Vector3;\n projectPointOntoPlane(\n point: Readonly<NumericArray>,\n result?: readonly number[]\n ): readonly number[];\n\n projectPointOntoPlane(point: Readonly<NumericArray>, result = [0, 0, 0]) {\n const scratchPoint = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(scratchPoint);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return scratchPoint.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
|
package/package.json
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
"name": "@math.gl/culling",
|
|
3
3
|
"description": "Culling Functionality for 3D Classes",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"publishConfig": {
|
|
6
7
|
"access": "public"
|
|
7
8
|
},
|
|
8
|
-
"version": "
|
|
9
|
+
"version": "4.0.0-alpha.2",
|
|
9
10
|
"keywords": [
|
|
10
11
|
"webgl",
|
|
11
12
|
"javascript",
|
|
@@ -27,16 +28,16 @@
|
|
|
27
28
|
"url": "https://github.com/uber-web/math.gl.git"
|
|
28
29
|
},
|
|
29
30
|
"types": "dist/index.d.ts",
|
|
30
|
-
"main": "dist/
|
|
31
|
-
"module": "dist/
|
|
31
|
+
"main": "dist/index.cjs",
|
|
32
|
+
"module": "dist/index.js",
|
|
32
33
|
"files": [
|
|
33
34
|
"dist",
|
|
34
35
|
"src"
|
|
35
36
|
],
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@babel/runtime": "^7.12.0",
|
|
38
|
-
"@math.gl/core": "
|
|
39
|
-
"gl-matrix": "^3.4.
|
|
39
|
+
"@math.gl/core": "4.0.0-alpha.2",
|
|
40
|
+
"gl-matrix": "^3.4.3"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2e693639e3cf898fee8e323c93efdd07be7c2ca7"
|
|
42
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
export {INTERSECTION} from './constants';
|
|
5
5
|
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
6
|
+
export {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
7
|
+
export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
|
|
8
|
+
export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
|
|
9
|
+
export {CullingVolume} from './lib/culling-volume';
|
|
10
|
+
export {Plane} from './lib/plane';
|
|
11
11
|
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
12
|
+
export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
|
|
13
|
+
export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
|
|
14
14
|
|
|
15
|
-
export {
|
|
15
|
+
export {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';
|
|
16
16
|
export {
|
|
17
17
|
makeAxisAlignedBoundingBoxFromPoints,
|
|
18
18
|
makeOrientedBoundingBoxFromPoints
|
|
19
19
|
} from './lib/algorithms/bounding-box-from-points';
|
|
20
|
-
export {
|
|
20
|
+
export {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
4
|
import {Vector3, Matrix3} from '@math.gl/core';
|
|
5
|
-
import computeEigenDecomposition from './compute-eigen-decomposition';
|
|
6
|
-
import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
|
|
7
|
-
import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
|
|
5
|
+
import {computeEigenDecomposition} from './compute-eigen-decomposition';
|
|
6
|
+
import {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';
|
|
7
|
+
import {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
|
|
8
8
|
|
|
9
9
|
const scratchVector2 = new Vector3();
|
|
10
10
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
4
|
import {Vector3} from '@math.gl/core';
|
|
5
|
-
import BoundingSphere from '../bounding-volumes/bounding-sphere';
|
|
5
|
+
import {BoundingSphere} from '../bounding-volumes/bounding-sphere';
|
|
6
6
|
|
|
7
7
|
/* eslint-disable */
|
|
8
8
|
const fromPointsXMin = new Vector3();
|
|
@@ -17,7 +17,7 @@ const fromPointsRitterCenter = new Vector3();
|
|
|
17
17
|
const fromPointsMinBoxPt = new Vector3();
|
|
18
18
|
const fromPointsMaxBoxPt = new Vector3();
|
|
19
19
|
const fromPointsNaiveCenterScratch = new Vector3();
|
|
20
|
-
const volumeConstant = (4.0 / 3.0) * Math.PI;
|
|
20
|
+
// const volumeConstant = (4.0 / 3.0) * Math.PI;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
|
|
@@ -30,7 +30,7 @@ const volumeConstant = (4.0 / 3.0) * Math.PI;
|
|
|
30
30
|
* @param result Optional object onto which to store the result.
|
|
31
31
|
* @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
33
|
+
export function makeBoundingSphereFromPoints(
|
|
34
34
|
positions: number[][],
|
|
35
35
|
result: BoundingSphere = new BoundingSphere()
|
|
36
36
|
): BoundingSphere {
|
|
@@ -45,7 +45,7 @@ export type EigenDecomposition = {
|
|
|
45
45
|
* const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector
|
|
46
46
|
* const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)
|
|
47
47
|
*/
|
|
48
|
-
export
|
|
48
|
+
export function computeEigenDecomposition(
|
|
49
49
|
matrix: number[],
|
|
50
50
|
// @ts-expect-error accept empty object type
|
|
51
51
|
result: EigenDecomposition = {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {BoundingVolume} from './bounding-volume';
|
|
2
2
|
import {Vector3} from '@math.gl/core';
|
|
3
|
-
import Plane from '../plane';
|
|
3
|
+
import {Plane} from '../plane';
|
|
4
4
|
import {INTERSECTION} from '../../constants';
|
|
5
5
|
|
|
6
6
|
const scratchVector = new Vector3();
|
|
@@ -12,7 +12,7 @@ const scratchNormal = new Vector3();
|
|
|
12
12
|
* @see BoundingRectangle
|
|
13
13
|
* @see OrientedBoundingBox
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export class AxisAlignedBoundingBox implements BoundingVolume {
|
|
16
16
|
/** The center point of the bounding box. */
|
|
17
17
|
readonly center: Vector3;
|
|
18
18
|
/** The positive half diagonal of the bounding box. */
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
3
|
|
|
4
4
|
import {NumericArray, Vector3} from '@math.gl/core';
|
|
5
|
+
// @ts-ignore gl-matrix typings...
|
|
5
6
|
import * as mat4 from 'gl-matrix/mat4';
|
|
7
|
+
|
|
6
8
|
import {INTERSECTION} from '../../constants';
|
|
7
9
|
import {BoundingVolume} from './bounding-volume';
|
|
8
|
-
import Plane from '../plane';
|
|
10
|
+
import {Plane} from '../plane';
|
|
9
11
|
|
|
10
12
|
const scratchVector = new Vector3();
|
|
11
13
|
const scratchVector2 = new Vector3();
|
|
12
14
|
|
|
13
15
|
/** A BoundingSphere */
|
|
14
|
-
export
|
|
16
|
+
export class BoundingSphere implements BoundingVolume {
|
|
15
17
|
center: Vector3;
|
|
16
18
|
radius: number;
|
|
17
19
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';
|
|
5
5
|
import type {BoundingVolume} from './bounding-volume';
|
|
6
|
-
import BoundingSphere from './bounding-sphere';
|
|
7
|
-
import type Plane from '../plane';
|
|
6
|
+
import {BoundingSphere} from './bounding-sphere';
|
|
7
|
+
import type {Plane} from '../plane';
|
|
8
8
|
import {INTERSECTION} from '../../constants';
|
|
9
9
|
|
|
10
10
|
const scratchVector3 = new Vector3();
|
|
@@ -32,7 +32,7 @@ const MATRIX3 = {
|
|
|
32
32
|
* It can provide a tighter bounding volume than `BoundingSphere` or
|
|
33
33
|
* `AxisAlignedBoundingBox` in many cases.
|
|
34
34
|
*/
|
|
35
|
-
export
|
|
35
|
+
export class OrientedBoundingBox implements BoundingVolume {
|
|
36
36
|
center: Vector3;
|
|
37
37
|
halfAxes: Matrix3;
|
|
38
38
|
|
|
@@ -41,8 +41,11 @@ export default class OrientedBoundingBox implements BoundingVolume {
|
|
|
41
41
|
* It can provide a tighter bounding volume than
|
|
42
42
|
* `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.
|
|
43
43
|
*/
|
|
44
|
-
constructor(center?:
|
|
45
|
-
constructor(
|
|
44
|
+
constructor(center?: Readonly<NumericArray>, halfAxes?: Readonly<NumericArray>);
|
|
45
|
+
constructor(
|
|
46
|
+
center: Readonly<NumericArray> = [0, 0, 0],
|
|
47
|
+
halfAxes: Readonly<NumericArray> = [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
48
|
+
) {
|
|
46
49
|
this.center = new Vector3().from(center);
|
|
47
50
|
this.halfAxes = new Matrix3(halfAxes);
|
|
48
51
|
}
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
import {Vector3, assert} from '@math.gl/core';
|
|
6
6
|
import {INTERSECTION} from '../constants';
|
|
7
|
-
import Plane from './plane';
|
|
7
|
+
import {Plane} from './plane';
|
|
8
8
|
import type {BoundingVolume} from './bounding-volumes/bounding-volume';
|
|
9
|
-
import type BoundingSphere from './bounding-volumes/bounding-sphere';
|
|
9
|
+
import type {BoundingSphere} from './bounding-volumes/bounding-sphere';
|
|
10
10
|
|
|
11
11
|
// X, Y, Z Unit vectors
|
|
12
12
|
const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];
|
|
13
13
|
|
|
14
14
|
const scratchPlaneCenter = new Vector3();
|
|
15
15
|
const scratchPlaneNormal = new Vector3();
|
|
16
|
-
const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);
|
|
16
|
+
// const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);
|
|
17
17
|
|
|
18
18
|
/** A culling volume defined by planes. */
|
|
19
|
-
export
|
|
19
|
+
export class CullingVolume {
|
|
20
20
|
/**
|
|
21
21
|
* For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
|
|
22
22
|
* represents the case where the object bounding volume is entirely outside the culling volume.
|
|
@@ -70,7 +70,7 @@ export default class CullingVolume {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
|
|
73
|
-
const plane0Distance = -faceNormal.dot(plane0Center);
|
|
73
|
+
// const plane0Distance = -faceNormal.dot(plane0Center);
|
|
74
74
|
|
|
75
75
|
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
76
76
|
|
|
@@ -78,7 +78,7 @@ export default class CullingVolume {
|
|
|
78
78
|
|
|
79
79
|
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
80
80
|
|
|
81
|
-
const plane1Distance = -negatedFaceNormal.dot(plane1Center);
|
|
81
|
+
// const plane1Distance = -negatedFaceNormal.dot(plane1Center);
|
|
82
82
|
|
|
83
83
|
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
84
84
|
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
// - Documentation has not been ported
|
|
7
7
|
|
|
8
8
|
import {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';
|
|
9
|
-
import PerspectiveOffCenterFrustum from './perspective-off-center-frustum';
|
|
10
|
-
import CullingVolume from './culling-volume';
|
|
9
|
+
import {PerspectiveOffCenterFrustum} from './perspective-off-center-frustum';
|
|
10
|
+
import {CullingVolume} from './culling-volume';
|
|
11
11
|
|
|
12
|
-
const defined = (val) => val !== null && typeof val !== 'undefined';
|
|
12
|
+
const defined = (val: unknown) => val !== null && typeof val !== 'undefined';
|
|
13
13
|
|
|
14
14
|
type PerspectiveFrustumOptions = {
|
|
15
15
|
/** The angle of the field of view (FOV), in radians. */
|
|
@@ -44,7 +44,7 @@ type PerspectiveFrustumOptions = {
|
|
|
44
44
|
*
|
|
45
45
|
* @see PerspectiveOffCenterFrustum
|
|
46
46
|
*/
|
|
47
|
-
export
|
|
47
|
+
export class PerspectiveFrustum {
|
|
48
48
|
private _offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
49
49
|
/**
|
|
50
50
|
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// - Documentation has not been ported
|
|
7
7
|
|
|
8
8
|
import {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';
|
|
9
|
-
import CullingVolume from './culling-volume';
|
|
10
|
-
import Plane from './plane';
|
|
9
|
+
import {CullingVolume} from './culling-volume';
|
|
10
|
+
import {Plane} from './plane';
|
|
11
11
|
|
|
12
12
|
const scratchPlaneUpVector = new Vector3();
|
|
13
13
|
const scratchPlaneRightVector = new Vector3();
|
|
@@ -24,7 +24,7 @@ type PerspectiveOffCenterFrustumOptions = {
|
|
|
24
24
|
far?: number;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export
|
|
27
|
+
export class PerspectiveOffCenterFrustum {
|
|
28
28
|
/**
|
|
29
29
|
* Defines the left clipping plane.
|
|
30
30
|
* @type {Number}
|
package/src/lib/plane.ts
CHANGED
|
@@ -8,7 +8,7 @@ const scratchPosition = new Vector3();
|
|
|
8
8
|
const scratchNormal = new Vector3();
|
|
9
9
|
|
|
10
10
|
// A plane in Hessian Normal Form
|
|
11
|
-
export
|
|
11
|
+
export class Plane {
|
|
12
12
|
readonly normal: Vector3;
|
|
13
13
|
distance: number;
|
|
14
14
|
|
|
@@ -74,12 +74,12 @@ export default class Plane {
|
|
|
74
74
|
result?: readonly number[]
|
|
75
75
|
): readonly number[];
|
|
76
76
|
|
|
77
|
-
projectPointOntoPlane(point
|
|
78
|
-
|
|
77
|
+
projectPointOntoPlane(point: Readonly<NumericArray>, result = [0, 0, 0]) {
|
|
78
|
+
const scratchPoint = scratchPosition.from(point);
|
|
79
79
|
// projectedPoint = point - (normal.point + scale) * normal
|
|
80
|
-
const pointDistance = this.getPointDistance(
|
|
80
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
81
81
|
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
82
82
|
|
|
83
|
-
return
|
|
83
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
84
84
|
}
|
|
85
85
|
}
|
package/dist/es5/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.INTERSECTION = void 0;
|
|
7
|
-
var INTERSECTION = {
|
|
8
|
-
OUTSIDE: -1,
|
|
9
|
-
INTERSECTING: 0,
|
|
10
|
-
INSIDE: 1
|
|
11
|
-
};
|
|
12
|
-
exports.INTERSECTION = INTERSECTION;
|
|
13
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;AAGO,IAAMA,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"}
|