@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
package/dist/index.cjs
CHANGED
|
@@ -35,11 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
CurveArcLength: () => CurveArcLength,
|
|
36
36
|
CylinderGeometry: () => CylinderGeometry,
|
|
37
37
|
CylinderShape: () => CylinderShape,
|
|
38
|
-
|
|
39
|
-
GLType: () => GLType,
|
|
40
|
-
GL_PRIMITIVE: () => GL_PRIMITIVE,
|
|
41
|
-
GL_PRIMITIVE_MODE: () => GL_PRIMITIVE_MODE,
|
|
42
|
-
GL_TYPE: () => GL_TYPE,
|
|
38
|
+
DEFAULT_POLE_SEARCH_SEGMENT_TESTS: () => DEFAULT_POLE_SEARCH_SEGMENT_TESTS,
|
|
43
39
|
Geometry: () => Geometry,
|
|
44
40
|
HermiteCurve: () => HermiteCurve,
|
|
45
41
|
HingeTree: () => HingeTree,
|
|
@@ -64,35 +60,59 @@ __export(index_exports, {
|
|
|
64
60
|
TruncatedConeGeometry: () => TruncatedConeGeometry,
|
|
65
61
|
_PerspectiveFrustum: () => PerspectiveFrustum,
|
|
66
62
|
_PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
|
|
63
|
+
boundsContainsBounds: () => boundsContainsBounds,
|
|
64
|
+
boundsContainsPoint: () => boundsContainsPoint,
|
|
65
|
+
boundsIntersect: () => boundsIntersect,
|
|
66
|
+
boundsIntersectSphere: () => boundsIntersectSphere,
|
|
67
|
+
clampPointToBounds: () => clampPointToBounds,
|
|
67
68
|
clipPolygon: () => clipPolygon,
|
|
68
69
|
clipPolyline: () => clipPolyline,
|
|
69
70
|
clipTriangleMesh: () => clipTriangleMesh,
|
|
71
|
+
composeAttributeProvenance: () => composeAttributeProvenance,
|
|
70
72
|
compressTextureCoordinates: () => compressTextureCoordinates,
|
|
71
73
|
computeEigenDecomposition: () => computeEigenDecomposition,
|
|
74
|
+
computeParallelTransportFrames: () => computeParallelTransportFrames,
|
|
72
75
|
computeVertexNormals: () => computeVertexNormals,
|
|
73
76
|
concatTypedArrays: () => concatTypedArrays,
|
|
77
|
+
createEmptyBounds: () => createEmptyBounds,
|
|
74
78
|
cutPolygonByGrid: () => cutPolygonByGrid,
|
|
75
79
|
cutPolygonByMercatorBounds: () => cutPolygonByMercatorBounds,
|
|
76
80
|
cutPolylineByGrid: () => cutPolylineByGrid,
|
|
77
81
|
cutPolylineByMercatorBounds: () => cutPolylineByMercatorBounds,
|
|
78
82
|
decodeRGB565: () => decodeRGB565,
|
|
79
83
|
decompressTextureCoordinates: () => decompressTextureCoordinates,
|
|
84
|
+
distanceToRay: () => distanceToRay,
|
|
80
85
|
earcut: () => earcut,
|
|
81
86
|
emod: () => emod,
|
|
82
87
|
encodeRGB565: () => encodeRGB565,
|
|
88
|
+
expandBounds: () => expandBounds,
|
|
89
|
+
expandBoundsByPoint: () => expandBoundsByPoint,
|
|
90
|
+
extractFrustumPlanes: () => extractFrustumPlanes,
|
|
83
91
|
forEachSegmentInPolygon: () => forEachSegmentInPolygon,
|
|
92
|
+
getClosestPointOnRay: () => getClosestPointOnRay,
|
|
84
93
|
getClosestPointOnTriangle: () => getClosestPointOnTriangle,
|
|
85
94
|
getClosestPointsOnSegments: () => getClosestPointsOnSegments,
|
|
95
|
+
getClosestPointsRaySegment: () => getClosestPointsRaySegment,
|
|
86
96
|
getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
|
|
87
97
|
getDegenerateTriangles: () => getDegenerateTriangles,
|
|
88
98
|
getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
|
|
99
|
+
getPoleOfInaccessibility: () => getPoleOfInaccessibility,
|
|
89
100
|
getPolygonSignedArea: () => getPolygonSignedArea,
|
|
90
101
|
getPolygonWindingDirection: () => getPolygonWindingDirection,
|
|
102
|
+
getRayPoint: () => getRayPoint,
|
|
103
|
+
getTriangleArea: () => getTriangleArea,
|
|
104
|
+
getTriangleBarycentric: () => getTriangleBarycentric,
|
|
105
|
+
getTriangleNormal: () => getTriangleNormal,
|
|
91
106
|
interpolatePackedAttributes: () => interpolatePackedAttributes,
|
|
107
|
+
interpolateTriangleAttribute: () => interpolateTriangleAttribute,
|
|
108
|
+
intersectBounds: () => intersectBounds,
|
|
92
109
|
intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
|
|
110
|
+
intersectPlaneSegment: () => intersectPlaneSegment,
|
|
93
111
|
intersectRayBounds: () => intersectRayBounds,
|
|
94
112
|
intersectRayTriangle: () => intersectRayTriangle,
|
|
113
|
+
isEmptyBounds: () => isEmptyBounds,
|
|
95
114
|
isGeometry: () => isGeometry,
|
|
115
|
+
isTriangleFrontFacing: () => isTriangleFrontFacing,
|
|
96
116
|
makeAttributeIterator: () => makeAttributeIterator,
|
|
97
117
|
makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
|
|
98
118
|
makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
|
|
@@ -113,9 +133,18 @@ __export(index_exports, {
|
|
|
113
133
|
octPack: () => octPack,
|
|
114
134
|
octPackFloat: () => octPackFloat,
|
|
115
135
|
octUnpack: () => octUnpack,
|
|
136
|
+
projectBounds: () => projectBounds,
|
|
137
|
+
projectTextureCoordinates: () => projectTextureCoordinates,
|
|
138
|
+
qualifySurfaceTransition: () => qualifySurfaceTransition,
|
|
139
|
+
sampleCurveAdaptive: () => sampleCurveAdaptive,
|
|
140
|
+
spheresIntersect: () => spheresIntersect,
|
|
116
141
|
subdividePolyline: () => subdividePolyline,
|
|
117
142
|
subdivideTriangleMesh: () => subdivideTriangleMesh,
|
|
118
143
|
transformGeometry: () => transformGeometry,
|
|
144
|
+
transformRay: () => transformRay,
|
|
145
|
+
triangleContainsPoint: () => triangleContainsPoint,
|
|
146
|
+
triangleIntersectsBounds: () => triangleIntersectsBounds,
|
|
147
|
+
unionBounds: () => unionBounds,
|
|
119
148
|
unpackIndexedGeometry: () => unpackIndexedGeometry,
|
|
120
149
|
validateQueryDistance: () => validateQueryDistance,
|
|
121
150
|
validateQueryPoint: () => validateQueryPoint,
|
|
@@ -263,10 +292,10 @@ var HingeTree = class {
|
|
|
263
292
|
* Output may alias the inputs: angles and root transform are snapshotted first.
|
|
264
293
|
* Finite inputs that overflow during composition throw; output may then be partial.
|
|
265
294
|
*/
|
|
266
|
-
evaluate(angles,
|
|
295
|
+
evaluate(angles, output2 = new Float64Array(this.panelCount * 16), rootTransform) {
|
|
267
296
|
if (angles.length !== this.panelCount)
|
|
268
297
|
throw new RangeError("Expected one angle per panel");
|
|
269
|
-
if (!(
|
|
298
|
+
if (!(output2 instanceof Float64Array) || output2.length !== this.panelCount * 16) {
|
|
270
299
|
throw new RangeError("Expected 16 Float64 values per panel");
|
|
271
300
|
}
|
|
272
301
|
for (let i = 0; i < angles.length; i++) {
|
|
@@ -291,16 +320,16 @@ var HingeTree = class {
|
|
|
291
320
|
this.world.copy(this.root);
|
|
292
321
|
else {
|
|
293
322
|
for (let i = 0; i < 16; i++)
|
|
294
|
-
this.world[i] =
|
|
323
|
+
this.world[i] = output2[joint.parent * 16 + i];
|
|
295
324
|
}
|
|
296
325
|
this.world.multiplyRight(this.local);
|
|
297
326
|
for (let i = 0; i < 16; i++) {
|
|
298
327
|
if (!Number.isFinite(this.world[i]))
|
|
299
328
|
throw new RangeError("Hinge transform overflow");
|
|
300
|
-
|
|
329
|
+
output2[index * 16 + i] = this.world[i];
|
|
301
330
|
}
|
|
302
331
|
}
|
|
303
|
-
return
|
|
332
|
+
return output2;
|
|
304
333
|
}
|
|
305
334
|
};
|
|
306
335
|
function copyVector(vector) {
|
|
@@ -321,10 +350,10 @@ function validateRigidTransform(matrix) {
|
|
|
321
350
|
throw new RangeError("Expected an affine rigid transform");
|
|
322
351
|
for (let a = 0; a < 3; a++) {
|
|
323
352
|
for (let b = a; b < 3; b++) {
|
|
324
|
-
let
|
|
353
|
+
let dot6 = 0;
|
|
325
354
|
for (let row = 0; row < 3; row++)
|
|
326
|
-
|
|
327
|
-
if (Math.abs(
|
|
355
|
+
dot6 += matrix[a * 4 + row] * matrix[b * 4 + row];
|
|
356
|
+
if (Math.abs(dot6 - (a === b ? 1 : 0)) > tolerance) {
|
|
328
357
|
throw new RangeError("Rigid transforms cannot scale or shear");
|
|
329
358
|
}
|
|
330
359
|
}
|
|
@@ -480,9 +509,9 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
480
509
|
const deltaRadius = radiusTop - radiusBottom;
|
|
481
510
|
if (Math.abs(deltaRadius) >= height) {
|
|
482
511
|
const topWins = radiusTop >= radiusBottom;
|
|
483
|
-
const
|
|
512
|
+
const radius2 = topWins ? radiusTop : radiusBottom;
|
|
484
513
|
const center = topWins ? height / 2 : -height / 2;
|
|
485
|
-
addSphereRings(rings, center,
|
|
514
|
+
addSphereRings(rings, center, radius2, ncap * 2);
|
|
486
515
|
} else {
|
|
487
516
|
const sinSlope = deltaRadius / height;
|
|
488
517
|
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
@@ -501,11 +530,11 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
501
530
|
}
|
|
502
531
|
for (let i = 1; i <= nvertical; i++) {
|
|
503
532
|
const t = i / nvertical;
|
|
504
|
-
const
|
|
533
|
+
const radius2 = radiusBottom + deltaRadius * t;
|
|
505
534
|
const center = bottomCenter + height * t;
|
|
506
535
|
rings.push({
|
|
507
|
-
radius:
|
|
508
|
-
y: center +
|
|
536
|
+
radius: radius2 * radialNormal,
|
|
537
|
+
y: center + radius2 * sideNormalY,
|
|
509
538
|
normalRadius: radialNormal,
|
|
510
539
|
normalY: sideNormalY
|
|
511
540
|
});
|
|
@@ -535,14 +564,14 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
535
564
|
});
|
|
536
565
|
}
|
|
537
566
|
};
|
|
538
|
-
function addSphereRings(rings, center,
|
|
567
|
+
function addSphereRings(rings, center, radius2, segments) {
|
|
539
568
|
for (let i = 0; i <= segments; i++) {
|
|
540
569
|
const angle = -Math.PI / 2 + i / segments * Math.PI;
|
|
541
570
|
const normalRadius = Math.cos(angle);
|
|
542
571
|
const normalY = Math.sin(angle);
|
|
543
572
|
rings.push({
|
|
544
|
-
radius:
|
|
545
|
-
y: center +
|
|
573
|
+
radius: radius2 * normalRadius,
|
|
574
|
+
y: center + radius2 * normalY,
|
|
546
575
|
normalRadius,
|
|
547
576
|
normalY
|
|
548
577
|
});
|
|
@@ -567,16 +596,16 @@ var TruncatedConeGeometry = class extends Geometry {
|
|
|
567
596
|
const stride = nradial + 1;
|
|
568
597
|
const slope = (bottomRadius - topRadius) / height;
|
|
569
598
|
const normalScale = 1 / Math.hypot(1, slope);
|
|
570
|
-
const addRing = (
|
|
599
|
+
const addRing = (radius2, y, normalRadius, normalY, v) => {
|
|
571
600
|
const ring = positions.length / 3 / stride;
|
|
572
601
|
for (let radial2 = 0; radial2 <= nradial; radial2++) {
|
|
573
602
|
const u = radial2 / nradial;
|
|
574
603
|
const angle = u * Math.PI * 2;
|
|
575
604
|
const sin = Math.sin(angle);
|
|
576
605
|
const cos = Math.cos(angle);
|
|
577
|
-
const
|
|
606
|
+
const point2 = orient([sin * radius2, y, cos * radius2], verticalAxis);
|
|
578
607
|
const normal = orient([sin * normalRadius, normalY, cos * normalRadius], verticalAxis);
|
|
579
|
-
positions.push(...
|
|
608
|
+
positions.push(...point2);
|
|
580
609
|
normals.push(...normal);
|
|
581
610
|
texCoords.push(u, v);
|
|
582
611
|
}
|
|
@@ -600,8 +629,8 @@ var TruncatedConeGeometry = class extends Geometry {
|
|
|
600
629
|
}
|
|
601
630
|
for (let vertical = 0; vertical <= nvertical; vertical++) {
|
|
602
631
|
const v = vertical / nvertical;
|
|
603
|
-
const
|
|
604
|
-
const ring = addRing(
|
|
632
|
+
const radius2 = bottomRadius + (topRadius - bottomRadius) * v;
|
|
633
|
+
const ring = addRing(radius2, (v - 0.5) * height, normalScale, slope * normalScale, v);
|
|
605
634
|
if (previous !== void 0 && !(bottomCap && vertical === 0))
|
|
606
635
|
connect(previous, ring);
|
|
607
636
|
previous = ring;
|
|
@@ -653,8 +682,8 @@ var CylinderGeometry = class extends TruncatedConeGeometry {
|
|
|
653
682
|
};
|
|
654
683
|
var ConeGeometry = class extends TruncatedConeGeometry {
|
|
655
684
|
constructor(props = {}) {
|
|
656
|
-
const { radius = 0.5, topCap = false, bottomCap = true } = props;
|
|
657
|
-
super({ ...props, topRadius: 0, bottomRadius:
|
|
685
|
+
const { radius: radius2 = 0.5, topCap = false, bottomCap = true } = props;
|
|
686
|
+
super({ ...props, topRadius: 0, bottomRadius: radius2, topCap, bottomCap });
|
|
658
687
|
}
|
|
659
688
|
};
|
|
660
689
|
|
|
@@ -707,8 +736,8 @@ var PlaneGeometry = class extends Geometry {
|
|
|
707
736
|
// dist/geometries/sphere-geometry.js
|
|
708
737
|
var SphereGeometry = class extends Geometry {
|
|
709
738
|
constructor(props = {}) {
|
|
710
|
-
const { radius = 0.5, nlat = 10, nlong = 10 } = props;
|
|
711
|
-
assertPositive(
|
|
739
|
+
const { radius: radius2 = 0.5, nlat = 10, nlong = 10 } = props;
|
|
740
|
+
assertPositive(radius2, "radius");
|
|
712
741
|
assertSegments(nlat, "nlat", 2);
|
|
713
742
|
assertSegments(nlong, "nlong", 3);
|
|
714
743
|
const rings = [];
|
|
@@ -716,7 +745,7 @@ var SphereGeometry = class extends Geometry {
|
|
|
716
745
|
const angle = -Math.PI / 2 + latitude / nlat * Math.PI;
|
|
717
746
|
const normalRadius = Math.cos(angle);
|
|
718
747
|
const normalY = Math.sin(angle);
|
|
719
|
-
rings.push({ radius:
|
|
748
|
+
rings.push({ radius: radius2 * normalRadius, y: radius2 * normalY, normalRadius, normalY });
|
|
720
749
|
}
|
|
721
750
|
const mesh = makeSurfaceOfRevolution(rings, nlong);
|
|
722
751
|
super({
|
|
@@ -736,8 +765,8 @@ var SphereGeometry = class extends Geometry {
|
|
|
736
765
|
// dist/geometries/ico-sphere-geometry.js
|
|
737
766
|
var IcoSphereGeometry = class extends Geometry {
|
|
738
767
|
constructor(props = {}) {
|
|
739
|
-
const { radius = 0.5, iterations = 0 } = props;
|
|
740
|
-
assertPositive(
|
|
768
|
+
const { radius: radius2 = 0.5, iterations = 0 } = props;
|
|
769
|
+
assertPositive(radius2, "radius");
|
|
741
770
|
assertSegments(iterations, "iterations", 0);
|
|
742
771
|
if (iterations > 8)
|
|
743
772
|
throw new Error("iterations must be <= 8");
|
|
@@ -793,7 +822,7 @@ var IcoSphereGeometry = class extends Geometry {
|
|
|
793
822
|
const texCoords = [];
|
|
794
823
|
for (const face of faces2) {
|
|
795
824
|
for (const normal of face) {
|
|
796
|
-
positions.push(normal[0] *
|
|
825
|
+
positions.push(normal[0] * radius2, normal[1] * radius2, normal[2] * radius2);
|
|
797
826
|
normals.push(...normal);
|
|
798
827
|
texCoords.push(0.5 + Math.atan2(normal[0], normal[2]) / (2 * Math.PI), 0.5 - Math.asin(normal[1]) / Math.PI);
|
|
799
828
|
}
|
|
@@ -817,12 +846,12 @@ function normalize(vector) {
|
|
|
817
846
|
|
|
818
847
|
// dist/geometries/primitive-mesh-builder.js
|
|
819
848
|
var FULL_CIRCLE = Math.PI * 2;
|
|
820
|
-
function radial(angle,
|
|
821
|
-
return [Math.cos(angle) *
|
|
849
|
+
function radial(angle, direction2 = 1) {
|
|
850
|
+
return [Math.cos(angle) * direction2, 0, -Math.sin(angle) * direction2];
|
|
822
851
|
}
|
|
823
|
-
function vertex(
|
|
852
|
+
function vertex(radius2, height, angle, normal, textureCoordinates) {
|
|
824
853
|
return {
|
|
825
|
-
position: [
|
|
854
|
+
position: [radius2 * Math.cos(angle), height, -radius2 * Math.sin(angle)],
|
|
826
855
|
normal,
|
|
827
856
|
textureCoordinates: textureCoordinates ?? [(Math.cos(angle) + 1) / 2, (Math.sin(angle) + 1) / 2]
|
|
828
857
|
};
|
|
@@ -851,12 +880,12 @@ var PrimitiveMeshBuilder = class {
|
|
|
851
880
|
addTriangle(first, second, third, indices) {
|
|
852
881
|
const firstEdge = second.position.map((value, index) => value - first.position[index]);
|
|
853
882
|
const secondEdge = third.position.map((value, index) => value - first.position[index]);
|
|
854
|
-
const
|
|
883
|
+
const cross6 = [
|
|
855
884
|
firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
|
|
856
885
|
firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
|
|
857
886
|
firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
|
|
858
887
|
];
|
|
859
|
-
const orientation =
|
|
888
|
+
const orientation = cross6.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
|
|
860
889
|
this.indices.push(...orientation < 0 ? [indices[0], indices[2], indices[1]] : indices);
|
|
861
890
|
}
|
|
862
891
|
triangle(first, second, third) {
|
|
@@ -889,8 +918,8 @@ var PrimitiveMeshBuilder = class {
|
|
|
889
918
|
// dist/geometries/prism-geometry.js
|
|
890
919
|
var PrismGeometry = class extends Geometry {
|
|
891
920
|
constructor(props = {}) {
|
|
892
|
-
const { radius = 1, height = 1, sides = 6, startAngle = 0 } = props;
|
|
893
|
-
assertPositive(
|
|
921
|
+
const { radius: radius2 = 1, height = 1, sides = 6, startAngle = 0 } = props;
|
|
922
|
+
assertPositive(radius2, "radius");
|
|
894
923
|
assertPositive(height, "height");
|
|
895
924
|
validateArc(sides, startAngle, FULL_CIRCLE);
|
|
896
925
|
const mesh = new PrimitiveMeshBuilder();
|
|
@@ -899,15 +928,15 @@ var PrismGeometry = class extends Geometry {
|
|
|
899
928
|
const secondAngle = startAngle + (segment + 1) * FULL_CIRCLE / sides;
|
|
900
929
|
const normal = radial((firstAngle + secondAngle) / 2);
|
|
901
930
|
const secondCornerAngle = segment === sides - 1 ? startAngle : secondAngle;
|
|
902
|
-
mesh.quad(vertex(
|
|
903
|
-
for (const
|
|
904
|
-
const capNormal = [0,
|
|
931
|
+
mesh.quad(vertex(radius2, -height / 2, firstAngle, normal, [segment / sides, 0]), vertex(radius2, height / 2, firstAngle, normal, [segment / sides, 1]), vertex(radius2, height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 1]), vertex(radius2, -height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 0]));
|
|
932
|
+
for (const direction2 of [-1, 1]) {
|
|
933
|
+
const capNormal = [0, direction2, 0];
|
|
905
934
|
const center = {
|
|
906
|
-
position: [0,
|
|
935
|
+
position: [0, direction2 * height / 2, 0],
|
|
907
936
|
normal: capNormal,
|
|
908
937
|
textureCoordinates: [0.5, 0.5]
|
|
909
938
|
};
|
|
910
|
-
mesh.triangle(center, vertex(
|
|
939
|
+
mesh.triangle(center, vertex(radius2, direction2 * height / 2, firstAngle, capNormal), vertex(radius2, direction2 * height / 2, secondCornerAngle, capNormal));
|
|
911
940
|
}
|
|
912
941
|
}
|
|
913
942
|
super(mesh.getProps(props));
|
|
@@ -928,39 +957,39 @@ var RingGeometry = class extends Geometry {
|
|
|
928
957
|
for (let segment = 0; segment < segments; segment++) {
|
|
929
958
|
const firstAngle = startAngle + segment * sweepAngle / segments;
|
|
930
959
|
const secondAngle = segment === segments - 1 ? sweepAngle === FULL_CIRCLE ? startAngle : startAngle + sweepAngle : startAngle + (segment + 1) * sweepAngle / segments;
|
|
931
|
-
const makeCapVertex = (
|
|
932
|
-
(
|
|
933
|
-
(
|
|
960
|
+
const makeCapVertex = (radius2, height2, angle, normal) => vertex(radius2, height2, angle, normal, [
|
|
961
|
+
(radius2 * Math.cos(angle) / outerRadius + 1) / 2,
|
|
962
|
+
(radius2 * Math.sin(angle) / outerRadius + 1) / 2
|
|
934
963
|
]);
|
|
935
|
-
for (const
|
|
936
|
-
const normal = [0,
|
|
937
|
-
mesh.quad(makeCapVertex(innerRadius,
|
|
964
|
+
for (const direction2 of [-1, 1]) {
|
|
965
|
+
const normal = [0, direction2, 0];
|
|
966
|
+
mesh.quad(makeCapVertex(innerRadius, direction2 * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction2 * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction2 * height / 2, secondAngle, normal), makeCapVertex(innerRadius, direction2 * height / 2, secondAngle, normal));
|
|
938
967
|
}
|
|
939
|
-
for (const [
|
|
968
|
+
for (const [radius2, direction2] of [
|
|
940
969
|
[innerRadius, -1],
|
|
941
970
|
[outerRadius, 1]
|
|
942
971
|
]) {
|
|
943
|
-
mesh.quad(vertex(
|
|
972
|
+
mesh.quad(vertex(radius2, -height / 2, firstAngle, radial(firstAngle, direction2), [
|
|
944
973
|
segment / segments,
|
|
945
974
|
0
|
|
946
|
-
]), vertex(
|
|
975
|
+
]), vertex(radius2, height / 2, firstAngle, radial(firstAngle, direction2), [
|
|
947
976
|
segment / segments,
|
|
948
977
|
1
|
|
949
|
-
]), vertex(
|
|
978
|
+
]), vertex(radius2, height / 2, secondAngle, radial(secondAngle, direction2), [
|
|
950
979
|
(segment + 1) / segments,
|
|
951
980
|
1
|
|
952
|
-
]), vertex(
|
|
981
|
+
]), vertex(radius2, -height / 2, secondAngle, radial(secondAngle, direction2), [
|
|
953
982
|
(segment + 1) / segments,
|
|
954
983
|
0
|
|
955
984
|
]));
|
|
956
985
|
}
|
|
957
986
|
}
|
|
958
987
|
if (sweepAngle < FULL_CIRCLE) {
|
|
959
|
-
for (const [angle,
|
|
988
|
+
for (const [angle, direction2] of [
|
|
960
989
|
[startAngle, -1],
|
|
961
990
|
[startAngle + sweepAngle, 1]
|
|
962
991
|
]) {
|
|
963
|
-
const normal = [-Math.sin(angle) *
|
|
992
|
+
const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
|
|
964
993
|
mesh.quad(vertex(innerRadius, -height / 2, angle, normal, [0, 0]), vertex(outerRadius, -height / 2, angle, normal, [1, 0]), vertex(outerRadius, height / 2, angle, normal, [1, 1]), vertex(innerRadius, height / 2, angle, normal, [0, 1]));
|
|
965
994
|
}
|
|
966
995
|
}
|
|
@@ -1072,8 +1101,8 @@ var TorusGeometry = class extends ParametricGeometry {
|
|
|
1072
1101
|
periodicU: arc === Math.PI * 2,
|
|
1073
1102
|
periodicV: true,
|
|
1074
1103
|
sample: (u, v) => {
|
|
1075
|
-
const theta = startAngle + u * arc, phi = v * Math.PI * 2,
|
|
1076
|
-
return [
|
|
1104
|
+
const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius2 = majorRadius + minorRadius * Math.cos(phi);
|
|
1105
|
+
return [radius2 * Math.cos(theta), minorRadius * Math.sin(phi), -radius2 * Math.sin(theta)];
|
|
1077
1106
|
},
|
|
1078
1107
|
normal: (u, v) => [
|
|
1079
1108
|
Math.cos(v * Math.PI * 2) * Math.cos(startAngle + u * arc),
|
|
@@ -1087,25 +1116,25 @@ var TorusGeometry = class extends ParametricGeometry {
|
|
|
1087
1116
|
const normals = Array.from(this.attributes["NORMAL"].value);
|
|
1088
1117
|
const textureCoordinates = Array.from(this.attributes["TEXCOORD_0"].value);
|
|
1089
1118
|
const indices = Array.from(this.indices.value);
|
|
1090
|
-
for (const [angle,
|
|
1119
|
+
for (const [angle, direction2] of [
|
|
1091
1120
|
[startAngle, -1],
|
|
1092
1121
|
[startAngle + arc, 1]
|
|
1093
1122
|
]) {
|
|
1094
|
-
const normal = [-Math.sin(angle) *
|
|
1123
|
+
const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
|
|
1095
1124
|
const centerIndex = positions.length / 3;
|
|
1096
1125
|
positions.push(majorRadius * Math.cos(angle), 0, -majorRadius * Math.sin(angle));
|
|
1097
1126
|
normals.push(...normal);
|
|
1098
1127
|
textureCoordinates.push(0.5, 0.5);
|
|
1099
1128
|
for (let minorSegment = 0; minorSegment <= minorSegments; minorSegment++) {
|
|
1100
1129
|
const tubeAngle = minorSegment % minorSegments * Math.PI * 2 / minorSegments;
|
|
1101
|
-
const boundaryOffset = (minorSegment * (majorSegments + 1) + (
|
|
1130
|
+
const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction2 < 0 ? 0 : majorSegments)) * 3;
|
|
1102
1131
|
positions.push(...surfacePositions.slice(boundaryOffset, boundaryOffset + 3));
|
|
1103
1132
|
normals.push(...normal);
|
|
1104
1133
|
textureCoordinates.push((Math.cos(tubeAngle) + 1) / 2, (Math.sin(tubeAngle) + 1) / 2);
|
|
1105
1134
|
if (minorSegment < minorSegments) {
|
|
1106
1135
|
const firstIndex = centerIndex + minorSegment + 1;
|
|
1107
1136
|
const secondIndex = firstIndex + 1;
|
|
1108
|
-
indices.push(centerIndex, ...
|
|
1137
|
+
indices.push(centerIndex, ...direction2 > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
|
|
1109
1138
|
}
|
|
1110
1139
|
}
|
|
1111
1140
|
}
|
|
@@ -1160,8 +1189,8 @@ var LatheGeometry = class extends ParametricGeometry {
|
|
|
1160
1189
|
vSegments: profile.length - 1,
|
|
1161
1190
|
periodicU: phiLength === Math.PI * 2,
|
|
1162
1191
|
sample: (u, v) => {
|
|
1163
|
-
const { i, t } = section(v),
|
|
1164
|
-
return [
|
|
1192
|
+
const { i, t } = section(v), radius2 = profile[i][0] * (1 - t) + profile[i + 1][0] * t, height = profile[i][1] * (1 - t) + profile[i + 1][1] * t, theta = phiStart + u * phiLength;
|
|
1193
|
+
return [radius2 * Math.cos(theta), height, -radius2 * Math.sin(theta)];
|
|
1165
1194
|
},
|
|
1166
1195
|
normal: (u, v) => {
|
|
1167
1196
|
const { i, t } = section(v), n = profileNormals[i].map((value, axis) => value * (1 - t) + profileNormals[i + 1][axis] * t), theta = phiStart + u * phiLength;
|
|
@@ -1171,111 +1200,27 @@ var LatheGeometry = class extends ParametricGeometry {
|
|
|
1171
1200
|
}
|
|
1172
1201
|
};
|
|
1173
1202
|
|
|
1174
|
-
// dist/utils/constants.js
|
|
1175
|
-
var GL_PRIMITIVE = {
|
|
1176
|
-
POINTS: 0,
|
|
1177
|
-
LINES: 1,
|
|
1178
|
-
TRIANGLES: 4
|
|
1179
|
-
};
|
|
1180
|
-
var GL_PRIMITIVE_MODE = {
|
|
1181
|
-
POINTS: 0,
|
|
1182
|
-
LINES: 1,
|
|
1183
|
-
LINE_LOOP: 2,
|
|
1184
|
-
LINE_STRIP: 3,
|
|
1185
|
-
TRIANGLES: 4,
|
|
1186
|
-
TRIANGLE_STRIP: 5,
|
|
1187
|
-
TRIANGLE_FAN: 6
|
|
1188
|
-
};
|
|
1189
|
-
var GL_TYPE = {
|
|
1190
|
-
BYTE: 5120,
|
|
1191
|
-
UNSIGNED_BYTE: 5121,
|
|
1192
|
-
SHORT: 5122,
|
|
1193
|
-
UNSIGNED_SHORT: 5123,
|
|
1194
|
-
INT: 5124,
|
|
1195
|
-
UNSIGNED_INT: 5125,
|
|
1196
|
-
FLOAT: 5126,
|
|
1197
|
-
DOUBLE: 5130,
|
|
1198
|
-
UNSIGNED_SHORT_4_4_4_4: 32819,
|
|
1199
|
-
UNSIGNED_SHORT_5_5_5_1: 32820,
|
|
1200
|
-
UNSIGNED_SHORT_5_6_5: 33635
|
|
1201
|
-
};
|
|
1202
|
-
var GL = {
|
|
1203
|
-
...GL_PRIMITIVE_MODE,
|
|
1204
|
-
...GL_TYPE
|
|
1205
|
-
};
|
|
1206
|
-
|
|
1207
|
-
// dist/utils/gl-type.js
|
|
1208
|
-
var GL_TYPE_TO_ARRAY_TYPE = {
|
|
1209
|
-
[GL_TYPE.DOUBLE]: Float64Array,
|
|
1210
|
-
[GL_TYPE.FLOAT]: Float32Array,
|
|
1211
|
-
[GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
|
|
1212
|
-
[GL_TYPE.UNSIGNED_INT]: Uint32Array,
|
|
1213
|
-
[GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
|
|
1214
|
-
[GL_TYPE.BYTE]: Int8Array,
|
|
1215
|
-
[GL_TYPE.SHORT]: Int16Array,
|
|
1216
|
-
[GL_TYPE.INT]: Int32Array,
|
|
1217
|
-
[GL_TYPE.UNSIGNED_SHORT_4_4_4_4]: Uint16Array,
|
|
1218
|
-
[GL_TYPE.UNSIGNED_SHORT_5_5_5_1]: Uint16Array,
|
|
1219
|
-
[GL_TYPE.UNSIGNED_SHORT_5_6_5]: Uint16Array
|
|
1220
|
-
};
|
|
1221
|
-
var NAME_TO_GL_TYPE = Object.fromEntries(Object.entries(GL_TYPE).map(([name, glType]) => [name, glType]));
|
|
1222
|
-
var TYPE_CONVERSION_ERROR = "Failed to convert GL type";
|
|
1223
|
-
var GLType = class _GLType {
|
|
1224
|
-
/** Returns the WebGL component constant for a typed array or typed-array constructor. */
|
|
1225
|
-
static fromTypedArray(arrayOrType) {
|
|
1226
|
-
const arrayType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
1227
|
-
if (arrayType === Uint8ClampedArray) {
|
|
1228
|
-
return GL_TYPE.UNSIGNED_BYTE;
|
|
1229
|
-
}
|
|
1230
|
-
for (const [glType, candidateArrayType] of Object.entries(GL_TYPE_TO_ARRAY_TYPE)) {
|
|
1231
|
-
if (candidateArrayType === arrayType) {
|
|
1232
|
-
return Number(glType);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
1236
|
-
}
|
|
1237
|
-
/** Returns a WebGL component constant from its uppercase name. */
|
|
1238
|
-
static fromName(name) {
|
|
1239
|
-
const glType = NAME_TO_GL_TYPE[name];
|
|
1240
|
-
if (glType === void 0) {
|
|
1241
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
1242
|
-
}
|
|
1243
|
-
return glType;
|
|
1244
|
-
}
|
|
1245
|
-
/** Returns the typed-array constructor for a WebGL component constant. */
|
|
1246
|
-
static getArrayType(glType) {
|
|
1247
|
-
const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
|
|
1248
|
-
if (!ArrayType) {
|
|
1249
|
-
throw new Error(TYPE_CONVERSION_ERROR);
|
|
1250
|
-
}
|
|
1251
|
-
return ArrayType;
|
|
1252
|
-
}
|
|
1253
|
-
/** Returns the size in bytes of one element of a WebGL component type. */
|
|
1254
|
-
static getByteSize(glType) {
|
|
1255
|
-
return _GLType.getArrayType(glType).BYTES_PER_ELEMENT;
|
|
1256
|
-
}
|
|
1257
|
-
/** Returns whether a value is a supported WebGL component type. */
|
|
1258
|
-
static validate(glType) {
|
|
1259
|
-
return Boolean(GL_TYPE_TO_ARRAY_TYPE[glType]);
|
|
1260
|
-
}
|
|
1261
|
-
/** Creates a typed view over an ArrayBuffer or an existing ArrayBuffer view. */
|
|
1262
|
-
static createTypedArray(glType, buffer, byteOffset = 0, length) {
|
|
1263
|
-
const ArrayType = _GLType.getArrayType(glType);
|
|
1264
|
-
const arrayBuffer = ArrayBuffer.isView(buffer) ? buffer.buffer : buffer;
|
|
1265
|
-
const viewByteOffset = ArrayBuffer.isView(buffer) ? buffer.byteOffset : 0;
|
|
1266
|
-
const resolvedByteOffset = viewByteOffset + byteOffset;
|
|
1267
|
-
const resolvedLength = length ?? Math.floor((buffer.byteLength - byteOffset) / ArrayType.BYTES_PER_ELEMENT);
|
|
1268
|
-
return new ArrayType(arrayBuffer, resolvedByteOffset, resolvedLength);
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
1203
|
// dist/utils/geometry.js
|
|
1273
1204
|
function isGeometry(value) {
|
|
1274
1205
|
if (!value || typeof value !== "object") {
|
|
1275
1206
|
return false;
|
|
1276
1207
|
}
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1208
|
+
const { topology, attributes } = value;
|
|
1209
|
+
if (!attributes || typeof attributes !== "object" || Array.isArray(attributes) || ArrayBuffer.isView(attributes)) {
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
switch (topology) {
|
|
1213
|
+
case "point-list":
|
|
1214
|
+
case "line-list":
|
|
1215
|
+
case "line-strip":
|
|
1216
|
+
case "line-loop":
|
|
1217
|
+
case "triangle-list":
|
|
1218
|
+
case "triangle-strip":
|
|
1219
|
+
case "triangle-fan":
|
|
1220
|
+
return true;
|
|
1221
|
+
default:
|
|
1222
|
+
return false;
|
|
1223
|
+
}
|
|
1279
1224
|
}
|
|
1280
1225
|
function getAttributeValues(attribute) {
|
|
1281
1226
|
if (ArrayBuffer.isView(attribute)) {
|
|
@@ -1314,75 +1259,73 @@ function* makeAttributeIterator(values, size) {
|
|
|
1314
1259
|
}
|
|
1315
1260
|
|
|
1316
1261
|
// dist/utils/primitive-iterator.js
|
|
1317
|
-
function* makePrimitiveIterator(
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1262
|
+
function* makePrimitiveIterator(geometry, options = {}) {
|
|
1263
|
+
if (!isGeometry(geometry)) {
|
|
1264
|
+
throw new TypeError("Geometry with a supported topology and attributes is required");
|
|
1265
|
+
}
|
|
1266
|
+
const { start = 0 } = options;
|
|
1267
|
+
let end = options.end;
|
|
1268
|
+
const { attributes, topology } = geometry;
|
|
1269
|
+
const indices = geometry.indices ? getAttributeValues(geometry.indices) : void 0;
|
|
1270
|
+
if (end === void 0) {
|
|
1271
|
+
if (indices) {
|
|
1272
|
+
end = indices.length;
|
|
1273
|
+
} else {
|
|
1325
1274
|
const position = getPositionAttribute(geometry);
|
|
1326
|
-
end =
|
|
1275
|
+
end = getAttributeValues(position).length / (position.size || 3);
|
|
1327
1276
|
}
|
|
1328
|
-
} else if (geometryOrIndices) {
|
|
1329
|
-
indices = getAttributeValues(geometryOrIndices);
|
|
1330
1277
|
}
|
|
1331
|
-
if (mode === void 0) {
|
|
1332
|
-
throw new Error("Primitive mode is required");
|
|
1333
|
-
}
|
|
1334
|
-
end ?? (end = (indices == null ? void 0 : indices.length) ?? start);
|
|
1335
1278
|
const dereference = (index) => Number(indices ? indices[index] : index);
|
|
1336
1279
|
let primitiveIndex = 0;
|
|
1337
|
-
switch (
|
|
1338
|
-
case
|
|
1280
|
+
switch (topology) {
|
|
1281
|
+
case "point-list":
|
|
1339
1282
|
for (let index = start; index < end; index++) {
|
|
1340
1283
|
yield {
|
|
1341
1284
|
attributes,
|
|
1342
|
-
type:
|
|
1285
|
+
type: "point-list",
|
|
1343
1286
|
i1: dereference(index),
|
|
1344
1287
|
primitiveIndex: primitiveIndex++
|
|
1345
1288
|
};
|
|
1346
1289
|
}
|
|
1347
1290
|
return;
|
|
1348
|
-
case
|
|
1291
|
+
case "line-list":
|
|
1349
1292
|
for (let index = start; index + 1 < end; index += 2) {
|
|
1350
1293
|
yield {
|
|
1351
1294
|
attributes,
|
|
1352
|
-
type:
|
|
1295
|
+
type: "line-list",
|
|
1353
1296
|
i1: dereference(index),
|
|
1354
1297
|
i2: dereference(index + 1),
|
|
1355
1298
|
primitiveIndex: primitiveIndex++
|
|
1356
1299
|
};
|
|
1357
1300
|
}
|
|
1358
1301
|
return;
|
|
1359
|
-
case
|
|
1302
|
+
case "line-strip":
|
|
1360
1303
|
for (let index = start; index + 1 < end; index++) {
|
|
1361
1304
|
yield {
|
|
1362
1305
|
attributes,
|
|
1363
|
-
type:
|
|
1306
|
+
type: "line-list",
|
|
1364
1307
|
i1: dereference(index),
|
|
1365
1308
|
i2: dereference(index + 1),
|
|
1366
1309
|
primitiveIndex: primitiveIndex++
|
|
1367
1310
|
};
|
|
1368
1311
|
}
|
|
1369
1312
|
return;
|
|
1370
|
-
case
|
|
1313
|
+
case "line-loop":
|
|
1371
1314
|
for (let index = start; index < end; index++) {
|
|
1372
1315
|
yield {
|
|
1373
1316
|
attributes,
|
|
1374
|
-
type:
|
|
1317
|
+
type: "line-list",
|
|
1375
1318
|
i1: dereference(index),
|
|
1376
1319
|
i2: dereference(index + 1 < end ? index + 1 : start),
|
|
1377
1320
|
primitiveIndex: primitiveIndex++
|
|
1378
1321
|
};
|
|
1379
1322
|
}
|
|
1380
1323
|
return;
|
|
1381
|
-
case
|
|
1324
|
+
case "triangle-list":
|
|
1382
1325
|
for (let index = start; index + 2 < end; index += 3) {
|
|
1383
1326
|
yield {
|
|
1384
1327
|
attributes,
|
|
1385
|
-
type:
|
|
1328
|
+
type: "triangle-list",
|
|
1386
1329
|
i1: dereference(index),
|
|
1387
1330
|
i2: dereference(index + 1),
|
|
1388
1331
|
i3: dereference(index + 2),
|
|
@@ -1390,12 +1333,12 @@ function* makePrimitiveIterator(geometryOrIndices, attributes = {}, mode, start
|
|
|
1390
1333
|
};
|
|
1391
1334
|
}
|
|
1392
1335
|
return;
|
|
1393
|
-
case
|
|
1336
|
+
case "triangle-strip":
|
|
1394
1337
|
for (let index = start; index + 2 < end; index++) {
|
|
1395
1338
|
const odd = (index - start) % 2 === 1;
|
|
1396
1339
|
yield {
|
|
1397
1340
|
attributes,
|
|
1398
|
-
type:
|
|
1341
|
+
type: "triangle-list",
|
|
1399
1342
|
i1: dereference(odd ? index + 1 : index),
|
|
1400
1343
|
i2: dereference(odd ? index : index + 1),
|
|
1401
1344
|
i3: dereference(index + 2),
|
|
@@ -1403,11 +1346,11 @@ function* makePrimitiveIterator(geometryOrIndices, attributes = {}, mode, start
|
|
|
1403
1346
|
};
|
|
1404
1347
|
}
|
|
1405
1348
|
return;
|
|
1406
|
-
case
|
|
1349
|
+
case "triangle-fan":
|
|
1407
1350
|
for (let index = start + 1; index + 1 < end; index++) {
|
|
1408
1351
|
yield {
|
|
1409
1352
|
attributes,
|
|
1410
|
-
type:
|
|
1353
|
+
type: "triangle-list",
|
|
1411
1354
|
i1: dereference(start),
|
|
1412
1355
|
i2: dereference(index),
|
|
1413
1356
|
i3: dereference(index + 1),
|
|
@@ -1415,15 +1358,13 @@ function* makePrimitiveIterator(geometryOrIndices, attributes = {}, mode, start
|
|
|
1415
1358
|
};
|
|
1416
1359
|
}
|
|
1417
1360
|
return;
|
|
1418
|
-
default:
|
|
1419
|
-
throw new Error(`Unknown primitive mode ${mode}`);
|
|
1420
1361
|
}
|
|
1421
1362
|
}
|
|
1422
1363
|
|
|
1423
1364
|
// dist/utils/compute-vertex-normals.js
|
|
1424
1365
|
var import_core2 = require("@math.gl/core");
|
|
1425
1366
|
function computeVertexNormals(geometry) {
|
|
1426
|
-
if (geometry.
|
|
1367
|
+
if (geometry.topology !== "triangle-list" && geometry.topology !== "triangle-strip" && geometry.topology !== "triangle-fan") {
|
|
1427
1368
|
throw new Error("Triangle geometry is required");
|
|
1428
1369
|
}
|
|
1429
1370
|
const position = getPositionAttribute(geometry);
|
|
@@ -1680,26 +1621,26 @@ function transformGeometry(geometry, matrix) {
|
|
|
1680
1621
|
const positions = new Float64Array(mesh.count * 3);
|
|
1681
1622
|
const source = mesh.attributes[mesh.position].value;
|
|
1682
1623
|
for (let i = 0; i < mesh.count; i++) {
|
|
1683
|
-
const
|
|
1684
|
-
positions.set(
|
|
1624
|
+
const point2 = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
|
|
1625
|
+
positions.set(point2, i * 3);
|
|
1685
1626
|
}
|
|
1686
1627
|
attributes[mesh.position] = { size: 3, value: positions };
|
|
1687
1628
|
if (normalName) {
|
|
1688
1629
|
const input = mesh.attributes[normalName];
|
|
1689
1630
|
if (input.size !== 3)
|
|
1690
1631
|
throw new RangeError("Normals must have size 3");
|
|
1691
|
-
const
|
|
1632
|
+
const output2 = new Float64Array(mesh.count * 3);
|
|
1692
1633
|
for (let i = 0; i < mesh.count; i++) {
|
|
1693
1634
|
const value = normalizedLinearCombination(cofactors, Array.from(input.value.slice(i * 3, i * 3 + 3)), scales.map((v) => -Math.log(v)));
|
|
1694
|
-
|
|
1635
|
+
output2.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
|
|
1695
1636
|
}
|
|
1696
|
-
attributes[normalName] = { size: 3, value:
|
|
1637
|
+
attributes[normalName] = { size: 3, value: output2 };
|
|
1697
1638
|
}
|
|
1698
1639
|
if (tangentName) {
|
|
1699
1640
|
const input = mesh.attributes[tangentName];
|
|
1700
1641
|
if (input.size !== 4)
|
|
1701
1642
|
throw new RangeError("Tangents must have size 4");
|
|
1702
|
-
const
|
|
1643
|
+
const output2 = new Float64Array(mesh.count * 4);
|
|
1703
1644
|
for (let i = 0; i < mesh.count; i++) {
|
|
1704
1645
|
const value = normalizedLinearCombination(basis, Array.from(input.value.slice(i * 4, i * 4 + 3)), scales.map(Math.log));
|
|
1705
1646
|
if (normalName) {
|
|
@@ -1709,16 +1650,16 @@ function transformGeometry(geometry, matrix) {
|
|
|
1709
1650
|
value[axis] -= projection * n[axis];
|
|
1710
1651
|
}
|
|
1711
1652
|
const length = Math.hypot(...value);
|
|
1712
|
-
|
|
1713
|
-
|
|
1653
|
+
output2.set(value.map((v) => length ? v / length : 0), i * 4);
|
|
1654
|
+
output2[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
|
|
1714
1655
|
}
|
|
1715
|
-
attributes[tangentName] = { size: 4, value:
|
|
1656
|
+
attributes[tangentName] = { size: 4, value: output2 };
|
|
1716
1657
|
}
|
|
1717
1658
|
const indices = mesh.indices.slice();
|
|
1718
1659
|
if (determinant < 0)
|
|
1719
1660
|
for (let i = 0; i < indices.length; i += 3)
|
|
1720
1661
|
[indices[i + 1], indices[i + 2]] = [indices[i + 2], indices[i + 1]];
|
|
1721
|
-
return {
|
|
1662
|
+
return { topology: "triangle-list", attributes, indices };
|
|
1722
1663
|
}
|
|
1723
1664
|
function mergeGeometries(geometries) {
|
|
1724
1665
|
if (!geometries.length)
|
|
@@ -1756,7 +1697,7 @@ function mergeGeometries(geometries) {
|
|
|
1756
1697
|
indices[indexOffset++] = index + vertexOffset;
|
|
1757
1698
|
vertexOffset += mesh.count;
|
|
1758
1699
|
}
|
|
1759
|
-
return {
|
|
1700
|
+
return { topology: "triangle-list", attributes, indices };
|
|
1760
1701
|
}
|
|
1761
1702
|
function weldGeometry(geometry, options = {}) {
|
|
1762
1703
|
const mesh = readMesh(geometry), grid = options.positionGridSize ?? 0;
|
|
@@ -1793,7 +1734,7 @@ function weldGeometry(geometry, options = {}) {
|
|
|
1793
1734
|
}
|
|
1794
1735
|
return {
|
|
1795
1736
|
geometry: {
|
|
1796
|
-
|
|
1737
|
+
topology: "triangle-list",
|
|
1797
1738
|
attributes,
|
|
1798
1739
|
indices: Uint32Array.from(mesh.indices, (index) => vertexMap[index])
|
|
1799
1740
|
},
|
|
@@ -1835,7 +1776,7 @@ function getDegenerateTriangles(geometry, areaEpsilon = 0) {
|
|
|
1835
1776
|
return Uint32Array.from(result);
|
|
1836
1777
|
}
|
|
1837
1778
|
function readMesh(geometry) {
|
|
1838
|
-
if (geometry.
|
|
1779
|
+
if (geometry.topology !== "triangle-list")
|
|
1839
1780
|
throw new RangeError("Packed triangle-list geometry is required");
|
|
1840
1781
|
const position = geometry.attributes["POSITION"] ? "POSITION" : geometry.attributes["positions"] ? "positions" : null;
|
|
1841
1782
|
if (!position)
|
|
@@ -1914,7 +1855,10 @@ function toDyadic(value) {
|
|
|
1914
1855
|
const exponentBits = high >>> 20 & 2047;
|
|
1915
1856
|
const fraction = BigInt(high & 1048575) << 32n | BigInt(low);
|
|
1916
1857
|
const n = exponentBits ? 1n << 52n | fraction : fraction;
|
|
1917
|
-
return {
|
|
1858
|
+
return {
|
|
1859
|
+
n: high >>> 31 ? -n : n,
|
|
1860
|
+
exponent: exponentBits ? exponentBits - 1075 : -1074
|
|
1861
|
+
};
|
|
1918
1862
|
}
|
|
1919
1863
|
function subtractDyadic(a, b) {
|
|
1920
1864
|
const exponent = Math.min(a.exponent, b.exponent);
|
|
@@ -1972,8 +1916,8 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
1972
1916
|
}
|
|
1973
1917
|
const sourceCount = source.byteLength / byteStride;
|
|
1974
1918
|
const input = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
1975
|
-
const
|
|
1976
|
-
const result = new DataView(
|
|
1919
|
+
const output2 = new Uint8Array(outputBytes);
|
|
1920
|
+
const result = new DataView(output2.buffer);
|
|
1977
1921
|
for (let vertex2 = 0; vertex2 < outputCount; vertex2++) {
|
|
1978
1922
|
let sum = 0;
|
|
1979
1923
|
let firstSource = -1;
|
|
@@ -1994,7 +1938,7 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
1994
1938
|
if (firstSource < 0 || Math.abs(sum - 1) > 1e-10) {
|
|
1995
1939
|
throw new RangeError("Interpolation weights must sum to one");
|
|
1996
1940
|
}
|
|
1997
|
-
|
|
1941
|
+
output2.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
|
|
1998
1942
|
for (const attribute of attributes) {
|
|
1999
1943
|
for (let component = 0; component < attribute.size; component++) {
|
|
2000
1944
|
const offset = attribute.byteOffset + component * BYTE_SIZES[attribute.type];
|
|
@@ -2023,7 +1967,7 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
2023
1967
|
}
|
|
2024
1968
|
}
|
|
2025
1969
|
}
|
|
2026
|
-
return
|
|
1970
|
+
return output2;
|
|
2027
1971
|
}
|
|
2028
1972
|
function validateInterpolation(interpolation) {
|
|
2029
1973
|
if (interpolation !== "linear" && interpolation !== "flat") {
|
|
@@ -2082,11 +2026,11 @@ function writeComponent(view, offset, type, value, littleEndian) {
|
|
|
2082
2026
|
|
|
2083
2027
|
// dist/curves/curve.js
|
|
2084
2028
|
var Curve = class {
|
|
2085
|
-
constructor(
|
|
2086
|
-
if (
|
|
2029
|
+
constructor(dimension2) {
|
|
2030
|
+
if (dimension2 !== 2 && dimension2 !== 3) {
|
|
2087
2031
|
throw new RangeError("Curve points must have two or three coordinates");
|
|
2088
2032
|
}
|
|
2089
|
-
this.dimension =
|
|
2033
|
+
this.dimension = dimension2;
|
|
2090
2034
|
}
|
|
2091
2035
|
getPoint(t, result = new Array(this.dimension)) {
|
|
2092
2036
|
validateParameter(t);
|
|
@@ -2113,10 +2057,10 @@ var Curve = class {
|
|
|
2113
2057
|
getPoints(divisions = 64) {
|
|
2114
2058
|
validateDivisions(divisions);
|
|
2115
2059
|
const points = new Float64Array((divisions + 1) * this.dimension);
|
|
2116
|
-
const
|
|
2060
|
+
const point2 = new Array(this.dimension);
|
|
2117
2061
|
for (let i = 0; i <= divisions; i++) {
|
|
2118
|
-
this.getPoint(i / divisions,
|
|
2119
|
-
points.set(
|
|
2062
|
+
this.getPoint(i / divisions, point2);
|
|
2063
|
+
points.set(point2, i * this.dimension);
|
|
2120
2064
|
}
|
|
2121
2065
|
return points;
|
|
2122
2066
|
}
|
|
@@ -2124,14 +2068,14 @@ var Curve = class {
|
|
|
2124
2068
|
function copyPoints(points) {
|
|
2125
2069
|
if (!points.length)
|
|
2126
2070
|
throw new RangeError("Invalid number of curve control points");
|
|
2127
|
-
const
|
|
2128
|
-
if (
|
|
2071
|
+
const dimension2 = points[0].length;
|
|
2072
|
+
if (dimension2 !== 2 && dimension2 !== 3) {
|
|
2129
2073
|
throw new RangeError("Curve points must have two or three coordinates");
|
|
2130
2074
|
}
|
|
2131
|
-
return points.map((
|
|
2132
|
-
if (
|
|
2075
|
+
return points.map((point2) => {
|
|
2076
|
+
if (point2.length !== dimension2)
|
|
2133
2077
|
throw new RangeError("Control point dimensions must match");
|
|
2134
|
-
return Array.from(
|
|
2078
|
+
return Array.from(point2, (value) => {
|
|
2135
2079
|
if (!Number.isFinite(value))
|
|
2136
2080
|
throw new RangeError("Control coordinates must be finite");
|
|
2137
2081
|
return value;
|
|
@@ -2148,8 +2092,8 @@ function validateDivisions(divisions) {
|
|
|
2148
2092
|
throw new RangeError("divisions must be a positive safe integer");
|
|
2149
2093
|
}
|
|
2150
2094
|
}
|
|
2151
|
-
function validateResult(result,
|
|
2152
|
-
if (result.length <
|
|
2095
|
+
function validateResult(result, dimension2) {
|
|
2096
|
+
if (result.length < dimension2)
|
|
2153
2097
|
throw new RangeError("Result buffer is too short");
|
|
2154
2098
|
}
|
|
2155
2099
|
|
|
@@ -2241,7 +2185,7 @@ var CatmullRomCurve = class extends Curve {
|
|
|
2241
2185
|
if (options.tension !== void 0 && mode !== "uniform") {
|
|
2242
2186
|
throw new RangeError("tension is only supported for uniform splines");
|
|
2243
2187
|
}
|
|
2244
|
-
const
|
|
2188
|
+
const point2 = (index) => {
|
|
2245
2189
|
if (this.closed)
|
|
2246
2190
|
return data[(index + data.length) % data.length];
|
|
2247
2191
|
if (index < 0)
|
|
@@ -2253,10 +2197,10 @@ var CatmullRomCurve = class extends Curve {
|
|
|
2253
2197
|
};
|
|
2254
2198
|
this.segments = [];
|
|
2255
2199
|
for (let s = 0; s < data.length - (this.closed ? 0 : 1); s++) {
|
|
2256
|
-
const p0 =
|
|
2257
|
-
const p1 =
|
|
2258
|
-
const p2 =
|
|
2259
|
-
const p3 =
|
|
2200
|
+
const p0 = point2(s - 1);
|
|
2201
|
+
const p1 = point2(s);
|
|
2202
|
+
const p2 = point2(s + 1);
|
|
2203
|
+
const p3 = point2(s + 2);
|
|
2260
2204
|
const interval = (a, b) => {
|
|
2261
2205
|
const distance = Math.hypot(...a.map((x, i) => b[i] - x));
|
|
2262
2206
|
return distance ** (mode === "chordal" ? 1 : 0.5);
|
|
@@ -2333,23 +2277,144 @@ var CurveArcLength = class {
|
|
|
2333
2277
|
getSpacedPoints(divisions = 64) {
|
|
2334
2278
|
validateDivisions(divisions);
|
|
2335
2279
|
const points = new Float64Array((divisions + 1) * this.curve.dimension);
|
|
2336
|
-
const
|
|
2280
|
+
const point2 = new Array(this.curve.dimension);
|
|
2337
2281
|
for (let i = 0; i <= divisions; i++) {
|
|
2338
|
-
this.getPointAt(i / divisions,
|
|
2339
|
-
points.set(
|
|
2282
|
+
this.getPointAt(i / divisions, point2);
|
|
2283
|
+
points.set(point2, i * this.curve.dimension);
|
|
2340
2284
|
}
|
|
2341
2285
|
return points;
|
|
2342
2286
|
}
|
|
2343
2287
|
};
|
|
2344
2288
|
|
|
2289
|
+
// dist/curves/adaptive-sampling.js
|
|
2290
|
+
function sampleCurveAdaptive(curve, options) {
|
|
2291
|
+
const { tolerance, maxDepth = 16, maxPoints = 65536 } = options;
|
|
2292
|
+
if (!Number.isFinite(tolerance) || tolerance <= 0 || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !Number.isSafeInteger(maxPoints) || maxPoints < 2)
|
|
2293
|
+
throw new RangeError("Invalid adaptive sampling budget");
|
|
2294
|
+
const parameters = [0], positions = [...curve.getPoint(0)];
|
|
2295
|
+
let converged = true, maxSampledError = 0;
|
|
2296
|
+
const stack = [{ t0: 0, t1: 1, a: curve.getPoint(0), b: curve.getPoint(1), depth: 0 }];
|
|
2297
|
+
while (stack.length) {
|
|
2298
|
+
const segment = stack.pop();
|
|
2299
|
+
const { t0, t1, a, b, depth } = segment;
|
|
2300
|
+
const localEdge = b.map((x, i) => x - a[i]);
|
|
2301
|
+
const samples = [0.25, 0.5, 0.75].map((f) => curve.getPoint(t0 + (t1 - t0) * f));
|
|
2302
|
+
const localSamples = samples.map((point2) => point2.map((x, i) => x - a[i]));
|
|
2303
|
+
const local = [...localEdge, ...localSamples.flat()].every(Number.isFinite);
|
|
2304
|
+
const scale = local ? Math.max(...localEdge.map(Math.abs), ...localSamples.flat().map(Math.abs), Number.MIN_VALUE) : Math.max(...a.map(Math.abs), ...b.map(Math.abs), ...samples.flat().map(Math.abs));
|
|
2305
|
+
const edge = local ? localEdge.map((x) => x / scale) : b.map((x, i) => x / scale - a[i] / scale);
|
|
2306
|
+
const squared = edge.reduce((sum, x) => sum + x * x, 0);
|
|
2307
|
+
const measuredError = Math.max(...samples.map((p, sampleIndex) => {
|
|
2308
|
+
const offset = local ? localSamples[sampleIndex].map((x) => x / scale) : p.map((x, i) => x / scale - a[i] / scale);
|
|
2309
|
+
const t = squared ? Math.max(0, Math.min(1, edge.reduce((sum, x, i) => sum + x * offset[i], 0) / squared)) : 0;
|
|
2310
|
+
return Math.hypot(...offset.map((x, i) => x - t * edge[i])) * scale;
|
|
2311
|
+
}));
|
|
2312
|
+
const error = Number.isFinite(measuredError) ? measuredError : Infinity;
|
|
2313
|
+
if (error > tolerance && depth < maxDepth && parameters.length + stack.length + 2 <= maxPoints) {
|
|
2314
|
+
const mid = (t0 + t1) / 2;
|
|
2315
|
+
stack.push({ t0: mid, t1, a: samples[1], b, depth: depth + 1 });
|
|
2316
|
+
stack.push({ t0, t1: mid, a, b: samples[1], depth: depth + 1 });
|
|
2317
|
+
} else {
|
|
2318
|
+
if (error > tolerance)
|
|
2319
|
+
converged = false;
|
|
2320
|
+
maxSampledError = Math.max(maxSampledError, error);
|
|
2321
|
+
parameters.push(t1);
|
|
2322
|
+
positions.push(...b);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
return {
|
|
2326
|
+
parameters: new Float64Array(parameters),
|
|
2327
|
+
positions: new Float64Array(positions),
|
|
2328
|
+
converged,
|
|
2329
|
+
maxSampledError
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// dist/curves/parallel-transport.js
|
|
2334
|
+
var sub = (a, b) => a.map((x, i) => x - b[i]);
|
|
2335
|
+
var dot = (a, b) => a.reduce((sum, x, i) => sum + x * b[i], 0);
|
|
2336
|
+
var cross2 = (a, b) => [
|
|
2337
|
+
a[1] * b[2] - a[2] * b[1],
|
|
2338
|
+
a[2] * b[0] - a[0] * b[2],
|
|
2339
|
+
a[0] * b[1] - a[1] * b[0]
|
|
2340
|
+
];
|
|
2341
|
+
var unit = (a) => {
|
|
2342
|
+
const length = Math.hypot(...a);
|
|
2343
|
+
if (!length)
|
|
2344
|
+
throw new RangeError("Cannot construct a frame for a stationary path");
|
|
2345
|
+
return a.map((x) => x / length);
|
|
2346
|
+
};
|
|
2347
|
+
function rotate(v, axis, angle) {
|
|
2348
|
+
const c = Math.cos(angle), s = Math.sin(angle), d = dot(axis, v), k = cross2(axis, v);
|
|
2349
|
+
return v.map((x, i) => x * c + k[i] * s + axis[i] * d * (1 - c));
|
|
2350
|
+
}
|
|
2351
|
+
function computeParallelTransportFrames(points, options = {}) {
|
|
2352
|
+
if (points.length < 2 || points.some((p) => p.length !== 3 || Array.from(p).some((x) => !Number.isFinite(x))))
|
|
2353
|
+
throw new RangeError("Expected at least two finite 3D points");
|
|
2354
|
+
const data = points.map((p) => Array.from(p)), n = data.length, closed = options.closed ?? false;
|
|
2355
|
+
if (closed && (n < 4 || Math.hypot(...sub(data[0], data[n - 1])) !== 0))
|
|
2356
|
+
throw new RangeError("A closed path must repeat its first point");
|
|
2357
|
+
const tangent = new Array(n);
|
|
2358
|
+
const edges = new Array(n - 1);
|
|
2359
|
+
let last;
|
|
2360
|
+
for (let i = 0; i < n - 1; i++) {
|
|
2361
|
+
const edge = sub(data[i + 1], data[i]);
|
|
2362
|
+
if (Math.hypot(...edge) > 0)
|
|
2363
|
+
last = edges[i] = unit(edge);
|
|
2364
|
+
}
|
|
2365
|
+
if (!last)
|
|
2366
|
+
throw new RangeError("Cannot construct a frame for a stationary path");
|
|
2367
|
+
tangent[n - 1] = last;
|
|
2368
|
+
for (let i = n - 2; i >= 0; i--) {
|
|
2369
|
+
last = edges[i] ?? last;
|
|
2370
|
+
tangent[i] = last;
|
|
2371
|
+
}
|
|
2372
|
+
if (closed)
|
|
2373
|
+
tangent[n - 1] = [...tangent[0]];
|
|
2374
|
+
const t = tangent[0];
|
|
2375
|
+
let initial = options.initialNormal ? Array.from(options.initialNormal) : [0, 0, 0];
|
|
2376
|
+
if (options.initialNormal && (initial.length !== 3 || initial.some((x) => !Number.isFinite(x))))
|
|
2377
|
+
throw new RangeError("Invalid initial normal");
|
|
2378
|
+
if (!options.initialNormal) {
|
|
2379
|
+
initial = [0, 0, 0];
|
|
2380
|
+
initial[t.map(Math.abs).indexOf(Math.min(...t.map(Math.abs)))] = 1;
|
|
2381
|
+
}
|
|
2382
|
+
initial = unit(initial);
|
|
2383
|
+
const perpendicular = cross2(t, initial);
|
|
2384
|
+
if (Math.hypot(...perpendicular) <= 1e-12) {
|
|
2385
|
+
throw new RangeError("Initial normal must not be parallel to the tangent");
|
|
2386
|
+
}
|
|
2387
|
+
const normals = [unit(cross2(perpendicular, t))];
|
|
2388
|
+
for (let i = 1; i < n; i++) {
|
|
2389
|
+
const axis = cross2(tangent[i - 1], tangent[i]), length = Math.hypot(...axis), cosine = Math.max(-1, Math.min(1, dot(tangent[i - 1], tangent[i])));
|
|
2390
|
+
let normal = normals[i - 1];
|
|
2391
|
+
if (length > 1e-12)
|
|
2392
|
+
normal = rotate(normal, axis.map((x) => x / length), Math.atan2(length, cosine));
|
|
2393
|
+
normals.push(unit(normal.map((x, j) => x - dot(normal, tangent[i]) * tangent[i][j])));
|
|
2394
|
+
}
|
|
2395
|
+
if (closed) {
|
|
2396
|
+
const mismatch = Math.atan2(dot(tangent[0], cross2(normals[n - 1], normals[0])), dot(normals[n - 1], normals[0]));
|
|
2397
|
+
const lengths = [0];
|
|
2398
|
+
for (let i = 1; i < n; i++)
|
|
2399
|
+
lengths.push(lengths[i - 1] + Math.hypot(...sub(data[i], data[i - 1])));
|
|
2400
|
+
for (let i = 1; i < n; i++)
|
|
2401
|
+
normals[i] = rotate(normals[i], tangent[i], mismatch * lengths[i] / lengths[n - 1]);
|
|
2402
|
+
}
|
|
2403
|
+
return {
|
|
2404
|
+
tangents: new Float64Array(tangent.flat()),
|
|
2405
|
+
normals: new Float64Array(normals.flat()),
|
|
2406
|
+
binormals: new Float64Array(normals.flatMap((normal, i) => cross2(tangent[i], normal)))
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2345
2410
|
// dist/polygon/polygon.js
|
|
2346
2411
|
var import_core6 = require("@math.gl/core");
|
|
2347
2412
|
|
|
2348
2413
|
// dist/polygon/polygon-utils.js
|
|
2349
2414
|
var import_core5 = require("@math.gl/core");
|
|
2350
|
-
function modifyPolygonWindingDirection(points,
|
|
2415
|
+
function modifyPolygonWindingDirection(points, direction2, options = {}) {
|
|
2351
2416
|
const windingDirection = getPolygonWindingDirection(points, options);
|
|
2352
|
-
if (windingDirection !==
|
|
2417
|
+
if (windingDirection !== direction2) {
|
|
2353
2418
|
reversePolygon(points, options);
|
|
2354
2419
|
return true;
|
|
2355
2420
|
}
|
|
@@ -2401,9 +2466,9 @@ function reversePolygon(points, options) {
|
|
|
2401
2466
|
}
|
|
2402
2467
|
}
|
|
2403
2468
|
}
|
|
2404
|
-
function modifyPolygonWindingDirectionPoints(points,
|
|
2469
|
+
function modifyPolygonWindingDirectionPoints(points, direction2, options = {}) {
|
|
2405
2470
|
const currentDirection = getPolygonWindingDirectionPoints(points, options);
|
|
2406
|
-
if (currentDirection !==
|
|
2471
|
+
if (currentDirection !== direction2) {
|
|
2407
2472
|
points.reverse();
|
|
2408
2473
|
return true;
|
|
2409
2474
|
}
|
|
@@ -2505,16 +2570,34 @@ var Polygon = class {
|
|
|
2505
2570
|
* @param direction Requested winding direction.
|
|
2506
2571
|
* @return Returns true if the winding direction was changed.
|
|
2507
2572
|
*/
|
|
2508
|
-
modifyWindingDirection(
|
|
2573
|
+
modifyWindingDirection(direction2) {
|
|
2509
2574
|
if (this.isFlatArray) {
|
|
2510
|
-
return modifyPolygonWindingDirection(this.points,
|
|
2575
|
+
return modifyPolygonWindingDirection(this.points, direction2, this.options);
|
|
2511
2576
|
}
|
|
2512
|
-
return modifyPolygonWindingDirectionPoints(this.points,
|
|
2577
|
+
return modifyPolygonWindingDirectionPoints(this.points, direction2, this.options);
|
|
2513
2578
|
}
|
|
2514
2579
|
};
|
|
2515
2580
|
|
|
2516
2581
|
// dist/polygon/earcut.js
|
|
2517
2582
|
function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
2583
|
+
const savedIndex = vertexPoolIndex;
|
|
2584
|
+
const savedQueue = activeHoleQueue;
|
|
2585
|
+
if (!holeQueues[callDepth])
|
|
2586
|
+
holeQueues[callDepth] = [];
|
|
2587
|
+
activeHoleQueue = holeQueues[callDepth];
|
|
2588
|
+
callDepth++;
|
|
2589
|
+
try {
|
|
2590
|
+
return triangulate(positions, holeIndices, dim, areas, plane);
|
|
2591
|
+
} finally {
|
|
2592
|
+
activeHoleQueue.length = 0;
|
|
2593
|
+
activeHoleQueue = savedQueue;
|
|
2594
|
+
vertexPoolIndex = savedIndex;
|
|
2595
|
+
callDepth--;
|
|
2596
|
+
if (callDepth === 0 && vertexPool.length > 65536)
|
|
2597
|
+
vertexPool.length = 0;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
function triangulate(positions, holeIndices, dim, areas, plane) {
|
|
2518
2601
|
const hasHoles = holeIndices && holeIndices.length;
|
|
2519
2602
|
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
2520
2603
|
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
@@ -2531,11 +2614,13 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
|
2531
2614
|
if (hasHoles)
|
|
2532
2615
|
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
2533
2616
|
if (positions.length > 80 * dim) {
|
|
2534
|
-
|
|
2535
|
-
|
|
2617
|
+
const i0 = DimIndex[plane[0]];
|
|
2618
|
+
const i1 = DimIndex[plane[1]];
|
|
2619
|
+
minX = maxX = positions[i0];
|
|
2620
|
+
minY = maxY = positions[i1];
|
|
2536
2621
|
for (let i = dim; i < outerLen; i += dim) {
|
|
2537
|
-
x = positions[i];
|
|
2538
|
-
y = positions[i +
|
|
2622
|
+
x = positions[i + i0];
|
|
2623
|
+
y = positions[i + i1];
|
|
2539
2624
|
if (x < minX)
|
|
2540
2625
|
minX = x;
|
|
2541
2626
|
if (y < minY)
|
|
@@ -2548,23 +2633,44 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
|
2548
2633
|
invSize = Math.max(maxX - minX, maxY - minY);
|
|
2549
2634
|
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
2550
2635
|
}
|
|
2551
|
-
earcutLinked(outerNode, triangles,
|
|
2636
|
+
earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
|
|
2552
2637
|
return triangles;
|
|
2553
2638
|
}
|
|
2554
2639
|
function linkedList(data, start, end, dim, clockwise, area2, plane) {
|
|
2640
|
+
if (start >= end)
|
|
2641
|
+
return null;
|
|
2555
2642
|
let i;
|
|
2556
2643
|
let last;
|
|
2644
|
+
const i0 = DimIndex[plane[0]];
|
|
2645
|
+
const i1 = DimIndex[plane[1]];
|
|
2557
2646
|
if (area2 === void 0) {
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2647
|
+
let sum = 0;
|
|
2648
|
+
let previousX = data[end - dim + i0];
|
|
2649
|
+
let previousY = data[end - dim + i1];
|
|
2650
|
+
for (i = start; i < end; i += dim) {
|
|
2651
|
+
const x = data[i + i0];
|
|
2652
|
+
const y = data[i + i1];
|
|
2653
|
+
sum += (x - previousX) * (y + previousY);
|
|
2654
|
+
last = insertNode(i / dim, x, y, last);
|
|
2655
|
+
previousX = x;
|
|
2656
|
+
previousY = y;
|
|
2657
|
+
}
|
|
2658
|
+
if (last && clockwise !== sum / 2 < 0) {
|
|
2659
|
+
let node = last;
|
|
2660
|
+
do {
|
|
2661
|
+
const next = node.next;
|
|
2662
|
+
node.next = node.prev;
|
|
2663
|
+
node.prev = next;
|
|
2664
|
+
node = next;
|
|
2665
|
+
} while (node !== last);
|
|
2666
|
+
last = last.prev;
|
|
2667
|
+
}
|
|
2668
|
+
} else if (clockwise === area2 < 0) {
|
|
2563
2669
|
for (i = start; i < end; i += dim)
|
|
2564
|
-
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
2670
|
+
last = insertNode(i / dim, data[i + i0], data[i + i1], last);
|
|
2565
2671
|
} else {
|
|
2566
2672
|
for (i = end - dim; i >= start; i -= dim)
|
|
2567
|
-
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
2673
|
+
last = insertNode(i / dim, data[i + i0], data[i + i1], last);
|
|
2568
2674
|
}
|
|
2569
2675
|
if (last && equals2(last, last.next)) {
|
|
2570
2676
|
removeNode(last);
|
|
@@ -2593,7 +2699,7 @@ function filterPoints(start, end) {
|
|
|
2593
2699
|
} while (again || p !== end);
|
|
2594
2700
|
return end;
|
|
2595
2701
|
}
|
|
2596
|
-
function earcutLinked(ear, triangles,
|
|
2702
|
+
function earcutLinked(ear, triangles, minX, minY, invSize, pass) {
|
|
2597
2703
|
if (!ear)
|
|
2598
2704
|
return;
|
|
2599
2705
|
if (!pass && invSize)
|
|
@@ -2605,9 +2711,9 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
|
2605
2711
|
prev = ear.prev;
|
|
2606
2712
|
next = ear.next;
|
|
2607
2713
|
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
2608
|
-
triangles.push(prev.i
|
|
2609
|
-
triangles.push(ear.i
|
|
2610
|
-
triangles.push(next.i
|
|
2714
|
+
triangles.push(prev.i);
|
|
2715
|
+
triangles.push(ear.i);
|
|
2716
|
+
triangles.push(next.i);
|
|
2611
2717
|
removeNode(ear);
|
|
2612
2718
|
ear = next.next;
|
|
2613
2719
|
stop = next.next;
|
|
@@ -2616,12 +2722,12 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
|
2616
2722
|
ear = next;
|
|
2617
2723
|
if (ear === stop) {
|
|
2618
2724
|
if (!pass) {
|
|
2619
|
-
earcutLinked(filterPoints(ear), triangles,
|
|
2725
|
+
earcutLinked(filterPoints(ear), triangles, minX, minY, invSize, 1);
|
|
2620
2726
|
} else if (pass === 1) {
|
|
2621
|
-
ear = cureLocalIntersections(filterPoints(ear), triangles
|
|
2622
|
-
earcutLinked(ear, triangles,
|
|
2727
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles);
|
|
2728
|
+
earcutLinked(ear, triangles, minX, minY, invSize, 2);
|
|
2623
2729
|
} else if (pass === 2) {
|
|
2624
|
-
splitEarcut(ear, triangles,
|
|
2730
|
+
splitEarcut(ear, triangles, minX, minY, invSize);
|
|
2625
2731
|
}
|
|
2626
2732
|
break;
|
|
2627
2733
|
}
|
|
@@ -2691,15 +2797,15 @@ function isEarHashed(ear, minX, minY, invSize) {
|
|
|
2691
2797
|
}
|
|
2692
2798
|
return true;
|
|
2693
2799
|
}
|
|
2694
|
-
function cureLocalIntersections(start, triangles
|
|
2800
|
+
function cureLocalIntersections(start, triangles) {
|
|
2695
2801
|
let p = start;
|
|
2696
2802
|
do {
|
|
2697
2803
|
const a = p.prev;
|
|
2698
2804
|
const b = p.next.next;
|
|
2699
2805
|
if (!equals2(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
2700
|
-
triangles.push(a.i
|
|
2701
|
-
triangles.push(p.i
|
|
2702
|
-
triangles.push(b.i
|
|
2806
|
+
triangles.push(a.i);
|
|
2807
|
+
triangles.push(p.i);
|
|
2808
|
+
triangles.push(b.i);
|
|
2703
2809
|
removeNode(p);
|
|
2704
2810
|
removeNode(p.next);
|
|
2705
2811
|
p = start = b;
|
|
@@ -2708,7 +2814,7 @@ function cureLocalIntersections(start, triangles, dim) {
|
|
|
2708
2814
|
} while (p !== start);
|
|
2709
2815
|
return filterPoints(p);
|
|
2710
2816
|
}
|
|
2711
|
-
function splitEarcut(start, triangles,
|
|
2817
|
+
function splitEarcut(start, triangles, minX, minY, invSize) {
|
|
2712
2818
|
let a = start;
|
|
2713
2819
|
do {
|
|
2714
2820
|
let b = a.next.next;
|
|
@@ -2717,8 +2823,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
|
2717
2823
|
let c = splitPolygon(a, b);
|
|
2718
2824
|
a = filterPoints(a, a.next);
|
|
2719
2825
|
c = filterPoints(c, c.next);
|
|
2720
|
-
earcutLinked(a, triangles,
|
|
2721
|
-
earcutLinked(c, triangles,
|
|
2826
|
+
earcutLinked(a, triangles, minX, minY, invSize, 0);
|
|
2827
|
+
earcutLinked(c, triangles, minX, minY, invSize, 0);
|
|
2722
2828
|
return;
|
|
2723
2829
|
}
|
|
2724
2830
|
b = b.next;
|
|
@@ -2727,7 +2833,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
|
2727
2833
|
} while (a !== start);
|
|
2728
2834
|
}
|
|
2729
2835
|
function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
|
|
2730
|
-
const queue =
|
|
2836
|
+
const queue = activeHoleQueue;
|
|
2837
|
+
queue.length = 0;
|
|
2731
2838
|
let i;
|
|
2732
2839
|
let len;
|
|
2733
2840
|
let start;
|
|
@@ -2737,6 +2844,8 @@ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
|
|
|
2737
2844
|
start = holeIndices[i] * dim;
|
|
2738
2845
|
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
2739
2846
|
list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
|
|
2847
|
+
if (!list)
|
|
2848
|
+
continue;
|
|
2740
2849
|
if (list === list.next)
|
|
2741
2850
|
list.steiner = true;
|
|
2742
2851
|
queue.push(getLeftmost(list));
|
|
@@ -2949,8 +3058,8 @@ function middleInside(a, b) {
|
|
|
2949
3058
|
return inside;
|
|
2950
3059
|
}
|
|
2951
3060
|
function splitPolygon(a, b) {
|
|
2952
|
-
const a2 =
|
|
2953
|
-
const b2 =
|
|
3061
|
+
const a2 = allocateVertex(a.i, a.x, a.y);
|
|
3062
|
+
const b2 = allocateVertex(b.i, b.x, b.y);
|
|
2954
3063
|
const an = a.next;
|
|
2955
3064
|
const bp = b.prev;
|
|
2956
3065
|
a.next = b;
|
|
@@ -2964,7 +3073,7 @@ function splitPolygon(a, b) {
|
|
|
2964
3073
|
return b2;
|
|
2965
3074
|
}
|
|
2966
3075
|
function insertNode(i, x, y, last) {
|
|
2967
|
-
const p =
|
|
3076
|
+
const p = allocateVertex(i, x, y);
|
|
2968
3077
|
if (!last) {
|
|
2969
3078
|
p.prev = p;
|
|
2970
3079
|
p.next = p;
|
|
@@ -2984,6 +3093,24 @@ function removeNode(p) {
|
|
|
2984
3093
|
if (p.nextZ)
|
|
2985
3094
|
p.nextZ.prevZ = p.prevZ;
|
|
2986
3095
|
}
|
|
3096
|
+
var vertexPool = [];
|
|
3097
|
+
var vertexPoolIndex = 0;
|
|
3098
|
+
var holeQueues = [];
|
|
3099
|
+
var activeHoleQueue = [];
|
|
3100
|
+
var callDepth = 0;
|
|
3101
|
+
function allocateVertex(i, x, y) {
|
|
3102
|
+
let vertex2 = vertexPool[vertexPoolIndex];
|
|
3103
|
+
if (!vertex2)
|
|
3104
|
+
vertexPool[vertexPoolIndex] = vertex2 = new Vertex(i, x, y);
|
|
3105
|
+
vertexPoolIndex++;
|
|
3106
|
+
vertex2.i = i;
|
|
3107
|
+
vertex2.x = x;
|
|
3108
|
+
vertex2.y = y;
|
|
3109
|
+
vertex2.prev = vertex2.next = vertex2.prevZ = vertex2.nextZ = null;
|
|
3110
|
+
vertex2.z = 0;
|
|
3111
|
+
vertex2.steiner = false;
|
|
3112
|
+
return vertex2;
|
|
3113
|
+
}
|
|
2987
3114
|
var Vertex = class {
|
|
2988
3115
|
constructor(i, x, y) {
|
|
2989
3116
|
this.prev = null;
|
|
@@ -3147,6 +3274,234 @@ function bitCode(p, bbox) {
|
|
|
3147
3274
|
return code;
|
|
3148
3275
|
}
|
|
3149
3276
|
|
|
3277
|
+
// dist/polygon/pole-of-inaccessibility.js
|
|
3278
|
+
var MAX_GRID_CELLS_PER_AXIS = 64;
|
|
3279
|
+
var MIN_RELATIVE_PRECISION = 1e-6;
|
|
3280
|
+
var DEFAULT_POLE_SEARCH_SEGMENT_TESTS = 5e6;
|
|
3281
|
+
function getPoleOfInaccessibility(polygon, precision, budget = {
|
|
3282
|
+
segmentTests: DEFAULT_POLE_SEARCH_SEGMENT_TESTS
|
|
3283
|
+
}) {
|
|
3284
|
+
const outline = polygon[0];
|
|
3285
|
+
if (!outline || outline.length === 0) {
|
|
3286
|
+
return null;
|
|
3287
|
+
}
|
|
3288
|
+
const vertexCount = countFiniteVertices(polygon);
|
|
3289
|
+
if (vertexCount < 0) {
|
|
3290
|
+
return null;
|
|
3291
|
+
}
|
|
3292
|
+
const box = getRingBox(outline);
|
|
3293
|
+
const width = box.right - box.left;
|
|
3294
|
+
const height = box.top - box.bottom;
|
|
3295
|
+
if (width === 0 || height === 0) {
|
|
3296
|
+
return null;
|
|
3297
|
+
}
|
|
3298
|
+
const longSide = Math.max(width, height);
|
|
3299
|
+
const minTolerance = longSide * MIN_RELATIVE_PRECISION;
|
|
3300
|
+
const tolerance = Math.max(Number.isFinite(precision) && precision > 0 ? precision : 0, minTolerance);
|
|
3301
|
+
const search = new PoleSearch(polygon, vertexCount, budget);
|
|
3302
|
+
const [centroidX, centroidY] = getAreaCentroid(polygon[0]);
|
|
3303
|
+
if (!search.score(centroidX, centroidY, 0)) {
|
|
3304
|
+
return null;
|
|
3305
|
+
}
|
|
3306
|
+
if (!search.score(box.left + width / 2, box.bottom + height / 2, 0)) {
|
|
3307
|
+
return search.bestPoint();
|
|
3308
|
+
}
|
|
3309
|
+
const side = Math.max(Math.min(width, height), longSide / MAX_GRID_CELLS_PER_AXIS);
|
|
3310
|
+
const columns = Math.ceil(width / side);
|
|
3311
|
+
const rows = Math.ceil(height / side);
|
|
3312
|
+
for (let column = 0; column < columns; column++) {
|
|
3313
|
+
for (let row = 0; row < rows; row++) {
|
|
3314
|
+
const x = box.left + (column + 0.5) * side;
|
|
3315
|
+
const y = box.bottom + (row + 0.5) * side;
|
|
3316
|
+
if (!search.score(x, y, side / 2)) {
|
|
3317
|
+
return search.bestPoint();
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
search.refine(tolerance, minTolerance);
|
|
3322
|
+
return search.bestPoint();
|
|
3323
|
+
}
|
|
3324
|
+
function countFiniteVertices(polygon) {
|
|
3325
|
+
let count = 0;
|
|
3326
|
+
for (const ring of polygon) {
|
|
3327
|
+
for (const point2 of ring) {
|
|
3328
|
+
if (!Number.isFinite(point2[0]) || !Number.isFinite(point2[1])) {
|
|
3329
|
+
return -1;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
count += ring.length;
|
|
3333
|
+
}
|
|
3334
|
+
return count;
|
|
3335
|
+
}
|
|
3336
|
+
function getRingBox(ring) {
|
|
3337
|
+
let left = Infinity;
|
|
3338
|
+
let bottom = Infinity;
|
|
3339
|
+
let right = -Infinity;
|
|
3340
|
+
let top = -Infinity;
|
|
3341
|
+
for (const point2 of ring) {
|
|
3342
|
+
left = Math.min(left, point2[0]);
|
|
3343
|
+
right = Math.max(right, point2[0]);
|
|
3344
|
+
bottom = Math.min(bottom, point2[1]);
|
|
3345
|
+
top = Math.max(top, point2[1]);
|
|
3346
|
+
}
|
|
3347
|
+
return { left, bottom, right, top };
|
|
3348
|
+
}
|
|
3349
|
+
function getAreaCentroid(ring) {
|
|
3350
|
+
let twiceArea = 0;
|
|
3351
|
+
let sumX = 0;
|
|
3352
|
+
let sumY = 0;
|
|
3353
|
+
let previous = ring[ring.length - 1];
|
|
3354
|
+
for (const current of ring) {
|
|
3355
|
+
const cross6 = previous[0] * current[1] - current[0] * previous[1];
|
|
3356
|
+
twiceArea += cross6;
|
|
3357
|
+
sumX += (previous[0] + current[0]) * cross6;
|
|
3358
|
+
sumY += (previous[1] + current[1]) * cross6;
|
|
3359
|
+
previous = current;
|
|
3360
|
+
}
|
|
3361
|
+
if (twiceArea === 0) {
|
|
3362
|
+
return [ring[0][0], ring[0][1]];
|
|
3363
|
+
}
|
|
3364
|
+
return [sumX / (3 * twiceArea), sumY / (3 * twiceArea)];
|
|
3365
|
+
}
|
|
3366
|
+
var PoleSearch = class {
|
|
3367
|
+
constructor(polygon, vertexCount, budget) {
|
|
3368
|
+
this.centerX = [];
|
|
3369
|
+
this.centerY = [];
|
|
3370
|
+
this.halfSide = [];
|
|
3371
|
+
this.reach = [];
|
|
3372
|
+
this.heap = [];
|
|
3373
|
+
this.bestX = NaN;
|
|
3374
|
+
this.bestY = NaN;
|
|
3375
|
+
this.bestDistance = -Infinity;
|
|
3376
|
+
this.polygon = polygon;
|
|
3377
|
+
this.vertexCount = vertexCount;
|
|
3378
|
+
this.budget = budget;
|
|
3379
|
+
}
|
|
3380
|
+
/** The best point so far, or null if no scored point is inside the polygon. */
|
|
3381
|
+
bestPoint() {
|
|
3382
|
+
return this.bestDistance > 0 ? [this.bestX, this.bestY] : null;
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* Scores the square centered at (x, y), keeps its center if it is the best so far, and queues
|
|
3386
|
+
* the square if it has area. Returns false, without scoring, when the budget cannot pay.
|
|
3387
|
+
*/
|
|
3388
|
+
score(x, y, half) {
|
|
3389
|
+
if (this.budget.segmentTests < this.vertexCount) {
|
|
3390
|
+
return false;
|
|
3391
|
+
}
|
|
3392
|
+
this.budget.segmentTests -= this.vertexCount;
|
|
3393
|
+
const distance = getSignedOutlineDistance(this.polygon, x, y);
|
|
3394
|
+
if (distance > this.bestDistance) {
|
|
3395
|
+
this.bestX = x;
|
|
3396
|
+
this.bestY = y;
|
|
3397
|
+
this.bestDistance = distance;
|
|
3398
|
+
}
|
|
3399
|
+
if (half > 0) {
|
|
3400
|
+
this.enqueue(x, y, half, distance + half * Math.SQRT2);
|
|
3401
|
+
}
|
|
3402
|
+
return true;
|
|
3403
|
+
}
|
|
3404
|
+
/**
|
|
3405
|
+
* Splits the most promising squares until none can beat the best point by `tolerance`. While no
|
|
3406
|
+
* scored point is inside the polygon, `tolerance` does not apply: the search continues while a
|
|
3407
|
+
* square can hold an inside point and is larger than `minTolerance`.
|
|
3408
|
+
*/
|
|
3409
|
+
refine(tolerance, minTolerance) {
|
|
3410
|
+
while (this.heap.length > 0) {
|
|
3411
|
+
const index = this.dequeue();
|
|
3412
|
+
const reach = this.reach[index];
|
|
3413
|
+
if (this.bestDistance > 0 ? reach - this.bestDistance <= tolerance : reach <= 0) {
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
if (this.bestDistance <= 0 && this.halfSide[index] * Math.SQRT2 <= minTolerance) {
|
|
3417
|
+
continue;
|
|
3418
|
+
}
|
|
3419
|
+
const quarter = this.halfSide[index] / 2;
|
|
3420
|
+
const x = this.centerX[index];
|
|
3421
|
+
const y = this.centerY[index];
|
|
3422
|
+
if (!this.score(x - quarter, y - quarter, quarter) || !this.score(x + quarter, y - quarter, quarter) || !this.score(x - quarter, y + quarter, quarter) || !this.score(x + quarter, y + quarter, quarter)) {
|
|
3423
|
+
return;
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
enqueue(x, y, half, reach) {
|
|
3428
|
+
const index = this.reach.length;
|
|
3429
|
+
this.centerX.push(x);
|
|
3430
|
+
this.centerY.push(y);
|
|
3431
|
+
this.halfSide.push(half);
|
|
3432
|
+
this.reach.push(reach);
|
|
3433
|
+
const { heap } = this;
|
|
3434
|
+
let slot = heap.length;
|
|
3435
|
+
heap.push(index);
|
|
3436
|
+
while (slot > 0) {
|
|
3437
|
+
const parentSlot = slot - 1 >> 1;
|
|
3438
|
+
if (this.reach[heap[parentSlot]] >= reach) {
|
|
3439
|
+
break;
|
|
3440
|
+
}
|
|
3441
|
+
heap[slot] = heap[parentSlot];
|
|
3442
|
+
slot = parentSlot;
|
|
3443
|
+
}
|
|
3444
|
+
heap[slot] = index;
|
|
3445
|
+
}
|
|
3446
|
+
dequeue() {
|
|
3447
|
+
const { heap, reach } = this;
|
|
3448
|
+
const top = heap[0];
|
|
3449
|
+
const moved = heap.pop();
|
|
3450
|
+
const size = heap.length;
|
|
3451
|
+
if (size === 0) {
|
|
3452
|
+
return top;
|
|
3453
|
+
}
|
|
3454
|
+
let slot = 0;
|
|
3455
|
+
for (; ; ) {
|
|
3456
|
+
let next = slot * 2 + 1;
|
|
3457
|
+
if (next >= size) {
|
|
3458
|
+
break;
|
|
3459
|
+
}
|
|
3460
|
+
if (next + 1 < size && reach[heap[next + 1]] > reach[heap[next]]) {
|
|
3461
|
+
next += 1;
|
|
3462
|
+
}
|
|
3463
|
+
if (reach[heap[next]] <= reach[moved]) {
|
|
3464
|
+
break;
|
|
3465
|
+
}
|
|
3466
|
+
heap[slot] = heap[next];
|
|
3467
|
+
slot = next;
|
|
3468
|
+
}
|
|
3469
|
+
heap[slot] = moved;
|
|
3470
|
+
return top;
|
|
3471
|
+
}
|
|
3472
|
+
};
|
|
3473
|
+
function getSignedOutlineDistance(polygon, x, y) {
|
|
3474
|
+
let nearestSquared = Infinity;
|
|
3475
|
+
let crossings = 0;
|
|
3476
|
+
for (const ring of polygon) {
|
|
3477
|
+
let start = ring[ring.length - 1];
|
|
3478
|
+
for (const end of ring) {
|
|
3479
|
+
if (start[1] <= y !== end[1] <= y) {
|
|
3480
|
+
const t = (y - start[1]) / (end[1] - start[1]);
|
|
3481
|
+
if (start[0] + t * (end[0] - start[0]) > x) {
|
|
3482
|
+
crossings++;
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
nearestSquared = Math.min(nearestSquared, getSquaredSegmentDistance(x, y, start, end));
|
|
3486
|
+
start = end;
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
if (nearestSquared === 0) {
|
|
3490
|
+
return 0;
|
|
3491
|
+
}
|
|
3492
|
+
const distance = Math.sqrt(nearestSquared);
|
|
3493
|
+
return crossings % 2 === 1 ? distance : -distance;
|
|
3494
|
+
}
|
|
3495
|
+
function getSquaredSegmentDistance(x, y, start, end) {
|
|
3496
|
+
const edgeX = end[0] - start[0];
|
|
3497
|
+
const edgeY = end[1] - start[1];
|
|
3498
|
+
const lengthSquared = edgeX * edgeX + edgeY * edgeY;
|
|
3499
|
+
const along = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, ((x - start[0]) * edgeX + (y - start[1]) * edgeY) / lengthSquared));
|
|
3500
|
+
const offsetX = start[0] + along * edgeX - x;
|
|
3501
|
+
const offsetY = start[1] + along * edgeY - y;
|
|
3502
|
+
return offsetX * offsetX + offsetY * offsetY;
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3150
3505
|
// dist/polygon/cut-by-grid.js
|
|
3151
3506
|
function cutPolylineByGrid(positions, options) {
|
|
3152
3507
|
const { size = 2, broken = false, gridResolution = 10, gridOffset = [0, 0], startIndex = 0, endIndex = positions.length } = options || {};
|
|
@@ -3205,6 +3560,7 @@ function cutPolygonByGrid(positions, holeIndices = null, options) {
|
|
|
3205
3560
|
const { pos, types, holes } = queue.shift();
|
|
3206
3561
|
getBoundingBox(pos, size, holes[0] || pos.length, bbox);
|
|
3207
3562
|
cell = getGridCell(bbox[0], gridResolution, gridOffset, cell);
|
|
3563
|
+
containPoint(cell, bbox[0], gridResolution);
|
|
3208
3564
|
const code = bitCode(bbox[1], cell);
|
|
3209
3565
|
if (code) {
|
|
3210
3566
|
let parts = bisectPolygon(pos, types, size, 0, holes[0] || pos.length, cell, code);
|
|
@@ -3295,6 +3651,17 @@ function getGridCell(p, gridResolution, gridOffset, out) {
|
|
|
3295
3651
|
out[3] = bottom + gridResolution;
|
|
3296
3652
|
return out;
|
|
3297
3653
|
}
|
|
3654
|
+
function containPoint(cell, p, gridResolution) {
|
|
3655
|
+
for (let axis = 0; axis < 2; axis++) {
|
|
3656
|
+
if (p[axis] < cell[axis]) {
|
|
3657
|
+
cell[axis + 2] = cell[axis];
|
|
3658
|
+
cell[axis] -= gridResolution;
|
|
3659
|
+
} else if (p[axis] >= cell[axis + 2]) {
|
|
3660
|
+
cell[axis] = cell[axis + 2];
|
|
3661
|
+
cell[axis + 2] += gridResolution;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3298
3665
|
function moveToNeighborCell(cell, gridResolution, edge) {
|
|
3299
3666
|
if (edge & 8) {
|
|
3300
3667
|
cell[1] += gridResolution;
|
|
@@ -3476,16 +3843,16 @@ function subdividePolyline(input, options) {
|
|
|
3476
3843
|
throw new RangeError("Transform returned nonfinite coordinates");
|
|
3477
3844
|
return { source, target, fraction };
|
|
3478
3845
|
}
|
|
3479
|
-
function append(
|
|
3846
|
+
function append(point2, segment) {
|
|
3480
3847
|
if (segmentIndices.length >= maxVertices) {
|
|
3481
3848
|
throw new RangeError("Polyline subdivision exceeded maxVertices");
|
|
3482
3849
|
}
|
|
3483
|
-
for (const value of
|
|
3850
|
+
for (const value of point2.source)
|
|
3484
3851
|
sourcePositions.push(value);
|
|
3485
|
-
for (const value of
|
|
3852
|
+
for (const value of point2.target)
|
|
3486
3853
|
positions.push(value);
|
|
3487
3854
|
segmentIndices.push(segment);
|
|
3488
|
-
segmentFractions.push(
|
|
3855
|
+
segmentFractions.push(point2.fraction);
|
|
3489
3856
|
}
|
|
3490
3857
|
function sampledSource(sampler, fraction) {
|
|
3491
3858
|
const value = sampler.sample(fraction);
|
|
@@ -3505,10 +3872,10 @@ function subdividePolyline(input, options) {
|
|
|
3505
3872
|
let error = 0;
|
|
3506
3873
|
let midpoint;
|
|
3507
3874
|
for (const fraction of [0.25, 0.5, 0.75]) {
|
|
3508
|
-
const
|
|
3875
|
+
const point2 = interpolate(a, b, fraction, sampler);
|
|
3509
3876
|
if (fraction === 0.5)
|
|
3510
|
-
midpoint =
|
|
3511
|
-
const delta =
|
|
3877
|
+
midpoint = point2;
|
|
3878
|
+
const delta = point2.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
|
|
3512
3879
|
error = Math.max(error, Math.hypot(...delta));
|
|
3513
3880
|
}
|
|
3514
3881
|
const sourceLength = sampler ? sampler.length * (b.fraction - a.fraction) : Math.hypot(...a.source.map((value, i) => value - b.source[i]));
|
|
@@ -3554,6 +3921,7 @@ function subdividePolyline(input, options) {
|
|
|
3554
3921
|
|
|
3555
3922
|
// dist/polygon/subdivide-triangle-mesh.js
|
|
3556
3923
|
var EDGE_FRACTIONS = [0.25, 0.5, 0.75];
|
|
3924
|
+
var EDGE_SAMPLE_ORDER = [1, 0, 2];
|
|
3557
3925
|
var FACE_WEIGHTS = [
|
|
3558
3926
|
[1 / 3, 1 / 3, 1 / 3],
|
|
3559
3927
|
[0.5, 0.25, 0.25],
|
|
@@ -3561,10 +3929,12 @@ var FACE_WEIGHTS = [
|
|
|
3561
3929
|
[0.25, 0.25, 0.5]
|
|
3562
3930
|
];
|
|
3563
3931
|
function subdivideTriangleMesh(mesh, options) {
|
|
3564
|
-
const { transform, tolerance, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
|
|
3932
|
+
const { transform, tolerance, errorMetric, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
|
|
3565
3933
|
validateOptions();
|
|
3566
3934
|
const vertices = [];
|
|
3567
3935
|
let faces2 = [];
|
|
3936
|
+
const edgeErrors = /* @__PURE__ */ new Map();
|
|
3937
|
+
const edgeMidpointTargets = /* @__PURE__ */ new Map();
|
|
3568
3938
|
for (let i = 0; i < mesh.positions.length; i += size) {
|
|
3569
3939
|
const source = Array.from({ length: size }, (_, j) => mesh.positions[i + j]);
|
|
3570
3940
|
if (!source.every(Number.isFinite))
|
|
@@ -3589,11 +3959,14 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3589
3959
|
splitEdges.add(edgeKey(a, b));
|
|
3590
3960
|
}
|
|
3591
3961
|
}
|
|
3962
|
+
} else if (face.accepted) {
|
|
3592
3963
|
} else if (needsRefinement(face)) {
|
|
3593
3964
|
const [a, b, c] = face.vertices;
|
|
3594
3965
|
splitEdges.add(edgeKey(a, b));
|
|
3595
3966
|
splitEdges.add(edgeKey(b, c));
|
|
3596
3967
|
splitEdges.add(edgeKey(c, a));
|
|
3968
|
+
} else {
|
|
3969
|
+
face.accepted = true;
|
|
3597
3970
|
}
|
|
3598
3971
|
}
|
|
3599
3972
|
if (!splitEdges.size)
|
|
@@ -3608,7 +3981,7 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3608
3981
|
faces2 = refined;
|
|
3609
3982
|
}
|
|
3610
3983
|
function validateOptions() {
|
|
3611
|
-
if (typeof transform !== "function" || refinement !== "transform-error" && refinement !== "source-edge" || refinement === "transform-error" && (tolerance === void 0 || !Number.isFinite(tolerance) || tolerance <= 0) || refinement === "source-edge" && (tolerance !== void 0 || !Number.isFinite(maxEdgeLength)) || size !== 2 && size !== 3 || targetSize !== 2 && targetSize !== 3 || !(maxEdgeLength > 0) || !Number.isFinite(maxEdgeLength) && maxEdgeLength !== Infinity || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !validLimit(maxVertices) || !validLimit(maxTriangles) || !Number.isSafeInteger(mesh.positions.length) || mesh.positions.length < 0 || mesh.positions.length % size !== 0 || !Number.isSafeInteger(mesh.indices.length) || mesh.indices.length < 0 || mesh.indices.length % 3 !== 0)
|
|
3984
|
+
if (typeof transform !== "function" || errorMetric !== void 0 && typeof errorMetric !== "function" || refinement !== "transform-error" && refinement !== "source-edge" || refinement === "transform-error" && (tolerance === void 0 || !Number.isFinite(tolerance) || tolerance <= 0) || refinement === "source-edge" && (tolerance !== void 0 || errorMetric !== void 0 || !Number.isFinite(maxEdgeLength)) || size !== 2 && size !== 3 || targetSize !== 2 && targetSize !== 3 || !(maxEdgeLength > 0) || !Number.isFinite(maxEdgeLength) && maxEdgeLength !== Infinity || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !validLimit(maxVertices) || !validLimit(maxTriangles) || !Number.isSafeInteger(mesh.positions.length) || mesh.positions.length < 0 || mesh.positions.length % size !== 0 || !Number.isSafeInteger(mesh.indices.length) || mesh.indices.length < 0 || mesh.indices.length % 3 !== 0)
|
|
3612
3985
|
throw new RangeError("Invalid triangle mesh subdivision options or input lengths");
|
|
3613
3986
|
if (mesh.positions.length / size > maxVertices || mesh.indices.length / 3 > maxTriangles) {
|
|
3614
3987
|
throw new RangeError("Input mesh exceeds subdivision limits");
|
|
@@ -3624,30 +3997,56 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3624
3997
|
throw new RangeError("Transform returned nonfinite coordinates");
|
|
3625
3998
|
return target;
|
|
3626
3999
|
}
|
|
3627
|
-
function error(points, weights) {
|
|
4000
|
+
function error(points, weights, keepExact) {
|
|
3628
4001
|
const source = blend(points.map((p) => p.source), weights);
|
|
3629
4002
|
const linearTarget = blend(points.map((p) => p.target), weights);
|
|
3630
|
-
|
|
4003
|
+
const exact = project(source);
|
|
4004
|
+
keepExact == null ? void 0 : keepExact.push(exact);
|
|
4005
|
+
if (!errorMetric)
|
|
4006
|
+
return Math.hypot(...exact.map((value2, i) => value2 - linearTarget[i]));
|
|
4007
|
+
const value = errorMetric({ source, exact: exact.slice(), interpolated: linearTarget });
|
|
4008
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
4009
|
+
throw new RangeError("errorMetric must return a finite nonnegative value");
|
|
4010
|
+
}
|
|
4011
|
+
return value;
|
|
4012
|
+
}
|
|
4013
|
+
function edgeError(a, b, sample) {
|
|
4014
|
+
const key = edgeKey(a, b);
|
|
4015
|
+
let errors = edgeErrors.get(key);
|
|
4016
|
+
if (!errors) {
|
|
4017
|
+
errors = [];
|
|
4018
|
+
edgeErrors.set(key, errors);
|
|
4019
|
+
}
|
|
4020
|
+
const slot = a <= b ? sample : EDGE_FRACTIONS.length - 1 - sample;
|
|
4021
|
+
let value = errors[slot];
|
|
4022
|
+
if (value === void 0) {
|
|
4023
|
+
const fraction = EDGE_FRACTIONS[sample];
|
|
4024
|
+
const keepExact = fraction === 0.5 ? [] : void 0;
|
|
4025
|
+
value = error([vertices[a], vertices[b]], [1 - fraction, fraction], keepExact);
|
|
4026
|
+
errors[slot] = value;
|
|
4027
|
+
if (keepExact)
|
|
4028
|
+
edgeMidpointTargets.set(key, keepExact[0]);
|
|
4029
|
+
}
|
|
4030
|
+
return value;
|
|
3631
4031
|
}
|
|
3632
4032
|
function needsRefinement(face) {
|
|
3633
4033
|
const points = face.vertices.map((index) => vertices[index]);
|
|
3634
|
-
|
|
4034
|
+
const limit = tolerance ?? Infinity;
|
|
3635
4035
|
for (let i = 0; i < 3; i++) {
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
exceedsTolerance = true;
|
|
4036
|
+
if (sourceEdgeLength(points[i], points[(i + 1) % 3]) > maxEdgeLength)
|
|
4037
|
+
return true;
|
|
4038
|
+
}
|
|
4039
|
+
for (const sample of EDGE_SAMPLE_ORDER) {
|
|
4040
|
+
for (let i = 0; i < 3; i++) {
|
|
4041
|
+
if (edgeError(face.vertices[i], face.vertices[(i + 1) % 3], sample) > limit)
|
|
4042
|
+
return true;
|
|
3644
4043
|
}
|
|
3645
4044
|
}
|
|
3646
4045
|
for (const weights of FACE_WEIGHTS) {
|
|
3647
|
-
if (error(points, weights) >
|
|
3648
|
-
|
|
4046
|
+
if (error(points, weights) > limit)
|
|
4047
|
+
return true;
|
|
3649
4048
|
}
|
|
3650
|
-
return
|
|
4049
|
+
return false;
|
|
3651
4050
|
}
|
|
3652
4051
|
function midpoint(a, b, midpoints) {
|
|
3653
4052
|
const key = edgeKey(a, b);
|
|
@@ -3666,19 +4065,21 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3666
4065
|
if (weights.size > 3)
|
|
3667
4066
|
throw new Error("Inconsistent mesh provenance");
|
|
3668
4067
|
const index = vertices.length;
|
|
3669
|
-
vertices.push({ source, target: project(source), weights });
|
|
4068
|
+
vertices.push({ source, target: edgeMidpointTargets.get(key) ?? project(source), weights });
|
|
3670
4069
|
midpoints.set(key, index);
|
|
3671
4070
|
return index;
|
|
3672
4071
|
}
|
|
3673
|
-
function splitFace(face,
|
|
4072
|
+
function splitFace(face, output2, splitEdges, midpoints) {
|
|
3674
4073
|
const [a, b, c] = face.vertices;
|
|
3675
4074
|
const ab = splitEdges.has(edgeKey(a, b)) ? midpoint(a, b, midpoints) : -1;
|
|
3676
4075
|
const bc = splitEdges.has(edgeKey(b, c)) ? midpoint(b, c, midpoints) : -1;
|
|
3677
4076
|
const ca = splitEdges.has(edgeKey(c, a)) ? midpoint(c, a, midpoints) : -1;
|
|
3678
4077
|
const count = Number(ab >= 0) + Number(bc >= 0) + Number(ca >= 0);
|
|
3679
|
-
if (count === 0)
|
|
3680
|
-
|
|
3681
|
-
|
|
4078
|
+
if (count === 0) {
|
|
4079
|
+
if (output2.length >= maxTriangles)
|
|
4080
|
+
throw new RangeError("Triangle mesh subdivision exceeded maxTriangles");
|
|
4081
|
+
output2.push(face);
|
|
4082
|
+
} else if (count === 3) {
|
|
3682
4083
|
emit(a, ab, ca);
|
|
3683
4084
|
emit(ab, b, bc);
|
|
3684
4085
|
emit(ca, bc, c);
|
|
@@ -3703,9 +4104,9 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3703
4104
|
}
|
|
3704
4105
|
}
|
|
3705
4106
|
function emit(x, y, z) {
|
|
3706
|
-
if (
|
|
4107
|
+
if (output2.length >= maxTriangles)
|
|
3707
4108
|
throw new RangeError("Triangle mesh subdivision exceeded maxTriangles");
|
|
3708
|
-
|
|
4109
|
+
output2.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
|
|
3709
4110
|
}
|
|
3710
4111
|
}
|
|
3711
4112
|
function buildResult() {
|
|
@@ -3768,8 +4169,8 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3768
4169
|
const positions = [], indices = [], sourceVertexIndices = [], sourceVertexWeights = [];
|
|
3769
4170
|
const sourceTriangleIndices = [], periodicCopies = [];
|
|
3770
4171
|
let intersections = 0;
|
|
3771
|
-
for (let
|
|
3772
|
-
const originalIndices = inputIndices.slice(
|
|
4172
|
+
for (let triangle2 = 0; triangle2 < inputIndices.length / 3; triangle2++) {
|
|
4173
|
+
const originalIndices = inputIndices.slice(triangle2 * 3, triangle2 * 3 + 3);
|
|
3773
4174
|
const vertices = originalIndices.map((index, j) => ({
|
|
3774
4175
|
position: source.slice(index * size, index * size + size),
|
|
3775
4176
|
weights: [0, 1, 2].map((k) => Number(k === j))
|
|
@@ -3801,7 +4202,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3801
4202
|
const clipped = [];
|
|
3802
4203
|
for (let i = 0; i < polygon.length; i++) {
|
|
3803
4204
|
const p = polygon[i], q = polygon[(i + 1) % polygon.length];
|
|
3804
|
-
const dp =
|
|
4205
|
+
const dp = cross3(a, b, p.position), dq = cross3(a, b, q.position);
|
|
3805
4206
|
if (dp >= 0)
|
|
3806
4207
|
clipped.push(p);
|
|
3807
4208
|
if (dp < 0 !== dq < 0) {
|
|
@@ -3817,7 +4218,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3817
4218
|
}
|
|
3818
4219
|
for (let j = 1; j + 1 < polygon.length; j++) {
|
|
3819
4220
|
const face = [polygon[0], polygon[j], polygon[j + 1]];
|
|
3820
|
-
if (
|
|
4221
|
+
if (cross3(face[0].position, face[1].position, face[2].position) === 0)
|
|
3821
4222
|
continue;
|
|
3822
4223
|
if (positions.length / size + 3 > maxVertices || indices.length / 3 + 1 > maxTriangles)
|
|
3823
4224
|
throw new RangeError("Mesh clipping exceeded output limits");
|
|
@@ -3827,7 +4228,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3827
4228
|
sourceVertexIndices.push(...originalIndices);
|
|
3828
4229
|
sourceVertexWeights.push(...vertex2.weights);
|
|
3829
4230
|
}
|
|
3830
|
-
sourceTriangleIndices.push(
|
|
4231
|
+
sourceTriangleIndices.push(triangle2);
|
|
3831
4232
|
periodicCopies.push(copy2);
|
|
3832
4233
|
}
|
|
3833
4234
|
}
|
|
@@ -3842,7 +4243,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3842
4243
|
periodicCopies: new Int32Array(periodicCopies)
|
|
3843
4244
|
};
|
|
3844
4245
|
}
|
|
3845
|
-
function
|
|
4246
|
+
function cross3(a, b, p) {
|
|
3846
4247
|
const result = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
|
|
3847
4248
|
if (!Number.isFinite(result))
|
|
3848
4249
|
throw new RangeError("Unrepresentable clipping arithmetic");
|
|
@@ -3853,13 +4254,13 @@ function validateRegion(region) {
|
|
|
3853
4254
|
throw new RangeError("Invalid convex clipping region");
|
|
3854
4255
|
let area2 = 0;
|
|
3855
4256
|
for (let i = 1; i + 1 < region.length; i++)
|
|
3856
|
-
area2 +=
|
|
4257
|
+
area2 += cross3(region[0], region[i], region[i + 1]);
|
|
3857
4258
|
if (!Number.isFinite(area2) || area2 === 0)
|
|
3858
4259
|
throw new RangeError("Degenerate clipping region");
|
|
3859
4260
|
const result = area2 > 0 ? Array.from(region) : Array.from(region).reverse();
|
|
3860
4261
|
for (let i = 0; i < result.length; i++) {
|
|
3861
4262
|
const a = result[i], b = result[(i + 1) % result.length];
|
|
3862
|
-
if (a[0] === b[0] && a[1] === b[1] || result.some((p) =>
|
|
4263
|
+
if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross3(a, b, p) < 0))
|
|
3863
4264
|
throw new RangeError("Clip region must be convex");
|
|
3864
4265
|
}
|
|
3865
4266
|
return result;
|
|
@@ -3902,15 +4303,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
|
|
|
3902
4303
|
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
3903
4304
|
}
|
|
3904
4305
|
/**
|
|
3905
|
-
*
|
|
3906
|
-
* @param transform The transformation matrix
|
|
3907
|
-
* @returns itself, i.e. the modified
|
|
4306
|
+
* Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
|
|
4307
|
+
* @param transform The affine transformation matrix.
|
|
4308
|
+
* @returns itself, i.e. the modified bounding box.
|
|
3908
4309
|
*/
|
|
3909
4310
|
transform(transform) {
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
this.maximum.
|
|
4311
|
+
if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
|
|
4312
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
4313
|
+
}
|
|
4314
|
+
const center = this.minimum.clone().add(this.maximum).scale(0.5);
|
|
4315
|
+
const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
|
|
4316
|
+
if (extent.some((x) => x < 0))
|
|
4317
|
+
throw new RangeError("Bounds must be ordered");
|
|
4318
|
+
center.transformAsPoint(transform);
|
|
4319
|
+
for (let row = 0; row < 3; row++) {
|
|
4320
|
+
this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
|
|
4321
|
+
}
|
|
4322
|
+
this.center.copy(center);
|
|
4323
|
+
this.minimum.copy(center).subtract(this.halfDiagonal);
|
|
4324
|
+
this.maximum.copy(center).add(this.halfDiagonal);
|
|
3914
4325
|
return this;
|
|
3915
4326
|
}
|
|
3916
4327
|
/**
|
|
@@ -3930,12 +4341,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
|
|
|
3930
4341
|
return "intersecting";
|
|
3931
4342
|
}
|
|
3932
4343
|
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
3933
|
-
distanceTo(
|
|
3934
|
-
return Math.sqrt(this.distanceSquaredTo(
|
|
4344
|
+
distanceTo(point2) {
|
|
4345
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
3935
4346
|
}
|
|
3936
4347
|
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
3937
|
-
distanceSquaredTo(
|
|
3938
|
-
const offset = scratchVector.from(
|
|
4348
|
+
distanceSquaredTo(point2) {
|
|
4349
|
+
const offset = scratchVector.from(point2).subtract(this.center);
|
|
3939
4350
|
const { halfDiagonal } = this;
|
|
3940
4351
|
let distanceSquared = 0;
|
|
3941
4352
|
let d;
|
|
@@ -3962,15 +4373,15 @@ var scratchVector4 = new import_core8.Vector3();
|
|
|
3962
4373
|
var scratchVector22 = new import_core8.Vector3();
|
|
3963
4374
|
var BoundingSphere = class _BoundingSphere {
|
|
3964
4375
|
/** Creates a bounding sphere */
|
|
3965
|
-
constructor(center = [0, 0, 0],
|
|
4376
|
+
constructor(center = [0, 0, 0], radius2 = 0) {
|
|
3966
4377
|
this.radius = -0;
|
|
3967
4378
|
this.center = new import_core8.Vector3();
|
|
3968
|
-
this.fromCenterRadius(center,
|
|
4379
|
+
this.fromCenterRadius(center, radius2);
|
|
3969
4380
|
}
|
|
3970
4381
|
/** Sets the bounding sphere from `center` and `radius`. */
|
|
3971
|
-
fromCenterRadius(center,
|
|
4382
|
+
fromCenterRadius(center, radius2) {
|
|
3972
4383
|
this.center.from(center);
|
|
3973
|
-
this.radius =
|
|
4384
|
+
this.radius = radius2;
|
|
3974
4385
|
return this;
|
|
3975
4386
|
}
|
|
3976
4387
|
/**
|
|
@@ -4012,11 +4423,11 @@ var BoundingSphere = class _BoundingSphere {
|
|
|
4012
4423
|
return this;
|
|
4013
4424
|
}
|
|
4014
4425
|
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
4015
|
-
expand(
|
|
4016
|
-
const scratchPoint = scratchVector4.from(
|
|
4017
|
-
const
|
|
4018
|
-
if (
|
|
4019
|
-
this.radius =
|
|
4426
|
+
expand(point2) {
|
|
4427
|
+
const scratchPoint = scratchVector4.from(point2);
|
|
4428
|
+
const radius2 = scratchPoint.subtract(this.center).magnitude();
|
|
4429
|
+
if (radius2 > this.radius) {
|
|
4430
|
+
this.radius = radius2;
|
|
4020
4431
|
}
|
|
4021
4432
|
return this;
|
|
4022
4433
|
}
|
|
@@ -4034,26 +4445,26 @@ var BoundingSphere = class _BoundingSphere {
|
|
|
4034
4445
|
return this;
|
|
4035
4446
|
}
|
|
4036
4447
|
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
4037
|
-
distanceSquaredTo(
|
|
4038
|
-
const d = this.distanceTo(
|
|
4448
|
+
distanceSquaredTo(point2) {
|
|
4449
|
+
const d = this.distanceTo(point2);
|
|
4039
4450
|
return d * d;
|
|
4040
4451
|
}
|
|
4041
4452
|
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
4042
|
-
distanceTo(
|
|
4043
|
-
const scratchPoint = scratchVector4.from(
|
|
4453
|
+
distanceTo(point2) {
|
|
4454
|
+
const scratchPoint = scratchVector4.from(point2);
|
|
4044
4455
|
const delta = scratchPoint.subtract(this.center);
|
|
4045
4456
|
return Math.max(0, delta.len() - this.radius);
|
|
4046
4457
|
}
|
|
4047
4458
|
/** Determines which side of a plane a sphere is located. */
|
|
4048
4459
|
intersectPlane(plane) {
|
|
4049
4460
|
const center = this.center;
|
|
4050
|
-
const
|
|
4461
|
+
const radius2 = this.radius;
|
|
4051
4462
|
const normal = plane.normal;
|
|
4052
4463
|
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
4053
|
-
if (distanceToPlane < -
|
|
4464
|
+
if (distanceToPlane < -radius2) {
|
|
4054
4465
|
return "outside";
|
|
4055
4466
|
}
|
|
4056
|
-
if (distanceToPlane <
|
|
4467
|
+
if (distanceToPlane < radius2) {
|
|
4057
4468
|
return "intersecting";
|
|
4058
4469
|
}
|
|
4059
4470
|
return "inside";
|
|
@@ -4129,16 +4540,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4129
4540
|
return "intersecting";
|
|
4130
4541
|
}
|
|
4131
4542
|
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
4132
|
-
distanceTo(
|
|
4133
|
-
return Math.sqrt(this.distanceSquaredTo(
|
|
4543
|
+
distanceTo(point2) {
|
|
4544
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
4134
4545
|
}
|
|
4135
4546
|
/**
|
|
4136
4547
|
* Computes the estimated distance squared from the closest point
|
|
4137
4548
|
* on a bounding box to a point.
|
|
4138
4549
|
* See Geometric Tools for Computer Graphics 10.4.2
|
|
4139
4550
|
*/
|
|
4140
|
-
distanceSquaredTo(
|
|
4141
|
-
const offset = scratchOffset.from(
|
|
4551
|
+
distanceSquaredTo(point2) {
|
|
4552
|
+
const offset = scratchOffset.from(point2).subtract(this.center);
|
|
4142
4553
|
const halfAxes = this.halfAxes;
|
|
4143
4554
|
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
4144
4555
|
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
@@ -4180,7 +4591,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4180
4591
|
* on the bounding box from position in direction.
|
|
4181
4592
|
*/
|
|
4182
4593
|
// eslint-disable-next-line max-statements
|
|
4183
|
-
computePlaneDistances(position,
|
|
4594
|
+
computePlaneDistances(position, direction2, result = [-0, -0]) {
|
|
4184
4595
|
let minDist = Number.POSITIVE_INFINITY;
|
|
4185
4596
|
let maxDist = Number.NEGATIVE_INFINITY;
|
|
4186
4597
|
const center = this.center;
|
|
@@ -4190,42 +4601,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4190
4601
|
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
4191
4602
|
const corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
4192
4603
|
const toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
4193
|
-
let mag =
|
|
4604
|
+
let mag = direction2.dot(toCenter);
|
|
4194
4605
|
minDist = Math.min(mag, minDist);
|
|
4195
4606
|
maxDist = Math.max(mag, maxDist);
|
|
4196
4607
|
corner.copy(center).add(u).add(v).subtract(w);
|
|
4197
4608
|
toCenter.copy(corner).subtract(position);
|
|
4198
|
-
mag =
|
|
4609
|
+
mag = direction2.dot(toCenter);
|
|
4199
4610
|
minDist = Math.min(mag, minDist);
|
|
4200
4611
|
maxDist = Math.max(mag, maxDist);
|
|
4201
4612
|
corner.copy(center).add(u).subtract(v).add(w);
|
|
4202
4613
|
toCenter.copy(corner).subtract(position);
|
|
4203
|
-
mag =
|
|
4614
|
+
mag = direction2.dot(toCenter);
|
|
4204
4615
|
minDist = Math.min(mag, minDist);
|
|
4205
4616
|
maxDist = Math.max(mag, maxDist);
|
|
4206
4617
|
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
4207
4618
|
toCenter.copy(corner).subtract(position);
|
|
4208
|
-
mag =
|
|
4619
|
+
mag = direction2.dot(toCenter);
|
|
4209
4620
|
minDist = Math.min(mag, minDist);
|
|
4210
4621
|
maxDist = Math.max(mag, maxDist);
|
|
4211
4622
|
center.copy(corner).subtract(u).add(v).add(w);
|
|
4212
4623
|
toCenter.copy(corner).subtract(position);
|
|
4213
|
-
mag =
|
|
4624
|
+
mag = direction2.dot(toCenter);
|
|
4214
4625
|
minDist = Math.min(mag, minDist);
|
|
4215
4626
|
maxDist = Math.max(mag, maxDist);
|
|
4216
4627
|
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
4217
4628
|
toCenter.copy(corner).subtract(position);
|
|
4218
|
-
mag =
|
|
4629
|
+
mag = direction2.dot(toCenter);
|
|
4219
4630
|
minDist = Math.min(mag, minDist);
|
|
4220
4631
|
maxDist = Math.max(mag, maxDist);
|
|
4221
4632
|
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
4222
4633
|
toCenter.copy(corner).subtract(position);
|
|
4223
|
-
mag =
|
|
4634
|
+
mag = direction2.dot(toCenter);
|
|
4224
4635
|
minDist = Math.min(mag, minDist);
|
|
4225
4636
|
maxDist = Math.max(mag, maxDist);
|
|
4226
4637
|
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
4227
4638
|
toCenter.copy(corner).subtract(position);
|
|
4228
|
-
mag =
|
|
4639
|
+
mag = direction2.dot(toCenter);
|
|
4229
4640
|
minDist = Math.min(mag, minDist);
|
|
4230
4641
|
maxDist = Math.max(mag, maxDist);
|
|
4231
4642
|
result[0] = minDist;
|
|
@@ -4254,6 +4665,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4254
4665
|
};
|
|
4255
4666
|
|
|
4256
4667
|
// dist/culling/lib/culling-volume.js
|
|
4668
|
+
var import_core13 = require("@math.gl/core");
|
|
4669
|
+
|
|
4670
|
+
// dist/culling/frustum-planes.js
|
|
4257
4671
|
var import_core12 = require("@math.gl/core");
|
|
4258
4672
|
|
|
4259
4673
|
// dist/culling/lib/plane.js
|
|
@@ -4274,10 +4688,10 @@ var Plane = class _Plane {
|
|
|
4274
4688
|
return this;
|
|
4275
4689
|
}
|
|
4276
4690
|
/** Creates a plane from a normal and a point on the plane. */
|
|
4277
|
-
fromPointNormal(
|
|
4278
|
-
|
|
4691
|
+
fromPointNormal(point2, normal) {
|
|
4692
|
+
point2 = scratchPosition.from(point2);
|
|
4279
4693
|
this.normal.from(normal).normalize();
|
|
4280
|
-
const distance = -this.normal.dot(
|
|
4694
|
+
const distance = -this.normal.dot(point2);
|
|
4281
4695
|
this.distance = distance;
|
|
4282
4696
|
return this;
|
|
4283
4697
|
}
|
|
@@ -4299,17 +4713,17 @@ var Plane = class _Plane {
|
|
|
4299
4713
|
/** Computes the signed shortest distance of a point to a plane.
|
|
4300
4714
|
* The sign of the distance determines which side of the plane the point is on.
|
|
4301
4715
|
*/
|
|
4302
|
-
getPointDistance(
|
|
4303
|
-
return this.normal.dot(
|
|
4716
|
+
getPointDistance(point2) {
|
|
4717
|
+
return this.normal.dot(point2) + this.distance;
|
|
4304
4718
|
}
|
|
4305
4719
|
/** Transforms the plane by the given transformation matrix. */
|
|
4306
4720
|
transform(matrix4) {
|
|
4307
4721
|
const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
4308
|
-
const
|
|
4309
|
-
return this.fromPointNormal(
|
|
4722
|
+
const point2 = this.normal.scale(-this.distance).transform(matrix4);
|
|
4723
|
+
return this.fromPointNormal(point2, normal);
|
|
4310
4724
|
}
|
|
4311
|
-
projectPointOntoPlane(
|
|
4312
|
-
const scratchPoint = scratchPosition.from(
|
|
4725
|
+
projectPointOntoPlane(point2, result = [0, 0, 0]) {
|
|
4726
|
+
const scratchPoint = scratchPosition.from(point2);
|
|
4313
4727
|
const pointDistance = this.getPointDistance(scratchPoint);
|
|
4314
4728
|
const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
|
|
4315
4729
|
return scratchPoint.subtract(scaledNormal).to(result);
|
|
@@ -4323,9 +4737,9 @@ var Plane = class _Plane {
|
|
|
4323
4737
|
*/
|
|
4324
4738
|
intersectWithRay(ray, result = new import_core11.Vector3()) {
|
|
4325
4739
|
const origin = ray.origin;
|
|
4326
|
-
const
|
|
4740
|
+
const direction2 = ray.direction;
|
|
4327
4741
|
const normal = this.normal;
|
|
4328
|
-
const denominator = normal.dot(
|
|
4742
|
+
const denominator = normal.dot(direction2);
|
|
4329
4743
|
if (Math.abs(denominator) < import_core11._MathUtils.EPSILON15) {
|
|
4330
4744
|
return void 0;
|
|
4331
4745
|
}
|
|
@@ -4333,14 +4747,45 @@ var Plane = class _Plane {
|
|
|
4333
4747
|
if (t < 0) {
|
|
4334
4748
|
return void 0;
|
|
4335
4749
|
}
|
|
4336
|
-
return result.copy(
|
|
4750
|
+
return result.copy(direction2).multiplyByScalar(t).add(origin);
|
|
4337
4751
|
}
|
|
4338
4752
|
};
|
|
4339
4753
|
|
|
4754
|
+
// dist/culling/frustum-planes.js
|
|
4755
|
+
function extractFrustumPlanes(matrix, options = {}) {
|
|
4756
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
|
|
4757
|
+
throw new RangeError("Expected a finite view-projection matrix");
|
|
4758
|
+
const [near, far] = (0, import_core12.getProjectionDepthRange)(options);
|
|
4759
|
+
const low = Math.min(near, far), high = Math.max(near, far);
|
|
4760
|
+
const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
|
|
4761
|
+
const x = row(0), y = row(1), z = row(2), w = row(3);
|
|
4762
|
+
const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
|
|
4763
|
+
const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
|
|
4764
|
+
const coefficients = [
|
|
4765
|
+
combine(w, x, 1),
|
|
4766
|
+
combine(w, x, -1),
|
|
4767
|
+
combine(w, y, 1),
|
|
4768
|
+
combine(w, y, -1),
|
|
4769
|
+
...options.reversedDepth ? [hi, lo] : [lo, hi]
|
|
4770
|
+
];
|
|
4771
|
+
const planes = [];
|
|
4772
|
+
for (const [a, b, c, d] of coefficients) {
|
|
4773
|
+
const length = Math.hypot(a, b, c);
|
|
4774
|
+
if (length === 0) {
|
|
4775
|
+
if (d < 0)
|
|
4776
|
+
throw new RangeError("Empty clipping volume");
|
|
4777
|
+
} else
|
|
4778
|
+
planes.push(new Plane([a / length, b / length, c / length], d / length));
|
|
4779
|
+
}
|
|
4780
|
+
if (planes.length < 4)
|
|
4781
|
+
throw new RangeError("Degenerate clipping volume");
|
|
4782
|
+
return planes;
|
|
4783
|
+
}
|
|
4784
|
+
|
|
4340
4785
|
// dist/culling/lib/culling-volume.js
|
|
4341
|
-
var faces = [new
|
|
4342
|
-
var scratchPlaneCenter = new
|
|
4343
|
-
var scratchPlaneNormal = new
|
|
4786
|
+
var faces = [new import_core13.Vector3([1, 0, 0]), new import_core13.Vector3([0, 1, 0]), new import_core13.Vector3([0, 0, 1])];
|
|
4787
|
+
var scratchPlaneCenter = new import_core13.Vector3();
|
|
4788
|
+
var scratchPlaneNormal = new import_core13.Vector3();
|
|
4344
4789
|
var CullingVolume = class _CullingVolume {
|
|
4345
4790
|
/**
|
|
4346
4791
|
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
@@ -4356,7 +4801,7 @@ var CullingVolume = class _CullingVolume {
|
|
|
4356
4801
|
fromBoundingSphere(boundingSphere) {
|
|
4357
4802
|
this.planes.length = 2 * faces.length;
|
|
4358
4803
|
const center = boundingSphere.center;
|
|
4359
|
-
const
|
|
4804
|
+
const radius2 = boundingSphere.radius;
|
|
4360
4805
|
let planeIndex = 0;
|
|
4361
4806
|
for (const faceNormal of faces) {
|
|
4362
4807
|
let plane0 = this.planes[planeIndex];
|
|
@@ -4367,15 +4812,21 @@ var CullingVolume = class _CullingVolume {
|
|
|
4367
4812
|
if (!plane1) {
|
|
4368
4813
|
plane1 = this.planes[planeIndex + 1] = new Plane();
|
|
4369
4814
|
}
|
|
4370
|
-
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-
|
|
4815
|
+
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
|
|
4371
4816
|
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
4372
|
-
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(
|
|
4817
|
+
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
|
|
4373
4818
|
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
4374
4819
|
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
4375
4820
|
planeIndex += 2;
|
|
4376
4821
|
}
|
|
4377
4822
|
return this;
|
|
4378
4823
|
}
|
|
4824
|
+
/** Replace planes from a view-projection matrix; validates before mutating. */
|
|
4825
|
+
fromViewProjection(matrix, options = {}) {
|
|
4826
|
+
const planes = extractFrustumPlanes(matrix, options);
|
|
4827
|
+
this.planes.splice(0, this.planes.length, ...planes);
|
|
4828
|
+
return this;
|
|
4829
|
+
}
|
|
4379
4830
|
/** Determines whether a bounding volume intersects the culling volume. */
|
|
4380
4831
|
computeVisibility(boundingVolume) {
|
|
4381
4832
|
let intersect2 = "inside";
|
|
@@ -4401,7 +4852,7 @@ var CullingVolume = class _CullingVolume {
|
|
|
4401
4852
|
* and that plane check can be skipped.
|
|
4402
4853
|
*/
|
|
4403
4854
|
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
4404
|
-
(0,
|
|
4855
|
+
(0, import_core13.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
|
|
4405
4856
|
if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
|
|
4406
4857
|
return parentPlaneMask;
|
|
4407
4858
|
}
|
|
@@ -4428,70 +4879,523 @@ CullingVolume.MASK_INSIDE = 0;
|
|
|
4428
4879
|
CullingVolume.MASK_INDETERMINATE = 2147483647;
|
|
4429
4880
|
|
|
4430
4881
|
// dist/culling/lib/ray.js
|
|
4431
|
-
var import_core13 = require("@math.gl/core");
|
|
4432
|
-
var Ray = class {
|
|
4433
|
-
/**
|
|
4434
|
-
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
4435
|
-
*
|
|
4436
|
-
* @param [origin=Vector3] The origin of the ray.
|
|
4437
|
-
* @param [direction=Vector3] The direction of the ray.
|
|
4438
|
-
*/
|
|
4439
|
-
constructor(origin, direction) {
|
|
4440
|
-
if (origin)
|
|
4441
|
-
origin = origin.clone();
|
|
4442
|
-
else
|
|
4443
|
-
origin = new import_core13.Vector3();
|
|
4444
|
-
if (direction)
|
|
4445
|
-
direction = direction.clone().normalize();
|
|
4446
|
-
else
|
|
4447
|
-
direction = new import_core13.Vector3();
|
|
4448
|
-
this.origin = origin;
|
|
4449
|
-
this.direction = direction;
|
|
4450
|
-
}
|
|
4451
|
-
};
|
|
4452
|
-
|
|
4453
|
-
// dist/culling/lib/shapes/implicit-shape.js
|
|
4454
4882
|
var import_core14 = require("@math.gl/core");
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4883
|
+
|
|
4884
|
+
// dist/culling/queries.js
|
|
4885
|
+
function validateQueryPoint(point2, dimension2) {
|
|
4886
|
+
if (point2.length !== dimension2)
|
|
4887
|
+
throw new RangeError("Query dimension must match the index");
|
|
4888
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4889
|
+
if (!Number.isFinite(point2[i]))
|
|
4890
|
+
throw new RangeError("Coordinates must be finite");
|
|
4462
4891
|
}
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4892
|
+
}
|
|
4893
|
+
function validateQueryDistance(distance) {
|
|
4894
|
+
if (Number.isNaN(distance) || distance < 0)
|
|
4895
|
+
throw new RangeError("Distance must be nonnegative");
|
|
4896
|
+
}
|
|
4897
|
+
function normalizeQueryDirection(direction2, dimension2) {
|
|
4898
|
+
validateQueryPoint(direction2, dimension2);
|
|
4899
|
+
const scale = Math.max(...Array.from(direction2, Math.abs));
|
|
4900
|
+
if (scale === 0)
|
|
4901
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4902
|
+
const scaled = Array.from(direction2, (x) => x / scale);
|
|
4903
|
+
const length = Math.hypot(...scaled);
|
|
4904
|
+
return scaled.map((x) => x / length);
|
|
4905
|
+
}
|
|
4906
|
+
function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
|
|
4907
|
+
const dimension2 = origin.length;
|
|
4908
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
4909
|
+
throw new RangeError("Bounds must be 2D or 3D");
|
|
4910
|
+
validateQueryPoint(origin, dimension2);
|
|
4911
|
+
validateQueryPoint(direction2, dimension2);
|
|
4912
|
+
validateQueryPoint(minimum, dimension2);
|
|
4913
|
+
validateQueryPoint(maximum, dimension2);
|
|
4914
|
+
validateQueryDistance(maxT);
|
|
4915
|
+
let near = 0, far = maxT, nonzero = false;
|
|
4916
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4917
|
+
if (minimum[i] > maximum[i])
|
|
4918
|
+
throw new RangeError("Bounds must be ordered");
|
|
4919
|
+
nonzero || (nonzero = direction2[i] !== 0);
|
|
4470
4920
|
}
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4921
|
+
if (!nonzero)
|
|
4922
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4923
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4924
|
+
if (direction2[i] === 0) {
|
|
4925
|
+
if (origin[i] < minimum[i] || origin[i] > maximum[i])
|
|
4926
|
+
return null;
|
|
4927
|
+
continue;
|
|
4928
|
+
}
|
|
4929
|
+
let a = (minimum[i] - origin[i]) / direction2[i];
|
|
4930
|
+
let b = (maximum[i] - origin[i]) / direction2[i];
|
|
4931
|
+
if (a > b)
|
|
4932
|
+
[a, b] = [b, a];
|
|
4933
|
+
near = Math.max(near, a);
|
|
4934
|
+
far = Math.min(far, b);
|
|
4935
|
+
if (near > far)
|
|
4936
|
+
return null;
|
|
4478
4937
|
}
|
|
4479
|
-
|
|
4480
|
-
|
|
4938
|
+
return Number.isFinite(near) ? near : null;
|
|
4939
|
+
}
|
|
4940
|
+
function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
|
|
4941
|
+
for (const point2 of [origin, direction2, a, b, c])
|
|
4942
|
+
validateQueryPoint(point2, 3);
|
|
4943
|
+
if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
|
|
4944
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4481
4945
|
}
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4946
|
+
const maxT = options.maxT ?? Infinity;
|
|
4947
|
+
validateQueryDistance(maxT);
|
|
4948
|
+
const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
4949
|
+
const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
4950
|
+
const p = cross4(direction2, e2);
|
|
4951
|
+
const determinant = dot2(e1, p);
|
|
4952
|
+
if (determinant === 0 || options.backfaceCulling && determinant < 0)
|
|
4953
|
+
return null;
|
|
4954
|
+
const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
|
|
4955
|
+
const u = dot2(offset, p) / determinant;
|
|
4956
|
+
if (u < 0 || u > 1)
|
|
4957
|
+
return null;
|
|
4958
|
+
const q = cross4(offset, e1);
|
|
4959
|
+
const v = dot2(direction2, q) / determinant;
|
|
4960
|
+
if (v < 0 || u + v > 1)
|
|
4961
|
+
return null;
|
|
4962
|
+
const t = dot2(e2, q) / determinant;
|
|
4963
|
+
if (!Number.isFinite(t) || t < 0 || t > maxT)
|
|
4964
|
+
return null;
|
|
4965
|
+
return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
|
|
4966
|
+
}
|
|
4967
|
+
function getClosestPointOnTriangle(point2, a, b, c) {
|
|
4968
|
+
for (const value of [point2, a, b, c])
|
|
4969
|
+
validateQueryPoint(value, 3);
|
|
4970
|
+
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
4971
|
+
const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
4972
|
+
const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
|
|
4973
|
+
const aa = dot2(ab, ab), bb = dot2(ac, ac), cc = dot2(ab, ac);
|
|
4974
|
+
const denominator = aa * bb - cc * cc;
|
|
4975
|
+
if (denominator > 0 && Number.isFinite(denominator)) {
|
|
4976
|
+
const u = (bb * dot2(ap, ab) - cc * dot2(ap, ac)) / denominator;
|
|
4977
|
+
const v = (aa * dot2(ap, ac) - cc * dot2(ap, ab)) / denominator;
|
|
4978
|
+
if (u >= 0 && v >= 0 && u + v <= 1) {
|
|
4979
|
+
return [
|
|
4980
|
+
a[0] + u * ab[0] + v * ac[0],
|
|
4981
|
+
a[1] + u * ab[1] + v * ac[1],
|
|
4982
|
+
a[2] + u * ab[2] + v * ac[2]
|
|
4983
|
+
];
|
|
4984
|
+
}
|
|
4485
4985
|
}
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4986
|
+
let best = [a[0], a[1], a[2]];
|
|
4987
|
+
let distance = Infinity;
|
|
4988
|
+
for (const [start, end] of [
|
|
4989
|
+
[a, b],
|
|
4990
|
+
[b, c],
|
|
4991
|
+
[c, a]
|
|
4992
|
+
]) {
|
|
4993
|
+
const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
|
|
4994
|
+
const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
|
|
4995
|
+
const squared = dot2(edge, edge);
|
|
4996
|
+
const t = squared > 0 ? Math.max(0, Math.min(1, dot2(offset, edge) / squared)) : 0;
|
|
4997
|
+
const candidate = [
|
|
4998
|
+
start[0] + t * edge[0],
|
|
4999
|
+
start[1] + t * edge[1],
|
|
5000
|
+
start[2] + t * edge[2]
|
|
5001
|
+
];
|
|
5002
|
+
const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
|
|
5003
|
+
if (d < distance) {
|
|
5004
|
+
distance = d;
|
|
5005
|
+
best = candidate;
|
|
5006
|
+
}
|
|
4492
5007
|
}
|
|
4493
|
-
|
|
4494
|
-
|
|
5008
|
+
return best;
|
|
5009
|
+
}
|
|
5010
|
+
function getClosestPointsOnSegments(a0, a1, b0, b1) {
|
|
5011
|
+
const frame = queryFrame([a0, a1, b0, b1]);
|
|
5012
|
+
const pair2 = closestSegments(...frame.points);
|
|
5013
|
+
const pointA = interpolatePoint(a0, a1, pair2.fractionA);
|
|
5014
|
+
const pointB = interpolatePoint(b0, b1, pair2.fractionB);
|
|
5015
|
+
return {
|
|
5016
|
+
distance: finiteDistance(pointA, pointB),
|
|
5017
|
+
pointA,
|
|
5018
|
+
pointB,
|
|
5019
|
+
fractionA: pair2.fractionA,
|
|
5020
|
+
fractionB: pair2.fractionB
|
|
5021
|
+
};
|
|
5022
|
+
}
|
|
5023
|
+
function getClosestPointsSegmentTriangle(start, end, a, b, c) {
|
|
5024
|
+
const frame = queryFrame([start, end, a, b, c]);
|
|
5025
|
+
const [s, e, va, vb, vc] = frame.points;
|
|
5026
|
+
const direction2 = subtract(e, s);
|
|
5027
|
+
if (direction2.some((value) => value !== 0)) {
|
|
5028
|
+
const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
|
|
5029
|
+
if (hit) {
|
|
5030
|
+
const point2 = interpolatePoint(start, end, hit.t);
|
|
5031
|
+
return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
|
|
5032
|
+
}
|
|
5033
|
+
}
|
|
5034
|
+
let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
|
|
5035
|
+
const consider = (point2, trianglePoint2, segmentFraction) => {
|
|
5036
|
+
const distance = Math.hypot(...subtract(point2, trianglePoint2));
|
|
5037
|
+
if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
|
|
5038
|
+
best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
|
|
5039
|
+
};
|
|
5040
|
+
consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
|
|
5041
|
+
consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
|
|
5042
|
+
for (const [v0, v1] of [
|
|
5043
|
+
[va, vb],
|
|
5044
|
+
[vb, vc],
|
|
5045
|
+
[vc, va]
|
|
5046
|
+
]) {
|
|
5047
|
+
const pair2 = closestSegments(s, e, v0, v1);
|
|
5048
|
+
consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
|
|
5049
|
+
}
|
|
5050
|
+
const trianglePoint = best.trianglePoint.map((value, axis) => Math.max(Math.min(a[axis], b[axis], c[axis]), Math.min(Math.max(a[axis], b[axis], c[axis]), start[axis] + value * frame.scale)));
|
|
5051
|
+
if (!trianglePoint.every(Number.isFinite))
|
|
5052
|
+
throw new RangeError("Closest-point result overflow");
|
|
5053
|
+
const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
|
|
5054
|
+
return {
|
|
5055
|
+
distance: finiteDistance(segmentPoint, trianglePoint),
|
|
5056
|
+
segmentPoint,
|
|
5057
|
+
trianglePoint,
|
|
5058
|
+
segmentFraction: best.segmentFraction
|
|
5059
|
+
};
|
|
5060
|
+
}
|
|
5061
|
+
function queryFrame(input) {
|
|
5062
|
+
input.forEach((point2) => validateQueryPoint(point2, 3));
|
|
5063
|
+
const offsets = input.map((point2) => subtract(point2, input[0]));
|
|
5064
|
+
let scale = 0;
|
|
5065
|
+
for (const offset of offsets)
|
|
5066
|
+
for (const value of offset) {
|
|
5067
|
+
if (!Number.isFinite(value))
|
|
5068
|
+
throw new RangeError("Closest-point coordinate span overflow");
|
|
5069
|
+
scale = Math.max(scale, Math.abs(value));
|
|
5070
|
+
}
|
|
5071
|
+
scale || (scale = 1);
|
|
5072
|
+
return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
|
|
5073
|
+
}
|
|
5074
|
+
function closestSegments(a0, a1, b0, b1) {
|
|
5075
|
+
const da = subtract(a1, a0), db = subtract(b1, b0);
|
|
5076
|
+
const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
|
|
5077
|
+
const ua = da.map((value) => lengthA ? value / lengthA : 0);
|
|
5078
|
+
const ub = db.map((value) => lengthB ? value / lengthB : 0);
|
|
5079
|
+
let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
|
|
5080
|
+
const consider = (fractionA, fractionB) => {
|
|
5081
|
+
const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
|
|
5082
|
+
if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
|
|
5083
|
+
best = { distance, fractionA, fractionB };
|
|
5084
|
+
};
|
|
5085
|
+
for (const t of [0, 1]) {
|
|
5086
|
+
consider(t, lengthB ? clampUnit(dot2(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
|
|
5087
|
+
consider(lengthA ? clampUnit(dot2(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
|
|
5088
|
+
}
|
|
5089
|
+
const normal = cross4(ua, ub);
|
|
5090
|
+
const sine = Math.hypot(...normal);
|
|
5091
|
+
if (sine > 0) {
|
|
5092
|
+
const unit2 = normal.map((value) => value / sine);
|
|
5093
|
+
const offset = subtract(b0, a0);
|
|
5094
|
+
const fractionA = dot2(cross4(offset, ub), unit2) / sine / lengthA;
|
|
5095
|
+
const fractionB = dot2(cross4(offset, ua), unit2) / sine / lengthB;
|
|
5096
|
+
if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
|
|
5097
|
+
consider(fractionA, fractionB);
|
|
5098
|
+
}
|
|
5099
|
+
return best;
|
|
5100
|
+
}
|
|
5101
|
+
function subtract(a, b) {
|
|
5102
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
5103
|
+
}
|
|
5104
|
+
function interpolatePoint(a, b, t) {
|
|
5105
|
+
return [0, 1, 2].map((axis) => Math.max(Math.min(a[axis], b[axis]), Math.min(Math.max(a[axis], b[axis]), (1 - t) * a[axis] + t * b[axis])));
|
|
5106
|
+
}
|
|
5107
|
+
function clampUnit(value) {
|
|
5108
|
+
return Math.max(0, Math.min(1, value));
|
|
5109
|
+
}
|
|
5110
|
+
function finiteDistance(a, b) {
|
|
5111
|
+
const distance = Math.hypot(...subtract(a, b));
|
|
5112
|
+
if (!Number.isFinite(distance))
|
|
5113
|
+
throw new RangeError("Closest-point distance overflow");
|
|
5114
|
+
return distance;
|
|
5115
|
+
}
|
|
5116
|
+
function dot2(a, b) {
|
|
5117
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
5118
|
+
}
|
|
5119
|
+
function cross4(a, b) {
|
|
5120
|
+
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
5121
|
+
}
|
|
5122
|
+
|
|
5123
|
+
// dist/culling/geometric-queries.js
|
|
5124
|
+
var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
5125
|
+
var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
5126
|
+
var cross5 = (a, b) => [
|
|
5127
|
+
a[1] * b[2] - a[2] * b[1],
|
|
5128
|
+
a[2] * b[0] - a[0] * b[2],
|
|
5129
|
+
a[0] * b[1] - a[1] * b[0]
|
|
5130
|
+
];
|
|
5131
|
+
var check = (...points) => {
|
|
5132
|
+
for (const p of points)
|
|
5133
|
+
validateQueryPoint(p, 3);
|
|
5134
|
+
};
|
|
5135
|
+
function output(out, values) {
|
|
5136
|
+
if (out.length < values.length)
|
|
5137
|
+
throw new RangeError("Result buffer is too short");
|
|
5138
|
+
const copy2 = Array.from(values);
|
|
5139
|
+
for (let i = 0; i < copy2.length; i++)
|
|
5140
|
+
out[i] = copy2[i];
|
|
5141
|
+
return out;
|
|
5142
|
+
}
|
|
5143
|
+
function direction(d) {
|
|
5144
|
+
check(d);
|
|
5145
|
+
if (Math.hypot(d[0], d[1], d[2]) === 0)
|
|
5146
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
5147
|
+
}
|
|
5148
|
+
function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
|
|
5149
|
+
check(origin);
|
|
5150
|
+
direction(dir);
|
|
5151
|
+
if (!Number.isFinite(t) || t < 0)
|
|
5152
|
+
throw new RangeError("Ray parameter must be finite and nonnegative");
|
|
5153
|
+
return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
|
|
5154
|
+
}
|
|
5155
|
+
function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
|
|
5156
|
+
check(point2, origin);
|
|
5157
|
+
direction(dir);
|
|
5158
|
+
const unit2 = normalizeQueryDirection(dir, 3);
|
|
5159
|
+
const distance = Math.max(0, dot3(sub2(point2, origin), unit2));
|
|
5160
|
+
return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit2[i]));
|
|
5161
|
+
}
|
|
5162
|
+
function distanceToRay(point2, origin, dir) {
|
|
5163
|
+
const p = getClosestPointOnRay(point2, origin, dir);
|
|
5164
|
+
return Math.hypot(...sub2(point2, p));
|
|
5165
|
+
}
|
|
5166
|
+
function getClosestPointsRaySegment(origin, dir, a, b) {
|
|
5167
|
+
check(origin, a, b);
|
|
5168
|
+
direction(dir);
|
|
5169
|
+
const unit2 = normalizeQueryDirection(dir, 3);
|
|
5170
|
+
const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
|
|
5171
|
+
const edge = sub2(b, a), offset = sub2(origin, a);
|
|
5172
|
+
const segmentLength = Math.hypot(...edge);
|
|
5173
|
+
const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
|
|
5174
|
+
const bb = dot3(unit2, segmentUnit), dd = dot3(unit2, offset), ee = dot3(segmentUnit, offset);
|
|
5175
|
+
const candidates = [
|
|
5176
|
+
[0, Math.max(0, Math.min(segmentLength, ee))],
|
|
5177
|
+
[Math.max(0, -dd), 0],
|
|
5178
|
+
[Math.max(0, bb * segmentLength - dd), segmentLength]
|
|
5179
|
+
];
|
|
5180
|
+
const normal = cross5(unit2, segmentUnit);
|
|
5181
|
+
const sine = Math.hypot(...normal);
|
|
5182
|
+
if (segmentLength > 0 && sine > 0) {
|
|
5183
|
+
const normalUnit = normal.map((value) => value / sine);
|
|
5184
|
+
const separation = sub2(a, origin);
|
|
5185
|
+
const t = dot3(cross5(separation, segmentUnit), normalUnit) / sine;
|
|
5186
|
+
const u = dot3(cross5(separation, unit2), normalUnit) / sine;
|
|
5187
|
+
if (t >= 0 && u >= 0 && u <= segmentLength)
|
|
5188
|
+
candidates.push([t, u]);
|
|
5189
|
+
}
|
|
5190
|
+
let best;
|
|
5191
|
+
for (const [t, u] of candidates) {
|
|
5192
|
+
const rayPoint = [
|
|
5193
|
+
origin[0] + t * unit2[0],
|
|
5194
|
+
origin[1] + t * unit2[1],
|
|
5195
|
+
origin[2] + t * unit2[2]
|
|
5196
|
+
];
|
|
5197
|
+
const segmentPoint = [
|
|
5198
|
+
a[0] + u * segmentUnit[0],
|
|
5199
|
+
a[1] + u * segmentUnit[1],
|
|
5200
|
+
a[2] + u * segmentUnit[2]
|
|
5201
|
+
];
|
|
5202
|
+
const distance = Math.hypot(...sub2(rayPoint, segmentPoint));
|
|
5203
|
+
if (!best || distance < best.distance)
|
|
5204
|
+
best = {
|
|
5205
|
+
rayPoint,
|
|
5206
|
+
segmentPoint,
|
|
5207
|
+
rayParameter: t / directionLength,
|
|
5208
|
+
segmentFraction: segmentLength ? u / segmentLength : 0,
|
|
5209
|
+
distance
|
|
5210
|
+
};
|
|
5211
|
+
}
|
|
5212
|
+
return best;
|
|
5213
|
+
}
|
|
5214
|
+
function transformRay(origin, dir, matrix) {
|
|
5215
|
+
check(origin);
|
|
5216
|
+
direction(dir);
|
|
5217
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
|
|
5218
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
5219
|
+
const apply = (p, w) => [0, 1, 2].map((i) => matrix[i] * p[0] + matrix[i + 4] * p[1] + matrix[i + 8] * p[2] + w * matrix[i + 12]);
|
|
5220
|
+
const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
|
|
5221
|
+
check(transformed.origin);
|
|
5222
|
+
direction(transformed.direction);
|
|
5223
|
+
return transformed;
|
|
5224
|
+
}
|
|
5225
|
+
function triangle(a, b, c) {
|
|
5226
|
+
check(a, b, c);
|
|
5227
|
+
const ab = sub2(b, a), ac = sub2(c, a);
|
|
5228
|
+
const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
|
|
5229
|
+
const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
|
|
5230
|
+
return { u, v, scale, normal: cross5(u, v) };
|
|
5231
|
+
}
|
|
5232
|
+
function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
|
|
5233
|
+
check(point2);
|
|
5234
|
+
const { u, v, scale, normal } = triangle(a, b, c), denominator = dot3(normal, normal);
|
|
5235
|
+
if (denominator === 0)
|
|
5236
|
+
return null;
|
|
5237
|
+
const p = sub2(point2, a).map((x) => x / scale);
|
|
5238
|
+
const second = dot3(cross5(p, v), normal) / denominator;
|
|
5239
|
+
const third = dot3(cross5(u, p), normal) / denominator;
|
|
5240
|
+
return output(out, [1 - second - third, second, third]);
|
|
5241
|
+
}
|
|
5242
|
+
function getTriangleArea(a, b, c) {
|
|
5243
|
+
const { normal, scale } = triangle(a, b, c);
|
|
5244
|
+
return Math.hypot(...normal) * scale * scale / 2;
|
|
5245
|
+
}
|
|
5246
|
+
function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
|
|
5247
|
+
const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
|
|
5248
|
+
return output(out, normal.map((x) => length ? x / length : 0));
|
|
5249
|
+
}
|
|
5250
|
+
function isTriangleFrontFacing(a, b, c, dir) {
|
|
5251
|
+
direction(dir);
|
|
5252
|
+
return dot3(triangle(a, b, c).normal, dir) < 0;
|
|
5253
|
+
}
|
|
5254
|
+
function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
|
|
5255
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
5256
|
+
throw new RangeError("Invalid tolerance");
|
|
5257
|
+
const weights = getTriangleBarycentric(point2, a, b, c);
|
|
5258
|
+
if (!weights)
|
|
5259
|
+
return false;
|
|
5260
|
+
const { normal, scale } = triangle(a, b, c);
|
|
5261
|
+
const distance = Math.abs(dot3(sub2(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
|
|
5262
|
+
return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
|
|
5263
|
+
}
|
|
5264
|
+
function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
|
|
5265
|
+
check(weights);
|
|
5266
|
+
if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
|
|
5267
|
+
throw new RangeError("Expected matching finite attributes");
|
|
5268
|
+
return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
|
|
5269
|
+
}
|
|
5270
|
+
function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
|
|
5271
|
+
check(start, end);
|
|
5272
|
+
direction(normal);
|
|
5273
|
+
if (!Number.isFinite(constant))
|
|
5274
|
+
throw new RangeError("Plane constant must be finite");
|
|
5275
|
+
const a = dot3(normal, start) + constant, b = dot3(normal, end) + constant;
|
|
5276
|
+
if (a === 0)
|
|
5277
|
+
return output(out, start);
|
|
5278
|
+
if (b === 0)
|
|
5279
|
+
return output(out, end);
|
|
5280
|
+
if (a > 0 === b > 0)
|
|
5281
|
+
return null;
|
|
5282
|
+
const t = a / (a - b);
|
|
5283
|
+
return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
|
|
5284
|
+
}
|
|
5285
|
+
function triangleIntersectsBounds(a, b, c, minimum, maximum) {
|
|
5286
|
+
check(a, b, c, minimum, maximum);
|
|
5287
|
+
if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
|
|
5288
|
+
return false;
|
|
5289
|
+
const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
|
|
5290
|
+
const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
|
|
5291
|
+
const vertices = [a, b, c].map((p) => sub2(p, center));
|
|
5292
|
+
const edges = [sub2(b, a), sub2(c, b), sub2(a, c)];
|
|
5293
|
+
const basis = [
|
|
5294
|
+
[1, 0, 0],
|
|
5295
|
+
[0, 1, 0],
|
|
5296
|
+
[0, 0, 1]
|
|
5297
|
+
];
|
|
5298
|
+
const axes = [
|
|
5299
|
+
...basis,
|
|
5300
|
+
cross5(edges[0], edges[1]),
|
|
5301
|
+
...edges.flatMap((e) => basis.map((axis) => cross5(e, axis)))
|
|
5302
|
+
];
|
|
5303
|
+
for (const axis of axes) {
|
|
5304
|
+
const length = Math.hypot(...axis);
|
|
5305
|
+
if (!length)
|
|
5306
|
+
continue;
|
|
5307
|
+
const unit2 = axis.map((x) => x / length);
|
|
5308
|
+
const projections = vertices.map((v) => dot3(v, unit2));
|
|
5309
|
+
const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit2[i]), 0);
|
|
5310
|
+
if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
|
|
5311
|
+
return false;
|
|
5312
|
+
}
|
|
5313
|
+
return true;
|
|
5314
|
+
}
|
|
5315
|
+
|
|
5316
|
+
// dist/culling/lib/ray.js
|
|
5317
|
+
var Ray = class {
|
|
5318
|
+
/**
|
|
5319
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
5320
|
+
*
|
|
5321
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
5322
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
5323
|
+
*/
|
|
5324
|
+
constructor(origin, direction2) {
|
|
5325
|
+
if (origin)
|
|
5326
|
+
origin = origin.clone();
|
|
5327
|
+
else
|
|
5328
|
+
origin = new import_core14.Vector3();
|
|
5329
|
+
if (direction2)
|
|
5330
|
+
direction2 = direction2.clone().normalize();
|
|
5331
|
+
else
|
|
5332
|
+
direction2 = new import_core14.Vector3();
|
|
5333
|
+
this.origin = origin;
|
|
5334
|
+
this.direction = direction2;
|
|
5335
|
+
}
|
|
5336
|
+
at(t, result = new import_core14.Vector3()) {
|
|
5337
|
+
getRayPoint(this.origin, this.direction, t, result);
|
|
5338
|
+
return result;
|
|
5339
|
+
}
|
|
5340
|
+
closestPointTo(point2, result = new import_core14.Vector3()) {
|
|
5341
|
+
getClosestPointOnRay(point2, this.origin, this.direction, result);
|
|
5342
|
+
return result;
|
|
5343
|
+
}
|
|
5344
|
+
distanceTo(point2) {
|
|
5345
|
+
return distanceToRay(point2, this.origin, this.direction);
|
|
5346
|
+
}
|
|
5347
|
+
/** Transform and renormalize: subsequent parameters are distances in the new space. */
|
|
5348
|
+
transform(matrix) {
|
|
5349
|
+
const ray = transformRay(this.origin, this.direction, matrix);
|
|
5350
|
+
const normalized2 = normalizeQueryDirection(ray.direction, 3);
|
|
5351
|
+
this.origin.copy(ray.origin);
|
|
5352
|
+
this.direction.copy(normalized2);
|
|
5353
|
+
return this;
|
|
5354
|
+
}
|
|
5355
|
+
};
|
|
5356
|
+
|
|
5357
|
+
// dist/culling/lib/shapes/implicit-shape.js
|
|
5358
|
+
var import_core15 = require("@math.gl/core");
|
|
5359
|
+
var ImplicitShapeBase = class {
|
|
5360
|
+
constructor(matrix) {
|
|
5361
|
+
this.matrix = new import_core15.Matrix4();
|
|
5362
|
+
if (matrix)
|
|
5363
|
+
this.matrix.copy(matrix);
|
|
5364
|
+
validateAffineMatrix(this.matrix);
|
|
5365
|
+
this.inverseMatrix = this.matrix.clone().invert();
|
|
5366
|
+
}
|
|
5367
|
+
equals(shape) {
|
|
5368
|
+
if (this.type !== shape.type)
|
|
5369
|
+
return false;
|
|
5370
|
+
for (let i = 0; i < 16; i++)
|
|
5371
|
+
if (this.matrix[i] !== shape.matrix[i])
|
|
5372
|
+
return false;
|
|
5373
|
+
return true;
|
|
5374
|
+
}
|
|
5375
|
+
transform(transform) {
|
|
5376
|
+
const next = new import_core15.Matrix4().copy(transform);
|
|
5377
|
+
validateAffineMatrix(next);
|
|
5378
|
+
this.matrix.multiplyLeft(next);
|
|
5379
|
+
validateAffineMatrix(this.matrix);
|
|
5380
|
+
this.inverseMatrix.copy(this.matrix).invert();
|
|
5381
|
+
return this;
|
|
5382
|
+
}
|
|
5383
|
+
containsPoint(point2) {
|
|
5384
|
+
return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
|
|
5385
|
+
}
|
|
5386
|
+
distanceSquaredTo(point2) {
|
|
5387
|
+
const distance = this.distanceTo(point2);
|
|
5388
|
+
return distance * distance;
|
|
5389
|
+
}
|
|
5390
|
+
/** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
|
|
5391
|
+
distanceTo(point2) {
|
|
5392
|
+
const localPoint = this.inverseMatrix.transformAsPoint(point2);
|
|
5393
|
+
const localDistance = this.distanceToLocalPoint(localPoint);
|
|
5394
|
+
const scales = this.matrix.getScale();
|
|
5395
|
+
return localDistance * Math.min(scales[0], scales[1], scales[2]);
|
|
5396
|
+
}
|
|
5397
|
+
intersectPlane(plane) {
|
|
5398
|
+
const maximum = this.getSupportPoint(plane.normal);
|
|
4495
5399
|
const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
|
|
4496
5400
|
const maxDistance = plane.getPointDistance(maximum);
|
|
4497
5401
|
const minDistance = plane.getPointDistance(minimum);
|
|
@@ -4507,20 +5411,20 @@ var ImplicitShapeBase = class {
|
|
|
4507
5411
|
const hit = this.intersectLocalRay(localOrigin, localDirection);
|
|
4508
5412
|
if (!hit || hit.distance < 0)
|
|
4509
5413
|
return void 0;
|
|
4510
|
-
const
|
|
5414
|
+
const point2 = new import_core15.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
|
|
4511
5415
|
const inverse = this.inverseMatrix;
|
|
4512
|
-
const normal = new
|
|
4513
|
-
return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
|
|
5416
|
+
const normal = new import_core15.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();
|
|
5417
|
+
return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
|
|
4514
5418
|
}
|
|
4515
5419
|
getAxisAlignedBoundingBox() {
|
|
4516
|
-
const minimum = new
|
|
4517
|
-
const maximum = new
|
|
5420
|
+
const minimum = new import_core15.Vector3();
|
|
5421
|
+
const maximum = new import_core15.Vector3();
|
|
4518
5422
|
for (let axis = 0; axis < 3; axis++) {
|
|
4519
|
-
const
|
|
4520
|
-
|
|
4521
|
-
maximum[axis] = this.getSupportPoint(
|
|
4522
|
-
|
|
4523
|
-
minimum[axis] = this.getSupportPoint(
|
|
5423
|
+
const direction2 = [0, 0, 0];
|
|
5424
|
+
direction2[axis] = 1;
|
|
5425
|
+
maximum[axis] = this.getSupportPoint(direction2)[axis];
|
|
5426
|
+
direction2[axis] = -1;
|
|
5427
|
+
minimum[axis] = this.getSupportPoint(direction2)[axis];
|
|
4524
5428
|
}
|
|
4525
5429
|
return new AxisAlignedBoundingBox(minimum, maximum);
|
|
4526
5430
|
}
|
|
@@ -4537,7 +5441,7 @@ var ImplicitShapeBase = class {
|
|
|
4537
5441
|
matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
|
|
4538
5442
|
matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
|
|
4539
5443
|
];
|
|
4540
|
-
return new
|
|
5444
|
+
return new import_core15.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
|
|
4541
5445
|
}
|
|
4542
5446
|
};
|
|
4543
5447
|
function validateAffineMatrix(matrix) {
|
|
@@ -4547,7 +5451,7 @@ function validateAffineMatrix(matrix) {
|
|
|
4547
5451
|
if (Math.abs(matrix[3]) > 1e-12 || Math.abs(matrix[7]) > 1e-12 || Math.abs(matrix[11]) > 1e-12 || Math.abs(matrix[15] - 1) > 1e-12) {
|
|
4548
5452
|
throw new Error("Shape matrix must be affine");
|
|
4549
5453
|
}
|
|
4550
|
-
if (Math.abs(new
|
|
5454
|
+
if (Math.abs(new import_core15.Matrix4().copy(matrix).determinant()) < 1e-15)
|
|
4551
5455
|
throw new Error("Shape matrix must be invertible");
|
|
4552
5456
|
}
|
|
4553
5457
|
function solveQuadratic(a, b, c) {
|
|
@@ -4566,19 +5470,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
|
|
|
4566
5470
|
const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
|
|
4567
5471
|
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
|
|
4568
5472
|
}
|
|
4569
|
-
function closestDistanceToCircleArc2D(px, py, centerY,
|
|
4570
|
-
if (
|
|
5473
|
+
function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
|
|
5474
|
+
if (radius2 === 0)
|
|
4571
5475
|
return Math.hypot(px, py - centerY);
|
|
4572
5476
|
const dx = px;
|
|
4573
5477
|
const dy = py - centerY;
|
|
4574
5478
|
const length = Math.hypot(dx, dy);
|
|
4575
5479
|
const normalY = length ? dy / length : 0;
|
|
4576
5480
|
if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
|
|
4577
|
-
return Math.abs(length -
|
|
5481
|
+
return Math.abs(length - radius2);
|
|
4578
5482
|
}
|
|
4579
|
-
const minimumRadius =
|
|
4580
|
-
const maximumRadius =
|
|
4581
|
-
return Math.min(Math.hypot(px - minimumRadius, py - (centerY +
|
|
5483
|
+
const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
|
|
5484
|
+
const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
|
|
5485
|
+
return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
|
|
4582
5486
|
}
|
|
4583
5487
|
|
|
4584
5488
|
// dist/culling/lib/shapes/box-shape.js
|
|
@@ -4598,28 +5502,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
|
|
|
4598
5502
|
equals(shape) {
|
|
4599
5503
|
return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
|
|
4600
5504
|
}
|
|
4601
|
-
containsLocalPoint(
|
|
4602
|
-
return
|
|
5505
|
+
containsLocalPoint(point2) {
|
|
5506
|
+
return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
|
|
4603
5507
|
}
|
|
4604
|
-
distanceToLocalPoint(
|
|
4605
|
-
return Math.hypot(...
|
|
5508
|
+
distanceToLocalPoint(point2) {
|
|
5509
|
+
return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
|
|
4606
5510
|
}
|
|
4607
|
-
supportLocal(
|
|
4608
|
-
return
|
|
5511
|
+
supportLocal(direction2) {
|
|
5512
|
+
return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
|
|
4609
5513
|
}
|
|
4610
|
-
intersectLocalRay(origin,
|
|
5514
|
+
intersectLocalRay(origin, direction2) {
|
|
4611
5515
|
let near = -Infinity;
|
|
4612
5516
|
let far = Infinity;
|
|
4613
5517
|
let nearAxis = 0;
|
|
4614
5518
|
let farAxis = 0;
|
|
4615
5519
|
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
4616
|
-
if (Math.abs(
|
|
5520
|
+
if (Math.abs(direction2[axis2]) < 1e-15) {
|
|
4617
5521
|
if (Math.abs(origin[axis2]) > this.halfSize[axis2])
|
|
4618
5522
|
return void 0;
|
|
4619
5523
|
continue;
|
|
4620
5524
|
}
|
|
4621
|
-
let t1 = (-this.halfSize[axis2] - origin[axis2]) /
|
|
4622
|
-
let t2 = (this.halfSize[axis2] - origin[axis2]) /
|
|
5525
|
+
let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
5526
|
+
let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
4623
5527
|
if (t1 > t2)
|
|
4624
5528
|
[t1, t2] = [t2, t1];
|
|
4625
5529
|
if (t1 > near) {
|
|
@@ -4637,7 +5541,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
|
|
|
4637
5541
|
if (distance < 0 || !Number.isFinite(distance))
|
|
4638
5542
|
return void 0;
|
|
4639
5543
|
const axis = near >= 0 ? nearAxis : farAxis;
|
|
4640
|
-
const pointCoordinate = origin[axis] + distance *
|
|
5544
|
+
const pointCoordinate = origin[axis] + distance * direction2[axis];
|
|
4641
5545
|
const normal = [0, 0, 0];
|
|
4642
5546
|
normal[axis] = pointCoordinate < 0 ? -1 : 1;
|
|
4643
5547
|
return { distance, normal };
|
|
@@ -4671,74 +5575,74 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
|
|
|
4671
5575
|
equals(shape) {
|
|
4672
5576
|
return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
4673
5577
|
}
|
|
4674
|
-
containsLocalPoint(
|
|
5578
|
+
containsLocalPoint(point2) {
|
|
4675
5579
|
const profile = this.getProfile();
|
|
4676
|
-
const radial2 = Math.hypot(
|
|
5580
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4677
5581
|
if (profile.sphere)
|
|
4678
|
-
return Math.hypot(radial2,
|
|
4679
|
-
if (
|
|
4680
|
-
return Math.hypot(radial2,
|
|
4681
|
-
if (
|
|
4682
|
-
return Math.hypot(radial2,
|
|
4683
|
-
const t = (
|
|
5582
|
+
return Math.hypot(radial2, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
|
|
5583
|
+
if (point2[1] < profile.bottom.y)
|
|
5584
|
+
return Math.hypot(radial2, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
|
|
5585
|
+
if (point2[1] > profile.top.y)
|
|
5586
|
+
return Math.hypot(radial2, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
|
|
5587
|
+
const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
4684
5588
|
return radial2 <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
|
|
4685
5589
|
}
|
|
4686
|
-
distanceToLocalPoint(
|
|
4687
|
-
if (this.containsLocalPoint(
|
|
5590
|
+
distanceToLocalPoint(point2) {
|
|
5591
|
+
if (this.containsLocalPoint(point2))
|
|
4688
5592
|
return 0;
|
|
4689
5593
|
const profile = this.getProfile();
|
|
4690
|
-
const radial2 = Math.hypot(
|
|
5594
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4691
5595
|
if (profile.sphere)
|
|
4692
|
-
return Math.max(0, Math.hypot(radial2,
|
|
5596
|
+
return Math.max(0, Math.hypot(radial2, point2[1] - profile.sphere.center) - profile.sphere.radius);
|
|
4693
5597
|
const delta = this.radiusTop - this.radiusBottom;
|
|
4694
5598
|
const sideNormalY = -delta / this.height;
|
|
4695
|
-
const bottomArc = closestDistanceToCircleArc2D(radial2,
|
|
4696
|
-
const topArc = closestDistanceToCircleArc2D(radial2,
|
|
4697
|
-
const side = closestDistanceToSegment2D(radial2,
|
|
5599
|
+
const bottomArc = closestDistanceToCircleArc2D(radial2, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
|
|
5600
|
+
const topArc = closestDistanceToCircleArc2D(radial2, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
|
|
5601
|
+
const side = closestDistanceToSegment2D(radial2, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
|
|
4698
5602
|
return Math.min(bottomArc, topArc, side);
|
|
4699
5603
|
}
|
|
4700
|
-
supportLocal(
|
|
4701
|
-
const length = Math.hypot(...
|
|
4702
|
-
const
|
|
5604
|
+
supportLocal(direction2) {
|
|
5605
|
+
const length = Math.hypot(...direction2);
|
|
5606
|
+
const unit2 = length ? direction2.map((value) => value / length) : [1, 0, 0];
|
|
4703
5607
|
const bottom = [
|
|
4704
|
-
|
|
4705
|
-
-this.height / 2 +
|
|
4706
|
-
|
|
5608
|
+
unit2[0] * this.radiusBottom,
|
|
5609
|
+
-this.height / 2 + unit2[1] * this.radiusBottom,
|
|
5610
|
+
unit2[2] * this.radiusBottom
|
|
4707
5611
|
];
|
|
4708
5612
|
const top = [
|
|
4709
|
-
|
|
4710
|
-
this.height / 2 +
|
|
4711
|
-
|
|
5613
|
+
unit2[0] * this.radiusTop,
|
|
5614
|
+
this.height / 2 + unit2[1] * this.radiusTop,
|
|
5615
|
+
unit2[2] * this.radiusTop
|
|
4712
5616
|
];
|
|
4713
|
-
return
|
|
5617
|
+
return dot4(top, direction2) >= dot4(bottom, direction2) ? top : bottom;
|
|
4714
5618
|
}
|
|
4715
|
-
intersectLocalRay(origin,
|
|
5619
|
+
intersectLocalRay(origin, direction2) {
|
|
4716
5620
|
const profile = this.getProfile();
|
|
4717
5621
|
if (profile.sphere)
|
|
4718
|
-
return intersectSphere(origin,
|
|
5622
|
+
return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
|
|
4719
5623
|
const candidates = [];
|
|
4720
5624
|
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
4721
5625
|
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
4722
5626
|
const radialAtOrigin = intercept + slope * origin[1];
|
|
4723
|
-
const radialAlongRay = slope *
|
|
4724
|
-
for (const distance of solveQuadratic(
|
|
4725
|
-
const y = origin[1] + distance *
|
|
5627
|
+
const radialAlongRay = slope * direction2[1];
|
|
5628
|
+
for (const distance of solveQuadratic(direction2[0] ** 2 + direction2[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction2[0] + origin[2] * direction2[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
|
|
5629
|
+
const y = origin[1] + distance * direction2[1];
|
|
4726
5630
|
if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
|
|
4727
|
-
const x = origin[0] + distance *
|
|
4728
|
-
const z = origin[2] + distance *
|
|
5631
|
+
const x = origin[0] + distance * direction2[0];
|
|
5632
|
+
const z = origin[2] + distance * direction2[2];
|
|
4729
5633
|
const radial2 = Math.hypot(x, z) || 1;
|
|
4730
5634
|
const normal = [x / radial2, -slope, z / radial2];
|
|
4731
5635
|
const length = Math.hypot(...normal);
|
|
4732
5636
|
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
4733
5637
|
}
|
|
4734
5638
|
}
|
|
4735
|
-
for (const bottomHit of intersectSphereRoots(origin,
|
|
4736
|
-
const y = origin[1] + bottomHit.distance *
|
|
5639
|
+
for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
|
|
5640
|
+
const y = origin[1] + bottomHit.distance * direction2[1];
|
|
4737
5641
|
if (y <= profile.bottom.y + EPSILON2)
|
|
4738
5642
|
candidates.push(bottomHit);
|
|
4739
5643
|
}
|
|
4740
|
-
for (const topHit of intersectSphereRoots(origin,
|
|
4741
|
-
const y = origin[1] + topHit.distance *
|
|
5644
|
+
for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
|
|
5645
|
+
const y = origin[1] + topHit.distance * direction2[1];
|
|
4742
5646
|
if (y >= profile.top.y - EPSILON2)
|
|
4743
5647
|
candidates.push(topHit);
|
|
4744
5648
|
}
|
|
@@ -4769,19 +5673,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
|
|
|
4769
5673
|
};
|
|
4770
5674
|
}
|
|
4771
5675
|
};
|
|
4772
|
-
function intersectSphere(origin,
|
|
4773
|
-
return intersectSphereRoots(origin,
|
|
5676
|
+
function intersectSphere(origin, direction2, centerY, radius2) {
|
|
5677
|
+
return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
|
|
4774
5678
|
}
|
|
4775
|
-
function intersectSphereRoots(origin,
|
|
4776
|
-
if (
|
|
5679
|
+
function intersectSphereRoots(origin, direction2, centerY, radius2) {
|
|
5680
|
+
if (radius2 === 0)
|
|
4777
5681
|
return [];
|
|
4778
5682
|
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
4779
|
-
return solveQuadratic(
|
|
5683
|
+
return solveQuadratic(dot4(direction2, direction2), 2 * dot4(relative, direction2), dot4(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
|
|
4780
5684
|
distance,
|
|
4781
|
-
normal: relative.map((value, i) => (value + distance *
|
|
5685
|
+
normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
|
|
4782
5686
|
}));
|
|
4783
5687
|
}
|
|
4784
|
-
function
|
|
5688
|
+
function dot4(a, b) {
|
|
4785
5689
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4786
5690
|
}
|
|
4787
5691
|
|
|
@@ -4812,61 +5716,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
|
|
|
4812
5716
|
equals(shape) {
|
|
4813
5717
|
return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
4814
5718
|
}
|
|
4815
|
-
containsLocalPoint(
|
|
5719
|
+
containsLocalPoint(point2) {
|
|
4816
5720
|
const half = this.height / 2;
|
|
4817
|
-
if (
|
|
5721
|
+
if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
|
|
4818
5722
|
return false;
|
|
4819
|
-
const t = (
|
|
4820
|
-
const
|
|
4821
|
-
return Math.hypot(
|
|
5723
|
+
const t = (point2[1] + half) / this.height;
|
|
5724
|
+
const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
5725
|
+
return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
|
|
4822
5726
|
}
|
|
4823
|
-
distanceToLocalPoint(
|
|
4824
|
-
if (this.containsLocalPoint(
|
|
5727
|
+
distanceToLocalPoint(point2) {
|
|
5728
|
+
if (this.containsLocalPoint(point2))
|
|
4825
5729
|
return 0;
|
|
4826
|
-
const radial2 = Math.hypot(
|
|
5730
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4827
5731
|
const half = this.height / 2;
|
|
4828
|
-
const side = closestDistanceToSegment2D(radial2,
|
|
4829
|
-
const bottom = closestDistanceToSegment2D(radial2,
|
|
4830
|
-
const top = closestDistanceToSegment2D(radial2,
|
|
5732
|
+
const side = closestDistanceToSegment2D(radial2, point2[1], this.radiusBottom, -half, this.radiusTop, half);
|
|
5733
|
+
const bottom = closestDistanceToSegment2D(radial2, point2[1], 0, -half, this.radiusBottom, -half);
|
|
5734
|
+
const top = closestDistanceToSegment2D(radial2, point2[1], 0, half, this.radiusTop, half);
|
|
4831
5735
|
return Math.min(side, bottom, top);
|
|
4832
5736
|
}
|
|
4833
|
-
supportLocal(
|
|
4834
|
-
const radialLength = Math.hypot(
|
|
4835
|
-
const x = radialLength ?
|
|
4836
|
-
const z = radialLength ?
|
|
5737
|
+
supportLocal(direction2) {
|
|
5738
|
+
const radialLength = Math.hypot(direction2[0], direction2[2]);
|
|
5739
|
+
const x = radialLength ? direction2[0] / radialLength : 1;
|
|
5740
|
+
const z = radialLength ? direction2[2] / radialLength : 0;
|
|
4837
5741
|
const half = this.height / 2;
|
|
4838
|
-
const bottomValue = radialLength * this.radiusBottom -
|
|
4839
|
-
const topValue = radialLength * this.radiusTop +
|
|
5742
|
+
const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
|
|
5743
|
+
const topValue = radialLength * this.radiusTop + direction2[1] * half;
|
|
4840
5744
|
return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
4841
5745
|
}
|
|
4842
|
-
intersectLocalRay(origin,
|
|
5746
|
+
intersectLocalRay(origin, direction2) {
|
|
4843
5747
|
const half = this.height / 2;
|
|
4844
5748
|
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
4845
5749
|
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
4846
5750
|
const radialAtOrigin = intercept + slope * origin[1];
|
|
4847
|
-
const radialAlongRay = slope *
|
|
5751
|
+
const radialAlongRay = slope * direction2[1];
|
|
4848
5752
|
const candidates = [];
|
|
4849
|
-
const roots = solveQuadratic(
|
|
5753
|
+
const roots = solveQuadratic(direction2[0] ** 2 + direction2[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction2[0] + origin[2] * direction2[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
|
|
4850
5754
|
for (const distance of roots) {
|
|
4851
|
-
const y = origin[1] + distance *
|
|
5755
|
+
const y = origin[1] + distance * direction2[1];
|
|
4852
5756
|
if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
|
|
4853
|
-
const x = origin[0] + distance *
|
|
4854
|
-
const z = origin[2] + distance *
|
|
5757
|
+
const x = origin[0] + distance * direction2[0];
|
|
5758
|
+
const z = origin[2] + distance * direction2[2];
|
|
4855
5759
|
const radial2 = Math.hypot(x, z) || 1;
|
|
4856
5760
|
const normal = [x / radial2, -slope, z / radial2];
|
|
4857
5761
|
const length = Math.hypot(...normal);
|
|
4858
5762
|
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
4859
5763
|
}
|
|
4860
5764
|
}
|
|
4861
|
-
if (Math.abs(
|
|
4862
|
-
for (const [y,
|
|
5765
|
+
if (Math.abs(direction2[1]) > 1e-15) {
|
|
5766
|
+
for (const [y, radius2, normalY] of [
|
|
4863
5767
|
[-half, this.radiusBottom, -1],
|
|
4864
5768
|
[half, this.radiusTop, 1]
|
|
4865
5769
|
]) {
|
|
4866
|
-
const distance = (y - origin[1]) /
|
|
4867
|
-
const x = origin[0] + distance *
|
|
4868
|
-
const z = origin[2] + distance *
|
|
4869
|
-
if (distance >= 0 && Math.hypot(x, z) <=
|
|
5770
|
+
const distance = (y - origin[1]) / direction2[1];
|
|
5771
|
+
const x = origin[0] + distance * direction2[0];
|
|
5772
|
+
const z = origin[2] + distance * direction2[2];
|
|
5773
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
|
|
4870
5774
|
candidates.push({ distance, normal: [0, normalY, 0] });
|
|
4871
5775
|
}
|
|
4872
5776
|
}
|
|
@@ -4875,7 +5779,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
|
|
|
4875
5779
|
};
|
|
4876
5780
|
|
|
4877
5781
|
// dist/culling/lib/shapes/plane-shape.js
|
|
4878
|
-
var
|
|
5782
|
+
var import_core16 = require("@math.gl/core");
|
|
4879
5783
|
var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
4880
5784
|
constructor(props = {}) {
|
|
4881
5785
|
super(props.matrix);
|
|
@@ -4893,23 +5797,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
|
4893
5797
|
equals(shape) {
|
|
4894
5798
|
return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
|
|
4895
5799
|
}
|
|
4896
|
-
containsLocalPoint(
|
|
4897
|
-
return
|
|
5800
|
+
containsLocalPoint(point2) {
|
|
5801
|
+
return point2[1] <= 1e-12;
|
|
4898
5802
|
}
|
|
4899
|
-
distanceToLocalPoint(
|
|
4900
|
-
return Math.max(0,
|
|
5803
|
+
distanceToLocalPoint(point2) {
|
|
5804
|
+
return Math.max(0, point2[1]);
|
|
4901
5805
|
}
|
|
4902
5806
|
supportLocal() {
|
|
4903
5807
|
throw new Error("An unbounded plane half-space has no finite support point");
|
|
4904
5808
|
}
|
|
4905
|
-
intersectLocalRay(origin,
|
|
4906
|
-
if (Math.abs(
|
|
5809
|
+
intersectLocalRay(origin, direction2) {
|
|
5810
|
+
if (Math.abs(direction2[1]) < 1e-15)
|
|
4907
5811
|
return void 0;
|
|
4908
|
-
const distance = -origin[1] /
|
|
5812
|
+
const distance = -origin[1] / direction2[1];
|
|
4909
5813
|
if (distance < 0)
|
|
4910
5814
|
return void 0;
|
|
4911
|
-
const x = origin[0] + distance *
|
|
4912
|
-
const z = origin[2] + distance *
|
|
5815
|
+
const x = origin[0] + distance * direction2[0];
|
|
5816
|
+
const z = origin[2] + distance * direction2[2];
|
|
4913
5817
|
if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
|
|
4914
5818
|
return void 0;
|
|
4915
5819
|
if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
|
|
@@ -4917,9 +5821,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
|
4917
5821
|
return { distance, normal: [0, 1, 0] };
|
|
4918
5822
|
}
|
|
4919
5823
|
intersectPlane(plane) {
|
|
4920
|
-
const boundaryPoint = new
|
|
5824
|
+
const boundaryPoint = new import_core16.Vector3(0, 0, 0).transform(this.matrix);
|
|
4921
5825
|
const inverse = this.inverseMatrix;
|
|
4922
|
-
const boundaryNormal = new
|
|
5826
|
+
const boundaryNormal = new import_core16.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
|
|
4923
5827
|
const alignment = boundaryNormal.dot(plane.normal);
|
|
4924
5828
|
if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
|
|
4925
5829
|
return "intersecting";
|
|
@@ -4954,36 +5858,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
|
|
|
4954
5858
|
equals(shape) {
|
|
4955
5859
|
return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
|
|
4956
5860
|
}
|
|
4957
|
-
containsLocalPoint(
|
|
4958
|
-
return Math.hypot(...
|
|
5861
|
+
containsLocalPoint(point2) {
|
|
5862
|
+
return Math.hypot(...point2) <= this.radius + EPSILON4;
|
|
4959
5863
|
}
|
|
4960
|
-
distanceToLocalPoint(
|
|
4961
|
-
return Math.max(0, Math.hypot(...
|
|
5864
|
+
distanceToLocalPoint(point2) {
|
|
5865
|
+
return Math.max(0, Math.hypot(...point2) - this.radius);
|
|
4962
5866
|
}
|
|
4963
|
-
supportLocal(
|
|
4964
|
-
const length = Math.hypot(...
|
|
4965
|
-
return length ?
|
|
5867
|
+
supportLocal(direction2) {
|
|
5868
|
+
const length = Math.hypot(...direction2);
|
|
5869
|
+
return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
|
|
4966
5870
|
}
|
|
4967
|
-
intersectLocalRay(origin,
|
|
4968
|
-
const roots = solveQuadratic(
|
|
5871
|
+
intersectLocalRay(origin, direction2) {
|
|
5872
|
+
const roots = solveQuadratic(dot5(direction2, direction2), 2 * dot5(origin, direction2), dot5(origin, origin) - this.radius * this.radius);
|
|
4969
5873
|
const distance = roots.find((value) => value >= 0);
|
|
4970
5874
|
if (distance === void 0)
|
|
4971
5875
|
return void 0;
|
|
4972
|
-
const
|
|
4973
|
-
return { distance, normal:
|
|
5876
|
+
const point2 = origin.map((value, i) => value + distance * direction2[i]);
|
|
5877
|
+
return { distance, normal: point2.map((value) => value / this.radius) };
|
|
4974
5878
|
}
|
|
4975
5879
|
};
|
|
4976
|
-
function
|
|
5880
|
+
function dot5(a, b) {
|
|
4977
5881
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4978
5882
|
}
|
|
4979
5883
|
|
|
4980
5884
|
// dist/culling/lib/perspective-off-center-frustum.js
|
|
4981
|
-
var
|
|
4982
|
-
var scratchPlaneUpVector = new
|
|
4983
|
-
var scratchPlaneRightVector = new
|
|
4984
|
-
var scratchPlaneNearCenter = new
|
|
4985
|
-
var scratchPlaneFarCenter = new
|
|
4986
|
-
var scratchPlaneNormal2 = new
|
|
5885
|
+
var import_core17 = require("@math.gl/core");
|
|
5886
|
+
var scratchPlaneUpVector = new import_core17.Vector3();
|
|
5887
|
+
var scratchPlaneRightVector = new import_core17.Vector3();
|
|
5888
|
+
var scratchPlaneNearCenter = new import_core17.Vector3();
|
|
5889
|
+
var scratchPlaneFarCenter = new import_core17.Vector3();
|
|
5890
|
+
var scratchPlaneNormal2 = new import_core17.Vector3();
|
|
4987
5891
|
var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
4988
5892
|
/**
|
|
4989
5893
|
* The viewing frustum is defined by 6 planes.
|
|
@@ -5014,8 +5918,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5014
5918
|
new Plane(),
|
|
5015
5919
|
new Plane()
|
|
5016
5920
|
]);
|
|
5017
|
-
this._perspectiveMatrix = new
|
|
5018
|
-
this._infinitePerspective = new
|
|
5921
|
+
this._perspectiveMatrix = new import_core17.Matrix4();
|
|
5922
|
+
this._infinitePerspective = new import_core17.Matrix4();
|
|
5019
5923
|
const { near = 1, far = 5e8 } = options;
|
|
5020
5924
|
this.left = options.left;
|
|
5021
5925
|
this._left = void 0;
|
|
@@ -5085,15 +5989,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5085
5989
|
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
5086
5990
|
*/
|
|
5087
5991
|
// eslint-disable-next-line complexity, max-statements
|
|
5088
|
-
computeCullingVolume(position,
|
|
5089
|
-
(0,
|
|
5090
|
-
(0,
|
|
5091
|
-
(0,
|
|
5992
|
+
computeCullingVolume(position, direction2, up) {
|
|
5993
|
+
(0, import_core17.assert)(position, "position is required.");
|
|
5994
|
+
(0, import_core17.assert)(direction2, "direction is required.");
|
|
5995
|
+
(0, import_core17.assert)(up, "up is required.");
|
|
5092
5996
|
const planes = this._cullingVolume.planes;
|
|
5093
5997
|
up = scratchPlaneUpVector.copy(up).normalize();
|
|
5094
|
-
const right = scratchPlaneRightVector.copy(
|
|
5095
|
-
const nearCenter = scratchPlaneNearCenter.copy(
|
|
5096
|
-
const farCenter = scratchPlaneFarCenter.copy(
|
|
5998
|
+
const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
|
|
5999
|
+
const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
|
|
6000
|
+
const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
|
|
5097
6001
|
let normal = scratchPlaneNormal2;
|
|
5098
6002
|
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
5099
6003
|
planes[0].fromPointNormal(position, normal);
|
|
@@ -5103,7 +6007,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5103
6007
|
planes[2].fromPointNormal(position, normal);
|
|
5104
6008
|
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
5105
6009
|
planes[3].fromPointNormal(position, normal);
|
|
5106
|
-
normal = new
|
|
6010
|
+
normal = new import_core17.Vector3().copy(direction2);
|
|
5107
6011
|
planes[4].fromPointNormal(nearCenter, normal);
|
|
5108
6012
|
normal.negate();
|
|
5109
6013
|
planes[5].fromPointNormal(farCenter, normal);
|
|
@@ -5135,11 +6039,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5135
6039
|
*/
|
|
5136
6040
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
5137
6041
|
this._update();
|
|
5138
|
-
(0,
|
|
5139
|
-
(0,
|
|
5140
|
-
(0,
|
|
5141
|
-
(0,
|
|
5142
|
-
(0,
|
|
6042
|
+
(0, import_core17.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
6043
|
+
(0, import_core17.assert)(drawingBufferWidth > 0);
|
|
6044
|
+
(0, import_core17.assert)(drawingBufferHeight > 0);
|
|
6045
|
+
(0, import_core17.assert)(distance > 0);
|
|
6046
|
+
(0, import_core17.assert)(result);
|
|
5143
6047
|
const inverseNear = 1 / this.near;
|
|
5144
6048
|
let tanTheta = this.top * inverseNear;
|
|
5145
6049
|
const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
|
|
@@ -5151,17 +6055,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5151
6055
|
}
|
|
5152
6056
|
// eslint-disable-next-line complexity, max-statements
|
|
5153
6057
|
_update() {
|
|
5154
|
-
(0,
|
|
6058
|
+
(0, import_core17.assert)(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
5155
6059
|
const { top, bottom, right, left, near, far } = this;
|
|
5156
6060
|
if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
|
|
5157
|
-
(0,
|
|
6061
|
+
(0, import_core17.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
|
|
5158
6062
|
this._left = left;
|
|
5159
6063
|
this._right = right;
|
|
5160
6064
|
this._top = top;
|
|
5161
6065
|
this._bottom = bottom;
|
|
5162
6066
|
this._near = near;
|
|
5163
6067
|
this._far = far;
|
|
5164
|
-
this._perspectiveMatrix = new
|
|
6068
|
+
this._perspectiveMatrix = new import_core17.Matrix4().frustum({
|
|
5165
6069
|
left,
|
|
5166
6070
|
right,
|
|
5167
6071
|
bottom,
|
|
@@ -5169,7 +6073,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5169
6073
|
near,
|
|
5170
6074
|
far
|
|
5171
6075
|
});
|
|
5172
|
-
this._infinitePerspective = new
|
|
6076
|
+
this._infinitePerspective = new import_core17.Matrix4().frustum({
|
|
5173
6077
|
left,
|
|
5174
6078
|
right,
|
|
5175
6079
|
bottom,
|
|
@@ -5182,7 +6086,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5182
6086
|
};
|
|
5183
6087
|
|
|
5184
6088
|
// dist/culling/lib/perspective-frustum.js
|
|
5185
|
-
var
|
|
6089
|
+
var import_core18 = require("@math.gl/core");
|
|
5186
6090
|
var defined = (val) => val !== null && typeof val !== "undefined";
|
|
5187
6091
|
var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
5188
6092
|
constructor(options = {}) {
|
|
@@ -5255,9 +6159,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5255
6159
|
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
5256
6160
|
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
5257
6161
|
*/
|
|
5258
|
-
computeCullingVolume(position,
|
|
6162
|
+
computeCullingVolume(position, direction2, up) {
|
|
5259
6163
|
this._update();
|
|
5260
|
-
return this._offCenterFrustum.computeCullingVolume(position,
|
|
6164
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
|
|
5261
6165
|
}
|
|
5262
6166
|
/**
|
|
5263
6167
|
* Returns the pixel's width and height in meters.
|
|
@@ -5284,16 +6188,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5284
6188
|
*/
|
|
5285
6189
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
5286
6190
|
this._update();
|
|
5287
|
-
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new
|
|
6191
|
+
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core18.Vector2());
|
|
5288
6192
|
}
|
|
5289
6193
|
// eslint-disable-next-line complexity, max-statements
|
|
5290
6194
|
_update() {
|
|
5291
|
-
(0,
|
|
6195
|
+
(0, import_core18.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
5292
6196
|
const f = this._offCenterFrustum;
|
|
5293
6197
|
if (this.fov !== this._fov || this.aspectRatio !== this._aspectRatio || this.near !== this._near || this.far !== this._far || this.xOffset !== this._xOffset || this.yOffset !== this._yOffset) {
|
|
5294
|
-
(0,
|
|
5295
|
-
(0,
|
|
5296
|
-
(0,
|
|
6198
|
+
(0, import_core18.assert)(this.fov >= 0 && this.fov < Math.PI);
|
|
6199
|
+
(0, import_core18.assert)(this.aspectRatio > 0);
|
|
6200
|
+
(0, import_core18.assert)(this.near >= 0 && this.near < this.far);
|
|
5297
6201
|
this._aspectRatio = this.aspectRatio;
|
|
5298
6202
|
this._fov = this.fov;
|
|
5299
6203
|
this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
|
|
@@ -5317,19 +6221,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5317
6221
|
};
|
|
5318
6222
|
|
|
5319
6223
|
// dist/culling/lib/algorithms/bounding-sphere-from-points.js
|
|
5320
|
-
var
|
|
5321
|
-
var fromPointsXMin = new
|
|
5322
|
-
var fromPointsYMin = new
|
|
5323
|
-
var fromPointsZMin = new
|
|
5324
|
-
var fromPointsXMax = new
|
|
5325
|
-
var fromPointsYMax = new
|
|
5326
|
-
var fromPointsZMax = new
|
|
5327
|
-
var fromPointsCurrentPos = new
|
|
5328
|
-
var fromPointsScratch = new
|
|
5329
|
-
var fromPointsRitterCenter = new
|
|
5330
|
-
var fromPointsMinBoxPt = new
|
|
5331
|
-
var fromPointsMaxBoxPt = new
|
|
5332
|
-
var fromPointsNaiveCenterScratch = new
|
|
6224
|
+
var import_core19 = require("@math.gl/core");
|
|
6225
|
+
var fromPointsXMin = new import_core19.Vector3();
|
|
6226
|
+
var fromPointsYMin = new import_core19.Vector3();
|
|
6227
|
+
var fromPointsZMin = new import_core19.Vector3();
|
|
6228
|
+
var fromPointsXMax = new import_core19.Vector3();
|
|
6229
|
+
var fromPointsYMax = new import_core19.Vector3();
|
|
6230
|
+
var fromPointsZMax = new import_core19.Vector3();
|
|
6231
|
+
var fromPointsCurrentPos = new import_core19.Vector3();
|
|
6232
|
+
var fromPointsScratch = new import_core19.Vector3();
|
|
6233
|
+
var fromPointsRitterCenter = new import_core19.Vector3();
|
|
6234
|
+
var fromPointsMinBoxPt = new import_core19.Vector3();
|
|
6235
|
+
var fromPointsMaxBoxPt = new import_core19.Vector3();
|
|
6236
|
+
var fromPointsNaiveCenterScratch = new import_core19.Vector3();
|
|
5333
6237
|
function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
|
|
5334
6238
|
if (!positions || positions.length === 0) {
|
|
5335
6239
|
return result.fromCenterRadius([0, 0, 0], 0);
|
|
@@ -5425,17 +6329,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
|
|
|
5425
6329
|
}
|
|
5426
6330
|
|
|
5427
6331
|
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
5428
|
-
var
|
|
6332
|
+
var import_core21 = require("@math.gl/core");
|
|
5429
6333
|
|
|
5430
6334
|
// dist/culling/lib/algorithms/compute-eigen-decomposition.js
|
|
5431
|
-
var
|
|
5432
|
-
var scratchMatrix = new
|
|
5433
|
-
var scratchUnitary = new
|
|
5434
|
-
var scratchDiagonal = new
|
|
5435
|
-
var jMatrix = new
|
|
5436
|
-
var jMatrixTranspose = new
|
|
6335
|
+
var import_core20 = require("@math.gl/core");
|
|
6336
|
+
var scratchMatrix = new import_core20.Matrix3();
|
|
6337
|
+
var scratchUnitary = new import_core20.Matrix3();
|
|
6338
|
+
var scratchDiagonal = new import_core20.Matrix3();
|
|
6339
|
+
var jMatrix = new import_core20.Matrix3();
|
|
6340
|
+
var jMatrixTranspose = new import_core20.Matrix3();
|
|
5437
6341
|
function computeEigenDecomposition(matrix, result = {}) {
|
|
5438
|
-
const EIGEN_TOLERANCE =
|
|
6342
|
+
const EIGEN_TOLERANCE = import_core20._MathUtils.EPSILON20;
|
|
5439
6343
|
const EIGEN_MAX_SWEEPS = 10;
|
|
5440
6344
|
let count = 0;
|
|
5441
6345
|
let sweep = 0;
|
|
@@ -5478,7 +6382,7 @@ function offDiagonalFrobeniusNorm(matrix) {
|
|
|
5478
6382
|
return Math.sqrt(norm);
|
|
5479
6383
|
}
|
|
5480
6384
|
function shurDecomposition(matrix, result) {
|
|
5481
|
-
const tolerance =
|
|
6385
|
+
const tolerance = import_core20._MathUtils.EPSILON15;
|
|
5482
6386
|
let maxDiagonal = 0;
|
|
5483
6387
|
let rotAxis = 1;
|
|
5484
6388
|
for (let i = 0; i < 3; ++i) {
|
|
@@ -5506,7 +6410,7 @@ function shurDecomposition(matrix, result) {
|
|
|
5506
6410
|
c = 1 / Math.sqrt(1 + t * t);
|
|
5507
6411
|
s = t * c;
|
|
5508
6412
|
}
|
|
5509
|
-
|
|
6413
|
+
import_core20.Matrix3.IDENTITY.to(result);
|
|
5510
6414
|
result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
|
|
5511
6415
|
result[scratchMatrix.getElementIndex(q, p)] = s;
|
|
5512
6416
|
result[scratchMatrix.getElementIndex(p, q)] = -s;
|
|
@@ -5514,24 +6418,24 @@ function shurDecomposition(matrix, result) {
|
|
|
5514
6418
|
}
|
|
5515
6419
|
|
|
5516
6420
|
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
5517
|
-
var scratchVector23 = new
|
|
5518
|
-
var scratchVector33 = new
|
|
5519
|
-
var scratchVector42 = new
|
|
5520
|
-
var scratchVector5 = new
|
|
5521
|
-
var scratchVector6 = new
|
|
5522
|
-
var scratchCovarianceResult = new
|
|
6421
|
+
var scratchVector23 = new import_core21.Vector3();
|
|
6422
|
+
var scratchVector33 = new import_core21.Vector3();
|
|
6423
|
+
var scratchVector42 = new import_core21.Vector3();
|
|
6424
|
+
var scratchVector5 = new import_core21.Vector3();
|
|
6425
|
+
var scratchVector6 = new import_core21.Vector3();
|
|
6426
|
+
var scratchCovarianceResult = new import_core21.Matrix3();
|
|
5523
6427
|
var scratchEigenResult = {
|
|
5524
|
-
diagonal: new
|
|
5525
|
-
unitary: new
|
|
6428
|
+
diagonal: new import_core21.Matrix3(),
|
|
6429
|
+
unitary: new import_core21.Matrix3()
|
|
5526
6430
|
};
|
|
5527
6431
|
function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
|
|
5528
6432
|
if (!positions || positions.length === 0) {
|
|
5529
|
-
result.halfAxes = new
|
|
5530
|
-
result.center = new
|
|
6433
|
+
result.halfAxes = new import_core21.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
6434
|
+
result.center = new import_core21.Vector3();
|
|
5531
6435
|
return result;
|
|
5532
6436
|
}
|
|
5533
6437
|
const length = positions.length;
|
|
5534
|
-
const meanPoint = new
|
|
6438
|
+
const meanPoint = new import_core21.Vector3(0, 0, 0);
|
|
5535
6439
|
for (const position of positions) {
|
|
5536
6440
|
meanPoint.add(position);
|
|
5537
6441
|
}
|
|
@@ -5593,7 +6497,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
|
|
|
5593
6497
|
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
5594
6498
|
result.center.copy(v1).add(v2).add(v3);
|
|
5595
6499
|
const scale = scratchVector33.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
5596
|
-
const scaleMatrix = new
|
|
6500
|
+
const scaleMatrix = new import_core21.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
5597
6501
|
result.halfAxes.multiplyRight(scaleMatrix);
|
|
5598
6502
|
return result;
|
|
5599
6503
|
}
|
|
@@ -5629,245 +6533,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
|
|
|
5629
6533
|
return result;
|
|
5630
6534
|
}
|
|
5631
6535
|
|
|
5632
|
-
// dist/culling/queries.js
|
|
5633
|
-
function validateQueryPoint(point, dimension) {
|
|
5634
|
-
if (point.length !== dimension)
|
|
5635
|
-
throw new RangeError("Query dimension must match the index");
|
|
5636
|
-
for (let i = 0; i < dimension; i++) {
|
|
5637
|
-
if (!Number.isFinite(point[i]))
|
|
5638
|
-
throw new RangeError("Coordinates must be finite");
|
|
5639
|
-
}
|
|
5640
|
-
}
|
|
5641
|
-
function validateQueryDistance(distance) {
|
|
5642
|
-
if (Number.isNaN(distance) || distance < 0)
|
|
5643
|
-
throw new RangeError("Distance must be nonnegative");
|
|
5644
|
-
}
|
|
5645
|
-
function normalizeQueryDirection(direction, dimension) {
|
|
5646
|
-
validateQueryPoint(direction, dimension);
|
|
5647
|
-
const scale = Math.max(...Array.from(direction, Math.abs));
|
|
5648
|
-
if (scale === 0)
|
|
5649
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5650
|
-
const scaled = Array.from(direction, (x) => x / scale);
|
|
5651
|
-
const length = Math.hypot(...scaled);
|
|
5652
|
-
return scaled.map((x) => x / length);
|
|
5653
|
-
}
|
|
5654
|
-
function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
|
|
5655
|
-
const dimension = origin.length;
|
|
5656
|
-
if (dimension !== 2 && dimension !== 3)
|
|
5657
|
-
throw new RangeError("Bounds must be 2D or 3D");
|
|
5658
|
-
validateQueryPoint(origin, dimension);
|
|
5659
|
-
validateQueryPoint(direction, dimension);
|
|
5660
|
-
validateQueryPoint(minimum, dimension);
|
|
5661
|
-
validateQueryPoint(maximum, dimension);
|
|
5662
|
-
validateQueryDistance(maxT);
|
|
5663
|
-
let near = 0, far = maxT, nonzero = false;
|
|
5664
|
-
for (let i = 0; i < dimension; i++) {
|
|
5665
|
-
if (minimum[i] > maximum[i])
|
|
5666
|
-
throw new RangeError("Bounds must be ordered");
|
|
5667
|
-
nonzero || (nonzero = direction[i] !== 0);
|
|
5668
|
-
}
|
|
5669
|
-
if (!nonzero)
|
|
5670
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5671
|
-
for (let i = 0; i < dimension; i++) {
|
|
5672
|
-
if (direction[i] === 0) {
|
|
5673
|
-
if (origin[i] < minimum[i] || origin[i] > maximum[i])
|
|
5674
|
-
return null;
|
|
5675
|
-
continue;
|
|
5676
|
-
}
|
|
5677
|
-
let a = (minimum[i] - origin[i]) / direction[i];
|
|
5678
|
-
let b = (maximum[i] - origin[i]) / direction[i];
|
|
5679
|
-
if (a > b)
|
|
5680
|
-
[a, b] = [b, a];
|
|
5681
|
-
near = Math.max(near, a);
|
|
5682
|
-
far = Math.min(far, b);
|
|
5683
|
-
if (near > far)
|
|
5684
|
-
return null;
|
|
5685
|
-
}
|
|
5686
|
-
return Number.isFinite(near) ? near : null;
|
|
5687
|
-
}
|
|
5688
|
-
function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
|
|
5689
|
-
for (const point of [origin, direction, a, b, c])
|
|
5690
|
-
validateQueryPoint(point, 3);
|
|
5691
|
-
if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
|
|
5692
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5693
|
-
}
|
|
5694
|
-
const maxT = options.maxT ?? Infinity;
|
|
5695
|
-
validateQueryDistance(maxT);
|
|
5696
|
-
const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
5697
|
-
const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
5698
|
-
const p = cross3(direction, e2);
|
|
5699
|
-
const determinant = dot3(e1, p);
|
|
5700
|
-
if (determinant === 0 || options.backfaceCulling && determinant < 0)
|
|
5701
|
-
return null;
|
|
5702
|
-
const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
|
|
5703
|
-
const u = dot3(offset, p) / determinant;
|
|
5704
|
-
if (u < 0 || u > 1)
|
|
5705
|
-
return null;
|
|
5706
|
-
const q = cross3(offset, e1);
|
|
5707
|
-
const v = dot3(direction, q) / determinant;
|
|
5708
|
-
if (v < 0 || u + v > 1)
|
|
5709
|
-
return null;
|
|
5710
|
-
const t = dot3(e2, q) / determinant;
|
|
5711
|
-
if (!Number.isFinite(t) || t < 0 || t > maxT)
|
|
5712
|
-
return null;
|
|
5713
|
-
return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
|
|
5714
|
-
}
|
|
5715
|
-
function getClosestPointOnTriangle(point, a, b, c) {
|
|
5716
|
-
for (const value of [point, a, b, c])
|
|
5717
|
-
validateQueryPoint(value, 3);
|
|
5718
|
-
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
5719
|
-
const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
5720
|
-
const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
|
|
5721
|
-
const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
|
|
5722
|
-
const denominator = aa * bb - cc * cc;
|
|
5723
|
-
if (denominator > 0 && Number.isFinite(denominator)) {
|
|
5724
|
-
const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
|
|
5725
|
-
const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
|
|
5726
|
-
if (u >= 0 && v >= 0 && u + v <= 1) {
|
|
5727
|
-
return [
|
|
5728
|
-
a[0] + u * ab[0] + v * ac[0],
|
|
5729
|
-
a[1] + u * ab[1] + v * ac[1],
|
|
5730
|
-
a[2] + u * ab[2] + v * ac[2]
|
|
5731
|
-
];
|
|
5732
|
-
}
|
|
5733
|
-
}
|
|
5734
|
-
let best = [a[0], a[1], a[2]];
|
|
5735
|
-
let distance = Infinity;
|
|
5736
|
-
for (const [start, end] of [
|
|
5737
|
-
[a, b],
|
|
5738
|
-
[b, c],
|
|
5739
|
-
[c, a]
|
|
5740
|
-
]) {
|
|
5741
|
-
const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
|
|
5742
|
-
const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
|
|
5743
|
-
const squared = dot3(edge, edge);
|
|
5744
|
-
const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
|
|
5745
|
-
const candidate = [
|
|
5746
|
-
start[0] + t * edge[0],
|
|
5747
|
-
start[1] + t * edge[1],
|
|
5748
|
-
start[2] + t * edge[2]
|
|
5749
|
-
];
|
|
5750
|
-
const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
|
|
5751
|
-
if (d < distance) {
|
|
5752
|
-
distance = d;
|
|
5753
|
-
best = candidate;
|
|
5754
|
-
}
|
|
5755
|
-
}
|
|
5756
|
-
return best;
|
|
5757
|
-
}
|
|
5758
|
-
function getClosestPointsOnSegments(a0, a1, b0, b1) {
|
|
5759
|
-
const frame = queryFrame([a0, a1, b0, b1]);
|
|
5760
|
-
const pair = closestSegments(...frame.points);
|
|
5761
|
-
const pointA = interpolatePoint(a0, a1, pair.fractionA);
|
|
5762
|
-
const pointB = interpolatePoint(b0, b1, pair.fractionB);
|
|
5763
|
-
return {
|
|
5764
|
-
distance: finiteDistance(pointA, pointB),
|
|
5765
|
-
pointA,
|
|
5766
|
-
pointB,
|
|
5767
|
-
fractionA: pair.fractionA,
|
|
5768
|
-
fractionB: pair.fractionB
|
|
5769
|
-
};
|
|
5770
|
-
}
|
|
5771
|
-
function getClosestPointsSegmentTriangle(start, end, a, b, c) {
|
|
5772
|
-
const frame = queryFrame([start, end, a, b, c]);
|
|
5773
|
-
const [s, e, va, vb, vc] = frame.points;
|
|
5774
|
-
const direction = subtract(e, s);
|
|
5775
|
-
if (direction.some((value) => value !== 0)) {
|
|
5776
|
-
const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
|
|
5777
|
-
if (hit) {
|
|
5778
|
-
const point = interpolatePoint(start, end, hit.t);
|
|
5779
|
-
return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
|
|
5780
|
-
}
|
|
5781
|
-
}
|
|
5782
|
-
let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
|
|
5783
|
-
const consider = (point, trianglePoint2, segmentFraction) => {
|
|
5784
|
-
const distance = Math.hypot(...subtract(point, trianglePoint2));
|
|
5785
|
-
if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
|
|
5786
|
-
best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
|
|
5787
|
-
};
|
|
5788
|
-
consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
|
|
5789
|
-
consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
|
|
5790
|
-
for (const [v0, v1] of [
|
|
5791
|
-
[va, vb],
|
|
5792
|
-
[vb, vc],
|
|
5793
|
-
[vc, va]
|
|
5794
|
-
]) {
|
|
5795
|
-
const pair = closestSegments(s, e, v0, v1);
|
|
5796
|
-
consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
|
|
5797
|
-
}
|
|
5798
|
-
const trianglePoint = best.trianglePoint.map((value, axis) => Math.max(Math.min(a[axis], b[axis], c[axis]), Math.min(Math.max(a[axis], b[axis], c[axis]), start[axis] + value * frame.scale)));
|
|
5799
|
-
if (!trianglePoint.every(Number.isFinite))
|
|
5800
|
-
throw new RangeError("Closest-point result overflow");
|
|
5801
|
-
const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
|
|
5802
|
-
return {
|
|
5803
|
-
distance: finiteDistance(segmentPoint, trianglePoint),
|
|
5804
|
-
segmentPoint,
|
|
5805
|
-
trianglePoint,
|
|
5806
|
-
segmentFraction: best.segmentFraction
|
|
5807
|
-
};
|
|
5808
|
-
}
|
|
5809
|
-
function queryFrame(input) {
|
|
5810
|
-
input.forEach((point) => validateQueryPoint(point, 3));
|
|
5811
|
-
const offsets = input.map((point) => subtract(point, input[0]));
|
|
5812
|
-
let scale = 0;
|
|
5813
|
-
for (const offset of offsets)
|
|
5814
|
-
for (const value of offset) {
|
|
5815
|
-
if (!Number.isFinite(value))
|
|
5816
|
-
throw new RangeError("Closest-point coordinate span overflow");
|
|
5817
|
-
scale = Math.max(scale, Math.abs(value));
|
|
5818
|
-
}
|
|
5819
|
-
scale || (scale = 1);
|
|
5820
|
-
return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
|
|
5821
|
-
}
|
|
5822
|
-
function closestSegments(a0, a1, b0, b1) {
|
|
5823
|
-
const da = subtract(a1, a0), db = subtract(b1, b0);
|
|
5824
|
-
const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
|
|
5825
|
-
const ua = da.map((value) => lengthA ? value / lengthA : 0);
|
|
5826
|
-
const ub = db.map((value) => lengthB ? value / lengthB : 0);
|
|
5827
|
-
let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
|
|
5828
|
-
const consider = (fractionA, fractionB) => {
|
|
5829
|
-
const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
|
|
5830
|
-
if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
|
|
5831
|
-
best = { distance, fractionA, fractionB };
|
|
5832
|
-
};
|
|
5833
|
-
for (const t of [0, 1]) {
|
|
5834
|
-
consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
|
|
5835
|
-
consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
|
|
5836
|
-
}
|
|
5837
|
-
const normal = cross3(ua, ub);
|
|
5838
|
-
const sine = Math.hypot(...normal);
|
|
5839
|
-
if (sine > 0) {
|
|
5840
|
-
const unit = normal.map((value) => value / sine);
|
|
5841
|
-
const offset = subtract(b0, a0);
|
|
5842
|
-
const fractionA = dot3(cross3(offset, ub), unit) / sine / lengthA;
|
|
5843
|
-
const fractionB = dot3(cross3(offset, ua), unit) / sine / lengthB;
|
|
5844
|
-
if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
|
|
5845
|
-
consider(fractionA, fractionB);
|
|
5846
|
-
}
|
|
5847
|
-
return best;
|
|
5848
|
-
}
|
|
5849
|
-
function subtract(a, b) {
|
|
5850
|
-
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
5851
|
-
}
|
|
5852
|
-
function interpolatePoint(a, b, t) {
|
|
5853
|
-
return [0, 1, 2].map((axis) => Math.max(Math.min(a[axis], b[axis]), Math.min(Math.max(a[axis], b[axis]), (1 - t) * a[axis] + t * b[axis])));
|
|
5854
|
-
}
|
|
5855
|
-
function clampUnit(value) {
|
|
5856
|
-
return Math.max(0, Math.min(1, value));
|
|
5857
|
-
}
|
|
5858
|
-
function finiteDistance(a, b) {
|
|
5859
|
-
const distance = Math.hypot(...subtract(a, b));
|
|
5860
|
-
if (!Number.isFinite(distance))
|
|
5861
|
-
throw new RangeError("Closest-point distance overflow");
|
|
5862
|
-
return distance;
|
|
5863
|
-
}
|
|
5864
|
-
function dot3(a, b) {
|
|
5865
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
5866
|
-
}
|
|
5867
|
-
function cross3(a, b) {
|
|
5868
|
-
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
5869
|
-
}
|
|
5870
|
-
|
|
5871
6536
|
// dist/culling/oriented-box-2d.js
|
|
5872
6537
|
function intersectOrientedBoxes2D(first, second, epsilon = 0) {
|
|
5873
6538
|
validateBox(first);
|
|
@@ -5919,64 +6584,177 @@ function validateVector(vector) {
|
|
|
5919
6584
|
}
|
|
5920
6585
|
|
|
5921
6586
|
// dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
|
|
5922
|
-
var
|
|
6587
|
+
var import_core22 = require("@math.gl/core");
|
|
5923
6588
|
function getOrientedBoundingBoxQuaternion(box) {
|
|
5924
|
-
const x = new
|
|
5925
|
-
const y = new
|
|
5926
|
-
const z = new
|
|
5927
|
-
return new
|
|
6589
|
+
const x = new import_core22.Vector3(box.halfAxes.getColumn(0)).normalize();
|
|
6590
|
+
const y = new import_core22.Vector3(box.halfAxes.getColumn(1)).normalize();
|
|
6591
|
+
const z = new import_core22.Vector3(box.halfAxes.getColumn(2)).normalize();
|
|
6592
|
+
return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z]));
|
|
5928
6593
|
}
|
|
5929
6594
|
function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
|
|
5930
|
-
const halfAxes = new
|
|
6595
|
+
const halfAxes = new import_core22.Matrix3().fromQuaternion(quaternion);
|
|
5931
6596
|
for (let column = 0; column < 3; column++) {
|
|
5932
6597
|
for (let row = 0; row < 3; row++)
|
|
5933
6598
|
halfAxes[column * 3 + row] *= halfSize[column];
|
|
5934
6599
|
}
|
|
5935
|
-
result.center = new
|
|
6600
|
+
result.center = new import_core22.Vector3(center);
|
|
5936
6601
|
result.halfAxes = halfAxes;
|
|
5937
6602
|
return result;
|
|
5938
6603
|
}
|
|
5939
6604
|
|
|
6605
|
+
// dist/culling/bounds.js
|
|
6606
|
+
function dimension(bounds) {
|
|
6607
|
+
const n = bounds[0].length;
|
|
6608
|
+
if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
|
|
6609
|
+
throw new RangeError("Expected 2D or 3D bounds without NaN");
|
|
6610
|
+
}
|
|
6611
|
+
const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
6612
|
+
if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
|
|
6613
|
+
throw new RangeError("Nonempty bounds must be finite");
|
|
6614
|
+
}
|
|
6615
|
+
return n;
|
|
6616
|
+
}
|
|
6617
|
+
function pair(a, b) {
|
|
6618
|
+
const n = dimension(a);
|
|
6619
|
+
if (dimension(b) !== n)
|
|
6620
|
+
throw new RangeError("Bounds dimensions must match");
|
|
6621
|
+
return n;
|
|
6622
|
+
}
|
|
6623
|
+
function point(p, n) {
|
|
6624
|
+
if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
|
|
6625
|
+
throw new RangeError("Expected a finite point of matching dimension");
|
|
6626
|
+
}
|
|
6627
|
+
function createEmptyBounds(dimension2) {
|
|
6628
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
6629
|
+
throw new RangeError("Expected dimension 2 or 3");
|
|
6630
|
+
return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
|
|
6631
|
+
}
|
|
6632
|
+
function isEmptyBounds(bounds) {
|
|
6633
|
+
return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
6634
|
+
}
|
|
6635
|
+
function boundsContainsPoint(bounds, p) {
|
|
6636
|
+
point(p, dimension(bounds));
|
|
6637
|
+
return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
|
|
6638
|
+
}
|
|
6639
|
+
function boundsContainsBounds(a, b) {
|
|
6640
|
+
const n = pair(a, b);
|
|
6641
|
+
return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
|
|
6642
|
+
}
|
|
6643
|
+
function boundsIntersect(a, b) {
|
|
6644
|
+
const n = pair(a, b);
|
|
6645
|
+
return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
|
|
6646
|
+
}
|
|
6647
|
+
function store(values, out = createEmptyBounds(values[0].length)) {
|
|
6648
|
+
if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
|
|
6649
|
+
throw new RangeError("Output bounds dimensions must match");
|
|
6650
|
+
}
|
|
6651
|
+
for (let j = 0; j < 2; j++)
|
|
6652
|
+
for (let i = 0; i < values[j].length; i++)
|
|
6653
|
+
out[j][i] = values[j][i];
|
|
6654
|
+
return out;
|
|
6655
|
+
}
|
|
6656
|
+
function unionBounds(a, b, out) {
|
|
6657
|
+
const n = pair(a, b);
|
|
6658
|
+
const values = createEmptyBounds(n);
|
|
6659
|
+
const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
|
|
6660
|
+
for (let i = 0; i < n; i++) {
|
|
6661
|
+
values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
|
|
6662
|
+
values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
|
|
6663
|
+
}
|
|
6664
|
+
return store(values, out);
|
|
6665
|
+
}
|
|
6666
|
+
function intersectBounds(a, b, out) {
|
|
6667
|
+
const n = pair(a, b), values = createEmptyBounds(n);
|
|
6668
|
+
if (boundsIntersect(a, b))
|
|
6669
|
+
for (let i = 0; i < n; i++) {
|
|
6670
|
+
values[0][i] = Math.max(a[0][i], b[0][i]);
|
|
6671
|
+
values[1][i] = Math.min(a[1][i], b[1][i]);
|
|
6672
|
+
}
|
|
6673
|
+
return store(values, out);
|
|
6674
|
+
}
|
|
6675
|
+
function expandBoundsByPoint(bounds, p, out) {
|
|
6676
|
+
point(p, dimension(bounds));
|
|
6677
|
+
return unionBounds(bounds, [p, p], out);
|
|
6678
|
+
}
|
|
6679
|
+
function expandBounds(bounds, padding, out) {
|
|
6680
|
+
if (!Number.isFinite(padding))
|
|
6681
|
+
throw new RangeError("Padding must be finite");
|
|
6682
|
+
const n = dimension(bounds), values = createEmptyBounds(n);
|
|
6683
|
+
if (!isEmptyBounds(bounds))
|
|
6684
|
+
for (let i = 0; i < n; i++) {
|
|
6685
|
+
values[0][i] = bounds[0][i] - padding;
|
|
6686
|
+
values[1][i] = bounds[1][i] + padding;
|
|
6687
|
+
}
|
|
6688
|
+
return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
|
|
6689
|
+
}
|
|
6690
|
+
function clampPointToBounds(bounds, p, out = new Array(p.length)) {
|
|
6691
|
+
point(p, dimension(bounds));
|
|
6692
|
+
if (out.length < p.length)
|
|
6693
|
+
throw new RangeError("Result buffer is too short");
|
|
6694
|
+
if (isEmptyBounds(bounds))
|
|
6695
|
+
return null;
|
|
6696
|
+
const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
|
|
6697
|
+
for (let i = 0; i < result.length; i++)
|
|
6698
|
+
out[i] = result[i];
|
|
6699
|
+
return out;
|
|
6700
|
+
}
|
|
6701
|
+
function radius(r) {
|
|
6702
|
+
if (!Number.isFinite(r) || r < 0)
|
|
6703
|
+
throw new RangeError("Radius must be finite and nonnegative");
|
|
6704
|
+
}
|
|
6705
|
+
function spheresIntersect(a, ar, b, br) {
|
|
6706
|
+
point(a, 3);
|
|
6707
|
+
point(b, 3);
|
|
6708
|
+
radius(ar);
|
|
6709
|
+
radius(br);
|
|
6710
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
|
|
6711
|
+
}
|
|
6712
|
+
function boundsIntersectSphere(bounds, center, r) {
|
|
6713
|
+
radius(r);
|
|
6714
|
+
const closest = clampPointToBounds(bounds, center);
|
|
6715
|
+
return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
|
|
6716
|
+
}
|
|
6717
|
+
|
|
5940
6718
|
// dist/spatial-index/box-index.js
|
|
5941
6719
|
var BoxIndex = class {
|
|
5942
6720
|
constructor(options) {
|
|
5943
|
-
const { dimension, bounds, leafSize = 8 } = options;
|
|
5944
|
-
if (
|
|
6721
|
+
const { dimension: dimension2, bounds, leafSize = 8 } = options;
|
|
6722
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
5945
6723
|
throw new RangeError("Index dimension must be 2 or 3");
|
|
5946
6724
|
if (!Number.isSafeInteger(leafSize) || leafSize < 1)
|
|
5947
6725
|
throw new RangeError("leafSize must be positive");
|
|
5948
|
-
if (bounds.length % (
|
|
6726
|
+
if (bounds.length % (dimension2 * 2))
|
|
5949
6727
|
throw new RangeError("Incomplete bounds record");
|
|
5950
|
-
this.dimension =
|
|
6728
|
+
this.dimension = dimension2;
|
|
5951
6729
|
this.bounds = Float64Array.from(bounds);
|
|
5952
|
-
this.size = bounds.length / (
|
|
6730
|
+
this.size = bounds.length / (dimension2 * 2);
|
|
5953
6731
|
if (this.size > 2147483647)
|
|
5954
6732
|
throw new RangeError("Index exceeds 32-bit capacity");
|
|
5955
|
-
const stride =
|
|
6733
|
+
const stride = dimension2 * 2;
|
|
5956
6734
|
for (let i = 0; i < this.size; i++)
|
|
5957
|
-
this.validateBounds(this.bounds.subarray(i * stride, i * stride +
|
|
6735
|
+
this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension2), this.bounds.subarray(i * stride + dimension2, (i + 1) * stride));
|
|
5958
6736
|
const records = [];
|
|
5959
6737
|
const ids = Array.from({ length: this.size }, (_, i) => i);
|
|
5960
6738
|
const build = (start, end) => {
|
|
5961
6739
|
const node = records.length;
|
|
5962
6740
|
const bound = [
|
|
5963
|
-
...new Array(
|
|
5964
|
-
...new Array(
|
|
6741
|
+
...new Array(dimension2).fill(Infinity),
|
|
6742
|
+
...new Array(dimension2).fill(-Infinity)
|
|
5965
6743
|
];
|
|
5966
6744
|
for (let i = start; i < end; i++)
|
|
5967
|
-
for (let axis = 0; axis <
|
|
6745
|
+
for (let axis = 0; axis < dimension2; axis++) {
|
|
5968
6746
|
bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
|
|
5969
|
-
bound[axis +
|
|
6747
|
+
bound[axis + dimension2] = Math.max(bound[axis + dimension2], this.bounds[ids[i] * stride + axis + dimension2]);
|
|
5970
6748
|
}
|
|
5971
6749
|
const record = { bounds: bound, left: -1, right: -1, start, count: end - start };
|
|
5972
6750
|
records.push(record);
|
|
5973
6751
|
if (end - start > leafSize) {
|
|
5974
6752
|
let axis = 0;
|
|
5975
|
-
for (let i = 1; i <
|
|
5976
|
-
if (bound[i +
|
|
6753
|
+
for (let i = 1; i < dimension2; i++) {
|
|
6754
|
+
if (bound[i + dimension2] - bound[i] > bound[axis + dimension2] - bound[axis])
|
|
5977
6755
|
axis = i;
|
|
5978
6756
|
}
|
|
5979
|
-
const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis +
|
|
6757
|
+
const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension2] / 2;
|
|
5980
6758
|
const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
|
|
5981
6759
|
for (let i = 0; i < sorted.length; i++)
|
|
5982
6760
|
ids[start + i] = sorted[i];
|
|
@@ -6050,11 +6828,11 @@ var BoxIndex = class {
|
|
|
6050
6828
|
return { result: result.sort((a, b) => a - b), complete, work: budget.work };
|
|
6051
6829
|
}
|
|
6052
6830
|
/** Branch-and-bound nearest box, optionally refined against actual geometry. */
|
|
6053
|
-
nearest(
|
|
6054
|
-
return this.nearestQuery(
|
|
6831
|
+
nearest(point2, options = {}) {
|
|
6832
|
+
return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
|
|
6055
6833
|
}
|
|
6056
|
-
nearestQuery(
|
|
6057
|
-
return this.nearestBoxQuery(
|
|
6834
|
+
nearestQuery(point2, options = {}) {
|
|
6835
|
+
return this.nearestBoxQuery(point2, point2, options);
|
|
6058
6836
|
}
|
|
6059
6837
|
/** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
|
|
6060
6838
|
nearestBoxQuery(minimum, maximum, options = {}) {
|
|
@@ -6118,19 +6896,19 @@ var BoxIndex = class {
|
|
|
6118
6896
|
* Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
|
|
6119
6897
|
* Rejected refinements do not clip the ray. Equal distances select the lowest original row.
|
|
6120
6898
|
*/
|
|
6121
|
-
intersectRay(origin,
|
|
6122
|
-
return this.intersectRayQuery(origin,
|
|
6899
|
+
intersectRay(origin, direction2, options = {}) {
|
|
6900
|
+
return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
|
|
6123
6901
|
}
|
|
6124
|
-
intersectRayQuery(origin,
|
|
6902
|
+
intersectRayQuery(origin, direction2, options = {}) {
|
|
6125
6903
|
validateQueryPoint(origin, this.dimension);
|
|
6126
6904
|
const budget = new QueryBudget(options.maxWork);
|
|
6127
|
-
const
|
|
6905
|
+
const unit2 = normalizeQueryDirection(direction2, this.dimension);
|
|
6128
6906
|
let best = options.maxDistance ?? Infinity;
|
|
6129
6907
|
validateQueryDistance(best);
|
|
6130
6908
|
let result = null;
|
|
6131
6909
|
const getEntry = (bounds, index) => {
|
|
6132
6910
|
const offset = index * this.dimension * 2;
|
|
6133
|
-
return intersectRayBounds(origin,
|
|
6911
|
+
return intersectRayBounds(origin, unit2, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
|
|
6134
6912
|
};
|
|
6135
6913
|
const stack = this.size ? [{ index: 0, distance: 0 }] : [];
|
|
6136
6914
|
let complete = true;
|
|
@@ -6183,13 +6961,13 @@ var BoxIndex = class {
|
|
|
6183
6961
|
return { result, complete, work: budget.work };
|
|
6184
6962
|
}
|
|
6185
6963
|
/** Broad-phase ray candidates, sorted by entry distance then original row index. */
|
|
6186
|
-
searchRay(origin,
|
|
6964
|
+
searchRay(origin, direction2, maxDistance = Infinity) {
|
|
6187
6965
|
validateQueryPoint(origin, this.dimension);
|
|
6188
|
-
const
|
|
6966
|
+
const unit2 = normalizeQueryDirection(direction2, this.dimension);
|
|
6189
6967
|
validateQueryDistance(maxDistance);
|
|
6190
6968
|
const entry = (bounds, index) => {
|
|
6191
6969
|
const start = index * this.dimension * 2;
|
|
6192
|
-
return intersectRayBounds(origin,
|
|
6970
|
+
return intersectRayBounds(origin, unit2, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
|
|
6193
6971
|
};
|
|
6194
6972
|
const result = [];
|
|
6195
6973
|
const stack = this.size ? [0] : [];
|
|
@@ -6239,16 +7017,16 @@ var QueryBudget = class {
|
|
|
6239
7017
|
};
|
|
6240
7018
|
var PointIndex = class extends BoxIndex {
|
|
6241
7019
|
constructor(options) {
|
|
6242
|
-
const { positions, dimension, leafSize } = options;
|
|
6243
|
-
if (
|
|
7020
|
+
const { positions, dimension: dimension2, leafSize } = options;
|
|
7021
|
+
if (dimension2 !== 2 && dimension2 !== 3 || positions.length % dimension2) {
|
|
6244
7022
|
throw new RangeError("Invalid point layout");
|
|
6245
7023
|
}
|
|
6246
7024
|
const bounds = new Float64Array(positions.length * 2);
|
|
6247
|
-
for (let i = 0; i < positions.length /
|
|
6248
|
-
for (let axis = 0; axis <
|
|
6249
|
-
bounds[i *
|
|
7025
|
+
for (let i = 0; i < positions.length / dimension2; i++)
|
|
7026
|
+
for (let axis = 0; axis < dimension2; axis++) {
|
|
7027
|
+
bounds[i * dimension2 * 2 + axis] = bounds[i * dimension2 * 2 + axis + dimension2] = positions[i * dimension2 + axis];
|
|
6250
7028
|
}
|
|
6251
|
-
super({ bounds, dimension, leafSize });
|
|
7029
|
+
super({ bounds, dimension: dimension2, leafSize });
|
|
6252
7030
|
}
|
|
6253
7031
|
};
|
|
6254
7032
|
|
|
@@ -6291,20 +7069,20 @@ var TriangleBVH = class {
|
|
|
6291
7069
|
return this.boxes.searchQuery(minimum, maximum, options);
|
|
6292
7070
|
}
|
|
6293
7071
|
/** Nearest accepted exact hit; application rejection never clips away later candidates. */
|
|
6294
|
-
intersectRay(origin,
|
|
6295
|
-
return this.intersectRayQuery(origin,
|
|
7072
|
+
intersectRay(origin, direction2, options = {}) {
|
|
7073
|
+
return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
|
|
6296
7074
|
}
|
|
6297
|
-
intersectRayQuery(origin,
|
|
7075
|
+
intersectRayQuery(origin, direction2, options = {}) {
|
|
6298
7076
|
validateQueryPoint(origin, 3);
|
|
6299
|
-
const
|
|
7077
|
+
const unit2 = normalizeQueryDirection(direction2, 3);
|
|
6300
7078
|
let result = null;
|
|
6301
|
-
const query = this.boxes.intersectRayQuery(origin,
|
|
7079
|
+
const query = this.boxes.intersectRayQuery(origin, direction2, {
|
|
6302
7080
|
maxWork: options.maxWork,
|
|
6303
7081
|
maxDistance: options.maxDistance,
|
|
6304
7082
|
filter: options.filter,
|
|
6305
7083
|
intersectItem: (index, maximum) => {
|
|
6306
7084
|
const [a, b, c] = this.triangle(index);
|
|
6307
|
-
const hit = intersectRayTriangle(origin,
|
|
7085
|
+
const hit = intersectRayTriangle(origin, unit2, a, b, c, {
|
|
6308
7086
|
backfaceCulling: options.backfaceCulling,
|
|
6309
7087
|
maxT: maximum
|
|
6310
7088
|
});
|
|
@@ -6313,9 +7091,9 @@ var TriangleBVH = class {
|
|
|
6313
7091
|
index,
|
|
6314
7092
|
distance: hit.t,
|
|
6315
7093
|
point: [
|
|
6316
|
-
origin[0] + hit.t *
|
|
6317
|
-
origin[1] + hit.t *
|
|
6318
|
-
origin[2] + hit.t *
|
|
7094
|
+
origin[0] + hit.t * unit2[0],
|
|
7095
|
+
origin[1] + hit.t * unit2[1],
|
|
7096
|
+
origin[2] + hit.t * unit2[2]
|
|
6319
7097
|
],
|
|
6320
7098
|
barycentric: hit.barycentric
|
|
6321
7099
|
};
|
|
@@ -6329,16 +7107,16 @@ var TriangleBVH = class {
|
|
|
6329
7107
|
});
|
|
6330
7108
|
return { ...query, result };
|
|
6331
7109
|
}
|
|
6332
|
-
nearest(
|
|
6333
|
-
return this.nearestQuery(
|
|
7110
|
+
nearest(point2, options = {}) {
|
|
7111
|
+
return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
|
|
6334
7112
|
}
|
|
6335
|
-
nearestQuery(
|
|
7113
|
+
nearestQuery(point2, options = {}) {
|
|
6336
7114
|
let candidate = null;
|
|
6337
|
-
const query = this.boxes.nearestQuery(
|
|
7115
|
+
const query = this.boxes.nearestQuery(point2, {
|
|
6338
7116
|
...options,
|
|
6339
7117
|
distanceToItem: (index) => {
|
|
6340
|
-
const closest = getClosestPointOnTriangle(
|
|
6341
|
-
const distance = Math.hypot(
|
|
7118
|
+
const closest = getClosestPointOnTriangle(point2, ...this.triangle(index));
|
|
7119
|
+
const distance = Math.hypot(point2[0] - closest[0], point2[1] - closest[1], point2[2] - closest[2]);
|
|
6342
7120
|
if (!candidate || distance < candidate.distance || distance === candidate.distance && index < candidate.index)
|
|
6343
7121
|
candidate = { index, distance, point: closest };
|
|
6344
7122
|
return distance;
|
|
@@ -6349,15 +7127,15 @@ var TriangleBVH = class {
|
|
|
6349
7127
|
/** All triangle contacts with a closed sphere, sorted by original index (not distance).
|
|
6350
7128
|
* Uses closest points on faces, edges and vertices. No contact manifold reduction.
|
|
6351
7129
|
*/
|
|
6352
|
-
intersectSphere(center,
|
|
7130
|
+
intersectSphere(center, radius2, options = {}) {
|
|
6353
7131
|
validateQueryPoint(center, 3);
|
|
6354
|
-
if (!Number.isFinite(
|
|
7132
|
+
if (!Number.isFinite(radius2) || radius2 < 0)
|
|
6355
7133
|
throw new RangeError("Sphere radius must be finite and nonnegative");
|
|
6356
7134
|
const minimum = [], maximum = [];
|
|
6357
7135
|
for (let axis = 0; axis < 3; axis++) {
|
|
6358
|
-
const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]),
|
|
6359
|
-
minimum.push(center[axis] -
|
|
6360
|
-
maximum.push(center[axis] +
|
|
7136
|
+
const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius2));
|
|
7137
|
+
minimum.push(center[axis] - radius2 - padding);
|
|
7138
|
+
maximum.push(center[axis] + radius2 + padding);
|
|
6361
7139
|
}
|
|
6362
7140
|
const hits = /* @__PURE__ */ new Map();
|
|
6363
7141
|
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
@@ -6365,13 +7143,13 @@ var TriangleBVH = class {
|
|
|
6365
7143
|
filter: (index) => {
|
|
6366
7144
|
if (options.filter && !options.filter(index))
|
|
6367
7145
|
return false;
|
|
6368
|
-
const
|
|
6369
|
-
const distance = Math.hypot(center[0] -
|
|
6370
|
-
if (!
|
|
7146
|
+
const point2 = getClosestPointOnTriangle(center, ...this.triangle(index));
|
|
7147
|
+
const distance = Math.hypot(center[0] - point2[0], center[1] - point2[1], center[2] - point2[2]);
|
|
7148
|
+
if (!point2.every(Number.isFinite) || !Number.isFinite(distance))
|
|
6371
7149
|
throw new RangeError("Sphere query arithmetic overflow");
|
|
6372
|
-
if (distance >
|
|
7150
|
+
if (distance > radius2)
|
|
6373
7151
|
return false;
|
|
6374
|
-
hits.set(index, { index, distance, point });
|
|
7152
|
+
hits.set(index, { index, distance, point: point2 });
|
|
6375
7153
|
return true;
|
|
6376
7154
|
}
|
|
6377
7155
|
});
|
|
@@ -6398,10 +7176,10 @@ var TriangleBVH = class {
|
|
|
6398
7176
|
/** Closed capsule overlap, with one closest pair per accepted triangle.
|
|
6399
7177
|
* A straight translating sphere covers this volume, but segmentFraction is not first-impact time.
|
|
6400
7178
|
*/
|
|
6401
|
-
intersectCapsule(start, end,
|
|
6402
|
-
if (!Number.isFinite(
|
|
7179
|
+
intersectCapsule(start, end, radius2, options = {}) {
|
|
7180
|
+
if (!Number.isFinite(radius2) || radius2 < 0)
|
|
6403
7181
|
throw new RangeError("Capsule radius must be finite and nonnegative");
|
|
6404
|
-
const { minimum, maximum } = segmentBounds(start, end,
|
|
7182
|
+
const { minimum, maximum } = segmentBounds(start, end, radius2);
|
|
6405
7183
|
const hits = /* @__PURE__ */ new Map();
|
|
6406
7184
|
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
6407
7185
|
...options,
|
|
@@ -6409,7 +7187,7 @@ var TriangleBVH = class {
|
|
|
6409
7187
|
if (options.filter && !options.filter(index))
|
|
6410
7188
|
return false;
|
|
6411
7189
|
const closest = this.segmentClosest(index, start, end);
|
|
6412
|
-
if (closest.distance >
|
|
7190
|
+
if (closest.distance > radius2)
|
|
6413
7191
|
return false;
|
|
6414
7192
|
hits.set(index, closest);
|
|
6415
7193
|
return true;
|
|
@@ -6435,7 +7213,7 @@ var TriangleBVH = class {
|
|
|
6435
7213
|
return [vertex2(0), vertex2(1), vertex2(2)];
|
|
6436
7214
|
}
|
|
6437
7215
|
};
|
|
6438
|
-
function segmentBounds(start, end,
|
|
7216
|
+
function segmentBounds(start, end, radius2) {
|
|
6439
7217
|
validateQueryPoint(start, 3);
|
|
6440
7218
|
validateQueryPoint(end, 3);
|
|
6441
7219
|
for (let axis = 0; axis < 3; axis++)
|
|
@@ -6443,10 +7221,286 @@ function segmentBounds(start, end, radius) {
|
|
|
6443
7221
|
throw new RangeError("Segment coordinate span overflow");
|
|
6444
7222
|
const minimum = [], maximum = [];
|
|
6445
7223
|
for (let axis = 0; axis < 3; axis++) {
|
|
6446
|
-
const padding =
|
|
7224
|
+
const padding = radius2 === void 0 ? 0 : radius2 + 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(start[axis]), Math.abs(end[axis]), radius2));
|
|
6447
7225
|
minimum.push(Math.min(start[axis], end[axis]) - padding);
|
|
6448
7226
|
maximum.push(Math.max(start[axis], end[axis]) + padding);
|
|
6449
7227
|
}
|
|
6450
7228
|
return { minimum, maximum };
|
|
6451
7229
|
}
|
|
7230
|
+
|
|
7231
|
+
// dist/utils/compose-attribute-provenance.js
|
|
7232
|
+
function composeAttributeProvenance(parent, child, options = {}) {
|
|
7233
|
+
const limit = options.maxVertices ?? 65536;
|
|
7234
|
+
if (!Number.isSafeInteger(limit) || limit < 0 || limit > 4294967295)
|
|
7235
|
+
throw new RangeError("Invalid provenance vertex limit");
|
|
7236
|
+
validate(parent);
|
|
7237
|
+
validate(child, parent.sourceVertexIndices.length / 3);
|
|
7238
|
+
if (child.sourceVertexIndices.length / 3 > limit)
|
|
7239
|
+
throw new RangeError("Provenance composition exceeded maxVertices");
|
|
7240
|
+
const indices = new Uint32Array(child.sourceVertexIndices.length);
|
|
7241
|
+
const weights = new Float64Array(indices.length);
|
|
7242
|
+
for (let vertex2 = 0; vertex2 < indices.length / 3; vertex2++) {
|
|
7243
|
+
const contributors = /* @__PURE__ */ new Map();
|
|
7244
|
+
for (let j = 0; j < 3; j++) {
|
|
7245
|
+
const weight = child.sourceVertexWeights[3 * vertex2 + j];
|
|
7246
|
+
if (!weight)
|
|
7247
|
+
continue;
|
|
7248
|
+
const intermediate = child.sourceVertexIndices[3 * vertex2 + j];
|
|
7249
|
+
for (let k = 0; k < 3; k++) {
|
|
7250
|
+
const w = weight * parent.sourceVertexWeights[3 * intermediate + k];
|
|
7251
|
+
if (!w)
|
|
7252
|
+
continue;
|
|
7253
|
+
const index = parent.sourceVertexIndices[3 * intermediate + k];
|
|
7254
|
+
contributors.set(index, (contributors.get(index) ?? 0) + w);
|
|
7255
|
+
}
|
|
7256
|
+
}
|
|
7257
|
+
if (contributors.size > 3)
|
|
7258
|
+
throw new RangeError("Composed vertex spans multiple source triangles");
|
|
7259
|
+
const sum = Array.from(contributors.values()).reduce((a, b) => a + b, 0);
|
|
7260
|
+
let slot = 3 * vertex2;
|
|
7261
|
+
for (const [index, weight] of contributors) {
|
|
7262
|
+
indices[slot] = index;
|
|
7263
|
+
weights[slot++] = weight / sum;
|
|
7264
|
+
}
|
|
7265
|
+
}
|
|
7266
|
+
return { sourceVertexIndices: indices, sourceVertexWeights: weights };
|
|
7267
|
+
}
|
|
7268
|
+
function validate(p, count = 4294967296) {
|
|
7269
|
+
if (!Number.isSafeInteger(p.sourceVertexIndices.length) || p.sourceVertexIndices.length < 0 || p.sourceVertexIndices.length % 3 || p.sourceVertexIndices.length !== p.sourceVertexWeights.length)
|
|
7270
|
+
throw new RangeError("Invalid provenance lengths");
|
|
7271
|
+
for (let i = 0; i < p.sourceVertexIndices.length; i += 3) {
|
|
7272
|
+
let sum = 0;
|
|
7273
|
+
for (let j = 0; j < 3; j++) {
|
|
7274
|
+
const w = p.sourceVertexWeights[i + j], index = p.sourceVertexIndices[i + j];
|
|
7275
|
+
if (!Number.isFinite(w) || w < 0 || w > 1 || w > 0 && (!Number.isSafeInteger(index) || index < 0 || index >= count))
|
|
7276
|
+
throw new RangeError("Invalid provenance contributor");
|
|
7277
|
+
sum += w;
|
|
7278
|
+
}
|
|
7279
|
+
if (Math.abs(sum - 1) > 1e-10)
|
|
7280
|
+
throw new RangeError("Provenance weights must sum to one");
|
|
7281
|
+
}
|
|
7282
|
+
}
|
|
7283
|
+
|
|
7284
|
+
// dist/utils/qualify-surface-transition.js
|
|
7285
|
+
function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
|
|
7286
|
+
const from = Array.from(mesh.positions), to = Array.from(targetPositions), indices = Array.from(mesh.indices), count = from.length / 3, maxChecks = options.maxChecks ?? 1e6;
|
|
7287
|
+
if (!from.length || from.length % 3 || to.length !== from.length || !indices.length || indices.length % 3 || !from.every(Number.isFinite) || !to.every(Number.isFinite) || !indices.every((i) => Number.isSafeInteger(i) && i >= 0 && i < count) || !Number.isSafeInteger(maxChecks) || maxChecks < 0)
|
|
7288
|
+
throw new RangeError("Invalid surface transition mesh or budget");
|
|
7289
|
+
let scale = 0;
|
|
7290
|
+
for (const positions of [from, to])
|
|
7291
|
+
for (let i = 0; i < indices.length; i += 3)
|
|
7292
|
+
for (let j = 0; j < 3; j++) {
|
|
7293
|
+
const a = indices[i + j] * 3, b = indices[i + (j + 1) % 3] * 3;
|
|
7294
|
+
scale = Math.max(scale, Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1]));
|
|
7295
|
+
}
|
|
7296
|
+
const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
|
|
7297
|
+
if (!Number.isFinite(margin) || margin <= 0)
|
|
7298
|
+
throw new RangeError("Expected positive finite area margin");
|
|
7299
|
+
let checks = 0;
|
|
7300
|
+
const tick = () => {
|
|
7301
|
+
if (++checks > maxChecks)
|
|
7302
|
+
throw new RangeError("Surface qualification exceeded maxChecks");
|
|
7303
|
+
};
|
|
7304
|
+
const edges = /* @__PURE__ */ new Map(), used = new Set(indices);
|
|
7305
|
+
let minimum = Infinity;
|
|
7306
|
+
const orientation = (a, b, c, t) => {
|
|
7307
|
+
const edge = (v2, k) => (from[3 * v2 + k] - from[3 * a + k]) * (1 - t) + (to[3 * v2 + k] - to[3 * a + k]) * t;
|
|
7308
|
+
return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
|
|
7309
|
+
};
|
|
7310
|
+
const minimumOrientation = (a, b, c) => {
|
|
7311
|
+
tick();
|
|
7312
|
+
return quadraticMinimum((t) => orientation(a, b, c, t));
|
|
7313
|
+
};
|
|
7314
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
7315
|
+
const tri = indices.slice(i, i + 3);
|
|
7316
|
+
const area2 = minimumOrientation(tri[0], tri[1], tri[2]);
|
|
7317
|
+
if (area2 < margin)
|
|
7318
|
+
throw new RangeError("Triangle collapses or reverses during transition");
|
|
7319
|
+
minimum = Math.min(minimum, area2);
|
|
7320
|
+
for (let j = 0; j < 3; j++) {
|
|
7321
|
+
const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
|
|
7322
|
+
if (edge) {
|
|
7323
|
+
if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
|
|
7324
|
+
throw new RangeError("Expected oriented manifold edges");
|
|
7325
|
+
edge.faces++;
|
|
7326
|
+
} else
|
|
7327
|
+
edges.set(key, { a, b, faces: 1 });
|
|
7328
|
+
}
|
|
7329
|
+
}
|
|
7330
|
+
const next = /* @__PURE__ */ new Map();
|
|
7331
|
+
for (const edge of edges.values())
|
|
7332
|
+
if (edge.faces === 1) {
|
|
7333
|
+
if (next.has(edge.a))
|
|
7334
|
+
throw new RangeError("Nonmanifold boundary");
|
|
7335
|
+
next.set(edge.a, edge.b);
|
|
7336
|
+
}
|
|
7337
|
+
if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
|
|
7338
|
+
throw new RangeError("Expected a triangulated disk without unused vertices");
|
|
7339
|
+
const start = next.keys().next().value, boundary = [];
|
|
7340
|
+
const visitedBoundary = /* @__PURE__ */ new Set();
|
|
7341
|
+
let v = start;
|
|
7342
|
+
do {
|
|
7343
|
+
if (visitedBoundary.has(v) || !next.has(v))
|
|
7344
|
+
throw new RangeError("Expected one boundary cycle");
|
|
7345
|
+
visitedBoundary.add(v);
|
|
7346
|
+
boundary.push(v);
|
|
7347
|
+
v = next.get(v);
|
|
7348
|
+
} while (v !== start);
|
|
7349
|
+
if (boundary.length !== next.size)
|
|
7350
|
+
throw new RangeError("Multiple boundary cycles");
|
|
7351
|
+
for (let i = 0; i < boundary.length; i++) {
|
|
7352
|
+
const a = boundary[i], b = boundary[(i + 1) % boundary.length];
|
|
7353
|
+
for (let j = i + 1; j < boundary.length; j++) {
|
|
7354
|
+
tick();
|
|
7355
|
+
const c = boundary[j];
|
|
7356
|
+
const separation = quadraticMinimum((t) => {
|
|
7357
|
+
const dx = (from[3 * c] - from[3 * a]) * (1 - t) + (to[3 * c] - to[3 * a]) * t, dy = (from[3 * c + 1] - from[3 * a + 1]) * (1 - t) + (to[3 * c + 1] - to[3 * a + 1]) * t;
|
|
7358
|
+
return dx * dx + dy * dy;
|
|
7359
|
+
});
|
|
7360
|
+
if (separation < margin)
|
|
7361
|
+
throw new RangeError("Boundary vertices meet during transition");
|
|
7362
|
+
}
|
|
7363
|
+
for (const c of boundary)
|
|
7364
|
+
if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
|
|
7365
|
+
throw new RangeError("Boundary is not convex throughout transition");
|
|
7366
|
+
}
|
|
7367
|
+
const neighbors = Array.from({ length: count }, () => []);
|
|
7368
|
+
for (const { a, b } of edges.values()) {
|
|
7369
|
+
neighbors[a].push(b);
|
|
7370
|
+
neighbors[b].push(a);
|
|
7371
|
+
}
|
|
7372
|
+
const seen = /* @__PURE__ */ new Set([start]), queue = [start];
|
|
7373
|
+
for (let i = 0; i < queue.length; i++)
|
|
7374
|
+
for (const n of neighbors[queue[i]])
|
|
7375
|
+
if (!seen.has(n)) {
|
|
7376
|
+
seen.add(n);
|
|
7377
|
+
queue.push(n);
|
|
7378
|
+
}
|
|
7379
|
+
if (seen.size !== count)
|
|
7380
|
+
throw new RangeError("Disconnected surface mesh");
|
|
7381
|
+
return {
|
|
7382
|
+
scope: "convex-xy-disk-linear",
|
|
7383
|
+
minimumProjectedDoubleArea: minimum,
|
|
7384
|
+
boundary: new Uint32Array(boundary)
|
|
7385
|
+
};
|
|
7386
|
+
}
|
|
7387
|
+
function quadraticMinimum(value) {
|
|
7388
|
+
const f = value(0), g = value(1), h = value(0.5), a = 2 * (f + g - 2 * h), b = g - f - a;
|
|
7389
|
+
if (![f, g, h, a, b].every(Number.isFinite))
|
|
7390
|
+
throw new RangeError("Nonfinite surface orientation polynomial");
|
|
7391
|
+
const t = a > 0 ? -b / (2 * a) : -1;
|
|
7392
|
+
const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
|
|
7393
|
+
if (!Number.isFinite(result))
|
|
7394
|
+
throw new RangeError("Nonfinite surface orientation");
|
|
7395
|
+
return result;
|
|
7396
|
+
}
|
|
7397
|
+
|
|
7398
|
+
// dist/utils/project-bounds.js
|
|
7399
|
+
function projectBounds(sourceBounds, options) {
|
|
7400
|
+
const [minimum, maximum] = sourceBounds;
|
|
7401
|
+
const size = minimum.length;
|
|
7402
|
+
const { transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz } = options;
|
|
7403
|
+
if (size !== 2 && size !== 3 || maximum.length !== size || targetSize !== 2 && targetSize !== 3) {
|
|
7404
|
+
throw new RangeError("Bounds and target dimension must be 2 or 3");
|
|
7405
|
+
}
|
|
7406
|
+
if (!Number.isSafeInteger(subdivisions) || subdivisions < 1 || !Number.isSafeInteger(maxSamples) || maxSamples < 1) {
|
|
7407
|
+
throw new RangeError("Subdivision and sample budgets must be positive safe integers");
|
|
7408
|
+
}
|
|
7409
|
+
if (lipschitz && (lipschitz.length !== targetSize || !Array.from(lipschitz).every((value) => Number.isFinite(value) && value >= 0))) {
|
|
7410
|
+
throw new RangeError("Lipschitz constants must be finite, nonnegative and match target size");
|
|
7411
|
+
}
|
|
7412
|
+
const widths = [];
|
|
7413
|
+
const counts = [];
|
|
7414
|
+
let count = 1;
|
|
7415
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7416
|
+
const width = maximum[axis] - minimum[axis];
|
|
7417
|
+
if (!Number.isFinite(minimum[axis]) || !Number.isFinite(maximum[axis]) || !Number.isFinite(width) || width < 0) {
|
|
7418
|
+
throw new RangeError("Source bounds must have finite ordered coordinates and extents");
|
|
7419
|
+
}
|
|
7420
|
+
widths.push(width);
|
|
7421
|
+
counts.push(width === 0 ? 1 : subdivisions + 1);
|
|
7422
|
+
count *= counts[axis];
|
|
7423
|
+
if (!Number.isSafeInteger(count) || count > maxSamples) {
|
|
7424
|
+
throw new RangeError("Projected bounds exceed the sample budget");
|
|
7425
|
+
}
|
|
7426
|
+
}
|
|
7427
|
+
const lower = new Array(targetSize).fill(Infinity);
|
|
7428
|
+
const upper = new Array(targetSize).fill(-Infinity);
|
|
7429
|
+
for (let index = 0; index < count; index++) {
|
|
7430
|
+
let remaining = index;
|
|
7431
|
+
const source = [];
|
|
7432
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7433
|
+
const step = remaining % counts[axis];
|
|
7434
|
+
remaining = Math.floor(remaining / counts[axis]);
|
|
7435
|
+
source.push(step === 0 ? minimum[axis] : step === subdivisions ? maximum[axis] : minimum[axis] + widths[axis] * (step / subdivisions));
|
|
7436
|
+
}
|
|
7437
|
+
const projected = transform(source);
|
|
7438
|
+
if (!projected || projected.length < targetSize) {
|
|
7439
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7440
|
+
}
|
|
7441
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7442
|
+
if (!Number.isFinite(projected[axis]))
|
|
7443
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7444
|
+
lower[axis] = Math.min(lower[axis], projected[axis]);
|
|
7445
|
+
upper[axis] = Math.max(upper[axis], projected[axis]);
|
|
7446
|
+
}
|
|
7447
|
+
}
|
|
7448
|
+
if (lipschitz) {
|
|
7449
|
+
const radius2 = Math.hypot(...widths.map((width, axis) => width / subdivisions / 2 + 4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))));
|
|
7450
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7451
|
+
const displacement = lipschitz[axis] * radius2;
|
|
7452
|
+
const roundoff = 8 * Number.EPSILON * Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
|
|
7453
|
+
lower[axis] -= displacement + roundoff;
|
|
7454
|
+
upper[axis] += displacement + roundoff;
|
|
7455
|
+
if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
|
|
7456
|
+
return { status: "invalid", bounds: null, sampleCount: count };
|
|
7457
|
+
}
|
|
7458
|
+
}
|
|
7459
|
+
}
|
|
7460
|
+
return {
|
|
7461
|
+
status: lipschitz ? "conservative" : "sampled",
|
|
7462
|
+
bounds: [lower, upper],
|
|
7463
|
+
sampleCount: count
|
|
7464
|
+
};
|
|
7465
|
+
}
|
|
7466
|
+
|
|
7467
|
+
// dist/utils/project-texture-coordinates.js
|
|
7468
|
+
function projectTextureCoordinates(positions, options) {
|
|
7469
|
+
const { transform, bounds, size = 3, origin = "top-left" } = options;
|
|
7470
|
+
if (size !== 2 && size !== 3)
|
|
7471
|
+
throw new RangeError("Source size must be 2 or 3");
|
|
7472
|
+
if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
|
|
7473
|
+
throw new RangeError("Positions must contain complete packed vertices");
|
|
7474
|
+
}
|
|
7475
|
+
if (origin !== "top-left" && origin !== "bottom-left") {
|
|
7476
|
+
throw new RangeError("Invalid texture origin");
|
|
7477
|
+
}
|
|
7478
|
+
if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
|
|
7479
|
+
throw new RangeError("Image bounds must contain four finite values");
|
|
7480
|
+
}
|
|
7481
|
+
const [left, bottom, right, top] = bounds;
|
|
7482
|
+
const width = right - left;
|
|
7483
|
+
const height = top - bottom;
|
|
7484
|
+
if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
7485
|
+
throw new RangeError("Image bounds must have finite positive extents");
|
|
7486
|
+
}
|
|
7487
|
+
const count = positions.length / size;
|
|
7488
|
+
const result = new Float64Array(count * 2);
|
|
7489
|
+
for (let index = 0; index < count; index++) {
|
|
7490
|
+
const source = Array.from({ length: size }, (_, axis) => positions[index * size + axis]);
|
|
7491
|
+
if (!source.every(Number.isFinite))
|
|
7492
|
+
throw new RangeError(`Invalid source vertex ${index}`);
|
|
7493
|
+
const projected = transform(source);
|
|
7494
|
+
if (!projected || projected.length < 2 || !Number.isFinite(projected[0]) || !Number.isFinite(projected[1])) {
|
|
7495
|
+
throw new RangeError(`Invalid projected vertex ${index}`);
|
|
7496
|
+
}
|
|
7497
|
+
const u = (projected[0] - left) / width;
|
|
7498
|
+
const v = origin === "top-left" ? (top - projected[1]) / height : (projected[1] - bottom) / height;
|
|
7499
|
+
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
7500
|
+
throw new RangeError(`Invalid UV at vertex ${index}`);
|
|
7501
|
+
result[index * 2] = u;
|
|
7502
|
+
result[index * 2 + 1] = v;
|
|
7503
|
+
}
|
|
7504
|
+
return result;
|
|
7505
|
+
}
|
|
6452
7506
|
//# sourceMappingURL=index.cjs.map
|