@math.gl/geometry 5.0.0-beta.4 → 5.0.0-beta.6
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 +917 -514
- package/dist/culling/index.cjs.map +3 -3
- package/dist/culling/index.d.ts +5 -1
- package/dist/culling/index.d.ts.map +1 -1
- package/dist/culling/index.js +3 -0
- package/dist/culling/index.js.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/culling/lib/culling-volume.d.ts +3 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -1
- package/dist/culling/lib/culling-volume.js +7 -0
- package/dist/culling/lib/culling-volume.js.map +1 -1
- package/dist/culling/lib/ray.d.ts +5 -0
- package/dist/culling/lib/ray.d.ts.map +1 -1
- package/dist/culling/lib/ray.js +21 -0
- package/dist/culling/lib/ray.js.map +1 -1
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/index.d.ts +4 -0
- package/dist/curves/index.d.ts.map +1 -1
- package/dist/curves/index.js +2 -0
- package/dist/curves/index.js.map +1 -1
- package/dist/curves/parallel-transport.d.ts +12 -0
- package/dist/curves/parallel-transport.d.ts.map +1 -0
- package/dist/curves/parallel-transport.js +83 -0
- package/dist/curves/parallel-transport.js.map +1 -0
- package/dist/index.cjs +1336 -699
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/lighting/index.cjs +175 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +5 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lighting-types.d.ts +16 -0
- package/dist/lighting/lighting-types.d.ts.map +1 -0
- package/dist/lighting/lighting-types.js +5 -0
- package/dist/lighting/lighting-types.js.map +1 -0
- package/dist/lighting/photometry.d.ts +36 -0
- package/dist/lighting/photometry.d.ts.map +1 -0
- package/dist/lighting/photometry.js +181 -0
- package/dist/lighting/photometry.js.map +1 -0
- package/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/package.json +15 -3
- package/src/color/color-lut-types.ts +19 -0
- package/src/color/index.ts +6 -0
- package/src/color/sample-lut.ts +175 -0
- package/src/culling/bounds.ts +152 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +37 -1
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
- package/src/culling/lib/culling-volume.ts +9 -1
- package/src/culling/lib/ray.ts +21 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/index.ts +4 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/index.ts +44 -0
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
package/dist/index.cjs
CHANGED
|
@@ -64,36 +64,58 @@ __export(index_exports, {
|
|
|
64
64
|
TruncatedConeGeometry: () => TruncatedConeGeometry,
|
|
65
65
|
_PerspectiveFrustum: () => PerspectiveFrustum,
|
|
66
66
|
_PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
|
|
67
|
+
boundsContainsBounds: () => boundsContainsBounds,
|
|
68
|
+
boundsContainsPoint: () => boundsContainsPoint,
|
|
69
|
+
boundsIntersect: () => boundsIntersect,
|
|
70
|
+
boundsIntersectSphere: () => boundsIntersectSphere,
|
|
71
|
+
clampPointToBounds: () => clampPointToBounds,
|
|
67
72
|
clipPolygon: () => clipPolygon,
|
|
68
73
|
clipPolyline: () => clipPolyline,
|
|
69
74
|
clipTriangleMesh: () => clipTriangleMesh,
|
|
70
75
|
composeAttributeProvenance: () => composeAttributeProvenance,
|
|
71
76
|
compressTextureCoordinates: () => compressTextureCoordinates,
|
|
72
77
|
computeEigenDecomposition: () => computeEigenDecomposition,
|
|
78
|
+
computeParallelTransportFrames: () => computeParallelTransportFrames,
|
|
73
79
|
computeVertexNormals: () => computeVertexNormals,
|
|
74
80
|
concatTypedArrays: () => concatTypedArrays,
|
|
81
|
+
createEmptyBounds: () => createEmptyBounds,
|
|
75
82
|
cutPolygonByGrid: () => cutPolygonByGrid,
|
|
76
83
|
cutPolygonByMercatorBounds: () => cutPolygonByMercatorBounds,
|
|
77
84
|
cutPolylineByGrid: () => cutPolylineByGrid,
|
|
78
85
|
cutPolylineByMercatorBounds: () => cutPolylineByMercatorBounds,
|
|
79
86
|
decodeRGB565: () => decodeRGB565,
|
|
80
87
|
decompressTextureCoordinates: () => decompressTextureCoordinates,
|
|
88
|
+
distanceToRay: () => distanceToRay,
|
|
81
89
|
earcut: () => earcut,
|
|
82
90
|
emod: () => emod,
|
|
83
91
|
encodeRGB565: () => encodeRGB565,
|
|
92
|
+
expandBounds: () => expandBounds,
|
|
93
|
+
expandBoundsByPoint: () => expandBoundsByPoint,
|
|
94
|
+
extractFrustumPlanes: () => extractFrustumPlanes,
|
|
84
95
|
forEachSegmentInPolygon: () => forEachSegmentInPolygon,
|
|
96
|
+
getClosestPointOnRay: () => getClosestPointOnRay,
|
|
85
97
|
getClosestPointOnTriangle: () => getClosestPointOnTriangle,
|
|
86
98
|
getClosestPointsOnSegments: () => getClosestPointsOnSegments,
|
|
99
|
+
getClosestPointsRaySegment: () => getClosestPointsRaySegment,
|
|
87
100
|
getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
|
|
88
101
|
getDegenerateTriangles: () => getDegenerateTriangles,
|
|
89
102
|
getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
|
|
90
103
|
getPolygonSignedArea: () => getPolygonSignedArea,
|
|
91
104
|
getPolygonWindingDirection: () => getPolygonWindingDirection,
|
|
105
|
+
getRayPoint: () => getRayPoint,
|
|
106
|
+
getTriangleArea: () => getTriangleArea,
|
|
107
|
+
getTriangleBarycentric: () => getTriangleBarycentric,
|
|
108
|
+
getTriangleNormal: () => getTriangleNormal,
|
|
92
109
|
interpolatePackedAttributes: () => interpolatePackedAttributes,
|
|
110
|
+
interpolateTriangleAttribute: () => interpolateTriangleAttribute,
|
|
111
|
+
intersectBounds: () => intersectBounds,
|
|
93
112
|
intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
|
|
113
|
+
intersectPlaneSegment: () => intersectPlaneSegment,
|
|
94
114
|
intersectRayBounds: () => intersectRayBounds,
|
|
95
115
|
intersectRayTriangle: () => intersectRayTriangle,
|
|
116
|
+
isEmptyBounds: () => isEmptyBounds,
|
|
96
117
|
isGeometry: () => isGeometry,
|
|
118
|
+
isTriangleFrontFacing: () => isTriangleFrontFacing,
|
|
97
119
|
makeAttributeIterator: () => makeAttributeIterator,
|
|
98
120
|
makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
|
|
99
121
|
makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
|
|
@@ -114,10 +136,18 @@ __export(index_exports, {
|
|
|
114
136
|
octPack: () => octPack,
|
|
115
137
|
octPackFloat: () => octPackFloat,
|
|
116
138
|
octUnpack: () => octUnpack,
|
|
139
|
+
projectBounds: () => projectBounds,
|
|
140
|
+
projectTextureCoordinates: () => projectTextureCoordinates,
|
|
117
141
|
qualifySurfaceTransition: () => qualifySurfaceTransition,
|
|
142
|
+
sampleCurveAdaptive: () => sampleCurveAdaptive,
|
|
143
|
+
spheresIntersect: () => spheresIntersect,
|
|
118
144
|
subdividePolyline: () => subdividePolyline,
|
|
119
145
|
subdivideTriangleMesh: () => subdivideTriangleMesh,
|
|
120
146
|
transformGeometry: () => transformGeometry,
|
|
147
|
+
transformRay: () => transformRay,
|
|
148
|
+
triangleContainsPoint: () => triangleContainsPoint,
|
|
149
|
+
triangleIntersectsBounds: () => triangleIntersectsBounds,
|
|
150
|
+
unionBounds: () => unionBounds,
|
|
121
151
|
unpackIndexedGeometry: () => unpackIndexedGeometry,
|
|
122
152
|
validateQueryDistance: () => validateQueryDistance,
|
|
123
153
|
validateQueryPoint: () => validateQueryPoint,
|
|
@@ -265,10 +295,10 @@ var HingeTree = class {
|
|
|
265
295
|
* Output may alias the inputs: angles and root transform are snapshotted first.
|
|
266
296
|
* Finite inputs that overflow during composition throw; output may then be partial.
|
|
267
297
|
*/
|
|
268
|
-
evaluate(angles,
|
|
298
|
+
evaluate(angles, output2 = new Float64Array(this.panelCount * 16), rootTransform) {
|
|
269
299
|
if (angles.length !== this.panelCount)
|
|
270
300
|
throw new RangeError("Expected one angle per panel");
|
|
271
|
-
if (!(
|
|
301
|
+
if (!(output2 instanceof Float64Array) || output2.length !== this.panelCount * 16) {
|
|
272
302
|
throw new RangeError("Expected 16 Float64 values per panel");
|
|
273
303
|
}
|
|
274
304
|
for (let i = 0; i < angles.length; i++) {
|
|
@@ -293,16 +323,16 @@ var HingeTree = class {
|
|
|
293
323
|
this.world.copy(this.root);
|
|
294
324
|
else {
|
|
295
325
|
for (let i = 0; i < 16; i++)
|
|
296
|
-
this.world[i] =
|
|
326
|
+
this.world[i] = output2[joint.parent * 16 + i];
|
|
297
327
|
}
|
|
298
328
|
this.world.multiplyRight(this.local);
|
|
299
329
|
for (let i = 0; i < 16; i++) {
|
|
300
330
|
if (!Number.isFinite(this.world[i]))
|
|
301
331
|
throw new RangeError("Hinge transform overflow");
|
|
302
|
-
|
|
332
|
+
output2[index * 16 + i] = this.world[i];
|
|
303
333
|
}
|
|
304
334
|
}
|
|
305
|
-
return
|
|
335
|
+
return output2;
|
|
306
336
|
}
|
|
307
337
|
};
|
|
308
338
|
function copyVector(vector) {
|
|
@@ -323,10 +353,10 @@ function validateRigidTransform(matrix) {
|
|
|
323
353
|
throw new RangeError("Expected an affine rigid transform");
|
|
324
354
|
for (let a = 0; a < 3; a++) {
|
|
325
355
|
for (let b = a; b < 3; b++) {
|
|
326
|
-
let
|
|
356
|
+
let dot6 = 0;
|
|
327
357
|
for (let row = 0; row < 3; row++)
|
|
328
|
-
|
|
329
|
-
if (Math.abs(
|
|
358
|
+
dot6 += matrix[a * 4 + row] * matrix[b * 4 + row];
|
|
359
|
+
if (Math.abs(dot6 - (a === b ? 1 : 0)) > tolerance) {
|
|
330
360
|
throw new RangeError("Rigid transforms cannot scale or shear");
|
|
331
361
|
}
|
|
332
362
|
}
|
|
@@ -482,9 +512,9 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
482
512
|
const deltaRadius = radiusTop - radiusBottom;
|
|
483
513
|
if (Math.abs(deltaRadius) >= height) {
|
|
484
514
|
const topWins = radiusTop >= radiusBottom;
|
|
485
|
-
const
|
|
515
|
+
const radius2 = topWins ? radiusTop : radiusBottom;
|
|
486
516
|
const center = topWins ? height / 2 : -height / 2;
|
|
487
|
-
addSphereRings(rings, center,
|
|
517
|
+
addSphereRings(rings, center, radius2, ncap * 2);
|
|
488
518
|
} else {
|
|
489
519
|
const sinSlope = deltaRadius / height;
|
|
490
520
|
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
@@ -503,11 +533,11 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
503
533
|
}
|
|
504
534
|
for (let i = 1; i <= nvertical; i++) {
|
|
505
535
|
const t = i / nvertical;
|
|
506
|
-
const
|
|
536
|
+
const radius2 = radiusBottom + deltaRadius * t;
|
|
507
537
|
const center = bottomCenter + height * t;
|
|
508
538
|
rings.push({
|
|
509
|
-
radius:
|
|
510
|
-
y: center +
|
|
539
|
+
radius: radius2 * radialNormal,
|
|
540
|
+
y: center + radius2 * sideNormalY,
|
|
511
541
|
normalRadius: radialNormal,
|
|
512
542
|
normalY: sideNormalY
|
|
513
543
|
});
|
|
@@ -537,14 +567,14 @@ var CapsuleGeometry = class extends Geometry {
|
|
|
537
567
|
});
|
|
538
568
|
}
|
|
539
569
|
};
|
|
540
|
-
function addSphereRings(rings, center,
|
|
570
|
+
function addSphereRings(rings, center, radius2, segments) {
|
|
541
571
|
for (let i = 0; i <= segments; i++) {
|
|
542
572
|
const angle = -Math.PI / 2 + i / segments * Math.PI;
|
|
543
573
|
const normalRadius = Math.cos(angle);
|
|
544
574
|
const normalY = Math.sin(angle);
|
|
545
575
|
rings.push({
|
|
546
|
-
radius:
|
|
547
|
-
y: center +
|
|
576
|
+
radius: radius2 * normalRadius,
|
|
577
|
+
y: center + radius2 * normalY,
|
|
548
578
|
normalRadius,
|
|
549
579
|
normalY
|
|
550
580
|
});
|
|
@@ -569,16 +599,16 @@ var TruncatedConeGeometry = class extends Geometry {
|
|
|
569
599
|
const stride = nradial + 1;
|
|
570
600
|
const slope = (bottomRadius - topRadius) / height;
|
|
571
601
|
const normalScale = 1 / Math.hypot(1, slope);
|
|
572
|
-
const addRing = (
|
|
602
|
+
const addRing = (radius2, y, normalRadius, normalY, v) => {
|
|
573
603
|
const ring = positions.length / 3 / stride;
|
|
574
604
|
for (let radial2 = 0; radial2 <= nradial; radial2++) {
|
|
575
605
|
const u = radial2 / nradial;
|
|
576
606
|
const angle = u * Math.PI * 2;
|
|
577
607
|
const sin = Math.sin(angle);
|
|
578
608
|
const cos = Math.cos(angle);
|
|
579
|
-
const
|
|
609
|
+
const point2 = orient([sin * radius2, y, cos * radius2], verticalAxis);
|
|
580
610
|
const normal = orient([sin * normalRadius, normalY, cos * normalRadius], verticalAxis);
|
|
581
|
-
positions.push(...
|
|
611
|
+
positions.push(...point2);
|
|
582
612
|
normals.push(...normal);
|
|
583
613
|
texCoords.push(u, v);
|
|
584
614
|
}
|
|
@@ -602,8 +632,8 @@ var TruncatedConeGeometry = class extends Geometry {
|
|
|
602
632
|
}
|
|
603
633
|
for (let vertical = 0; vertical <= nvertical; vertical++) {
|
|
604
634
|
const v = vertical / nvertical;
|
|
605
|
-
const
|
|
606
|
-
const ring = addRing(
|
|
635
|
+
const radius2 = bottomRadius + (topRadius - bottomRadius) * v;
|
|
636
|
+
const ring = addRing(radius2, (v - 0.5) * height, normalScale, slope * normalScale, v);
|
|
607
637
|
if (previous !== void 0 && !(bottomCap && vertical === 0))
|
|
608
638
|
connect(previous, ring);
|
|
609
639
|
previous = ring;
|
|
@@ -655,8 +685,8 @@ var CylinderGeometry = class extends TruncatedConeGeometry {
|
|
|
655
685
|
};
|
|
656
686
|
var ConeGeometry = class extends TruncatedConeGeometry {
|
|
657
687
|
constructor(props = {}) {
|
|
658
|
-
const { radius = 0.5, topCap = false, bottomCap = true } = props;
|
|
659
|
-
super({ ...props, topRadius: 0, bottomRadius:
|
|
688
|
+
const { radius: radius2 = 0.5, topCap = false, bottomCap = true } = props;
|
|
689
|
+
super({ ...props, topRadius: 0, bottomRadius: radius2, topCap, bottomCap });
|
|
660
690
|
}
|
|
661
691
|
};
|
|
662
692
|
|
|
@@ -709,8 +739,8 @@ var PlaneGeometry = class extends Geometry {
|
|
|
709
739
|
// dist/geometries/sphere-geometry.js
|
|
710
740
|
var SphereGeometry = class extends Geometry {
|
|
711
741
|
constructor(props = {}) {
|
|
712
|
-
const { radius = 0.5, nlat = 10, nlong = 10 } = props;
|
|
713
|
-
assertPositive(
|
|
742
|
+
const { radius: radius2 = 0.5, nlat = 10, nlong = 10 } = props;
|
|
743
|
+
assertPositive(radius2, "radius");
|
|
714
744
|
assertSegments(nlat, "nlat", 2);
|
|
715
745
|
assertSegments(nlong, "nlong", 3);
|
|
716
746
|
const rings = [];
|
|
@@ -718,7 +748,7 @@ var SphereGeometry = class extends Geometry {
|
|
|
718
748
|
const angle = -Math.PI / 2 + latitude / nlat * Math.PI;
|
|
719
749
|
const normalRadius = Math.cos(angle);
|
|
720
750
|
const normalY = Math.sin(angle);
|
|
721
|
-
rings.push({ radius:
|
|
751
|
+
rings.push({ radius: radius2 * normalRadius, y: radius2 * normalY, normalRadius, normalY });
|
|
722
752
|
}
|
|
723
753
|
const mesh = makeSurfaceOfRevolution(rings, nlong);
|
|
724
754
|
super({
|
|
@@ -738,8 +768,8 @@ var SphereGeometry = class extends Geometry {
|
|
|
738
768
|
// dist/geometries/ico-sphere-geometry.js
|
|
739
769
|
var IcoSphereGeometry = class extends Geometry {
|
|
740
770
|
constructor(props = {}) {
|
|
741
|
-
const { radius = 0.5, iterations = 0 } = props;
|
|
742
|
-
assertPositive(
|
|
771
|
+
const { radius: radius2 = 0.5, iterations = 0 } = props;
|
|
772
|
+
assertPositive(radius2, "radius");
|
|
743
773
|
assertSegments(iterations, "iterations", 0);
|
|
744
774
|
if (iterations > 8)
|
|
745
775
|
throw new Error("iterations must be <= 8");
|
|
@@ -795,7 +825,7 @@ var IcoSphereGeometry = class extends Geometry {
|
|
|
795
825
|
const texCoords = [];
|
|
796
826
|
for (const face of faces2) {
|
|
797
827
|
for (const normal of face) {
|
|
798
|
-
positions.push(normal[0] *
|
|
828
|
+
positions.push(normal[0] * radius2, normal[1] * radius2, normal[2] * radius2);
|
|
799
829
|
normals.push(...normal);
|
|
800
830
|
texCoords.push(0.5 + Math.atan2(normal[0], normal[2]) / (2 * Math.PI), 0.5 - Math.asin(normal[1]) / Math.PI);
|
|
801
831
|
}
|
|
@@ -819,12 +849,12 @@ function normalize(vector) {
|
|
|
819
849
|
|
|
820
850
|
// dist/geometries/primitive-mesh-builder.js
|
|
821
851
|
var FULL_CIRCLE = Math.PI * 2;
|
|
822
|
-
function radial(angle,
|
|
823
|
-
return [Math.cos(angle) *
|
|
852
|
+
function radial(angle, direction2 = 1) {
|
|
853
|
+
return [Math.cos(angle) * direction2, 0, -Math.sin(angle) * direction2];
|
|
824
854
|
}
|
|
825
|
-
function vertex(
|
|
855
|
+
function vertex(radius2, height, angle, normal, textureCoordinates) {
|
|
826
856
|
return {
|
|
827
|
-
position: [
|
|
857
|
+
position: [radius2 * Math.cos(angle), height, -radius2 * Math.sin(angle)],
|
|
828
858
|
normal,
|
|
829
859
|
textureCoordinates: textureCoordinates ?? [(Math.cos(angle) + 1) / 2, (Math.sin(angle) + 1) / 2]
|
|
830
860
|
};
|
|
@@ -853,12 +883,12 @@ var PrimitiveMeshBuilder = class {
|
|
|
853
883
|
addTriangle(first, second, third, indices) {
|
|
854
884
|
const firstEdge = second.position.map((value, index) => value - first.position[index]);
|
|
855
885
|
const secondEdge = third.position.map((value, index) => value - first.position[index]);
|
|
856
|
-
const
|
|
886
|
+
const cross6 = [
|
|
857
887
|
firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
|
|
858
888
|
firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
|
|
859
889
|
firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
|
|
860
890
|
];
|
|
861
|
-
const orientation =
|
|
891
|
+
const orientation = cross6.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
|
|
862
892
|
this.indices.push(...orientation < 0 ? [indices[0], indices[2], indices[1]] : indices);
|
|
863
893
|
}
|
|
864
894
|
triangle(first, second, third) {
|
|
@@ -891,8 +921,8 @@ var PrimitiveMeshBuilder = class {
|
|
|
891
921
|
// dist/geometries/prism-geometry.js
|
|
892
922
|
var PrismGeometry = class extends Geometry {
|
|
893
923
|
constructor(props = {}) {
|
|
894
|
-
const { radius = 1, height = 1, sides = 6, startAngle = 0 } = props;
|
|
895
|
-
assertPositive(
|
|
924
|
+
const { radius: radius2 = 1, height = 1, sides = 6, startAngle = 0 } = props;
|
|
925
|
+
assertPositive(radius2, "radius");
|
|
896
926
|
assertPositive(height, "height");
|
|
897
927
|
validateArc(sides, startAngle, FULL_CIRCLE);
|
|
898
928
|
const mesh = new PrimitiveMeshBuilder();
|
|
@@ -901,15 +931,15 @@ var PrismGeometry = class extends Geometry {
|
|
|
901
931
|
const secondAngle = startAngle + (segment + 1) * FULL_CIRCLE / sides;
|
|
902
932
|
const normal = radial((firstAngle + secondAngle) / 2);
|
|
903
933
|
const secondCornerAngle = segment === sides - 1 ? startAngle : secondAngle;
|
|
904
|
-
mesh.quad(vertex(
|
|
905
|
-
for (const
|
|
906
|
-
const capNormal = [0,
|
|
934
|
+
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]));
|
|
935
|
+
for (const direction2 of [-1, 1]) {
|
|
936
|
+
const capNormal = [0, direction2, 0];
|
|
907
937
|
const center = {
|
|
908
|
-
position: [0,
|
|
938
|
+
position: [0, direction2 * height / 2, 0],
|
|
909
939
|
normal: capNormal,
|
|
910
940
|
textureCoordinates: [0.5, 0.5]
|
|
911
941
|
};
|
|
912
|
-
mesh.triangle(center, vertex(
|
|
942
|
+
mesh.triangle(center, vertex(radius2, direction2 * height / 2, firstAngle, capNormal), vertex(radius2, direction2 * height / 2, secondCornerAngle, capNormal));
|
|
913
943
|
}
|
|
914
944
|
}
|
|
915
945
|
super(mesh.getProps(props));
|
|
@@ -930,39 +960,39 @@ var RingGeometry = class extends Geometry {
|
|
|
930
960
|
for (let segment = 0; segment < segments; segment++) {
|
|
931
961
|
const firstAngle = startAngle + segment * sweepAngle / segments;
|
|
932
962
|
const secondAngle = segment === segments - 1 ? sweepAngle === FULL_CIRCLE ? startAngle : startAngle + sweepAngle : startAngle + (segment + 1) * sweepAngle / segments;
|
|
933
|
-
const makeCapVertex = (
|
|
934
|
-
(
|
|
935
|
-
(
|
|
963
|
+
const makeCapVertex = (radius2, height2, angle, normal) => vertex(radius2, height2, angle, normal, [
|
|
964
|
+
(radius2 * Math.cos(angle) / outerRadius + 1) / 2,
|
|
965
|
+
(radius2 * Math.sin(angle) / outerRadius + 1) / 2
|
|
936
966
|
]);
|
|
937
|
-
for (const
|
|
938
|
-
const normal = [0,
|
|
939
|
-
mesh.quad(makeCapVertex(innerRadius,
|
|
967
|
+
for (const direction2 of [-1, 1]) {
|
|
968
|
+
const normal = [0, direction2, 0];
|
|
969
|
+
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));
|
|
940
970
|
}
|
|
941
|
-
for (const [
|
|
971
|
+
for (const [radius2, direction2] of [
|
|
942
972
|
[innerRadius, -1],
|
|
943
973
|
[outerRadius, 1]
|
|
944
974
|
]) {
|
|
945
|
-
mesh.quad(vertex(
|
|
975
|
+
mesh.quad(vertex(radius2, -height / 2, firstAngle, radial(firstAngle, direction2), [
|
|
946
976
|
segment / segments,
|
|
947
977
|
0
|
|
948
|
-
]), vertex(
|
|
978
|
+
]), vertex(radius2, height / 2, firstAngle, radial(firstAngle, direction2), [
|
|
949
979
|
segment / segments,
|
|
950
980
|
1
|
|
951
|
-
]), vertex(
|
|
981
|
+
]), vertex(radius2, height / 2, secondAngle, radial(secondAngle, direction2), [
|
|
952
982
|
(segment + 1) / segments,
|
|
953
983
|
1
|
|
954
|
-
]), vertex(
|
|
984
|
+
]), vertex(radius2, -height / 2, secondAngle, radial(secondAngle, direction2), [
|
|
955
985
|
(segment + 1) / segments,
|
|
956
986
|
0
|
|
957
987
|
]));
|
|
958
988
|
}
|
|
959
989
|
}
|
|
960
990
|
if (sweepAngle < FULL_CIRCLE) {
|
|
961
|
-
for (const [angle,
|
|
991
|
+
for (const [angle, direction2] of [
|
|
962
992
|
[startAngle, -1],
|
|
963
993
|
[startAngle + sweepAngle, 1]
|
|
964
994
|
]) {
|
|
965
|
-
const normal = [-Math.sin(angle) *
|
|
995
|
+
const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
|
|
966
996
|
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]));
|
|
967
997
|
}
|
|
968
998
|
}
|
|
@@ -1074,8 +1104,8 @@ var TorusGeometry = class extends ParametricGeometry {
|
|
|
1074
1104
|
periodicU: arc === Math.PI * 2,
|
|
1075
1105
|
periodicV: true,
|
|
1076
1106
|
sample: (u, v) => {
|
|
1077
|
-
const theta = startAngle + u * arc, phi = v * Math.PI * 2,
|
|
1078
|
-
return [
|
|
1107
|
+
const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius2 = majorRadius + minorRadius * Math.cos(phi);
|
|
1108
|
+
return [radius2 * Math.cos(theta), minorRadius * Math.sin(phi), -radius2 * Math.sin(theta)];
|
|
1079
1109
|
},
|
|
1080
1110
|
normal: (u, v) => [
|
|
1081
1111
|
Math.cos(v * Math.PI * 2) * Math.cos(startAngle + u * arc),
|
|
@@ -1089,25 +1119,25 @@ var TorusGeometry = class extends ParametricGeometry {
|
|
|
1089
1119
|
const normals = Array.from(this.attributes["NORMAL"].value);
|
|
1090
1120
|
const textureCoordinates = Array.from(this.attributes["TEXCOORD_0"].value);
|
|
1091
1121
|
const indices = Array.from(this.indices.value);
|
|
1092
|
-
for (const [angle,
|
|
1122
|
+
for (const [angle, direction2] of [
|
|
1093
1123
|
[startAngle, -1],
|
|
1094
1124
|
[startAngle + arc, 1]
|
|
1095
1125
|
]) {
|
|
1096
|
-
const normal = [-Math.sin(angle) *
|
|
1126
|
+
const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
|
|
1097
1127
|
const centerIndex = positions.length / 3;
|
|
1098
1128
|
positions.push(majorRadius * Math.cos(angle), 0, -majorRadius * Math.sin(angle));
|
|
1099
1129
|
normals.push(...normal);
|
|
1100
1130
|
textureCoordinates.push(0.5, 0.5);
|
|
1101
1131
|
for (let minorSegment = 0; minorSegment <= minorSegments; minorSegment++) {
|
|
1102
1132
|
const tubeAngle = minorSegment % minorSegments * Math.PI * 2 / minorSegments;
|
|
1103
|
-
const boundaryOffset = (minorSegment * (majorSegments + 1) + (
|
|
1133
|
+
const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction2 < 0 ? 0 : majorSegments)) * 3;
|
|
1104
1134
|
positions.push(...surfacePositions.slice(boundaryOffset, boundaryOffset + 3));
|
|
1105
1135
|
normals.push(...normal);
|
|
1106
1136
|
textureCoordinates.push((Math.cos(tubeAngle) + 1) / 2, (Math.sin(tubeAngle) + 1) / 2);
|
|
1107
1137
|
if (minorSegment < minorSegments) {
|
|
1108
1138
|
const firstIndex = centerIndex + minorSegment + 1;
|
|
1109
1139
|
const secondIndex = firstIndex + 1;
|
|
1110
|
-
indices.push(centerIndex, ...
|
|
1140
|
+
indices.push(centerIndex, ...direction2 > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
|
|
1111
1141
|
}
|
|
1112
1142
|
}
|
|
1113
1143
|
}
|
|
@@ -1162,8 +1192,8 @@ var LatheGeometry = class extends ParametricGeometry {
|
|
|
1162
1192
|
vSegments: profile.length - 1,
|
|
1163
1193
|
periodicU: phiLength === Math.PI * 2,
|
|
1164
1194
|
sample: (u, v) => {
|
|
1165
|
-
const { i, t } = section(v),
|
|
1166
|
-
return [
|
|
1195
|
+
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;
|
|
1196
|
+
return [radius2 * Math.cos(theta), height, -radius2 * Math.sin(theta)];
|
|
1167
1197
|
},
|
|
1168
1198
|
normal: (u, v) => {
|
|
1169
1199
|
const { i, t } = section(v), n = profileNormals[i].map((value, axis) => value * (1 - t) + profileNormals[i + 1][axis] * t), theta = phiStart + u * phiLength;
|
|
@@ -1682,26 +1712,26 @@ function transformGeometry(geometry, matrix) {
|
|
|
1682
1712
|
const positions = new Float64Array(mesh.count * 3);
|
|
1683
1713
|
const source = mesh.attributes[mesh.position].value;
|
|
1684
1714
|
for (let i = 0; i < mesh.count; i++) {
|
|
1685
|
-
const
|
|
1686
|
-
positions.set(
|
|
1715
|
+
const point2 = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
|
|
1716
|
+
positions.set(point2, i * 3);
|
|
1687
1717
|
}
|
|
1688
1718
|
attributes[mesh.position] = { size: 3, value: positions };
|
|
1689
1719
|
if (normalName) {
|
|
1690
1720
|
const input = mesh.attributes[normalName];
|
|
1691
1721
|
if (input.size !== 3)
|
|
1692
1722
|
throw new RangeError("Normals must have size 3");
|
|
1693
|
-
const
|
|
1723
|
+
const output2 = new Float64Array(mesh.count * 3);
|
|
1694
1724
|
for (let i = 0; i < mesh.count; i++) {
|
|
1695
1725
|
const value = normalizedLinearCombination(cofactors, Array.from(input.value.slice(i * 3, i * 3 + 3)), scales.map((v) => -Math.log(v)));
|
|
1696
|
-
|
|
1726
|
+
output2.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
|
|
1697
1727
|
}
|
|
1698
|
-
attributes[normalName] = { size: 3, value:
|
|
1728
|
+
attributes[normalName] = { size: 3, value: output2 };
|
|
1699
1729
|
}
|
|
1700
1730
|
if (tangentName) {
|
|
1701
1731
|
const input = mesh.attributes[tangentName];
|
|
1702
1732
|
if (input.size !== 4)
|
|
1703
1733
|
throw new RangeError("Tangents must have size 4");
|
|
1704
|
-
const
|
|
1734
|
+
const output2 = new Float64Array(mesh.count * 4);
|
|
1705
1735
|
for (let i = 0; i < mesh.count; i++) {
|
|
1706
1736
|
const value = normalizedLinearCombination(basis, Array.from(input.value.slice(i * 4, i * 4 + 3)), scales.map(Math.log));
|
|
1707
1737
|
if (normalName) {
|
|
@@ -1711,10 +1741,10 @@ function transformGeometry(geometry, matrix) {
|
|
|
1711
1741
|
value[axis] -= projection * n[axis];
|
|
1712
1742
|
}
|
|
1713
1743
|
const length = Math.hypot(...value);
|
|
1714
|
-
|
|
1715
|
-
|
|
1744
|
+
output2.set(value.map((v) => length ? v / length : 0), i * 4);
|
|
1745
|
+
output2[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
|
|
1716
1746
|
}
|
|
1717
|
-
attributes[tangentName] = { size: 4, value:
|
|
1747
|
+
attributes[tangentName] = { size: 4, value: output2 };
|
|
1718
1748
|
}
|
|
1719
1749
|
const indices = mesh.indices.slice();
|
|
1720
1750
|
if (determinant < 0)
|
|
@@ -1974,8 +2004,8 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
1974
2004
|
}
|
|
1975
2005
|
const sourceCount = source.byteLength / byteStride;
|
|
1976
2006
|
const input = new DataView(source.buffer, source.byteOffset, source.byteLength);
|
|
1977
|
-
const
|
|
1978
|
-
const result = new DataView(
|
|
2007
|
+
const output2 = new Uint8Array(outputBytes);
|
|
2008
|
+
const result = new DataView(output2.buffer);
|
|
1979
2009
|
for (let vertex2 = 0; vertex2 < outputCount; vertex2++) {
|
|
1980
2010
|
let sum = 0;
|
|
1981
2011
|
let firstSource = -1;
|
|
@@ -1996,7 +2026,7 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
1996
2026
|
if (firstSource < 0 || Math.abs(sum - 1) > 1e-10) {
|
|
1997
2027
|
throw new RangeError("Interpolation weights must sum to one");
|
|
1998
2028
|
}
|
|
1999
|
-
|
|
2029
|
+
output2.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
|
|
2000
2030
|
for (const attribute of attributes) {
|
|
2001
2031
|
for (let component = 0; component < attribute.size; component++) {
|
|
2002
2032
|
const offset = attribute.byteOffset + component * BYTE_SIZES[attribute.type];
|
|
@@ -2025,7 +2055,7 @@ function interpolatePackedAttributes(source, provenance, options) {
|
|
|
2025
2055
|
}
|
|
2026
2056
|
}
|
|
2027
2057
|
}
|
|
2028
|
-
return
|
|
2058
|
+
return output2;
|
|
2029
2059
|
}
|
|
2030
2060
|
function validateInterpolation(interpolation) {
|
|
2031
2061
|
if (interpolation !== "linear" && interpolation !== "flat") {
|
|
@@ -2084,11 +2114,11 @@ function writeComponent(view, offset, type, value, littleEndian) {
|
|
|
2084
2114
|
|
|
2085
2115
|
// dist/curves/curve.js
|
|
2086
2116
|
var Curve = class {
|
|
2087
|
-
constructor(
|
|
2088
|
-
if (
|
|
2117
|
+
constructor(dimension2) {
|
|
2118
|
+
if (dimension2 !== 2 && dimension2 !== 3) {
|
|
2089
2119
|
throw new RangeError("Curve points must have two or three coordinates");
|
|
2090
2120
|
}
|
|
2091
|
-
this.dimension =
|
|
2121
|
+
this.dimension = dimension2;
|
|
2092
2122
|
}
|
|
2093
2123
|
getPoint(t, result = new Array(this.dimension)) {
|
|
2094
2124
|
validateParameter(t);
|
|
@@ -2115,10 +2145,10 @@ var Curve = class {
|
|
|
2115
2145
|
getPoints(divisions = 64) {
|
|
2116
2146
|
validateDivisions(divisions);
|
|
2117
2147
|
const points = new Float64Array((divisions + 1) * this.dimension);
|
|
2118
|
-
const
|
|
2148
|
+
const point2 = new Array(this.dimension);
|
|
2119
2149
|
for (let i = 0; i <= divisions; i++) {
|
|
2120
|
-
this.getPoint(i / divisions,
|
|
2121
|
-
points.set(
|
|
2150
|
+
this.getPoint(i / divisions, point2);
|
|
2151
|
+
points.set(point2, i * this.dimension);
|
|
2122
2152
|
}
|
|
2123
2153
|
return points;
|
|
2124
2154
|
}
|
|
@@ -2126,14 +2156,14 @@ var Curve = class {
|
|
|
2126
2156
|
function copyPoints(points) {
|
|
2127
2157
|
if (!points.length)
|
|
2128
2158
|
throw new RangeError("Invalid number of curve control points");
|
|
2129
|
-
const
|
|
2130
|
-
if (
|
|
2159
|
+
const dimension2 = points[0].length;
|
|
2160
|
+
if (dimension2 !== 2 && dimension2 !== 3) {
|
|
2131
2161
|
throw new RangeError("Curve points must have two or three coordinates");
|
|
2132
2162
|
}
|
|
2133
|
-
return points.map((
|
|
2134
|
-
if (
|
|
2163
|
+
return points.map((point2) => {
|
|
2164
|
+
if (point2.length !== dimension2)
|
|
2135
2165
|
throw new RangeError("Control point dimensions must match");
|
|
2136
|
-
return Array.from(
|
|
2166
|
+
return Array.from(point2, (value) => {
|
|
2137
2167
|
if (!Number.isFinite(value))
|
|
2138
2168
|
throw new RangeError("Control coordinates must be finite");
|
|
2139
2169
|
return value;
|
|
@@ -2150,8 +2180,8 @@ function validateDivisions(divisions) {
|
|
|
2150
2180
|
throw new RangeError("divisions must be a positive safe integer");
|
|
2151
2181
|
}
|
|
2152
2182
|
}
|
|
2153
|
-
function validateResult(result,
|
|
2154
|
-
if (result.length <
|
|
2183
|
+
function validateResult(result, dimension2) {
|
|
2184
|
+
if (result.length < dimension2)
|
|
2155
2185
|
throw new RangeError("Result buffer is too short");
|
|
2156
2186
|
}
|
|
2157
2187
|
|
|
@@ -2243,7 +2273,7 @@ var CatmullRomCurve = class extends Curve {
|
|
|
2243
2273
|
if (options.tension !== void 0 && mode !== "uniform") {
|
|
2244
2274
|
throw new RangeError("tension is only supported for uniform splines");
|
|
2245
2275
|
}
|
|
2246
|
-
const
|
|
2276
|
+
const point2 = (index) => {
|
|
2247
2277
|
if (this.closed)
|
|
2248
2278
|
return data[(index + data.length) % data.length];
|
|
2249
2279
|
if (index < 0)
|
|
@@ -2255,10 +2285,10 @@ var CatmullRomCurve = class extends Curve {
|
|
|
2255
2285
|
};
|
|
2256
2286
|
this.segments = [];
|
|
2257
2287
|
for (let s = 0; s < data.length - (this.closed ? 0 : 1); s++) {
|
|
2258
|
-
const p0 =
|
|
2259
|
-
const p1 =
|
|
2260
|
-
const p2 =
|
|
2261
|
-
const p3 =
|
|
2288
|
+
const p0 = point2(s - 1);
|
|
2289
|
+
const p1 = point2(s);
|
|
2290
|
+
const p2 = point2(s + 1);
|
|
2291
|
+
const p3 = point2(s + 2);
|
|
2262
2292
|
const interval = (a, b) => {
|
|
2263
2293
|
const distance = Math.hypot(...a.map((x, i) => b[i] - x));
|
|
2264
2294
|
return distance ** (mode === "chordal" ? 1 : 0.5);
|
|
@@ -2335,23 +2365,144 @@ var CurveArcLength = class {
|
|
|
2335
2365
|
getSpacedPoints(divisions = 64) {
|
|
2336
2366
|
validateDivisions(divisions);
|
|
2337
2367
|
const points = new Float64Array((divisions + 1) * this.curve.dimension);
|
|
2338
|
-
const
|
|
2368
|
+
const point2 = new Array(this.curve.dimension);
|
|
2339
2369
|
for (let i = 0; i <= divisions; i++) {
|
|
2340
|
-
this.getPointAt(i / divisions,
|
|
2341
|
-
points.set(
|
|
2370
|
+
this.getPointAt(i / divisions, point2);
|
|
2371
|
+
points.set(point2, i * this.curve.dimension);
|
|
2342
2372
|
}
|
|
2343
2373
|
return points;
|
|
2344
2374
|
}
|
|
2345
2375
|
};
|
|
2346
2376
|
|
|
2377
|
+
// dist/curves/adaptive-sampling.js
|
|
2378
|
+
function sampleCurveAdaptive(curve, options) {
|
|
2379
|
+
const { tolerance, maxDepth = 16, maxPoints = 65536 } = options;
|
|
2380
|
+
if (!Number.isFinite(tolerance) || tolerance <= 0 || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !Number.isSafeInteger(maxPoints) || maxPoints < 2)
|
|
2381
|
+
throw new RangeError("Invalid adaptive sampling budget");
|
|
2382
|
+
const parameters = [0], positions = [...curve.getPoint(0)];
|
|
2383
|
+
let converged = true, maxSampledError = 0;
|
|
2384
|
+
const stack = [{ t0: 0, t1: 1, a: curve.getPoint(0), b: curve.getPoint(1), depth: 0 }];
|
|
2385
|
+
while (stack.length) {
|
|
2386
|
+
const segment = stack.pop();
|
|
2387
|
+
const { t0, t1, a, b, depth } = segment;
|
|
2388
|
+
const localEdge = b.map((x, i) => x - a[i]);
|
|
2389
|
+
const samples = [0.25, 0.5, 0.75].map((f) => curve.getPoint(t0 + (t1 - t0) * f));
|
|
2390
|
+
const localSamples = samples.map((point2) => point2.map((x, i) => x - a[i]));
|
|
2391
|
+
const local = [...localEdge, ...localSamples.flat()].every(Number.isFinite);
|
|
2392
|
+
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));
|
|
2393
|
+
const edge = local ? localEdge.map((x) => x / scale) : b.map((x, i) => x / scale - a[i] / scale);
|
|
2394
|
+
const squared = edge.reduce((sum, x) => sum + x * x, 0);
|
|
2395
|
+
const measuredError = Math.max(...samples.map((p, sampleIndex) => {
|
|
2396
|
+
const offset = local ? localSamples[sampleIndex].map((x) => x / scale) : p.map((x, i) => x / scale - a[i] / scale);
|
|
2397
|
+
const t = squared ? Math.max(0, Math.min(1, edge.reduce((sum, x, i) => sum + x * offset[i], 0) / squared)) : 0;
|
|
2398
|
+
return Math.hypot(...offset.map((x, i) => x - t * edge[i])) * scale;
|
|
2399
|
+
}));
|
|
2400
|
+
const error = Number.isFinite(measuredError) ? measuredError : Infinity;
|
|
2401
|
+
if (error > tolerance && depth < maxDepth && parameters.length + stack.length + 2 <= maxPoints) {
|
|
2402
|
+
const mid = (t0 + t1) / 2;
|
|
2403
|
+
stack.push({ t0: mid, t1, a: samples[1], b, depth: depth + 1 });
|
|
2404
|
+
stack.push({ t0, t1: mid, a, b: samples[1], depth: depth + 1 });
|
|
2405
|
+
} else {
|
|
2406
|
+
if (error > tolerance)
|
|
2407
|
+
converged = false;
|
|
2408
|
+
maxSampledError = Math.max(maxSampledError, error);
|
|
2409
|
+
parameters.push(t1);
|
|
2410
|
+
positions.push(...b);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
return {
|
|
2414
|
+
parameters: new Float64Array(parameters),
|
|
2415
|
+
positions: new Float64Array(positions),
|
|
2416
|
+
converged,
|
|
2417
|
+
maxSampledError
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
// dist/curves/parallel-transport.js
|
|
2422
|
+
var sub = (a, b) => a.map((x, i) => x - b[i]);
|
|
2423
|
+
var dot = (a, b) => a.reduce((sum, x, i) => sum + x * b[i], 0);
|
|
2424
|
+
var cross2 = (a, b) => [
|
|
2425
|
+
a[1] * b[2] - a[2] * b[1],
|
|
2426
|
+
a[2] * b[0] - a[0] * b[2],
|
|
2427
|
+
a[0] * b[1] - a[1] * b[0]
|
|
2428
|
+
];
|
|
2429
|
+
var unit = (a) => {
|
|
2430
|
+
const length = Math.hypot(...a);
|
|
2431
|
+
if (!length)
|
|
2432
|
+
throw new RangeError("Cannot construct a frame for a stationary path");
|
|
2433
|
+
return a.map((x) => x / length);
|
|
2434
|
+
};
|
|
2435
|
+
function rotate(v, axis, angle) {
|
|
2436
|
+
const c = Math.cos(angle), s = Math.sin(angle), d = dot(axis, v), k = cross2(axis, v);
|
|
2437
|
+
return v.map((x, i) => x * c + k[i] * s + axis[i] * d * (1 - c));
|
|
2438
|
+
}
|
|
2439
|
+
function computeParallelTransportFrames(points, options = {}) {
|
|
2440
|
+
if (points.length < 2 || points.some((p) => p.length !== 3 || Array.from(p).some((x) => !Number.isFinite(x))))
|
|
2441
|
+
throw new RangeError("Expected at least two finite 3D points");
|
|
2442
|
+
const data = points.map((p) => Array.from(p)), n = data.length, closed = options.closed ?? false;
|
|
2443
|
+
if (closed && (n < 4 || Math.hypot(...sub(data[0], data[n - 1])) !== 0))
|
|
2444
|
+
throw new RangeError("A closed path must repeat its first point");
|
|
2445
|
+
const tangent = new Array(n);
|
|
2446
|
+
const edges = new Array(n - 1);
|
|
2447
|
+
let last;
|
|
2448
|
+
for (let i = 0; i < n - 1; i++) {
|
|
2449
|
+
const edge = sub(data[i + 1], data[i]);
|
|
2450
|
+
if (Math.hypot(...edge) > 0)
|
|
2451
|
+
last = edges[i] = unit(edge);
|
|
2452
|
+
}
|
|
2453
|
+
if (!last)
|
|
2454
|
+
throw new RangeError("Cannot construct a frame for a stationary path");
|
|
2455
|
+
tangent[n - 1] = last;
|
|
2456
|
+
for (let i = n - 2; i >= 0; i--) {
|
|
2457
|
+
last = edges[i] ?? last;
|
|
2458
|
+
tangent[i] = last;
|
|
2459
|
+
}
|
|
2460
|
+
if (closed)
|
|
2461
|
+
tangent[n - 1] = [...tangent[0]];
|
|
2462
|
+
const t = tangent[0];
|
|
2463
|
+
let initial = options.initialNormal ? Array.from(options.initialNormal) : [0, 0, 0];
|
|
2464
|
+
if (options.initialNormal && (initial.length !== 3 || initial.some((x) => !Number.isFinite(x))))
|
|
2465
|
+
throw new RangeError("Invalid initial normal");
|
|
2466
|
+
if (!options.initialNormal) {
|
|
2467
|
+
initial = [0, 0, 0];
|
|
2468
|
+
initial[t.map(Math.abs).indexOf(Math.min(...t.map(Math.abs)))] = 1;
|
|
2469
|
+
}
|
|
2470
|
+
initial = unit(initial);
|
|
2471
|
+
const perpendicular = cross2(t, initial);
|
|
2472
|
+
if (Math.hypot(...perpendicular) <= 1e-12) {
|
|
2473
|
+
throw new RangeError("Initial normal must not be parallel to the tangent");
|
|
2474
|
+
}
|
|
2475
|
+
const normals = [unit(cross2(perpendicular, t))];
|
|
2476
|
+
for (let i = 1; i < n; i++) {
|
|
2477
|
+
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])));
|
|
2478
|
+
let normal = normals[i - 1];
|
|
2479
|
+
if (length > 1e-12)
|
|
2480
|
+
normal = rotate(normal, axis.map((x) => x / length), Math.atan2(length, cosine));
|
|
2481
|
+
normals.push(unit(normal.map((x, j) => x - dot(normal, tangent[i]) * tangent[i][j])));
|
|
2482
|
+
}
|
|
2483
|
+
if (closed) {
|
|
2484
|
+
const mismatch = Math.atan2(dot(tangent[0], cross2(normals[n - 1], normals[0])), dot(normals[n - 1], normals[0]));
|
|
2485
|
+
const lengths = [0];
|
|
2486
|
+
for (let i = 1; i < n; i++)
|
|
2487
|
+
lengths.push(lengths[i - 1] + Math.hypot(...sub(data[i], data[i - 1])));
|
|
2488
|
+
for (let i = 1; i < n; i++)
|
|
2489
|
+
normals[i] = rotate(normals[i], tangent[i], mismatch * lengths[i] / lengths[n - 1]);
|
|
2490
|
+
}
|
|
2491
|
+
return {
|
|
2492
|
+
tangents: new Float64Array(tangent.flat()),
|
|
2493
|
+
normals: new Float64Array(normals.flat()),
|
|
2494
|
+
binormals: new Float64Array(normals.flatMap((normal, i) => cross2(tangent[i], normal)))
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2347
2498
|
// dist/polygon/polygon.js
|
|
2348
2499
|
var import_core6 = require("@math.gl/core");
|
|
2349
2500
|
|
|
2350
2501
|
// dist/polygon/polygon-utils.js
|
|
2351
2502
|
var import_core5 = require("@math.gl/core");
|
|
2352
|
-
function modifyPolygonWindingDirection(points,
|
|
2503
|
+
function modifyPolygonWindingDirection(points, direction2, options = {}) {
|
|
2353
2504
|
const windingDirection = getPolygonWindingDirection(points, options);
|
|
2354
|
-
if (windingDirection !==
|
|
2505
|
+
if (windingDirection !== direction2) {
|
|
2355
2506
|
reversePolygon(points, options);
|
|
2356
2507
|
return true;
|
|
2357
2508
|
}
|
|
@@ -2403,9 +2554,9 @@ function reversePolygon(points, options) {
|
|
|
2403
2554
|
}
|
|
2404
2555
|
}
|
|
2405
2556
|
}
|
|
2406
|
-
function modifyPolygonWindingDirectionPoints(points,
|
|
2557
|
+
function modifyPolygonWindingDirectionPoints(points, direction2, options = {}) {
|
|
2407
2558
|
const currentDirection = getPolygonWindingDirectionPoints(points, options);
|
|
2408
|
-
if (currentDirection !==
|
|
2559
|
+
if (currentDirection !== direction2) {
|
|
2409
2560
|
points.reverse();
|
|
2410
2561
|
return true;
|
|
2411
2562
|
}
|
|
@@ -2507,11 +2658,11 @@ var Polygon = class {
|
|
|
2507
2658
|
* @param direction Requested winding direction.
|
|
2508
2659
|
* @return Returns true if the winding direction was changed.
|
|
2509
2660
|
*/
|
|
2510
|
-
modifyWindingDirection(
|
|
2661
|
+
modifyWindingDirection(direction2) {
|
|
2511
2662
|
if (this.isFlatArray) {
|
|
2512
|
-
return modifyPolygonWindingDirection(this.points,
|
|
2663
|
+
return modifyPolygonWindingDirection(this.points, direction2, this.options);
|
|
2513
2664
|
}
|
|
2514
|
-
return modifyPolygonWindingDirectionPoints(this.points,
|
|
2665
|
+
return modifyPolygonWindingDirectionPoints(this.points, direction2, this.options);
|
|
2515
2666
|
}
|
|
2516
2667
|
};
|
|
2517
2668
|
|
|
@@ -3540,16 +3691,16 @@ function subdividePolyline(input, options) {
|
|
|
3540
3691
|
throw new RangeError("Transform returned nonfinite coordinates");
|
|
3541
3692
|
return { source, target, fraction };
|
|
3542
3693
|
}
|
|
3543
|
-
function append(
|
|
3694
|
+
function append(point2, segment) {
|
|
3544
3695
|
if (segmentIndices.length >= maxVertices) {
|
|
3545
3696
|
throw new RangeError("Polyline subdivision exceeded maxVertices");
|
|
3546
3697
|
}
|
|
3547
|
-
for (const value of
|
|
3698
|
+
for (const value of point2.source)
|
|
3548
3699
|
sourcePositions.push(value);
|
|
3549
|
-
for (const value of
|
|
3700
|
+
for (const value of point2.target)
|
|
3550
3701
|
positions.push(value);
|
|
3551
3702
|
segmentIndices.push(segment);
|
|
3552
|
-
segmentFractions.push(
|
|
3703
|
+
segmentFractions.push(point2.fraction);
|
|
3553
3704
|
}
|
|
3554
3705
|
function sampledSource(sampler, fraction) {
|
|
3555
3706
|
const value = sampler.sample(fraction);
|
|
@@ -3569,10 +3720,10 @@ function subdividePolyline(input, options) {
|
|
|
3569
3720
|
let error = 0;
|
|
3570
3721
|
let midpoint;
|
|
3571
3722
|
for (const fraction of [0.25, 0.5, 0.75]) {
|
|
3572
|
-
const
|
|
3723
|
+
const point2 = interpolate(a, b, fraction, sampler);
|
|
3573
3724
|
if (fraction === 0.5)
|
|
3574
|
-
midpoint =
|
|
3575
|
-
const delta =
|
|
3725
|
+
midpoint = point2;
|
|
3726
|
+
const delta = point2.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
|
|
3576
3727
|
error = Math.max(error, Math.hypot(...delta));
|
|
3577
3728
|
}
|
|
3578
3729
|
const sourceLength = sampler ? sampler.length * (b.fraction - a.fraction) : Math.hypot(...a.source.map((value, i) => value - b.source[i]));
|
|
@@ -3741,7 +3892,7 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3741
3892
|
midpoints.set(key, index);
|
|
3742
3893
|
return index;
|
|
3743
3894
|
}
|
|
3744
|
-
function splitFace(face,
|
|
3895
|
+
function splitFace(face, output2, splitEdges, midpoints) {
|
|
3745
3896
|
const [a, b, c] = face.vertices;
|
|
3746
3897
|
const ab = splitEdges.has(edgeKey(a, b)) ? midpoint(a, b, midpoints) : -1;
|
|
3747
3898
|
const bc = splitEdges.has(edgeKey(b, c)) ? midpoint(b, c, midpoints) : -1;
|
|
@@ -3774,9 +3925,9 @@ function subdivideTriangleMesh(mesh, options) {
|
|
|
3774
3925
|
}
|
|
3775
3926
|
}
|
|
3776
3927
|
function emit(x, y, z) {
|
|
3777
|
-
if (
|
|
3928
|
+
if (output2.length >= maxTriangles)
|
|
3778
3929
|
throw new RangeError("Triangle mesh subdivision exceeded maxTriangles");
|
|
3779
|
-
|
|
3930
|
+
output2.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
|
|
3780
3931
|
}
|
|
3781
3932
|
}
|
|
3782
3933
|
function buildResult() {
|
|
@@ -3839,8 +3990,8 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3839
3990
|
const positions = [], indices = [], sourceVertexIndices = [], sourceVertexWeights = [];
|
|
3840
3991
|
const sourceTriangleIndices = [], periodicCopies = [];
|
|
3841
3992
|
let intersections = 0;
|
|
3842
|
-
for (let
|
|
3843
|
-
const originalIndices = inputIndices.slice(
|
|
3993
|
+
for (let triangle2 = 0; triangle2 < inputIndices.length / 3; triangle2++) {
|
|
3994
|
+
const originalIndices = inputIndices.slice(triangle2 * 3, triangle2 * 3 + 3);
|
|
3844
3995
|
const vertices = originalIndices.map((index, j) => ({
|
|
3845
3996
|
position: source.slice(index * size, index * size + size),
|
|
3846
3997
|
weights: [0, 1, 2].map((k) => Number(k === j))
|
|
@@ -3872,7 +4023,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3872
4023
|
const clipped = [];
|
|
3873
4024
|
for (let i = 0; i < polygon.length; i++) {
|
|
3874
4025
|
const p = polygon[i], q = polygon[(i + 1) % polygon.length];
|
|
3875
|
-
const dp =
|
|
4026
|
+
const dp = cross3(a, b, p.position), dq = cross3(a, b, q.position);
|
|
3876
4027
|
if (dp >= 0)
|
|
3877
4028
|
clipped.push(p);
|
|
3878
4029
|
if (dp < 0 !== dq < 0) {
|
|
@@ -3888,7 +4039,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3888
4039
|
}
|
|
3889
4040
|
for (let j = 1; j + 1 < polygon.length; j++) {
|
|
3890
4041
|
const face = [polygon[0], polygon[j], polygon[j + 1]];
|
|
3891
|
-
if (
|
|
4042
|
+
if (cross3(face[0].position, face[1].position, face[2].position) === 0)
|
|
3892
4043
|
continue;
|
|
3893
4044
|
if (positions.length / size + 3 > maxVertices || indices.length / 3 + 1 > maxTriangles)
|
|
3894
4045
|
throw new RangeError("Mesh clipping exceeded output limits");
|
|
@@ -3898,7 +4049,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3898
4049
|
sourceVertexIndices.push(...originalIndices);
|
|
3899
4050
|
sourceVertexWeights.push(...vertex2.weights);
|
|
3900
4051
|
}
|
|
3901
|
-
sourceTriangleIndices.push(
|
|
4052
|
+
sourceTriangleIndices.push(triangle2);
|
|
3902
4053
|
periodicCopies.push(copy2);
|
|
3903
4054
|
}
|
|
3904
4055
|
}
|
|
@@ -3913,7 +4064,7 @@ function clipTriangleMesh(mesh, options) {
|
|
|
3913
4064
|
periodicCopies: new Int32Array(periodicCopies)
|
|
3914
4065
|
};
|
|
3915
4066
|
}
|
|
3916
|
-
function
|
|
4067
|
+
function cross3(a, b, p) {
|
|
3917
4068
|
const result = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
|
|
3918
4069
|
if (!Number.isFinite(result))
|
|
3919
4070
|
throw new RangeError("Unrepresentable clipping arithmetic");
|
|
@@ -3924,13 +4075,13 @@ function validateRegion(region) {
|
|
|
3924
4075
|
throw new RangeError("Invalid convex clipping region");
|
|
3925
4076
|
let area2 = 0;
|
|
3926
4077
|
for (let i = 1; i + 1 < region.length; i++)
|
|
3927
|
-
area2 +=
|
|
4078
|
+
area2 += cross3(region[0], region[i], region[i + 1]);
|
|
3928
4079
|
if (!Number.isFinite(area2) || area2 === 0)
|
|
3929
4080
|
throw new RangeError("Degenerate clipping region");
|
|
3930
4081
|
const result = area2 > 0 ? Array.from(region) : Array.from(region).reverse();
|
|
3931
4082
|
for (let i = 0; i < result.length; i++) {
|
|
3932
4083
|
const a = result[i], b = result[(i + 1) % result.length];
|
|
3933
|
-
if (a[0] === b[0] && a[1] === b[1] || result.some((p) =>
|
|
4084
|
+
if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross3(a, b, p) < 0))
|
|
3934
4085
|
throw new RangeError("Clip region must be convex");
|
|
3935
4086
|
}
|
|
3936
4087
|
return result;
|
|
@@ -3973,15 +4124,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
|
|
|
3973
4124
|
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
3974
4125
|
}
|
|
3975
4126
|
/**
|
|
3976
|
-
*
|
|
3977
|
-
* @param transform The transformation matrix
|
|
3978
|
-
* @returns itself, i.e. the modified
|
|
4127
|
+
* Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
|
|
4128
|
+
* @param transform The affine transformation matrix.
|
|
4129
|
+
* @returns itself, i.e. the modified bounding box.
|
|
3979
4130
|
*/
|
|
3980
4131
|
transform(transform) {
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
this.maximum.
|
|
4132
|
+
if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
|
|
4133
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
4134
|
+
}
|
|
4135
|
+
const center = this.minimum.clone().add(this.maximum).scale(0.5);
|
|
4136
|
+
const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
|
|
4137
|
+
if (extent.some((x) => x < 0))
|
|
4138
|
+
throw new RangeError("Bounds must be ordered");
|
|
4139
|
+
center.transformAsPoint(transform);
|
|
4140
|
+
for (let row = 0; row < 3; row++) {
|
|
4141
|
+
this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
|
|
4142
|
+
}
|
|
4143
|
+
this.center.copy(center);
|
|
4144
|
+
this.minimum.copy(center).subtract(this.halfDiagonal);
|
|
4145
|
+
this.maximum.copy(center).add(this.halfDiagonal);
|
|
3985
4146
|
return this;
|
|
3986
4147
|
}
|
|
3987
4148
|
/**
|
|
@@ -4001,12 +4162,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
|
|
|
4001
4162
|
return "intersecting";
|
|
4002
4163
|
}
|
|
4003
4164
|
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
4004
|
-
distanceTo(
|
|
4005
|
-
return Math.sqrt(this.distanceSquaredTo(
|
|
4165
|
+
distanceTo(point2) {
|
|
4166
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
4006
4167
|
}
|
|
4007
4168
|
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
4008
|
-
distanceSquaredTo(
|
|
4009
|
-
const offset = scratchVector.from(
|
|
4169
|
+
distanceSquaredTo(point2) {
|
|
4170
|
+
const offset = scratchVector.from(point2).subtract(this.center);
|
|
4010
4171
|
const { halfDiagonal } = this;
|
|
4011
4172
|
let distanceSquared = 0;
|
|
4012
4173
|
let d;
|
|
@@ -4033,15 +4194,15 @@ var scratchVector4 = new import_core8.Vector3();
|
|
|
4033
4194
|
var scratchVector22 = new import_core8.Vector3();
|
|
4034
4195
|
var BoundingSphere = class _BoundingSphere {
|
|
4035
4196
|
/** Creates a bounding sphere */
|
|
4036
|
-
constructor(center = [0, 0, 0],
|
|
4197
|
+
constructor(center = [0, 0, 0], radius2 = 0) {
|
|
4037
4198
|
this.radius = -0;
|
|
4038
4199
|
this.center = new import_core8.Vector3();
|
|
4039
|
-
this.fromCenterRadius(center,
|
|
4200
|
+
this.fromCenterRadius(center, radius2);
|
|
4040
4201
|
}
|
|
4041
4202
|
/** Sets the bounding sphere from `center` and `radius`. */
|
|
4042
|
-
fromCenterRadius(center,
|
|
4203
|
+
fromCenterRadius(center, radius2) {
|
|
4043
4204
|
this.center.from(center);
|
|
4044
|
-
this.radius =
|
|
4205
|
+
this.radius = radius2;
|
|
4045
4206
|
return this;
|
|
4046
4207
|
}
|
|
4047
4208
|
/**
|
|
@@ -4083,11 +4244,11 @@ var BoundingSphere = class _BoundingSphere {
|
|
|
4083
4244
|
return this;
|
|
4084
4245
|
}
|
|
4085
4246
|
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
4086
|
-
expand(
|
|
4087
|
-
const scratchPoint = scratchVector4.from(
|
|
4088
|
-
const
|
|
4089
|
-
if (
|
|
4090
|
-
this.radius =
|
|
4247
|
+
expand(point2) {
|
|
4248
|
+
const scratchPoint = scratchVector4.from(point2);
|
|
4249
|
+
const radius2 = scratchPoint.subtract(this.center).magnitude();
|
|
4250
|
+
if (radius2 > this.radius) {
|
|
4251
|
+
this.radius = radius2;
|
|
4091
4252
|
}
|
|
4092
4253
|
return this;
|
|
4093
4254
|
}
|
|
@@ -4105,26 +4266,26 @@ var BoundingSphere = class _BoundingSphere {
|
|
|
4105
4266
|
return this;
|
|
4106
4267
|
}
|
|
4107
4268
|
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
4108
|
-
distanceSquaredTo(
|
|
4109
|
-
const d = this.distanceTo(
|
|
4269
|
+
distanceSquaredTo(point2) {
|
|
4270
|
+
const d = this.distanceTo(point2);
|
|
4110
4271
|
return d * d;
|
|
4111
4272
|
}
|
|
4112
4273
|
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
4113
|
-
distanceTo(
|
|
4114
|
-
const scratchPoint = scratchVector4.from(
|
|
4274
|
+
distanceTo(point2) {
|
|
4275
|
+
const scratchPoint = scratchVector4.from(point2);
|
|
4115
4276
|
const delta = scratchPoint.subtract(this.center);
|
|
4116
4277
|
return Math.max(0, delta.len() - this.radius);
|
|
4117
4278
|
}
|
|
4118
4279
|
/** Determines which side of a plane a sphere is located. */
|
|
4119
4280
|
intersectPlane(plane) {
|
|
4120
4281
|
const center = this.center;
|
|
4121
|
-
const
|
|
4282
|
+
const radius2 = this.radius;
|
|
4122
4283
|
const normal = plane.normal;
|
|
4123
4284
|
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
4124
|
-
if (distanceToPlane < -
|
|
4285
|
+
if (distanceToPlane < -radius2) {
|
|
4125
4286
|
return "outside";
|
|
4126
4287
|
}
|
|
4127
|
-
if (distanceToPlane <
|
|
4288
|
+
if (distanceToPlane < radius2) {
|
|
4128
4289
|
return "intersecting";
|
|
4129
4290
|
}
|
|
4130
4291
|
return "inside";
|
|
@@ -4200,16 +4361,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4200
4361
|
return "intersecting";
|
|
4201
4362
|
}
|
|
4202
4363
|
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
4203
|
-
distanceTo(
|
|
4204
|
-
return Math.sqrt(this.distanceSquaredTo(
|
|
4364
|
+
distanceTo(point2) {
|
|
4365
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
4205
4366
|
}
|
|
4206
4367
|
/**
|
|
4207
4368
|
* Computes the estimated distance squared from the closest point
|
|
4208
4369
|
* on a bounding box to a point.
|
|
4209
4370
|
* See Geometric Tools for Computer Graphics 10.4.2
|
|
4210
4371
|
*/
|
|
4211
|
-
distanceSquaredTo(
|
|
4212
|
-
const offset = scratchOffset.from(
|
|
4372
|
+
distanceSquaredTo(point2) {
|
|
4373
|
+
const offset = scratchOffset.from(point2).subtract(this.center);
|
|
4213
4374
|
const halfAxes = this.halfAxes;
|
|
4214
4375
|
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
4215
4376
|
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
@@ -4251,7 +4412,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4251
4412
|
* on the bounding box from position in direction.
|
|
4252
4413
|
*/
|
|
4253
4414
|
// eslint-disable-next-line max-statements
|
|
4254
|
-
computePlaneDistances(position,
|
|
4415
|
+
computePlaneDistances(position, direction2, result = [-0, -0]) {
|
|
4255
4416
|
let minDist = Number.POSITIVE_INFINITY;
|
|
4256
4417
|
let maxDist = Number.NEGATIVE_INFINITY;
|
|
4257
4418
|
const center = this.center;
|
|
@@ -4261,42 +4422,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4261
4422
|
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
4262
4423
|
const corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
4263
4424
|
const toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
4264
|
-
let mag =
|
|
4425
|
+
let mag = direction2.dot(toCenter);
|
|
4265
4426
|
minDist = Math.min(mag, minDist);
|
|
4266
4427
|
maxDist = Math.max(mag, maxDist);
|
|
4267
4428
|
corner.copy(center).add(u).add(v).subtract(w);
|
|
4268
4429
|
toCenter.copy(corner).subtract(position);
|
|
4269
|
-
mag =
|
|
4430
|
+
mag = direction2.dot(toCenter);
|
|
4270
4431
|
minDist = Math.min(mag, minDist);
|
|
4271
4432
|
maxDist = Math.max(mag, maxDist);
|
|
4272
4433
|
corner.copy(center).add(u).subtract(v).add(w);
|
|
4273
4434
|
toCenter.copy(corner).subtract(position);
|
|
4274
|
-
mag =
|
|
4435
|
+
mag = direction2.dot(toCenter);
|
|
4275
4436
|
minDist = Math.min(mag, minDist);
|
|
4276
4437
|
maxDist = Math.max(mag, maxDist);
|
|
4277
4438
|
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
4278
4439
|
toCenter.copy(corner).subtract(position);
|
|
4279
|
-
mag =
|
|
4440
|
+
mag = direction2.dot(toCenter);
|
|
4280
4441
|
minDist = Math.min(mag, minDist);
|
|
4281
4442
|
maxDist = Math.max(mag, maxDist);
|
|
4282
4443
|
center.copy(corner).subtract(u).add(v).add(w);
|
|
4283
4444
|
toCenter.copy(corner).subtract(position);
|
|
4284
|
-
mag =
|
|
4445
|
+
mag = direction2.dot(toCenter);
|
|
4285
4446
|
minDist = Math.min(mag, minDist);
|
|
4286
4447
|
maxDist = Math.max(mag, maxDist);
|
|
4287
4448
|
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
4288
4449
|
toCenter.copy(corner).subtract(position);
|
|
4289
|
-
mag =
|
|
4450
|
+
mag = direction2.dot(toCenter);
|
|
4290
4451
|
minDist = Math.min(mag, minDist);
|
|
4291
4452
|
maxDist = Math.max(mag, maxDist);
|
|
4292
4453
|
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
4293
4454
|
toCenter.copy(corner).subtract(position);
|
|
4294
|
-
mag =
|
|
4455
|
+
mag = direction2.dot(toCenter);
|
|
4295
4456
|
minDist = Math.min(mag, minDist);
|
|
4296
4457
|
maxDist = Math.max(mag, maxDist);
|
|
4297
4458
|
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
4298
4459
|
toCenter.copy(corner).subtract(position);
|
|
4299
|
-
mag =
|
|
4460
|
+
mag = direction2.dot(toCenter);
|
|
4300
4461
|
minDist = Math.min(mag, minDist);
|
|
4301
4462
|
maxDist = Math.max(mag, maxDist);
|
|
4302
4463
|
result[0] = minDist;
|
|
@@ -4325,6 +4486,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
|
4325
4486
|
};
|
|
4326
4487
|
|
|
4327
4488
|
// dist/culling/lib/culling-volume.js
|
|
4489
|
+
var import_core13 = require("@math.gl/core");
|
|
4490
|
+
|
|
4491
|
+
// dist/culling/frustum-planes.js
|
|
4328
4492
|
var import_core12 = require("@math.gl/core");
|
|
4329
4493
|
|
|
4330
4494
|
// dist/culling/lib/plane.js
|
|
@@ -4345,10 +4509,10 @@ var Plane = class _Plane {
|
|
|
4345
4509
|
return this;
|
|
4346
4510
|
}
|
|
4347
4511
|
/** Creates a plane from a normal and a point on the plane. */
|
|
4348
|
-
fromPointNormal(
|
|
4349
|
-
|
|
4512
|
+
fromPointNormal(point2, normal) {
|
|
4513
|
+
point2 = scratchPosition.from(point2);
|
|
4350
4514
|
this.normal.from(normal).normalize();
|
|
4351
|
-
const distance = -this.normal.dot(
|
|
4515
|
+
const distance = -this.normal.dot(point2);
|
|
4352
4516
|
this.distance = distance;
|
|
4353
4517
|
return this;
|
|
4354
4518
|
}
|
|
@@ -4370,17 +4534,17 @@ var Plane = class _Plane {
|
|
|
4370
4534
|
/** Computes the signed shortest distance of a point to a plane.
|
|
4371
4535
|
* The sign of the distance determines which side of the plane the point is on.
|
|
4372
4536
|
*/
|
|
4373
|
-
getPointDistance(
|
|
4374
|
-
return this.normal.dot(
|
|
4537
|
+
getPointDistance(point2) {
|
|
4538
|
+
return this.normal.dot(point2) + this.distance;
|
|
4375
4539
|
}
|
|
4376
4540
|
/** Transforms the plane by the given transformation matrix. */
|
|
4377
4541
|
transform(matrix4) {
|
|
4378
4542
|
const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
4379
|
-
const
|
|
4380
|
-
return this.fromPointNormal(
|
|
4543
|
+
const point2 = this.normal.scale(-this.distance).transform(matrix4);
|
|
4544
|
+
return this.fromPointNormal(point2, normal);
|
|
4381
4545
|
}
|
|
4382
|
-
projectPointOntoPlane(
|
|
4383
|
-
const scratchPoint = scratchPosition.from(
|
|
4546
|
+
projectPointOntoPlane(point2, result = [0, 0, 0]) {
|
|
4547
|
+
const scratchPoint = scratchPosition.from(point2);
|
|
4384
4548
|
const pointDistance = this.getPointDistance(scratchPoint);
|
|
4385
4549
|
const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
|
|
4386
4550
|
return scratchPoint.subtract(scaledNormal).to(result);
|
|
@@ -4394,9 +4558,9 @@ var Plane = class _Plane {
|
|
|
4394
4558
|
*/
|
|
4395
4559
|
intersectWithRay(ray, result = new import_core11.Vector3()) {
|
|
4396
4560
|
const origin = ray.origin;
|
|
4397
|
-
const
|
|
4561
|
+
const direction2 = ray.direction;
|
|
4398
4562
|
const normal = this.normal;
|
|
4399
|
-
const denominator = normal.dot(
|
|
4563
|
+
const denominator = normal.dot(direction2);
|
|
4400
4564
|
if (Math.abs(denominator) < import_core11._MathUtils.EPSILON15) {
|
|
4401
4565
|
return void 0;
|
|
4402
4566
|
}
|
|
@@ -4404,14 +4568,45 @@ var Plane = class _Plane {
|
|
|
4404
4568
|
if (t < 0) {
|
|
4405
4569
|
return void 0;
|
|
4406
4570
|
}
|
|
4407
|
-
return result.copy(
|
|
4571
|
+
return result.copy(direction2).multiplyByScalar(t).add(origin);
|
|
4408
4572
|
}
|
|
4409
4573
|
};
|
|
4410
4574
|
|
|
4575
|
+
// dist/culling/frustum-planes.js
|
|
4576
|
+
function extractFrustumPlanes(matrix, options = {}) {
|
|
4577
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
|
|
4578
|
+
throw new RangeError("Expected a finite view-projection matrix");
|
|
4579
|
+
const [near, far] = (0, import_core12.getProjectionDepthRange)(options);
|
|
4580
|
+
const low = Math.min(near, far), high = Math.max(near, far);
|
|
4581
|
+
const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
|
|
4582
|
+
const x = row(0), y = row(1), z = row(2), w = row(3);
|
|
4583
|
+
const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
|
|
4584
|
+
const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
|
|
4585
|
+
const coefficients = [
|
|
4586
|
+
combine(w, x, 1),
|
|
4587
|
+
combine(w, x, -1),
|
|
4588
|
+
combine(w, y, 1),
|
|
4589
|
+
combine(w, y, -1),
|
|
4590
|
+
...options.reversedDepth ? [hi, lo] : [lo, hi]
|
|
4591
|
+
];
|
|
4592
|
+
const planes = [];
|
|
4593
|
+
for (const [a, b, c, d] of coefficients) {
|
|
4594
|
+
const length = Math.hypot(a, b, c);
|
|
4595
|
+
if (length === 0) {
|
|
4596
|
+
if (d < 0)
|
|
4597
|
+
throw new RangeError("Empty clipping volume");
|
|
4598
|
+
} else
|
|
4599
|
+
planes.push(new Plane([a / length, b / length, c / length], d / length));
|
|
4600
|
+
}
|
|
4601
|
+
if (planes.length < 4)
|
|
4602
|
+
throw new RangeError("Degenerate clipping volume");
|
|
4603
|
+
return planes;
|
|
4604
|
+
}
|
|
4605
|
+
|
|
4411
4606
|
// dist/culling/lib/culling-volume.js
|
|
4412
|
-
var faces = [new
|
|
4413
|
-
var scratchPlaneCenter = new
|
|
4414
|
-
var scratchPlaneNormal = new
|
|
4607
|
+
var faces = [new import_core13.Vector3([1, 0, 0]), new import_core13.Vector3([0, 1, 0]), new import_core13.Vector3([0, 0, 1])];
|
|
4608
|
+
var scratchPlaneCenter = new import_core13.Vector3();
|
|
4609
|
+
var scratchPlaneNormal = new import_core13.Vector3();
|
|
4415
4610
|
var CullingVolume = class _CullingVolume {
|
|
4416
4611
|
/**
|
|
4417
4612
|
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
@@ -4427,7 +4622,7 @@ var CullingVolume = class _CullingVolume {
|
|
|
4427
4622
|
fromBoundingSphere(boundingSphere) {
|
|
4428
4623
|
this.planes.length = 2 * faces.length;
|
|
4429
4624
|
const center = boundingSphere.center;
|
|
4430
|
-
const
|
|
4625
|
+
const radius2 = boundingSphere.radius;
|
|
4431
4626
|
let planeIndex = 0;
|
|
4432
4627
|
for (const faceNormal of faces) {
|
|
4433
4628
|
let plane0 = this.planes[planeIndex];
|
|
@@ -4438,15 +4633,21 @@ var CullingVolume = class _CullingVolume {
|
|
|
4438
4633
|
if (!plane1) {
|
|
4439
4634
|
plane1 = this.planes[planeIndex + 1] = new Plane();
|
|
4440
4635
|
}
|
|
4441
|
-
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-
|
|
4636
|
+
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
|
|
4442
4637
|
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
4443
|
-
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(
|
|
4638
|
+
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
|
|
4444
4639
|
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
4445
4640
|
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
4446
4641
|
planeIndex += 2;
|
|
4447
4642
|
}
|
|
4448
4643
|
return this;
|
|
4449
4644
|
}
|
|
4645
|
+
/** Replace planes from a view-projection matrix; validates before mutating. */
|
|
4646
|
+
fromViewProjection(matrix, options = {}) {
|
|
4647
|
+
const planes = extractFrustumPlanes(matrix, options);
|
|
4648
|
+
this.planes.splice(0, this.planes.length, ...planes);
|
|
4649
|
+
return this;
|
|
4650
|
+
}
|
|
4450
4651
|
/** Determines whether a bounding volume intersects the culling volume. */
|
|
4451
4652
|
computeVisibility(boundingVolume) {
|
|
4452
4653
|
let intersect2 = "inside";
|
|
@@ -4472,7 +4673,7 @@ var CullingVolume = class _CullingVolume {
|
|
|
4472
4673
|
* and that plane check can be skipped.
|
|
4473
4674
|
*/
|
|
4474
4675
|
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
4475
|
-
(0,
|
|
4676
|
+
(0, import_core13.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
|
|
4476
4677
|
if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
|
|
4477
4678
|
return parentPlaneMask;
|
|
4478
4679
|
}
|
|
@@ -4499,7 +4700,441 @@ CullingVolume.MASK_INSIDE = 0;
|
|
|
4499
4700
|
CullingVolume.MASK_INDETERMINATE = 2147483647;
|
|
4500
4701
|
|
|
4501
4702
|
// dist/culling/lib/ray.js
|
|
4502
|
-
var
|
|
4703
|
+
var import_core14 = require("@math.gl/core");
|
|
4704
|
+
|
|
4705
|
+
// dist/culling/queries.js
|
|
4706
|
+
function validateQueryPoint(point2, dimension2) {
|
|
4707
|
+
if (point2.length !== dimension2)
|
|
4708
|
+
throw new RangeError("Query dimension must match the index");
|
|
4709
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4710
|
+
if (!Number.isFinite(point2[i]))
|
|
4711
|
+
throw new RangeError("Coordinates must be finite");
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
function validateQueryDistance(distance) {
|
|
4715
|
+
if (Number.isNaN(distance) || distance < 0)
|
|
4716
|
+
throw new RangeError("Distance must be nonnegative");
|
|
4717
|
+
}
|
|
4718
|
+
function normalizeQueryDirection(direction2, dimension2) {
|
|
4719
|
+
validateQueryPoint(direction2, dimension2);
|
|
4720
|
+
const scale = Math.max(...Array.from(direction2, Math.abs));
|
|
4721
|
+
if (scale === 0)
|
|
4722
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4723
|
+
const scaled = Array.from(direction2, (x) => x / scale);
|
|
4724
|
+
const length = Math.hypot(...scaled);
|
|
4725
|
+
return scaled.map((x) => x / length);
|
|
4726
|
+
}
|
|
4727
|
+
function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
|
|
4728
|
+
const dimension2 = origin.length;
|
|
4729
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
4730
|
+
throw new RangeError("Bounds must be 2D or 3D");
|
|
4731
|
+
validateQueryPoint(origin, dimension2);
|
|
4732
|
+
validateQueryPoint(direction2, dimension2);
|
|
4733
|
+
validateQueryPoint(minimum, dimension2);
|
|
4734
|
+
validateQueryPoint(maximum, dimension2);
|
|
4735
|
+
validateQueryDistance(maxT);
|
|
4736
|
+
let near = 0, far = maxT, nonzero = false;
|
|
4737
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4738
|
+
if (minimum[i] > maximum[i])
|
|
4739
|
+
throw new RangeError("Bounds must be ordered");
|
|
4740
|
+
nonzero || (nonzero = direction2[i] !== 0);
|
|
4741
|
+
}
|
|
4742
|
+
if (!nonzero)
|
|
4743
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4744
|
+
for (let i = 0; i < dimension2; i++) {
|
|
4745
|
+
if (direction2[i] === 0) {
|
|
4746
|
+
if (origin[i] < minimum[i] || origin[i] > maximum[i])
|
|
4747
|
+
return null;
|
|
4748
|
+
continue;
|
|
4749
|
+
}
|
|
4750
|
+
let a = (minimum[i] - origin[i]) / direction2[i];
|
|
4751
|
+
let b = (maximum[i] - origin[i]) / direction2[i];
|
|
4752
|
+
if (a > b)
|
|
4753
|
+
[a, b] = [b, a];
|
|
4754
|
+
near = Math.max(near, a);
|
|
4755
|
+
far = Math.min(far, b);
|
|
4756
|
+
if (near > far)
|
|
4757
|
+
return null;
|
|
4758
|
+
}
|
|
4759
|
+
return Number.isFinite(near) ? near : null;
|
|
4760
|
+
}
|
|
4761
|
+
function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
|
|
4762
|
+
for (const point2 of [origin, direction2, a, b, c])
|
|
4763
|
+
validateQueryPoint(point2, 3);
|
|
4764
|
+
if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
|
|
4765
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4766
|
+
}
|
|
4767
|
+
const maxT = options.maxT ?? Infinity;
|
|
4768
|
+
validateQueryDistance(maxT);
|
|
4769
|
+
const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
4770
|
+
const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
4771
|
+
const p = cross4(direction2, e2);
|
|
4772
|
+
const determinant = dot2(e1, p);
|
|
4773
|
+
if (determinant === 0 || options.backfaceCulling && determinant < 0)
|
|
4774
|
+
return null;
|
|
4775
|
+
const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
|
|
4776
|
+
const u = dot2(offset, p) / determinant;
|
|
4777
|
+
if (u < 0 || u > 1)
|
|
4778
|
+
return null;
|
|
4779
|
+
const q = cross4(offset, e1);
|
|
4780
|
+
const v = dot2(direction2, q) / determinant;
|
|
4781
|
+
if (v < 0 || u + v > 1)
|
|
4782
|
+
return null;
|
|
4783
|
+
const t = dot2(e2, q) / determinant;
|
|
4784
|
+
if (!Number.isFinite(t) || t < 0 || t > maxT)
|
|
4785
|
+
return null;
|
|
4786
|
+
return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
|
|
4787
|
+
}
|
|
4788
|
+
function getClosestPointOnTriangle(point2, a, b, c) {
|
|
4789
|
+
for (const value of [point2, a, b, c])
|
|
4790
|
+
validateQueryPoint(value, 3);
|
|
4791
|
+
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
4792
|
+
const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
4793
|
+
const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
|
|
4794
|
+
const aa = dot2(ab, ab), bb = dot2(ac, ac), cc = dot2(ab, ac);
|
|
4795
|
+
const denominator = aa * bb - cc * cc;
|
|
4796
|
+
if (denominator > 0 && Number.isFinite(denominator)) {
|
|
4797
|
+
const u = (bb * dot2(ap, ab) - cc * dot2(ap, ac)) / denominator;
|
|
4798
|
+
const v = (aa * dot2(ap, ac) - cc * dot2(ap, ab)) / denominator;
|
|
4799
|
+
if (u >= 0 && v >= 0 && u + v <= 1) {
|
|
4800
|
+
return [
|
|
4801
|
+
a[0] + u * ab[0] + v * ac[0],
|
|
4802
|
+
a[1] + u * ab[1] + v * ac[1],
|
|
4803
|
+
a[2] + u * ab[2] + v * ac[2]
|
|
4804
|
+
];
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
4807
|
+
let best = [a[0], a[1], a[2]];
|
|
4808
|
+
let distance = Infinity;
|
|
4809
|
+
for (const [start, end] of [
|
|
4810
|
+
[a, b],
|
|
4811
|
+
[b, c],
|
|
4812
|
+
[c, a]
|
|
4813
|
+
]) {
|
|
4814
|
+
const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
|
|
4815
|
+
const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
|
|
4816
|
+
const squared = dot2(edge, edge);
|
|
4817
|
+
const t = squared > 0 ? Math.max(0, Math.min(1, dot2(offset, edge) / squared)) : 0;
|
|
4818
|
+
const candidate = [
|
|
4819
|
+
start[0] + t * edge[0],
|
|
4820
|
+
start[1] + t * edge[1],
|
|
4821
|
+
start[2] + t * edge[2]
|
|
4822
|
+
];
|
|
4823
|
+
const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
|
|
4824
|
+
if (d < distance) {
|
|
4825
|
+
distance = d;
|
|
4826
|
+
best = candidate;
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4829
|
+
return best;
|
|
4830
|
+
}
|
|
4831
|
+
function getClosestPointsOnSegments(a0, a1, b0, b1) {
|
|
4832
|
+
const frame = queryFrame([a0, a1, b0, b1]);
|
|
4833
|
+
const pair2 = closestSegments(...frame.points);
|
|
4834
|
+
const pointA = interpolatePoint(a0, a1, pair2.fractionA);
|
|
4835
|
+
const pointB = interpolatePoint(b0, b1, pair2.fractionB);
|
|
4836
|
+
return {
|
|
4837
|
+
distance: finiteDistance(pointA, pointB),
|
|
4838
|
+
pointA,
|
|
4839
|
+
pointB,
|
|
4840
|
+
fractionA: pair2.fractionA,
|
|
4841
|
+
fractionB: pair2.fractionB
|
|
4842
|
+
};
|
|
4843
|
+
}
|
|
4844
|
+
function getClosestPointsSegmentTriangle(start, end, a, b, c) {
|
|
4845
|
+
const frame = queryFrame([start, end, a, b, c]);
|
|
4846
|
+
const [s, e, va, vb, vc] = frame.points;
|
|
4847
|
+
const direction2 = subtract(e, s);
|
|
4848
|
+
if (direction2.some((value) => value !== 0)) {
|
|
4849
|
+
const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
|
|
4850
|
+
if (hit) {
|
|
4851
|
+
const point2 = interpolatePoint(start, end, hit.t);
|
|
4852
|
+
return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
|
|
4856
|
+
const consider = (point2, trianglePoint2, segmentFraction) => {
|
|
4857
|
+
const distance = Math.hypot(...subtract(point2, trianglePoint2));
|
|
4858
|
+
if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
|
|
4859
|
+
best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
|
|
4860
|
+
};
|
|
4861
|
+
consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
|
|
4862
|
+
consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
|
|
4863
|
+
for (const [v0, v1] of [
|
|
4864
|
+
[va, vb],
|
|
4865
|
+
[vb, vc],
|
|
4866
|
+
[vc, va]
|
|
4867
|
+
]) {
|
|
4868
|
+
const pair2 = closestSegments(s, e, v0, v1);
|
|
4869
|
+
consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
|
|
4870
|
+
}
|
|
4871
|
+
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)));
|
|
4872
|
+
if (!trianglePoint.every(Number.isFinite))
|
|
4873
|
+
throw new RangeError("Closest-point result overflow");
|
|
4874
|
+
const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
|
|
4875
|
+
return {
|
|
4876
|
+
distance: finiteDistance(segmentPoint, trianglePoint),
|
|
4877
|
+
segmentPoint,
|
|
4878
|
+
trianglePoint,
|
|
4879
|
+
segmentFraction: best.segmentFraction
|
|
4880
|
+
};
|
|
4881
|
+
}
|
|
4882
|
+
function queryFrame(input) {
|
|
4883
|
+
input.forEach((point2) => validateQueryPoint(point2, 3));
|
|
4884
|
+
const offsets = input.map((point2) => subtract(point2, input[0]));
|
|
4885
|
+
let scale = 0;
|
|
4886
|
+
for (const offset of offsets)
|
|
4887
|
+
for (const value of offset) {
|
|
4888
|
+
if (!Number.isFinite(value))
|
|
4889
|
+
throw new RangeError("Closest-point coordinate span overflow");
|
|
4890
|
+
scale = Math.max(scale, Math.abs(value));
|
|
4891
|
+
}
|
|
4892
|
+
scale || (scale = 1);
|
|
4893
|
+
return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
|
|
4894
|
+
}
|
|
4895
|
+
function closestSegments(a0, a1, b0, b1) {
|
|
4896
|
+
const da = subtract(a1, a0), db = subtract(b1, b0);
|
|
4897
|
+
const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
|
|
4898
|
+
const ua = da.map((value) => lengthA ? value / lengthA : 0);
|
|
4899
|
+
const ub = db.map((value) => lengthB ? value / lengthB : 0);
|
|
4900
|
+
let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
|
|
4901
|
+
const consider = (fractionA, fractionB) => {
|
|
4902
|
+
const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
|
|
4903
|
+
if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
|
|
4904
|
+
best = { distance, fractionA, fractionB };
|
|
4905
|
+
};
|
|
4906
|
+
for (const t of [0, 1]) {
|
|
4907
|
+
consider(t, lengthB ? clampUnit(dot2(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
|
|
4908
|
+
consider(lengthA ? clampUnit(dot2(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
|
|
4909
|
+
}
|
|
4910
|
+
const normal = cross4(ua, ub);
|
|
4911
|
+
const sine = Math.hypot(...normal);
|
|
4912
|
+
if (sine > 0) {
|
|
4913
|
+
const unit2 = normal.map((value) => value / sine);
|
|
4914
|
+
const offset = subtract(b0, a0);
|
|
4915
|
+
const fractionA = dot2(cross4(offset, ub), unit2) / sine / lengthA;
|
|
4916
|
+
const fractionB = dot2(cross4(offset, ua), unit2) / sine / lengthB;
|
|
4917
|
+
if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
|
|
4918
|
+
consider(fractionA, fractionB);
|
|
4919
|
+
}
|
|
4920
|
+
return best;
|
|
4921
|
+
}
|
|
4922
|
+
function subtract(a, b) {
|
|
4923
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
4924
|
+
}
|
|
4925
|
+
function interpolatePoint(a, b, t) {
|
|
4926
|
+
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])));
|
|
4927
|
+
}
|
|
4928
|
+
function clampUnit(value) {
|
|
4929
|
+
return Math.max(0, Math.min(1, value));
|
|
4930
|
+
}
|
|
4931
|
+
function finiteDistance(a, b) {
|
|
4932
|
+
const distance = Math.hypot(...subtract(a, b));
|
|
4933
|
+
if (!Number.isFinite(distance))
|
|
4934
|
+
throw new RangeError("Closest-point distance overflow");
|
|
4935
|
+
return distance;
|
|
4936
|
+
}
|
|
4937
|
+
function dot2(a, b) {
|
|
4938
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4939
|
+
}
|
|
4940
|
+
function cross4(a, b) {
|
|
4941
|
+
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]];
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4944
|
+
// dist/culling/geometric-queries.js
|
|
4945
|
+
var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
4946
|
+
var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4947
|
+
var cross5 = (a, b) => [
|
|
4948
|
+
a[1] * b[2] - a[2] * b[1],
|
|
4949
|
+
a[2] * b[0] - a[0] * b[2],
|
|
4950
|
+
a[0] * b[1] - a[1] * b[0]
|
|
4951
|
+
];
|
|
4952
|
+
var check = (...points) => {
|
|
4953
|
+
for (const p of points)
|
|
4954
|
+
validateQueryPoint(p, 3);
|
|
4955
|
+
};
|
|
4956
|
+
function output(out, values) {
|
|
4957
|
+
if (out.length < values.length)
|
|
4958
|
+
throw new RangeError("Result buffer is too short");
|
|
4959
|
+
const copy2 = Array.from(values);
|
|
4960
|
+
for (let i = 0; i < copy2.length; i++)
|
|
4961
|
+
out[i] = copy2[i];
|
|
4962
|
+
return out;
|
|
4963
|
+
}
|
|
4964
|
+
function direction(d) {
|
|
4965
|
+
check(d);
|
|
4966
|
+
if (Math.hypot(d[0], d[1], d[2]) === 0)
|
|
4967
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
4968
|
+
}
|
|
4969
|
+
function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
|
|
4970
|
+
check(origin);
|
|
4971
|
+
direction(dir);
|
|
4972
|
+
if (!Number.isFinite(t) || t < 0)
|
|
4973
|
+
throw new RangeError("Ray parameter must be finite and nonnegative");
|
|
4974
|
+
return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
|
|
4975
|
+
}
|
|
4976
|
+
function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
|
|
4977
|
+
check(point2, origin);
|
|
4978
|
+
direction(dir);
|
|
4979
|
+
const unit2 = normalizeQueryDirection(dir, 3);
|
|
4980
|
+
const distance = Math.max(0, dot3(sub2(point2, origin), unit2));
|
|
4981
|
+
return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit2[i]));
|
|
4982
|
+
}
|
|
4983
|
+
function distanceToRay(point2, origin, dir) {
|
|
4984
|
+
const p = getClosestPointOnRay(point2, origin, dir);
|
|
4985
|
+
return Math.hypot(...sub2(point2, p));
|
|
4986
|
+
}
|
|
4987
|
+
function getClosestPointsRaySegment(origin, dir, a, b) {
|
|
4988
|
+
check(origin, a, b);
|
|
4989
|
+
direction(dir);
|
|
4990
|
+
const unit2 = normalizeQueryDirection(dir, 3);
|
|
4991
|
+
const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
|
|
4992
|
+
const edge = sub2(b, a), offset = sub2(origin, a);
|
|
4993
|
+
const segmentLength = Math.hypot(...edge);
|
|
4994
|
+
const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
|
|
4995
|
+
const bb = dot3(unit2, segmentUnit), dd = dot3(unit2, offset), ee = dot3(segmentUnit, offset);
|
|
4996
|
+
const candidates = [
|
|
4997
|
+
[0, Math.max(0, Math.min(segmentLength, ee))],
|
|
4998
|
+
[Math.max(0, -dd), 0],
|
|
4999
|
+
[Math.max(0, bb * segmentLength - dd), segmentLength]
|
|
5000
|
+
];
|
|
5001
|
+
const normal = cross5(unit2, segmentUnit);
|
|
5002
|
+
const sine = Math.hypot(...normal);
|
|
5003
|
+
if (segmentLength > 0 && sine > 0) {
|
|
5004
|
+
const normalUnit = normal.map((value) => value / sine);
|
|
5005
|
+
const separation = sub2(a, origin);
|
|
5006
|
+
const t = dot3(cross5(separation, segmentUnit), normalUnit) / sine;
|
|
5007
|
+
const u = dot3(cross5(separation, unit2), normalUnit) / sine;
|
|
5008
|
+
if (t >= 0 && u >= 0 && u <= segmentLength)
|
|
5009
|
+
candidates.push([t, u]);
|
|
5010
|
+
}
|
|
5011
|
+
let best;
|
|
5012
|
+
for (const [t, u] of candidates) {
|
|
5013
|
+
const rayPoint = [
|
|
5014
|
+
origin[0] + t * unit2[0],
|
|
5015
|
+
origin[1] + t * unit2[1],
|
|
5016
|
+
origin[2] + t * unit2[2]
|
|
5017
|
+
];
|
|
5018
|
+
const segmentPoint = [
|
|
5019
|
+
a[0] + u * segmentUnit[0],
|
|
5020
|
+
a[1] + u * segmentUnit[1],
|
|
5021
|
+
a[2] + u * segmentUnit[2]
|
|
5022
|
+
];
|
|
5023
|
+
const distance = Math.hypot(...sub2(rayPoint, segmentPoint));
|
|
5024
|
+
if (!best || distance < best.distance)
|
|
5025
|
+
best = {
|
|
5026
|
+
rayPoint,
|
|
5027
|
+
segmentPoint,
|
|
5028
|
+
rayParameter: t / directionLength,
|
|
5029
|
+
segmentFraction: segmentLength ? u / segmentLength : 0,
|
|
5030
|
+
distance
|
|
5031
|
+
};
|
|
5032
|
+
}
|
|
5033
|
+
return best;
|
|
5034
|
+
}
|
|
5035
|
+
function transformRay(origin, dir, matrix) {
|
|
5036
|
+
check(origin);
|
|
5037
|
+
direction(dir);
|
|
5038
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
|
|
5039
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
5040
|
+
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]);
|
|
5041
|
+
const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
|
|
5042
|
+
check(transformed.origin);
|
|
5043
|
+
direction(transformed.direction);
|
|
5044
|
+
return transformed;
|
|
5045
|
+
}
|
|
5046
|
+
function triangle(a, b, c) {
|
|
5047
|
+
check(a, b, c);
|
|
5048
|
+
const ab = sub2(b, a), ac = sub2(c, a);
|
|
5049
|
+
const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
|
|
5050
|
+
const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
|
|
5051
|
+
return { u, v, scale, normal: cross5(u, v) };
|
|
5052
|
+
}
|
|
5053
|
+
function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
|
|
5054
|
+
check(point2);
|
|
5055
|
+
const { u, v, scale, normal } = triangle(a, b, c), denominator = dot3(normal, normal);
|
|
5056
|
+
if (denominator === 0)
|
|
5057
|
+
return null;
|
|
5058
|
+
const p = sub2(point2, a).map((x) => x / scale);
|
|
5059
|
+
const second = dot3(cross5(p, v), normal) / denominator;
|
|
5060
|
+
const third = dot3(cross5(u, p), normal) / denominator;
|
|
5061
|
+
return output(out, [1 - second - third, second, third]);
|
|
5062
|
+
}
|
|
5063
|
+
function getTriangleArea(a, b, c) {
|
|
5064
|
+
const { normal, scale } = triangle(a, b, c);
|
|
5065
|
+
return Math.hypot(...normal) * scale * scale / 2;
|
|
5066
|
+
}
|
|
5067
|
+
function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
|
|
5068
|
+
const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
|
|
5069
|
+
return output(out, normal.map((x) => length ? x / length : 0));
|
|
5070
|
+
}
|
|
5071
|
+
function isTriangleFrontFacing(a, b, c, dir) {
|
|
5072
|
+
direction(dir);
|
|
5073
|
+
return dot3(triangle(a, b, c).normal, dir) < 0;
|
|
5074
|
+
}
|
|
5075
|
+
function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
|
|
5076
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
5077
|
+
throw new RangeError("Invalid tolerance");
|
|
5078
|
+
const weights = getTriangleBarycentric(point2, a, b, c);
|
|
5079
|
+
if (!weights)
|
|
5080
|
+
return false;
|
|
5081
|
+
const { normal, scale } = triangle(a, b, c);
|
|
5082
|
+
const distance = Math.abs(dot3(sub2(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
|
|
5083
|
+
return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
|
|
5084
|
+
}
|
|
5085
|
+
function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
|
|
5086
|
+
check(weights);
|
|
5087
|
+
if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
|
|
5088
|
+
throw new RangeError("Expected matching finite attributes");
|
|
5089
|
+
return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
|
|
5090
|
+
}
|
|
5091
|
+
function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
|
|
5092
|
+
check(start, end);
|
|
5093
|
+
direction(normal);
|
|
5094
|
+
if (!Number.isFinite(constant))
|
|
5095
|
+
throw new RangeError("Plane constant must be finite");
|
|
5096
|
+
const a = dot3(normal, start) + constant, b = dot3(normal, end) + constant;
|
|
5097
|
+
if (a === 0)
|
|
5098
|
+
return output(out, start);
|
|
5099
|
+
if (b === 0)
|
|
5100
|
+
return output(out, end);
|
|
5101
|
+
if (a > 0 === b > 0)
|
|
5102
|
+
return null;
|
|
5103
|
+
const t = a / (a - b);
|
|
5104
|
+
return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
|
|
5105
|
+
}
|
|
5106
|
+
function triangleIntersectsBounds(a, b, c, minimum, maximum) {
|
|
5107
|
+
check(a, b, c, minimum, maximum);
|
|
5108
|
+
if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
|
|
5109
|
+
return false;
|
|
5110
|
+
const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
|
|
5111
|
+
const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
|
|
5112
|
+
const vertices = [a, b, c].map((p) => sub2(p, center));
|
|
5113
|
+
const edges = [sub2(b, a), sub2(c, b), sub2(a, c)];
|
|
5114
|
+
const basis = [
|
|
5115
|
+
[1, 0, 0],
|
|
5116
|
+
[0, 1, 0],
|
|
5117
|
+
[0, 0, 1]
|
|
5118
|
+
];
|
|
5119
|
+
const axes = [
|
|
5120
|
+
...basis,
|
|
5121
|
+
cross5(edges[0], edges[1]),
|
|
5122
|
+
...edges.flatMap((e) => basis.map((axis) => cross5(e, axis)))
|
|
5123
|
+
];
|
|
5124
|
+
for (const axis of axes) {
|
|
5125
|
+
const length = Math.hypot(...axis);
|
|
5126
|
+
if (!length)
|
|
5127
|
+
continue;
|
|
5128
|
+
const unit2 = axis.map((x) => x / length);
|
|
5129
|
+
const projections = vertices.map((v) => dot3(v, unit2));
|
|
5130
|
+
const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit2[i]), 0);
|
|
5131
|
+
if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
|
|
5132
|
+
return false;
|
|
5133
|
+
}
|
|
5134
|
+
return true;
|
|
5135
|
+
}
|
|
5136
|
+
|
|
5137
|
+
// dist/culling/lib/ray.js
|
|
4503
5138
|
var Ray = class {
|
|
4504
5139
|
/**
|
|
4505
5140
|
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
@@ -4507,25 +5142,44 @@ var Ray = class {
|
|
|
4507
5142
|
* @param [origin=Vector3] The origin of the ray.
|
|
4508
5143
|
* @param [direction=Vector3] The direction of the ray.
|
|
4509
5144
|
*/
|
|
4510
|
-
constructor(origin,
|
|
5145
|
+
constructor(origin, direction2) {
|
|
4511
5146
|
if (origin)
|
|
4512
5147
|
origin = origin.clone();
|
|
4513
5148
|
else
|
|
4514
|
-
origin = new
|
|
4515
|
-
if (
|
|
4516
|
-
|
|
5149
|
+
origin = new import_core14.Vector3();
|
|
5150
|
+
if (direction2)
|
|
5151
|
+
direction2 = direction2.clone().normalize();
|
|
4517
5152
|
else
|
|
4518
|
-
|
|
5153
|
+
direction2 = new import_core14.Vector3();
|
|
4519
5154
|
this.origin = origin;
|
|
4520
|
-
this.direction =
|
|
5155
|
+
this.direction = direction2;
|
|
5156
|
+
}
|
|
5157
|
+
at(t, result = new import_core14.Vector3()) {
|
|
5158
|
+
getRayPoint(this.origin, this.direction, t, result);
|
|
5159
|
+
return result;
|
|
5160
|
+
}
|
|
5161
|
+
closestPointTo(point2, result = new import_core14.Vector3()) {
|
|
5162
|
+
getClosestPointOnRay(point2, this.origin, this.direction, result);
|
|
5163
|
+
return result;
|
|
5164
|
+
}
|
|
5165
|
+
distanceTo(point2) {
|
|
5166
|
+
return distanceToRay(point2, this.origin, this.direction);
|
|
5167
|
+
}
|
|
5168
|
+
/** Transform and renormalize: subsequent parameters are distances in the new space. */
|
|
5169
|
+
transform(matrix) {
|
|
5170
|
+
const ray = transformRay(this.origin, this.direction, matrix);
|
|
5171
|
+
const normalized2 = normalizeQueryDirection(ray.direction, 3);
|
|
5172
|
+
this.origin.copy(ray.origin);
|
|
5173
|
+
this.direction.copy(normalized2);
|
|
5174
|
+
return this;
|
|
4521
5175
|
}
|
|
4522
5176
|
};
|
|
4523
5177
|
|
|
4524
5178
|
// dist/culling/lib/shapes/implicit-shape.js
|
|
4525
|
-
var
|
|
5179
|
+
var import_core15 = require("@math.gl/core");
|
|
4526
5180
|
var ImplicitShapeBase = class {
|
|
4527
5181
|
constructor(matrix) {
|
|
4528
|
-
this.matrix = new
|
|
5182
|
+
this.matrix = new import_core15.Matrix4();
|
|
4529
5183
|
if (matrix)
|
|
4530
5184
|
this.matrix.copy(matrix);
|
|
4531
5185
|
validateAffineMatrix(this.matrix);
|
|
@@ -4540,23 +5194,23 @@ var ImplicitShapeBase = class {
|
|
|
4540
5194
|
return true;
|
|
4541
5195
|
}
|
|
4542
5196
|
transform(transform) {
|
|
4543
|
-
const next = new
|
|
5197
|
+
const next = new import_core15.Matrix4().copy(transform);
|
|
4544
5198
|
validateAffineMatrix(next);
|
|
4545
5199
|
this.matrix.multiplyLeft(next);
|
|
4546
5200
|
validateAffineMatrix(this.matrix);
|
|
4547
5201
|
this.inverseMatrix.copy(this.matrix).invert();
|
|
4548
5202
|
return this;
|
|
4549
5203
|
}
|
|
4550
|
-
containsPoint(
|
|
4551
|
-
return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(
|
|
5204
|
+
containsPoint(point2) {
|
|
5205
|
+
return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
|
|
4552
5206
|
}
|
|
4553
|
-
distanceSquaredTo(
|
|
4554
|
-
const distance = this.distanceTo(
|
|
5207
|
+
distanceSquaredTo(point2) {
|
|
5208
|
+
const distance = this.distanceTo(point2);
|
|
4555
5209
|
return distance * distance;
|
|
4556
5210
|
}
|
|
4557
5211
|
/** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
|
|
4558
|
-
distanceTo(
|
|
4559
|
-
const localPoint = this.inverseMatrix.transformAsPoint(
|
|
5212
|
+
distanceTo(point2) {
|
|
5213
|
+
const localPoint = this.inverseMatrix.transformAsPoint(point2);
|
|
4560
5214
|
const localDistance = this.distanceToLocalPoint(localPoint);
|
|
4561
5215
|
const scales = this.matrix.getScale();
|
|
4562
5216
|
return localDistance * Math.min(scales[0], scales[1], scales[2]);
|
|
@@ -4578,20 +5232,20 @@ var ImplicitShapeBase = class {
|
|
|
4578
5232
|
const hit = this.intersectLocalRay(localOrigin, localDirection);
|
|
4579
5233
|
if (!hit || hit.distance < 0)
|
|
4580
5234
|
return void 0;
|
|
4581
|
-
const
|
|
5235
|
+
const point2 = new import_core15.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
|
|
4582
5236
|
const inverse = this.inverseMatrix;
|
|
4583
|
-
const normal = new
|
|
4584
|
-
return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
|
|
5237
|
+
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();
|
|
5238
|
+
return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
|
|
4585
5239
|
}
|
|
4586
5240
|
getAxisAlignedBoundingBox() {
|
|
4587
|
-
const minimum = new
|
|
4588
|
-
const maximum = new
|
|
5241
|
+
const minimum = new import_core15.Vector3();
|
|
5242
|
+
const maximum = new import_core15.Vector3();
|
|
4589
5243
|
for (let axis = 0; axis < 3; axis++) {
|
|
4590
|
-
const
|
|
4591
|
-
|
|
4592
|
-
maximum[axis] = this.getSupportPoint(
|
|
4593
|
-
|
|
4594
|
-
minimum[axis] = this.getSupportPoint(
|
|
5244
|
+
const direction2 = [0, 0, 0];
|
|
5245
|
+
direction2[axis] = 1;
|
|
5246
|
+
maximum[axis] = this.getSupportPoint(direction2)[axis];
|
|
5247
|
+
direction2[axis] = -1;
|
|
5248
|
+
minimum[axis] = this.getSupportPoint(direction2)[axis];
|
|
4595
5249
|
}
|
|
4596
5250
|
return new AxisAlignedBoundingBox(minimum, maximum);
|
|
4597
5251
|
}
|
|
@@ -4608,7 +5262,7 @@ var ImplicitShapeBase = class {
|
|
|
4608
5262
|
matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
|
|
4609
5263
|
matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
|
|
4610
5264
|
];
|
|
4611
|
-
return new
|
|
5265
|
+
return new import_core15.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
|
|
4612
5266
|
}
|
|
4613
5267
|
};
|
|
4614
5268
|
function validateAffineMatrix(matrix) {
|
|
@@ -4618,7 +5272,7 @@ function validateAffineMatrix(matrix) {
|
|
|
4618
5272
|
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) {
|
|
4619
5273
|
throw new Error("Shape matrix must be affine");
|
|
4620
5274
|
}
|
|
4621
|
-
if (Math.abs(new
|
|
5275
|
+
if (Math.abs(new import_core15.Matrix4().copy(matrix).determinant()) < 1e-15)
|
|
4622
5276
|
throw new Error("Shape matrix must be invertible");
|
|
4623
5277
|
}
|
|
4624
5278
|
function solveQuadratic(a, b, c) {
|
|
@@ -4637,19 +5291,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
|
|
|
4637
5291
|
const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
|
|
4638
5292
|
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
|
|
4639
5293
|
}
|
|
4640
|
-
function closestDistanceToCircleArc2D(px, py, centerY,
|
|
4641
|
-
if (
|
|
5294
|
+
function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
|
|
5295
|
+
if (radius2 === 0)
|
|
4642
5296
|
return Math.hypot(px, py - centerY);
|
|
4643
5297
|
const dx = px;
|
|
4644
5298
|
const dy = py - centerY;
|
|
4645
5299
|
const length = Math.hypot(dx, dy);
|
|
4646
5300
|
const normalY = length ? dy / length : 0;
|
|
4647
5301
|
if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
|
|
4648
|
-
return Math.abs(length -
|
|
5302
|
+
return Math.abs(length - radius2);
|
|
4649
5303
|
}
|
|
4650
|
-
const minimumRadius =
|
|
4651
|
-
const maximumRadius =
|
|
4652
|
-
return Math.min(Math.hypot(px - minimumRadius, py - (centerY +
|
|
5304
|
+
const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
|
|
5305
|
+
const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
|
|
5306
|
+
return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
|
|
4653
5307
|
}
|
|
4654
5308
|
|
|
4655
5309
|
// dist/culling/lib/shapes/box-shape.js
|
|
@@ -4669,28 +5323,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
|
|
|
4669
5323
|
equals(shape) {
|
|
4670
5324
|
return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
|
|
4671
5325
|
}
|
|
4672
|
-
containsLocalPoint(
|
|
4673
|
-
return
|
|
5326
|
+
containsLocalPoint(point2) {
|
|
5327
|
+
return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
|
|
4674
5328
|
}
|
|
4675
|
-
distanceToLocalPoint(
|
|
4676
|
-
return Math.hypot(...
|
|
5329
|
+
distanceToLocalPoint(point2) {
|
|
5330
|
+
return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
|
|
4677
5331
|
}
|
|
4678
|
-
supportLocal(
|
|
4679
|
-
return
|
|
5332
|
+
supportLocal(direction2) {
|
|
5333
|
+
return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
|
|
4680
5334
|
}
|
|
4681
|
-
intersectLocalRay(origin,
|
|
5335
|
+
intersectLocalRay(origin, direction2) {
|
|
4682
5336
|
let near = -Infinity;
|
|
4683
5337
|
let far = Infinity;
|
|
4684
5338
|
let nearAxis = 0;
|
|
4685
5339
|
let farAxis = 0;
|
|
4686
5340
|
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
4687
|
-
if (Math.abs(
|
|
5341
|
+
if (Math.abs(direction2[axis2]) < 1e-15) {
|
|
4688
5342
|
if (Math.abs(origin[axis2]) > this.halfSize[axis2])
|
|
4689
5343
|
return void 0;
|
|
4690
5344
|
continue;
|
|
4691
5345
|
}
|
|
4692
|
-
let t1 = (-this.halfSize[axis2] - origin[axis2]) /
|
|
4693
|
-
let t2 = (this.halfSize[axis2] - origin[axis2]) /
|
|
5346
|
+
let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
5347
|
+
let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
4694
5348
|
if (t1 > t2)
|
|
4695
5349
|
[t1, t2] = [t2, t1];
|
|
4696
5350
|
if (t1 > near) {
|
|
@@ -4708,7 +5362,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
|
|
|
4708
5362
|
if (distance < 0 || !Number.isFinite(distance))
|
|
4709
5363
|
return void 0;
|
|
4710
5364
|
const axis = near >= 0 ? nearAxis : farAxis;
|
|
4711
|
-
const pointCoordinate = origin[axis] + distance *
|
|
5365
|
+
const pointCoordinate = origin[axis] + distance * direction2[axis];
|
|
4712
5366
|
const normal = [0, 0, 0];
|
|
4713
5367
|
normal[axis] = pointCoordinate < 0 ? -1 : 1;
|
|
4714
5368
|
return { distance, normal };
|
|
@@ -4742,74 +5396,74 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
|
|
|
4742
5396
|
equals(shape) {
|
|
4743
5397
|
return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
4744
5398
|
}
|
|
4745
|
-
containsLocalPoint(
|
|
5399
|
+
containsLocalPoint(point2) {
|
|
4746
5400
|
const profile = this.getProfile();
|
|
4747
|
-
const radial2 = Math.hypot(
|
|
5401
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4748
5402
|
if (profile.sphere)
|
|
4749
|
-
return Math.hypot(radial2,
|
|
4750
|
-
if (
|
|
4751
|
-
return Math.hypot(radial2,
|
|
4752
|
-
if (
|
|
4753
|
-
return Math.hypot(radial2,
|
|
4754
|
-
const t = (
|
|
5403
|
+
return Math.hypot(radial2, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
|
|
5404
|
+
if (point2[1] < profile.bottom.y)
|
|
5405
|
+
return Math.hypot(radial2, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
|
|
5406
|
+
if (point2[1] > profile.top.y)
|
|
5407
|
+
return Math.hypot(radial2, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
|
|
5408
|
+
const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
4755
5409
|
return radial2 <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
|
|
4756
5410
|
}
|
|
4757
|
-
distanceToLocalPoint(
|
|
4758
|
-
if (this.containsLocalPoint(
|
|
5411
|
+
distanceToLocalPoint(point2) {
|
|
5412
|
+
if (this.containsLocalPoint(point2))
|
|
4759
5413
|
return 0;
|
|
4760
5414
|
const profile = this.getProfile();
|
|
4761
|
-
const radial2 = Math.hypot(
|
|
5415
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4762
5416
|
if (profile.sphere)
|
|
4763
|
-
return Math.max(0, Math.hypot(radial2,
|
|
5417
|
+
return Math.max(0, Math.hypot(radial2, point2[1] - profile.sphere.center) - profile.sphere.radius);
|
|
4764
5418
|
const delta = this.radiusTop - this.radiusBottom;
|
|
4765
5419
|
const sideNormalY = -delta / this.height;
|
|
4766
|
-
const bottomArc = closestDistanceToCircleArc2D(radial2,
|
|
4767
|
-
const topArc = closestDistanceToCircleArc2D(radial2,
|
|
4768
|
-
const side = closestDistanceToSegment2D(radial2,
|
|
5420
|
+
const bottomArc = closestDistanceToCircleArc2D(radial2, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
|
|
5421
|
+
const topArc = closestDistanceToCircleArc2D(radial2, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
|
|
5422
|
+
const side = closestDistanceToSegment2D(radial2, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
|
|
4769
5423
|
return Math.min(bottomArc, topArc, side);
|
|
4770
5424
|
}
|
|
4771
|
-
supportLocal(
|
|
4772
|
-
const length = Math.hypot(...
|
|
4773
|
-
const
|
|
5425
|
+
supportLocal(direction2) {
|
|
5426
|
+
const length = Math.hypot(...direction2);
|
|
5427
|
+
const unit2 = length ? direction2.map((value) => value / length) : [1, 0, 0];
|
|
4774
5428
|
const bottom = [
|
|
4775
|
-
|
|
4776
|
-
-this.height / 2 +
|
|
4777
|
-
|
|
5429
|
+
unit2[0] * this.radiusBottom,
|
|
5430
|
+
-this.height / 2 + unit2[1] * this.radiusBottom,
|
|
5431
|
+
unit2[2] * this.radiusBottom
|
|
4778
5432
|
];
|
|
4779
5433
|
const top = [
|
|
4780
|
-
|
|
4781
|
-
this.height / 2 +
|
|
4782
|
-
|
|
5434
|
+
unit2[0] * this.radiusTop,
|
|
5435
|
+
this.height / 2 + unit2[1] * this.radiusTop,
|
|
5436
|
+
unit2[2] * this.radiusTop
|
|
4783
5437
|
];
|
|
4784
|
-
return
|
|
5438
|
+
return dot4(top, direction2) >= dot4(bottom, direction2) ? top : bottom;
|
|
4785
5439
|
}
|
|
4786
|
-
intersectLocalRay(origin,
|
|
5440
|
+
intersectLocalRay(origin, direction2) {
|
|
4787
5441
|
const profile = this.getProfile();
|
|
4788
5442
|
if (profile.sphere)
|
|
4789
|
-
return intersectSphere(origin,
|
|
5443
|
+
return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
|
|
4790
5444
|
const candidates = [];
|
|
4791
5445
|
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
4792
5446
|
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
4793
5447
|
const radialAtOrigin = intercept + slope * origin[1];
|
|
4794
|
-
const radialAlongRay = slope *
|
|
4795
|
-
for (const distance of solveQuadratic(
|
|
4796
|
-
const y = origin[1] + distance *
|
|
5448
|
+
const radialAlongRay = slope * direction2[1];
|
|
5449
|
+
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)) {
|
|
5450
|
+
const y = origin[1] + distance * direction2[1];
|
|
4797
5451
|
if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
|
|
4798
|
-
const x = origin[0] + distance *
|
|
4799
|
-
const z = origin[2] + distance *
|
|
5452
|
+
const x = origin[0] + distance * direction2[0];
|
|
5453
|
+
const z = origin[2] + distance * direction2[2];
|
|
4800
5454
|
const radial2 = Math.hypot(x, z) || 1;
|
|
4801
5455
|
const normal = [x / radial2, -slope, z / radial2];
|
|
4802
5456
|
const length = Math.hypot(...normal);
|
|
4803
5457
|
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
4804
5458
|
}
|
|
4805
5459
|
}
|
|
4806
|
-
for (const bottomHit of intersectSphereRoots(origin,
|
|
4807
|
-
const y = origin[1] + bottomHit.distance *
|
|
5460
|
+
for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
|
|
5461
|
+
const y = origin[1] + bottomHit.distance * direction2[1];
|
|
4808
5462
|
if (y <= profile.bottom.y + EPSILON2)
|
|
4809
5463
|
candidates.push(bottomHit);
|
|
4810
5464
|
}
|
|
4811
|
-
for (const topHit of intersectSphereRoots(origin,
|
|
4812
|
-
const y = origin[1] + topHit.distance *
|
|
5465
|
+
for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
|
|
5466
|
+
const y = origin[1] + topHit.distance * direction2[1];
|
|
4813
5467
|
if (y >= profile.top.y - EPSILON2)
|
|
4814
5468
|
candidates.push(topHit);
|
|
4815
5469
|
}
|
|
@@ -4840,19 +5494,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
|
|
|
4840
5494
|
};
|
|
4841
5495
|
}
|
|
4842
5496
|
};
|
|
4843
|
-
function intersectSphere(origin,
|
|
4844
|
-
return intersectSphereRoots(origin,
|
|
5497
|
+
function intersectSphere(origin, direction2, centerY, radius2) {
|
|
5498
|
+
return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
|
|
4845
5499
|
}
|
|
4846
|
-
function intersectSphereRoots(origin,
|
|
4847
|
-
if (
|
|
5500
|
+
function intersectSphereRoots(origin, direction2, centerY, radius2) {
|
|
5501
|
+
if (radius2 === 0)
|
|
4848
5502
|
return [];
|
|
4849
5503
|
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
4850
|
-
return solveQuadratic(
|
|
5504
|
+
return solveQuadratic(dot4(direction2, direction2), 2 * dot4(relative, direction2), dot4(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
|
|
4851
5505
|
distance,
|
|
4852
|
-
normal: relative.map((value, i) => (value + distance *
|
|
5506
|
+
normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
|
|
4853
5507
|
}));
|
|
4854
5508
|
}
|
|
4855
|
-
function
|
|
5509
|
+
function dot4(a, b) {
|
|
4856
5510
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4857
5511
|
}
|
|
4858
5512
|
|
|
@@ -4883,61 +5537,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
|
|
|
4883
5537
|
equals(shape) {
|
|
4884
5538
|
return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
4885
5539
|
}
|
|
4886
|
-
containsLocalPoint(
|
|
5540
|
+
containsLocalPoint(point2) {
|
|
4887
5541
|
const half = this.height / 2;
|
|
4888
|
-
if (
|
|
5542
|
+
if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
|
|
4889
5543
|
return false;
|
|
4890
|
-
const t = (
|
|
4891
|
-
const
|
|
4892
|
-
return Math.hypot(
|
|
5544
|
+
const t = (point2[1] + half) / this.height;
|
|
5545
|
+
const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
5546
|
+
return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
|
|
4893
5547
|
}
|
|
4894
|
-
distanceToLocalPoint(
|
|
4895
|
-
if (this.containsLocalPoint(
|
|
5548
|
+
distanceToLocalPoint(point2) {
|
|
5549
|
+
if (this.containsLocalPoint(point2))
|
|
4896
5550
|
return 0;
|
|
4897
|
-
const radial2 = Math.hypot(
|
|
5551
|
+
const radial2 = Math.hypot(point2[0], point2[2]);
|
|
4898
5552
|
const half = this.height / 2;
|
|
4899
|
-
const side = closestDistanceToSegment2D(radial2,
|
|
4900
|
-
const bottom = closestDistanceToSegment2D(radial2,
|
|
4901
|
-
const top = closestDistanceToSegment2D(radial2,
|
|
5553
|
+
const side = closestDistanceToSegment2D(radial2, point2[1], this.radiusBottom, -half, this.radiusTop, half);
|
|
5554
|
+
const bottom = closestDistanceToSegment2D(radial2, point2[1], 0, -half, this.radiusBottom, -half);
|
|
5555
|
+
const top = closestDistanceToSegment2D(radial2, point2[1], 0, half, this.radiusTop, half);
|
|
4902
5556
|
return Math.min(side, bottom, top);
|
|
4903
5557
|
}
|
|
4904
|
-
supportLocal(
|
|
4905
|
-
const radialLength = Math.hypot(
|
|
4906
|
-
const x = radialLength ?
|
|
4907
|
-
const z = radialLength ?
|
|
5558
|
+
supportLocal(direction2) {
|
|
5559
|
+
const radialLength = Math.hypot(direction2[0], direction2[2]);
|
|
5560
|
+
const x = radialLength ? direction2[0] / radialLength : 1;
|
|
5561
|
+
const z = radialLength ? direction2[2] / radialLength : 0;
|
|
4908
5562
|
const half = this.height / 2;
|
|
4909
|
-
const bottomValue = radialLength * this.radiusBottom -
|
|
4910
|
-
const topValue = radialLength * this.radiusTop +
|
|
5563
|
+
const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
|
|
5564
|
+
const topValue = radialLength * this.radiusTop + direction2[1] * half;
|
|
4911
5565
|
return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
4912
5566
|
}
|
|
4913
|
-
intersectLocalRay(origin,
|
|
5567
|
+
intersectLocalRay(origin, direction2) {
|
|
4914
5568
|
const half = this.height / 2;
|
|
4915
5569
|
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
4916
5570
|
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
4917
5571
|
const radialAtOrigin = intercept + slope * origin[1];
|
|
4918
|
-
const radialAlongRay = slope *
|
|
5572
|
+
const radialAlongRay = slope * direction2[1];
|
|
4919
5573
|
const candidates = [];
|
|
4920
|
-
const roots = solveQuadratic(
|
|
5574
|
+
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);
|
|
4921
5575
|
for (const distance of roots) {
|
|
4922
|
-
const y = origin[1] + distance *
|
|
5576
|
+
const y = origin[1] + distance * direction2[1];
|
|
4923
5577
|
if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
|
|
4924
|
-
const x = origin[0] + distance *
|
|
4925
|
-
const z = origin[2] + distance *
|
|
5578
|
+
const x = origin[0] + distance * direction2[0];
|
|
5579
|
+
const z = origin[2] + distance * direction2[2];
|
|
4926
5580
|
const radial2 = Math.hypot(x, z) || 1;
|
|
4927
5581
|
const normal = [x / radial2, -slope, z / radial2];
|
|
4928
5582
|
const length = Math.hypot(...normal);
|
|
4929
5583
|
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
4930
5584
|
}
|
|
4931
5585
|
}
|
|
4932
|
-
if (Math.abs(
|
|
4933
|
-
for (const [y,
|
|
5586
|
+
if (Math.abs(direction2[1]) > 1e-15) {
|
|
5587
|
+
for (const [y, radius2, normalY] of [
|
|
4934
5588
|
[-half, this.radiusBottom, -1],
|
|
4935
5589
|
[half, this.radiusTop, 1]
|
|
4936
5590
|
]) {
|
|
4937
|
-
const distance = (y - origin[1]) /
|
|
4938
|
-
const x = origin[0] + distance *
|
|
4939
|
-
const z = origin[2] + distance *
|
|
4940
|
-
if (distance >= 0 && Math.hypot(x, z) <=
|
|
5591
|
+
const distance = (y - origin[1]) / direction2[1];
|
|
5592
|
+
const x = origin[0] + distance * direction2[0];
|
|
5593
|
+
const z = origin[2] + distance * direction2[2];
|
|
5594
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
|
|
4941
5595
|
candidates.push({ distance, normal: [0, normalY, 0] });
|
|
4942
5596
|
}
|
|
4943
5597
|
}
|
|
@@ -4946,7 +5600,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
|
|
|
4946
5600
|
};
|
|
4947
5601
|
|
|
4948
5602
|
// dist/culling/lib/shapes/plane-shape.js
|
|
4949
|
-
var
|
|
5603
|
+
var import_core16 = require("@math.gl/core");
|
|
4950
5604
|
var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
4951
5605
|
constructor(props = {}) {
|
|
4952
5606
|
super(props.matrix);
|
|
@@ -4964,23 +5618,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
|
4964
5618
|
equals(shape) {
|
|
4965
5619
|
return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
|
|
4966
5620
|
}
|
|
4967
|
-
containsLocalPoint(
|
|
4968
|
-
return
|
|
5621
|
+
containsLocalPoint(point2) {
|
|
5622
|
+
return point2[1] <= 1e-12;
|
|
4969
5623
|
}
|
|
4970
|
-
distanceToLocalPoint(
|
|
4971
|
-
return Math.max(0,
|
|
5624
|
+
distanceToLocalPoint(point2) {
|
|
5625
|
+
return Math.max(0, point2[1]);
|
|
4972
5626
|
}
|
|
4973
5627
|
supportLocal() {
|
|
4974
5628
|
throw new Error("An unbounded plane half-space has no finite support point");
|
|
4975
5629
|
}
|
|
4976
|
-
intersectLocalRay(origin,
|
|
4977
|
-
if (Math.abs(
|
|
5630
|
+
intersectLocalRay(origin, direction2) {
|
|
5631
|
+
if (Math.abs(direction2[1]) < 1e-15)
|
|
4978
5632
|
return void 0;
|
|
4979
|
-
const distance = -origin[1] /
|
|
5633
|
+
const distance = -origin[1] / direction2[1];
|
|
4980
5634
|
if (distance < 0)
|
|
4981
5635
|
return void 0;
|
|
4982
|
-
const x = origin[0] + distance *
|
|
4983
|
-
const z = origin[2] + distance *
|
|
5636
|
+
const x = origin[0] + distance * direction2[0];
|
|
5637
|
+
const z = origin[2] + distance * direction2[2];
|
|
4984
5638
|
if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
|
|
4985
5639
|
return void 0;
|
|
4986
5640
|
if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
|
|
@@ -4988,9 +5642,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
|
4988
5642
|
return { distance, normal: [0, 1, 0] };
|
|
4989
5643
|
}
|
|
4990
5644
|
intersectPlane(plane) {
|
|
4991
|
-
const boundaryPoint = new
|
|
5645
|
+
const boundaryPoint = new import_core16.Vector3(0, 0, 0).transform(this.matrix);
|
|
4992
5646
|
const inverse = this.inverseMatrix;
|
|
4993
|
-
const boundaryNormal = new
|
|
5647
|
+
const boundaryNormal = new import_core16.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
|
|
4994
5648
|
const alignment = boundaryNormal.dot(plane.normal);
|
|
4995
5649
|
if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
|
|
4996
5650
|
return "intersecting";
|
|
@@ -5025,36 +5679,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
|
|
|
5025
5679
|
equals(shape) {
|
|
5026
5680
|
return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
|
|
5027
5681
|
}
|
|
5028
|
-
containsLocalPoint(
|
|
5029
|
-
return Math.hypot(...
|
|
5682
|
+
containsLocalPoint(point2) {
|
|
5683
|
+
return Math.hypot(...point2) <= this.radius + EPSILON4;
|
|
5030
5684
|
}
|
|
5031
|
-
distanceToLocalPoint(
|
|
5032
|
-
return Math.max(0, Math.hypot(...
|
|
5685
|
+
distanceToLocalPoint(point2) {
|
|
5686
|
+
return Math.max(0, Math.hypot(...point2) - this.radius);
|
|
5033
5687
|
}
|
|
5034
|
-
supportLocal(
|
|
5035
|
-
const length = Math.hypot(...
|
|
5036
|
-
return length ?
|
|
5688
|
+
supportLocal(direction2) {
|
|
5689
|
+
const length = Math.hypot(...direction2);
|
|
5690
|
+
return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
|
|
5037
5691
|
}
|
|
5038
|
-
intersectLocalRay(origin,
|
|
5039
|
-
const roots = solveQuadratic(
|
|
5692
|
+
intersectLocalRay(origin, direction2) {
|
|
5693
|
+
const roots = solveQuadratic(dot5(direction2, direction2), 2 * dot5(origin, direction2), dot5(origin, origin) - this.radius * this.radius);
|
|
5040
5694
|
const distance = roots.find((value) => value >= 0);
|
|
5041
5695
|
if (distance === void 0)
|
|
5042
5696
|
return void 0;
|
|
5043
|
-
const
|
|
5044
|
-
return { distance, normal:
|
|
5697
|
+
const point2 = origin.map((value, i) => value + distance * direction2[i]);
|
|
5698
|
+
return { distance, normal: point2.map((value) => value / this.radius) };
|
|
5045
5699
|
}
|
|
5046
5700
|
};
|
|
5047
|
-
function
|
|
5701
|
+
function dot5(a, b) {
|
|
5048
5702
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
5049
5703
|
}
|
|
5050
5704
|
|
|
5051
5705
|
// dist/culling/lib/perspective-off-center-frustum.js
|
|
5052
|
-
var
|
|
5053
|
-
var scratchPlaneUpVector = new
|
|
5054
|
-
var scratchPlaneRightVector = new
|
|
5055
|
-
var scratchPlaneNearCenter = new
|
|
5056
|
-
var scratchPlaneFarCenter = new
|
|
5057
|
-
var scratchPlaneNormal2 = new
|
|
5706
|
+
var import_core17 = require("@math.gl/core");
|
|
5707
|
+
var scratchPlaneUpVector = new import_core17.Vector3();
|
|
5708
|
+
var scratchPlaneRightVector = new import_core17.Vector3();
|
|
5709
|
+
var scratchPlaneNearCenter = new import_core17.Vector3();
|
|
5710
|
+
var scratchPlaneFarCenter = new import_core17.Vector3();
|
|
5711
|
+
var scratchPlaneNormal2 = new import_core17.Vector3();
|
|
5058
5712
|
var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
5059
5713
|
/**
|
|
5060
5714
|
* The viewing frustum is defined by 6 planes.
|
|
@@ -5085,8 +5739,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5085
5739
|
new Plane(),
|
|
5086
5740
|
new Plane()
|
|
5087
5741
|
]);
|
|
5088
|
-
this._perspectiveMatrix = new
|
|
5089
|
-
this._infinitePerspective = new
|
|
5742
|
+
this._perspectiveMatrix = new import_core17.Matrix4();
|
|
5743
|
+
this._infinitePerspective = new import_core17.Matrix4();
|
|
5090
5744
|
const { near = 1, far = 5e8 } = options;
|
|
5091
5745
|
this.left = options.left;
|
|
5092
5746
|
this._left = void 0;
|
|
@@ -5156,15 +5810,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5156
5810
|
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
5157
5811
|
*/
|
|
5158
5812
|
// eslint-disable-next-line complexity, max-statements
|
|
5159
|
-
computeCullingVolume(position,
|
|
5160
|
-
(0,
|
|
5161
|
-
(0,
|
|
5162
|
-
(0,
|
|
5813
|
+
computeCullingVolume(position, direction2, up) {
|
|
5814
|
+
(0, import_core17.assert)(position, "position is required.");
|
|
5815
|
+
(0, import_core17.assert)(direction2, "direction is required.");
|
|
5816
|
+
(0, import_core17.assert)(up, "up is required.");
|
|
5163
5817
|
const planes = this._cullingVolume.planes;
|
|
5164
5818
|
up = scratchPlaneUpVector.copy(up).normalize();
|
|
5165
|
-
const right = scratchPlaneRightVector.copy(
|
|
5166
|
-
const nearCenter = scratchPlaneNearCenter.copy(
|
|
5167
|
-
const farCenter = scratchPlaneFarCenter.copy(
|
|
5819
|
+
const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
|
|
5820
|
+
const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
|
|
5821
|
+
const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
|
|
5168
5822
|
let normal = scratchPlaneNormal2;
|
|
5169
5823
|
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
5170
5824
|
planes[0].fromPointNormal(position, normal);
|
|
@@ -5174,7 +5828,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5174
5828
|
planes[2].fromPointNormal(position, normal);
|
|
5175
5829
|
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
5176
5830
|
planes[3].fromPointNormal(position, normal);
|
|
5177
|
-
normal = new
|
|
5831
|
+
normal = new import_core17.Vector3().copy(direction2);
|
|
5178
5832
|
planes[4].fromPointNormal(nearCenter, normal);
|
|
5179
5833
|
normal.negate();
|
|
5180
5834
|
planes[5].fromPointNormal(farCenter, normal);
|
|
@@ -5206,11 +5860,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5206
5860
|
*/
|
|
5207
5861
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
5208
5862
|
this._update();
|
|
5209
|
-
(0,
|
|
5210
|
-
(0,
|
|
5211
|
-
(0,
|
|
5212
|
-
(0,
|
|
5213
|
-
(0,
|
|
5863
|
+
(0, import_core17.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
5864
|
+
(0, import_core17.assert)(drawingBufferWidth > 0);
|
|
5865
|
+
(0, import_core17.assert)(drawingBufferHeight > 0);
|
|
5866
|
+
(0, import_core17.assert)(distance > 0);
|
|
5867
|
+
(0, import_core17.assert)(result);
|
|
5214
5868
|
const inverseNear = 1 / this.near;
|
|
5215
5869
|
let tanTheta = this.top * inverseNear;
|
|
5216
5870
|
const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
|
|
@@ -5222,17 +5876,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5222
5876
|
}
|
|
5223
5877
|
// eslint-disable-next-line complexity, max-statements
|
|
5224
5878
|
_update() {
|
|
5225
|
-
(0,
|
|
5879
|
+
(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));
|
|
5226
5880
|
const { top, bottom, right, left, near, far } = this;
|
|
5227
5881
|
if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
|
|
5228
|
-
(0,
|
|
5882
|
+
(0, import_core17.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
|
|
5229
5883
|
this._left = left;
|
|
5230
5884
|
this._right = right;
|
|
5231
5885
|
this._top = top;
|
|
5232
5886
|
this._bottom = bottom;
|
|
5233
5887
|
this._near = near;
|
|
5234
5888
|
this._far = far;
|
|
5235
|
-
this._perspectiveMatrix = new
|
|
5889
|
+
this._perspectiveMatrix = new import_core17.Matrix4().frustum({
|
|
5236
5890
|
left,
|
|
5237
5891
|
right,
|
|
5238
5892
|
bottom,
|
|
@@ -5240,7 +5894,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5240
5894
|
near,
|
|
5241
5895
|
far
|
|
5242
5896
|
});
|
|
5243
|
-
this._infinitePerspective = new
|
|
5897
|
+
this._infinitePerspective = new import_core17.Matrix4().frustum({
|
|
5244
5898
|
left,
|
|
5245
5899
|
right,
|
|
5246
5900
|
bottom,
|
|
@@ -5253,7 +5907,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
|
5253
5907
|
};
|
|
5254
5908
|
|
|
5255
5909
|
// dist/culling/lib/perspective-frustum.js
|
|
5256
|
-
var
|
|
5910
|
+
var import_core18 = require("@math.gl/core");
|
|
5257
5911
|
var defined = (val) => val !== null && typeof val !== "undefined";
|
|
5258
5912
|
var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
5259
5913
|
constructor(options = {}) {
|
|
@@ -5326,9 +5980,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5326
5980
|
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
5327
5981
|
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
5328
5982
|
*/
|
|
5329
|
-
computeCullingVolume(position,
|
|
5983
|
+
computeCullingVolume(position, direction2, up) {
|
|
5330
5984
|
this._update();
|
|
5331
|
-
return this._offCenterFrustum.computeCullingVolume(position,
|
|
5985
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
|
|
5332
5986
|
}
|
|
5333
5987
|
/**
|
|
5334
5988
|
* Returns the pixel's width and height in meters.
|
|
@@ -5355,16 +6009,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5355
6009
|
*/
|
|
5356
6010
|
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
5357
6011
|
this._update();
|
|
5358
|
-
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new
|
|
6012
|
+
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core18.Vector2());
|
|
5359
6013
|
}
|
|
5360
6014
|
// eslint-disable-next-line complexity, max-statements
|
|
5361
6015
|
_update() {
|
|
5362
|
-
(0,
|
|
6016
|
+
(0, import_core18.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
5363
6017
|
const f = this._offCenterFrustum;
|
|
5364
6018
|
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) {
|
|
5365
|
-
(0,
|
|
5366
|
-
(0,
|
|
5367
|
-
(0,
|
|
6019
|
+
(0, import_core18.assert)(this.fov >= 0 && this.fov < Math.PI);
|
|
6020
|
+
(0, import_core18.assert)(this.aspectRatio > 0);
|
|
6021
|
+
(0, import_core18.assert)(this.near >= 0 && this.near < this.far);
|
|
5368
6022
|
this._aspectRatio = this.aspectRatio;
|
|
5369
6023
|
this._fov = this.fov;
|
|
5370
6024
|
this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
|
|
@@ -5388,19 +6042,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
|
5388
6042
|
};
|
|
5389
6043
|
|
|
5390
6044
|
// dist/culling/lib/algorithms/bounding-sphere-from-points.js
|
|
5391
|
-
var
|
|
5392
|
-
var fromPointsXMin = new
|
|
5393
|
-
var fromPointsYMin = new
|
|
5394
|
-
var fromPointsZMin = new
|
|
5395
|
-
var fromPointsXMax = new
|
|
5396
|
-
var fromPointsYMax = new
|
|
5397
|
-
var fromPointsZMax = new
|
|
5398
|
-
var fromPointsCurrentPos = new
|
|
5399
|
-
var fromPointsScratch = new
|
|
5400
|
-
var fromPointsRitterCenter = new
|
|
5401
|
-
var fromPointsMinBoxPt = new
|
|
5402
|
-
var fromPointsMaxBoxPt = new
|
|
5403
|
-
var fromPointsNaiveCenterScratch = new
|
|
6045
|
+
var import_core19 = require("@math.gl/core");
|
|
6046
|
+
var fromPointsXMin = new import_core19.Vector3();
|
|
6047
|
+
var fromPointsYMin = new import_core19.Vector3();
|
|
6048
|
+
var fromPointsZMin = new import_core19.Vector3();
|
|
6049
|
+
var fromPointsXMax = new import_core19.Vector3();
|
|
6050
|
+
var fromPointsYMax = new import_core19.Vector3();
|
|
6051
|
+
var fromPointsZMax = new import_core19.Vector3();
|
|
6052
|
+
var fromPointsCurrentPos = new import_core19.Vector3();
|
|
6053
|
+
var fromPointsScratch = new import_core19.Vector3();
|
|
6054
|
+
var fromPointsRitterCenter = new import_core19.Vector3();
|
|
6055
|
+
var fromPointsMinBoxPt = new import_core19.Vector3();
|
|
6056
|
+
var fromPointsMaxBoxPt = new import_core19.Vector3();
|
|
6057
|
+
var fromPointsNaiveCenterScratch = new import_core19.Vector3();
|
|
5404
6058
|
function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
|
|
5405
6059
|
if (!positions || positions.length === 0) {
|
|
5406
6060
|
return result.fromCenterRadius([0, 0, 0], 0);
|
|
@@ -5496,17 +6150,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
|
|
|
5496
6150
|
}
|
|
5497
6151
|
|
|
5498
6152
|
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
5499
|
-
var
|
|
6153
|
+
var import_core21 = require("@math.gl/core");
|
|
5500
6154
|
|
|
5501
6155
|
// dist/culling/lib/algorithms/compute-eigen-decomposition.js
|
|
5502
|
-
var
|
|
5503
|
-
var scratchMatrix = new
|
|
5504
|
-
var scratchUnitary = new
|
|
5505
|
-
var scratchDiagonal = new
|
|
5506
|
-
var jMatrix = new
|
|
5507
|
-
var jMatrixTranspose = new
|
|
6156
|
+
var import_core20 = require("@math.gl/core");
|
|
6157
|
+
var scratchMatrix = new import_core20.Matrix3();
|
|
6158
|
+
var scratchUnitary = new import_core20.Matrix3();
|
|
6159
|
+
var scratchDiagonal = new import_core20.Matrix3();
|
|
6160
|
+
var jMatrix = new import_core20.Matrix3();
|
|
6161
|
+
var jMatrixTranspose = new import_core20.Matrix3();
|
|
5508
6162
|
function computeEigenDecomposition(matrix, result = {}) {
|
|
5509
|
-
const EIGEN_TOLERANCE =
|
|
6163
|
+
const EIGEN_TOLERANCE = import_core20._MathUtils.EPSILON20;
|
|
5510
6164
|
const EIGEN_MAX_SWEEPS = 10;
|
|
5511
6165
|
let count = 0;
|
|
5512
6166
|
let sweep = 0;
|
|
@@ -5549,7 +6203,7 @@ function offDiagonalFrobeniusNorm(matrix) {
|
|
|
5549
6203
|
return Math.sqrt(norm);
|
|
5550
6204
|
}
|
|
5551
6205
|
function shurDecomposition(matrix, result) {
|
|
5552
|
-
const tolerance =
|
|
6206
|
+
const tolerance = import_core20._MathUtils.EPSILON15;
|
|
5553
6207
|
let maxDiagonal = 0;
|
|
5554
6208
|
let rotAxis = 1;
|
|
5555
6209
|
for (let i = 0; i < 3; ++i) {
|
|
@@ -5577,7 +6231,7 @@ function shurDecomposition(matrix, result) {
|
|
|
5577
6231
|
c = 1 / Math.sqrt(1 + t * t);
|
|
5578
6232
|
s = t * c;
|
|
5579
6233
|
}
|
|
5580
|
-
|
|
6234
|
+
import_core20.Matrix3.IDENTITY.to(result);
|
|
5581
6235
|
result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
|
|
5582
6236
|
result[scratchMatrix.getElementIndex(q, p)] = s;
|
|
5583
6237
|
result[scratchMatrix.getElementIndex(p, q)] = -s;
|
|
@@ -5585,24 +6239,24 @@ function shurDecomposition(matrix, result) {
|
|
|
5585
6239
|
}
|
|
5586
6240
|
|
|
5587
6241
|
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
5588
|
-
var scratchVector23 = new
|
|
5589
|
-
var scratchVector33 = new
|
|
5590
|
-
var scratchVector42 = new
|
|
5591
|
-
var scratchVector5 = new
|
|
5592
|
-
var scratchVector6 = new
|
|
5593
|
-
var scratchCovarianceResult = new
|
|
6242
|
+
var scratchVector23 = new import_core21.Vector3();
|
|
6243
|
+
var scratchVector33 = new import_core21.Vector3();
|
|
6244
|
+
var scratchVector42 = new import_core21.Vector3();
|
|
6245
|
+
var scratchVector5 = new import_core21.Vector3();
|
|
6246
|
+
var scratchVector6 = new import_core21.Vector3();
|
|
6247
|
+
var scratchCovarianceResult = new import_core21.Matrix3();
|
|
5594
6248
|
var scratchEigenResult = {
|
|
5595
|
-
diagonal: new
|
|
5596
|
-
unitary: new
|
|
6249
|
+
diagonal: new import_core21.Matrix3(),
|
|
6250
|
+
unitary: new import_core21.Matrix3()
|
|
5597
6251
|
};
|
|
5598
6252
|
function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
|
|
5599
6253
|
if (!positions || positions.length === 0) {
|
|
5600
|
-
result.halfAxes = new
|
|
5601
|
-
result.center = new
|
|
6254
|
+
result.halfAxes = new import_core21.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
6255
|
+
result.center = new import_core21.Vector3();
|
|
5602
6256
|
return result;
|
|
5603
6257
|
}
|
|
5604
6258
|
const length = positions.length;
|
|
5605
|
-
const meanPoint = new
|
|
6259
|
+
const meanPoint = new import_core21.Vector3(0, 0, 0);
|
|
5606
6260
|
for (const position of positions) {
|
|
5607
6261
|
meanPoint.add(position);
|
|
5608
6262
|
}
|
|
@@ -5664,7 +6318,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
|
|
|
5664
6318
|
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
5665
6319
|
result.center.copy(v1).add(v2).add(v3);
|
|
5666
6320
|
const scale = scratchVector33.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
5667
|
-
const scaleMatrix = new
|
|
6321
|
+
const scaleMatrix = new import_core21.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
5668
6322
|
result.halfAxes.multiplyRight(scaleMatrix);
|
|
5669
6323
|
return result;
|
|
5670
6324
|
}
|
|
@@ -5700,245 +6354,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
|
|
|
5700
6354
|
return result;
|
|
5701
6355
|
}
|
|
5702
6356
|
|
|
5703
|
-
// dist/culling/queries.js
|
|
5704
|
-
function validateQueryPoint(point, dimension) {
|
|
5705
|
-
if (point.length !== dimension)
|
|
5706
|
-
throw new RangeError("Query dimension must match the index");
|
|
5707
|
-
for (let i = 0; i < dimension; i++) {
|
|
5708
|
-
if (!Number.isFinite(point[i]))
|
|
5709
|
-
throw new RangeError("Coordinates must be finite");
|
|
5710
|
-
}
|
|
5711
|
-
}
|
|
5712
|
-
function validateQueryDistance(distance) {
|
|
5713
|
-
if (Number.isNaN(distance) || distance < 0)
|
|
5714
|
-
throw new RangeError("Distance must be nonnegative");
|
|
5715
|
-
}
|
|
5716
|
-
function normalizeQueryDirection(direction, dimension) {
|
|
5717
|
-
validateQueryPoint(direction, dimension);
|
|
5718
|
-
const scale = Math.max(...Array.from(direction, Math.abs));
|
|
5719
|
-
if (scale === 0)
|
|
5720
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5721
|
-
const scaled = Array.from(direction, (x) => x / scale);
|
|
5722
|
-
const length = Math.hypot(...scaled);
|
|
5723
|
-
return scaled.map((x) => x / length);
|
|
5724
|
-
}
|
|
5725
|
-
function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
|
|
5726
|
-
const dimension = origin.length;
|
|
5727
|
-
if (dimension !== 2 && dimension !== 3)
|
|
5728
|
-
throw new RangeError("Bounds must be 2D or 3D");
|
|
5729
|
-
validateQueryPoint(origin, dimension);
|
|
5730
|
-
validateQueryPoint(direction, dimension);
|
|
5731
|
-
validateQueryPoint(minimum, dimension);
|
|
5732
|
-
validateQueryPoint(maximum, dimension);
|
|
5733
|
-
validateQueryDistance(maxT);
|
|
5734
|
-
let near = 0, far = maxT, nonzero = false;
|
|
5735
|
-
for (let i = 0; i < dimension; i++) {
|
|
5736
|
-
if (minimum[i] > maximum[i])
|
|
5737
|
-
throw new RangeError("Bounds must be ordered");
|
|
5738
|
-
nonzero || (nonzero = direction[i] !== 0);
|
|
5739
|
-
}
|
|
5740
|
-
if (!nonzero)
|
|
5741
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5742
|
-
for (let i = 0; i < dimension; i++) {
|
|
5743
|
-
if (direction[i] === 0) {
|
|
5744
|
-
if (origin[i] < minimum[i] || origin[i] > maximum[i])
|
|
5745
|
-
return null;
|
|
5746
|
-
continue;
|
|
5747
|
-
}
|
|
5748
|
-
let a = (minimum[i] - origin[i]) / direction[i];
|
|
5749
|
-
let b = (maximum[i] - origin[i]) / direction[i];
|
|
5750
|
-
if (a > b)
|
|
5751
|
-
[a, b] = [b, a];
|
|
5752
|
-
near = Math.max(near, a);
|
|
5753
|
-
far = Math.min(far, b);
|
|
5754
|
-
if (near > far)
|
|
5755
|
-
return null;
|
|
5756
|
-
}
|
|
5757
|
-
return Number.isFinite(near) ? near : null;
|
|
5758
|
-
}
|
|
5759
|
-
function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
|
|
5760
|
-
for (const point of [origin, direction, a, b, c])
|
|
5761
|
-
validateQueryPoint(point, 3);
|
|
5762
|
-
if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
|
|
5763
|
-
throw new RangeError("Ray direction must be nonzero");
|
|
5764
|
-
}
|
|
5765
|
-
const maxT = options.maxT ?? Infinity;
|
|
5766
|
-
validateQueryDistance(maxT);
|
|
5767
|
-
const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
5768
|
-
const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
5769
|
-
const p = cross3(direction, e2);
|
|
5770
|
-
const determinant = dot3(e1, p);
|
|
5771
|
-
if (determinant === 0 || options.backfaceCulling && determinant < 0)
|
|
5772
|
-
return null;
|
|
5773
|
-
const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
|
|
5774
|
-
const u = dot3(offset, p) / determinant;
|
|
5775
|
-
if (u < 0 || u > 1)
|
|
5776
|
-
return null;
|
|
5777
|
-
const q = cross3(offset, e1);
|
|
5778
|
-
const v = dot3(direction, q) / determinant;
|
|
5779
|
-
if (v < 0 || u + v > 1)
|
|
5780
|
-
return null;
|
|
5781
|
-
const t = dot3(e2, q) / determinant;
|
|
5782
|
-
if (!Number.isFinite(t) || t < 0 || t > maxT)
|
|
5783
|
-
return null;
|
|
5784
|
-
return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
|
|
5785
|
-
}
|
|
5786
|
-
function getClosestPointOnTriangle(point, a, b, c) {
|
|
5787
|
-
for (const value of [point, a, b, c])
|
|
5788
|
-
validateQueryPoint(value, 3);
|
|
5789
|
-
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
5790
|
-
const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
5791
|
-
const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
|
|
5792
|
-
const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
|
|
5793
|
-
const denominator = aa * bb - cc * cc;
|
|
5794
|
-
if (denominator > 0 && Number.isFinite(denominator)) {
|
|
5795
|
-
const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
|
|
5796
|
-
const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
|
|
5797
|
-
if (u >= 0 && v >= 0 && u + v <= 1) {
|
|
5798
|
-
return [
|
|
5799
|
-
a[0] + u * ab[0] + v * ac[0],
|
|
5800
|
-
a[1] + u * ab[1] + v * ac[1],
|
|
5801
|
-
a[2] + u * ab[2] + v * ac[2]
|
|
5802
|
-
];
|
|
5803
|
-
}
|
|
5804
|
-
}
|
|
5805
|
-
let best = [a[0], a[1], a[2]];
|
|
5806
|
-
let distance = Infinity;
|
|
5807
|
-
for (const [start, end] of [
|
|
5808
|
-
[a, b],
|
|
5809
|
-
[b, c],
|
|
5810
|
-
[c, a]
|
|
5811
|
-
]) {
|
|
5812
|
-
const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
|
|
5813
|
-
const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
|
|
5814
|
-
const squared = dot3(edge, edge);
|
|
5815
|
-
const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
|
|
5816
|
-
const candidate = [
|
|
5817
|
-
start[0] + t * edge[0],
|
|
5818
|
-
start[1] + t * edge[1],
|
|
5819
|
-
start[2] + t * edge[2]
|
|
5820
|
-
];
|
|
5821
|
-
const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
|
|
5822
|
-
if (d < distance) {
|
|
5823
|
-
distance = d;
|
|
5824
|
-
best = candidate;
|
|
5825
|
-
}
|
|
5826
|
-
}
|
|
5827
|
-
return best;
|
|
5828
|
-
}
|
|
5829
|
-
function getClosestPointsOnSegments(a0, a1, b0, b1) {
|
|
5830
|
-
const frame = queryFrame([a0, a1, b0, b1]);
|
|
5831
|
-
const pair = closestSegments(...frame.points);
|
|
5832
|
-
const pointA = interpolatePoint(a0, a1, pair.fractionA);
|
|
5833
|
-
const pointB = interpolatePoint(b0, b1, pair.fractionB);
|
|
5834
|
-
return {
|
|
5835
|
-
distance: finiteDistance(pointA, pointB),
|
|
5836
|
-
pointA,
|
|
5837
|
-
pointB,
|
|
5838
|
-
fractionA: pair.fractionA,
|
|
5839
|
-
fractionB: pair.fractionB
|
|
5840
|
-
};
|
|
5841
|
-
}
|
|
5842
|
-
function getClosestPointsSegmentTriangle(start, end, a, b, c) {
|
|
5843
|
-
const frame = queryFrame([start, end, a, b, c]);
|
|
5844
|
-
const [s, e, va, vb, vc] = frame.points;
|
|
5845
|
-
const direction = subtract(e, s);
|
|
5846
|
-
if (direction.some((value) => value !== 0)) {
|
|
5847
|
-
const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
|
|
5848
|
-
if (hit) {
|
|
5849
|
-
const point = interpolatePoint(start, end, hit.t);
|
|
5850
|
-
return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
|
|
5851
|
-
}
|
|
5852
|
-
}
|
|
5853
|
-
let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
|
|
5854
|
-
const consider = (point, trianglePoint2, segmentFraction) => {
|
|
5855
|
-
const distance = Math.hypot(...subtract(point, trianglePoint2));
|
|
5856
|
-
if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
|
|
5857
|
-
best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
|
|
5858
|
-
};
|
|
5859
|
-
consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
|
|
5860
|
-
consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
|
|
5861
|
-
for (const [v0, v1] of [
|
|
5862
|
-
[va, vb],
|
|
5863
|
-
[vb, vc],
|
|
5864
|
-
[vc, va]
|
|
5865
|
-
]) {
|
|
5866
|
-
const pair = closestSegments(s, e, v0, v1);
|
|
5867
|
-
consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
|
|
5868
|
-
}
|
|
5869
|
-
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)));
|
|
5870
|
-
if (!trianglePoint.every(Number.isFinite))
|
|
5871
|
-
throw new RangeError("Closest-point result overflow");
|
|
5872
|
-
const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
|
|
5873
|
-
return {
|
|
5874
|
-
distance: finiteDistance(segmentPoint, trianglePoint),
|
|
5875
|
-
segmentPoint,
|
|
5876
|
-
trianglePoint,
|
|
5877
|
-
segmentFraction: best.segmentFraction
|
|
5878
|
-
};
|
|
5879
|
-
}
|
|
5880
|
-
function queryFrame(input) {
|
|
5881
|
-
input.forEach((point) => validateQueryPoint(point, 3));
|
|
5882
|
-
const offsets = input.map((point) => subtract(point, input[0]));
|
|
5883
|
-
let scale = 0;
|
|
5884
|
-
for (const offset of offsets)
|
|
5885
|
-
for (const value of offset) {
|
|
5886
|
-
if (!Number.isFinite(value))
|
|
5887
|
-
throw new RangeError("Closest-point coordinate span overflow");
|
|
5888
|
-
scale = Math.max(scale, Math.abs(value));
|
|
5889
|
-
}
|
|
5890
|
-
scale || (scale = 1);
|
|
5891
|
-
return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
|
|
5892
|
-
}
|
|
5893
|
-
function closestSegments(a0, a1, b0, b1) {
|
|
5894
|
-
const da = subtract(a1, a0), db = subtract(b1, b0);
|
|
5895
|
-
const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
|
|
5896
|
-
const ua = da.map((value) => lengthA ? value / lengthA : 0);
|
|
5897
|
-
const ub = db.map((value) => lengthB ? value / lengthB : 0);
|
|
5898
|
-
let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
|
|
5899
|
-
const consider = (fractionA, fractionB) => {
|
|
5900
|
-
const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
|
|
5901
|
-
if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
|
|
5902
|
-
best = { distance, fractionA, fractionB };
|
|
5903
|
-
};
|
|
5904
|
-
for (const t of [0, 1]) {
|
|
5905
|
-
consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
|
|
5906
|
-
consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
|
|
5907
|
-
}
|
|
5908
|
-
const normal = cross3(ua, ub);
|
|
5909
|
-
const sine = Math.hypot(...normal);
|
|
5910
|
-
if (sine > 0) {
|
|
5911
|
-
const unit = normal.map((value) => value / sine);
|
|
5912
|
-
const offset = subtract(b0, a0);
|
|
5913
|
-
const fractionA = dot3(cross3(offset, ub), unit) / sine / lengthA;
|
|
5914
|
-
const fractionB = dot3(cross3(offset, ua), unit) / sine / lengthB;
|
|
5915
|
-
if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
|
|
5916
|
-
consider(fractionA, fractionB);
|
|
5917
|
-
}
|
|
5918
|
-
return best;
|
|
5919
|
-
}
|
|
5920
|
-
function subtract(a, b) {
|
|
5921
|
-
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
5922
|
-
}
|
|
5923
|
-
function interpolatePoint(a, b, t) {
|
|
5924
|
-
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])));
|
|
5925
|
-
}
|
|
5926
|
-
function clampUnit(value) {
|
|
5927
|
-
return Math.max(0, Math.min(1, value));
|
|
5928
|
-
}
|
|
5929
|
-
function finiteDistance(a, b) {
|
|
5930
|
-
const distance = Math.hypot(...subtract(a, b));
|
|
5931
|
-
if (!Number.isFinite(distance))
|
|
5932
|
-
throw new RangeError("Closest-point distance overflow");
|
|
5933
|
-
return distance;
|
|
5934
|
-
}
|
|
5935
|
-
function dot3(a, b) {
|
|
5936
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
5937
|
-
}
|
|
5938
|
-
function cross3(a, b) {
|
|
5939
|
-
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]];
|
|
5940
|
-
}
|
|
5941
|
-
|
|
5942
6357
|
// dist/culling/oriented-box-2d.js
|
|
5943
6358
|
function intersectOrientedBoxes2D(first, second, epsilon = 0) {
|
|
5944
6359
|
validateBox(first);
|
|
@@ -5990,64 +6405,177 @@ function validateVector(vector) {
|
|
|
5990
6405
|
}
|
|
5991
6406
|
|
|
5992
6407
|
// dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
|
|
5993
|
-
var
|
|
6408
|
+
var import_core22 = require("@math.gl/core");
|
|
5994
6409
|
function getOrientedBoundingBoxQuaternion(box) {
|
|
5995
|
-
const x = new
|
|
5996
|
-
const y = new
|
|
5997
|
-
const z = new
|
|
5998
|
-
return new
|
|
6410
|
+
const x = new import_core22.Vector3(box.halfAxes.getColumn(0)).normalize();
|
|
6411
|
+
const y = new import_core22.Vector3(box.halfAxes.getColumn(1)).normalize();
|
|
6412
|
+
const z = new import_core22.Vector3(box.halfAxes.getColumn(2)).normalize();
|
|
6413
|
+
return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z]));
|
|
5999
6414
|
}
|
|
6000
6415
|
function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
|
|
6001
|
-
const halfAxes = new
|
|
6416
|
+
const halfAxes = new import_core22.Matrix3().fromQuaternion(quaternion);
|
|
6002
6417
|
for (let column = 0; column < 3; column++) {
|
|
6003
6418
|
for (let row = 0; row < 3; row++)
|
|
6004
6419
|
halfAxes[column * 3 + row] *= halfSize[column];
|
|
6005
6420
|
}
|
|
6006
|
-
result.center = new
|
|
6421
|
+
result.center = new import_core22.Vector3(center);
|
|
6007
6422
|
result.halfAxes = halfAxes;
|
|
6008
6423
|
return result;
|
|
6009
6424
|
}
|
|
6010
6425
|
|
|
6426
|
+
// dist/culling/bounds.js
|
|
6427
|
+
function dimension(bounds) {
|
|
6428
|
+
const n = bounds[0].length;
|
|
6429
|
+
if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
|
|
6430
|
+
throw new RangeError("Expected 2D or 3D bounds without NaN");
|
|
6431
|
+
}
|
|
6432
|
+
const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
6433
|
+
if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
|
|
6434
|
+
throw new RangeError("Nonempty bounds must be finite");
|
|
6435
|
+
}
|
|
6436
|
+
return n;
|
|
6437
|
+
}
|
|
6438
|
+
function pair(a, b) {
|
|
6439
|
+
const n = dimension(a);
|
|
6440
|
+
if (dimension(b) !== n)
|
|
6441
|
+
throw new RangeError("Bounds dimensions must match");
|
|
6442
|
+
return n;
|
|
6443
|
+
}
|
|
6444
|
+
function point(p, n) {
|
|
6445
|
+
if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
|
|
6446
|
+
throw new RangeError("Expected a finite point of matching dimension");
|
|
6447
|
+
}
|
|
6448
|
+
function createEmptyBounds(dimension2) {
|
|
6449
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
6450
|
+
throw new RangeError("Expected dimension 2 or 3");
|
|
6451
|
+
return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
|
|
6452
|
+
}
|
|
6453
|
+
function isEmptyBounds(bounds) {
|
|
6454
|
+
return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
6455
|
+
}
|
|
6456
|
+
function boundsContainsPoint(bounds, p) {
|
|
6457
|
+
point(p, dimension(bounds));
|
|
6458
|
+
return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
|
|
6459
|
+
}
|
|
6460
|
+
function boundsContainsBounds(a, b) {
|
|
6461
|
+
const n = pair(a, b);
|
|
6462
|
+
return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
|
|
6463
|
+
}
|
|
6464
|
+
function boundsIntersect(a, b) {
|
|
6465
|
+
const n = pair(a, b);
|
|
6466
|
+
return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
|
|
6467
|
+
}
|
|
6468
|
+
function store(values, out = createEmptyBounds(values[0].length)) {
|
|
6469
|
+
if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
|
|
6470
|
+
throw new RangeError("Output bounds dimensions must match");
|
|
6471
|
+
}
|
|
6472
|
+
for (let j = 0; j < 2; j++)
|
|
6473
|
+
for (let i = 0; i < values[j].length; i++)
|
|
6474
|
+
out[j][i] = values[j][i];
|
|
6475
|
+
return out;
|
|
6476
|
+
}
|
|
6477
|
+
function unionBounds(a, b, out) {
|
|
6478
|
+
const n = pair(a, b);
|
|
6479
|
+
const values = createEmptyBounds(n);
|
|
6480
|
+
const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
|
|
6481
|
+
for (let i = 0; i < n; i++) {
|
|
6482
|
+
values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
|
|
6483
|
+
values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
|
|
6484
|
+
}
|
|
6485
|
+
return store(values, out);
|
|
6486
|
+
}
|
|
6487
|
+
function intersectBounds(a, b, out) {
|
|
6488
|
+
const n = pair(a, b), values = createEmptyBounds(n);
|
|
6489
|
+
if (boundsIntersect(a, b))
|
|
6490
|
+
for (let i = 0; i < n; i++) {
|
|
6491
|
+
values[0][i] = Math.max(a[0][i], b[0][i]);
|
|
6492
|
+
values[1][i] = Math.min(a[1][i], b[1][i]);
|
|
6493
|
+
}
|
|
6494
|
+
return store(values, out);
|
|
6495
|
+
}
|
|
6496
|
+
function expandBoundsByPoint(bounds, p, out) {
|
|
6497
|
+
point(p, dimension(bounds));
|
|
6498
|
+
return unionBounds(bounds, [p, p], out);
|
|
6499
|
+
}
|
|
6500
|
+
function expandBounds(bounds, padding, out) {
|
|
6501
|
+
if (!Number.isFinite(padding))
|
|
6502
|
+
throw new RangeError("Padding must be finite");
|
|
6503
|
+
const n = dimension(bounds), values = createEmptyBounds(n);
|
|
6504
|
+
if (!isEmptyBounds(bounds))
|
|
6505
|
+
for (let i = 0; i < n; i++) {
|
|
6506
|
+
values[0][i] = bounds[0][i] - padding;
|
|
6507
|
+
values[1][i] = bounds[1][i] + padding;
|
|
6508
|
+
}
|
|
6509
|
+
return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
|
|
6510
|
+
}
|
|
6511
|
+
function clampPointToBounds(bounds, p, out = new Array(p.length)) {
|
|
6512
|
+
point(p, dimension(bounds));
|
|
6513
|
+
if (out.length < p.length)
|
|
6514
|
+
throw new RangeError("Result buffer is too short");
|
|
6515
|
+
if (isEmptyBounds(bounds))
|
|
6516
|
+
return null;
|
|
6517
|
+
const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
|
|
6518
|
+
for (let i = 0; i < result.length; i++)
|
|
6519
|
+
out[i] = result[i];
|
|
6520
|
+
return out;
|
|
6521
|
+
}
|
|
6522
|
+
function radius(r) {
|
|
6523
|
+
if (!Number.isFinite(r) || r < 0)
|
|
6524
|
+
throw new RangeError("Radius must be finite and nonnegative");
|
|
6525
|
+
}
|
|
6526
|
+
function spheresIntersect(a, ar, b, br) {
|
|
6527
|
+
point(a, 3);
|
|
6528
|
+
point(b, 3);
|
|
6529
|
+
radius(ar);
|
|
6530
|
+
radius(br);
|
|
6531
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
|
|
6532
|
+
}
|
|
6533
|
+
function boundsIntersectSphere(bounds, center, r) {
|
|
6534
|
+
radius(r);
|
|
6535
|
+
const closest = clampPointToBounds(bounds, center);
|
|
6536
|
+
return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
|
|
6537
|
+
}
|
|
6538
|
+
|
|
6011
6539
|
// dist/spatial-index/box-index.js
|
|
6012
6540
|
var BoxIndex = class {
|
|
6013
6541
|
constructor(options) {
|
|
6014
|
-
const { dimension, bounds, leafSize = 8 } = options;
|
|
6015
|
-
if (
|
|
6542
|
+
const { dimension: dimension2, bounds, leafSize = 8 } = options;
|
|
6543
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
6016
6544
|
throw new RangeError("Index dimension must be 2 or 3");
|
|
6017
6545
|
if (!Number.isSafeInteger(leafSize) || leafSize < 1)
|
|
6018
6546
|
throw new RangeError("leafSize must be positive");
|
|
6019
|
-
if (bounds.length % (
|
|
6547
|
+
if (bounds.length % (dimension2 * 2))
|
|
6020
6548
|
throw new RangeError("Incomplete bounds record");
|
|
6021
|
-
this.dimension =
|
|
6549
|
+
this.dimension = dimension2;
|
|
6022
6550
|
this.bounds = Float64Array.from(bounds);
|
|
6023
|
-
this.size = bounds.length / (
|
|
6551
|
+
this.size = bounds.length / (dimension2 * 2);
|
|
6024
6552
|
if (this.size > 2147483647)
|
|
6025
6553
|
throw new RangeError("Index exceeds 32-bit capacity");
|
|
6026
|
-
const stride =
|
|
6554
|
+
const stride = dimension2 * 2;
|
|
6027
6555
|
for (let i = 0; i < this.size; i++)
|
|
6028
|
-
this.validateBounds(this.bounds.subarray(i * stride, i * stride +
|
|
6556
|
+
this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension2), this.bounds.subarray(i * stride + dimension2, (i + 1) * stride));
|
|
6029
6557
|
const records = [];
|
|
6030
6558
|
const ids = Array.from({ length: this.size }, (_, i) => i);
|
|
6031
6559
|
const build = (start, end) => {
|
|
6032
6560
|
const node = records.length;
|
|
6033
6561
|
const bound = [
|
|
6034
|
-
...new Array(
|
|
6035
|
-
...new Array(
|
|
6562
|
+
...new Array(dimension2).fill(Infinity),
|
|
6563
|
+
...new Array(dimension2).fill(-Infinity)
|
|
6036
6564
|
];
|
|
6037
6565
|
for (let i = start; i < end; i++)
|
|
6038
|
-
for (let axis = 0; axis <
|
|
6566
|
+
for (let axis = 0; axis < dimension2; axis++) {
|
|
6039
6567
|
bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
|
|
6040
|
-
bound[axis +
|
|
6568
|
+
bound[axis + dimension2] = Math.max(bound[axis + dimension2], this.bounds[ids[i] * stride + axis + dimension2]);
|
|
6041
6569
|
}
|
|
6042
6570
|
const record = { bounds: bound, left: -1, right: -1, start, count: end - start };
|
|
6043
6571
|
records.push(record);
|
|
6044
6572
|
if (end - start > leafSize) {
|
|
6045
6573
|
let axis = 0;
|
|
6046
|
-
for (let i = 1; i <
|
|
6047
|
-
if (bound[i +
|
|
6574
|
+
for (let i = 1; i < dimension2; i++) {
|
|
6575
|
+
if (bound[i + dimension2] - bound[i] > bound[axis + dimension2] - bound[axis])
|
|
6048
6576
|
axis = i;
|
|
6049
6577
|
}
|
|
6050
|
-
const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis +
|
|
6578
|
+
const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension2] / 2;
|
|
6051
6579
|
const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
|
|
6052
6580
|
for (let i = 0; i < sorted.length; i++)
|
|
6053
6581
|
ids[start + i] = sorted[i];
|
|
@@ -6121,11 +6649,11 @@ var BoxIndex = class {
|
|
|
6121
6649
|
return { result: result.sort((a, b) => a - b), complete, work: budget.work };
|
|
6122
6650
|
}
|
|
6123
6651
|
/** Branch-and-bound nearest box, optionally refined against actual geometry. */
|
|
6124
|
-
nearest(
|
|
6125
|
-
return this.nearestQuery(
|
|
6652
|
+
nearest(point2, options = {}) {
|
|
6653
|
+
return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
|
|
6126
6654
|
}
|
|
6127
|
-
nearestQuery(
|
|
6128
|
-
return this.nearestBoxQuery(
|
|
6655
|
+
nearestQuery(point2, options = {}) {
|
|
6656
|
+
return this.nearestBoxQuery(point2, point2, options);
|
|
6129
6657
|
}
|
|
6130
6658
|
/** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
|
|
6131
6659
|
nearestBoxQuery(minimum, maximum, options = {}) {
|
|
@@ -6189,19 +6717,19 @@ var BoxIndex = class {
|
|
|
6189
6717
|
* Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
|
|
6190
6718
|
* Rejected refinements do not clip the ray. Equal distances select the lowest original row.
|
|
6191
6719
|
*/
|
|
6192
|
-
intersectRay(origin,
|
|
6193
|
-
return this.intersectRayQuery(origin,
|
|
6720
|
+
intersectRay(origin, direction2, options = {}) {
|
|
6721
|
+
return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
|
|
6194
6722
|
}
|
|
6195
|
-
intersectRayQuery(origin,
|
|
6723
|
+
intersectRayQuery(origin, direction2, options = {}) {
|
|
6196
6724
|
validateQueryPoint(origin, this.dimension);
|
|
6197
6725
|
const budget = new QueryBudget(options.maxWork);
|
|
6198
|
-
const
|
|
6726
|
+
const unit2 = normalizeQueryDirection(direction2, this.dimension);
|
|
6199
6727
|
let best = options.maxDistance ?? Infinity;
|
|
6200
6728
|
validateQueryDistance(best);
|
|
6201
6729
|
let result = null;
|
|
6202
6730
|
const getEntry = (bounds, index) => {
|
|
6203
6731
|
const offset = index * this.dimension * 2;
|
|
6204
|
-
return intersectRayBounds(origin,
|
|
6732
|
+
return intersectRayBounds(origin, unit2, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
|
|
6205
6733
|
};
|
|
6206
6734
|
const stack = this.size ? [{ index: 0, distance: 0 }] : [];
|
|
6207
6735
|
let complete = true;
|
|
@@ -6254,13 +6782,13 @@ var BoxIndex = class {
|
|
|
6254
6782
|
return { result, complete, work: budget.work };
|
|
6255
6783
|
}
|
|
6256
6784
|
/** Broad-phase ray candidates, sorted by entry distance then original row index. */
|
|
6257
|
-
searchRay(origin,
|
|
6785
|
+
searchRay(origin, direction2, maxDistance = Infinity) {
|
|
6258
6786
|
validateQueryPoint(origin, this.dimension);
|
|
6259
|
-
const
|
|
6787
|
+
const unit2 = normalizeQueryDirection(direction2, this.dimension);
|
|
6260
6788
|
validateQueryDistance(maxDistance);
|
|
6261
6789
|
const entry = (bounds, index) => {
|
|
6262
6790
|
const start = index * this.dimension * 2;
|
|
6263
|
-
return intersectRayBounds(origin,
|
|
6791
|
+
return intersectRayBounds(origin, unit2, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
|
|
6264
6792
|
};
|
|
6265
6793
|
const result = [];
|
|
6266
6794
|
const stack = this.size ? [0] : [];
|
|
@@ -6310,16 +6838,16 @@ var QueryBudget = class {
|
|
|
6310
6838
|
};
|
|
6311
6839
|
var PointIndex = class extends BoxIndex {
|
|
6312
6840
|
constructor(options) {
|
|
6313
|
-
const { positions, dimension, leafSize } = options;
|
|
6314
|
-
if (
|
|
6841
|
+
const { positions, dimension: dimension2, leafSize } = options;
|
|
6842
|
+
if (dimension2 !== 2 && dimension2 !== 3 || positions.length % dimension2) {
|
|
6315
6843
|
throw new RangeError("Invalid point layout");
|
|
6316
6844
|
}
|
|
6317
6845
|
const bounds = new Float64Array(positions.length * 2);
|
|
6318
|
-
for (let i = 0; i < positions.length /
|
|
6319
|
-
for (let axis = 0; axis <
|
|
6320
|
-
bounds[i *
|
|
6846
|
+
for (let i = 0; i < positions.length / dimension2; i++)
|
|
6847
|
+
for (let axis = 0; axis < dimension2; axis++) {
|
|
6848
|
+
bounds[i * dimension2 * 2 + axis] = bounds[i * dimension2 * 2 + axis + dimension2] = positions[i * dimension2 + axis];
|
|
6321
6849
|
}
|
|
6322
|
-
super({ bounds, dimension, leafSize });
|
|
6850
|
+
super({ bounds, dimension: dimension2, leafSize });
|
|
6323
6851
|
}
|
|
6324
6852
|
};
|
|
6325
6853
|
|
|
@@ -6362,20 +6890,20 @@ var TriangleBVH = class {
|
|
|
6362
6890
|
return this.boxes.searchQuery(minimum, maximum, options);
|
|
6363
6891
|
}
|
|
6364
6892
|
/** Nearest accepted exact hit; application rejection never clips away later candidates. */
|
|
6365
|
-
intersectRay(origin,
|
|
6366
|
-
return this.intersectRayQuery(origin,
|
|
6893
|
+
intersectRay(origin, direction2, options = {}) {
|
|
6894
|
+
return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
|
|
6367
6895
|
}
|
|
6368
|
-
intersectRayQuery(origin,
|
|
6896
|
+
intersectRayQuery(origin, direction2, options = {}) {
|
|
6369
6897
|
validateQueryPoint(origin, 3);
|
|
6370
|
-
const
|
|
6898
|
+
const unit2 = normalizeQueryDirection(direction2, 3);
|
|
6371
6899
|
let result = null;
|
|
6372
|
-
const query = this.boxes.intersectRayQuery(origin,
|
|
6900
|
+
const query = this.boxes.intersectRayQuery(origin, direction2, {
|
|
6373
6901
|
maxWork: options.maxWork,
|
|
6374
6902
|
maxDistance: options.maxDistance,
|
|
6375
6903
|
filter: options.filter,
|
|
6376
6904
|
intersectItem: (index, maximum) => {
|
|
6377
6905
|
const [a, b, c] = this.triangle(index);
|
|
6378
|
-
const hit = intersectRayTriangle(origin,
|
|
6906
|
+
const hit = intersectRayTriangle(origin, unit2, a, b, c, {
|
|
6379
6907
|
backfaceCulling: options.backfaceCulling,
|
|
6380
6908
|
maxT: maximum
|
|
6381
6909
|
});
|
|
@@ -6384,9 +6912,9 @@ var TriangleBVH = class {
|
|
|
6384
6912
|
index,
|
|
6385
6913
|
distance: hit.t,
|
|
6386
6914
|
point: [
|
|
6387
|
-
origin[0] + hit.t *
|
|
6388
|
-
origin[1] + hit.t *
|
|
6389
|
-
origin[2] + hit.t *
|
|
6915
|
+
origin[0] + hit.t * unit2[0],
|
|
6916
|
+
origin[1] + hit.t * unit2[1],
|
|
6917
|
+
origin[2] + hit.t * unit2[2]
|
|
6390
6918
|
],
|
|
6391
6919
|
barycentric: hit.barycentric
|
|
6392
6920
|
};
|
|
@@ -6400,16 +6928,16 @@ var TriangleBVH = class {
|
|
|
6400
6928
|
});
|
|
6401
6929
|
return { ...query, result };
|
|
6402
6930
|
}
|
|
6403
|
-
nearest(
|
|
6404
|
-
return this.nearestQuery(
|
|
6931
|
+
nearest(point2, options = {}) {
|
|
6932
|
+
return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
|
|
6405
6933
|
}
|
|
6406
|
-
nearestQuery(
|
|
6934
|
+
nearestQuery(point2, options = {}) {
|
|
6407
6935
|
let candidate = null;
|
|
6408
|
-
const query = this.boxes.nearestQuery(
|
|
6936
|
+
const query = this.boxes.nearestQuery(point2, {
|
|
6409
6937
|
...options,
|
|
6410
6938
|
distanceToItem: (index) => {
|
|
6411
|
-
const closest = getClosestPointOnTriangle(
|
|
6412
|
-
const distance = Math.hypot(
|
|
6939
|
+
const closest = getClosestPointOnTriangle(point2, ...this.triangle(index));
|
|
6940
|
+
const distance = Math.hypot(point2[0] - closest[0], point2[1] - closest[1], point2[2] - closest[2]);
|
|
6413
6941
|
if (!candidate || distance < candidate.distance || distance === candidate.distance && index < candidate.index)
|
|
6414
6942
|
candidate = { index, distance, point: closest };
|
|
6415
6943
|
return distance;
|
|
@@ -6420,15 +6948,15 @@ var TriangleBVH = class {
|
|
|
6420
6948
|
/** All triangle contacts with a closed sphere, sorted by original index (not distance).
|
|
6421
6949
|
* Uses closest points on faces, edges and vertices. No contact manifold reduction.
|
|
6422
6950
|
*/
|
|
6423
|
-
intersectSphere(center,
|
|
6951
|
+
intersectSphere(center, radius2, options = {}) {
|
|
6424
6952
|
validateQueryPoint(center, 3);
|
|
6425
|
-
if (!Number.isFinite(
|
|
6953
|
+
if (!Number.isFinite(radius2) || radius2 < 0)
|
|
6426
6954
|
throw new RangeError("Sphere radius must be finite and nonnegative");
|
|
6427
6955
|
const minimum = [], maximum = [];
|
|
6428
6956
|
for (let axis = 0; axis < 3; axis++) {
|
|
6429
|
-
const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]),
|
|
6430
|
-
minimum.push(center[axis] -
|
|
6431
|
-
maximum.push(center[axis] +
|
|
6957
|
+
const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius2));
|
|
6958
|
+
minimum.push(center[axis] - radius2 - padding);
|
|
6959
|
+
maximum.push(center[axis] + radius2 + padding);
|
|
6432
6960
|
}
|
|
6433
6961
|
const hits = /* @__PURE__ */ new Map();
|
|
6434
6962
|
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
@@ -6436,13 +6964,13 @@ var TriangleBVH = class {
|
|
|
6436
6964
|
filter: (index) => {
|
|
6437
6965
|
if (options.filter && !options.filter(index))
|
|
6438
6966
|
return false;
|
|
6439
|
-
const
|
|
6440
|
-
const distance = Math.hypot(center[0] -
|
|
6441
|
-
if (!
|
|
6967
|
+
const point2 = getClosestPointOnTriangle(center, ...this.triangle(index));
|
|
6968
|
+
const distance = Math.hypot(center[0] - point2[0], center[1] - point2[1], center[2] - point2[2]);
|
|
6969
|
+
if (!point2.every(Number.isFinite) || !Number.isFinite(distance))
|
|
6442
6970
|
throw new RangeError("Sphere query arithmetic overflow");
|
|
6443
|
-
if (distance >
|
|
6971
|
+
if (distance > radius2)
|
|
6444
6972
|
return false;
|
|
6445
|
-
hits.set(index, { index, distance, point });
|
|
6973
|
+
hits.set(index, { index, distance, point: point2 });
|
|
6446
6974
|
return true;
|
|
6447
6975
|
}
|
|
6448
6976
|
});
|
|
@@ -6469,10 +6997,10 @@ var TriangleBVH = class {
|
|
|
6469
6997
|
/** Closed capsule overlap, with one closest pair per accepted triangle.
|
|
6470
6998
|
* A straight translating sphere covers this volume, but segmentFraction is not first-impact time.
|
|
6471
6999
|
*/
|
|
6472
|
-
intersectCapsule(start, end,
|
|
6473
|
-
if (!Number.isFinite(
|
|
7000
|
+
intersectCapsule(start, end, radius2, options = {}) {
|
|
7001
|
+
if (!Number.isFinite(radius2) || radius2 < 0)
|
|
6474
7002
|
throw new RangeError("Capsule radius must be finite and nonnegative");
|
|
6475
|
-
const { minimum, maximum } = segmentBounds(start, end,
|
|
7003
|
+
const { minimum, maximum } = segmentBounds(start, end, radius2);
|
|
6476
7004
|
const hits = /* @__PURE__ */ new Map();
|
|
6477
7005
|
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
6478
7006
|
...options,
|
|
@@ -6480,7 +7008,7 @@ var TriangleBVH = class {
|
|
|
6480
7008
|
if (options.filter && !options.filter(index))
|
|
6481
7009
|
return false;
|
|
6482
7010
|
const closest = this.segmentClosest(index, start, end);
|
|
6483
|
-
if (closest.distance >
|
|
7011
|
+
if (closest.distance > radius2)
|
|
6484
7012
|
return false;
|
|
6485
7013
|
hits.set(index, closest);
|
|
6486
7014
|
return true;
|
|
@@ -6506,7 +7034,7 @@ var TriangleBVH = class {
|
|
|
6506
7034
|
return [vertex2(0), vertex2(1), vertex2(2)];
|
|
6507
7035
|
}
|
|
6508
7036
|
};
|
|
6509
|
-
function segmentBounds(start, end,
|
|
7037
|
+
function segmentBounds(start, end, radius2) {
|
|
6510
7038
|
validateQueryPoint(start, 3);
|
|
6511
7039
|
validateQueryPoint(end, 3);
|
|
6512
7040
|
for (let axis = 0; axis < 3; axis++)
|
|
@@ -6514,7 +7042,7 @@ function segmentBounds(start, end, radius) {
|
|
|
6514
7042
|
throw new RangeError("Segment coordinate span overflow");
|
|
6515
7043
|
const minimum = [], maximum = [];
|
|
6516
7044
|
for (let axis = 0; axis < 3; axis++) {
|
|
6517
|
-
const padding =
|
|
7045
|
+
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));
|
|
6518
7046
|
minimum.push(Math.min(start[axis], end[axis]) - padding);
|
|
6519
7047
|
maximum.push(Math.max(start[axis], end[axis]) + padding);
|
|
6520
7048
|
}
|
|
@@ -6687,4 +7215,113 @@ function quadraticMinimum(value) {
|
|
|
6687
7215
|
throw new RangeError("Nonfinite surface orientation");
|
|
6688
7216
|
return result;
|
|
6689
7217
|
}
|
|
7218
|
+
|
|
7219
|
+
// dist/utils/project-bounds.js
|
|
7220
|
+
function projectBounds(sourceBounds, options) {
|
|
7221
|
+
const [minimum, maximum] = sourceBounds;
|
|
7222
|
+
const size = minimum.length;
|
|
7223
|
+
const { transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz } = options;
|
|
7224
|
+
if (size !== 2 && size !== 3 || maximum.length !== size || targetSize !== 2 && targetSize !== 3) {
|
|
7225
|
+
throw new RangeError("Bounds and target dimension must be 2 or 3");
|
|
7226
|
+
}
|
|
7227
|
+
if (!Number.isSafeInteger(subdivisions) || subdivisions < 1 || !Number.isSafeInteger(maxSamples) || maxSamples < 1) {
|
|
7228
|
+
throw new RangeError("Subdivision and sample budgets must be positive safe integers");
|
|
7229
|
+
}
|
|
7230
|
+
if (lipschitz && (lipschitz.length !== targetSize || !Array.from(lipschitz).every((value) => Number.isFinite(value) && value >= 0))) {
|
|
7231
|
+
throw new RangeError("Lipschitz constants must be finite, nonnegative and match target size");
|
|
7232
|
+
}
|
|
7233
|
+
const widths = [];
|
|
7234
|
+
const counts = [];
|
|
7235
|
+
let count = 1;
|
|
7236
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7237
|
+
const width = maximum[axis] - minimum[axis];
|
|
7238
|
+
if (!Number.isFinite(minimum[axis]) || !Number.isFinite(maximum[axis]) || !Number.isFinite(width) || width < 0) {
|
|
7239
|
+
throw new RangeError("Source bounds must have finite ordered coordinates and extents");
|
|
7240
|
+
}
|
|
7241
|
+
widths.push(width);
|
|
7242
|
+
counts.push(width === 0 ? 1 : subdivisions + 1);
|
|
7243
|
+
count *= counts[axis];
|
|
7244
|
+
if (!Number.isSafeInteger(count) || count > maxSamples) {
|
|
7245
|
+
throw new RangeError("Projected bounds exceed the sample budget");
|
|
7246
|
+
}
|
|
7247
|
+
}
|
|
7248
|
+
const lower = new Array(targetSize).fill(Infinity);
|
|
7249
|
+
const upper = new Array(targetSize).fill(-Infinity);
|
|
7250
|
+
for (let index = 0; index < count; index++) {
|
|
7251
|
+
let remaining = index;
|
|
7252
|
+
const source = [];
|
|
7253
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7254
|
+
const step = remaining % counts[axis];
|
|
7255
|
+
remaining = Math.floor(remaining / counts[axis]);
|
|
7256
|
+
source.push(step === 0 ? minimum[axis] : step === subdivisions ? maximum[axis] : minimum[axis] + widths[axis] * (step / subdivisions));
|
|
7257
|
+
}
|
|
7258
|
+
const projected = transform(source);
|
|
7259
|
+
if (!projected || projected.length < targetSize) {
|
|
7260
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7261
|
+
}
|
|
7262
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7263
|
+
if (!Number.isFinite(projected[axis]))
|
|
7264
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7265
|
+
lower[axis] = Math.min(lower[axis], projected[axis]);
|
|
7266
|
+
upper[axis] = Math.max(upper[axis], projected[axis]);
|
|
7267
|
+
}
|
|
7268
|
+
}
|
|
7269
|
+
if (lipschitz) {
|
|
7270
|
+
const radius2 = Math.hypot(...widths.map((width, axis) => width / subdivisions / 2 + 4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))));
|
|
7271
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7272
|
+
const displacement = lipschitz[axis] * radius2;
|
|
7273
|
+
const roundoff = 8 * Number.EPSILON * Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
|
|
7274
|
+
lower[axis] -= displacement + roundoff;
|
|
7275
|
+
upper[axis] += displacement + roundoff;
|
|
7276
|
+
if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
|
|
7277
|
+
return { status: "invalid", bounds: null, sampleCount: count };
|
|
7278
|
+
}
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
return {
|
|
7282
|
+
status: lipschitz ? "conservative" : "sampled",
|
|
7283
|
+
bounds: [lower, upper],
|
|
7284
|
+
sampleCount: count
|
|
7285
|
+
};
|
|
7286
|
+
}
|
|
7287
|
+
|
|
7288
|
+
// dist/utils/project-texture-coordinates.js
|
|
7289
|
+
function projectTextureCoordinates(positions, options) {
|
|
7290
|
+
const { transform, bounds, size = 3, origin = "top-left" } = options;
|
|
7291
|
+
if (size !== 2 && size !== 3)
|
|
7292
|
+
throw new RangeError("Source size must be 2 or 3");
|
|
7293
|
+
if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
|
|
7294
|
+
throw new RangeError("Positions must contain complete packed vertices");
|
|
7295
|
+
}
|
|
7296
|
+
if (origin !== "top-left" && origin !== "bottom-left") {
|
|
7297
|
+
throw new RangeError("Invalid texture origin");
|
|
7298
|
+
}
|
|
7299
|
+
if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
|
|
7300
|
+
throw new RangeError("Image bounds must contain four finite values");
|
|
7301
|
+
}
|
|
7302
|
+
const [left, bottom, right, top] = bounds;
|
|
7303
|
+
const width = right - left;
|
|
7304
|
+
const height = top - bottom;
|
|
7305
|
+
if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
7306
|
+
throw new RangeError("Image bounds must have finite positive extents");
|
|
7307
|
+
}
|
|
7308
|
+
const count = positions.length / size;
|
|
7309
|
+
const result = new Float64Array(count * 2);
|
|
7310
|
+
for (let index = 0; index < count; index++) {
|
|
7311
|
+
const source = Array.from({ length: size }, (_, axis) => positions[index * size + axis]);
|
|
7312
|
+
if (!source.every(Number.isFinite))
|
|
7313
|
+
throw new RangeError(`Invalid source vertex ${index}`);
|
|
7314
|
+
const projected = transform(source);
|
|
7315
|
+
if (!projected || projected.length < 2 || !Number.isFinite(projected[0]) || !Number.isFinite(projected[1])) {
|
|
7316
|
+
throw new RangeError(`Invalid projected vertex ${index}`);
|
|
7317
|
+
}
|
|
7318
|
+
const u = (projected[0] - left) / width;
|
|
7319
|
+
const v = origin === "top-left" ? (top - projected[1]) / height : (projected[1] - bottom) / height;
|
|
7320
|
+
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
7321
|
+
throw new RangeError(`Invalid UV at vertex ${index}`);
|
|
7322
|
+
result[index * 2] = u;
|
|
7323
|
+
result[index * 2 + 1] = v;
|
|
7324
|
+
}
|
|
7325
|
+
return result;
|
|
7326
|
+
}
|
|
6690
7327
|
//# sourceMappingURL=index.cjs.map
|