@math.gl/culling 3.6.3 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm/constants.js → constants.js} +0 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +1049 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- 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/{esm/lib → lib}/algorithms/bounding-sphere-from-points.js +1 -2
- 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 +0 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/{esm/lib → lib}/bounding-volumes/axis-aligned-bounding-box.js +1 -1
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/bounding-sphere.js +1 -1
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -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
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +2 -2
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/oriented-bounding-box.js +2 -2
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/{esm/lib → lib}/culling-volume.js +2 -5
- package/dist/lib/culling-volume.js.map +1 -0
- package/dist/lib/perspective-frustum.d.ts +1 -1
- package/dist/lib/perspective-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-frustum.js +1 -1
- package/dist/lib/perspective-frustum.js.map +1 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +1 -1
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-off-center-frustum.js +2 -2
- package/dist/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/{esm/lib → lib}/plane.js +3 -3
- package/dist/lib/plane.js.map +1 -0
- package/package.json +7 -6
- package/src/lib/algorithms/bounding-sphere-from-points.ts +1 -1
- package/src/lib/bounding-volumes/bounding-sphere.ts +2 -0
- package/src/lib/bounding-volumes/bounding-volume.ts +1 -1
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +5 -2
- package/src/lib/culling-volume.ts +3 -3
- package/src/lib/perspective-frustum.ts +1 -1
- package/src/lib/plane.ts +4 -4
- 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/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.1",
|
|
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.1",
|
|
40
|
+
"gl-matrix": "^3.4.3"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "66f872ea615a3ef81431595727cdf58dcadf3670"
|
|
42
43
|
}
|
|
@@ -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.
|
|
@@ -2,7 +2,9 @@
|
|
|
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
10
|
import Plane from '../plane';
|
|
@@ -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
|
}
|
|
@@ -13,7 +13,7 @@ const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0
|
|
|
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
19
|
export default class CullingVolume {
|
|
@@ -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
|
|
|
@@ -9,7 +9,7 @@ import {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';
|
|
|
9
9
|
import PerspectiveOffCenterFrustum from './perspective-off-center-frustum';
|
|
10
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. */
|
package/src/lib/plane.ts
CHANGED
|
@@ -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"}
|
package/dist/es5/index.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports, "INTERSECTION", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _constants.INTERSECTION;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "AxisAlignedBoundingBox", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function get() {
|
|
17
|
-
return _axisAlignedBoundingBox.default;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, "BoundingSphere", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function get() {
|
|
23
|
-
return _boundingSphere.default;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, "OrientedBoundingBox", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function get() {
|
|
29
|
-
return _orientedBoundingBox.default;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports, "CullingVolume", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function get() {
|
|
35
|
-
return _cullingVolume.default;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(exports, "Plane", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function get() {
|
|
41
|
-
return _plane.default;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "_PerspectiveOffCenterFrustum", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function get() {
|
|
47
|
-
return _perspectiveOffCenterFrustum.default;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, "_PerspectiveFrustum", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function get() {
|
|
53
|
-
return _perspectiveFrustum.default;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, "makeBoundingSphereFromPoints", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function get() {
|
|
59
|
-
return _boundingSphereFromPoints.default;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, "makeAxisAlignedBoundingBoxFromPoints", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function get() {
|
|
65
|
-
return _boundingBoxFromPoints.makeAxisAlignedBoundingBoxFromPoints;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, "makeOrientedBoundingBoxFromPoints", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function get() {
|
|
71
|
-
return _boundingBoxFromPoints.makeOrientedBoundingBoxFromPoints;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(exports, "computeEigenDecomposition", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
get: function get() {
|
|
77
|
-
return _computeEigenDecomposition.default;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
var _constants = require("./constants");
|
|
82
|
-
|
|
83
|
-
var _axisAlignedBoundingBox = _interopRequireDefault(require("./lib/bounding-volumes/axis-aligned-bounding-box"));
|
|
84
|
-
|
|
85
|
-
var _boundingSphere = _interopRequireDefault(require("./lib/bounding-volumes/bounding-sphere"));
|
|
86
|
-
|
|
87
|
-
var _orientedBoundingBox = _interopRequireDefault(require("./lib/bounding-volumes/oriented-bounding-box"));
|
|
88
|
-
|
|
89
|
-
var _cullingVolume = _interopRequireDefault(require("./lib/culling-volume"));
|
|
90
|
-
|
|
91
|
-
var _plane = _interopRequireDefault(require("./lib/plane"));
|
|
92
|
-
|
|
93
|
-
var _perspectiveOffCenterFrustum = _interopRequireDefault(require("./lib/perspective-off-center-frustum"));
|
|
94
|
-
|
|
95
|
-
var _perspectiveFrustum = _interopRequireDefault(require("./lib/perspective-frustum"));
|
|
96
|
-
|
|
97
|
-
var _boundingSphereFromPoints = _interopRequireDefault(require("./lib/algorithms/bounding-sphere-from-points"));
|
|
98
|
-
|
|
99
|
-
var _boundingBoxFromPoints = require("./lib/algorithms/bounding-box-from-points");
|
|
100
|
-
|
|
101
|
-
var _computeEigenDecomposition = _interopRequireDefault(require("./lib/algorithms/compute-eigen-decomposition"));
|
|
102
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AAIA","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nexport {INTERSECTION} from './constants';\n\nexport {default as AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {default as BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {default as OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {default as CullingVolume} from './lib/culling-volume';\nexport {default as Plane} from './lib/plane';\n\nexport {default as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {default as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {default as makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {default as computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.makeOrientedBoundingBoxFromPoints = makeOrientedBoundingBoxFromPoints;
|
|
9
|
-
exports.makeAxisAlignedBoundingBoxFromPoints = makeAxisAlignedBoundingBoxFromPoints;
|
|
10
|
-
|
|
11
|
-
var _core = require("@math.gl/core");
|
|
12
|
-
|
|
13
|
-
var _computeEigenDecomposition = _interopRequireDefault(require("./compute-eigen-decomposition"));
|
|
14
|
-
|
|
15
|
-
var _orientedBoundingBox = _interopRequireDefault(require("../bounding-volumes/oriented-bounding-box"));
|
|
16
|
-
|
|
17
|
-
var _axisAlignedBoundingBox = _interopRequireDefault(require("../bounding-volumes/axis-aligned-bounding-box"));
|
|
18
|
-
|
|
19
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
20
|
-
|
|
21
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
-
|
|
23
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
24
|
-
|
|
25
|
-
var scratchVector2 = new _core.Vector3();
|
|
26
|
-
var scratchVector3 = new _core.Vector3();
|
|
27
|
-
var scratchVector4 = new _core.Vector3();
|
|
28
|
-
var scratchVector5 = new _core.Vector3();
|
|
29
|
-
var scratchVector6 = new _core.Vector3();
|
|
30
|
-
var scratchCovarianceResult = new _core.Matrix3();
|
|
31
|
-
var scratchEigenResult = {
|
|
32
|
-
diagonal: new _core.Matrix3(),
|
|
33
|
-
unitary: new _core.Matrix3()
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function makeOrientedBoundingBoxFromPoints(positions) {
|
|
37
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _orientedBoundingBox.default();
|
|
38
|
-
|
|
39
|
-
if (!positions || positions.length === 0) {
|
|
40
|
-
result.halfAxes = new _core.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
41
|
-
result.center = new _core.Vector3();
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var length = positions.length;
|
|
46
|
-
var meanPoint = new _core.Vector3(0, 0, 0);
|
|
47
|
-
|
|
48
|
-
var _iterator = _createForOfIteratorHelper(positions),
|
|
49
|
-
_step;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
-
var position = _step.value;
|
|
54
|
-
meanPoint.add(position);
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
_iterator.e(err);
|
|
58
|
-
} finally {
|
|
59
|
-
_iterator.f();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var invLength = 1.0 / length;
|
|
63
|
-
meanPoint.multiplyByScalar(invLength);
|
|
64
|
-
var exx = 0.0;
|
|
65
|
-
var exy = 0.0;
|
|
66
|
-
var exz = 0.0;
|
|
67
|
-
var eyy = 0.0;
|
|
68
|
-
var eyz = 0.0;
|
|
69
|
-
var ezz = 0.0;
|
|
70
|
-
|
|
71
|
-
var _iterator2 = _createForOfIteratorHelper(positions),
|
|
72
|
-
_step2;
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
76
|
-
var _position = _step2.value;
|
|
77
|
-
var p = scratchVector2.copy(_position).subtract(meanPoint);
|
|
78
|
-
exx += p.x * p.x;
|
|
79
|
-
exy += p.x * p.y;
|
|
80
|
-
exz += p.x * p.z;
|
|
81
|
-
eyy += p.y * p.y;
|
|
82
|
-
eyz += p.y * p.z;
|
|
83
|
-
ezz += p.z * p.z;
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
_iterator2.e(err);
|
|
87
|
-
} finally {
|
|
88
|
-
_iterator2.f();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
exx *= invLength;
|
|
92
|
-
exy *= invLength;
|
|
93
|
-
exz *= invLength;
|
|
94
|
-
eyy *= invLength;
|
|
95
|
-
eyz *= invLength;
|
|
96
|
-
ezz *= invLength;
|
|
97
|
-
var covarianceMatrix = scratchCovarianceResult;
|
|
98
|
-
covarianceMatrix[0] = exx;
|
|
99
|
-
covarianceMatrix[1] = exy;
|
|
100
|
-
covarianceMatrix[2] = exz;
|
|
101
|
-
covarianceMatrix[3] = exy;
|
|
102
|
-
covarianceMatrix[4] = eyy;
|
|
103
|
-
covarianceMatrix[5] = eyz;
|
|
104
|
-
covarianceMatrix[6] = exz;
|
|
105
|
-
covarianceMatrix[7] = eyz;
|
|
106
|
-
covarianceMatrix[8] = ezz;
|
|
107
|
-
|
|
108
|
-
var _computeEigenDecompos = (0, _computeEigenDecomposition.default)(covarianceMatrix, scratchEigenResult),
|
|
109
|
-
unitary = _computeEigenDecompos.unitary;
|
|
110
|
-
|
|
111
|
-
var rotation = result.halfAxes.copy(unitary);
|
|
112
|
-
var v1 = rotation.getColumn(0, scratchVector4);
|
|
113
|
-
var v2 = rotation.getColumn(1, scratchVector5);
|
|
114
|
-
var v3 = rotation.getColumn(2, scratchVector6);
|
|
115
|
-
var u1 = -Number.MAX_VALUE;
|
|
116
|
-
var u2 = -Number.MAX_VALUE;
|
|
117
|
-
var u3 = -Number.MAX_VALUE;
|
|
118
|
-
var l1 = Number.MAX_VALUE;
|
|
119
|
-
var l2 = Number.MAX_VALUE;
|
|
120
|
-
var l3 = Number.MAX_VALUE;
|
|
121
|
-
|
|
122
|
-
var _iterator3 = _createForOfIteratorHelper(positions),
|
|
123
|
-
_step3;
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
127
|
-
var _position2 = _step3.value;
|
|
128
|
-
scratchVector2.copy(_position2);
|
|
129
|
-
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
130
|
-
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
131
|
-
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
132
|
-
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
133
|
-
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
134
|
-
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
135
|
-
}
|
|
136
|
-
} catch (err) {
|
|
137
|
-
_iterator3.e(err);
|
|
138
|
-
} finally {
|
|
139
|
-
_iterator3.f();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
143
|
-
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
144
|
-
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
145
|
-
result.center.copy(v1).add(v2).add(v3);
|
|
146
|
-
var scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
147
|
-
var scaleMatrix = new _core.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
148
|
-
result.halfAxes.multiplyRight(scaleMatrix);
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function makeAxisAlignedBoundingBoxFromPoints(positions) {
|
|
153
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _axisAlignedBoundingBox.default();
|
|
154
|
-
|
|
155
|
-
if (!positions || positions.length === 0) {
|
|
156
|
-
result.minimum.set(0, 0, 0);
|
|
157
|
-
result.maximum.set(0, 0, 0);
|
|
158
|
-
result.center.set(0, 0, 0);
|
|
159
|
-
result.halfDiagonal.set(0, 0, 0);
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var minimumX = positions[0][0];
|
|
164
|
-
var minimumY = positions[0][1];
|
|
165
|
-
var minimumZ = positions[0][2];
|
|
166
|
-
var maximumX = positions[0][0];
|
|
167
|
-
var maximumY = positions[0][1];
|
|
168
|
-
var maximumZ = positions[0][2];
|
|
169
|
-
|
|
170
|
-
var _iterator4 = _createForOfIteratorHelper(positions),
|
|
171
|
-
_step4;
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
175
|
-
var p = _step4.value;
|
|
176
|
-
var x = p[0];
|
|
177
|
-
var y = p[1];
|
|
178
|
-
var z = p[2];
|
|
179
|
-
minimumX = Math.min(x, minimumX);
|
|
180
|
-
maximumX = Math.max(x, maximumX);
|
|
181
|
-
minimumY = Math.min(y, minimumY);
|
|
182
|
-
maximumY = Math.max(y, maximumY);
|
|
183
|
-
minimumZ = Math.min(z, minimumZ);
|
|
184
|
-
maximumZ = Math.max(z, maximumZ);
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
_iterator4.e(err);
|
|
188
|
-
} finally {
|
|
189
|
-
_iterator4.f();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
193
|
-
result.maximum.set(maximumX, maximumY, maximumZ);
|
|
194
|
-
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
|
|
195
|
-
result.halfDiagonal.copy(result.maximum).subtract(result.center);
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=bounding-box-from-points.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":["scratchVector2","Vector3","scratchVector3","scratchVector4","scratchVector5","scratchVector6","scratchCovarianceResult","Matrix3","scratchEigenResult","diagonal","unitary","makeOrientedBoundingBoxFromPoints","positions","result","OrientedBoundingBox","length","halfAxes","center","meanPoint","position","add","invLength","multiplyByScalar","exx","exy","exz","eyy","eyz","ezz","p","copy","subtract","x","y","z","covarianceMatrix","rotation","v1","getColumn","v2","v3","u1","Number","MAX_VALUE","u2","u3","l1","l2","l3","Math","max","dot","min","scale","set","scaleMatrix","multiplyRight","makeAxisAlignedBoundingBoxFromPoints","AxisAlignedBoundingBox","minimum","maximum","halfDiagonal","minimumX","minimumY","minimumZ","maximumX","maximumY","maximumZ"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AAEA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AAEA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AAEA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AAEA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AAEA,IAAMK,uBAAuB,GAAG,IAAIC,aAAJ,EAAhC;AAEA,IAAMC,kBAAkB,GAAG;AACzBC,EAAAA,QAAQ,EAAE,IAAIF,aAAJ,EADe;AAEzBG,EAAAA,OAAO,EAAE,IAAIH,aAAJ;AAFgB,CAA3B;;AAYO,SAASI,iCAAT,CACLC,SADK,EAGgB;AAAA,MADrBC,MACqB,uEADS,IAAIC,4BAAJ,EACT;;AACrB,MAAI,CAACF,SAAD,IAAcA,SAAS,CAACG,MAAV,KAAqB,CAAvC,EAA0C;AACxCF,IAAAA,MAAM,CAACG,QAAP,GAAkB,IAAIT,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAZ,CAAlB;AACAM,IAAAA,MAAM,CAACI,MAAP,GAAgB,IAAIhB,aAAJ,EAAhB;AACA,WAAOY,MAAP;AACD;;AAED,MAAME,MAAM,GAAGH,SAAS,CAACG,MAAzB;AACA,MAAMG,SAAS,GAAG,IAAIjB,aAAJ,CAAY,CAAZ,EAAe,CAAf,EAAkB,CAAlB,CAAlB;;AARqB,6CASEW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AP,CAAeN,GAAf,CAAmBW,QAAnB,EAA6BC,QAA7B,EAAuCC,QAAvC;AACAtD,EAAAA,MAAM,CAACI,MAAP,CAAca,IAAd,CAAmBjB,MAAM,CAAC8C,OAA1B,EAAmCvC,GAAnC,CAAuCP,MAAM,CAAC+C,OAA9C,EAAuDP,KAAvD,CAA6D,GAA7D;AACAxC,EAAAA,MAAM,CAACgD,YAAP,CAAoB/B,IAApB,CAAyBjB,MAAM,CAAC+C,OAAhC,EAAyC7B,QAAzC,CAAkDlB,MAAM,CAACI,MAAzD;AAEA,SAAOJ,MAAP;AACD","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\nimport {Vector3, Matrix3} from '@math.gl/core';\nimport computeEigenDecomposition from './compute-eigen-decomposition';\nimport OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';\nimport AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';\n\nconst scratchVector2 = new Vector3();\n\nconst scratchVector3 = new Vector3();\n\nconst scratchVector4 = new Vector3();\n\nconst scratchVector5 = new Vector3();\n\nconst scratchVector6 = new Vector3();\n\nconst scratchCovarianceResult = new Matrix3();\n\nconst scratchEigenResult = {\n diagonal: new Matrix3(),\n unitary: new Matrix3()\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n *\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n */\n/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(\n positions: number[][],\n result: OrientedBoundingBox = new OrientedBoundingBox()\n): OrientedBoundingBox {\n if (!positions || positions.length === 0) {\n result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);\n result.center = new Vector3();\n return result;\n }\n\n const length = positions.length;\n const meanPoint = new Vector3(0, 0, 0);\n for (const position of positions) {\n meanPoint.add(position);\n }\n const invLength = 1.0 / length;\n meanPoint.multiplyByScalar(invLength);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n\n for (const position of positions) {\n const p = scratchVector2.copy(position).subtract(meanPoint);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);\n const rotation = result.halfAxes.copy(unitary);\n\n let v1 = rotation.getColumn(0, scratchVector4);\n let v2 = rotation.getColumn(1, scratchVector5);\n let v3 = rotation.getColumn(2, scratchVector6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (const position of positions) {\n scratchVector2.copy(position);\n\n u1 = Math.max(scratchVector2.dot(v1), u1);\n u2 = Math.max(scratchVector2.dot(v2), u2);\n u3 = Math.max(scratchVector2.dot(v3), u3);\n\n l1 = Math.min(scratchVector2.dot(v1), l1);\n l2 = Math.min(scratchVector2.dot(v2), l2);\n l3 = Math.min(scratchVector2.dot(v3), l3);\n }\n\n v1 = v1.multiplyByScalar(0.5 * (l1 + u1));\n v2 = v2.multiplyByScalar(0.5 * (l2 + u2));\n v3 = v3.multiplyByScalar(0.5 * (l3 + u3));\n\n result.center.copy(v1).add(v2).add(v3);\n\n const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);\n const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);\n result.halfAxes.multiplyRight(scaleMatrix);\n\n return result;\n}\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n */\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions: readonly number[][],\n result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()\n): AxisAlignedBoundingBox {\n if (!positions || positions.length === 0) {\n result.minimum.set(0, 0, 0);\n result.maximum.set(0, 0, 0);\n result.center.set(0, 0, 0);\n result.halfDiagonal.set(0, 0, 0);\n return result;\n }\n\n let minimumX = positions[0][0];\n let minimumY = positions[0][1];\n let minimumZ = positions[0][2];\n\n let maximumX = positions[0][0];\n let maximumY = positions[0][1];\n let maximumZ = positions[0][2];\n\n for (const p of positions) {\n const x = p[0];\n const y = p[1];\n const z = p[2];\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n result.minimum.set(minimumX, minimumY, minimumZ);\n result.maximum.set(maximumX, maximumY, maximumZ);\n result.center.copy(result.minimum).add(result.maximum).scale(0.5);\n result.halfDiagonal.copy(result.maximum).subtract(result.center);\n\n return result;\n}\n"],"file":"bounding-box-from-points.js"}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = makeBoundingSphereFromPoints;
|
|
9
|
-
|
|
10
|
-
var _core = require("@math.gl/core");
|
|
11
|
-
|
|
12
|
-
var _boundingSphere = _interopRequireDefault(require("../bounding-volumes/bounding-sphere"));
|
|
13
|
-
|
|
14
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
15
|
-
|
|
16
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
-
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
-
|
|
20
|
-
var fromPointsXMin = new _core.Vector3();
|
|
21
|
-
var fromPointsYMin = new _core.Vector3();
|
|
22
|
-
var fromPointsZMin = new _core.Vector3();
|
|
23
|
-
var fromPointsXMax = new _core.Vector3();
|
|
24
|
-
var fromPointsYMax = new _core.Vector3();
|
|
25
|
-
var fromPointsZMax = new _core.Vector3();
|
|
26
|
-
var fromPointsCurrentPos = new _core.Vector3();
|
|
27
|
-
var fromPointsScratch = new _core.Vector3();
|
|
28
|
-
var fromPointsRitterCenter = new _core.Vector3();
|
|
29
|
-
var fromPointsMinBoxPt = new _core.Vector3();
|
|
30
|
-
var fromPointsMaxBoxPt = new _core.Vector3();
|
|
31
|
-
var fromPointsNaiveCenterScratch = new _core.Vector3();
|
|
32
|
-
var volumeConstant = 4.0 / 3.0 * Math.PI;
|
|
33
|
-
|
|
34
|
-
function makeBoundingSphereFromPoints(positions) {
|
|
35
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _boundingSphere.default();
|
|
36
|
-
|
|
37
|
-
if (!positions || positions.length === 0) {
|
|
38
|
-
return result.fromCenterRadius([0, 0, 0], 0);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var currentPos = fromPointsCurrentPos.copy(positions[0]);
|
|
42
|
-
var xMin = fromPointsXMin.copy(currentPos);
|
|
43
|
-
var yMin = fromPointsYMin.copy(currentPos);
|
|
44
|
-
var zMin = fromPointsZMin.copy(currentPos);
|
|
45
|
-
var xMax = fromPointsXMax.copy(currentPos);
|
|
46
|
-
var yMax = fromPointsYMax.copy(currentPos);
|
|
47
|
-
var zMax = fromPointsZMax.copy(currentPos);
|
|
48
|
-
|
|
49
|
-
var _iterator = _createForOfIteratorHelper(positions),
|
|
50
|
-
_step;
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
-
var position = _step.value;
|
|
55
|
-
currentPos.copy(position);
|
|
56
|
-
var x = currentPos.x;
|
|
57
|
-
var y = currentPos.y;
|
|
58
|
-
var z = currentPos.z;
|
|
59
|
-
|
|
60
|
-
if (x < xMin.x) {
|
|
61
|
-
xMin.copy(currentPos);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (x > xMax.x) {
|
|
65
|
-
xMax.copy(currentPos);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (y < yMin.y) {
|
|
69
|
-
yMin.copy(currentPos);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (y > yMax.y) {
|
|
73
|
-
yMax.copy(currentPos);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (z < zMin.z) {
|
|
77
|
-
zMin.copy(currentPos);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (z > zMax.z) {
|
|
81
|
-
zMax.copy(currentPos);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
_iterator.e(err);
|
|
86
|
-
} finally {
|
|
87
|
-
_iterator.f();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
|
|
91
|
-
var ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
|
|
92
|
-
var zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
|
|
93
|
-
var diameter1 = xMin;
|
|
94
|
-
var diameter2 = xMax;
|
|
95
|
-
var maxSpan = xSpan;
|
|
96
|
-
|
|
97
|
-
if (ySpan > maxSpan) {
|
|
98
|
-
maxSpan = ySpan;
|
|
99
|
-
diameter1 = yMin;
|
|
100
|
-
diameter2 = yMax;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (zSpan > maxSpan) {
|
|
104
|
-
maxSpan = zSpan;
|
|
105
|
-
diameter1 = zMin;
|
|
106
|
-
diameter2 = zMax;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var ritterCenter = fromPointsRitterCenter;
|
|
110
|
-
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
|
|
111
|
-
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
|
|
112
|
-
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
|
|
113
|
-
var radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
|
|
114
|
-
var ritterRadius = Math.sqrt(radiusSquared);
|
|
115
|
-
var minBoxPt = fromPointsMinBoxPt;
|
|
116
|
-
minBoxPt.x = xMin.x;
|
|
117
|
-
minBoxPt.y = yMin.y;
|
|
118
|
-
minBoxPt.z = zMin.z;
|
|
119
|
-
var maxBoxPt = fromPointsMaxBoxPt;
|
|
120
|
-
maxBoxPt.x = xMax.x;
|
|
121
|
-
maxBoxPt.y = yMax.y;
|
|
122
|
-
maxBoxPt.z = zMax.z;
|
|
123
|
-
var naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5);
|
|
124
|
-
var naiveRadius = 0;
|
|
125
|
-
|
|
126
|
-
var _iterator2 = _createForOfIteratorHelper(positions),
|
|
127
|
-
_step2;
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
131
|
-
var _position = _step2.value;
|
|
132
|
-
currentPos.copy(_position);
|
|
133
|
-
var r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
|
|
134
|
-
|
|
135
|
-
if (r > naiveRadius) {
|
|
136
|
-
naiveRadius = r;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared();
|
|
140
|
-
|
|
141
|
-
if (oldCenterToPointSquared > radiusSquared) {
|
|
142
|
-
var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
|
|
143
|
-
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
|
|
144
|
-
radiusSquared = ritterRadius * ritterRadius;
|
|
145
|
-
var oldToNew = oldCenterToPoint - ritterRadius;
|
|
146
|
-
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
|
|
147
|
-
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
|
|
148
|
-
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} catch (err) {
|
|
152
|
-
_iterator2.e(err);
|
|
153
|
-
} finally {
|
|
154
|
-
_iterator2.f();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (ritterRadius < naiveRadius) {
|
|
158
|
-
ritterCenter.to(result.center);
|
|
159
|
-
result.radius = ritterRadius;
|
|
160
|
-
} else {
|
|
161
|
-
naiveCenter.to(result.center);
|
|
162
|
-
result.radius = naiveRadius;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=bounding-sphere-from-points.js.map
|