@math.gl/culling 4.1.0-alpha.9 → 4.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +353 -62
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
- package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/lib/plane.d.ts +9 -0
- package/dist/lib/plane.d.ts.map +1 -1
- package/dist/lib/plane.js +25 -1
- package/dist/lib/plane.js.map +1 -1
- package/dist/lib/ray.d.ts +13 -0
- package/dist/lib/ray.d.ts.map +1 -0
- package/dist/lib/ray.js +28 -0
- package/dist/lib/ray.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/lib/bounding-volumes/oriented-bounding-box.ts +2 -1
- package/src/lib/plane.ts +31 -1
- package/src/lib/ray.ts +31 -0
package/dist/lib/plane.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Vector3, NumericArray } from '@math.gl/core';
|
|
2
|
+
import { Ray } from "./ray.js";
|
|
2
3
|
export declare class Plane {
|
|
3
4
|
readonly normal: Vector3;
|
|
4
5
|
distance: number;
|
|
@@ -22,5 +23,13 @@ export declare class Plane {
|
|
|
22
23
|
/** Projects a point onto the plane. */
|
|
23
24
|
projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;
|
|
24
25
|
projectPointOntoPlane(point: Readonly<NumericArray>, result?: readonly number[]): readonly number[];
|
|
26
|
+
/**
|
|
27
|
+
* Computes the intersection of a ray and this plane.
|
|
28
|
+
*
|
|
29
|
+
* @param {Ray} ray The ray.
|
|
30
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
31
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersections.
|
|
32
|
+
*/
|
|
33
|
+
intersectWithRay(ray: Ray, result?: Vector3): Vector3;
|
|
25
34
|
}
|
|
26
35
|
//# sourceMappingURL=plane.d.ts.map
|
package/dist/lib/plane.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,OAAO,EAAkB,YAAY,
|
|
1
|
+
{"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,OAAO,EAAkB,YAAY,EAAa,MAAM,eAAe,CAAC;AAChF,OAAO,EAAC,GAAG,EAAC,iBAAc;AAM1B,qBAAa,KAAK;IAChB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,GAAE,QAAQ,CAAC,YAAY,CAAa,EAAE,QAAQ,GAAE,MAAU;IAM5E,oEAAoE;IACpE,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAO1E,8DAA8D;IAC9D,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAQpF,gDAAgD;IAChD,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAOlE,mCAAmC;IACnC,KAAK,IAAI,KAAK;IAId,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAIvD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI;IAMhD,uCAAuC;IACvC,qBAAqB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAC9E,qBAAqB,CACnB,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC7B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE;IAWpB;;;;;;OAMG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO;CAqBtD"}
|
package/dist/lib/plane.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// This file is derived from the Cesium math library under Apache 2 license
|
|
5
5
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
6
6
|
/* eslint-disable */
|
|
7
|
-
import { Vector3, equals, assert } from '@math.gl/core';
|
|
7
|
+
import { Vector3, equals, assert, _MathUtils } from '@math.gl/core';
|
|
8
8
|
const scratchPosition = new Vector3();
|
|
9
9
|
const scratchNormal = new Vector3();
|
|
10
10
|
// A plane in Hessian Normal Form
|
|
@@ -63,5 +63,29 @@ export class Plane {
|
|
|
63
63
|
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
64
64
|
return scratchPoint.subtract(scaledNormal).to(result);
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Computes the intersection of a ray and this plane.
|
|
68
|
+
*
|
|
69
|
+
* @param {Ray} ray The ray.
|
|
70
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
71
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersections.
|
|
72
|
+
*/
|
|
73
|
+
intersectWithRay(ray, result) {
|
|
74
|
+
if (!result)
|
|
75
|
+
result = new Vector3();
|
|
76
|
+
const origin = ray.origin;
|
|
77
|
+
const direction = ray.direction;
|
|
78
|
+
const normal = this.normal;
|
|
79
|
+
const denominator = normal.dot(direction);
|
|
80
|
+
if (Math.abs(denominator) < _MathUtils.EPSILON15) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const t = (-this.distance - normal.dot(origin)) / denominator;
|
|
84
|
+
if (t < 0) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
result = result.copy(direction).multiplyByScalar(t);
|
|
88
|
+
return origin.add(result);
|
|
89
|
+
}
|
|
66
90
|
}
|
|
67
91
|
//# sourceMappingURL=plane.js.map
|
package/dist/lib/plane.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane.js","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oCAAoC;AAEpC,2EAA2E;AAC3E,4FAA4F;AAE5F,oBAAoB;AACpB,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"plane.js","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oCAAoC;AAEpC,2EAA2E;AAC3E,4FAA4F;AAE5F,oBAAoB;AACpB,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAgB,UAAU,EAAC,MAAM,eAAe,CAAC;AAGhF,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,IAAI,OAAO,EAAE,CAAC;AAEpC,iCAAiC;AACjC,MAAM,OAAO,KAAK;IAIhB,YAAY,SAAiC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,WAAmB,CAAC;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,kBAAkB,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C,MAAM,CAAC;QAC1B,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAE1C,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;YACjD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC;QAE9D,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QACpD,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Vector3 } from '@math.gl/core';
|
|
2
|
+
export declare class Ray {
|
|
3
|
+
origin: Vector3;
|
|
4
|
+
direction: Vector3;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
7
|
+
*
|
|
8
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
9
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
10
|
+
*/
|
|
11
|
+
constructor(origin?: Vector3, direction?: Vector3);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray.d.ts","sourceRoot":"","sources":["../../src/lib/ray.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAGtC,qBAAa,GAAG;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IAEnB;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO;CAUlD"}
|
package/dist/lib/ray.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT and Apache-2.0
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium library under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
6
|
+
import { Vector3 } from '@math.gl/core';
|
|
7
|
+
/* Represents a ray that extends infinitely from the provided origin in the provided direction. */
|
|
8
|
+
export class Ray {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
11
|
+
*
|
|
12
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
13
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
14
|
+
*/
|
|
15
|
+
constructor(origin, direction) {
|
|
16
|
+
if (origin)
|
|
17
|
+
origin = origin.clone();
|
|
18
|
+
else
|
|
19
|
+
origin = new Vector3();
|
|
20
|
+
if (direction)
|
|
21
|
+
direction = direction.clone().normalize();
|
|
22
|
+
else
|
|
23
|
+
direction = new Vector3();
|
|
24
|
+
this.origin = origin;
|
|
25
|
+
this.direction = direction;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray.js","sourceRoot":"","sources":["../../src/lib/ray.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oCAAoC;AAEpC,sEAAsE;AACtE,4FAA4F;AAE5F,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,kGAAkG;AAClG,MAAM,OAAO,GAAG;IAId;;;;;OAKG;IACH,YAAY,MAAgB,EAAE,SAAmB;QAC/C,IAAI,MAAM;YAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;;YAC/B,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAE5B,IAAI,SAAS;YAAE,SAAS,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,CAAC;;YACpD,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "4.
|
|
9
|
+
"version": "4.2.0-alpha.3",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"webgl",
|
|
12
12
|
"javascript",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@math.gl/core": "4.
|
|
46
|
-
"@math.gl/types": "4.
|
|
45
|
+
"@math.gl/core": "4.2.0-alpha.3",
|
|
46
|
+
"@math.gl/types": "4.2.0-alpha.3"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4238aa95fb38da43a65c6e5f2b8343a875666d92"
|
|
49
49
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
|
|
|
9
9
|
export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
|
|
10
10
|
export {CullingVolume} from './lib/culling-volume';
|
|
11
11
|
export {Plane} from './lib/plane';
|
|
12
|
+
export {Ray} from './lib/ray';
|
|
12
13
|
|
|
13
14
|
export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
|
|
14
15
|
export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import {NumericArray} from '@math.gl/types';
|
|
9
9
|
import {Vector3, Matrix3, Matrix4, Quaternion} from '@math.gl/core';
|
|
10
|
+
|
|
10
11
|
import type {BoundingVolume} from './bounding-volume';
|
|
11
12
|
import {BoundingSphere} from './bounding-sphere';
|
|
12
|
-
import
|
|
13
|
+
import {Plane} from '../plane';
|
|
13
14
|
import {INTERSECTION} from '../../constants';
|
|
14
15
|
|
|
15
16
|
const scratchVector3 = new Vector3();
|
package/src/lib/plane.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
7
7
|
|
|
8
8
|
/* eslint-disable */
|
|
9
|
-
import {Vector3, equals, assert, NumericArray} from '@math.gl/core';
|
|
9
|
+
import {Vector3, equals, assert, NumericArray, _MathUtils} from '@math.gl/core';
|
|
10
|
+
import {Ray} from './ray';
|
|
10
11
|
|
|
11
12
|
const scratchPosition = new Vector3();
|
|
12
13
|
const scratchNormal = new Vector3();
|
|
@@ -86,4 +87,33 @@ export class Plane {
|
|
|
86
87
|
|
|
87
88
|
return scratchPoint.subtract(scaledNormal).to(result);
|
|
88
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Computes the intersection of a ray and this plane.
|
|
93
|
+
*
|
|
94
|
+
* @param {Ray} ray The ray.
|
|
95
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
96
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersections.
|
|
97
|
+
*/
|
|
98
|
+
intersectWithRay(ray: Ray, result?: Vector3): Vector3 {
|
|
99
|
+
if (!result) result = new Vector3();
|
|
100
|
+
|
|
101
|
+
const origin = ray.origin;
|
|
102
|
+
const direction = ray.direction;
|
|
103
|
+
const normal = this.normal;
|
|
104
|
+
const denominator = normal.dot(direction);
|
|
105
|
+
|
|
106
|
+
if (Math.abs(denominator) < _MathUtils.EPSILON15) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const t = (-this.distance - normal.dot(origin)) / denominator;
|
|
111
|
+
|
|
112
|
+
if (t < 0) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
result = result.copy(direction).multiplyByScalar(t);
|
|
117
|
+
return origin.add(result);
|
|
118
|
+
}
|
|
89
119
|
}
|
package/src/lib/ray.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT and Apache-2.0
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// This file is derived from the Cesium library under Apache 2 license
|
|
6
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
7
|
+
|
|
8
|
+
import {Vector3} from '@math.gl/core';
|
|
9
|
+
|
|
10
|
+
/* Represents a ray that extends infinitely from the provided origin in the provided direction. */
|
|
11
|
+
export class Ray {
|
|
12
|
+
origin: Vector3;
|
|
13
|
+
direction: Vector3;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
17
|
+
*
|
|
18
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
19
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
20
|
+
*/
|
|
21
|
+
constructor(origin?: Vector3, direction?: Vector3) {
|
|
22
|
+
if (origin) origin = origin.clone();
|
|
23
|
+
else origin = new Vector3();
|
|
24
|
+
|
|
25
|
+
if (direction) direction = direction.clone().normalize();
|
|
26
|
+
else direction = new Vector3();
|
|
27
|
+
|
|
28
|
+
this.origin = origin;
|
|
29
|
+
this.direction = direction;
|
|
30
|
+
}
|
|
31
|
+
}
|