@math.gl/culling 3.6.3 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +1049 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/bounding-box-from-points.js +3 -3
- package/dist/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +2 -2
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/bounding-sphere-from-points.js +2 -3
- package/dist/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/algorithms/compute-eigen-decomposition.js +1 -1
- package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -2
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/axis-aligned-bounding-box.js +2 -2
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -2
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/bounding-sphere.js +2 -2
- package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -1
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +5 -5
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/bounding-volumes/oriented-bounding-box.js +3 -3
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/lib/culling-volume.d.ts +3 -3
- package/dist/lib/culling-volume.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/culling-volume.js +3 -6
- package/dist/lib/culling-volume.js.map +1 -0
- package/dist/lib/perspective-frustum.d.ts +2 -2
- package/dist/lib/perspective-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-frustum.js +2 -2
- package/dist/lib/perspective-frustum.js.map +1 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +2 -2
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/perspective-off-center-frustum.js +3 -3
- package/dist/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/lib/plane.d.ts +1 -1
- package/dist/lib/plane.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/plane.js +4 -4
- package/dist/lib/plane.js.map +1 -0
- package/package.json +7 -6
- package/src/index.ts +9 -9
- package/src/lib/algorithms/bounding-box-from-points.ts +3 -3
- package/src/lib/algorithms/bounding-sphere-from-points.ts +3 -3
- package/src/lib/algorithms/compute-eigen-decomposition.ts +1 -1
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
- package/src/lib/bounding-volumes/bounding-sphere.ts +4 -2
- package/src/lib/bounding-volumes/bounding-volume.ts +2 -2
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +8 -5
- package/src/lib/culling-volume.ts +6 -6
- package/src/lib/perspective-frustum.ts +4 -4
- package/src/lib/perspective-off-center-frustum.ts +3 -3
- package/src/lib/plane.ts +5 -5
- package/dist/es5/constants.js +0 -13
- package/dist/es5/constants.js.map +0 -1
- package/dist/es5/index.js +0 -102
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +0 -198
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +0 -167
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +0 -114
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +0 -114
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +0 -148
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/es5/lib/bounding-volumes/bounding-volume.js +0 -2
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +0 -253
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/es5/lib/culling-volume.js +0 -154
- package/dist/es5/lib/culling-volume.js.map +0 -1
- package/dist/es5/lib/perspective-frustum.js +0 -161
- package/dist/es5/lib/perspective-frustum.js.map +0 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +0 -183
- package/dist/es5/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/es5/lib/plane.js +0 -94
- package/dist/es5/lib/plane.js.map +0 -1
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +0 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/bounding-volume.js.map +0 -1
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
- package/dist/esm/lib/culling-volume.js.map +0 -1
- package/dist/esm/lib/perspective-frustum.js.map +0 -1
- package/dist/esm/lib/perspective-off-center-frustum.js.map +0 -1
- package/dist/esm/lib/plane.js.map +0 -1
- /package/dist/{esm/constants.js → constants.js} +0 -0
- /package/dist/{esm/lib → lib}/bounding-volumes/bounding-volume.js +0 -0
- /package/dist/{es5/lib → lib}/bounding-volumes/bounding-volume.js.map +0 -0
|
@@ -1,114 +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 = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _core = require("@math.gl/core");
|
|
17
|
-
|
|
18
|
-
var _constants = require("../../constants");
|
|
19
|
-
|
|
20
|
-
var scratchVector = new _core.Vector3();
|
|
21
|
-
var scratchNormal = new _core.Vector3();
|
|
22
|
-
|
|
23
|
-
var AxisAlignedBoundingBox = function () {
|
|
24
|
-
function AxisAlignedBoundingBox() {
|
|
25
|
-
var minimum = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
|
|
26
|
-
var maximum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
|
|
27
|
-
var center = arguments.length > 2 ? arguments[2] : undefined;
|
|
28
|
-
(0, _classCallCheck2.default)(this, AxisAlignedBoundingBox);
|
|
29
|
-
(0, _defineProperty2.default)(this, "center", void 0);
|
|
30
|
-
(0, _defineProperty2.default)(this, "halfDiagonal", void 0);
|
|
31
|
-
(0, _defineProperty2.default)(this, "minimum", void 0);
|
|
32
|
-
(0, _defineProperty2.default)(this, "maximum", void 0);
|
|
33
|
-
center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
|
|
34
|
-
this.center = new _core.Vector3(center);
|
|
35
|
-
this.halfDiagonal = new _core.Vector3(maximum).subtract(this.center);
|
|
36
|
-
this.minimum = new _core.Vector3(minimum);
|
|
37
|
-
this.maximum = new _core.Vector3(maximum);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
(0, _createClass2.default)(AxisAlignedBoundingBox, [{
|
|
41
|
-
key: "clone",
|
|
42
|
-
value: function clone() {
|
|
43
|
-
return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "equals",
|
|
47
|
-
value: function equals(right) {
|
|
48
|
-
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "transform",
|
|
52
|
-
value: function transform(_transform) {
|
|
53
|
-
this.center.transformAsPoint(_transform);
|
|
54
|
-
this.halfDiagonal.transform(_transform);
|
|
55
|
-
this.minimum.transform(_transform);
|
|
56
|
-
this.maximum.transform(_transform);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
key: "intersectPlane",
|
|
61
|
-
value: function intersectPlane(plane) {
|
|
62
|
-
var halfDiagonal = this.halfDiagonal;
|
|
63
|
-
var normal = scratchNormal.from(plane.normal);
|
|
64
|
-
var e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
|
|
65
|
-
var s = this.center.dot(normal) + plane.distance;
|
|
66
|
-
|
|
67
|
-
if (s - e > 0) {
|
|
68
|
-
return _constants.INTERSECTION.INSIDE;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (s + e < 0) {
|
|
72
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return _constants.INTERSECTION.INTERSECTING;
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
key: "distanceTo",
|
|
79
|
-
value: function distanceTo(point) {
|
|
80
|
-
return Math.sqrt(this.distanceSquaredTo(point));
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "distanceSquaredTo",
|
|
84
|
-
value: function distanceSquaredTo(point) {
|
|
85
|
-
var offset = scratchVector.from(point).subtract(this.center);
|
|
86
|
-
var halfDiagonal = this.halfDiagonal;
|
|
87
|
-
var distanceSquared = 0.0;
|
|
88
|
-
var d;
|
|
89
|
-
d = Math.abs(offset.x) - halfDiagonal.x;
|
|
90
|
-
|
|
91
|
-
if (d > 0) {
|
|
92
|
-
distanceSquared += d * d;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
d = Math.abs(offset.y) - halfDiagonal.y;
|
|
96
|
-
|
|
97
|
-
if (d > 0) {
|
|
98
|
-
distanceSquared += d * d;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
d = Math.abs(offset.z) - halfDiagonal.z;
|
|
102
|
-
|
|
103
|
-
if (d > 0) {
|
|
104
|
-
distanceSquared += d * d;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return distanceSquared;
|
|
108
|
-
}
|
|
109
|
-
}]);
|
|
110
|
-
return AxisAlignedBoundingBox;
|
|
111
|
-
}();
|
|
112
|
-
|
|
113
|
-
exports.default = AxisAlignedBoundingBox;
|
|
114
|
-
//# sourceMappingURL=axis-aligned-bounding-box.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAQqBE,sB;AAgBnB,oCAIE;AAAA,QAHAC,OAGA,uEAH6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAG7B;AAAA,QAFAC,OAEA,uEAF6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAE7B;AAAA,QADAC,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIL,aAAJ,CAAYK,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIT,aAAJ,CAAYI,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;AAOA,SAAKF,OAAL,GAAe,IAAIH,aAAJ,CAAYG,OAAZ,CAAf;AAOA,SAAKC,OAAL,GAAe,IAAIJ,aAAJ,CAAYI,OAAZ,CAAf;AACD;;;;WAOD,iBAAgC;AAC9B,aAAO,IAAIF,sBAAJ,CAA2B,KAAKC,OAAhC,EAAyC,KAAKC,OAA9C,EAAuD,KAAKC,MAA5D,CAAP;AACD;;;WASD,gBAAOM,KAAP,EAA+C;AAC7C,aACE,SAASA,KAAT,IACCC,OAAO,CAACD,KAAD,CAAP,IAAkB,KAAKR,OAAL,CAAaU,MAAb,CAAoBF,KAAK,CAACR,OAA1B,CAAlB,IAAwD,KAAKC,OAAL,CAAaS,MAAb,CAAoBF,KAAK,CA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C,KAAKL,MAAxC,CAAf;AACA,UAAOI,YAAP,GAAuB,IAAvB,CAAOA,YAAP;AAEA,UAAI2B,eAAe,GAAG,GAAtB;AACA,UAAIC,CAAJ;AAEAA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBX,YAAY,CAACW,CAAtC;;AACA,UAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBd,YAAY,CAACc,CAAtC;;AACA,UAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBf,YAAY,CAACe,CAAtC;;AACA,UAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,aAAOD,eAAP;AACD","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): number {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.default = void 0;
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
-
|
|
18
|
-
var _core = require("@math.gl/core");
|
|
19
|
-
|
|
20
|
-
var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
|
|
21
|
-
|
|
22
|
-
var _constants = require("../../constants");
|
|
23
|
-
|
|
24
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
25
|
-
|
|
26
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
-
|
|
28
|
-
var scratchVector = new _core.Vector3();
|
|
29
|
-
var scratchVector2 = new _core.Vector3();
|
|
30
|
-
|
|
31
|
-
var BoundingSphere = function () {
|
|
32
|
-
function BoundingSphere() {
|
|
33
|
-
var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
|
|
34
|
-
var radius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
|
|
35
|
-
(0, _classCallCheck2.default)(this, BoundingSphere);
|
|
36
|
-
(0, _defineProperty2.default)(this, "center", void 0);
|
|
37
|
-
(0, _defineProperty2.default)(this, "radius", void 0);
|
|
38
|
-
this.radius = -0;
|
|
39
|
-
this.center = new _core.Vector3();
|
|
40
|
-
this.fromCenterRadius(center, radius);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
(0, _createClass2.default)(BoundingSphere, [{
|
|
44
|
-
key: "fromCenterRadius",
|
|
45
|
-
value: function fromCenterRadius(center, radius) {
|
|
46
|
-
this.center.from(center);
|
|
47
|
-
this.radius = radius;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "fromCornerPoints",
|
|
52
|
-
value: function fromCornerPoints(corner, oppositeCorner) {
|
|
53
|
-
oppositeCorner = scratchVector.from(oppositeCorner);
|
|
54
|
-
this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5);
|
|
55
|
-
this.radius = this.center.distance(oppositeCorner);
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "equals",
|
|
60
|
-
value: function equals(right) {
|
|
61
|
-
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "clone",
|
|
65
|
-
value: function clone() {
|
|
66
|
-
return new BoundingSphere(this.center, this.radius);
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "union",
|
|
70
|
-
value: function union(boundingSphere) {
|
|
71
|
-
var leftCenter = this.center;
|
|
72
|
-
var leftRadius = this.radius;
|
|
73
|
-
var rightCenter = boundingSphere.center;
|
|
74
|
-
var rightRadius = boundingSphere.radius;
|
|
75
|
-
var toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);
|
|
76
|
-
var centerSeparation = toRightCenter.magnitude();
|
|
77
|
-
|
|
78
|
-
if (leftRadius >= centerSeparation + rightRadius) {
|
|
79
|
-
return this.clone();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (rightRadius >= centerSeparation + leftRadius) {
|
|
83
|
-
return boundingSphere.clone();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
|
|
87
|
-
scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
|
|
88
|
-
this.center.copy(scratchVector2);
|
|
89
|
-
this.radius = halfDistanceBetweenTangentPoints;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "expand",
|
|
94
|
-
value: function expand(point) {
|
|
95
|
-
var scratchPoint = scratchVector.from(point);
|
|
96
|
-
var radius = scratchPoint.subtract(this.center).magnitude();
|
|
97
|
-
|
|
98
|
-
if (radius > this.radius) {
|
|
99
|
-
this.radius = radius;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
key: "transform",
|
|
106
|
-
value: function transform(_transform) {
|
|
107
|
-
this.center.transform(_transform);
|
|
108
|
-
var scale = mat4.getScaling(scratchVector, _transform);
|
|
109
|
-
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "distanceSquaredTo",
|
|
114
|
-
value: function distanceSquaredTo(point) {
|
|
115
|
-
var d = this.distanceTo(point);
|
|
116
|
-
return d * d;
|
|
117
|
-
}
|
|
118
|
-
}, {
|
|
119
|
-
key: "distanceTo",
|
|
120
|
-
value: function distanceTo(point) {
|
|
121
|
-
var scratchPoint = scratchVector.from(point);
|
|
122
|
-
var delta = scratchPoint.subtract(this.center);
|
|
123
|
-
return Math.max(0, delta.len() - this.radius);
|
|
124
|
-
}
|
|
125
|
-
}, {
|
|
126
|
-
key: "intersectPlane",
|
|
127
|
-
value: function intersectPlane(plane) {
|
|
128
|
-
var center = this.center;
|
|
129
|
-
var radius = this.radius;
|
|
130
|
-
var normal = plane.normal;
|
|
131
|
-
var distanceToPlane = normal.dot(center) + plane.distance;
|
|
132
|
-
|
|
133
|
-
if (distanceToPlane < -radius) {
|
|
134
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (distanceToPlane < radius) {
|
|
138
|
-
return _constants.INTERSECTION.INTERSECTING;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return _constants.INTERSECTION.INSIDE;
|
|
142
|
-
}
|
|
143
|
-
}]);
|
|
144
|
-
return BoundingSphere;
|
|
145
|
-
}();
|
|
146
|
-
|
|
147
|
-
exports.default = BoundingSphere;
|
|
148
|
-
//# sourceMappingURL=bounding-sphere.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["scratchVector","Vector3","scratchVector2","BoundingSphere","center","radius","fromCenterRadius","from","corner","oppositeCorner","add","scale","distance","right","Boolean","equals","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","clone","halfDistanceBetweenTangentPoints","point","scratchPoint","transform","mat4","getScaling","Math","max","d","distanceTo","delta","len","plane","normal","distanceToPlane","dot","INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;;;;;AAIA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;;IAGqBE,c;AAKnB,4BAAyE;AAAA,QAA7DC,MAA6D,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,MAAsB,uEAAL,GAAK;AAAA;AAAA;AAAA;AACvE,SAAKA,MAAL,GAAc,CAAC,CAAf;AACA,SAAKD,MAAL,GAAc,IAAIH,aAAJ,EAAd;AACA,SAAKK,gBAAL,CAAsBF,MAAtB,EAA8BC,MAA9B;AACD;;;;WAGD,0B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CAAC,GAAGA,CAAX;AACD;;;WAGD,oBAAWP,KAAX,EAAkD;AAChD,UAAMC,YAAY,GAAG7B,aAAa,CAACO,IAAd,CAAmBqB,KAAnB,CAArB;AACA,UAAMS,KAAK,GAAGR,YAAY,CAACN,QAAb,CAAsB,KAAKnB,MAA3B,CAAd;AACA,aAAO6B,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYG,KAAK,CAACC,GAAN,KAAc,KAAKjC,MAA/B,CAAP;AACD;;;WAGD,wBAAekC,KAAf,EAAqC;AACnC,UAAMnC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMmC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAWtC,MAAX,IAAqBmC,KAAK,CAAC3B,QAAnD;;AAGA,UAAI6B,eAAe,GAAG,CAACpC,MAAvB,EAA+B;AAC7B,eAAOsC,wBAAaC,OAApB;AACD;;AAED,UAAIH,eAAe,GAAGpC,MAAtB,EAA8B;AAC5B,eAAOsC,wBAAaE,YAApB;AACD;;AAED,aAAOF,wBAAaG,MAApB;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 {NumericArray, Vector3} from '@math.gl/core';\nimport * as mat4 from 'gl-matrix/mat4';\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport Plane from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport default class BoundingSphere implements BoundingVolume {\n center: Vector3;\n radius: number;\n\n /** Creates a bounding sphere */\n constructor(center: readonly number[] = [0, 0, 0], radius: number = 0.0) {\n this.radius = -0;\n this.center = new Vector3();\n this.fromCenterRadius(center, radius);\n }\n\n /** Sets the bounding sphere from `center` and `radius`. */\n fromCenterRadius(center: readonly number[], radius: number): this {\n this.center.from(center);\n this.radius = radius;\n return this;\n }\n\n /**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n */\n fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this {\n oppositeCorner = scratchVector.from(oppositeCorner);\n this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);\n this.radius = this.center.distance(oppositeCorner);\n return this;\n }\n\n /** Compares the provided BoundingSphere component wise */\n equals(right: BoundingSphere): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.radius === right.radius)\n );\n }\n\n /** Duplicates a BoundingSphere instance. */\n clone(): BoundingSphere {\n return new BoundingSphere(this.center, this.radius);\n }\n\n /** Computes a bounding sphere that contains both the left and right bounding spheres. */\n union(boundingSphere: BoundingSphere): BoundingSphere {\n const leftCenter = this.center;\n const leftRadius = this.radius;\n const rightCenter = boundingSphere.center;\n const rightRadius = boundingSphere.radius;\n\n const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);\n const centerSeparation = toRightCenter.magnitude();\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n return this.clone();\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n return boundingSphere.clone();\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n scratchVector2\n .copy(toRightCenter)\n .scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation)\n .add(leftCenter);\n\n this.center.copy(scratchVector2);\n this.radius = halfDistanceBetweenTangentPoints;\n\n return this;\n }\n\n /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */\n expand(point: readonly number[]): this {\n const scratchPoint = scratchVector.from(point);\n const radius = scratchPoint.subtract(this.center).magnitude();\n if (radius > this.radius) {\n this.radius = radius;\n }\n return this;\n }\n\n // BoundingVolume interface\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param sphere The bounding sphere to apply the transformation to.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns self.\n */\n transform(transform: readonly number[]): this {\n this.center.transform(transform);\n const scale = mat4.getScaling(scratchVector, transform);\n this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;\n return this;\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */\n distanceSquaredTo(point: Readonly<NumericArray>): number {\n const d = this.distanceTo(point);\n return d * d;\n }\n\n /** Computes the estimated distance from the closest point on a bounding sphere to a point. */\n distanceTo(point: Readonly<NumericArray>): number {\n const scratchPoint = scratchVector.from(point);\n const delta = scratchPoint.subtract(this.center);\n return Math.max(0, delta.len() - this.radius);\n }\n\n /** Determines which side of a plane a sphere is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const radius = this.radius;\n const normal = plane.normal;\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n // The center point is negative side of the plane normal\n if (distanceToPlane < -radius) {\n return INTERSECTION.OUTSIDE;\n }\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n if (distanceToPlane < radius) {\n return INTERSECTION.INTERSECTING;\n }\n // The center point and radius is positive side of the plane\n return INTERSECTION.INSIDE;\n }\n}\n"],"file":"bounding-sphere.js"}
|
|
@@ -1,253 +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 = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
-
|
|
18
|
-
var _core = require("@math.gl/core");
|
|
19
|
-
|
|
20
|
-
var _boundingSphere = _interopRequireDefault(require("./bounding-sphere"));
|
|
21
|
-
|
|
22
|
-
var _constants = require("../../constants");
|
|
23
|
-
|
|
24
|
-
var scratchVector3 = new _core.Vector3();
|
|
25
|
-
var scratchOffset = new _core.Vector3();
|
|
26
|
-
var scratchVectorU = new _core.Vector3();
|
|
27
|
-
var scratchVectorV = new _core.Vector3();
|
|
28
|
-
var scratchVectorW = new _core.Vector3();
|
|
29
|
-
var scratchCorner = new _core.Vector3();
|
|
30
|
-
var scratchToCenter = new _core.Vector3();
|
|
31
|
-
var MATRIX3 = {
|
|
32
|
-
COLUMN0ROW0: 0,
|
|
33
|
-
COLUMN0ROW1: 1,
|
|
34
|
-
COLUMN0ROW2: 2,
|
|
35
|
-
COLUMN1ROW0: 3,
|
|
36
|
-
COLUMN1ROW1: 4,
|
|
37
|
-
COLUMN1ROW2: 5,
|
|
38
|
-
COLUMN2ROW0: 6,
|
|
39
|
-
COLUMN2ROW1: 7,
|
|
40
|
-
COLUMN2ROW2: 8
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var OrientedBoundingBox = function () {
|
|
44
|
-
function OrientedBoundingBox() {
|
|
45
|
-
var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
|
|
46
|
-
var halfAxes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
47
|
-
(0, _classCallCheck2.default)(this, OrientedBoundingBox);
|
|
48
|
-
(0, _defineProperty2.default)(this, "center", void 0);
|
|
49
|
-
(0, _defineProperty2.default)(this, "halfAxes", void 0);
|
|
50
|
-
this.center = new _core.Vector3().from(center);
|
|
51
|
-
this.halfAxes = new _core.Matrix3(halfAxes);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
(0, _createClass2.default)(OrientedBoundingBox, [{
|
|
55
|
-
key: "halfSize",
|
|
56
|
-
get: function get() {
|
|
57
|
-
var xAxis = this.halfAxes.getColumn(0);
|
|
58
|
-
var yAxis = this.halfAxes.getColumn(1);
|
|
59
|
-
var zAxis = this.halfAxes.getColumn(2);
|
|
60
|
-
return [new _core.Vector3(xAxis).len(), new _core.Vector3(yAxis).len(), new _core.Vector3(zAxis).len()];
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "quaternion",
|
|
64
|
-
get: function get() {
|
|
65
|
-
var xAxis = this.halfAxes.getColumn(0);
|
|
66
|
-
var yAxis = this.halfAxes.getColumn(1);
|
|
67
|
-
var zAxis = this.halfAxes.getColumn(2);
|
|
68
|
-
var normXAxis = new _core.Vector3(xAxis).normalize();
|
|
69
|
-
var normYAxis = new _core.Vector3(yAxis).normalize();
|
|
70
|
-
var normZAxis = new _core.Vector3(zAxis).normalize();
|
|
71
|
-
return new _core.Quaternion().fromMatrix3(new _core.Matrix3([].concat((0, _toConsumableArray2.default)(normXAxis), (0, _toConsumableArray2.default)(normYAxis), (0, _toConsumableArray2.default)(normZAxis))));
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "fromCenterHalfSizeQuaternion",
|
|
75
|
-
value: function fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
|
|
76
|
-
var quaternionObject = new _core.Quaternion(quaternion);
|
|
77
|
-
var directionsMatrix = new _core.Matrix3().fromQuaternion(quaternionObject);
|
|
78
|
-
directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
|
|
79
|
-
directionsMatrix[1] = directionsMatrix[1] * halfSize[0];
|
|
80
|
-
directionsMatrix[2] = directionsMatrix[2] * halfSize[0];
|
|
81
|
-
directionsMatrix[3] = directionsMatrix[3] * halfSize[1];
|
|
82
|
-
directionsMatrix[4] = directionsMatrix[4] * halfSize[1];
|
|
83
|
-
directionsMatrix[5] = directionsMatrix[5] * halfSize[1];
|
|
84
|
-
directionsMatrix[6] = directionsMatrix[6] * halfSize[2];
|
|
85
|
-
directionsMatrix[7] = directionsMatrix[7] * halfSize[2];
|
|
86
|
-
directionsMatrix[8] = directionsMatrix[8] * halfSize[2];
|
|
87
|
-
this.center = new _core.Vector3().from(center);
|
|
88
|
-
this.halfAxes = directionsMatrix;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
}, {
|
|
92
|
-
key: "clone",
|
|
93
|
-
value: function clone() {
|
|
94
|
-
return new OrientedBoundingBox(this.center, this.halfAxes);
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "equals",
|
|
98
|
-
value: function equals(right) {
|
|
99
|
-
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);
|
|
100
|
-
}
|
|
101
|
-
}, {
|
|
102
|
-
key: "getBoundingSphere",
|
|
103
|
-
value: function getBoundingSphere() {
|
|
104
|
-
var result = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new _boundingSphere.default();
|
|
105
|
-
var halfAxes = this.halfAxes;
|
|
106
|
-
var u = halfAxes.getColumn(0, scratchVectorU);
|
|
107
|
-
var v = halfAxes.getColumn(1, scratchVectorV);
|
|
108
|
-
var w = halfAxes.getColumn(2, scratchVectorW);
|
|
109
|
-
var cornerVector = scratchVector3.copy(u).add(v).add(w);
|
|
110
|
-
result.center.copy(this.center);
|
|
111
|
-
result.radius = cornerVector.magnitude();
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
}, {
|
|
115
|
-
key: "intersectPlane",
|
|
116
|
-
value: function intersectPlane(plane) {
|
|
117
|
-
var center = this.center;
|
|
118
|
-
var normal = plane.normal;
|
|
119
|
-
var halfAxes = this.halfAxes;
|
|
120
|
-
var normalX = normal.x;
|
|
121
|
-
var normalY = normal.y;
|
|
122
|
-
var normalZ = normal.z;
|
|
123
|
-
var radEffective = Math.abs(normalX * halfAxes[MATRIX3.COLUMN0ROW0] + normalY * halfAxes[MATRIX3.COLUMN0ROW1] + normalZ * halfAxes[MATRIX3.COLUMN0ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN1ROW0] + normalY * halfAxes[MATRIX3.COLUMN1ROW1] + normalZ * halfAxes[MATRIX3.COLUMN1ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN2ROW0] + normalY * halfAxes[MATRIX3.COLUMN2ROW1] + normalZ * halfAxes[MATRIX3.COLUMN2ROW2]);
|
|
124
|
-
var distanceToPlane = normal.dot(center) + plane.distance;
|
|
125
|
-
|
|
126
|
-
if (distanceToPlane <= -radEffective) {
|
|
127
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
128
|
-
} else if (distanceToPlane >= radEffective) {
|
|
129
|
-
return _constants.INTERSECTION.INSIDE;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return _constants.INTERSECTION.INTERSECTING;
|
|
133
|
-
}
|
|
134
|
-
}, {
|
|
135
|
-
key: "distanceTo",
|
|
136
|
-
value: function distanceTo(point) {
|
|
137
|
-
return Math.sqrt(this.distanceSquaredTo(point));
|
|
138
|
-
}
|
|
139
|
-
}, {
|
|
140
|
-
key: "distanceSquaredTo",
|
|
141
|
-
value: function distanceSquaredTo(point) {
|
|
142
|
-
var offset = scratchOffset.from(point).subtract(this.center);
|
|
143
|
-
var halfAxes = this.halfAxes;
|
|
144
|
-
var u = halfAxes.getColumn(0, scratchVectorU);
|
|
145
|
-
var v = halfAxes.getColumn(1, scratchVectorV);
|
|
146
|
-
var w = halfAxes.getColumn(2, scratchVectorW);
|
|
147
|
-
var uHalf = u.magnitude();
|
|
148
|
-
var vHalf = v.magnitude();
|
|
149
|
-
var wHalf = w.magnitude();
|
|
150
|
-
u.normalize();
|
|
151
|
-
v.normalize();
|
|
152
|
-
w.normalize();
|
|
153
|
-
var distanceSquared = 0.0;
|
|
154
|
-
var d;
|
|
155
|
-
d = Math.abs(offset.dot(u)) - uHalf;
|
|
156
|
-
|
|
157
|
-
if (d > 0) {
|
|
158
|
-
distanceSquared += d * d;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
d = Math.abs(offset.dot(v)) - vHalf;
|
|
162
|
-
|
|
163
|
-
if (d > 0) {
|
|
164
|
-
distanceSquared += d * d;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
d = Math.abs(offset.dot(w)) - wHalf;
|
|
168
|
-
|
|
169
|
-
if (d > 0) {
|
|
170
|
-
distanceSquared += d * d;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return distanceSquared;
|
|
174
|
-
}
|
|
175
|
-
}, {
|
|
176
|
-
key: "computePlaneDistances",
|
|
177
|
-
value: function computePlaneDistances(position, direction) {
|
|
178
|
-
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [-0, -0];
|
|
179
|
-
var minDist = Number.POSITIVE_INFINITY;
|
|
180
|
-
var maxDist = Number.NEGATIVE_INFINITY;
|
|
181
|
-
var center = this.center;
|
|
182
|
-
var halfAxes = this.halfAxes;
|
|
183
|
-
var u = halfAxes.getColumn(0, scratchVectorU);
|
|
184
|
-
var v = halfAxes.getColumn(1, scratchVectorV);
|
|
185
|
-
var w = halfAxes.getColumn(2, scratchVectorW);
|
|
186
|
-
var corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
187
|
-
var toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
188
|
-
var mag = direction.dot(toCenter);
|
|
189
|
-
minDist = Math.min(mag, minDist);
|
|
190
|
-
maxDist = Math.max(mag, maxDist);
|
|
191
|
-
corner.copy(center).add(u).add(v).subtract(w);
|
|
192
|
-
toCenter.copy(corner).subtract(position);
|
|
193
|
-
mag = direction.dot(toCenter);
|
|
194
|
-
minDist = Math.min(mag, minDist);
|
|
195
|
-
maxDist = Math.max(mag, maxDist);
|
|
196
|
-
corner.copy(center).add(u).subtract(v).add(w);
|
|
197
|
-
toCenter.copy(corner).subtract(position);
|
|
198
|
-
mag = direction.dot(toCenter);
|
|
199
|
-
minDist = Math.min(mag, minDist);
|
|
200
|
-
maxDist = Math.max(mag, maxDist);
|
|
201
|
-
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
202
|
-
toCenter.copy(corner).subtract(position);
|
|
203
|
-
mag = direction.dot(toCenter);
|
|
204
|
-
minDist = Math.min(mag, minDist);
|
|
205
|
-
maxDist = Math.max(mag, maxDist);
|
|
206
|
-
center.copy(corner).subtract(u).add(v).add(w);
|
|
207
|
-
toCenter.copy(corner).subtract(position);
|
|
208
|
-
mag = direction.dot(toCenter);
|
|
209
|
-
minDist = Math.min(mag, minDist);
|
|
210
|
-
maxDist = Math.max(mag, maxDist);
|
|
211
|
-
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
212
|
-
toCenter.copy(corner).subtract(position);
|
|
213
|
-
mag = direction.dot(toCenter);
|
|
214
|
-
minDist = Math.min(mag, minDist);
|
|
215
|
-
maxDist = Math.max(mag, maxDist);
|
|
216
|
-
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
217
|
-
toCenter.copy(corner).subtract(position);
|
|
218
|
-
mag = direction.dot(toCenter);
|
|
219
|
-
minDist = Math.min(mag, minDist);
|
|
220
|
-
maxDist = Math.max(mag, maxDist);
|
|
221
|
-
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
222
|
-
toCenter.copy(corner).subtract(position);
|
|
223
|
-
mag = direction.dot(toCenter);
|
|
224
|
-
minDist = Math.min(mag, minDist);
|
|
225
|
-
maxDist = Math.max(mag, maxDist);
|
|
226
|
-
result[0] = minDist;
|
|
227
|
-
result[1] = maxDist;
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
}, {
|
|
231
|
-
key: "transform",
|
|
232
|
-
value: function transform(transformation) {
|
|
233
|
-
this.center.transformAsPoint(transformation);
|
|
234
|
-
var xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
235
|
-
xAxis.transformAsPoint(transformation);
|
|
236
|
-
var yAxis = this.halfAxes.getColumn(1, scratchVectorV);
|
|
237
|
-
yAxis.transformAsPoint(transformation);
|
|
238
|
-
var zAxis = this.halfAxes.getColumn(2, scratchVectorW);
|
|
239
|
-
zAxis.transformAsPoint(transformation);
|
|
240
|
-
this.halfAxes = new _core.Matrix3([].concat((0, _toConsumableArray2.default)(xAxis), (0, _toConsumableArray2.default)(yAxis), (0, _toConsumableArray2.default)(zAxis)));
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
key: "getTransform",
|
|
245
|
-
value: function getTransform() {
|
|
246
|
-
throw new Error('not implemented');
|
|
247
|
-
}
|
|
248
|
-
}]);
|
|
249
|
-
return OrientedBoundingBox;
|
|
250
|
-
}();
|
|
251
|
-
|
|
252
|
-
exports.default = OrientedBoundingBox;
|
|
253
|
-
//# sourceMappingURL=oriented-bounding-box.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["scratchVector3","Vector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","center","halfAxes","from","Matrix3","xAxis","getColumn","yAxis","zAxis","len","normXAxis","normalize","normYAxis","normZAxis","Quaternion","fromMatrix3","halfSize","quaternion","quaternionObject","directionsMatrix","fromQuaternion","right","Boolean","equals","result","BoundingSphere","u","v","w","cornerVector","copy","add","radius","magnitude","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","INTERSECTION","OUTSIDE","INSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","position","direction","minDist","Number","POSITIVE_INFINITY","maxD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ICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
|