@math.gl/geometry 5.0.0-beta.1 → 5.0.0-beta.11
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/README.md +61 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/color/color-lut-types.d.ts +16 -0
- package/dist/color/color-lut-types.d.ts.map +1 -0
- package/dist/color/color-lut-types.js +5 -0
- package/dist/color/color-lut-types.js.map +1 -0
- package/dist/color/index.cjs +132 -0
- package/dist/color/index.cjs.map +6 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/sample-lut.d.ts +13 -0
- package/dist/color/sample-lut.d.ts.map +1 -0
- package/dist/color/sample-lut.js +132 -0
- package/dist/color/sample-lut.js.map +1 -0
- package/dist/culling/bounds.d.ts +20 -0
- package/dist/culling/bounds.d.ts.map +1 -0
- package/dist/culling/bounds.js +121 -0
- package/dist/culling/bounds.js.map +1 -0
- package/dist/culling/frustum-planes.d.ts +5 -0
- package/dist/culling/frustum-planes.d.ts.map +1 -0
- package/dist/culling/frustum-planes.js +37 -0
- package/dist/culling/frustum-planes.js.map +1 -0
- package/dist/culling/geometric-queries.d.ts +34 -0
- package/dist/culling/geometric-queries.d.ts.map +1 -0
- package/dist/culling/geometric-queries.js +208 -0
- package/dist/culling/geometric-queries.js.map +1 -0
- package/dist/culling/index.cjs +944 -508
- package/dist/culling/index.cjs.map +3 -3
- package/dist/culling/index.d.ts +7 -1
- package/dist/culling/index.d.ts.map +1 -1
- package/dist/culling/index.js +4 -0
- package/dist/culling/index.js.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/culling/lib/culling-volume.d.ts +3 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -1
- package/dist/culling/lib/culling-volume.js +7 -0
- package/dist/culling/lib/culling-volume.js.map +1 -1
- package/dist/culling/lib/ray.d.ts +5 -0
- package/dist/culling/lib/ray.d.ts.map +1 -1
- package/dist/culling/lib/ray.js +21 -0
- package/dist/culling/lib/ray.js.map +1 -1
- package/dist/culling/screen-ray.d.ts +22 -0
- package/dist/culling/screen-ray.d.ts.map +1 -0
- package/dist/culling/screen-ray.js +55 -0
- package/dist/culling/screen-ray.js.map +1 -0
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/index.d.ts +4 -0
- package/dist/curves/index.d.ts.map +1 -1
- package/dist/curves/index.js +2 -0
- package/dist/curves/index.js.map +1 -1
- package/dist/curves/parallel-transport.d.ts +12 -0
- package/dist/curves/parallel-transport.d.ts.map +1 -0
- package/dist/curves/parallel-transport.js +83 -0
- package/dist/curves/parallel-transport.js.map +1 -0
- package/dist/index.cjs +1988 -934
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/lighting/index.cjs +175 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +5 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lighting-types.d.ts +16 -0
- package/dist/lighting/lighting-types.d.ts.map +1 -0
- package/dist/lighting/lighting-types.js +5 -0
- package/dist/lighting/lighting-types.js.map +1 -0
- package/dist/lighting/photometry.d.ts +36 -0
- package/dist/lighting/photometry.d.ts.map +1 -0
- package/dist/lighting/photometry.js +181 -0
- package/dist/lighting/photometry.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -1
- package/dist/polygon/cut-by-grid.js +18 -0
- package/dist/polygon/cut-by-grid.js.map +1 -1
- package/dist/polygon/earcut.d.ts.map +1 -1
- package/dist/polygon/earcut.js +100 -34
- package/dist/polygon/earcut.js.map +1 -1
- package/dist/polygon/index.d.ts +2 -0
- package/dist/polygon/index.d.ts.map +1 -1
- package/dist/polygon/index.js +1 -0
- package/dist/polygon/index.js.map +1 -1
- package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.js +285 -0
- package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +10 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
- package/dist/polygon/subdivide-triangle-mesh.js +67 -19
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +2 -2
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -1
- package/dist/utils/compute-vertex-normals.js +3 -4
- package/dist/utils/compute-vertex-normals.js.map +1 -1
- package/dist/utils/geometry.d.ts +11 -4
- package/dist/utils/geometry.d.ts.map +1 -1
- package/dist/utils/geometry.js +19 -2
- package/dist/utils/geometry.js.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mesh-processing.d.ts +16 -6
- package/dist/utils/mesh-processing.d.ts.map +1 -1
- package/dist/utils/mesh-processing.js +9 -6
- package/dist/utils/mesh-processing.js.map +1 -1
- package/dist/utils/primitive-iterator.d.ts +16 -8
- package/dist/utils/primitive-iterator.d.ts.map +1 -1
- package/dist/utils/primitive-iterator.js +32 -35
- package/dist/utils/primitive-iterator.js.map +1 -1
- package/dist/utils/project-bounds.d.ts +44 -0
- package/dist/utils/project-bounds.d.ts.map +1 -0
- package/dist/utils/project-bounds.js +93 -0
- package/dist/utils/project-bounds.js.map +1 -0
- package/dist/utils/project-texture-coordinates.d.ts +19 -0
- package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
- package/dist/utils/project-texture-coordinates.js +49 -0
- package/dist/utils/project-texture-coordinates.js.map +1 -0
- package/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/package.json +15 -3
- package/src/color/color-lut-types.ts +19 -0
- package/src/color/index.ts +6 -0
- package/src/color/sample-lut.ts +175 -0
- package/src/culling/bounds.ts +152 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +39 -1
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
- package/src/culling/lib/culling-volume.ts +9 -1
- package/src/culling/lib/ray.ts +21 -0
- package/src/culling/screen-ray.ts +75 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/index.ts +4 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/index.ts +71 -9
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
- package/src/polygon/cut-by-grid.ts +18 -0
- package/src/polygon/earcut.ts +98 -37
- package/src/polygon/index.ts +6 -0
- package/src/polygon/pole-of-inaccessibility.ts +330 -0
- package/src/polygon/subdivide-triangle-mesh.ts +77 -17
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +5 -6
- package/src/utils/geometry.ts +32 -6
- package/src/utils/index.ts +5 -5
- package/src/utils/mesh-processing.ts +30 -14
- package/src/utils/primitive-iterator.ts +45 -43
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/dist/utils/constants.d.ts +0 -52
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js +0 -39
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/gl-type.d.ts +0 -17
- package/dist/utils/gl-type.d.ts.map +0 -1
- package/dist/utils/gl-type.js +0 -69
- package/dist/utils/gl-type.js.map +0 -1
- package/src/utils/constants.ts +0 -42
- package/src/utils/gl-type.ts +0 -87
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Matrix4} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
/** Top-origin viewport rectangle in the same units as the supplied screen position. */
|
|
8
|
+
export type ScreenRayViewport = {
|
|
9
|
+
x?: number;
|
|
10
|
+
y?: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** A finite near-to-far segment: origin + direction reaches the far endpoint. */
|
|
16
|
+
export type ScreenRay = {
|
|
17
|
+
origin: [number, number, number];
|
|
18
|
+
direction: [number, number, number];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unproject a top-origin screen position through an inverse clip matrix.
|
|
23
|
+
* The column-major matrix maps clip coordinates to the caller's output space;
|
|
24
|
+
* include any desired placement or coordinate conversion in it beforehand.
|
|
25
|
+
* The depth range defaults to WebGL/deck.gl clip coordinates [-1, 1]; use [0, 1]
|
|
26
|
+
* for a zero-to-one clip convention. Positions outside the viewport are allowed.
|
|
27
|
+
* Returns null for invalid or degenerate input or an unbounded segment.
|
|
28
|
+
*/
|
|
29
|
+
export function unprojectScreenRay(
|
|
30
|
+
inverseClipMatrix: Readonly<ArrayLike<number>>,
|
|
31
|
+
viewport: ScreenRayViewport,
|
|
32
|
+
pixel: readonly [number, number],
|
|
33
|
+
depthRange: readonly [number, number] = [-1, 1]
|
|
34
|
+
): ScreenRay | null {
|
|
35
|
+
const x = viewport.x ?? 0;
|
|
36
|
+
const y = viewport.y ?? 0;
|
|
37
|
+
if (
|
|
38
|
+
inverseClipMatrix.length !== 16 ||
|
|
39
|
+
!Array.from(inverseClipMatrix).every(Number.isFinite) ||
|
|
40
|
+
![x, y, viewport.width, viewport.height, ...pixel, ...depthRange].every(Number.isFinite) ||
|
|
41
|
+
viewport.width <= 0 ||
|
|
42
|
+
viewport.height <= 0 ||
|
|
43
|
+
pixel.length !== 2 ||
|
|
44
|
+
depthRange.length !== 2 ||
|
|
45
|
+
depthRange[0] === depthRange[1]
|
|
46
|
+
)
|
|
47
|
+
return null;
|
|
48
|
+
|
|
49
|
+
const matrix = new Matrix4(Array.from(inverseClipMatrix));
|
|
50
|
+
const determinant = matrix.determinant();
|
|
51
|
+
if (!Number.isFinite(determinant) || determinant === 0) return null;
|
|
52
|
+
const horizontal = (2 * (pixel[0] - x)) / viewport.width - 1;
|
|
53
|
+
const vertical = 1 - (2 * (pixel[1] - y)) / viewport.height;
|
|
54
|
+
const points = depthRange.map(depth => matrix.transform([horizontal, vertical, depth, 1]));
|
|
55
|
+
if (points.some(point => point[3] === 0 || !point.every(Number.isFinite))) return null;
|
|
56
|
+
// A sign change crosses w=0 between endpoints, so the projected segment is unbounded.
|
|
57
|
+
if (points[0][3] < 0 !== points[1][3] < 0) return null;
|
|
58
|
+
const origin: [number, number, number] = [
|
|
59
|
+
points[0][0] / points[0][3],
|
|
60
|
+
points[0][1] / points[0][3],
|
|
61
|
+
points[0][2] / points[0][3]
|
|
62
|
+
];
|
|
63
|
+
const direction: [number, number, number] = [
|
|
64
|
+
points[1][0] / points[1][3] - origin[0],
|
|
65
|
+
points[1][1] / points[1][3] - origin[1],
|
|
66
|
+
points[1][2] / points[1][3] - origin[2]
|
|
67
|
+
];
|
|
68
|
+
const distance = Math.hypot(...direction);
|
|
69
|
+
return origin.every(Number.isFinite) &&
|
|
70
|
+
direction.every(Number.isFinite) &&
|
|
71
|
+
Number.isFinite(distance) &&
|
|
72
|
+
distance > 0
|
|
73
|
+
? {origin, direction}
|
|
74
|
+
: null;
|
|
75
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {Curve} from './curve';
|
|
5
|
+
|
|
6
|
+
export type AdaptiveCurveOptions = {
|
|
7
|
+
tolerance: number;
|
|
8
|
+
maxDepth?: number;
|
|
9
|
+
maxPoints?: number;
|
|
10
|
+
};
|
|
11
|
+
export type AdaptiveCurveSamples = {
|
|
12
|
+
parameters: Float64Array;
|
|
13
|
+
positions: Float64Array;
|
|
14
|
+
/** False means a work limit prevented meeting the sampled chord-error criterion. */
|
|
15
|
+
converged: boolean;
|
|
16
|
+
maxSampledError: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Quarter/midpoint chord-error sampling. This is not a certified bound for arbitrary curves. */
|
|
20
|
+
export function sampleCurveAdaptive(
|
|
21
|
+
curve: Curve,
|
|
22
|
+
options: AdaptiveCurveOptions
|
|
23
|
+
): AdaptiveCurveSamples {
|
|
24
|
+
const {tolerance, maxDepth = 16, maxPoints = 65536} = options;
|
|
25
|
+
if (
|
|
26
|
+
!Number.isFinite(tolerance) ||
|
|
27
|
+
tolerance <= 0 ||
|
|
28
|
+
!Number.isInteger(maxDepth) ||
|
|
29
|
+
maxDepth < 0 ||
|
|
30
|
+
maxDepth > 30 ||
|
|
31
|
+
!Number.isSafeInteger(maxPoints) ||
|
|
32
|
+
maxPoints < 2
|
|
33
|
+
)
|
|
34
|
+
throw new RangeError('Invalid adaptive sampling budget');
|
|
35
|
+
const parameters = [0],
|
|
36
|
+
positions = [...curve.getPoint(0)];
|
|
37
|
+
let converged = true,
|
|
38
|
+
maxSampledError = 0;
|
|
39
|
+
const stack = [{t0: 0, t1: 1, a: curve.getPoint(0), b: curve.getPoint(1), depth: 0}];
|
|
40
|
+
while (stack.length) {
|
|
41
|
+
const segment = stack.pop()!;
|
|
42
|
+
const {t0, t1, a, b, depth} = segment;
|
|
43
|
+
const localEdge = b.map((x, i) => x - a[i]);
|
|
44
|
+
const samples = [0.25, 0.5, 0.75].map(f => curve.getPoint(t0 + (t1 - t0) * f));
|
|
45
|
+
const localSamples = samples.map(point => point.map((x, i) => x - a[i]));
|
|
46
|
+
const local = [...localEdge, ...localSamples.flat()].every(Number.isFinite);
|
|
47
|
+
const scale = local
|
|
48
|
+
? Math.max(...localEdge.map(Math.abs), ...localSamples.flat().map(Math.abs), Number.MIN_VALUE)
|
|
49
|
+
: Math.max(...a.map(Math.abs), ...b.map(Math.abs), ...samples.flat().map(Math.abs));
|
|
50
|
+
const edge = local ? localEdge.map(x => x / scale) : b.map((x, i) => x / scale - a[i] / scale);
|
|
51
|
+
const squared = edge.reduce((sum, x) => sum + x * x, 0);
|
|
52
|
+
const measuredError = Math.max(
|
|
53
|
+
...samples.map((p, sampleIndex) => {
|
|
54
|
+
const offset = local
|
|
55
|
+
? localSamples[sampleIndex].map(x => x / scale)
|
|
56
|
+
: p.map((x, i) => x / scale - a[i] / scale);
|
|
57
|
+
const t = squared
|
|
58
|
+
? Math.max(0, Math.min(1, edge.reduce((sum, x, i) => sum + x * offset[i], 0) / squared))
|
|
59
|
+
: 0;
|
|
60
|
+
return Math.hypot(...offset.map((x, i) => x - t * edge[i])) * scale;
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
const error = Number.isFinite(measuredError) ? measuredError : Infinity;
|
|
64
|
+
if (
|
|
65
|
+
error > tolerance &&
|
|
66
|
+
depth < maxDepth &&
|
|
67
|
+
parameters.length + stack.length + 2 <= maxPoints
|
|
68
|
+
) {
|
|
69
|
+
const mid = (t0 + t1) / 2;
|
|
70
|
+
stack.push({t0: mid, t1, a: samples[1], b, depth: depth + 1});
|
|
71
|
+
stack.push({t0, t1: mid, a, b: samples[1], depth: depth + 1});
|
|
72
|
+
} else {
|
|
73
|
+
if (error > tolerance) converged = false;
|
|
74
|
+
maxSampledError = Math.max(maxSampledError, error);
|
|
75
|
+
parameters.push(t1);
|
|
76
|
+
positions.push(...b);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
parameters: new Float64Array(parameters),
|
|
81
|
+
positions: new Float64Array(positions),
|
|
82
|
+
converged,
|
|
83
|
+
maxSampledError
|
|
84
|
+
};
|
|
85
|
+
}
|
package/src/curves/index.ts
CHANGED
|
@@ -13,3 +13,7 @@ export {HermiteCurve} from './hermite-curve';
|
|
|
13
13
|
export {CatmullRomCurve} from './catmull-rom-curve';
|
|
14
14
|
export type {CatmullRomCurveOptions} from './catmull-rom-curve';
|
|
15
15
|
export {CurveArcLength} from './curve-arc-length';
|
|
16
|
+
export {sampleCurveAdaptive} from './adaptive-sampling';
|
|
17
|
+
export type {AdaptiveCurveOptions, AdaptiveCurveSamples} from './adaptive-sampling';
|
|
18
|
+
export {computeParallelTransportFrames} from './parallel-transport';
|
|
19
|
+
export type {CurveFrames} from './parallel-transport';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {CurvePoint} from './curve';
|
|
5
|
+
|
|
6
|
+
export type CurveFrames = {tangents: Float64Array; normals: Float64Array; binormals: Float64Array};
|
|
7
|
+
type V = number[];
|
|
8
|
+
const sub = (a: V, b: V) => a.map((x, i) => x - b[i]);
|
|
9
|
+
const dot = (a: V, b: V) => a.reduce((sum, x, i) => sum + x * b[i], 0);
|
|
10
|
+
const cross = (a: V, b: V): V => [
|
|
11
|
+
a[1] * b[2] - a[2] * b[1],
|
|
12
|
+
a[2] * b[0] - a[0] * b[2],
|
|
13
|
+
a[0] * b[1] - a[1] * b[0]
|
|
14
|
+
];
|
|
15
|
+
const unit = (a: V) => {
|
|
16
|
+
const length = Math.hypot(...a);
|
|
17
|
+
if (!length) throw new RangeError('Cannot construct a frame for a stationary path');
|
|
18
|
+
return a.map(x => x / length);
|
|
19
|
+
};
|
|
20
|
+
function rotate(v: V, axis: V, angle: number): V {
|
|
21
|
+
const c = Math.cos(angle),
|
|
22
|
+
s = Math.sin(angle),
|
|
23
|
+
d = dot(axis, v),
|
|
24
|
+
k = cross(axis, v);
|
|
25
|
+
return v.map((x, i) => x * c + k[i] * s + axis[i] * d * (1 - c));
|
|
26
|
+
}
|
|
27
|
+
/** Frames on a 3D polyline; repeated points inherit a neighboring direction. Closed paths repeat the first point. */
|
|
28
|
+
export function computeParallelTransportFrames(
|
|
29
|
+
points: readonly CurvePoint[],
|
|
30
|
+
options: {closed?: boolean; initialNormal?: CurvePoint} = {}
|
|
31
|
+
): CurveFrames {
|
|
32
|
+
if (
|
|
33
|
+
points.length < 2 ||
|
|
34
|
+
points.some(p => p.length !== 3 || Array.from(p).some(x => !Number.isFinite(x)))
|
|
35
|
+
)
|
|
36
|
+
throw new RangeError('Expected at least two finite 3D points');
|
|
37
|
+
const data = points.map(p => Array.from(p)),
|
|
38
|
+
n = data.length,
|
|
39
|
+
closed = options.closed ?? false;
|
|
40
|
+
if (closed && (n < 4 || Math.hypot(...sub(data[0], data[n - 1])) !== 0))
|
|
41
|
+
throw new RangeError('A closed path must repeat its first point');
|
|
42
|
+
// Cache adjacent nonzero directions, then propagate backwards across equal runs.
|
|
43
|
+
// This keeps repeated-point paths linear rather than rescanning each suffix.
|
|
44
|
+
const tangent: V[] = new Array(n);
|
|
45
|
+
const edges: (V | undefined)[] = new Array(n - 1);
|
|
46
|
+
let last: V | undefined;
|
|
47
|
+
for (let i = 0; i < n - 1; i++) {
|
|
48
|
+
const edge = sub(data[i + 1], data[i]);
|
|
49
|
+
if (Math.hypot(...edge) > 0) last = edges[i] = unit(edge);
|
|
50
|
+
}
|
|
51
|
+
if (!last) throw new RangeError('Cannot construct a frame for a stationary path');
|
|
52
|
+
tangent[n - 1] = last;
|
|
53
|
+
for (let i = n - 2; i >= 0; i--) {
|
|
54
|
+
last = edges[i] ?? last;
|
|
55
|
+
tangent[i] = last;
|
|
56
|
+
}
|
|
57
|
+
if (closed) tangent[n - 1] = [...tangent[0]];
|
|
58
|
+
const t = tangent[0];
|
|
59
|
+
let initial = options.initialNormal ? Array.from(options.initialNormal) : [0, 0, 0];
|
|
60
|
+
if (options.initialNormal && (initial.length !== 3 || initial.some(x => !Number.isFinite(x))))
|
|
61
|
+
throw new RangeError('Invalid initial normal');
|
|
62
|
+
// Select an axis by absolute alignment (including negative tangent components).
|
|
63
|
+
if (!options.initialNormal) {
|
|
64
|
+
initial = [0, 0, 0];
|
|
65
|
+
initial[t.map(Math.abs).indexOf(Math.min(...t.map(Math.abs)))] = 1;
|
|
66
|
+
}
|
|
67
|
+
initial = unit(initial);
|
|
68
|
+
const perpendicular = cross(t, initial);
|
|
69
|
+
if (Math.hypot(...perpendicular) <= 1e-12) {
|
|
70
|
+
throw new RangeError('Initial normal must not be parallel to the tangent');
|
|
71
|
+
}
|
|
72
|
+
// A double cross product avoids normalizing a cancellation residual along t.
|
|
73
|
+
const normals: V[] = [unit(cross(perpendicular, t))];
|
|
74
|
+
for (let i = 1; i < n; i++) {
|
|
75
|
+
const axis = cross(tangent[i - 1], tangent[i]),
|
|
76
|
+
length = Math.hypot(...axis),
|
|
77
|
+
cosine = Math.max(-1, Math.min(1, dot(tangent[i - 1], tangent[i])));
|
|
78
|
+
let normal = normals[i - 1];
|
|
79
|
+
if (length > 1e-12)
|
|
80
|
+
normal = rotate(
|
|
81
|
+
normal,
|
|
82
|
+
axis.map(x => x / length),
|
|
83
|
+
Math.atan2(length, cosine)
|
|
84
|
+
);
|
|
85
|
+
// At an exact reversal the previous normal defines the deterministic 180-degree axis.
|
|
86
|
+
normals.push(unit(normal.map((x, j) => x - dot(normal, tangent[i]) * tangent[i][j])));
|
|
87
|
+
}
|
|
88
|
+
if (closed) {
|
|
89
|
+
const mismatch = Math.atan2(
|
|
90
|
+
dot(tangent[0], cross(normals[n - 1], normals[0])),
|
|
91
|
+
dot(normals[n - 1], normals[0])
|
|
92
|
+
);
|
|
93
|
+
const lengths = [0];
|
|
94
|
+
for (let i = 1; i < n; i++)
|
|
95
|
+
lengths.push(lengths[i - 1] + Math.hypot(...sub(data[i], data[i - 1])));
|
|
96
|
+
for (let i = 1; i < n; i++)
|
|
97
|
+
normals[i] = rotate(normals[i], tangent[i], (mismatch * lengths[i]) / lengths[n - 1]);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
tangents: new Float64Array(tangent.flat()),
|
|
101
|
+
normals: new Float64Array(normals.flat()),
|
|
102
|
+
binormals: new Float64Array(normals.flatMap((normal, i) => cross(tangent[i], normal)))
|
|
103
|
+
};
|
|
104
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,17 @@ export type {HingePanel} from './lib/hinge-tree';
|
|
|
16
16
|
export {unpackIndexedGeometry} from './lib/geometry-utils';
|
|
17
17
|
|
|
18
18
|
export {BoxGeometry, CubeGeometry} from './geometries/box-geometry';
|
|
19
|
-
export type {
|
|
19
|
+
export type {
|
|
20
|
+
BoxGeometryProps,
|
|
21
|
+
CubeGeometryProps
|
|
22
|
+
} from './geometries/box-geometry';
|
|
20
23
|
export {CapsuleGeometry} from './geometries/capsule-geometry';
|
|
21
24
|
export type {CapsuleGeometryProps} from './geometries/capsule-geometry';
|
|
22
25
|
export {CylinderGeometry, ConeGeometry} from './geometries/cylinder-geometry';
|
|
23
|
-
export type {
|
|
26
|
+
export type {
|
|
27
|
+
CylinderGeometryProps,
|
|
28
|
+
ConeGeometryProps
|
|
29
|
+
} from './geometries/cylinder-geometry';
|
|
24
30
|
export {PlaneGeometry} from './geometries/plane-geometry';
|
|
25
31
|
export type {PlaneGeometryProps} from './geometries/plane-geometry';
|
|
26
32
|
export {SphereGeometry} from './geometries/sphere-geometry';
|
|
@@ -45,11 +51,6 @@ export type {
|
|
|
45
51
|
LatheGeometryProps
|
|
46
52
|
} from './parametric';
|
|
47
53
|
export {
|
|
48
|
-
GL,
|
|
49
|
-
GL_TYPE,
|
|
50
|
-
GL_PRIMITIVE,
|
|
51
|
-
GL_PRIMITIVE_MODE,
|
|
52
|
-
GLType,
|
|
53
54
|
isGeometry,
|
|
54
55
|
makeAttributeIterator,
|
|
55
56
|
makePrimitiveIterator,
|
|
@@ -109,6 +110,8 @@ export {
|
|
|
109
110
|
earcut,
|
|
110
111
|
clipPolygon,
|
|
111
112
|
clipPolyline,
|
|
113
|
+
getPoleOfInaccessibility,
|
|
114
|
+
DEFAULT_POLE_SEARCH_SEGMENT_TESTS,
|
|
112
115
|
cutPolygonByGrid,
|
|
113
116
|
cutPolylineByGrid,
|
|
114
117
|
cutPolylineByMercatorBounds,
|
|
@@ -119,6 +122,7 @@ export {
|
|
|
119
122
|
export type {
|
|
120
123
|
PolygonWinding,
|
|
121
124
|
WindingDirection,
|
|
125
|
+
PoleSearchBudget,
|
|
122
126
|
SubdividePolylineOptions,
|
|
123
127
|
SubdividedPolyline,
|
|
124
128
|
PolylineEdgeSampler,
|
|
@@ -154,6 +158,7 @@ export {
|
|
|
154
158
|
export type {
|
|
155
159
|
CullingResult,
|
|
156
160
|
ImplicitShape,
|
|
161
|
+
Shape,
|
|
157
162
|
RayIntersection,
|
|
158
163
|
BoxShapeProps,
|
|
159
164
|
CapsuleShapeProps,
|
|
@@ -171,7 +176,10 @@ export {
|
|
|
171
176
|
getClosestPointsOnSegments,
|
|
172
177
|
getClosestPointsSegmentTriangle
|
|
173
178
|
} from './culling/queries';
|
|
174
|
-
export type {
|
|
179
|
+
export type {
|
|
180
|
+
SegmentClosestPoints,
|
|
181
|
+
SegmentTriangleClosestPoints
|
|
182
|
+
} from './culling/queries';
|
|
175
183
|
export {BoxIndex, PointIndex, TriangleBVH} from './spatial-index/index';
|
|
176
184
|
export type {
|
|
177
185
|
BoxIndexOptions,
|
|
@@ -190,7 +198,7 @@ export type {
|
|
|
190
198
|
} from './spatial-index/index';
|
|
191
199
|
|
|
192
200
|
export type {
|
|
193
|
-
|
|
201
|
+
GeometryInput,
|
|
194
202
|
GeometryAttribute as UtilityGeometryAttribute
|
|
195
203
|
} from './utils/geometry';
|
|
196
204
|
|
|
@@ -200,3 +208,57 @@ export type {
|
|
|
200
208
|
ClipTriangleMeshOptions,
|
|
201
209
|
ClippedTriangleMesh
|
|
202
210
|
} from './polygon/clip-triangle-mesh';
|
|
211
|
+
|
|
212
|
+
export {composeAttributeProvenance} from './utils/compose-attribute-provenance';
|
|
213
|
+
export {qualifySurfaceTransition} from './utils/qualify-surface-transition';
|
|
214
|
+
export type {SurfaceTransitionQualification} from './utils/qualify-surface-transition';
|
|
215
|
+
|
|
216
|
+
export {
|
|
217
|
+
extractFrustumPlanes,
|
|
218
|
+
createEmptyBounds,
|
|
219
|
+
isEmptyBounds,
|
|
220
|
+
boundsContainsPoint,
|
|
221
|
+
boundsContainsBounds,
|
|
222
|
+
boundsIntersect,
|
|
223
|
+
unionBounds,
|
|
224
|
+
intersectBounds,
|
|
225
|
+
expandBoundsByPoint,
|
|
226
|
+
expandBounds,
|
|
227
|
+
clampPointToBounds,
|
|
228
|
+
spheresIntersect,
|
|
229
|
+
boundsIntersectSphere
|
|
230
|
+
} from './culling/index';
|
|
231
|
+
export {
|
|
232
|
+
getRayPoint,
|
|
233
|
+
getClosestPointOnRay,
|
|
234
|
+
distanceToRay,
|
|
235
|
+
getClosestPointsRaySegment,
|
|
236
|
+
transformRay,
|
|
237
|
+
getTriangleBarycentric,
|
|
238
|
+
getTriangleArea,
|
|
239
|
+
getTriangleNormal,
|
|
240
|
+
isTriangleFrontFacing,
|
|
241
|
+
triangleContainsPoint,
|
|
242
|
+
interpolateTriangleAttribute,
|
|
243
|
+
intersectPlaneSegment,
|
|
244
|
+
triangleIntersectsBounds
|
|
245
|
+
} from './culling/geometric-queries';
|
|
246
|
+
export type {RaySegmentClosestPoints} from './culling/geometric-queries';
|
|
247
|
+
export {
|
|
248
|
+
sampleCurveAdaptive,
|
|
249
|
+
computeParallelTransportFrames
|
|
250
|
+
} from './curves/index';
|
|
251
|
+
export type {
|
|
252
|
+
AdaptiveCurveOptions,
|
|
253
|
+
AdaptiveCurveSamples,
|
|
254
|
+
CurveFrames
|
|
255
|
+
} from './curves/index';
|
|
256
|
+
|
|
257
|
+
export {projectBounds} from './utils/project-bounds';
|
|
258
|
+
export type {
|
|
259
|
+
ProjectionSourceBounds,
|
|
260
|
+
ProjectBoundsOptions,
|
|
261
|
+
ProjectedBoundsResult
|
|
262
|
+
} from './utils/project-bounds';
|
|
263
|
+
export {projectTextureCoordinates} from './utils/project-texture-coordinates';
|
|
264
|
+
export type {ProjectTextureCoordinatesOptions} from './utils/project-texture-coordinates';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
export {
|
|
5
|
+
createPhotometricSampler,
|
|
6
|
+
integrateLuminousFlux,
|
|
7
|
+
resamplePhotometricProfile
|
|
8
|
+
} from './photometry';
|
|
9
|
+
export type {PhotometricSampler, PhotometricGrid, PhotometricResampleOptions} from './photometry';
|
|
10
|
+
export type {PhotometricProfile, PhotometricSymmetry} from './lighting-types';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Explicit azimuth extension rule; never inferred from a file or its metadata. */
|
|
6
|
+
export type PhotometricSymmetry = 'rotational' | 'quadrant' | 'bilateral' | 'none';
|
|
7
|
+
|
|
8
|
+
/** Format-independent polar/azimuth intensity measurements in degrees and candela. */
|
|
9
|
+
export type PhotometricProfile = {
|
|
10
|
+
/** Ordered polar angles in [0, 180], measured from an application-chosen pole. */
|
|
11
|
+
verticalAngles: ArrayLike<number>;
|
|
12
|
+
/** Ordered azimuth angles in [0, 360], relative to an application-chosen origin. */
|
|
13
|
+
horizontalAngles: ArrayLike<number>;
|
|
14
|
+
/** Candela samples, vertical angle varying fastest. */
|
|
15
|
+
intensities: ArrayLike<number>;
|
|
16
|
+
/** Uniform intensity multiplier; default 1. No lamp, ballast or file metadata is read. */
|
|
17
|
+
intensityScale?: number;
|
|
18
|
+
/** Explicit rotational, quadrant, bilateral or full-circle interpretation. */
|
|
19
|
+
symmetry: PhotometricSymmetry;
|
|
20
|
+
};
|