@math.gl/culling 4.2.0-alpha.3 → 4.2.0-alpha.5
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/LICENSE +51 -0
- package/README.md +8 -1
- package/dist/index.cjs +618 -89
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/plane.d.ts +2 -2
- package/dist/lib/plane.d.ts.map +1 -1
- package/dist/lib/plane.js +3 -6
- package/dist/lib/plane.js.map +1 -1
- package/dist/lib/shapes/box-shape.d.ts +19 -0
- package/dist/lib/shapes/box-shape.d.ts.map +1 -0
- package/dist/lib/shapes/box-shape.js +69 -0
- package/dist/lib/shapes/box-shape.js.map +1 -0
- package/dist/lib/shapes/capsule-shape.d.ts +23 -0
- package/dist/lib/shapes/capsule-shape.d.ts.map +1 -0
- package/dist/lib/shapes/capsule-shape.js +151 -0
- package/dist/lib/shapes/capsule-shape.js.map +1 -0
- package/dist/lib/shapes/cylinder-shape.d.ts +22 -0
- package/dist/lib/shapes/cylinder-shape.d.ts.map +1 -0
- package/dist/lib/shapes/cylinder-shape.js +99 -0
- package/dist/lib/shapes/cylinder-shape.js.map +1 -0
- package/dist/lib/shapes/implicit-shape.d.ts +55 -0
- package/dist/lib/shapes/implicit-shape.d.ts.map +1 -0
- package/dist/lib/shapes/implicit-shape.js +143 -0
- package/dist/lib/shapes/implicit-shape.js.map +1 -0
- package/dist/lib/shapes/plane-shape.d.ts +26 -0
- package/dist/lib/shapes/plane-shape.d.ts.map +1 -0
- package/dist/lib/shapes/plane-shape.js +72 -0
- package/dist/lib/shapes/plane-shape.js.map +1 -0
- package/dist/lib/shapes/sphere-shape.d.ts +18 -0
- package/dist/lib/shapes/sphere-shape.d.ts.map +1 -0
- package/dist/lib/shapes/sphere-shape.js +43 -0
- package/dist/lib/shapes/sphere-shape.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +12 -0
- package/src/lib/plane.ts +3 -6
- package/src/lib/shapes/box-shape.ts +78 -0
- package/src/lib/shapes/capsule-shape.ts +232 -0
- package/src/lib/shapes/cylinder-shape.ts +133 -0
- package/src/lib/shapes/implicit-shape.ts +209 -0
- package/src/lib/shapes/plane-shape.ts +78 -0
- package/src/lib/shapes/sphere-shape.ts +60 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { closestDistanceToCircleArc2D, closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
|
|
5
|
+
const EPSILON = 1e-6;
|
|
6
|
+
/** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
|
|
7
|
+
export class CapsuleShape extends ImplicitShapeBase {
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
super(props.matrix);
|
|
10
|
+
this.type = 'capsule';
|
|
11
|
+
this.height = props.height ?? 1;
|
|
12
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
13
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
14
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
15
|
+
throw new Error('Capsule height must be greater than zero');
|
|
16
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
17
|
+
throw new Error('Capsule radii must be non-negative');
|
|
18
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
19
|
+
throw new Error('At least one capsule radius must be greater than zero');
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
return new CapsuleShape({
|
|
23
|
+
height: this.height,
|
|
24
|
+
radiusBottom: this.radiusBottom,
|
|
25
|
+
radiusTop: this.radiusTop,
|
|
26
|
+
matrix: this.matrix
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
equals(shape) {
|
|
30
|
+
return (shape instanceof CapsuleShape &&
|
|
31
|
+
super.equals(shape) &&
|
|
32
|
+
this.height === shape.height &&
|
|
33
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
34
|
+
this.radiusTop === shape.radiusTop);
|
|
35
|
+
}
|
|
36
|
+
containsLocalPoint(point) {
|
|
37
|
+
const profile = this.getProfile();
|
|
38
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
39
|
+
if (profile.sphere)
|
|
40
|
+
return (Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON);
|
|
41
|
+
if (point[1] < profile.bottom.y)
|
|
42
|
+
return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON;
|
|
43
|
+
if (point[1] > profile.top.y)
|
|
44
|
+
return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON;
|
|
45
|
+
const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
46
|
+
return (radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON);
|
|
47
|
+
}
|
|
48
|
+
distanceToLocalPoint(point) {
|
|
49
|
+
if (this.containsLocalPoint(point))
|
|
50
|
+
return 0;
|
|
51
|
+
const profile = this.getProfile();
|
|
52
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
53
|
+
if (profile.sphere)
|
|
54
|
+
return Math.max(0, Math.hypot(radial, point[1] - profile.sphere.center) - profile.sphere.radius);
|
|
55
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
56
|
+
const sideNormalY = -delta / this.height;
|
|
57
|
+
const bottomArc = closestDistanceToCircleArc2D(radial, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
|
|
58
|
+
const topArc = closestDistanceToCircleArc2D(radial, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
|
|
59
|
+
const side = closestDistanceToSegment2D(radial, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
|
|
60
|
+
return Math.min(bottomArc, topArc, side);
|
|
61
|
+
}
|
|
62
|
+
supportLocal(direction) {
|
|
63
|
+
const length = Math.hypot(...direction);
|
|
64
|
+
const unit = length ? direction.map(value => value / length) : [1, 0, 0];
|
|
65
|
+
const bottom = [
|
|
66
|
+
unit[0] * this.radiusBottom,
|
|
67
|
+
-this.height / 2 + unit[1] * this.radiusBottom,
|
|
68
|
+
unit[2] * this.radiusBottom
|
|
69
|
+
];
|
|
70
|
+
const top = [
|
|
71
|
+
unit[0] * this.radiusTop,
|
|
72
|
+
this.height / 2 + unit[1] * this.radiusTop,
|
|
73
|
+
unit[2] * this.radiusTop
|
|
74
|
+
];
|
|
75
|
+
return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
|
|
76
|
+
}
|
|
77
|
+
intersectLocalRay(origin, direction) {
|
|
78
|
+
const profile = this.getProfile();
|
|
79
|
+
if (profile.sphere)
|
|
80
|
+
return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
|
|
81
|
+
const candidates = [];
|
|
82
|
+
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
83
|
+
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
84
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
85
|
+
const radialAlongRay = slope * direction[1];
|
|
86
|
+
for (const distance of solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
|
|
87
|
+
const y = origin[1] + distance * direction[1];
|
|
88
|
+
if (distance >= 0 && y >= profile.bottom.y - EPSILON && y <= profile.top.y + EPSILON) {
|
|
89
|
+
const x = origin[0] + distance * direction[0];
|
|
90
|
+
const z = origin[2] + distance * direction[2];
|
|
91
|
+
const radial = Math.hypot(x, z) || 1;
|
|
92
|
+
const normal = [x / radial, -slope, z / radial];
|
|
93
|
+
const length = Math.hypot(...normal);
|
|
94
|
+
candidates.push({ distance, normal: normal.map(value => value / length) });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
|
|
98
|
+
const y = origin[1] + bottomHit.distance * direction[1];
|
|
99
|
+
if (y <= profile.bottom.y + EPSILON)
|
|
100
|
+
candidates.push(bottomHit);
|
|
101
|
+
}
|
|
102
|
+
for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
|
|
103
|
+
const y = origin[1] + topHit.distance * direction[1];
|
|
104
|
+
if (y >= profile.top.y - EPSILON)
|
|
105
|
+
candidates.push(topHit);
|
|
106
|
+
}
|
|
107
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
108
|
+
}
|
|
109
|
+
getProfile() {
|
|
110
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
111
|
+
if (Math.abs(delta) >= this.height) {
|
|
112
|
+
const topWins = this.radiusTop >= this.radiusBottom;
|
|
113
|
+
return {
|
|
114
|
+
sphere: {
|
|
115
|
+
center: topWins ? this.height / 2 : -this.height / 2,
|
|
116
|
+
radius: topWins ? this.radiusTop : this.radiusBottom
|
|
117
|
+
},
|
|
118
|
+
bottom: { radius: 0, y: 0 },
|
|
119
|
+
top: { radius: 0, y: 0 }
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const sinSlope = delta / this.height;
|
|
123
|
+
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
124
|
+
const normalY = -sinSlope;
|
|
125
|
+
return {
|
|
126
|
+
bottom: {
|
|
127
|
+
radius: this.radiusBottom * radialNormal,
|
|
128
|
+
y: -this.height / 2 + this.radiusBottom * normalY
|
|
129
|
+
},
|
|
130
|
+
top: { radius: this.radiusTop * radialNormal, y: this.height / 2 + this.radiusTop * normalY }
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function intersectSphere(origin, direction, centerY, radius) {
|
|
135
|
+
return intersectSphereRoots(origin, direction, centerY, radius)[0];
|
|
136
|
+
}
|
|
137
|
+
function intersectSphereRoots(origin, direction, centerY, radius) {
|
|
138
|
+
if (radius === 0)
|
|
139
|
+
return [];
|
|
140
|
+
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
141
|
+
return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius)
|
|
142
|
+
.filter(distance => distance >= 0)
|
|
143
|
+
.map(distance => ({
|
|
144
|
+
distance,
|
|
145
|
+
normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
function dot(a, b) {
|
|
149
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=capsule-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/capsule-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,2EAA2E;AAC3E,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IAMjD,YAAY,QAA2B,EAAE;QACvC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,SAAkB,CAAC;QAOjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,M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AAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
|
|
2
|
+
export type CylinderShapeProps = {
|
|
3
|
+
height?: number;
|
|
4
|
+
radiusBottom?: number;
|
|
5
|
+
radiusTop?: number;
|
|
6
|
+
matrix?: readonly number[];
|
|
7
|
+
};
|
|
8
|
+
/** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
|
|
9
|
+
export declare class CylinderShape extends ImplicitShapeBase {
|
|
10
|
+
readonly type: "cylinder";
|
|
11
|
+
readonly height: number;
|
|
12
|
+
readonly radiusBottom: number;
|
|
13
|
+
readonly radiusTop: number;
|
|
14
|
+
constructor(props?: CylinderShapeProps);
|
|
15
|
+
clone(): CylinderShape;
|
|
16
|
+
equals(shape: ImplicitShape): boolean;
|
|
17
|
+
containsLocalPoint(point: readonly number[]): boolean;
|
|
18
|
+
distanceToLocalPoint(point: readonly number[]): number;
|
|
19
|
+
supportLocal(direction: readonly number[]): readonly number[];
|
|
20
|
+
intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cylinder-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cylinder-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,iBAAiB,EAEjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,4BAAyB;AAI1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,mFAAmF;AACnF,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,QAAQ,CAAC,IAAI,EAAG,UAAU,CAAU;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,GAAE,kBAAuB;IAa1C,KAAK,IAAI,aAAa;IAQb,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAS9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAOrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAgBtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAW7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;CAqCpC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
|
|
5
|
+
const EPSILON = 1e-6;
|
|
6
|
+
/** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
|
|
7
|
+
export class CylinderShape extends ImplicitShapeBase {
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
super(props.matrix);
|
|
10
|
+
this.type = 'cylinder';
|
|
11
|
+
this.height = props.height ?? 2;
|
|
12
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
13
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
14
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
15
|
+
throw new Error('Cylinder height must be greater than zero');
|
|
16
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
17
|
+
throw new Error('Cylinder radii must be non-negative');
|
|
18
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
19
|
+
throw new Error('At least one cylinder radius must be greater than zero');
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
return new CylinderShape({
|
|
23
|
+
height: this.height,
|
|
24
|
+
radiusBottom: this.radiusBottom,
|
|
25
|
+
radiusTop: this.radiusTop,
|
|
26
|
+
matrix: this.matrix
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
equals(shape) {
|
|
30
|
+
return (shape instanceof CylinderShape &&
|
|
31
|
+
super.equals(shape) &&
|
|
32
|
+
this.height === shape.height &&
|
|
33
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
34
|
+
this.radiusTop === shape.radiusTop);
|
|
35
|
+
}
|
|
36
|
+
containsLocalPoint(point) {
|
|
37
|
+
const half = this.height / 2;
|
|
38
|
+
if (point[1] < -half - EPSILON || point[1] > half + EPSILON)
|
|
39
|
+
return false;
|
|
40
|
+
const t = (point[1] + half) / this.height;
|
|
41
|
+
const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
42
|
+
return Math.hypot(point[0], point[2]) <= radius + EPSILON;
|
|
43
|
+
}
|
|
44
|
+
distanceToLocalPoint(point) {
|
|
45
|
+
if (this.containsLocalPoint(point))
|
|
46
|
+
return 0;
|
|
47
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
48
|
+
const half = this.height / 2;
|
|
49
|
+
const side = closestDistanceToSegment2D(radial, point[1], this.radiusBottom, -half, this.radiusTop, half);
|
|
50
|
+
const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
|
|
51
|
+
const top = closestDistanceToSegment2D(radial, point[1], 0, half, this.radiusTop, half);
|
|
52
|
+
return Math.min(side, bottom, top);
|
|
53
|
+
}
|
|
54
|
+
supportLocal(direction) {
|
|
55
|
+
const radialLength = Math.hypot(direction[0], direction[2]);
|
|
56
|
+
const x = radialLength ? direction[0] / radialLength : 1;
|
|
57
|
+
const z = radialLength ? direction[2] / radialLength : 0;
|
|
58
|
+
const half = this.height / 2;
|
|
59
|
+
const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
|
|
60
|
+
const topValue = radialLength * this.radiusTop + direction[1] * half;
|
|
61
|
+
return topValue >= bottomValue
|
|
62
|
+
? [x * this.radiusTop, half, z * this.radiusTop]
|
|
63
|
+
: [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
64
|
+
}
|
|
65
|
+
intersectLocalRay(origin, direction) {
|
|
66
|
+
const half = this.height / 2;
|
|
67
|
+
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
68
|
+
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
69
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
70
|
+
const radialAlongRay = slope * direction[1];
|
|
71
|
+
const candidates = [];
|
|
72
|
+
const roots = solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
|
|
73
|
+
for (const distance of roots) {
|
|
74
|
+
const y = origin[1] + distance * direction[1];
|
|
75
|
+
if (distance >= 0 && y >= -half - EPSILON && y <= half + EPSILON) {
|
|
76
|
+
const x = origin[0] + distance * direction[0];
|
|
77
|
+
const z = origin[2] + distance * direction[2];
|
|
78
|
+
const radial = Math.hypot(x, z) || 1;
|
|
79
|
+
const normal = [x / radial, -slope, z / radial];
|
|
80
|
+
const length = Math.hypot(...normal);
|
|
81
|
+
candidates.push({ distance, normal: normal.map(value => value / length) });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Math.abs(direction[1]) > 1e-15) {
|
|
85
|
+
for (const [y, radius, normalY] of [
|
|
86
|
+
[-half, this.radiusBottom, -1],
|
|
87
|
+
[half, this.radiusTop, 1]
|
|
88
|
+
]) {
|
|
89
|
+
const distance = (y - origin[1]) / direction[1];
|
|
90
|
+
const x = origin[0] + distance * direction[0];
|
|
91
|
+
const z = origin[2] + distance * direction[2];
|
|
92
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON)
|
|
93
|
+
candidates.push({ distance, normal: [0, normalY, 0] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=cylinder-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cylinder-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,mFAAmF;AACnF,MAAM,OAAO,aAAc,SAAQ,iBAAiB;IAMlD,YAAY,QAA4B,EAAE;QACxC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,UAAmB,CAAC;QAOlC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,E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ACH,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;YACnC,KAAK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI;gBACjC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;gBAC9B,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aAC1B,EAAE,CAAC;gBACF,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAChD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC9C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC9C,IAAI,QAAQ,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,GAAG,OAAO;oBACvD,UAAU,CAAC,IAAI,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QACD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
2
|
+
import { AxisAlignedBoundingBox } from "../bounding-volumes/axis-aligned-bounding-box.js";
|
|
3
|
+
import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
|
|
4
|
+
import type { BoundingVolume } from "../bounding-volumes/bounding-volume.js";
|
|
5
|
+
import type { Plane } from "../plane.js";
|
|
6
|
+
import type { Ray } from "../ray.js";
|
|
7
|
+
export type RayIntersection = {
|
|
8
|
+
distance: number;
|
|
9
|
+
point: Vector3;
|
|
10
|
+
normal: Vector3;
|
|
11
|
+
entering: boolean;
|
|
12
|
+
};
|
|
13
|
+
export interface ImplicitShape extends BoundingVolume {
|
|
14
|
+
readonly type: 'box' | 'capsule' | 'cylinder' | 'plane' | 'sphere';
|
|
15
|
+
readonly matrix: Matrix4;
|
|
16
|
+
clone(): ImplicitShape;
|
|
17
|
+
equals(shape: ImplicitShape): boolean;
|
|
18
|
+
containsPoint(point: readonly number[]): boolean;
|
|
19
|
+
intersectRay(ray: Ray): RayIntersection | undefined;
|
|
20
|
+
getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
|
|
21
|
+
getBoundingSphere(): BoundingSphere | undefined;
|
|
22
|
+
}
|
|
23
|
+
export type LocalRayIntersection = {
|
|
24
|
+
distance: number;
|
|
25
|
+
normal: readonly number[];
|
|
26
|
+
};
|
|
27
|
+
/** Shared affine transform, support mapping and query implementation for finite convex shapes. */
|
|
28
|
+
export declare abstract class ImplicitShapeBase implements ImplicitShape {
|
|
29
|
+
abstract readonly type: ImplicitShape['type'];
|
|
30
|
+
readonly matrix: Matrix4;
|
|
31
|
+
protected inverseMatrix: Matrix4;
|
|
32
|
+
constructor(matrix?: readonly number[]);
|
|
33
|
+
abstract clone(): ImplicitShapeBase;
|
|
34
|
+
abstract containsLocalPoint(point: readonly number[]): boolean;
|
|
35
|
+
abstract distanceToLocalPoint(point: readonly number[]): number;
|
|
36
|
+
abstract supportLocal(direction: readonly number[]): readonly number[];
|
|
37
|
+
abstract intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
38
|
+
equals(shape: ImplicitShape): boolean;
|
|
39
|
+
transform(transform: readonly number[]): this;
|
|
40
|
+
containsPoint(point: readonly number[]): boolean;
|
|
41
|
+
distanceSquaredTo(point: readonly number[]): number;
|
|
42
|
+
/** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
|
|
43
|
+
distanceTo(point: readonly number[]): number;
|
|
44
|
+
intersectPlane(plane: Plane): number;
|
|
45
|
+
intersectRay(ray: Ray): RayIntersection | undefined;
|
|
46
|
+
getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
|
|
47
|
+
getBoundingSphere(): BoundingSphere | undefined;
|
|
48
|
+
protected getSupportPoint(worldDirection: readonly number[]): Vector3;
|
|
49
|
+
}
|
|
50
|
+
export declare function validateAffineMatrix(matrix: readonly number[]): void;
|
|
51
|
+
export declare function solveQuadratic(a: number, b: number, c: number): number[];
|
|
52
|
+
export declare function closestDistanceToSegment2D(px: number, py: number, ax: number, ay: number, bx: number, by: number): number;
|
|
53
|
+
/** Distance in the radial/Y half-plane to a spherical profile arc selected by normal Y range. */
|
|
54
|
+
export declare function closestDistanceToCircleArc2D(px: number, py: number, centerY: number, radius: number, minimumNormalY: number, maximumNormalY: number): number;
|
|
55
|
+
//# sourceMappingURL=implicit-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"implicit-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/implicit-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,sBAAsB,EAAC,yDAAsD;AACrF,OAAO,EAAC,cAAc,EAAC,+CAA4C;AACnE,OAAO,KAAK,EAAC,cAAc,EAAC,+CAA4C;AACxE,OAAO,KAAK,EAAC,KAAK,EAAC,oBAAiB;AACpC,OAAO,KAAK,EAAC,GAAG,EAAC,kBAAe;AAEhC,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,E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B,MAAM,CAeR"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
5
|
+
import { INTERSECTION } from "../../constants.js";
|
|
6
|
+
import { AxisAlignedBoundingBox } from "../bounding-volumes/axis-aligned-bounding-box.js";
|
|
7
|
+
import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
|
|
8
|
+
/** Shared affine transform, support mapping and query implementation for finite convex shapes. */
|
|
9
|
+
export class ImplicitShapeBase {
|
|
10
|
+
constructor(matrix) {
|
|
11
|
+
this.matrix = new Matrix4();
|
|
12
|
+
if (matrix)
|
|
13
|
+
this.matrix.copy(matrix);
|
|
14
|
+
validateAffineMatrix(this.matrix);
|
|
15
|
+
this.inverseMatrix = this.matrix.clone().invert();
|
|
16
|
+
}
|
|
17
|
+
equals(shape) {
|
|
18
|
+
if (this.type !== shape.type)
|
|
19
|
+
return false;
|
|
20
|
+
for (let i = 0; i < 16; i++)
|
|
21
|
+
if (this.matrix[i] !== shape.matrix[i])
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
transform(transform) {
|
|
26
|
+
const next = new Matrix4().copy(transform);
|
|
27
|
+
validateAffineMatrix(next);
|
|
28
|
+
this.matrix.multiplyLeft(next);
|
|
29
|
+
validateAffineMatrix(this.matrix);
|
|
30
|
+
this.inverseMatrix.copy(this.matrix).invert();
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
containsPoint(point) {
|
|
34
|
+
return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point));
|
|
35
|
+
}
|
|
36
|
+
distanceSquaredTo(point) {
|
|
37
|
+
const distance = this.distanceTo(point);
|
|
38
|
+
return distance * distance;
|
|
39
|
+
}
|
|
40
|
+
/** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
|
|
41
|
+
distanceTo(point) {
|
|
42
|
+
const localPoint = this.inverseMatrix.transformAsPoint(point);
|
|
43
|
+
const localDistance = this.distanceToLocalPoint(localPoint);
|
|
44
|
+
const scales = this.matrix.getScale();
|
|
45
|
+
return localDistance * Math.min(scales[0], scales[1], scales[2]);
|
|
46
|
+
}
|
|
47
|
+
intersectPlane(plane) {
|
|
48
|
+
const maximum = this.getSupportPoint(plane.normal);
|
|
49
|
+
const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
|
|
50
|
+
const maxDistance = plane.getPointDistance(maximum);
|
|
51
|
+
const minDistance = plane.getPointDistance(minimum);
|
|
52
|
+
if (minDistance > 0)
|
|
53
|
+
return INTERSECTION.INSIDE;
|
|
54
|
+
if (maxDistance < 0)
|
|
55
|
+
return INTERSECTION.OUTSIDE;
|
|
56
|
+
return INTERSECTION.INTERSECTING;
|
|
57
|
+
}
|
|
58
|
+
intersectRay(ray) {
|
|
59
|
+
const localOrigin = this.inverseMatrix.transformAsPoint(ray.origin);
|
|
60
|
+
const localDirection = this.inverseMatrix.transformAsVector(ray.direction);
|
|
61
|
+
const hit = this.intersectLocalRay(localOrigin, localDirection);
|
|
62
|
+
if (!hit || hit.distance < 0)
|
|
63
|
+
return undefined;
|
|
64
|
+
const point = new Vector3(ray.direction).scale(hit.distance).add(ray.origin);
|
|
65
|
+
const inverse = this.inverseMatrix;
|
|
66
|
+
const normal = new Vector3(inverse[0] * hit.normal[0] + inverse[1] * hit.normal[1] + inverse[2] * hit.normal[2], inverse[4] * hit.normal[0] + inverse[5] * hit.normal[1] + inverse[6] * hit.normal[2], inverse[8] * hit.normal[0] + inverse[9] * hit.normal[1] + inverse[10] * hit.normal[2]).normalize();
|
|
67
|
+
return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
|
|
68
|
+
}
|
|
69
|
+
getAxisAlignedBoundingBox() {
|
|
70
|
+
const minimum = new Vector3();
|
|
71
|
+
const maximum = new Vector3();
|
|
72
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
73
|
+
const direction = [0, 0, 0];
|
|
74
|
+
direction[axis] = 1;
|
|
75
|
+
maximum[axis] = this.getSupportPoint(direction)[axis];
|
|
76
|
+
direction[axis] = -1;
|
|
77
|
+
minimum[axis] = this.getSupportPoint(direction)[axis];
|
|
78
|
+
}
|
|
79
|
+
return new AxisAlignedBoundingBox(minimum, maximum);
|
|
80
|
+
}
|
|
81
|
+
getBoundingSphere() {
|
|
82
|
+
const box = this.getAxisAlignedBoundingBox();
|
|
83
|
+
if (!box)
|
|
84
|
+
return undefined;
|
|
85
|
+
return new BoundingSphere().fromCornerPoints(box.minimum, box.maximum);
|
|
86
|
+
}
|
|
87
|
+
getSupportPoint(worldDirection) {
|
|
88
|
+
const matrix = this.matrix;
|
|
89
|
+
const localDirection = [
|
|
90
|
+
matrix[0] * worldDirection[0] + matrix[1] * worldDirection[1] + matrix[2] * worldDirection[2],
|
|
91
|
+
matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
|
|
92
|
+
matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
|
|
93
|
+
];
|
|
94
|
+
return new Vector3(this.supportLocal(localDirection)).transform(this.matrix);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function validateAffineMatrix(matrix) {
|
|
98
|
+
if (matrix.length !== 16 || matrix.some(value => !Number.isFinite(value))) {
|
|
99
|
+
throw new Error('Shape matrix must contain 16 finite values');
|
|
100
|
+
}
|
|
101
|
+
if (Math.abs(matrix[3]) > 1e-12 ||
|
|
102
|
+
Math.abs(matrix[7]) > 1e-12 ||
|
|
103
|
+
Math.abs(matrix[11]) > 1e-12 ||
|
|
104
|
+
Math.abs(matrix[15] - 1) > 1e-12) {
|
|
105
|
+
throw new Error('Shape matrix must be affine');
|
|
106
|
+
}
|
|
107
|
+
if (Math.abs(new Matrix4().copy(matrix).determinant()) < 1e-15)
|
|
108
|
+
throw new Error('Shape matrix must be invertible');
|
|
109
|
+
}
|
|
110
|
+
export function solveQuadratic(a, b, c) {
|
|
111
|
+
if (Math.abs(a) < 1e-15)
|
|
112
|
+
return Math.abs(b) < 1e-15 ? [] : [-c / b];
|
|
113
|
+
const discriminant = b * b - 4 * a * c;
|
|
114
|
+
if (discriminant < 0)
|
|
115
|
+
return [];
|
|
116
|
+
const root = Math.sqrt(Math.max(0, discriminant));
|
|
117
|
+
return [(-b - root) / (2 * a), (-b + root) / (2 * a)].sort((left, right) => left - right);
|
|
118
|
+
}
|
|
119
|
+
export function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
|
|
120
|
+
const dx = bx - ax;
|
|
121
|
+
const dy = by - ay;
|
|
122
|
+
const denominator = dx * dx + dy * dy;
|
|
123
|
+
const t = denominator
|
|
124
|
+
? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator))
|
|
125
|
+
: 0;
|
|
126
|
+
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
|
|
127
|
+
}
|
|
128
|
+
/** Distance in the radial/Y half-plane to a spherical profile arc selected by normal Y range. */
|
|
129
|
+
export function closestDistanceToCircleArc2D(px, py, centerY, radius, minimumNormalY, maximumNormalY) {
|
|
130
|
+
if (radius === 0)
|
|
131
|
+
return Math.hypot(px, py - centerY);
|
|
132
|
+
const dx = px;
|
|
133
|
+
const dy = py - centerY;
|
|
134
|
+
const length = Math.hypot(dx, dy);
|
|
135
|
+
const normalY = length ? dy / length : 0;
|
|
136
|
+
if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
|
|
137
|
+
return Math.abs(length - radius);
|
|
138
|
+
}
|
|
139
|
+
const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
|
|
140
|
+
const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
|
|
141
|
+
return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius * maximumNormalY)));
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=implicit-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"implicit-shape.js","sourceRoot":"","sources":["../../../src/lib/shapes/implicit-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,sBAAsB,EAAC,yDAAsD;AACrF,OAAO,EAAC,cAAc,EAAC,+CAA4C;AAyBnE,kGAAkG;AAClG,MAAM,OAAgB,iBAAiB;IAKrC,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,MAAM;YAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC;IACpD,CAAC;IAWD,MAAM,CAAC,KAAoB;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE;YAAE,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,SAA4B;QACpC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3C,oBAAoB,CAAC,I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AM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,OAAO,IAAI,cAAc,IAAI,OAAO,IAAI,cAAc,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACnC,CAAC;IACD,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/E,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,IAAI,CAAC,GAAG,CACb,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,aAAa,EAAE,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC,CAAC,EACxE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,aAAa,EAAE,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC,CAAC,CACzE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
|
|
2
|
+
import type { AxisAlignedBoundingBox } from "../bounding-volumes/axis-aligned-bounding-box.js";
|
|
3
|
+
import type { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
|
|
4
|
+
import type { Plane } from "../plane.js";
|
|
5
|
+
export type PlaneShapeProps = {
|
|
6
|
+
sizeX?: number;
|
|
7
|
+
sizeZ?: number;
|
|
8
|
+
matrix?: readonly number[];
|
|
9
|
+
};
|
|
10
|
+
/** Analytic glTF plane. The surface faces +Y and the negative-Y half-space is inside. */
|
|
11
|
+
export declare class PlaneShape extends ImplicitShapeBase {
|
|
12
|
+
readonly type: "plane";
|
|
13
|
+
readonly sizeX?: number;
|
|
14
|
+
readonly sizeZ?: number;
|
|
15
|
+
constructor(props?: PlaneShapeProps);
|
|
16
|
+
clone(): PlaneShape;
|
|
17
|
+
equals(shape: ImplicitShape): boolean;
|
|
18
|
+
containsLocalPoint(point: readonly number[]): boolean;
|
|
19
|
+
distanceToLocalPoint(point: readonly number[]): number;
|
|
20
|
+
supportLocal(): readonly number[];
|
|
21
|
+
intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
22
|
+
intersectPlane(plane: Plane): number;
|
|
23
|
+
getAxisAlignedBoundingBox(): AxisAlignedBoundingBox | undefined;
|
|
24
|
+
getBoundingSphere(): BoundingSphere | undefined;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=plane-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane-shape.d.ts","sourceRoot":"","sources":["../../../src/lib/shapes/plane-shape.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAC,4BAAyB;AAClG,OAAO,KAAK,EAAC,sBAAsB,EAAC,yDAAsD;AAC1F,OAAO,KAAK,EAAC,cAAc,EAAC,+CAA4C;AACxE,OAAO,KAAK,EAAC,KAAK,EAAC,oBAAiB;AAEpC,MAAM,MAAM,eAAe,GAAG;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAC,CAAC;AAE3F,yFAAyF;AACzF,qBAAa,UAAW,SAAQ,iBAAiB;IAC/C,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAU;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;gBACZ,KAAK,GAAE,eAAoB;IASvC,KAAK,IAAI,UAAU;IAGV,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAQ9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAGrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAGtD,YAAY,IAAI,SAAS,MAAM,EAAE;IAGjC,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;IAU1B,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAWpC,yBAAyB,IAAI,sBAAsB,GAAG,SAAS;IAG/D,iBAAiB,IAAI,cAAc,GAAG,SAAS;CAGzD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Vector3 } from '@math.gl/core';
|
|
5
|
+
import { INTERSECTION } from "../../constants.js";
|
|
6
|
+
import { ImplicitShapeBase } from "./implicit-shape.js";
|
|
7
|
+
/** Analytic glTF plane. The surface faces +Y and the negative-Y half-space is inside. */
|
|
8
|
+
export class PlaneShape extends ImplicitShapeBase {
|
|
9
|
+
constructor(props = {}) {
|
|
10
|
+
super(props.matrix);
|
|
11
|
+
this.type = 'plane';
|
|
12
|
+
this.sizeX = props.sizeX;
|
|
13
|
+
this.sizeZ = props.sizeZ;
|
|
14
|
+
if (this.sizeX !== undefined && (!Number.isFinite(this.sizeX) || this.sizeX <= 0))
|
|
15
|
+
throw new Error('Plane sizeX must be greater than zero');
|
|
16
|
+
if (this.sizeZ !== undefined && (!Number.isFinite(this.sizeZ) || this.sizeZ <= 0))
|
|
17
|
+
throw new Error('Plane sizeZ must be greater than zero');
|
|
18
|
+
}
|
|
19
|
+
clone() {
|
|
20
|
+
return new PlaneShape({ sizeX: this.sizeX, sizeZ: this.sizeZ, matrix: this.matrix });
|
|
21
|
+
}
|
|
22
|
+
equals(shape) {
|
|
23
|
+
return (shape instanceof PlaneShape &&
|
|
24
|
+
super.equals(shape) &&
|
|
25
|
+
this.sizeX === shape.sizeX &&
|
|
26
|
+
this.sizeZ === shape.sizeZ);
|
|
27
|
+
}
|
|
28
|
+
containsLocalPoint(point) {
|
|
29
|
+
return point[1] <= 1e-12;
|
|
30
|
+
}
|
|
31
|
+
distanceToLocalPoint(point) {
|
|
32
|
+
return Math.max(0, point[1]);
|
|
33
|
+
}
|
|
34
|
+
supportLocal() {
|
|
35
|
+
throw new Error('An unbounded plane half-space has no finite support point');
|
|
36
|
+
}
|
|
37
|
+
intersectLocalRay(origin, direction) {
|
|
38
|
+
if (Math.abs(direction[1]) < 1e-15)
|
|
39
|
+
return undefined;
|
|
40
|
+
const distance = -origin[1] / direction[1];
|
|
41
|
+
if (distance < 0)
|
|
42
|
+
return undefined;
|
|
43
|
+
const x = origin[0] + distance * direction[0];
|
|
44
|
+
const z = origin[2] + distance * direction[2];
|
|
45
|
+
if (this.sizeX !== undefined && Math.abs(x) > this.sizeX / 2 + 1e-12)
|
|
46
|
+
return undefined;
|
|
47
|
+
if (this.sizeZ !== undefined && Math.abs(z) > this.sizeZ / 2 + 1e-12)
|
|
48
|
+
return undefined;
|
|
49
|
+
return { distance, normal: [0, 1, 0] };
|
|
50
|
+
}
|
|
51
|
+
intersectPlane(plane) {
|
|
52
|
+
const boundaryPoint = new Vector3(0, 0, 0).transform(this.matrix);
|
|
53
|
+
const inverse = this.inverseMatrix;
|
|
54
|
+
const boundaryNormal = new Vector3(inverse[1], inverse[5], inverse[9]).normalize();
|
|
55
|
+
const alignment = boundaryNormal.dot(plane.normal);
|
|
56
|
+
if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
|
|
57
|
+
return INTERSECTION.INTERSECTING;
|
|
58
|
+
const boundaryDistance = plane.getPointDistance(boundaryPoint);
|
|
59
|
+
if (alignment < 0 && boundaryDistance > 0)
|
|
60
|
+
return INTERSECTION.INSIDE;
|
|
61
|
+
if (alignment > 0 && boundaryDistance < 0)
|
|
62
|
+
return INTERSECTION.OUTSIDE;
|
|
63
|
+
return INTERSECTION.INTERSECTING;
|
|
64
|
+
}
|
|
65
|
+
getAxisAlignedBoundingBox() {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
getBoundingSphere() {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=plane-shape.js.map
|