@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,169 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {TriangleMesh} from '../polygon/subdivide-triangle-mesh';
|
|
5
|
+
|
|
6
|
+
export type SurfaceTransitionQualification = {
|
|
7
|
+
/** A fixed indexed disk stays a graph over XY throughout linear vertex interpolation. */
|
|
8
|
+
scope: 'convex-xy-disk-linear';
|
|
9
|
+
minimumProjectedDoubleArea: number;
|
|
10
|
+
boundary: Uint32Array;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Qualify a conservative subset of 3D mesh morphs, without time sampling.
|
|
14
|
+
* Input is an oriented, connected triangulated disk. Both endpoints share indices.
|
|
15
|
+
* Every triangle must retain positive XY orientation and the boundary must stay
|
|
16
|
+
* convex throughout linear vertex motion. Quadratic extrema test the full [0,1].
|
|
17
|
+
* This excludes holes, folded surfaces, most global globe meshes and curved vertex
|
|
18
|
+
* trajectories. It qualifies the piecewise-linear mesh, not its underlying smooth
|
|
19
|
+
* projection or a camera's approximation error. Floating-point margins reject
|
|
20
|
+
* near-degeneracy; this is not a formal interval-arithmetic certificate.
|
|
21
|
+
*/
|
|
22
|
+
export function qualifySurfaceTransition(
|
|
23
|
+
mesh: TriangleMesh,
|
|
24
|
+
targetPositions: ArrayLike<number>,
|
|
25
|
+
options: {minimumDoubleArea?: number; maxChecks?: number} = {}
|
|
26
|
+
): SurfaceTransitionQualification {
|
|
27
|
+
const from = Array.from(mesh.positions),
|
|
28
|
+
to = Array.from(targetPositions),
|
|
29
|
+
indices = Array.from(mesh.indices),
|
|
30
|
+
count = from.length / 3,
|
|
31
|
+
maxChecks = options.maxChecks ?? 1000000;
|
|
32
|
+
if (
|
|
33
|
+
!from.length ||
|
|
34
|
+
from.length % 3 ||
|
|
35
|
+
to.length !== from.length ||
|
|
36
|
+
!indices.length ||
|
|
37
|
+
indices.length % 3 ||
|
|
38
|
+
!from.every(Number.isFinite) ||
|
|
39
|
+
!to.every(Number.isFinite) ||
|
|
40
|
+
!indices.every(i => Number.isSafeInteger(i) && i >= 0 && i < count) ||
|
|
41
|
+
!Number.isSafeInteger(maxChecks) ||
|
|
42
|
+
maxChecks < 0
|
|
43
|
+
)
|
|
44
|
+
throw new RangeError('Invalid surface transition mesh or budget');
|
|
45
|
+
let scale = 0;
|
|
46
|
+
for (const positions of [from, to])
|
|
47
|
+
for (let i = 0; i < indices.length; i += 3)
|
|
48
|
+
for (let j = 0; j < 3; j++) {
|
|
49
|
+
const a = indices[i + j] * 3,
|
|
50
|
+
b = indices[i + ((j + 1) % 3)] * 3;
|
|
51
|
+
scale = Math.max(
|
|
52
|
+
scale,
|
|
53
|
+
Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1])
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
|
|
57
|
+
if (!Number.isFinite(margin) || margin <= 0)
|
|
58
|
+
throw new RangeError('Expected positive finite area margin');
|
|
59
|
+
let checks = 0;
|
|
60
|
+
const tick = () => {
|
|
61
|
+
if (++checks > maxChecks) throw new RangeError('Surface qualification exceeded maxChecks');
|
|
62
|
+
};
|
|
63
|
+
const edges = new Map<string, {a: number; b: number; faces: number}>(),
|
|
64
|
+
used = new Set(indices);
|
|
65
|
+
let minimum = Infinity;
|
|
66
|
+
const orientation = (a: number, b: number, c: number, t: number) => {
|
|
67
|
+
// Interpolate relative edges, avoiding cancellation from translating a patch
|
|
68
|
+
// across large world-coordinate origins before subtracting vertex positions.
|
|
69
|
+
const edge = (v: number, k: number) =>
|
|
70
|
+
(from[3 * v + k] - from[3 * a + k]) * (1 - t) + (to[3 * v + k] - to[3 * a + k]) * t;
|
|
71
|
+
return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
|
|
72
|
+
};
|
|
73
|
+
const minimumOrientation = (a: number, b: number, c: number) => {
|
|
74
|
+
tick();
|
|
75
|
+
return quadraticMinimum(t => orientation(a, b, c, t));
|
|
76
|
+
};
|
|
77
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
78
|
+
const tri = indices.slice(i, i + 3);
|
|
79
|
+
const area = minimumOrientation(tri[0], tri[1], tri[2]);
|
|
80
|
+
if (area < margin) throw new RangeError('Triangle collapses or reverses during transition');
|
|
81
|
+
minimum = Math.min(minimum, area);
|
|
82
|
+
for (let j = 0; j < 3; j++) {
|
|
83
|
+
const a = tri[j],
|
|
84
|
+
b = tri[(j + 1) % 3],
|
|
85
|
+
key = a < b ? `${a}:${b}` : `${b}:${a}`,
|
|
86
|
+
edge = edges.get(key);
|
|
87
|
+
if (edge) {
|
|
88
|
+
if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
|
|
89
|
+
throw new RangeError('Expected oriented manifold edges');
|
|
90
|
+
edge.faces++;
|
|
91
|
+
} else edges.set(key, {a, b, faces: 1});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const next = new Map<number, number>();
|
|
95
|
+
for (const edge of edges.values())
|
|
96
|
+
if (edge.faces === 1) {
|
|
97
|
+
if (next.has(edge.a)) throw new RangeError('Nonmanifold boundary');
|
|
98
|
+
next.set(edge.a, edge.b);
|
|
99
|
+
}
|
|
100
|
+
if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
|
|
101
|
+
throw new RangeError('Expected a triangulated disk without unused vertices');
|
|
102
|
+
const start = next.keys().next().value!,
|
|
103
|
+
boundary: number[] = [];
|
|
104
|
+
const visitedBoundary = new Set<number>();
|
|
105
|
+
let v = start;
|
|
106
|
+
do {
|
|
107
|
+
if (visitedBoundary.has(v) || !next.has(v)) throw new RangeError('Expected one boundary cycle');
|
|
108
|
+
visitedBoundary.add(v);
|
|
109
|
+
boundary.push(v);
|
|
110
|
+
v = next.get(v)!;
|
|
111
|
+
} while (v !== start);
|
|
112
|
+
if (boundary.length !== next.size) throw new RangeError('Multiple boundary cycles');
|
|
113
|
+
// Every boundary vertex stays left of each directed support edge. This allows
|
|
114
|
+
// collinear refinement vertices while rejecting a nonconvex or crossing outline.
|
|
115
|
+
for (let i = 0; i < boundary.length; i++) {
|
|
116
|
+
const a = boundary[i],
|
|
117
|
+
b = boundary[(i + 1) % boundary.length];
|
|
118
|
+
// Distinct boundary vertices rule out multiple winding of a convex outline
|
|
119
|
+
// (a locally positive double-cover fan would otherwise pass support tests).
|
|
120
|
+
for (let j = i + 1; j < boundary.length; j++) {
|
|
121
|
+
tick();
|
|
122
|
+
const c = boundary[j];
|
|
123
|
+
const separation = quadraticMinimum(t => {
|
|
124
|
+
const dx = (from[3 * c] - from[3 * a]) * (1 - t) + (to[3 * c] - to[3 * a]) * t,
|
|
125
|
+
dy = (from[3 * c + 1] - from[3 * a + 1]) * (1 - t) + (to[3 * c + 1] - to[3 * a + 1]) * t;
|
|
126
|
+
return dx * dx + dy * dy;
|
|
127
|
+
});
|
|
128
|
+
if (separation < margin) throw new RangeError('Boundary vertices meet during transition');
|
|
129
|
+
}
|
|
130
|
+
for (const c of boundary)
|
|
131
|
+
if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
|
|
132
|
+
throw new RangeError('Boundary is not convex throughout transition');
|
|
133
|
+
}
|
|
134
|
+
// Euler characteristic plus one boundary is insufficient if a closed component
|
|
135
|
+
// is present. Explicitly require connectivity of the vertex graph.
|
|
136
|
+
const neighbors = Array.from({length: count}, () => [] as number[]);
|
|
137
|
+
for (const {a, b} of edges.values()) {
|
|
138
|
+
neighbors[a].push(b);
|
|
139
|
+
neighbors[b].push(a);
|
|
140
|
+
}
|
|
141
|
+
const seen = new Set<number>([start]),
|
|
142
|
+
queue = [start];
|
|
143
|
+
for (let i = 0; i < queue.length; i++)
|
|
144
|
+
for (const n of neighbors[queue[i]])
|
|
145
|
+
if (!seen.has(n)) {
|
|
146
|
+
seen.add(n);
|
|
147
|
+
queue.push(n);
|
|
148
|
+
}
|
|
149
|
+
if (seen.size !== count) throw new RangeError('Disconnected surface mesh');
|
|
150
|
+
return {
|
|
151
|
+
scope: 'convex-xy-disk-linear',
|
|
152
|
+
minimumProjectedDoubleArea: minimum,
|
|
153
|
+
boundary: new Uint32Array(boundary)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function quadraticMinimum(value: (t: number) => number): number {
|
|
158
|
+
const f = value(0),
|
|
159
|
+
g = value(1),
|
|
160
|
+
h = value(0.5),
|
|
161
|
+
a = 2 * (f + g - 2 * h),
|
|
162
|
+
b = g - f - a;
|
|
163
|
+
if (![f, g, h, a, b].every(Number.isFinite))
|
|
164
|
+
throw new RangeError('Nonfinite surface orientation polynomial');
|
|
165
|
+
const t = a > 0 ? -b / (2 * a) : -1;
|
|
166
|
+
const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
|
|
167
|
+
if (!Number.isFinite(result)) throw new RangeError('Nonfinite surface orientation');
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/** Portable point, line, and triangle primitive types. */
|
|
2
|
-
export declare const GL_PRIMITIVE: {
|
|
3
|
-
readonly POINTS: 0;
|
|
4
|
-
readonly LINES: 1;
|
|
5
|
-
readonly TRIANGLES: 4;
|
|
6
|
-
};
|
|
7
|
-
/** WebGL-compatible primitive topology constants. */
|
|
8
|
-
export declare const GL_PRIMITIVE_MODE: {
|
|
9
|
-
readonly POINTS: 0;
|
|
10
|
-
readonly LINES: 1;
|
|
11
|
-
readonly LINE_LOOP: 2;
|
|
12
|
-
readonly LINE_STRIP: 3;
|
|
13
|
-
readonly TRIANGLES: 4;
|
|
14
|
-
readonly TRIANGLE_STRIP: 5;
|
|
15
|
-
readonly TRIANGLE_FAN: 6;
|
|
16
|
-
};
|
|
17
|
-
/** WebGL-compatible vertex component type constants. */
|
|
18
|
-
export declare const GL_TYPE: {
|
|
19
|
-
readonly BYTE: 5120;
|
|
20
|
-
readonly UNSIGNED_BYTE: 5121;
|
|
21
|
-
readonly SHORT: 5122;
|
|
22
|
-
readonly UNSIGNED_SHORT: 5123;
|
|
23
|
-
readonly INT: 5124;
|
|
24
|
-
readonly UNSIGNED_INT: 5125;
|
|
25
|
-
readonly FLOAT: 5126;
|
|
26
|
-
readonly DOUBLE: 5130;
|
|
27
|
-
readonly UNSIGNED_SHORT_4_4_4_4: 32819;
|
|
28
|
-
readonly UNSIGNED_SHORT_5_5_5_1: 32820;
|
|
29
|
-
readonly UNSIGNED_SHORT_5_6_5: 33635;
|
|
30
|
-
};
|
|
31
|
-
/** WebGL-compatible constants used by geometry utilities. */
|
|
32
|
-
export declare const GL: {
|
|
33
|
-
readonly BYTE: 5120;
|
|
34
|
-
readonly UNSIGNED_BYTE: 5121;
|
|
35
|
-
readonly SHORT: 5122;
|
|
36
|
-
readonly UNSIGNED_SHORT: 5123;
|
|
37
|
-
readonly INT: 5124;
|
|
38
|
-
readonly UNSIGNED_INT: 5125;
|
|
39
|
-
readonly FLOAT: 5126;
|
|
40
|
-
readonly DOUBLE: 5130;
|
|
41
|
-
readonly UNSIGNED_SHORT_4_4_4_4: 32819;
|
|
42
|
-
readonly UNSIGNED_SHORT_5_5_5_1: 32820;
|
|
43
|
-
readonly UNSIGNED_SHORT_5_6_5: 33635;
|
|
44
|
-
readonly POINTS: 0;
|
|
45
|
-
readonly LINES: 1;
|
|
46
|
-
readonly LINE_LOOP: 2;
|
|
47
|
-
readonly LINE_STRIP: 3;
|
|
48
|
-
readonly TRIANGLES: 4;
|
|
49
|
-
readonly TRIANGLE_STRIP: 5;
|
|
50
|
-
readonly TRIANGLE_FAN: 6;
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAIA,0DAA0D;AAC1D,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,qDAAqD;AACrD,eAAO,MAAM,iBAAiB;;;;;;;;CAQpB,CAAC;AAEX,wDAAwD;AACxD,eAAO,MAAM,OAAO;;;;;;;;;;;;CAYV,CAAC;AAEX,6DAA6D;AAC7D,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;CAGL,CAAC"}
|
package/dist/utils/constants.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// math.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
/** Portable point, line, and triangle primitive types. */
|
|
5
|
-
export const GL_PRIMITIVE = {
|
|
6
|
-
POINTS: 0x0000,
|
|
7
|
-
LINES: 0x0001,
|
|
8
|
-
TRIANGLES: 0x0004
|
|
9
|
-
};
|
|
10
|
-
/** WebGL-compatible primitive topology constants. */
|
|
11
|
-
export const GL_PRIMITIVE_MODE = {
|
|
12
|
-
POINTS: 0x0000,
|
|
13
|
-
LINES: 0x0001,
|
|
14
|
-
LINE_LOOP: 0x0002,
|
|
15
|
-
LINE_STRIP: 0x0003,
|
|
16
|
-
TRIANGLES: 0x0004,
|
|
17
|
-
TRIANGLE_STRIP: 0x0005,
|
|
18
|
-
TRIANGLE_FAN: 0x0006
|
|
19
|
-
};
|
|
20
|
-
/** WebGL-compatible vertex component type constants. */
|
|
21
|
-
export const GL_TYPE = {
|
|
22
|
-
BYTE: 5120,
|
|
23
|
-
UNSIGNED_BYTE: 5121,
|
|
24
|
-
SHORT: 5122,
|
|
25
|
-
UNSIGNED_SHORT: 5123,
|
|
26
|
-
INT: 5124,
|
|
27
|
-
UNSIGNED_INT: 5125,
|
|
28
|
-
FLOAT: 5126,
|
|
29
|
-
DOUBLE: 5130,
|
|
30
|
-
UNSIGNED_SHORT_4_4_4_4: 32819,
|
|
31
|
-
UNSIGNED_SHORT_5_5_5_1: 32820,
|
|
32
|
-
UNSIGNED_SHORT_5_6_5: 33635
|
|
33
|
-
};
|
|
34
|
-
/** WebGL-compatible constants used by geometry utilities. */
|
|
35
|
-
export const GL = {
|
|
36
|
-
...GL_PRIMITIVE_MODE,
|
|
37
|
-
...GL_TYPE
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,0DAA0D;AAC1D,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,MAAM;CACT,CAAC;AAEX,qDAAqD;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,MAAM;IACjB,cAAc,EAAE,MAAM;IACtB,YAAY,EAAE,MAAM;CACZ,CAAC;AAEX,wDAAwD;AACxD,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,IAAI;IACV,aAAa,EAAE,IAAI;IACnB,KAAK,EAAE,IAAI;IACX,cAAc,EAAE,IAAI;IACpB,GAAG,EAAE,IAAI;IACT,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,sBAAsB,EAAE,KAAK;IAC7B,sBAAsB,EAAE,KAAK;IAC7B,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,6DAA6D;AAC7D,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,GAAG,iBAAiB;IACpB,GAAG,OAAO;CACF,CAAC"}
|
package/dist/utils/gl-type.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TypedArray, TypedArrayConstructor } from '@math.gl/core';
|
|
2
|
-
/** Converts between WebGL component constants and JavaScript typed arrays. */
|
|
3
|
-
export default class GLType {
|
|
4
|
-
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
5
|
-
static fromTypedArray(arrayOrType: TypedArray | TypedArrayConstructor): number;
|
|
6
|
-
/** Returns a WebGL component constant from its uppercase name. */
|
|
7
|
-
static fromName(name: string): number;
|
|
8
|
-
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
9
|
-
static getArrayType(glType: number): TypedArrayConstructor;
|
|
10
|
-
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
11
|
-
static getByteSize(glType: number): number;
|
|
12
|
-
/** Returns whether a value is a supported WebGL component type. */
|
|
13
|
-
static validate(glType: number): boolean;
|
|
14
|
-
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
15
|
-
static createTypedArray(glType: number, buffer: ArrayBufferLike | ArrayBufferView, byteOffset?: number, length?: number): TypedArray;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=gl-type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gl-type.d.ts","sourceRoot":"","sources":["../../src/utils/gl-type.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAC;AAuBrE,8EAA8E;AAC9E,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,yFAAyF;IACzF,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,UAAU,GAAG,qBAAqB,GAAG,MAAM;IAa9E,kEAAkE;IAClE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAQrC,0EAA0E;IAC1E,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB;IAQ1D,0EAA0E;IAC1E,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI1C,mEAAmE;IACnE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIxC,gFAAgF;IAChF,MAAM,CAAC,gBAAgB,CACrB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,GAAG,eAAe,EACzC,UAAU,SAAI,EACd,MAAM,CAAC,EAAE,MAAM,GACd,UAAU;CASd"}
|
package/dist/utils/gl-type.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// math.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
import { GL_TYPE } from "./constants.js";
|
|
5
|
-
const GL_TYPE_TO_ARRAY_TYPE = {
|
|
6
|
-
[GL_TYPE.DOUBLE]: Float64Array,
|
|
7
|
-
[GL_TYPE.FLOAT]: Float32Array,
|
|
8
|
-
[GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
|
|
9
|
-
[GL_TYPE.UNSIGNED_INT]: Uint32Array,
|
|
10
|
-
[GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
|
|
11
|
-
[GL_TYPE.BYTE]: Int8Array,
|
|
12
|
-
[GL_TYPE.SHORT]: Int16Array,
|
|
13
|
-
[GL_TYPE.INT]: Int32Array,
|
|
14
|
-
[GL_TYPE.UNSIGNED_SHORT_4_4_4_4]: Uint16Array,
|
|
15
|
-
[GL_TYPE.UNSIGNED_SHORT_5_5_5_1]: Uint16Array,
|
|
16
|
-
[GL_TYPE.UNSIGNED_SHORT_5_6_5]: Uint16Array
|
|
17
|
-
};
|
|
18
|
-
const NAME_TO_GL_TYPE = Object.fromEntries(Object.entries(GL_TYPE).map(([name, glType]) => [name, glType]));
|
|
19
|
-
const TYPE_CONVERSION_ERROR = 'Failed to convert GL type';
|
|
20
|
-
/** Converts between WebGL component constants and JavaScript typed arrays. */
|
|
21
|
-
export default class GLType {
|
|
22
|
-
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
23
|
-
static fromTypedArray(arrayOrType) {
|
|
24
|
-
const arrayType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
25
|
-
if (arrayType === Uint8ClampedArray) {
|
|
26
|
-
return GL_TYPE.UNSIGNED_BYTE;
|
|
27
|
-
}
|
|
28
|
-
for (const [glType, candidateArrayType] of Object.entries(GL_TYPE_TO_ARRAY_TYPE)) {
|
|
29
|
-
if (candidateArrayType === arrayType) {
|
|
30
|
-
return Number(glType);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
34
|
-
}
|
|
35
|
-
/** Returns a WebGL component constant from its uppercase name. */
|
|
36
|
-
static fromName(name) {
|
|
37
|
-
const glType = NAME_TO_GL_TYPE[name];
|
|
38
|
-
if (glType === undefined) {
|
|
39
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
40
|
-
}
|
|
41
|
-
return glType;
|
|
42
|
-
}
|
|
43
|
-
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
44
|
-
static getArrayType(glType) {
|
|
45
|
-
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
46
|
-
if (!ArrayType) {
|
|
47
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
48
|
-
}
|
|
49
|
-
return ArrayType;
|
|
50
|
-
}
|
|
51
|
-
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
52
|
-
static getByteSize(glType) {
|
|
53
|
-
return GLType.getArrayType(glType).BYTES_PER_ELEMENT;
|
|
54
|
-
}
|
|
55
|
-
/** Returns whether a value is a supported WebGL component type. */
|
|
56
|
-
static validate(glType) {
|
|
57
|
-
return Boolean(GL_TYPE_TO_ARRAY_TYPE[glType]);
|
|
58
|
-
}
|
|
59
|
-
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
60
|
-
static createTypedArray(glType, buffer, byteOffset = 0, length) {
|
|
61
|
-
const ArrayType = GLType.getArrayType(glType);
|
|
62
|
-
const arrayBuffer = ArrayBuffer.isView(buffer) ? buffer.buffer : buffer;
|
|
63
|
-
const viewByteOffset = ArrayBuffer.isView(buffer) ? buffer.byteOffset : 0;
|
|
64
|
-
const resolvedByteOffset = viewByteOffset + byteOffset;
|
|
65
|
-
const resolvedLength = length ?? Math.floor((buffer.byteLength - byteOffset) / ArrayType.BYTES_PER_ELEMENT);
|
|
66
|
-
return new ArrayType(arrayBuffer, resolvedByteOffset, resolvedLength);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=gl-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gl-type.js","sourceRoot":"","sources":["../../src/utils/gl-type.ts"],"names":[],"mappings":"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"}
|
package/src/utils/constants.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// math.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/** Portable point, line, and triangle primitive types. */
|
|
6
|
-
export const GL_PRIMITIVE = {
|
|
7
|
-
POINTS: 0x0000,
|
|
8
|
-
LINES: 0x0001,
|
|
9
|
-
TRIANGLES: 0x0004
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
/** WebGL-compatible primitive topology constants. */
|
|
13
|
-
export const GL_PRIMITIVE_MODE = {
|
|
14
|
-
POINTS: 0x0000,
|
|
15
|
-
LINES: 0x0001,
|
|
16
|
-
LINE_LOOP: 0x0002,
|
|
17
|
-
LINE_STRIP: 0x0003,
|
|
18
|
-
TRIANGLES: 0x0004,
|
|
19
|
-
TRIANGLE_STRIP: 0x0005,
|
|
20
|
-
TRIANGLE_FAN: 0x0006
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
/** WebGL-compatible vertex component type constants. */
|
|
24
|
-
export const GL_TYPE = {
|
|
25
|
-
BYTE: 5120,
|
|
26
|
-
UNSIGNED_BYTE: 5121,
|
|
27
|
-
SHORT: 5122,
|
|
28
|
-
UNSIGNED_SHORT: 5123,
|
|
29
|
-
INT: 5124,
|
|
30
|
-
UNSIGNED_INT: 5125,
|
|
31
|
-
FLOAT: 5126,
|
|
32
|
-
DOUBLE: 5130,
|
|
33
|
-
UNSIGNED_SHORT_4_4_4_4: 32819,
|
|
34
|
-
UNSIGNED_SHORT_5_5_5_1: 32820,
|
|
35
|
-
UNSIGNED_SHORT_5_6_5: 33635
|
|
36
|
-
} as const;
|
|
37
|
-
|
|
38
|
-
/** WebGL-compatible constants used by geometry utilities. */
|
|
39
|
-
export const GL = {
|
|
40
|
-
...GL_PRIMITIVE_MODE,
|
|
41
|
-
...GL_TYPE
|
|
42
|
-
} as const;
|
package/src/utils/gl-type.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// math.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {TypedArray, TypedArrayConstructor} from '@math.gl/core';
|
|
6
|
-
import {GL_TYPE} from './constants';
|
|
7
|
-
|
|
8
|
-
const GL_TYPE_TO_ARRAY_TYPE: Record<number, TypedArrayConstructor> = {
|
|
9
|
-
[GL_TYPE.DOUBLE]: Float64Array,
|
|
10
|
-
[GL_TYPE.FLOAT]: Float32Array,
|
|
11
|
-
[GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
|
|
12
|
-
[GL_TYPE.UNSIGNED_INT]: Uint32Array,
|
|
13
|
-
[GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
|
|
14
|
-
[GL_TYPE.BYTE]: Int8Array,
|
|
15
|
-
[GL_TYPE.SHORT]: Int16Array,
|
|
16
|
-
[GL_TYPE.INT]: Int32Array,
|
|
17
|
-
[GL_TYPE.UNSIGNED_SHORT_4_4_4_4]: Uint16Array,
|
|
18
|
-
[GL_TYPE.UNSIGNED_SHORT_5_5_5_1]: Uint16Array,
|
|
19
|
-
[GL_TYPE.UNSIGNED_SHORT_5_6_5]: Uint16Array
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const NAME_TO_GL_TYPE: Record<string, number> = Object.fromEntries(
|
|
23
|
-
Object.entries(GL_TYPE).map(([name, glType]) => [name, glType])
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const TYPE_CONVERSION_ERROR = 'Failed to convert GL type';
|
|
27
|
-
|
|
28
|
-
/** Converts between WebGL component constants and JavaScript typed arrays. */
|
|
29
|
-
export default class GLType {
|
|
30
|
-
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
31
|
-
static fromTypedArray(arrayOrType: TypedArray | TypedArrayConstructor): number {
|
|
32
|
-
const arrayType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
33
|
-
if (arrayType === Uint8ClampedArray) {
|
|
34
|
-
return GL_TYPE.UNSIGNED_BYTE;
|
|
35
|
-
}
|
|
36
|
-
for (const [glType, candidateArrayType] of Object.entries(GL_TYPE_TO_ARRAY_TYPE)) {
|
|
37
|
-
if (candidateArrayType === arrayType) {
|
|
38
|
-
return Number(glType);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Returns a WebGL component constant from its uppercase name. */
|
|
45
|
-
static fromName(name: string): number {
|
|
46
|
-
const glType = NAME_TO_GL_TYPE[name];
|
|
47
|
-
if (glType === undefined) {
|
|
48
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
49
|
-
}
|
|
50
|
-
return glType;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
54
|
-
static getArrayType(glType: number): TypedArrayConstructor {
|
|
55
|
-
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
56
|
-
if (!ArrayType) {
|
|
57
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
58
|
-
}
|
|
59
|
-
return ArrayType;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
63
|
-
static getByteSize(glType: number): number {
|
|
64
|
-
return GLType.getArrayType(glType).BYTES_PER_ELEMENT;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Returns whether a value is a supported WebGL component type. */
|
|
68
|
-
static validate(glType: number): boolean {
|
|
69
|
-
return Boolean(GL_TYPE_TO_ARRAY_TYPE[glType]);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
73
|
-
static createTypedArray(
|
|
74
|
-
glType: number,
|
|
75
|
-
buffer: ArrayBufferLike | ArrayBufferView,
|
|
76
|
-
byteOffset = 0,
|
|
77
|
-
length?: number
|
|
78
|
-
): TypedArray {
|
|
79
|
-
const ArrayType = GLType.getArrayType(glType);
|
|
80
|
-
const arrayBuffer = ArrayBuffer.isView(buffer) ? buffer.buffer : buffer;
|
|
81
|
-
const viewByteOffset = ArrayBuffer.isView(buffer) ? buffer.byteOffset : 0;
|
|
82
|
-
const resolvedByteOffset = viewByteOffset + byteOffset;
|
|
83
|
-
const resolvedLength =
|
|
84
|
-
length ?? Math.floor((buffer.byteLength - byteOffset) / ArrayType.BYTES_PER_ELEMENT);
|
|
85
|
-
return new ArrayType(arrayBuffer as ArrayBuffer, resolvedByteOffset, resolvedLength);
|
|
86
|
-
}
|
|
87
|
-
}
|