@math.gl/geometry 5.0.0-beta.4 → 5.0.0-beta.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/README.md +58 -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 +917 -514
- package/dist/culling/index.cjs.map +3 -3
- package/dist/culling/index.d.ts +5 -1
- package/dist/culling/index.d.ts.map +1 -1
- package/dist/culling/index.js +3 -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/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 +1225 -699
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- 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/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 +37 -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/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 +35 -0
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
package/src/culling/index.ts
CHANGED
|
@@ -11,7 +11,11 @@ export {CullingVolume} from './lib/culling-volume';
|
|
|
11
11
|
export {Plane} from './lib/plane';
|
|
12
12
|
export {Ray} from './lib/ray';
|
|
13
13
|
|
|
14
|
-
export type {
|
|
14
|
+
export type {
|
|
15
|
+
ImplicitShape,
|
|
16
|
+
ImplicitShape as Shape,
|
|
17
|
+
RayIntersection
|
|
18
|
+
} from './lib/shapes/implicit-shape';
|
|
15
19
|
export {BoxShape} from './lib/shapes/box-shape';
|
|
16
20
|
export type {BoxShapeProps} from './lib/shapes/box-shape';
|
|
17
21
|
export {CapsuleShape} from './lib/shapes/capsule-shape';
|
|
@@ -55,3 +59,35 @@ export {
|
|
|
55
59
|
getClosestPointsSegmentTriangle
|
|
56
60
|
} from './queries';
|
|
57
61
|
export type {SegmentClosestPoints, SegmentTriangleClosestPoints} from './queries';
|
|
62
|
+
|
|
63
|
+
export {extractFrustumPlanes} from './frustum-planes';
|
|
64
|
+
export {
|
|
65
|
+
createEmptyBounds,
|
|
66
|
+
isEmptyBounds,
|
|
67
|
+
boundsContainsPoint,
|
|
68
|
+
boundsContainsBounds,
|
|
69
|
+
boundsIntersect,
|
|
70
|
+
unionBounds,
|
|
71
|
+
intersectBounds,
|
|
72
|
+
expandBoundsByPoint,
|
|
73
|
+
expandBounds,
|
|
74
|
+
clampPointToBounds,
|
|
75
|
+
spheresIntersect,
|
|
76
|
+
boundsIntersectSphere
|
|
77
|
+
} from './bounds';
|
|
78
|
+
export {
|
|
79
|
+
getRayPoint,
|
|
80
|
+
getClosestPointOnRay,
|
|
81
|
+
distanceToRay,
|
|
82
|
+
getClosestPointsRaySegment,
|
|
83
|
+
transformRay,
|
|
84
|
+
getTriangleBarycentric,
|
|
85
|
+
getTriangleArea,
|
|
86
|
+
getTriangleNormal,
|
|
87
|
+
isTriangleFrontFacing,
|
|
88
|
+
triangleContainsPoint,
|
|
89
|
+
interpolateTriangleAttribute,
|
|
90
|
+
intersectPlaneSegment,
|
|
91
|
+
triangleIntersectsBounds
|
|
92
|
+
} from './geometric-queries';
|
|
93
|
+
export type {RaySegmentClosestPoints} from './geometric-queries';
|
|
@@ -83,16 +83,34 @@ export class AxisAlignedBoundingBox implements BoundingVolume {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
* @param transform The transformation matrix
|
|
88
|
-
* @returns itself, i.e. the modified
|
|
86
|
+
* Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
|
|
87
|
+
* @param transform The affine transformation matrix.
|
|
88
|
+
* @returns itself, i.e. the modified bounding box.
|
|
89
89
|
*/
|
|
90
90
|
transform(transform: readonly number[]): this {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
if (
|
|
92
|
+
transform.length !== 16 ||
|
|
93
|
+
transform.some(x => !Number.isFinite(x)) ||
|
|
94
|
+
transform[3] !== 0 ||
|
|
95
|
+
transform[7] !== 0 ||
|
|
96
|
+
transform[11] !== 0 ||
|
|
97
|
+
transform[15] !== 1
|
|
98
|
+
) {
|
|
99
|
+
throw new RangeError('Expected a finite affine matrix');
|
|
100
|
+
}
|
|
101
|
+
const center = this.minimum.clone().add(this.maximum).scale(0.5);
|
|
102
|
+
const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
|
|
103
|
+
if (extent.some(x => x < 0)) throw new RangeError('Bounds must be ordered');
|
|
104
|
+
center.transformAsPoint(transform);
|
|
105
|
+
for (let row = 0; row < 3; row++) {
|
|
106
|
+
this.halfDiagonal[row] =
|
|
107
|
+
Math.abs(transform[row]) * extent[0] +
|
|
108
|
+
Math.abs(transform[row + 4]) * extent[1] +
|
|
109
|
+
Math.abs(transform[row + 8]) * extent[2];
|
|
110
|
+
}
|
|
111
|
+
this.center.copy(center);
|
|
112
|
+
this.minimum.copy(center).subtract(this.halfDiagonal);
|
|
113
|
+
this.maximum.copy(center).add(this.halfDiagonal);
|
|
96
114
|
return this;
|
|
97
115
|
}
|
|
98
116
|
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
9
|
|
|
10
10
|
/* eslint-disable */
|
|
11
|
-
import {Vector3, assert} from '@math.gl/core';
|
|
11
|
+
import {Vector3, assert, type ProjectionDepthOptions} from '@math.gl/core';
|
|
12
|
+
import {extractFrustumPlanes} from '../frustum-planes';
|
|
12
13
|
import type {CullingResult} from '../constants';
|
|
13
14
|
import {Plane} from './plane';
|
|
14
15
|
import type {BoundingVolume} from './bounding-volumes/bounding-volume';
|
|
@@ -94,6 +95,13 @@ export class CullingVolume {
|
|
|
94
95
|
return this;
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
/** Replace planes from a view-projection matrix; validates before mutating. */
|
|
99
|
+
fromViewProjection(matrix: ArrayLike<number>, options: ProjectionDepthOptions = {}): this {
|
|
100
|
+
const planes = extractFrustumPlanes(matrix, options);
|
|
101
|
+
this.planes.splice(0, this.planes.length, ...planes);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
/** Determines whether a bounding volume intersects the culling volume. */
|
|
98
106
|
computeVisibility(boundingVolume: BoundingVolume): CullingResult {
|
|
99
107
|
// const planes = this.planes;
|
package/src/culling/lib/ray.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
9
|
|
|
10
10
|
import {Vector3} from '@math.gl/core';
|
|
11
|
+
import {normalizeQueryDirection} from '../queries';
|
|
12
|
+
import {getRayPoint, getClosestPointOnRay, distanceToRay, transformRay} from '../geometric-queries';
|
|
11
13
|
|
|
12
14
|
/* Represents a ray that extends infinitely from the provided origin in the provided direction. */
|
|
13
15
|
export class Ray {
|
|
@@ -30,4 +32,23 @@ export class Ray {
|
|
|
30
32
|
this.origin = origin;
|
|
31
33
|
this.direction = direction;
|
|
32
34
|
}
|
|
35
|
+
at(t: number, result = new Vector3()): Vector3 {
|
|
36
|
+
getRayPoint(this.origin, this.direction, t, result);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
closestPointTo(point: readonly number[], result = new Vector3()): Vector3 {
|
|
40
|
+
getClosestPointOnRay(point, this.origin, this.direction, result);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
distanceTo(point: readonly number[]): number {
|
|
44
|
+
return distanceToRay(point, this.origin, this.direction);
|
|
45
|
+
}
|
|
46
|
+
/** Transform and renormalize: subsequent parameters are distances in the new space. */
|
|
47
|
+
transform(matrix: readonly number[]): this {
|
|
48
|
+
const ray = transformRay(this.origin, this.direction, matrix);
|
|
49
|
+
const normalized = normalizeQueryDirection(ray.direction, 3);
|
|
50
|
+
this.origin.copy(ray.origin);
|
|
51
|
+
this.direction.copy(normalized);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
33
54
|
}
|
|
@@ -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
|
@@ -154,6 +154,7 @@ export {
|
|
|
154
154
|
export type {
|
|
155
155
|
CullingResult,
|
|
156
156
|
ImplicitShape,
|
|
157
|
+
Shape,
|
|
157
158
|
RayIntersection,
|
|
158
159
|
BoxShapeProps,
|
|
159
160
|
CapsuleShapeProps,
|
|
@@ -204,3 +205,37 @@ export type {
|
|
|
204
205
|
export {composeAttributeProvenance} from './utils/compose-attribute-provenance';
|
|
205
206
|
export {qualifySurfaceTransition} from './utils/qualify-surface-transition';
|
|
206
207
|
export type {SurfaceTransitionQualification} from './utils/qualify-surface-transition';
|
|
208
|
+
|
|
209
|
+
export {
|
|
210
|
+
extractFrustumPlanes,
|
|
211
|
+
createEmptyBounds,
|
|
212
|
+
isEmptyBounds,
|
|
213
|
+
boundsContainsPoint,
|
|
214
|
+
boundsContainsBounds,
|
|
215
|
+
boundsIntersect,
|
|
216
|
+
unionBounds,
|
|
217
|
+
intersectBounds,
|
|
218
|
+
expandBoundsByPoint,
|
|
219
|
+
expandBounds,
|
|
220
|
+
clampPointToBounds,
|
|
221
|
+
spheresIntersect,
|
|
222
|
+
boundsIntersectSphere
|
|
223
|
+
} from './culling/index';
|
|
224
|
+
export {
|
|
225
|
+
getRayPoint,
|
|
226
|
+
getClosestPointOnRay,
|
|
227
|
+
distanceToRay,
|
|
228
|
+
getClosestPointsRaySegment,
|
|
229
|
+
transformRay,
|
|
230
|
+
getTriangleBarycentric,
|
|
231
|
+
getTriangleArea,
|
|
232
|
+
getTriangleNormal,
|
|
233
|
+
isTriangleFrontFacing,
|
|
234
|
+
triangleContainsPoint,
|
|
235
|
+
interpolateTriangleAttribute,
|
|
236
|
+
intersectPlaneSegment,
|
|
237
|
+
triangleIntersectsBounds
|
|
238
|
+
} from './culling/geometric-queries';
|
|
239
|
+
export type {RaySegmentClosestPoints} from './culling/geometric-queries';
|
|
240
|
+
export {sampleCurveAdaptive, computeParallelTransportFrames} from './curves/index';
|
|
241
|
+
export type {AdaptiveCurveOptions, AdaptiveCurveSamples, CurveFrames} from './curves/index';
|
|
@@ -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
|
+
};
|