@math.gl/culling 3.5.7 → 3.6.0-alpha.3
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 +0 -12
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +12 -6
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +8 -4
- 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 +4 -0
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +6 -20
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +17 -7
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +17 -5
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +5 -1
- 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.map +1 -1
- 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 +9 -4
- 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 +140 -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} +17 -4
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +15 -3
- 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} +44 -29
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-frustum.js"],"names":["assert","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","near","far","xOffset","yOffset","_offCenterFrustum","fov","_fov","undefined","_fovy","_sseDenominator","aspectRatio","_aspectRatio","_near","_far","_xOffset","_yOffset","clone","equals","other","update","projectionMatrix","infiniteProjectionMatrix","fovy","sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","frustum","Number","isFinite","f","Math","PI","atan","tan","top","bottom","right","left"],"mappings":"AASA,SAAQA,MAAR,QAAqB,eAArB;AACA,OAAOC,2BAAP,MAAwC,kCAAxC;;AAEA,MAAMC,OAAO,GAAIC,GAAD,IAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAxD;;AA6BA,eAAe,MAAMC,kBAAN,CAAyB;AACtCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxBA,IAAAA,OAAO,GAAG;AACRC,MAAAA,IAAI,EAAE,GADE;AAERC,MAAAA,GAAG,EAAE,WAFG;AAGRC,MAAAA,OAAO,EAAE,GAHD;AAIRC,MAAAA,OAAO,EAAE,GAJD;AAKR,SAAGJ;AALK,KAAV;AAQA,SAAKK,iBAAL,GAAyB,IAAIV,2BAAJ,EAAzB;AASA,SAAKW,GAAL,GAAWN,OAAO,CAACM,GAAnB;AACA,SAAKC,IAAL,GAAYC,SAAZ;AACA,SAAKC,KAAL,GAAaD,SAAb;AAEA,SAAKE,eAAL,GAAuBF,SAAvB;AAOA,SAAKG,WAAL,GAAmBX,OAAO,CAACW,WAA3B;AACA,SAAKC,YAAL,GAAoBJ,SAApB;AAOA,SAAKP,IAAL,GAAYD,OAAO,CAACC,IAApB;AACA,SAAKY,KAAL,GAAa,KAAKZ,IA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AA,CAAC,CAACK,GAAF,GAAQR,OAAO,CAACjC,IAAR,GAAeqC,IAAI,CAACG,GAAL,CAAS,MAAMP,OAAO,CAACzB,KAAvB,CAAvB;AACA4B,IAAAA,CAAC,CAACM,MAAF,GAAW,CAACN,CAAC,CAACK,GAAd;AACAL,IAAAA,CAAC,CAACO,KAAF,GAAUV,OAAO,CAACvB,WAAR,GAAsB0B,CAAC,CAACK,GAAlC;AACAL,IAAAA,CAAC,CAACQ,IAAF,GAAS,CAACR,CAAC,CAACO,KAAZ;AACAP,IAAAA,CAAC,CAACpC,IAAF,GAASiC,OAAO,CAACjC,IAAjB;AACAoC,IAAAA,CAAC,CAACnC,GAAF,GAAQgC,OAAO,CAAChC,GAAhB;AAEAmC,IAAAA,CAAC,CAACO,KAAF,IAAWV,OAAO,CAAC/B,OAAnB;AACAkC,IAAAA,CAAC,CAACQ,IAAF,IAAUX,OAAO,CAAC/B,OAAlB;AACAkC,IAAAA,CAAC,CAACK,GAAF,IAASR,OAAO,CAAC9B,OAAjB;AACAiC,IAAAA,CAAC,CAACM,MAAF,IAAYT,OAAO,CAAC9B,OAApB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {assert} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.\n * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {Number} [options.near=1.0] The distance of the near plane.\n * @param {Number} [options.far=500000000.0] The distance of the far plane.\n * @param {Number} [options.xOffset=0.0] The offset in the x direction.\n * @param {Number} [options.yOffset=0.0] The offset in the y direction.\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n constructor(options = {}) {\n options = {\n near: 1.0,\n far: 500000000.0,\n xOffset: 0.0,\n yOffset: 0.0,\n ...options\n };\n\n this._offCenterFrustum = new PerspectiveOffCenterFrustum();\n\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 * @type {Number}\n * @default undefined\n */\n this.fov = options.fov;\n this._fov = undefined;\n this._fovy = undefined;\n\n this._sseDenominator = undefined;\n\n /**\n * The aspect ratio of the frustum's width to it's height.\n * @type {Number}\n * @default undefined\n */\n this.aspectRatio = options.aspectRatio;\n this._aspectRatio = 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 * Offsets the frustum in the x direction.\n * @type {Number}\n * @default 0.0\n */\n this.xOffset = options.xOffset;\n this._xOffset = this.xOffset;\n\n /**\n * Offsets the frustum in the y direction.\n * @type {Number}\n * @default 0.0\n */\n this.yOffset = options.yOffset;\n this._yOffset = this.yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n *\n * @param {PerspectiveFrustum} [result] The object onto which to store the result.\n * @returns {PerspectiveFrustum} The modified result parameter or a new PerspectiveFrustum instance if one was not provided.\n */\n clone() {\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 * @param {PerspectiveFrustum} [other] The right hand side PerspectiveFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveFrustum.prototype\n * @type {Matrix4}\n * @readonly\n */\n get projectionMatrix() {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveFrustum.prototype\n * @type {Matrix4}\n * @readonly\n *\n * @see PerspectiveFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix() {\n update(this);\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n * @memberof PerspectiveFrustum.prototype\n * @type {Number}\n * @readonly\n * @default undefined\n */\n get fovy() {\n update(this);\n return this._fovy;\n }\n\n /**\n * @readonly\n * @private\n */\n get sseDenominator() {\n update(this);\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(position, direction, up) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result\n );\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.fov) &&\n Number.isFinite(frustum.aspectRatio) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.fov !== frustum._fov ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far ||\n frustum.xOffset !== frustum._xOffset ||\n frustum.yOffset !== frustum._yOffset\n ) {\n assert(frustum.fov >= 0 && frustum.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(frustum.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(frustum.near >= 0 && frustum.near < frustum.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._fov = frustum.fov;\n frustum._fovy =\n frustum.aspectRatio <= 1\n ? frustum.fov\n : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);\n frustum._xOffset = frustum.xOffset;\n frustum._yOffset = frustum.yOffset;\n\n f.top = frustum.near * Math.tan(0.5 * frustum._fovy);\n f.bottom = -f.top;\n f.right = frustum.aspectRatio * f.top;\n f.left = -f.right;\n f.near = frustum.near;\n f.far = frustum.far;\n\n f.right += frustum.xOffset;\n f.left += frustum.xOffset;\n f.top += frustum.yOffset;\n f.bottom += frustum.yOffset;\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["assert","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","near","far","xOffset","yOffset","fov","aspectRatio","_near","_far","_xOffset","_yOffset","clone","equals","other","update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","frustum","Number","isFinite","f","_fov","_aspectRatio","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AASA,SAAQA,MAAR,QAA8B,eAA9B;AACA,OAAOC,2BAAP,MAAwC,kCAAxC;;AAEA,MAAMC,OAAO,GAAIC,GAAD,IAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,K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;AACA8B,IAAAA,CAAC,CAACQ,MAAF,IAAYX,OAAO,CAAC3B,OAApB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {assert, Matrix4} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.\n * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {Number} [options.near=1.0] The distance of the near plane.\n * @param {Number} [options.far=500000000.0] The distance of the far plane.\n * @param {Number} [options.xOffset=0.0] The offset in the x direction.\n * @param {Number} [options.yOffset=0.0] The offset in the y direction.\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov: number;\n _fov;\n _fovy;\n _sseDenominator;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio: number;\n _aspectRatio;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n _near;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n _far;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n _xOffset;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n _yOffset;\n\n constructor(options: Record<string, any> = {}) {\n options = {\n near: 1.0,\n far: 500000000.0,\n xOffset: 0.0,\n yOffset: 0.0,\n ...options\n };\n\n this.fov = options.fov;\n\n this.aspectRatio = options.aspectRatio;\n\n this.near = options.near;\n this._near = this.near;\n\n this.far = options.far;\n this._far = this.far;\n\n this.xOffset = options.xOffset;\n this._xOffset = this.xOffset;\n\n this.yOffset = options.yOffset;\n this._yOffset = this.yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n */\n get projectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n update(this);\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n update(this);\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(position, direction, up) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result\n );\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.fov) &&\n Number.isFinite(frustum.aspectRatio) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.fov !== frustum._fov ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far ||\n frustum.xOffset !== frustum._xOffset ||\n frustum.yOffset !== frustum._yOffset\n ) {\n assert(frustum.fov >= 0 && frustum.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(frustum.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(frustum.near >= 0 && frustum.near < frustum.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._fov = frustum.fov;\n frustum._fovy =\n frustum.aspectRatio <= 1\n ? frustum.fov\n : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);\n frustum._xOffset = frustum.xOffset;\n frustum._yOffset = frustum.yOffset;\n\n f.top = frustum.near * Math.tan(0.5 * frustum._fovy);\n f.bottom = -f.top;\n f.right = frustum.aspectRatio * f.top;\n f.left = -f.right;\n f.near = frustum.near;\n f.far = frustum.far;\n\n f.right += frustum.xOffset;\n f.left += frustum.xOffset;\n f.top += frustum.yOffset;\n f.bottom += frustum.yOffset;\n }\n}\n"],"file":"perspective-frustum.js"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import { Vector3, Matrix4, assert } from '@math.gl/core';
|
|
2
3
|
import CullingVolume from './culling-volume';
|
|
3
4
|
import Plane from './plane';
|
|
@@ -8,6 +9,36 @@ const scratchPlaneFarCenter = new Vector3();
|
|
|
8
9
|
const scratchPlaneNormal = new Vector3();
|
|
9
10
|
export default class PerspectiveOffCenterFrustum {
|
|
10
11
|
constructor(options = {}) {
|
|
12
|
+
_defineProperty(this, "left", void 0);
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "_left", void 0);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "right", void 0);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "_right", void 0);
|
|
19
|
+
|
|
20
|
+
_defineProperty(this, "top", void 0);
|
|
21
|
+
|
|
22
|
+
_defineProperty(this, "_top", void 0);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "bottom", void 0);
|
|
25
|
+
|
|
26
|
+
_defineProperty(this, "_bottom", void 0);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "near", void 0);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "_near", void 0);
|
|
31
|
+
|
|
32
|
+
_defineProperty(this, "far", void 0);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "_far", void 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "_cullingVolume", new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]));
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "_perspectiveMatrix", new Matrix4());
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "_infinitePerspective", new Matrix4());
|
|
41
|
+
|
|
11
42
|
options = {
|
|
12
43
|
near: 1.0,
|
|
13
44
|
far: 500000000.0,
|
|
@@ -25,9 +56,6 @@ export default class PerspectiveOffCenterFrustum {
|
|
|
25
56
|
this._near = this.near;
|
|
26
57
|
this.far = options.far;
|
|
27
58
|
this._far = this.far;
|
|
28
|
-
this._cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
|
|
29
|
-
this._perspectiveMatrix = new Matrix4();
|
|
30
|
-
this._infinitePerspective = new Matrix4();
|
|
31
59
|
}
|
|
32
60
|
|
|
33
61
|
clone() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.js"],"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","_cullingVolume","_perspectiveMatrix","_infinitePerspective","clone","equals","other","projectionMatrix","update","infiniteProjectionMatrix","computeCullingVolume","position","direction","up","planes","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,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,MAA1B,QAAuC,eAAvC;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,OAAOC,KAAP,MAAkB,SAAlB;AAEA,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;AAEA,eAAe,MAAMU,2BAAN,CAAkC;AA8B/CC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxBA,IAAAA,OAAO,GAAG;AAACC,MAAAA,IAAI,EAAE,GAAP;AAAYC,MAAAA,GAAG,EAAE,WAAjB;AAA8B,SAAGF;AAAjC,KAAV;AAOA,SAAKG,IAAL,GAAYH,OAAO,CAACG,IAApB;AACA,SAAKC,KAAL,GAAaC,SAAb;AAOA,SAAKC,KAAL,GAAaN,OAAO,CAACM,KAArB;AACA,SAAKC,MAAL,GAAcF,SAA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oBAAR,GAA+B,IAAI3B,OAAJ,GAAc+D,OAAd,CAAsB;AACnDjD,MAAAA,IADmD;AAEnDG,MAAAA,KAFmD;AAGnDI,MAAAA,MAHmD;AAInDF,MAAAA,GAJmD;AAKnDP,MAAAA,IALmD;AAMnDC,MAAAA,GAAG,EAAEmD;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":["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","drawing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,OADnB,IAEAR,IAAI,KAAKiD,OAAO,CAAChD,KAFjB,IAGAE,KAAK,KAAK8C,OAAO,CAAC7C,MAHlB,IAIAN,IAAI,KAAKmD,OAAO,CAACxC,KAJjB,IAKAV,GAAG,KAAKkD,OAAO,CAACvC,IANlB,EAOE;AACAvB,IAAAA,MAAM,CACJ8D,OAAO,CAACnD,IAAR,GAAe,CAAf,IAAoBmD,OAAO,CAACnD,IAAR,GAAemD,OAAO,CAAClD,GADvC,EAEJ,mDAFI,CAAN;AAKAkD,IAAAA,OAAO,CAAChD,KAAR,GAAgBD,IAAhB;AACAiD,IAAAA,OAAO,CAAC7C,MAAR,GAAiBD,KAAjB;AACA8C,IAAAA,OAAO,CAAC3C,IAAR,GAAeD,GAAf;AACA4C,IAAAA,OAAO,CAACzC,OAAR,GAAkBD,MAAlB;AACA0C,IAAAA,OAAO,CAACxC,KAAR,GAAgBX,IAAhB;AACAmD,IAAAA,OAAO,CAACvC,IAAR,GAAeX,GAAf;AACAkD,IAAAA,OAAO,CAACjC,kBAAR,GAA6B,IAAI9B,OAAJ,GAAc+D,OAAd,CAAsB;AACjDjD,MAAAA,IADiD;AAEjDG,MAAAA,KAFiD;AAGjDI,MAAAA,MAHiD;AAIjDF,MAAAA,GAJiD;AAKjDP,MAAAA,IALiD;AAMjDC,MAAAA;AANiD,KAAtB,CAA7B;AAQAkD,IAAAA,OAAO,CAAC/B,oBAAR,GAA+B,IAAIhC,OAAJ,GAAc+D,OAAd,CAAsB;AACnDjD,MAAAA,IADmD;AAEnDG,MAAAA,KAFmD;AAGnDI,MAAAA,MAHmD;AAInDF,MAAAA,GAJmD;AAKnDP,MAAAA,IALmD;AAMnDC,MAAAA,GAAG,EAAEmD;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 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/esm/lib/plane.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
2
|
import { Vector3, equals, assert } from '@math.gl/core';
|
|
2
3
|
const scratchPosition = new Vector3();
|
|
3
4
|
const scratchNormal = new Vector3();
|
|
4
5
|
export default class Plane {
|
|
5
6
|
constructor(normal = [0, 0, 1], distance = 0) {
|
|
7
|
+
_defineProperty(this, "normal", void 0);
|
|
8
|
+
|
|
9
|
+
_defineProperty(this, "distance", void 0);
|
|
10
|
+
|
|
6
11
|
this.normal = new Vector3();
|
|
7
12
|
this.distance = -0;
|
|
8
13
|
this.fromNormalDistance(normal, distance);
|
|
@@ -30,7 +35,7 @@ export default class Plane {
|
|
|
30
35
|
return this;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
clone(
|
|
38
|
+
clone() {
|
|
34
39
|
return new Plane(this.normal, this.distance);
|
|
35
40
|
}
|
|
36
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/plane.
|
|
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","pointDistance","scaledNormal","subtract","to"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,EAAyBC,MAAzB,QAAsC,eAAtC;AAEA,MAAMC,eAAe,GAAG,IAAIH,OAAJ,EAAxB;AACA,MAAMI,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAGA,eAAe,MAAMK,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,IAAIP,OAAJ,EAAd;AACA,SAAKQ,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;AAGDC,EAAAA,kBAAkB,CAACF,MAAD,EAA4BC,QAA5B,EAAoD;AACpEN,IAAAA,MAAM,CAACQ,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAD,CAAN;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,GAAGZ,eAAe,CAACS,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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EAA4B;AAC/ClB,IAAAA,KAAK,GAAGZ,eAAe,CAACS,IAAhB,CAAqBG,KAArB,CAAR;AAEA,UAAMmB,aAAa,GAAG,KAAKR,gBAAL,CAAsBX,KAAtB,CAAtB;AACA,UAAMoB,YAAY,GAAG/B,aAAa,CAACyB,IAAd,CAAmB,KAAKtB,MAAxB,EAAgCwB,KAAhC,CAAsCG,aAAtC,CAArB;AAEA,WAAOnB,KAAK,CAACqB,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/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { INTERSECTION } from './constants';
|
|
2
|
+
export { default as AxisAlignedBoundingBox } from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
3
|
+
export { default as BoundingSphere } from './lib/bounding-volumes/bounding-sphere';
|
|
4
|
+
export { default as OrientedBoundingBox } from './lib/bounding-volumes/oriented-bounding-box';
|
|
5
|
+
export { default as CullingVolume } from './lib/culling-volume';
|
|
6
|
+
export { default as Plane } from './lib/plane';
|
|
7
|
+
export { default as _PerspectiveOffCenterFrustum } from './lib/perspective-off-center-frustum';
|
|
8
|
+
export { default as _PerspectiveFrustum } from './lib/perspective-frustum';
|
|
9
|
+
export { default as makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
|
|
10
|
+
export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './lib/algorithms/bounding-box-from-points';
|
|
11
|
+
export { default as computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,OAAO,IAAI,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACnG,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,KAAK,EAAC,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAEzE,OAAO,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,8CAA8C,CAAC;AACrG,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAC,OAAO,IAAI,yBAAyB,EAAC,MAAM,8CAA8C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export { INTERSECTION } from './constants';
|
|
4
|
+
export { default as AxisAlignedBoundingBox } from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
5
|
+
export { default as BoundingSphere } from './lib/bounding-volumes/bounding-sphere';
|
|
6
|
+
export { default as OrientedBoundingBox } from './lib/bounding-volumes/oriented-bounding-box';
|
|
7
|
+
export { default as CullingVolume } from './lib/culling-volume';
|
|
8
|
+
export { default as Plane } from './lib/plane';
|
|
9
|
+
export { default as _PerspectiveOffCenterFrustum } from './lib/perspective-off-center-frustum';
|
|
10
|
+
export { default as _PerspectiveFrustum } from './lib/perspective-frustum';
|
|
11
|
+
export { default as makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
|
|
12
|
+
export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './lib/algorithms/bounding-box-from-points';
|
|
13
|
+
export { default as computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
|
|
2
2
|
import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Computes an instance of an OrientedBoundingBox of the given positions.
|
|
6
5
|
*
|
|
7
6
|
* This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
|
|
8
7
|
* Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
|
|
9
8
|
*/
|
|
10
|
-
export function makeOrientedBoundingBoxFromPoints(
|
|
11
|
-
positions: number[][],
|
|
12
|
-
result?: OrientedBoundingBox
|
|
13
|
-
): OrientedBoundingBox;
|
|
14
|
-
|
|
9
|
+
export declare function makeOrientedBoundingBoxFromPoints(positions: number[][], result?: OrientedBoundingBox): OrientedBoundingBox;
|
|
15
10
|
/**
|
|
16
11
|
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
|
|
17
12
|
* finding the points spaced the farthest apart on the x, y, and z axes.
|
|
18
13
|
*/
|
|
19
|
-
export function makeAxisAlignedBoundingBoxFromPoints(
|
|
20
|
-
|
|
21
|
-
result?: AxisAlignedBoundingBox
|
|
22
|
-
): AxisAlignedBoundingBox;
|
|
14
|
+
export declare function makeAxisAlignedBoundingBoxFromPoints(positions: readonly number[][], result?: AxisAlignedBoundingBox): AxisAlignedBoundingBox;
|
|
15
|
+
//# sourceMappingURL=bounding-box-from-points.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounding-box-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":[],"mappings":"AAKA,OAAO,mBAAmB,MAAM,2CAA2C,CAAC;AAC5E,OAAO,sBAAsB,MAAM,+CAA+C,CAAC;AAmBnF;;;;;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"}
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
import { Vector3, Matrix3 } from '@math.gl/core';
|
|
4
|
+
import computeEigenDecomposition from './compute-eigen-decomposition';
|
|
5
|
+
import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
|
|
6
|
+
import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
|
|
7
|
+
const scratchVector2 = new Vector3();
|
|
8
|
+
const scratchVector3 = new Vector3();
|
|
9
|
+
const scratchVector4 = new Vector3();
|
|
10
|
+
const scratchVector5 = new Vector3();
|
|
11
|
+
const scratchVector6 = new Vector3();
|
|
12
|
+
const scratchCovarianceResult = new Matrix3();
|
|
13
|
+
const scratchEigenResult = {
|
|
14
|
+
diagonal: new Matrix3(),
|
|
15
|
+
unitary: new Matrix3()
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Computes an instance of an OrientedBoundingBox of the given positions.
|
|
19
|
+
*
|
|
20
|
+
* This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
|
|
21
|
+
* Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
|
|
22
|
+
*/
|
|
23
|
+
/* eslint-disable max-statements */
|
|
24
|
+
export function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
|
|
25
|
+
if (!positions || positions.length === 0) {
|
|
26
|
+
result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
27
|
+
result.center = new Vector3();
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const length = positions.length;
|
|
31
|
+
const meanPoint = new Vector3(0, 0, 0);
|
|
32
|
+
for (const position of positions) {
|
|
33
|
+
meanPoint.add(position);
|
|
34
|
+
}
|
|
35
|
+
const invLength = 1.0 / length;
|
|
36
|
+
meanPoint.multiplyByScalar(invLength);
|
|
37
|
+
let exx = 0.0;
|
|
38
|
+
let exy = 0.0;
|
|
39
|
+
let exz = 0.0;
|
|
40
|
+
let eyy = 0.0;
|
|
41
|
+
let eyz = 0.0;
|
|
42
|
+
let ezz = 0.0;
|
|
43
|
+
for (const position of positions) {
|
|
44
|
+
const p = scratchVector2.copy(position).subtract(meanPoint);
|
|
45
|
+
exx += p.x * p.x;
|
|
46
|
+
exy += p.x * p.y;
|
|
47
|
+
exz += p.x * p.z;
|
|
48
|
+
eyy += p.y * p.y;
|
|
49
|
+
eyz += p.y * p.z;
|
|
50
|
+
ezz += p.z * p.z;
|
|
51
|
+
}
|
|
52
|
+
exx *= invLength;
|
|
53
|
+
exy *= invLength;
|
|
54
|
+
exz *= invLength;
|
|
55
|
+
eyy *= invLength;
|
|
56
|
+
eyz *= invLength;
|
|
57
|
+
ezz *= invLength;
|
|
58
|
+
const covarianceMatrix = scratchCovarianceResult;
|
|
59
|
+
covarianceMatrix[0] = exx;
|
|
60
|
+
covarianceMatrix[1] = exy;
|
|
61
|
+
covarianceMatrix[2] = exz;
|
|
62
|
+
covarianceMatrix[3] = exy;
|
|
63
|
+
covarianceMatrix[4] = eyy;
|
|
64
|
+
covarianceMatrix[5] = eyz;
|
|
65
|
+
covarianceMatrix[6] = exz;
|
|
66
|
+
covarianceMatrix[7] = eyz;
|
|
67
|
+
covarianceMatrix[8] = ezz;
|
|
68
|
+
const { unitary } = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
|
|
69
|
+
const rotation = result.halfAxes.copy(unitary);
|
|
70
|
+
let v1 = rotation.getColumn(0, scratchVector4);
|
|
71
|
+
let v2 = rotation.getColumn(1, scratchVector5);
|
|
72
|
+
let v3 = rotation.getColumn(2, scratchVector6);
|
|
73
|
+
let u1 = -Number.MAX_VALUE;
|
|
74
|
+
let u2 = -Number.MAX_VALUE;
|
|
75
|
+
let u3 = -Number.MAX_VALUE;
|
|
76
|
+
let l1 = Number.MAX_VALUE;
|
|
77
|
+
let l2 = Number.MAX_VALUE;
|
|
78
|
+
let l3 = Number.MAX_VALUE;
|
|
79
|
+
for (const position of positions) {
|
|
80
|
+
scratchVector2.copy(position);
|
|
81
|
+
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
82
|
+
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
83
|
+
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
84
|
+
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
85
|
+
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
86
|
+
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
87
|
+
}
|
|
88
|
+
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
89
|
+
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
90
|
+
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
91
|
+
result.center.copy(v1).add(v2).add(v3);
|
|
92
|
+
const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
93
|
+
const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
94
|
+
result.halfAxes.multiplyRight(scaleMatrix);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
|
|
99
|
+
* finding the points spaced the farthest apart on the x, y, and z axes.
|
|
100
|
+
*/
|
|
101
|
+
export function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAlignedBoundingBox()) {
|
|
102
|
+
if (!positions || positions.length === 0) {
|
|
103
|
+
result.minimum.set(0, 0, 0);
|
|
104
|
+
result.maximum.set(0, 0, 0);
|
|
105
|
+
result.center.set(0, 0, 0);
|
|
106
|
+
result.halfDiagonal.set(0, 0, 0);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
let minimumX = positions[0][0];
|
|
110
|
+
let minimumY = positions[0][1];
|
|
111
|
+
let minimumZ = positions[0][2];
|
|
112
|
+
let maximumX = positions[0][0];
|
|
113
|
+
let maximumY = positions[0][1];
|
|
114
|
+
let maximumZ = positions[0][2];
|
|
115
|
+
for (const p of positions) {
|
|
116
|
+
const x = p[0];
|
|
117
|
+
const y = p[1];
|
|
118
|
+
const z = p[2];
|
|
119
|
+
minimumX = Math.min(x, minimumX);
|
|
120
|
+
maximumX = Math.max(x, maximumX);
|
|
121
|
+
minimumY = Math.min(y, minimumY);
|
|
122
|
+
maximumY = Math.max(y, maximumY);
|
|
123
|
+
minimumZ = Math.min(z, minimumZ);
|
|
124
|
+
maximumZ = Math.max(z, maximumZ);
|
|
125
|
+
}
|
|
126
|
+
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
127
|
+
result.maximum.set(maximumX, maximumY, maximumZ);
|
|
128
|
+
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
|
|
129
|
+
result.halfDiagonal.copy(result.maximum).subtract(result.center);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import BoundingSphere from '../bounding-volumes/bounding-sphere';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
|
|
5
4
|
*
|
|
@@ -11,7 +10,5 @@ import BoundingSphere from '../bounding-volumes/bounding-sphere';
|
|
|
11
10
|
* @param result Optional object onto which to store the result.
|
|
12
11
|
* @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
|
|
13
12
|
*/
|
|
14
|
-
export default function makeBoundingSphereFromPoints(
|
|
15
|
-
|
|
16
|
-
result?: BoundingSphere
|
|
17
|
-
): BoundingSphere;
|
|
13
|
+
export default function makeBoundingSphereFromPoints(positions: number[][], result?: BoundingSphere): BoundingSphere;
|
|
14
|
+
//# sourceMappingURL=bounding-sphere-from-points.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounding-sphere-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,qCAAqC,CAAC;AAiBjE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAClD,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,cAAqC,GAC5C,cAAc,CAqIhB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
import { Vector3 } from '@math.gl/core';
|
|
4
|
+
import BoundingSphere from '../bounding-volumes/bounding-sphere';
|
|
5
|
+
/* eslint-disable */
|
|
6
|
+
const fromPointsXMin = new Vector3();
|
|
7
|
+
const fromPointsYMin = new Vector3();
|
|
8
|
+
const fromPointsZMin = new Vector3();
|
|
9
|
+
const fromPointsXMax = new Vector3();
|
|
10
|
+
const fromPointsYMax = new Vector3();
|
|
11
|
+
const fromPointsZMax = new Vector3();
|
|
12
|
+
const fromPointsCurrentPos = new Vector3();
|
|
13
|
+
const fromPointsScratch = new Vector3();
|
|
14
|
+
const fromPointsRitterCenter = new Vector3();
|
|
15
|
+
const fromPointsMinBoxPt = new Vector3();
|
|
16
|
+
const fromPointsMaxBoxPt = new Vector3();
|
|
17
|
+
const fromPointsNaiveCenterScratch = new Vector3();
|
|
18
|
+
const volumeConstant = (4.0 / 3.0) * Math.PI;
|
|
19
|
+
/**
|
|
20
|
+
* Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
|
|
21
|
+
*
|
|
22
|
+
* The bounding sphere is computed by running two algorithms, a naive algorithm and
|
|
23
|
+
* Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
|
|
24
|
+
* Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding
|
|
25
|
+
*
|
|
26
|
+
* @param positions An array of points that the bounding sphere will enclose.
|
|
27
|
+
* @param result Optional object onto which to store the result.
|
|
28
|
+
* @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
|
|
29
|
+
*/
|
|
30
|
+
export default function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
|
|
31
|
+
if (!positions || positions.length === 0) {
|
|
32
|
+
return result.fromCenterRadius([0, 0, 0], 0);
|
|
33
|
+
}
|
|
34
|
+
const currentPos = fromPointsCurrentPos.copy(positions[0]);
|
|
35
|
+
const xMin = fromPointsXMin.copy(currentPos);
|
|
36
|
+
const yMin = fromPointsYMin.copy(currentPos);
|
|
37
|
+
const zMin = fromPointsZMin.copy(currentPos);
|
|
38
|
+
const xMax = fromPointsXMax.copy(currentPos);
|
|
39
|
+
const yMax = fromPointsYMax.copy(currentPos);
|
|
40
|
+
const zMax = fromPointsZMax.copy(currentPos);
|
|
41
|
+
for (const position of positions) {
|
|
42
|
+
currentPos.copy(position);
|
|
43
|
+
const x = currentPos.x;
|
|
44
|
+
const y = currentPos.y;
|
|
45
|
+
const z = currentPos.z;
|
|
46
|
+
// Store points containing the the smallest and largest components
|
|
47
|
+
if (x < xMin.x) {
|
|
48
|
+
xMin.copy(currentPos);
|
|
49
|
+
}
|
|
50
|
+
if (x > xMax.x) {
|
|
51
|
+
xMax.copy(currentPos);
|
|
52
|
+
}
|
|
53
|
+
if (y < yMin.y) {
|
|
54
|
+
yMin.copy(currentPos);
|
|
55
|
+
}
|
|
56
|
+
if (y > yMax.y) {
|
|
57
|
+
yMax.copy(currentPos);
|
|
58
|
+
}
|
|
59
|
+
if (z < zMin.z) {
|
|
60
|
+
zMin.copy(currentPos);
|
|
61
|
+
}
|
|
62
|
+
if (z > zMax.z) {
|
|
63
|
+
zMax.copy(currentPos);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
|
|
67
|
+
const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
|
|
68
|
+
const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
|
|
69
|
+
const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
|
|
70
|
+
// Set the diameter endpoints to the largest span.
|
|
71
|
+
let diameter1 = xMin;
|
|
72
|
+
let diameter2 = xMax;
|
|
73
|
+
let maxSpan = xSpan;
|
|
74
|
+
if (ySpan > maxSpan) {
|
|
75
|
+
maxSpan = ySpan;
|
|
76
|
+
diameter1 = yMin;
|
|
77
|
+
diameter2 = yMax;
|
|
78
|
+
}
|
|
79
|
+
if (zSpan > maxSpan) {
|
|
80
|
+
maxSpan = zSpan;
|
|
81
|
+
diameter1 = zMin;
|
|
82
|
+
diameter2 = zMax;
|
|
83
|
+
}
|
|
84
|
+
// Calculate the center of the initial sphere found by Ritter's algorithm
|
|
85
|
+
const ritterCenter = fromPointsRitterCenter;
|
|
86
|
+
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
|
|
87
|
+
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
|
|
88
|
+
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
|
|
89
|
+
// Calculate the radius of the initial sphere found by Ritter's algorithm
|
|
90
|
+
let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
|
|
91
|
+
let ritterRadius = Math.sqrt(radiusSquared);
|
|
92
|
+
// Find the center of the sphere found using the Naive method.
|
|
93
|
+
const minBoxPt = fromPointsMinBoxPt;
|
|
94
|
+
minBoxPt.x = xMin.x;
|
|
95
|
+
minBoxPt.y = yMin.y;
|
|
96
|
+
minBoxPt.z = zMin.z;
|
|
97
|
+
const maxBoxPt = fromPointsMaxBoxPt;
|
|
98
|
+
maxBoxPt.x = xMax.x;
|
|
99
|
+
maxBoxPt.y = yMax.y;
|
|
100
|
+
maxBoxPt.z = zMax.z;
|
|
101
|
+
const naiveCenter = fromPointsNaiveCenterScratch
|
|
102
|
+
.copy(minBoxPt)
|
|
103
|
+
.add(maxBoxPt)
|
|
104
|
+
.multiplyByScalar(0.5);
|
|
105
|
+
// Begin 2nd pass to find naive radius and modify the ritter sphere.
|
|
106
|
+
let naiveRadius = 0;
|
|
107
|
+
for (const position of positions) {
|
|
108
|
+
currentPos.copy(position);
|
|
109
|
+
// Find the furthest point from the naive center to calculate the naive radius.
|
|
110
|
+
const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
|
|
111
|
+
if (r > naiveRadius) {
|
|
112
|
+
naiveRadius = r;
|
|
113
|
+
}
|
|
114
|
+
// Make adjustments to the Ritter Sphere to include all points.
|
|
115
|
+
const oldCenterToPointSquared = fromPointsScratch
|
|
116
|
+
.copy(currentPos)
|
|
117
|
+
.subtract(ritterCenter)
|
|
118
|
+
.magnitudeSquared();
|
|
119
|
+
if (oldCenterToPointSquared > radiusSquared) {
|
|
120
|
+
const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
|
|
121
|
+
// Calculate new radius to include the point that lies outside
|
|
122
|
+
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
|
|
123
|
+
radiusSquared = ritterRadius * ritterRadius;
|
|
124
|
+
// Calculate center of new Ritter sphere
|
|
125
|
+
const oldToNew = oldCenterToPoint - ritterRadius;
|
|
126
|
+
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
|
|
127
|
+
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
|
|
128
|
+
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (ritterRadius < naiveRadius) {
|
|
132
|
+
ritterCenter.to(result.center);
|
|
133
|
+
result.radius = ritterRadius;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
naiveCenter.to(result.center);
|
|
137
|
+
result.radius = naiveRadius;
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|