@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.10
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/LICENSE +97 -49
- package/README.md +77 -1
- package/THIRD-PARTY-NOTICES.md +18 -0
- 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/constants.d.ts +3 -0
- package/dist/culling/constants.d.ts.map +1 -0
- package/dist/culling/constants.js +5 -0
- package/dist/culling/constants.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 +2560 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +37 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +29 -0
- package/dist/culling/index.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +133 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/culling/lib/culling-volume.d.ts +49 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +133 -0
- package/dist/culling/lib/culling-volume.js.map +1 -0
- package/dist/culling/lib/perspective-frustum.d.ts +153 -0
- package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-frustum.js +191 -0
- package/dist/culling/lib/perspective-frustum.js.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
- package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/culling/lib/plane.d.ts +35 -0
- package/dist/culling/lib/plane.d.ts.map +1 -0
- package/dist/culling/lib/plane.js +90 -0
- package/dist/culling/lib/plane.js.map +1 -0
- package/dist/culling/lib/ray.d.ts +18 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +51 -0
- package/dist/culling/lib/ray.js.map +1 -0
- package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
- package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/box-shape.js +69 -0
- package/dist/culling/lib/shapes/box-shape.js.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.js +151 -0
- package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
- package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.js +142 -0
- package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.js +71 -0
- package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.js +43 -0
- package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
- package/dist/culling/oriented-box-2d.d.ts +22 -0
- package/dist/culling/oriented-box-2d.d.ts.map +1 -0
- package/dist/culling/oriented-box-2d.js +86 -0
- package/dist/culling/oriented-box-2d.js.map +1 -0
- package/dist/culling/queries.d.ts +44 -0
- package/dist/culling/queries.d.ts.map +1 -0
- package/dist/culling/queries.js +259 -0
- package/dist/culling/queries.js.map +1 -0
- package/dist/culling/screen-ray.d.ts +22 -0
- package/dist/culling/screen-ray.d.ts.map +1 -0
- package/dist/culling/screen-ray.js +55 -0
- package/dist/culling/screen-ray.js.map +1 -0
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/bezier-curves.d.ts +18 -0
- package/dist/curves/bezier-curves.d.ts.map +1 -0
- package/dist/curves/bezier-curves.js +54 -0
- package/dist/curves/bezier-curves.js.map +1 -0
- package/dist/curves/catmull-rom-curve.d.ts +15 -0
- package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
- package/dist/curves/catmull-rom-curve.js +77 -0
- package/dist/curves/catmull-rom-curve.js.map +1 -0
- package/dist/curves/curve-arc-length.d.ts +17 -0
- package/dist/curves/curve-arc-length.d.ts.map +1 -0
- package/dist/curves/curve-arc-length.js +58 -0
- package/dist/curves/curve-arc-length.js.map +1 -0
- package/dist/curves/curve.d.ts +23 -0
- package/dist/curves/curve.d.ts.map +1 -0
- package/dist/curves/curve.js +77 -0
- package/dist/curves/curve.js.map +1 -0
- package/dist/curves/hermite-curve.d.ts +9 -0
- package/dist/curves/hermite-curve.d.ts.map +1 -0
- package/dist/curves/hermite-curve.js +24 -0
- package/dist/curves/hermite-curve.js.map +1 -0
- package/dist/curves/index.d.ts +12 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +11 -0
- package/dist/curves/index.js.map +1 -0
- 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/geometries/box-geometry.js +1 -1
- package/dist/geometries/box-geometry.js.map +1 -1
- package/dist/geometries/capsule-geometry.js +1 -1
- package/dist/geometries/capsule-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/geometry-helpers.js +1 -1
- package/dist/geometries/geometry-helpers.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
- package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
- package/dist/geometries/primitive-mesh-builder.js +74 -0
- package/dist/geometries/primitive-mesh-builder.js.map +1 -0
- package/dist/geometries/prism-geometry.d.ts +13 -0
- package/dist/geometries/prism-geometry.d.ts.map +1 -0
- package/dist/geometries/prism-geometry.js +34 -0
- package/dist/geometries/prism-geometry.js.map +1 -0
- package/dist/geometries/ring-geometry.d.ts +15 -0
- package/dist/geometries/ring-geometry.d.ts.map +1 -0
- package/dist/geometries/ring-geometry.js +64 -0
- package/dist/geometries/ring-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/surface-of-revolution.js +1 -1
- package/dist/geometries/surface-of-revolution.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +1 -1
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/index.cjs +6993 -37
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/geometry-utils.js +1 -1
- package/dist/lib/geometry-utils.js.map +1 -1
- package/dist/lib/geometry.d.ts +1 -1
- package/dist/lib/geometry.d.ts.map +1 -1
- package/dist/lib/geometry.js +1 -1
- package/dist/lib/geometry.js.map +1 -1
- package/dist/lib/hinge-tree.d.ts +33 -0
- package/dist/lib/hinge-tree.d.ts.map +1 -0
- package/dist/lib/hinge-tree.js +144 -0
- package/dist/lib/hinge-tree.js.map +1 -0
- 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/parametric/lathe-geometry.d.ts +14 -0
- package/dist/parametric/lathe-geometry.d.ts.map +1 -0
- package/dist/parametric/lathe-geometry.js +48 -0
- package/dist/parametric/lathe-geometry.js.map +1 -0
- package/dist/parametric/parametric-geometry.d.ts +20 -0
- package/dist/parametric/parametric-geometry.d.ts.map +1 -0
- package/dist/parametric/parametric-geometry.js +88 -0
- package/dist/parametric/parametric-geometry.js.map +1 -0
- package/dist/parametric/torus-geometry.d.ts +19 -0
- package/dist/parametric/torus-geometry.d.ts.map +1 -0
- package/dist/parametric/torus-geometry.js +89 -0
- package/dist/parametric/torus-geometry.js.map +1 -0
- package/dist/parametric.d.ts +7 -0
- package/dist/parametric.d.ts.map +1 -0
- package/dist/parametric.js +7 -0
- package/dist/parametric.js.map +1 -0
- package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
- package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/clip-triangle-mesh.js +155 -0
- package/dist/polygon/clip-triangle-mesh.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts +24 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -0
- package/dist/polygon/cut-by-grid.js +221 -0
- package/dist/polygon/cut-by-grid.js.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.js +149 -0
- package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
- package/dist/polygon/earcut.d.ts +13 -0
- package/dist/polygon/earcut.d.ts.map +1 -0
- package/dist/polygon/earcut.js +693 -0
- package/dist/polygon/earcut.js.map +1 -0
- package/dist/polygon/index.d.ts +16 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +14 -0
- package/dist/polygon/index.js.map +1 -0
- package/dist/polygon/lineclip.d.ts +31 -0
- package/dist/polygon/lineclip.d.ts.map +1 -0
- package/dist/polygon/lineclip.js +184 -0
- package/dist/polygon/lineclip.js.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.js +285 -0
- package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
- package/dist/polygon/polygon-utils.d.ts +103 -0
- package/dist/polygon/polygon-utils.d.ts.map +1 -0
- package/dist/polygon/polygon-utils.js +155 -0
- package/dist/polygon/polygon-utils.js.map +1 -0
- package/dist/polygon/polygon.d.ts +41 -0
- package/dist/polygon/polygon.d.ts.map +1 -0
- package/dist/polygon/polygon.js +76 -0
- package/dist/polygon/polygon.js.map +1 -0
- package/dist/polygon/subdivide-polyline.d.ts +56 -0
- package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
- package/dist/polygon/subdivide-polyline.js +141 -0
- package/dist/polygon/subdivide-polyline.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +238 -0
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
- package/dist/polygon/utils.d.ts +5 -0
- package/dist/polygon/utils.d.ts.map +1 -0
- package/dist/polygon/utils.js +38 -0
- package/dist/polygon/utils.js.map +1 -0
- package/dist/spatial-index/box-index.d.ts +86 -0
- package/dist/spatial-index/box-index.d.ts.map +1 -0
- package/dist/spatial-index/box-index.js +335 -0
- package/dist/spatial-index/box-index.js.map +1 -0
- package/dist/spatial-index/index.d.ts +7 -0
- package/dist/spatial-index/index.d.ts.map +1 -0
- package/dist/spatial-index/index.js +6 -0
- package/dist/spatial-index/index.js.map +1 -0
- package/dist/spatial-index/triangle-bvh.d.ts +74 -0
- package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
- package/dist/spatial-index/triangle-bvh.js +221 -0
- package/dist/spatial-index/triangle-bvh.js.map +1 -0
- package/dist/utils/attribute-compression.d.ts +50 -0
- package/dist/utils/attribute-compression.d.ts.map +1 -0
- package/dist/utils/attribute-compression.js +186 -0
- package/dist/utils/attribute-compression.js.map +1 -0
- package/dist/utils/attribute-iterator.d.ts +8 -0
- package/dist/utils/attribute-iterator.d.ts.map +1 -0
- package/dist/utils/attribute-iterator.js +25 -0
- package/dist/utils/attribute-iterator.js.map +1 -0
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +4 -0
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
- package/dist/utils/compute-vertex-normals.js +54 -0
- package/dist/utils/compute-vertex-normals.js.map +1 -0
- package/dist/utils/constants.d.ts +52 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +39 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coordinates.d.ts +3 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +8 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/dist/utils/geometry.d.ts +20 -0
- package/dist/utils/geometry.d.ts.map +1 -0
- package/dist/utils/geometry.js +31 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/gl-type.d.ts +17 -0
- package/dist/utils/gl-type.d.ts.map +1 -0
- package/dist/utils/gl-type.js +69 -0
- package/dist/utils/gl-type.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
- package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
- package/dist/utils/interpolate-packed-attributes.js +192 -0
- package/dist/utils/interpolate-packed-attributes.js.map +1 -0
- package/dist/utils/mesh-processing.d.ts +18 -0
- package/dist/utils/mesh-processing.d.ts.map +1 -0
- package/dist/utils/mesh-processing.js +300 -0
- package/dist/utils/mesh-processing.js.map +1 -0
- package/dist/utils/primitive-iterator.d.ts +21 -0
- package/dist/utils/primitive-iterator.d.ts.map +1 -0
- package/dist/utils/primitive-iterator.js +117 -0
- package/dist/utils/primitive-iterator.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/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/dist/utils/rgb565.d.ts +5 -0
- package/dist/utils/rgb565.d.ts.map +1 -0
- package/dist/utils/rgb565.js +24 -0
- package/dist/utils/rgb565.js.map +1 -0
- package/dist/utils/typed-array-utils.d.ts +3 -0
- package/dist/utils/typed-array-utils.d.ts.map +1 -0
- package/dist/utils/typed-array-utils.js +16 -0
- package/dist/utils/typed-array-utils.js.map +1 -0
- package/package.json +24 -4
- 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/constants.ts +6 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +93 -0
- package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
- package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
- package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
- package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +171 -0
- package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
- package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
- package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
- package/src/culling/lib/culling-volume.ts +171 -0
- package/src/culling/lib/perspective-frustum.ts +288 -0
- package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
- package/src/culling/lib/plane.ts +118 -0
- package/src/culling/lib/ray.ts +54 -0
- package/src/culling/lib/shapes/box-shape.ts +78 -0
- package/src/culling/lib/shapes/capsule-shape.ts +232 -0
- package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
- package/src/culling/lib/shapes/implicit-shape.ts +209 -0
- package/src/culling/lib/shapes/plane-shape.ts +78 -0
- package/src/culling/lib/shapes/sphere-shape.ts +60 -0
- package/src/culling/oriented-box-2d.ts +165 -0
- package/src/culling/queries.ts +332 -0
- package/src/culling/screen-ray.ts +75 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/bezier-curves.ts +62 -0
- package/src/curves/catmull-rom-curve.ts +89 -0
- package/src/curves/curve-arc-length.ts +70 -0
- package/src/curves/curve.ts +96 -0
- package/src/curves/hermite-curve.ts +34 -0
- package/src/curves/index.ts +19 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/geometries/box-geometry.ts +1 -1
- package/src/geometries/capsule-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/geometry-helpers.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/primitive-mesh-builder.ts +84 -0
- package/src/geometries/prism-geometry.ts +57 -0
- package/src/geometries/ring-geometry.ts +102 -0
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/surface-of-revolution.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +1 -1
- package/src/index.ts +226 -1
- package/src/lib/geometry-utils.ts +2 -2
- package/src/lib/geometry.ts +2 -2
- package/src/lib/hinge-tree.ts +170 -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/parametric/lathe-geometry.ts +70 -0
- package/src/parametric/parametric-geometry.ts +118 -0
- package/src/parametric/torus-geometry.ts +118 -0
- package/src/parametric.ts +9 -0
- package/src/polygon/clip-triangle-mesh.ts +218 -0
- package/src/polygon/cut-by-grid.ts +313 -0
- package/src/polygon/cut-by-mercator-bounds.ts +204 -0
- package/src/polygon/earcut.ts +859 -0
- package/src/polygon/index.ts +48 -0
- package/src/polygon/lineclip.ts +218 -0
- package/src/polygon/pole-of-inaccessibility.ts +330 -0
- package/src/polygon/polygon-utils.ts +273 -0
- package/src/polygon/polygon.ts +105 -0
- package/src/polygon/subdivide-polyline.ts +223 -0
- package/src/polygon/subdivide-triangle-mesh.ts +342 -0
- package/src/polygon/utils.ts +50 -0
- package/src/spatial-index/box-index.ts +452 -0
- package/src/spatial-index/index.ts +20 -0
- package/src/spatial-index/triangle-bvh.ts +345 -0
- package/src/utils/attribute-compression.ts +234 -0
- package/src/utils/attribute-iterator.ts +28 -0
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +63 -0
- package/src/utils/constants.ts +42 -0
- package/src/utils/coordinates.ts +8 -0
- package/src/utils/geometry.ts +49 -0
- package/src/utils/gl-type.ts +87 -0
- package/src/utils/index.ts +55 -0
- package/src/utils/interpolate-packed-attributes.ts +284 -0
- package/src/utils/mesh-processing.ts +377 -0
- package/src/utils/primitive-iterator.ts +145 -0
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/src/utils/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,2560 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// dist/culling/index.js
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
AxisAlignedBoundingBox: () => AxisAlignedBoundingBox,
|
|
23
|
+
BoundingSphere: () => BoundingSphere,
|
|
24
|
+
BoxShape: () => BoxShape,
|
|
25
|
+
CapsuleShape: () => CapsuleShape,
|
|
26
|
+
CullingVolume: () => CullingVolume,
|
|
27
|
+
CylinderShape: () => CylinderShape,
|
|
28
|
+
OrientedBoundingBox: () => OrientedBoundingBox,
|
|
29
|
+
Plane: () => Plane,
|
|
30
|
+
PlaneShape: () => PlaneShape,
|
|
31
|
+
Ray: () => Ray,
|
|
32
|
+
SphereShape: () => SphereShape,
|
|
33
|
+
_PerspectiveFrustum: () => PerspectiveFrustum,
|
|
34
|
+
_PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
|
|
35
|
+
boundsContainsBounds: () => boundsContainsBounds,
|
|
36
|
+
boundsContainsPoint: () => boundsContainsPoint,
|
|
37
|
+
boundsIntersect: () => boundsIntersect,
|
|
38
|
+
boundsIntersectSphere: () => boundsIntersectSphere,
|
|
39
|
+
clampPointToBounds: () => clampPointToBounds,
|
|
40
|
+
computeEigenDecomposition: () => computeEigenDecomposition,
|
|
41
|
+
createEmptyBounds: () => createEmptyBounds,
|
|
42
|
+
distanceToRay: () => distanceToRay,
|
|
43
|
+
expandBounds: () => expandBounds,
|
|
44
|
+
expandBoundsByPoint: () => expandBoundsByPoint,
|
|
45
|
+
extractFrustumPlanes: () => extractFrustumPlanes,
|
|
46
|
+
getClosestPointOnRay: () => getClosestPointOnRay,
|
|
47
|
+
getClosestPointOnTriangle: () => getClosestPointOnTriangle,
|
|
48
|
+
getClosestPointsOnSegments: () => getClosestPointsOnSegments,
|
|
49
|
+
getClosestPointsRaySegment: () => getClosestPointsRaySegment,
|
|
50
|
+
getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
|
|
51
|
+
getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
|
|
52
|
+
getRayPoint: () => getRayPoint,
|
|
53
|
+
getTriangleArea: () => getTriangleArea,
|
|
54
|
+
getTriangleBarycentric: () => getTriangleBarycentric,
|
|
55
|
+
getTriangleNormal: () => getTriangleNormal,
|
|
56
|
+
interpolateTriangleAttribute: () => interpolateTriangleAttribute,
|
|
57
|
+
intersectBounds: () => intersectBounds,
|
|
58
|
+
intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
|
|
59
|
+
intersectPlaneSegment: () => intersectPlaneSegment,
|
|
60
|
+
intersectRayBounds: () => intersectRayBounds,
|
|
61
|
+
intersectRayTriangle: () => intersectRayTriangle,
|
|
62
|
+
isEmptyBounds: () => isEmptyBounds,
|
|
63
|
+
isTriangleFrontFacing: () => isTriangleFrontFacing,
|
|
64
|
+
makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
|
|
65
|
+
makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
|
|
66
|
+
makeOrientedBoundingBoxFromPoints: () => makeOrientedBoundingBoxFromPoints,
|
|
67
|
+
makeOrientedBoundingBoxFromQuaternion: () => makeOrientedBoundingBoxFromQuaternion,
|
|
68
|
+
normalizeQueryDirection: () => normalizeQueryDirection,
|
|
69
|
+
spheresIntersect: () => spheresIntersect,
|
|
70
|
+
transformRay: () => transformRay,
|
|
71
|
+
triangleContainsPoint: () => triangleContainsPoint,
|
|
72
|
+
triangleIntersectsBounds: () => triangleIntersectsBounds,
|
|
73
|
+
unionBounds: () => unionBounds,
|
|
74
|
+
unprojectScreenRay: () => unprojectScreenRay,
|
|
75
|
+
validateQueryDistance: () => validateQueryDistance,
|
|
76
|
+
validateQueryPoint: () => validateQueryPoint
|
|
77
|
+
});
|
|
78
|
+
module.exports = __toCommonJS(index_exports);
|
|
79
|
+
|
|
80
|
+
// dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js
|
|
81
|
+
var import_core = require("@math.gl/core");
|
|
82
|
+
var scratchVector = new import_core.Vector3();
|
|
83
|
+
var scratchNormal = new import_core.Vector3();
|
|
84
|
+
var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
|
|
85
|
+
/**
|
|
86
|
+
* Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.
|
|
87
|
+
* @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.
|
|
88
|
+
* @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.
|
|
89
|
+
* @param center The center of the box; automatically computed if not supplied.
|
|
90
|
+
*/
|
|
91
|
+
constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) {
|
|
92
|
+
center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
|
|
93
|
+
this.center = new import_core.Vector3(center);
|
|
94
|
+
this.halfDiagonal = new import_core.Vector3(maximum).subtract(this.center);
|
|
95
|
+
this.minimum = new import_core.Vector3(minimum);
|
|
96
|
+
this.maximum = new import_core.Vector3(maximum);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Duplicates a AxisAlignedBoundingBox instance.
|
|
100
|
+
*
|
|
101
|
+
* @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.
|
|
102
|
+
*/
|
|
103
|
+
clone() {
|
|
104
|
+
return new _AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Compares the provided AxisAlignedBoundingBox componentwise and returns
|
|
108
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
109
|
+
*
|
|
110
|
+
* @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.
|
|
111
|
+
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
|
|
112
|
+
*/
|
|
113
|
+
equals(right) {
|
|
114
|
+
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
|
|
118
|
+
* @param transform The affine transformation matrix.
|
|
119
|
+
* @returns itself, i.e. the modified bounding box.
|
|
120
|
+
*/
|
|
121
|
+
transform(transform) {
|
|
122
|
+
if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
|
|
123
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
124
|
+
}
|
|
125
|
+
const center = this.minimum.clone().add(this.maximum).scale(0.5);
|
|
126
|
+
const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
|
|
127
|
+
if (extent.some((x) => x < 0))
|
|
128
|
+
throw new RangeError("Bounds must be ordered");
|
|
129
|
+
center.transformAsPoint(transform);
|
|
130
|
+
for (let row = 0; row < 3; row++) {
|
|
131
|
+
this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
|
|
132
|
+
}
|
|
133
|
+
this.center.copy(center);
|
|
134
|
+
this.minimum.copy(center).subtract(this.halfDiagonal);
|
|
135
|
+
this.maximum.copy(center).add(this.halfDiagonal);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Determines which side of a plane a box is located.
|
|
140
|
+
*/
|
|
141
|
+
intersectPlane(plane) {
|
|
142
|
+
const { halfDiagonal } = this;
|
|
143
|
+
const normal = scratchNormal.from(plane.normal);
|
|
144
|
+
const e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
|
|
145
|
+
const s = this.center.dot(normal) + plane.distance;
|
|
146
|
+
if (s - e > 0) {
|
|
147
|
+
return "inside";
|
|
148
|
+
}
|
|
149
|
+
if (s + e < 0) {
|
|
150
|
+
return "outside";
|
|
151
|
+
}
|
|
152
|
+
return "intersecting";
|
|
153
|
+
}
|
|
154
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
155
|
+
distanceTo(point2) {
|
|
156
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
157
|
+
}
|
|
158
|
+
/** Computes the estimated distance squared from the closest point on a bounding box to a point. */
|
|
159
|
+
distanceSquaredTo(point2) {
|
|
160
|
+
const offset = scratchVector.from(point2).subtract(this.center);
|
|
161
|
+
const { halfDiagonal } = this;
|
|
162
|
+
let distanceSquared = 0;
|
|
163
|
+
let d;
|
|
164
|
+
d = Math.abs(offset.x) - halfDiagonal.x;
|
|
165
|
+
if (d > 0) {
|
|
166
|
+
distanceSquared += d * d;
|
|
167
|
+
}
|
|
168
|
+
d = Math.abs(offset.y) - halfDiagonal.y;
|
|
169
|
+
if (d > 0) {
|
|
170
|
+
distanceSquared += d * d;
|
|
171
|
+
}
|
|
172
|
+
d = Math.abs(offset.z) - halfDiagonal.z;
|
|
173
|
+
if (d > 0) {
|
|
174
|
+
distanceSquared += d * d;
|
|
175
|
+
}
|
|
176
|
+
return distanceSquared;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// dist/culling/lib/bounding-volumes/bounding-sphere.js
|
|
181
|
+
var import_core2 = require("@math.gl/core");
|
|
182
|
+
var import_core3 = require("@math.gl/core");
|
|
183
|
+
var scratchVector2 = new import_core2.Vector3();
|
|
184
|
+
var scratchVector22 = new import_core2.Vector3();
|
|
185
|
+
var BoundingSphere = class _BoundingSphere {
|
|
186
|
+
/** Creates a bounding sphere */
|
|
187
|
+
constructor(center = [0, 0, 0], radius2 = 0) {
|
|
188
|
+
this.radius = -0;
|
|
189
|
+
this.center = new import_core2.Vector3();
|
|
190
|
+
this.fromCenterRadius(center, radius2);
|
|
191
|
+
}
|
|
192
|
+
/** Sets the bounding sphere from `center` and `radius`. */
|
|
193
|
+
fromCenterRadius(center, radius2) {
|
|
194
|
+
this.center.from(center);
|
|
195
|
+
this.radius = radius2;
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere
|
|
200
|
+
* tightly and fully encompasses the box.
|
|
201
|
+
*/
|
|
202
|
+
fromCornerPoints(corner, oppositeCorner) {
|
|
203
|
+
oppositeCorner = scratchVector2.from(oppositeCorner);
|
|
204
|
+
this.center = new import_core2.Vector3().from(corner).add(oppositeCorner).scale(0.5);
|
|
205
|
+
this.radius = this.center.distance(oppositeCorner);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
/** Compares the provided BoundingSphere component wise */
|
|
209
|
+
equals(right) {
|
|
210
|
+
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
|
|
211
|
+
}
|
|
212
|
+
/** Duplicates a BoundingSphere instance. */
|
|
213
|
+
clone() {
|
|
214
|
+
return new _BoundingSphere(this.center, this.radius);
|
|
215
|
+
}
|
|
216
|
+
/** Computes a bounding sphere that contains both the left and right bounding spheres. */
|
|
217
|
+
union(boundingSphere) {
|
|
218
|
+
const leftCenter = this.center;
|
|
219
|
+
const leftRadius = this.radius;
|
|
220
|
+
const rightCenter = boundingSphere.center;
|
|
221
|
+
const rightRadius = boundingSphere.radius;
|
|
222
|
+
const toRightCenter = scratchVector2.copy(rightCenter).subtract(leftCenter);
|
|
223
|
+
const centerSeparation = toRightCenter.magnitude();
|
|
224
|
+
if (leftRadius >= centerSeparation + rightRadius) {
|
|
225
|
+
return this.clone();
|
|
226
|
+
}
|
|
227
|
+
if (rightRadius >= centerSeparation + leftRadius) {
|
|
228
|
+
return boundingSphere.clone();
|
|
229
|
+
}
|
|
230
|
+
const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
|
|
231
|
+
scratchVector22.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
|
|
232
|
+
this.center.copy(scratchVector22);
|
|
233
|
+
this.radius = halfDistanceBetweenTangentPoints;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
/** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
|
|
237
|
+
expand(point2) {
|
|
238
|
+
const scratchPoint = scratchVector2.from(point2);
|
|
239
|
+
const radius2 = scratchPoint.subtract(this.center).magnitude();
|
|
240
|
+
if (radius2 > this.radius) {
|
|
241
|
+
this.radius = radius2;
|
|
242
|
+
}
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
// BoundingVolume interface
|
|
246
|
+
/**
|
|
247
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
248
|
+
* @param sphere The bounding sphere to apply the transformation to.
|
|
249
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
250
|
+
* @returns self.
|
|
251
|
+
*/
|
|
252
|
+
transform(transform) {
|
|
253
|
+
this.center.transform(transform);
|
|
254
|
+
const scale = (0, import_core3.mat4GetScaling)(scratchVector2, transform);
|
|
255
|
+
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
/** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
|
|
259
|
+
distanceSquaredTo(point2) {
|
|
260
|
+
const d = this.distanceTo(point2);
|
|
261
|
+
return d * d;
|
|
262
|
+
}
|
|
263
|
+
/** Computes the estimated distance from the closest point on a bounding sphere to a point. */
|
|
264
|
+
distanceTo(point2) {
|
|
265
|
+
const scratchPoint = scratchVector2.from(point2);
|
|
266
|
+
const delta = scratchPoint.subtract(this.center);
|
|
267
|
+
return Math.max(0, delta.len() - this.radius);
|
|
268
|
+
}
|
|
269
|
+
/** Determines which side of a plane a sphere is located. */
|
|
270
|
+
intersectPlane(plane) {
|
|
271
|
+
const center = this.center;
|
|
272
|
+
const radius2 = this.radius;
|
|
273
|
+
const normal = plane.normal;
|
|
274
|
+
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
275
|
+
if (distanceToPlane < -radius2) {
|
|
276
|
+
return "outside";
|
|
277
|
+
}
|
|
278
|
+
if (distanceToPlane < radius2) {
|
|
279
|
+
return "intersecting";
|
|
280
|
+
}
|
|
281
|
+
return "inside";
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// dist/culling/lib/bounding-volumes/oriented-bounding-box.js
|
|
286
|
+
var import_core4 = require("@math.gl/core");
|
|
287
|
+
var scratchVector3 = new import_core4.Vector3();
|
|
288
|
+
var scratchOffset = new import_core4.Vector3();
|
|
289
|
+
var scratchVectorU = new import_core4.Vector3();
|
|
290
|
+
var scratchVectorV = new import_core4.Vector3();
|
|
291
|
+
var scratchVectorW = new import_core4.Vector3();
|
|
292
|
+
var scratchCorner = new import_core4.Vector3();
|
|
293
|
+
var scratchToCenter = new import_core4.Vector3();
|
|
294
|
+
var MATRIX3 = {
|
|
295
|
+
COLUMN0ROW0: 0,
|
|
296
|
+
COLUMN0ROW1: 1,
|
|
297
|
+
COLUMN0ROW2: 2,
|
|
298
|
+
COLUMN1ROW0: 3,
|
|
299
|
+
COLUMN1ROW1: 4,
|
|
300
|
+
COLUMN1ROW2: 5,
|
|
301
|
+
COLUMN2ROW0: 6,
|
|
302
|
+
COLUMN2ROW1: 7,
|
|
303
|
+
COLUMN2ROW2: 8
|
|
304
|
+
};
|
|
305
|
+
var OrientedBoundingBox = class _OrientedBoundingBox {
|
|
306
|
+
constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
|
|
307
|
+
this.center = new import_core4.Vector3().from(center);
|
|
308
|
+
this.halfAxes = new import_core4.Matrix3(halfAxes);
|
|
309
|
+
}
|
|
310
|
+
/** Returns an array with three halfSizes for the bounding box */
|
|
311
|
+
get halfSize() {
|
|
312
|
+
const xAxis = this.halfAxes.getColumn(0);
|
|
313
|
+
const yAxis = this.halfAxes.getColumn(1);
|
|
314
|
+
const zAxis = this.halfAxes.getColumn(2);
|
|
315
|
+
return [new import_core4.Vector3(xAxis).len(), new import_core4.Vector3(yAxis).len(), new import_core4.Vector3(zAxis).len()];
|
|
316
|
+
}
|
|
317
|
+
/** Duplicates a OrientedBoundingBox instance. */
|
|
318
|
+
clone() {
|
|
319
|
+
return new _OrientedBoundingBox(this.center, this.halfAxes);
|
|
320
|
+
}
|
|
321
|
+
/** Compares the provided OrientedBoundingBox component wise and returns */
|
|
322
|
+
equals(right) {
|
|
323
|
+
return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);
|
|
324
|
+
}
|
|
325
|
+
/** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
|
|
326
|
+
getBoundingSphere(result = new BoundingSphere()) {
|
|
327
|
+
const halfAxes = this.halfAxes;
|
|
328
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
329
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
330
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
331
|
+
const cornerVector = scratchVector3.copy(u).add(v).add(w);
|
|
332
|
+
result.center.copy(this.center);
|
|
333
|
+
result.radius = cornerVector.magnitude();
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
/** Determines which side of a plane the oriented bounding box is located. */
|
|
337
|
+
intersectPlane(plane) {
|
|
338
|
+
const center = this.center;
|
|
339
|
+
const normal = plane.normal;
|
|
340
|
+
const halfAxes = this.halfAxes;
|
|
341
|
+
const normalX = normal.x;
|
|
342
|
+
const normalY = normal.y;
|
|
343
|
+
const normalZ = normal.z;
|
|
344
|
+
const radEffective = Math.abs(normalX * halfAxes[MATRIX3.COLUMN0ROW0] + normalY * halfAxes[MATRIX3.COLUMN0ROW1] + normalZ * halfAxes[MATRIX3.COLUMN0ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN1ROW0] + normalY * halfAxes[MATRIX3.COLUMN1ROW1] + normalZ * halfAxes[MATRIX3.COLUMN1ROW2]) + Math.abs(normalX * halfAxes[MATRIX3.COLUMN2ROW0] + normalY * halfAxes[MATRIX3.COLUMN2ROW1] + normalZ * halfAxes[MATRIX3.COLUMN2ROW2]);
|
|
345
|
+
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
346
|
+
if (distanceToPlane <= -radEffective) {
|
|
347
|
+
return "outside";
|
|
348
|
+
} else if (distanceToPlane >= radEffective) {
|
|
349
|
+
return "inside";
|
|
350
|
+
}
|
|
351
|
+
return "intersecting";
|
|
352
|
+
}
|
|
353
|
+
/** Computes the estimated distance from the closest point on a bounding box to a point. */
|
|
354
|
+
distanceTo(point2) {
|
|
355
|
+
return Math.sqrt(this.distanceSquaredTo(point2));
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Computes the estimated distance squared from the closest point
|
|
359
|
+
* on a bounding box to a point.
|
|
360
|
+
* See Geometric Tools for Computer Graphics 10.4.2
|
|
361
|
+
*/
|
|
362
|
+
distanceSquaredTo(point2) {
|
|
363
|
+
const offset = scratchOffset.from(point2).subtract(this.center);
|
|
364
|
+
const halfAxes = this.halfAxes;
|
|
365
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
366
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
367
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
368
|
+
const uHalf = u.magnitude();
|
|
369
|
+
const vHalf = v.magnitude();
|
|
370
|
+
const wHalf = w.magnitude();
|
|
371
|
+
u.normalize();
|
|
372
|
+
v.normalize();
|
|
373
|
+
w.normalize();
|
|
374
|
+
let distanceSquared = 0;
|
|
375
|
+
let d;
|
|
376
|
+
d = Math.abs(offset.dot(u)) - uHalf;
|
|
377
|
+
if (d > 0) {
|
|
378
|
+
distanceSquared += d * d;
|
|
379
|
+
}
|
|
380
|
+
d = Math.abs(offset.dot(v)) - vHalf;
|
|
381
|
+
if (d > 0) {
|
|
382
|
+
distanceSquared += d * d;
|
|
383
|
+
}
|
|
384
|
+
d = Math.abs(offset.dot(w)) - wHalf;
|
|
385
|
+
if (d > 0) {
|
|
386
|
+
distanceSquared += d * d;
|
|
387
|
+
}
|
|
388
|
+
return distanceSquared;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* The distances calculated by the vector from the center of the bounding box
|
|
392
|
+
* to position projected onto direction.
|
|
393
|
+
*
|
|
394
|
+
* - If you imagine the infinite number of planes with normal direction,
|
|
395
|
+
* this computes the smallest distance to the closest and farthest planes
|
|
396
|
+
* from `position` that intersect the bounding box.
|
|
397
|
+
*
|
|
398
|
+
* @param position The position to calculate the distance from.
|
|
399
|
+
* @param direction The direction from position.
|
|
400
|
+
* @param result An Interval (array of length 2) to store the nearest and farthest distances.
|
|
401
|
+
* @returns Interval (array of length 2) with nearest and farthest distances
|
|
402
|
+
* on the bounding box from position in direction.
|
|
403
|
+
*/
|
|
404
|
+
// eslint-disable-next-line max-statements
|
|
405
|
+
computePlaneDistances(position, direction2, result = [-0, -0]) {
|
|
406
|
+
let minDist = Number.POSITIVE_INFINITY;
|
|
407
|
+
let maxDist = Number.NEGATIVE_INFINITY;
|
|
408
|
+
const center = this.center;
|
|
409
|
+
const halfAxes = this.halfAxes;
|
|
410
|
+
const u = halfAxes.getColumn(0, scratchVectorU);
|
|
411
|
+
const v = halfAxes.getColumn(1, scratchVectorV);
|
|
412
|
+
const w = halfAxes.getColumn(2, scratchVectorW);
|
|
413
|
+
const corner = scratchCorner.copy(u).add(v).add(w).add(center);
|
|
414
|
+
const toCenter = scratchToCenter.copy(corner).subtract(position);
|
|
415
|
+
let mag = direction2.dot(toCenter);
|
|
416
|
+
minDist = Math.min(mag, minDist);
|
|
417
|
+
maxDist = Math.max(mag, maxDist);
|
|
418
|
+
corner.copy(center).add(u).add(v).subtract(w);
|
|
419
|
+
toCenter.copy(corner).subtract(position);
|
|
420
|
+
mag = direction2.dot(toCenter);
|
|
421
|
+
minDist = Math.min(mag, minDist);
|
|
422
|
+
maxDist = Math.max(mag, maxDist);
|
|
423
|
+
corner.copy(center).add(u).subtract(v).add(w);
|
|
424
|
+
toCenter.copy(corner).subtract(position);
|
|
425
|
+
mag = direction2.dot(toCenter);
|
|
426
|
+
minDist = Math.min(mag, minDist);
|
|
427
|
+
maxDist = Math.max(mag, maxDist);
|
|
428
|
+
corner.copy(center).add(u).subtract(v).subtract(w);
|
|
429
|
+
toCenter.copy(corner).subtract(position);
|
|
430
|
+
mag = direction2.dot(toCenter);
|
|
431
|
+
minDist = Math.min(mag, minDist);
|
|
432
|
+
maxDist = Math.max(mag, maxDist);
|
|
433
|
+
center.copy(corner).subtract(u).add(v).add(w);
|
|
434
|
+
toCenter.copy(corner).subtract(position);
|
|
435
|
+
mag = direction2.dot(toCenter);
|
|
436
|
+
minDist = Math.min(mag, minDist);
|
|
437
|
+
maxDist = Math.max(mag, maxDist);
|
|
438
|
+
center.copy(corner).subtract(u).add(v).subtract(w);
|
|
439
|
+
toCenter.copy(corner).subtract(position);
|
|
440
|
+
mag = direction2.dot(toCenter);
|
|
441
|
+
minDist = Math.min(mag, minDist);
|
|
442
|
+
maxDist = Math.max(mag, maxDist);
|
|
443
|
+
center.copy(corner).subtract(u).subtract(v).add(w);
|
|
444
|
+
toCenter.copy(corner).subtract(position);
|
|
445
|
+
mag = direction2.dot(toCenter);
|
|
446
|
+
minDist = Math.min(mag, minDist);
|
|
447
|
+
maxDist = Math.max(mag, maxDist);
|
|
448
|
+
center.copy(corner).subtract(u).subtract(v).subtract(w);
|
|
449
|
+
toCenter.copy(corner).subtract(position);
|
|
450
|
+
mag = direction2.dot(toCenter);
|
|
451
|
+
minDist = Math.min(mag, minDist);
|
|
452
|
+
maxDist = Math.max(mag, maxDist);
|
|
453
|
+
result[0] = minDist;
|
|
454
|
+
result[1] = maxDist;
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Applies a 4x4 affine transformation matrix to a bounding sphere.
|
|
459
|
+
* @param transform The transformation matrix to apply to the bounding sphere.
|
|
460
|
+
* @returns itself, i.e. the modified BoundingVolume.
|
|
461
|
+
*/
|
|
462
|
+
transform(transformation) {
|
|
463
|
+
this.center.transformAsPoint(transformation);
|
|
464
|
+
const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
|
|
465
|
+
xAxis.transformAsPoint(transformation);
|
|
466
|
+
const yAxis = this.halfAxes.getColumn(1, scratchVectorV);
|
|
467
|
+
yAxis.transformAsPoint(transformation);
|
|
468
|
+
const zAxis = this.halfAxes.getColumn(2, scratchVectorW);
|
|
469
|
+
zAxis.transformAsPoint(transformation);
|
|
470
|
+
this.halfAxes = new import_core4.Matrix3([...xAxis, ...yAxis, ...zAxis]);
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
getTransform() {
|
|
474
|
+
throw new Error("not implemented");
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// dist/culling/lib/culling-volume.js
|
|
479
|
+
var import_core7 = require("@math.gl/core");
|
|
480
|
+
|
|
481
|
+
// dist/culling/frustum-planes.js
|
|
482
|
+
var import_core6 = require("@math.gl/core");
|
|
483
|
+
|
|
484
|
+
// dist/culling/lib/plane.js
|
|
485
|
+
var import_core5 = require("@math.gl/core");
|
|
486
|
+
var scratchPosition = new import_core5.Vector3();
|
|
487
|
+
var scratchNormal2 = new import_core5.Vector3();
|
|
488
|
+
var Plane = class _Plane {
|
|
489
|
+
constructor(normal = [0, 0, 1], distance = 0) {
|
|
490
|
+
this.normal = new import_core5.Vector3();
|
|
491
|
+
this.distance = -0;
|
|
492
|
+
this.fromNormalDistance(normal, distance);
|
|
493
|
+
}
|
|
494
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
495
|
+
fromNormalDistance(normal, distance) {
|
|
496
|
+
(0, import_core5.assert)(Number.isFinite(distance));
|
|
497
|
+
this.normal.from(normal).normalize();
|
|
498
|
+
this.distance = distance;
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
502
|
+
fromPointNormal(point2, normal) {
|
|
503
|
+
point2 = scratchPosition.from(point2);
|
|
504
|
+
this.normal.from(normal).normalize();
|
|
505
|
+
const distance = -this.normal.dot(point2);
|
|
506
|
+
this.distance = distance;
|
|
507
|
+
return this;
|
|
508
|
+
}
|
|
509
|
+
/** Creates a plane from the general equation */
|
|
510
|
+
fromCoefficients(a, b, c, d) {
|
|
511
|
+
this.normal.set(a, b, c);
|
|
512
|
+
(0, import_core5.assert)((0, import_core5.equals)(this.normal.len(), 1));
|
|
513
|
+
this.distance = d;
|
|
514
|
+
return this;
|
|
515
|
+
}
|
|
516
|
+
/** Duplicates a Plane instance. */
|
|
517
|
+
clone() {
|
|
518
|
+
return new _Plane(this.normal, this.distance);
|
|
519
|
+
}
|
|
520
|
+
/** Compares the provided Planes by normal and distance */
|
|
521
|
+
equals(right) {
|
|
522
|
+
return (0, import_core5.equals)(this.distance, right.distance) && (0, import_core5.equals)(this.normal, right.normal);
|
|
523
|
+
}
|
|
524
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
525
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
526
|
+
*/
|
|
527
|
+
getPointDistance(point2) {
|
|
528
|
+
return this.normal.dot(point2) + this.distance;
|
|
529
|
+
}
|
|
530
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
531
|
+
transform(matrix4) {
|
|
532
|
+
const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
533
|
+
const point2 = this.normal.scale(-this.distance).transform(matrix4);
|
|
534
|
+
return this.fromPointNormal(point2, normal);
|
|
535
|
+
}
|
|
536
|
+
projectPointOntoPlane(point2, result = [0, 0, 0]) {
|
|
537
|
+
const scratchPoint = scratchPosition.from(point2);
|
|
538
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
539
|
+
const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
|
|
540
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Computes the intersection of a ray and this plane.
|
|
544
|
+
*
|
|
545
|
+
* @param {Ray} ray The ray.
|
|
546
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
547
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersection.
|
|
548
|
+
*/
|
|
549
|
+
intersectWithRay(ray, result = new import_core5.Vector3()) {
|
|
550
|
+
const origin = ray.origin;
|
|
551
|
+
const direction2 = ray.direction;
|
|
552
|
+
const normal = this.normal;
|
|
553
|
+
const denominator = normal.dot(direction2);
|
|
554
|
+
if (Math.abs(denominator) < import_core5._MathUtils.EPSILON15) {
|
|
555
|
+
return void 0;
|
|
556
|
+
}
|
|
557
|
+
const t = (-this.distance - normal.dot(origin)) / denominator;
|
|
558
|
+
if (t < 0) {
|
|
559
|
+
return void 0;
|
|
560
|
+
}
|
|
561
|
+
return result.copy(direction2).multiplyByScalar(t).add(origin);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// dist/culling/frustum-planes.js
|
|
566
|
+
function extractFrustumPlanes(matrix, options = {}) {
|
|
567
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
|
|
568
|
+
throw new RangeError("Expected a finite view-projection matrix");
|
|
569
|
+
const [near, far] = (0, import_core6.getProjectionDepthRange)(options);
|
|
570
|
+
const low = Math.min(near, far), high = Math.max(near, far);
|
|
571
|
+
const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
|
|
572
|
+
const x = row(0), y = row(1), z = row(2), w = row(3);
|
|
573
|
+
const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
|
|
574
|
+
const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
|
|
575
|
+
const coefficients = [
|
|
576
|
+
combine(w, x, 1),
|
|
577
|
+
combine(w, x, -1),
|
|
578
|
+
combine(w, y, 1),
|
|
579
|
+
combine(w, y, -1),
|
|
580
|
+
...options.reversedDepth ? [hi, lo] : [lo, hi]
|
|
581
|
+
];
|
|
582
|
+
const planes = [];
|
|
583
|
+
for (const [a, b, c, d] of coefficients) {
|
|
584
|
+
const length = Math.hypot(a, b, c);
|
|
585
|
+
if (length === 0) {
|
|
586
|
+
if (d < 0)
|
|
587
|
+
throw new RangeError("Empty clipping volume");
|
|
588
|
+
} else
|
|
589
|
+
planes.push(new Plane([a / length, b / length, c / length], d / length));
|
|
590
|
+
}
|
|
591
|
+
if (planes.length < 4)
|
|
592
|
+
throw new RangeError("Degenerate clipping volume");
|
|
593
|
+
return planes;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// dist/culling/lib/culling-volume.js
|
|
597
|
+
var faces = [new import_core7.Vector3([1, 0, 0]), new import_core7.Vector3([0, 1, 0]), new import_core7.Vector3([0, 0, 1])];
|
|
598
|
+
var scratchPlaneCenter = new import_core7.Vector3();
|
|
599
|
+
var scratchPlaneNormal = new import_core7.Vector3();
|
|
600
|
+
var CullingVolume = class _CullingVolume {
|
|
601
|
+
/**
|
|
602
|
+
* Create a new `CullingVolume` bounded by an array of clipping planed
|
|
603
|
+
* @param planes Array of clipping planes.
|
|
604
|
+
* */
|
|
605
|
+
constructor(planes = []) {
|
|
606
|
+
this.planes = planes;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
|
|
610
|
+
* The planes are aligned to the x, y, and z axes in world coordinates.
|
|
611
|
+
*/
|
|
612
|
+
fromBoundingSphere(boundingSphere) {
|
|
613
|
+
this.planes.length = 2 * faces.length;
|
|
614
|
+
const center = boundingSphere.center;
|
|
615
|
+
const radius2 = boundingSphere.radius;
|
|
616
|
+
let planeIndex = 0;
|
|
617
|
+
for (const faceNormal of faces) {
|
|
618
|
+
let plane0 = this.planes[planeIndex];
|
|
619
|
+
let plane1 = this.planes[planeIndex + 1];
|
|
620
|
+
if (!plane0) {
|
|
621
|
+
plane0 = this.planes[planeIndex] = new Plane();
|
|
622
|
+
}
|
|
623
|
+
if (!plane1) {
|
|
624
|
+
plane1 = this.planes[planeIndex + 1] = new Plane();
|
|
625
|
+
}
|
|
626
|
+
const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
|
|
627
|
+
plane0.fromPointNormal(plane0Center, faceNormal);
|
|
628
|
+
const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
|
|
629
|
+
const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
|
|
630
|
+
plane1.fromPointNormal(plane1Center, negatedFaceNormal);
|
|
631
|
+
planeIndex += 2;
|
|
632
|
+
}
|
|
633
|
+
return this;
|
|
634
|
+
}
|
|
635
|
+
/** Replace planes from a view-projection matrix; validates before mutating. */
|
|
636
|
+
fromViewProjection(matrix, options = {}) {
|
|
637
|
+
const planes = extractFrustumPlanes(matrix, options);
|
|
638
|
+
this.planes.splice(0, this.planes.length, ...planes);
|
|
639
|
+
return this;
|
|
640
|
+
}
|
|
641
|
+
/** Determines whether a bounding volume intersects the culling volume. */
|
|
642
|
+
computeVisibility(boundingVolume) {
|
|
643
|
+
let intersect = "inside";
|
|
644
|
+
for (const plane of this.planes) {
|
|
645
|
+
const result = boundingVolume.intersectPlane(plane);
|
|
646
|
+
switch (result) {
|
|
647
|
+
case "outside":
|
|
648
|
+
return "outside";
|
|
649
|
+
case "intersecting":
|
|
650
|
+
intersect = "intersecting";
|
|
651
|
+
break;
|
|
652
|
+
default:
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return intersect;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Determines whether a bounding volume intersects the culling volume.
|
|
659
|
+
*
|
|
660
|
+
* @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
|
|
661
|
+
* volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
|
|
662
|
+
* the parent (and therefore this) volume is completely inside plane[planeIndex]
|
|
663
|
+
* and that plane check can be skipped.
|
|
664
|
+
*/
|
|
665
|
+
computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
|
|
666
|
+
(0, import_core7.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
|
|
667
|
+
if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
|
|
668
|
+
return parentPlaneMask;
|
|
669
|
+
}
|
|
670
|
+
let mask = _CullingVolume.MASK_INSIDE;
|
|
671
|
+
const planes = this.planes;
|
|
672
|
+
for (let k = 0; k < this.planes.length; ++k) {
|
|
673
|
+
const flag = k < 31 ? 1 << k : 0;
|
|
674
|
+
if (k < 31 && (parentPlaneMask & flag) === 0) {
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
const plane = planes[k];
|
|
678
|
+
const result = boundingVolume.intersectPlane(plane);
|
|
679
|
+
if (result === "outside") {
|
|
680
|
+
return _CullingVolume.MASK_OUTSIDE;
|
|
681
|
+
} else if (result === "intersecting") {
|
|
682
|
+
mask |= flag;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return mask;
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
CullingVolume.MASK_OUTSIDE = 4294967295;
|
|
689
|
+
CullingVolume.MASK_INSIDE = 0;
|
|
690
|
+
CullingVolume.MASK_INDETERMINATE = 2147483647;
|
|
691
|
+
|
|
692
|
+
// dist/culling/lib/ray.js
|
|
693
|
+
var import_core8 = require("@math.gl/core");
|
|
694
|
+
|
|
695
|
+
// dist/culling/queries.js
|
|
696
|
+
function validateQueryPoint(point2, dimension2) {
|
|
697
|
+
if (point2.length !== dimension2)
|
|
698
|
+
throw new RangeError("Query dimension must match the index");
|
|
699
|
+
for (let i = 0; i < dimension2; i++) {
|
|
700
|
+
if (!Number.isFinite(point2[i]))
|
|
701
|
+
throw new RangeError("Coordinates must be finite");
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
function validateQueryDistance(distance) {
|
|
705
|
+
if (Number.isNaN(distance) || distance < 0)
|
|
706
|
+
throw new RangeError("Distance must be nonnegative");
|
|
707
|
+
}
|
|
708
|
+
function normalizeQueryDirection(direction2, dimension2) {
|
|
709
|
+
validateQueryPoint(direction2, dimension2);
|
|
710
|
+
const scale = Math.max(...Array.from(direction2, Math.abs));
|
|
711
|
+
if (scale === 0)
|
|
712
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
713
|
+
const scaled = Array.from(direction2, (x) => x / scale);
|
|
714
|
+
const length = Math.hypot(...scaled);
|
|
715
|
+
return scaled.map((x) => x / length);
|
|
716
|
+
}
|
|
717
|
+
function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
|
|
718
|
+
const dimension2 = origin.length;
|
|
719
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
720
|
+
throw new RangeError("Bounds must be 2D or 3D");
|
|
721
|
+
validateQueryPoint(origin, dimension2);
|
|
722
|
+
validateQueryPoint(direction2, dimension2);
|
|
723
|
+
validateQueryPoint(minimum, dimension2);
|
|
724
|
+
validateQueryPoint(maximum, dimension2);
|
|
725
|
+
validateQueryDistance(maxT);
|
|
726
|
+
let near = 0, far = maxT, nonzero = false;
|
|
727
|
+
for (let i = 0; i < dimension2; i++) {
|
|
728
|
+
if (minimum[i] > maximum[i])
|
|
729
|
+
throw new RangeError("Bounds must be ordered");
|
|
730
|
+
nonzero || (nonzero = direction2[i] !== 0);
|
|
731
|
+
}
|
|
732
|
+
if (!nonzero)
|
|
733
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
734
|
+
for (let i = 0; i < dimension2; i++) {
|
|
735
|
+
if (direction2[i] === 0) {
|
|
736
|
+
if (origin[i] < minimum[i] || origin[i] > maximum[i])
|
|
737
|
+
return null;
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
let a = (minimum[i] - origin[i]) / direction2[i];
|
|
741
|
+
let b = (maximum[i] - origin[i]) / direction2[i];
|
|
742
|
+
if (a > b)
|
|
743
|
+
[a, b] = [b, a];
|
|
744
|
+
near = Math.max(near, a);
|
|
745
|
+
far = Math.min(far, b);
|
|
746
|
+
if (near > far)
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
return Number.isFinite(near) ? near : null;
|
|
750
|
+
}
|
|
751
|
+
function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
|
|
752
|
+
for (const point2 of [origin, direction2, a, b, c])
|
|
753
|
+
validateQueryPoint(point2, 3);
|
|
754
|
+
if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
|
|
755
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
756
|
+
}
|
|
757
|
+
const maxT = options.maxT ?? Infinity;
|
|
758
|
+
validateQueryDistance(maxT);
|
|
759
|
+
const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
760
|
+
const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
761
|
+
const p = cross(direction2, e2);
|
|
762
|
+
const determinant = dot(e1, p);
|
|
763
|
+
if (determinant === 0 || options.backfaceCulling && determinant < 0)
|
|
764
|
+
return null;
|
|
765
|
+
const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
|
|
766
|
+
const u = dot(offset, p) / determinant;
|
|
767
|
+
if (u < 0 || u > 1)
|
|
768
|
+
return null;
|
|
769
|
+
const q = cross(offset, e1);
|
|
770
|
+
const v = dot(direction2, q) / determinant;
|
|
771
|
+
if (v < 0 || u + v > 1)
|
|
772
|
+
return null;
|
|
773
|
+
const t = dot(e2, q) / determinant;
|
|
774
|
+
if (!Number.isFinite(t) || t < 0 || t > maxT)
|
|
775
|
+
return null;
|
|
776
|
+
return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
|
|
777
|
+
}
|
|
778
|
+
function getClosestPointOnTriangle(point2, a, b, c) {
|
|
779
|
+
for (const value of [point2, a, b, c])
|
|
780
|
+
validateQueryPoint(value, 3);
|
|
781
|
+
const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
|
|
782
|
+
const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
783
|
+
const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
|
|
784
|
+
const aa = dot(ab, ab), bb = dot(ac, ac), cc = dot(ab, ac);
|
|
785
|
+
const denominator = aa * bb - cc * cc;
|
|
786
|
+
if (denominator > 0 && Number.isFinite(denominator)) {
|
|
787
|
+
const u = (bb * dot(ap, ab) - cc * dot(ap, ac)) / denominator;
|
|
788
|
+
const v = (aa * dot(ap, ac) - cc * dot(ap, ab)) / denominator;
|
|
789
|
+
if (u >= 0 && v >= 0 && u + v <= 1) {
|
|
790
|
+
return [
|
|
791
|
+
a[0] + u * ab[0] + v * ac[0],
|
|
792
|
+
a[1] + u * ab[1] + v * ac[1],
|
|
793
|
+
a[2] + u * ab[2] + v * ac[2]
|
|
794
|
+
];
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
let best = [a[0], a[1], a[2]];
|
|
798
|
+
let distance = Infinity;
|
|
799
|
+
for (const [start, end] of [
|
|
800
|
+
[a, b],
|
|
801
|
+
[b, c],
|
|
802
|
+
[c, a]
|
|
803
|
+
]) {
|
|
804
|
+
const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
|
|
805
|
+
const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
|
|
806
|
+
const squared = dot(edge, edge);
|
|
807
|
+
const t = squared > 0 ? Math.max(0, Math.min(1, dot(offset, edge) / squared)) : 0;
|
|
808
|
+
const candidate = [
|
|
809
|
+
start[0] + t * edge[0],
|
|
810
|
+
start[1] + t * edge[1],
|
|
811
|
+
start[2] + t * edge[2]
|
|
812
|
+
];
|
|
813
|
+
const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
|
|
814
|
+
if (d < distance) {
|
|
815
|
+
distance = d;
|
|
816
|
+
best = candidate;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return best;
|
|
820
|
+
}
|
|
821
|
+
function getClosestPointsOnSegments(a0, a1, b0, b1) {
|
|
822
|
+
const frame = queryFrame([a0, a1, b0, b1]);
|
|
823
|
+
const pair2 = closestSegments(...frame.points);
|
|
824
|
+
const pointA = interpolatePoint(a0, a1, pair2.fractionA);
|
|
825
|
+
const pointB = interpolatePoint(b0, b1, pair2.fractionB);
|
|
826
|
+
return {
|
|
827
|
+
distance: finiteDistance(pointA, pointB),
|
|
828
|
+
pointA,
|
|
829
|
+
pointB,
|
|
830
|
+
fractionA: pair2.fractionA,
|
|
831
|
+
fractionB: pair2.fractionB
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function getClosestPointsSegmentTriangle(start, end, a, b, c) {
|
|
835
|
+
const frame = queryFrame([start, end, a, b, c]);
|
|
836
|
+
const [s, e, va, vb, vc] = frame.points;
|
|
837
|
+
const direction2 = subtract(e, s);
|
|
838
|
+
if (direction2.some((value) => value !== 0)) {
|
|
839
|
+
const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
|
|
840
|
+
if (hit) {
|
|
841
|
+
const point2 = interpolatePoint(start, end, hit.t);
|
|
842
|
+
return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
|
|
846
|
+
const consider = (point2, trianglePoint2, segmentFraction) => {
|
|
847
|
+
const distance = Math.hypot(...subtract(point2, trianglePoint2));
|
|
848
|
+
if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
|
|
849
|
+
best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
|
|
850
|
+
};
|
|
851
|
+
consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
|
|
852
|
+
consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
|
|
853
|
+
for (const [v0, v1] of [
|
|
854
|
+
[va, vb],
|
|
855
|
+
[vb, vc],
|
|
856
|
+
[vc, va]
|
|
857
|
+
]) {
|
|
858
|
+
const pair2 = closestSegments(s, e, v0, v1);
|
|
859
|
+
consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
|
|
860
|
+
}
|
|
861
|
+
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)));
|
|
862
|
+
if (!trianglePoint.every(Number.isFinite))
|
|
863
|
+
throw new RangeError("Closest-point result overflow");
|
|
864
|
+
const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
|
|
865
|
+
return {
|
|
866
|
+
distance: finiteDistance(segmentPoint, trianglePoint),
|
|
867
|
+
segmentPoint,
|
|
868
|
+
trianglePoint,
|
|
869
|
+
segmentFraction: best.segmentFraction
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function queryFrame(input) {
|
|
873
|
+
input.forEach((point2) => validateQueryPoint(point2, 3));
|
|
874
|
+
const offsets = input.map((point2) => subtract(point2, input[0]));
|
|
875
|
+
let scale = 0;
|
|
876
|
+
for (const offset of offsets)
|
|
877
|
+
for (const value of offset) {
|
|
878
|
+
if (!Number.isFinite(value))
|
|
879
|
+
throw new RangeError("Closest-point coordinate span overflow");
|
|
880
|
+
scale = Math.max(scale, Math.abs(value));
|
|
881
|
+
}
|
|
882
|
+
scale || (scale = 1);
|
|
883
|
+
return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
|
|
884
|
+
}
|
|
885
|
+
function closestSegments(a0, a1, b0, b1) {
|
|
886
|
+
const da = subtract(a1, a0), db = subtract(b1, b0);
|
|
887
|
+
const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
|
|
888
|
+
const ua = da.map((value) => lengthA ? value / lengthA : 0);
|
|
889
|
+
const ub = db.map((value) => lengthB ? value / lengthB : 0);
|
|
890
|
+
let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
|
|
891
|
+
const consider = (fractionA, fractionB) => {
|
|
892
|
+
const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
|
|
893
|
+
if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
|
|
894
|
+
best = { distance, fractionA, fractionB };
|
|
895
|
+
};
|
|
896
|
+
for (const t of [0, 1]) {
|
|
897
|
+
consider(t, lengthB ? clampUnit(dot(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
|
|
898
|
+
consider(lengthA ? clampUnit(dot(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
|
|
899
|
+
}
|
|
900
|
+
const normal = cross(ua, ub);
|
|
901
|
+
const sine = Math.hypot(...normal);
|
|
902
|
+
if (sine > 0) {
|
|
903
|
+
const unit = normal.map((value) => value / sine);
|
|
904
|
+
const offset = subtract(b0, a0);
|
|
905
|
+
const fractionA = dot(cross(offset, ub), unit) / sine / lengthA;
|
|
906
|
+
const fractionB = dot(cross(offset, ua), unit) / sine / lengthB;
|
|
907
|
+
if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
|
|
908
|
+
consider(fractionA, fractionB);
|
|
909
|
+
}
|
|
910
|
+
return best;
|
|
911
|
+
}
|
|
912
|
+
function subtract(a, b) {
|
|
913
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
914
|
+
}
|
|
915
|
+
function interpolatePoint(a, b, t) {
|
|
916
|
+
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])));
|
|
917
|
+
}
|
|
918
|
+
function clampUnit(value) {
|
|
919
|
+
return Math.max(0, Math.min(1, value));
|
|
920
|
+
}
|
|
921
|
+
function finiteDistance(a, b) {
|
|
922
|
+
const distance = Math.hypot(...subtract(a, b));
|
|
923
|
+
if (!Number.isFinite(distance))
|
|
924
|
+
throw new RangeError("Closest-point distance overflow");
|
|
925
|
+
return distance;
|
|
926
|
+
}
|
|
927
|
+
function dot(a, b) {
|
|
928
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
929
|
+
}
|
|
930
|
+
function cross(a, b) {
|
|
931
|
+
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]];
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// dist/culling/geometric-queries.js
|
|
935
|
+
var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
936
|
+
var dot2 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
937
|
+
var cross2 = (a, b) => [
|
|
938
|
+
a[1] * b[2] - a[2] * b[1],
|
|
939
|
+
a[2] * b[0] - a[0] * b[2],
|
|
940
|
+
a[0] * b[1] - a[1] * b[0]
|
|
941
|
+
];
|
|
942
|
+
var check = (...points) => {
|
|
943
|
+
for (const p of points)
|
|
944
|
+
validateQueryPoint(p, 3);
|
|
945
|
+
};
|
|
946
|
+
function output(out, values) {
|
|
947
|
+
if (out.length < values.length)
|
|
948
|
+
throw new RangeError("Result buffer is too short");
|
|
949
|
+
const copy = Array.from(values);
|
|
950
|
+
for (let i = 0; i < copy.length; i++)
|
|
951
|
+
out[i] = copy[i];
|
|
952
|
+
return out;
|
|
953
|
+
}
|
|
954
|
+
function direction(d) {
|
|
955
|
+
check(d);
|
|
956
|
+
if (Math.hypot(d[0], d[1], d[2]) === 0)
|
|
957
|
+
throw new RangeError("Ray direction must be nonzero");
|
|
958
|
+
}
|
|
959
|
+
function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
|
|
960
|
+
check(origin);
|
|
961
|
+
direction(dir);
|
|
962
|
+
if (!Number.isFinite(t) || t < 0)
|
|
963
|
+
throw new RangeError("Ray parameter must be finite and nonnegative");
|
|
964
|
+
return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
|
|
965
|
+
}
|
|
966
|
+
function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
|
|
967
|
+
check(point2, origin);
|
|
968
|
+
direction(dir);
|
|
969
|
+
const unit = normalizeQueryDirection(dir, 3);
|
|
970
|
+
const distance = Math.max(0, dot2(sub(point2, origin), unit));
|
|
971
|
+
return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit[i]));
|
|
972
|
+
}
|
|
973
|
+
function distanceToRay(point2, origin, dir) {
|
|
974
|
+
const p = getClosestPointOnRay(point2, origin, dir);
|
|
975
|
+
return Math.hypot(...sub(point2, p));
|
|
976
|
+
}
|
|
977
|
+
function getClosestPointsRaySegment(origin, dir, a, b) {
|
|
978
|
+
check(origin, a, b);
|
|
979
|
+
direction(dir);
|
|
980
|
+
const unit = normalizeQueryDirection(dir, 3);
|
|
981
|
+
const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
|
|
982
|
+
const edge = sub(b, a), offset = sub(origin, a);
|
|
983
|
+
const segmentLength = Math.hypot(...edge);
|
|
984
|
+
const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
|
|
985
|
+
const bb = dot2(unit, segmentUnit), dd = dot2(unit, offset), ee = dot2(segmentUnit, offset);
|
|
986
|
+
const candidates = [
|
|
987
|
+
[0, Math.max(0, Math.min(segmentLength, ee))],
|
|
988
|
+
[Math.max(0, -dd), 0],
|
|
989
|
+
[Math.max(0, bb * segmentLength - dd), segmentLength]
|
|
990
|
+
];
|
|
991
|
+
const normal = cross2(unit, segmentUnit);
|
|
992
|
+
const sine = Math.hypot(...normal);
|
|
993
|
+
if (segmentLength > 0 && sine > 0) {
|
|
994
|
+
const normalUnit = normal.map((value) => value / sine);
|
|
995
|
+
const separation = sub(a, origin);
|
|
996
|
+
const t = dot2(cross2(separation, segmentUnit), normalUnit) / sine;
|
|
997
|
+
const u = dot2(cross2(separation, unit), normalUnit) / sine;
|
|
998
|
+
if (t >= 0 && u >= 0 && u <= segmentLength)
|
|
999
|
+
candidates.push([t, u]);
|
|
1000
|
+
}
|
|
1001
|
+
let best;
|
|
1002
|
+
for (const [t, u] of candidates) {
|
|
1003
|
+
const rayPoint = [
|
|
1004
|
+
origin[0] + t * unit[0],
|
|
1005
|
+
origin[1] + t * unit[1],
|
|
1006
|
+
origin[2] + t * unit[2]
|
|
1007
|
+
];
|
|
1008
|
+
const segmentPoint = [
|
|
1009
|
+
a[0] + u * segmentUnit[0],
|
|
1010
|
+
a[1] + u * segmentUnit[1],
|
|
1011
|
+
a[2] + u * segmentUnit[2]
|
|
1012
|
+
];
|
|
1013
|
+
const distance = Math.hypot(...sub(rayPoint, segmentPoint));
|
|
1014
|
+
if (!best || distance < best.distance)
|
|
1015
|
+
best = {
|
|
1016
|
+
rayPoint,
|
|
1017
|
+
segmentPoint,
|
|
1018
|
+
rayParameter: t / directionLength,
|
|
1019
|
+
segmentFraction: segmentLength ? u / segmentLength : 0,
|
|
1020
|
+
distance
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
return best;
|
|
1024
|
+
}
|
|
1025
|
+
function transformRay(origin, dir, matrix) {
|
|
1026
|
+
check(origin);
|
|
1027
|
+
direction(dir);
|
|
1028
|
+
if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
|
|
1029
|
+
throw new RangeError("Expected a finite affine matrix");
|
|
1030
|
+
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]);
|
|
1031
|
+
const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
|
|
1032
|
+
check(transformed.origin);
|
|
1033
|
+
direction(transformed.direction);
|
|
1034
|
+
return transformed;
|
|
1035
|
+
}
|
|
1036
|
+
function triangle(a, b, c) {
|
|
1037
|
+
check(a, b, c);
|
|
1038
|
+
const ab = sub(b, a), ac = sub(c, a);
|
|
1039
|
+
const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
|
|
1040
|
+
const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
|
|
1041
|
+
return { u, v, scale, normal: cross2(u, v) };
|
|
1042
|
+
}
|
|
1043
|
+
function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
|
|
1044
|
+
check(point2);
|
|
1045
|
+
const { u, v, scale, normal } = triangle(a, b, c), denominator = dot2(normal, normal);
|
|
1046
|
+
if (denominator === 0)
|
|
1047
|
+
return null;
|
|
1048
|
+
const p = sub(point2, a).map((x) => x / scale);
|
|
1049
|
+
const second = dot2(cross2(p, v), normal) / denominator;
|
|
1050
|
+
const third = dot2(cross2(u, p), normal) / denominator;
|
|
1051
|
+
return output(out, [1 - second - third, second, third]);
|
|
1052
|
+
}
|
|
1053
|
+
function getTriangleArea(a, b, c) {
|
|
1054
|
+
const { normal, scale } = triangle(a, b, c);
|
|
1055
|
+
return Math.hypot(...normal) * scale * scale / 2;
|
|
1056
|
+
}
|
|
1057
|
+
function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
|
|
1058
|
+
const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
|
|
1059
|
+
return output(out, normal.map((x) => length ? x / length : 0));
|
|
1060
|
+
}
|
|
1061
|
+
function isTriangleFrontFacing(a, b, c, dir) {
|
|
1062
|
+
direction(dir);
|
|
1063
|
+
return dot2(triangle(a, b, c).normal, dir) < 0;
|
|
1064
|
+
}
|
|
1065
|
+
function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
|
|
1066
|
+
if (!Number.isFinite(tolerance) || tolerance < 0)
|
|
1067
|
+
throw new RangeError("Invalid tolerance");
|
|
1068
|
+
const weights = getTriangleBarycentric(point2, a, b, c);
|
|
1069
|
+
if (!weights)
|
|
1070
|
+
return false;
|
|
1071
|
+
const { normal, scale } = triangle(a, b, c);
|
|
1072
|
+
const distance = Math.abs(dot2(sub(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
|
|
1073
|
+
return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
|
|
1074
|
+
}
|
|
1075
|
+
function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
|
|
1076
|
+
check(weights);
|
|
1077
|
+
if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
|
|
1078
|
+
throw new RangeError("Expected matching finite attributes");
|
|
1079
|
+
return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
|
|
1080
|
+
}
|
|
1081
|
+
function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
|
|
1082
|
+
check(start, end);
|
|
1083
|
+
direction(normal);
|
|
1084
|
+
if (!Number.isFinite(constant))
|
|
1085
|
+
throw new RangeError("Plane constant must be finite");
|
|
1086
|
+
const a = dot2(normal, start) + constant, b = dot2(normal, end) + constant;
|
|
1087
|
+
if (a === 0)
|
|
1088
|
+
return output(out, start);
|
|
1089
|
+
if (b === 0)
|
|
1090
|
+
return output(out, end);
|
|
1091
|
+
if (a > 0 === b > 0)
|
|
1092
|
+
return null;
|
|
1093
|
+
const t = a / (a - b);
|
|
1094
|
+
return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
|
|
1095
|
+
}
|
|
1096
|
+
function triangleIntersectsBounds(a, b, c, minimum, maximum) {
|
|
1097
|
+
check(a, b, c, minimum, maximum);
|
|
1098
|
+
if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
|
|
1099
|
+
return false;
|
|
1100
|
+
const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
|
|
1101
|
+
const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
|
|
1102
|
+
const vertices = [a, b, c].map((p) => sub(p, center));
|
|
1103
|
+
const edges = [sub(b, a), sub(c, b), sub(a, c)];
|
|
1104
|
+
const basis = [
|
|
1105
|
+
[1, 0, 0],
|
|
1106
|
+
[0, 1, 0],
|
|
1107
|
+
[0, 0, 1]
|
|
1108
|
+
];
|
|
1109
|
+
const axes = [
|
|
1110
|
+
...basis,
|
|
1111
|
+
cross2(edges[0], edges[1]),
|
|
1112
|
+
...edges.flatMap((e) => basis.map((axis) => cross2(e, axis)))
|
|
1113
|
+
];
|
|
1114
|
+
for (const axis of axes) {
|
|
1115
|
+
const length = Math.hypot(...axis);
|
|
1116
|
+
if (!length)
|
|
1117
|
+
continue;
|
|
1118
|
+
const unit = axis.map((x) => x / length);
|
|
1119
|
+
const projections = vertices.map((v) => dot2(v, unit));
|
|
1120
|
+
const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit[i]), 0);
|
|
1121
|
+
if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// dist/culling/lib/ray.js
|
|
1128
|
+
var Ray = class {
|
|
1129
|
+
/**
|
|
1130
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
1131
|
+
*
|
|
1132
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
1133
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
1134
|
+
*/
|
|
1135
|
+
constructor(origin, direction2) {
|
|
1136
|
+
if (origin)
|
|
1137
|
+
origin = origin.clone();
|
|
1138
|
+
else
|
|
1139
|
+
origin = new import_core8.Vector3();
|
|
1140
|
+
if (direction2)
|
|
1141
|
+
direction2 = direction2.clone().normalize();
|
|
1142
|
+
else
|
|
1143
|
+
direction2 = new import_core8.Vector3();
|
|
1144
|
+
this.origin = origin;
|
|
1145
|
+
this.direction = direction2;
|
|
1146
|
+
}
|
|
1147
|
+
at(t, result = new import_core8.Vector3()) {
|
|
1148
|
+
getRayPoint(this.origin, this.direction, t, result);
|
|
1149
|
+
return result;
|
|
1150
|
+
}
|
|
1151
|
+
closestPointTo(point2, result = new import_core8.Vector3()) {
|
|
1152
|
+
getClosestPointOnRay(point2, this.origin, this.direction, result);
|
|
1153
|
+
return result;
|
|
1154
|
+
}
|
|
1155
|
+
distanceTo(point2) {
|
|
1156
|
+
return distanceToRay(point2, this.origin, this.direction);
|
|
1157
|
+
}
|
|
1158
|
+
/** Transform and renormalize: subsequent parameters are distances in the new space. */
|
|
1159
|
+
transform(matrix) {
|
|
1160
|
+
const ray = transformRay(this.origin, this.direction, matrix);
|
|
1161
|
+
const normalized = normalizeQueryDirection(ray.direction, 3);
|
|
1162
|
+
this.origin.copy(ray.origin);
|
|
1163
|
+
this.direction.copy(normalized);
|
|
1164
|
+
return this;
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1168
|
+
// dist/culling/lib/shapes/implicit-shape.js
|
|
1169
|
+
var import_core9 = require("@math.gl/core");
|
|
1170
|
+
var ImplicitShapeBase = class {
|
|
1171
|
+
constructor(matrix) {
|
|
1172
|
+
this.matrix = new import_core9.Matrix4();
|
|
1173
|
+
if (matrix)
|
|
1174
|
+
this.matrix.copy(matrix);
|
|
1175
|
+
validateAffineMatrix(this.matrix);
|
|
1176
|
+
this.inverseMatrix = this.matrix.clone().invert();
|
|
1177
|
+
}
|
|
1178
|
+
equals(shape) {
|
|
1179
|
+
if (this.type !== shape.type)
|
|
1180
|
+
return false;
|
|
1181
|
+
for (let i = 0; i < 16; i++)
|
|
1182
|
+
if (this.matrix[i] !== shape.matrix[i])
|
|
1183
|
+
return false;
|
|
1184
|
+
return true;
|
|
1185
|
+
}
|
|
1186
|
+
transform(transform) {
|
|
1187
|
+
const next = new import_core9.Matrix4().copy(transform);
|
|
1188
|
+
validateAffineMatrix(next);
|
|
1189
|
+
this.matrix.multiplyLeft(next);
|
|
1190
|
+
validateAffineMatrix(this.matrix);
|
|
1191
|
+
this.inverseMatrix.copy(this.matrix).invert();
|
|
1192
|
+
return this;
|
|
1193
|
+
}
|
|
1194
|
+
containsPoint(point2) {
|
|
1195
|
+
return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
|
|
1196
|
+
}
|
|
1197
|
+
distanceSquaredTo(point2) {
|
|
1198
|
+
const distance = this.distanceTo(point2);
|
|
1199
|
+
return distance * distance;
|
|
1200
|
+
}
|
|
1201
|
+
/** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
|
|
1202
|
+
distanceTo(point2) {
|
|
1203
|
+
const localPoint = this.inverseMatrix.transformAsPoint(point2);
|
|
1204
|
+
const localDistance = this.distanceToLocalPoint(localPoint);
|
|
1205
|
+
const scales = this.matrix.getScale();
|
|
1206
|
+
return localDistance * Math.min(scales[0], scales[1], scales[2]);
|
|
1207
|
+
}
|
|
1208
|
+
intersectPlane(plane) {
|
|
1209
|
+
const maximum = this.getSupportPoint(plane.normal);
|
|
1210
|
+
const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
|
|
1211
|
+
const maxDistance = plane.getPointDistance(maximum);
|
|
1212
|
+
const minDistance = plane.getPointDistance(minimum);
|
|
1213
|
+
if (minDistance > 0)
|
|
1214
|
+
return "inside";
|
|
1215
|
+
if (maxDistance < 0)
|
|
1216
|
+
return "outside";
|
|
1217
|
+
return "intersecting";
|
|
1218
|
+
}
|
|
1219
|
+
intersectRay(ray) {
|
|
1220
|
+
const localOrigin = this.inverseMatrix.transformAsPoint(ray.origin);
|
|
1221
|
+
const localDirection = this.inverseMatrix.transformAsVector(ray.direction);
|
|
1222
|
+
const hit = this.intersectLocalRay(localOrigin, localDirection);
|
|
1223
|
+
if (!hit || hit.distance < 0)
|
|
1224
|
+
return void 0;
|
|
1225
|
+
const point2 = new import_core9.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
|
|
1226
|
+
const inverse = this.inverseMatrix;
|
|
1227
|
+
const normal = new import_core9.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();
|
|
1228
|
+
return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
|
|
1229
|
+
}
|
|
1230
|
+
getAxisAlignedBoundingBox() {
|
|
1231
|
+
const minimum = new import_core9.Vector3();
|
|
1232
|
+
const maximum = new import_core9.Vector3();
|
|
1233
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
1234
|
+
const direction2 = [0, 0, 0];
|
|
1235
|
+
direction2[axis] = 1;
|
|
1236
|
+
maximum[axis] = this.getSupportPoint(direction2)[axis];
|
|
1237
|
+
direction2[axis] = -1;
|
|
1238
|
+
minimum[axis] = this.getSupportPoint(direction2)[axis];
|
|
1239
|
+
}
|
|
1240
|
+
return new AxisAlignedBoundingBox(minimum, maximum);
|
|
1241
|
+
}
|
|
1242
|
+
getBoundingSphere() {
|
|
1243
|
+
const box = this.getAxisAlignedBoundingBox();
|
|
1244
|
+
if (!box)
|
|
1245
|
+
return void 0;
|
|
1246
|
+
return new BoundingSphere().fromCornerPoints(box.minimum, box.maximum);
|
|
1247
|
+
}
|
|
1248
|
+
getSupportPoint(worldDirection) {
|
|
1249
|
+
const matrix = this.matrix;
|
|
1250
|
+
const localDirection = [
|
|
1251
|
+
matrix[0] * worldDirection[0] + matrix[1] * worldDirection[1] + matrix[2] * worldDirection[2],
|
|
1252
|
+
matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
|
|
1253
|
+
matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
|
|
1254
|
+
];
|
|
1255
|
+
return new import_core9.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
function validateAffineMatrix(matrix) {
|
|
1259
|
+
if (matrix.length !== 16 || matrix.some((value) => !Number.isFinite(value))) {
|
|
1260
|
+
throw new Error("Shape matrix must contain 16 finite values");
|
|
1261
|
+
}
|
|
1262
|
+
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) {
|
|
1263
|
+
throw new Error("Shape matrix must be affine");
|
|
1264
|
+
}
|
|
1265
|
+
if (Math.abs(new import_core9.Matrix4().copy(matrix).determinant()) < 1e-15)
|
|
1266
|
+
throw new Error("Shape matrix must be invertible");
|
|
1267
|
+
}
|
|
1268
|
+
function solveQuadratic(a, b, c) {
|
|
1269
|
+
if (Math.abs(a) < 1e-15)
|
|
1270
|
+
return Math.abs(b) < 1e-15 ? [] : [-c / b];
|
|
1271
|
+
const discriminant = b * b - 4 * a * c;
|
|
1272
|
+
if (discriminant < 0)
|
|
1273
|
+
return [];
|
|
1274
|
+
const root = Math.sqrt(Math.max(0, discriminant));
|
|
1275
|
+
return [(-b - root) / (2 * a), (-b + root) / (2 * a)].sort((left, right) => left - right);
|
|
1276
|
+
}
|
|
1277
|
+
function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
|
|
1278
|
+
const dx = bx - ax;
|
|
1279
|
+
const dy = by - ay;
|
|
1280
|
+
const denominator = dx * dx + dy * dy;
|
|
1281
|
+
const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
|
|
1282
|
+
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
|
|
1283
|
+
}
|
|
1284
|
+
function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
|
|
1285
|
+
if (radius2 === 0)
|
|
1286
|
+
return Math.hypot(px, py - centerY);
|
|
1287
|
+
const dx = px;
|
|
1288
|
+
const dy = py - centerY;
|
|
1289
|
+
const length = Math.hypot(dx, dy);
|
|
1290
|
+
const normalY = length ? dy / length : 0;
|
|
1291
|
+
if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
|
|
1292
|
+
return Math.abs(length - radius2);
|
|
1293
|
+
}
|
|
1294
|
+
const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
|
|
1295
|
+
const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
|
|
1296
|
+
return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// dist/culling/lib/shapes/box-shape.js
|
|
1300
|
+
var EPSILON = 1e-6;
|
|
1301
|
+
var BoxShape = class _BoxShape extends ImplicitShapeBase {
|
|
1302
|
+
constructor(props = {}) {
|
|
1303
|
+
super(props.matrix);
|
|
1304
|
+
this.type = "box";
|
|
1305
|
+
this.size = props.size ? [...props.size] : [1, 1, 1];
|
|
1306
|
+
if (this.size.some((value) => !Number.isFinite(value) || value <= 0))
|
|
1307
|
+
throw new Error("Box size values must be greater than zero");
|
|
1308
|
+
this.halfSize = [this.size[0] / 2, this.size[1] / 2, this.size[2] / 2];
|
|
1309
|
+
}
|
|
1310
|
+
clone() {
|
|
1311
|
+
return new _BoxShape({ size: this.size, matrix: this.matrix });
|
|
1312
|
+
}
|
|
1313
|
+
equals(shape) {
|
|
1314
|
+
return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
|
|
1315
|
+
}
|
|
1316
|
+
containsLocalPoint(point2) {
|
|
1317
|
+
return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
|
|
1318
|
+
}
|
|
1319
|
+
distanceToLocalPoint(point2) {
|
|
1320
|
+
return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
|
|
1321
|
+
}
|
|
1322
|
+
supportLocal(direction2) {
|
|
1323
|
+
return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
|
|
1324
|
+
}
|
|
1325
|
+
intersectLocalRay(origin, direction2) {
|
|
1326
|
+
let near = -Infinity;
|
|
1327
|
+
let far = Infinity;
|
|
1328
|
+
let nearAxis = 0;
|
|
1329
|
+
let farAxis = 0;
|
|
1330
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
1331
|
+
if (Math.abs(direction2[axis2]) < 1e-15) {
|
|
1332
|
+
if (Math.abs(origin[axis2]) > this.halfSize[axis2])
|
|
1333
|
+
return void 0;
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
1337
|
+
let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
|
|
1338
|
+
if (t1 > t2)
|
|
1339
|
+
[t1, t2] = [t2, t1];
|
|
1340
|
+
if (t1 > near) {
|
|
1341
|
+
near = t1;
|
|
1342
|
+
nearAxis = axis2;
|
|
1343
|
+
}
|
|
1344
|
+
if (t2 < far) {
|
|
1345
|
+
far = t2;
|
|
1346
|
+
farAxis = axis2;
|
|
1347
|
+
}
|
|
1348
|
+
if (near > far)
|
|
1349
|
+
return void 0;
|
|
1350
|
+
}
|
|
1351
|
+
const distance = near >= 0 ? near : far;
|
|
1352
|
+
if (distance < 0 || !Number.isFinite(distance))
|
|
1353
|
+
return void 0;
|
|
1354
|
+
const axis = near >= 0 ? nearAxis : farAxis;
|
|
1355
|
+
const pointCoordinate = origin[axis] + distance * direction2[axis];
|
|
1356
|
+
const normal = [0, 0, 0];
|
|
1357
|
+
normal[axis] = pointCoordinate < 0 ? -1 : 1;
|
|
1358
|
+
return { distance, normal };
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// dist/culling/lib/shapes/capsule-shape.js
|
|
1363
|
+
var EPSILON2 = 1e-6;
|
|
1364
|
+
var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
|
|
1365
|
+
constructor(props = {}) {
|
|
1366
|
+
super(props.matrix);
|
|
1367
|
+
this.type = "capsule";
|
|
1368
|
+
this.height = props.height ?? 1;
|
|
1369
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
1370
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
1371
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
1372
|
+
throw new Error("Capsule height must be greater than zero");
|
|
1373
|
+
if (![this.radiusBottom, this.radiusTop].every((value) => Number.isFinite(value) && value >= 0))
|
|
1374
|
+
throw new Error("Capsule radii must be non-negative");
|
|
1375
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
1376
|
+
throw new Error("At least one capsule radius must be greater than zero");
|
|
1377
|
+
}
|
|
1378
|
+
clone() {
|
|
1379
|
+
return new _CapsuleShape({
|
|
1380
|
+
height: this.height,
|
|
1381
|
+
radiusBottom: this.radiusBottom,
|
|
1382
|
+
radiusTop: this.radiusTop,
|
|
1383
|
+
matrix: this.matrix
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
equals(shape) {
|
|
1387
|
+
return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
1388
|
+
}
|
|
1389
|
+
containsLocalPoint(point2) {
|
|
1390
|
+
const profile = this.getProfile();
|
|
1391
|
+
const radial = Math.hypot(point2[0], point2[2]);
|
|
1392
|
+
if (profile.sphere)
|
|
1393
|
+
return Math.hypot(radial, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
|
|
1394
|
+
if (point2[1] < profile.bottom.y)
|
|
1395
|
+
return Math.hypot(radial, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
|
|
1396
|
+
if (point2[1] > profile.top.y)
|
|
1397
|
+
return Math.hypot(radial, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
|
|
1398
|
+
const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
1399
|
+
return radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
|
|
1400
|
+
}
|
|
1401
|
+
distanceToLocalPoint(point2) {
|
|
1402
|
+
if (this.containsLocalPoint(point2))
|
|
1403
|
+
return 0;
|
|
1404
|
+
const profile = this.getProfile();
|
|
1405
|
+
const radial = Math.hypot(point2[0], point2[2]);
|
|
1406
|
+
if (profile.sphere)
|
|
1407
|
+
return Math.max(0, Math.hypot(radial, point2[1] - profile.sphere.center) - profile.sphere.radius);
|
|
1408
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
1409
|
+
const sideNormalY = -delta / this.height;
|
|
1410
|
+
const bottomArc = closestDistanceToCircleArc2D(radial, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
|
|
1411
|
+
const topArc = closestDistanceToCircleArc2D(radial, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
|
|
1412
|
+
const side = closestDistanceToSegment2D(radial, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
|
|
1413
|
+
return Math.min(bottomArc, topArc, side);
|
|
1414
|
+
}
|
|
1415
|
+
supportLocal(direction2) {
|
|
1416
|
+
const length = Math.hypot(...direction2);
|
|
1417
|
+
const unit = length ? direction2.map((value) => value / length) : [1, 0, 0];
|
|
1418
|
+
const bottom = [
|
|
1419
|
+
unit[0] * this.radiusBottom,
|
|
1420
|
+
-this.height / 2 + unit[1] * this.radiusBottom,
|
|
1421
|
+
unit[2] * this.radiusBottom
|
|
1422
|
+
];
|
|
1423
|
+
const top = [
|
|
1424
|
+
unit[0] * this.radiusTop,
|
|
1425
|
+
this.height / 2 + unit[1] * this.radiusTop,
|
|
1426
|
+
unit[2] * this.radiusTop
|
|
1427
|
+
];
|
|
1428
|
+
return dot3(top, direction2) >= dot3(bottom, direction2) ? top : bottom;
|
|
1429
|
+
}
|
|
1430
|
+
intersectLocalRay(origin, direction2) {
|
|
1431
|
+
const profile = this.getProfile();
|
|
1432
|
+
if (profile.sphere)
|
|
1433
|
+
return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
|
|
1434
|
+
const candidates = [];
|
|
1435
|
+
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
1436
|
+
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
1437
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
1438
|
+
const radialAlongRay = slope * direction2[1];
|
|
1439
|
+
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)) {
|
|
1440
|
+
const y = origin[1] + distance * direction2[1];
|
|
1441
|
+
if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
|
|
1442
|
+
const x = origin[0] + distance * direction2[0];
|
|
1443
|
+
const z = origin[2] + distance * direction2[2];
|
|
1444
|
+
const radial = Math.hypot(x, z) || 1;
|
|
1445
|
+
const normal = [x / radial, -slope, z / radial];
|
|
1446
|
+
const length = Math.hypot(...normal);
|
|
1447
|
+
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
|
|
1451
|
+
const y = origin[1] + bottomHit.distance * direction2[1];
|
|
1452
|
+
if (y <= profile.bottom.y + EPSILON2)
|
|
1453
|
+
candidates.push(bottomHit);
|
|
1454
|
+
}
|
|
1455
|
+
for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
|
|
1456
|
+
const y = origin[1] + topHit.distance * direction2[1];
|
|
1457
|
+
if (y >= profile.top.y - EPSILON2)
|
|
1458
|
+
candidates.push(topHit);
|
|
1459
|
+
}
|
|
1460
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
1461
|
+
}
|
|
1462
|
+
getProfile() {
|
|
1463
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
1464
|
+
if (Math.abs(delta) >= this.height) {
|
|
1465
|
+
const topWins = this.radiusTop >= this.radiusBottom;
|
|
1466
|
+
return {
|
|
1467
|
+
sphere: {
|
|
1468
|
+
center: topWins ? this.height / 2 : -this.height / 2,
|
|
1469
|
+
radius: topWins ? this.radiusTop : this.radiusBottom
|
|
1470
|
+
},
|
|
1471
|
+
bottom: { radius: 0, y: 0 },
|
|
1472
|
+
top: { radius: 0, y: 0 }
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
const sinSlope = delta / this.height;
|
|
1476
|
+
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
1477
|
+
const normalY = -sinSlope;
|
|
1478
|
+
return {
|
|
1479
|
+
bottom: {
|
|
1480
|
+
radius: this.radiusBottom * radialNormal,
|
|
1481
|
+
y: -this.height / 2 + this.radiusBottom * normalY
|
|
1482
|
+
},
|
|
1483
|
+
top: { radius: this.radiusTop * radialNormal, y: this.height / 2 + this.radiusTop * normalY }
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
function intersectSphere(origin, direction2, centerY, radius2) {
|
|
1488
|
+
return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
|
|
1489
|
+
}
|
|
1490
|
+
function intersectSphereRoots(origin, direction2, centerY, radius2) {
|
|
1491
|
+
if (radius2 === 0)
|
|
1492
|
+
return [];
|
|
1493
|
+
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
1494
|
+
return solveQuadratic(dot3(direction2, direction2), 2 * dot3(relative, direction2), dot3(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
|
|
1495
|
+
distance,
|
|
1496
|
+
normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
|
|
1497
|
+
}));
|
|
1498
|
+
}
|
|
1499
|
+
function dot3(a, b) {
|
|
1500
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// dist/culling/lib/shapes/cylinder-shape.js
|
|
1504
|
+
var EPSILON3 = 1e-6;
|
|
1505
|
+
var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
|
|
1506
|
+
constructor(props = {}) {
|
|
1507
|
+
super(props.matrix);
|
|
1508
|
+
this.type = "cylinder";
|
|
1509
|
+
this.height = props.height ?? 2;
|
|
1510
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
1511
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
1512
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
1513
|
+
throw new Error("Cylinder height must be greater than zero");
|
|
1514
|
+
if (![this.radiusBottom, this.radiusTop].every((value) => Number.isFinite(value) && value >= 0))
|
|
1515
|
+
throw new Error("Cylinder radii must be non-negative");
|
|
1516
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
1517
|
+
throw new Error("At least one cylinder radius must be greater than zero");
|
|
1518
|
+
}
|
|
1519
|
+
clone() {
|
|
1520
|
+
return new _CylinderShape({
|
|
1521
|
+
height: this.height,
|
|
1522
|
+
radiusBottom: this.radiusBottom,
|
|
1523
|
+
radiusTop: this.radiusTop,
|
|
1524
|
+
matrix: this.matrix
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
equals(shape) {
|
|
1528
|
+
return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
|
|
1529
|
+
}
|
|
1530
|
+
containsLocalPoint(point2) {
|
|
1531
|
+
const half = this.height / 2;
|
|
1532
|
+
if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
|
|
1533
|
+
return false;
|
|
1534
|
+
const t = (point2[1] + half) / this.height;
|
|
1535
|
+
const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
1536
|
+
return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
|
|
1537
|
+
}
|
|
1538
|
+
distanceToLocalPoint(point2) {
|
|
1539
|
+
if (this.containsLocalPoint(point2))
|
|
1540
|
+
return 0;
|
|
1541
|
+
const radial = Math.hypot(point2[0], point2[2]);
|
|
1542
|
+
const half = this.height / 2;
|
|
1543
|
+
const side = closestDistanceToSegment2D(radial, point2[1], this.radiusBottom, -half, this.radiusTop, half);
|
|
1544
|
+
const bottom = closestDistanceToSegment2D(radial, point2[1], 0, -half, this.radiusBottom, -half);
|
|
1545
|
+
const top = closestDistanceToSegment2D(radial, point2[1], 0, half, this.radiusTop, half);
|
|
1546
|
+
return Math.min(side, bottom, top);
|
|
1547
|
+
}
|
|
1548
|
+
supportLocal(direction2) {
|
|
1549
|
+
const radialLength = Math.hypot(direction2[0], direction2[2]);
|
|
1550
|
+
const x = radialLength ? direction2[0] / radialLength : 1;
|
|
1551
|
+
const z = radialLength ? direction2[2] / radialLength : 0;
|
|
1552
|
+
const half = this.height / 2;
|
|
1553
|
+
const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
|
|
1554
|
+
const topValue = radialLength * this.radiusTop + direction2[1] * half;
|
|
1555
|
+
return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
1556
|
+
}
|
|
1557
|
+
intersectLocalRay(origin, direction2) {
|
|
1558
|
+
const half = this.height / 2;
|
|
1559
|
+
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
1560
|
+
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
1561
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
1562
|
+
const radialAlongRay = slope * direction2[1];
|
|
1563
|
+
const candidates = [];
|
|
1564
|
+
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);
|
|
1565
|
+
for (const distance of roots) {
|
|
1566
|
+
const y = origin[1] + distance * direction2[1];
|
|
1567
|
+
if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
|
|
1568
|
+
const x = origin[0] + distance * direction2[0];
|
|
1569
|
+
const z = origin[2] + distance * direction2[2];
|
|
1570
|
+
const radial = Math.hypot(x, z) || 1;
|
|
1571
|
+
const normal = [x / radial, -slope, z / radial];
|
|
1572
|
+
const length = Math.hypot(...normal);
|
|
1573
|
+
candidates.push({ distance, normal: normal.map((value) => value / length) });
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
if (Math.abs(direction2[1]) > 1e-15) {
|
|
1577
|
+
for (const [y, radius2, normalY] of [
|
|
1578
|
+
[-half, this.radiusBottom, -1],
|
|
1579
|
+
[half, this.radiusTop, 1]
|
|
1580
|
+
]) {
|
|
1581
|
+
const distance = (y - origin[1]) / direction2[1];
|
|
1582
|
+
const x = origin[0] + distance * direction2[0];
|
|
1583
|
+
const z = origin[2] + distance * direction2[2];
|
|
1584
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
|
|
1585
|
+
candidates.push({ distance, normal: [0, normalY, 0] });
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
// dist/culling/lib/shapes/plane-shape.js
|
|
1593
|
+
var import_core10 = require("@math.gl/core");
|
|
1594
|
+
var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
|
|
1595
|
+
constructor(props = {}) {
|
|
1596
|
+
super(props.matrix);
|
|
1597
|
+
this.type = "plane";
|
|
1598
|
+
this.sizeX = props.sizeX;
|
|
1599
|
+
this.sizeZ = props.sizeZ;
|
|
1600
|
+
if (this.sizeX !== void 0 && (!Number.isFinite(this.sizeX) || this.sizeX <= 0))
|
|
1601
|
+
throw new Error("Plane sizeX must be greater than zero");
|
|
1602
|
+
if (this.sizeZ !== void 0 && (!Number.isFinite(this.sizeZ) || this.sizeZ <= 0))
|
|
1603
|
+
throw new Error("Plane sizeZ must be greater than zero");
|
|
1604
|
+
}
|
|
1605
|
+
clone() {
|
|
1606
|
+
return new _PlaneShape({ sizeX: this.sizeX, sizeZ: this.sizeZ, matrix: this.matrix });
|
|
1607
|
+
}
|
|
1608
|
+
equals(shape) {
|
|
1609
|
+
return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
|
|
1610
|
+
}
|
|
1611
|
+
containsLocalPoint(point2) {
|
|
1612
|
+
return point2[1] <= 1e-12;
|
|
1613
|
+
}
|
|
1614
|
+
distanceToLocalPoint(point2) {
|
|
1615
|
+
return Math.max(0, point2[1]);
|
|
1616
|
+
}
|
|
1617
|
+
supportLocal() {
|
|
1618
|
+
throw new Error("An unbounded plane half-space has no finite support point");
|
|
1619
|
+
}
|
|
1620
|
+
intersectLocalRay(origin, direction2) {
|
|
1621
|
+
if (Math.abs(direction2[1]) < 1e-15)
|
|
1622
|
+
return void 0;
|
|
1623
|
+
const distance = -origin[1] / direction2[1];
|
|
1624
|
+
if (distance < 0)
|
|
1625
|
+
return void 0;
|
|
1626
|
+
const x = origin[0] + distance * direction2[0];
|
|
1627
|
+
const z = origin[2] + distance * direction2[2];
|
|
1628
|
+
if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
|
|
1629
|
+
return void 0;
|
|
1630
|
+
if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
|
|
1631
|
+
return void 0;
|
|
1632
|
+
return { distance, normal: [0, 1, 0] };
|
|
1633
|
+
}
|
|
1634
|
+
intersectPlane(plane) {
|
|
1635
|
+
const boundaryPoint = new import_core10.Vector3(0, 0, 0).transform(this.matrix);
|
|
1636
|
+
const inverse = this.inverseMatrix;
|
|
1637
|
+
const boundaryNormal = new import_core10.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
|
|
1638
|
+
const alignment = boundaryNormal.dot(plane.normal);
|
|
1639
|
+
if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
|
|
1640
|
+
return "intersecting";
|
|
1641
|
+
const boundaryDistance = plane.getPointDistance(boundaryPoint);
|
|
1642
|
+
if (alignment < 0 && boundaryDistance > 0)
|
|
1643
|
+
return "inside";
|
|
1644
|
+
if (alignment > 0 && boundaryDistance < 0)
|
|
1645
|
+
return "outside";
|
|
1646
|
+
return "intersecting";
|
|
1647
|
+
}
|
|
1648
|
+
getAxisAlignedBoundingBox() {
|
|
1649
|
+
return void 0;
|
|
1650
|
+
}
|
|
1651
|
+
getBoundingSphere() {
|
|
1652
|
+
return void 0;
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
|
|
1656
|
+
// dist/culling/lib/shapes/sphere-shape.js
|
|
1657
|
+
var EPSILON4 = 1e-6;
|
|
1658
|
+
var SphereShape = class _SphereShape extends ImplicitShapeBase {
|
|
1659
|
+
constructor(props = {}) {
|
|
1660
|
+
super(props.matrix);
|
|
1661
|
+
this.type = "sphere";
|
|
1662
|
+
this.radius = props.radius ?? 0.5;
|
|
1663
|
+
if (!Number.isFinite(this.radius) || this.radius <= 0)
|
|
1664
|
+
throw new Error("Sphere radius must be greater than zero");
|
|
1665
|
+
}
|
|
1666
|
+
clone() {
|
|
1667
|
+
return new _SphereShape({ radius: this.radius, matrix: this.matrix });
|
|
1668
|
+
}
|
|
1669
|
+
equals(shape) {
|
|
1670
|
+
return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
|
|
1671
|
+
}
|
|
1672
|
+
containsLocalPoint(point2) {
|
|
1673
|
+
return Math.hypot(...point2) <= this.radius + EPSILON4;
|
|
1674
|
+
}
|
|
1675
|
+
distanceToLocalPoint(point2) {
|
|
1676
|
+
return Math.max(0, Math.hypot(...point2) - this.radius);
|
|
1677
|
+
}
|
|
1678
|
+
supportLocal(direction2) {
|
|
1679
|
+
const length = Math.hypot(...direction2);
|
|
1680
|
+
return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
|
|
1681
|
+
}
|
|
1682
|
+
intersectLocalRay(origin, direction2) {
|
|
1683
|
+
const roots = solveQuadratic(dot4(direction2, direction2), 2 * dot4(origin, direction2), dot4(origin, origin) - this.radius * this.radius);
|
|
1684
|
+
const distance = roots.find((value) => value >= 0);
|
|
1685
|
+
if (distance === void 0)
|
|
1686
|
+
return void 0;
|
|
1687
|
+
const point2 = origin.map((value, i) => value + distance * direction2[i]);
|
|
1688
|
+
return { distance, normal: point2.map((value) => value / this.radius) };
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
function dot4(a, b) {
|
|
1692
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
// dist/culling/lib/perspective-off-center-frustum.js
|
|
1696
|
+
var import_core11 = require("@math.gl/core");
|
|
1697
|
+
var scratchPlaneUpVector = new import_core11.Vector3();
|
|
1698
|
+
var scratchPlaneRightVector = new import_core11.Vector3();
|
|
1699
|
+
var scratchPlaneNearCenter = new import_core11.Vector3();
|
|
1700
|
+
var scratchPlaneFarCenter = new import_core11.Vector3();
|
|
1701
|
+
var scratchPlaneNormal2 = new import_core11.Vector3();
|
|
1702
|
+
var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
|
|
1703
|
+
/**
|
|
1704
|
+
* The viewing frustum is defined by 6 planes.
|
|
1705
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
1706
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
1707
|
+
* plane from the origin/camera position.
|
|
1708
|
+
*
|
|
1709
|
+
* @alias PerspectiveOffCenterFrustum
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* const frustum = new PerspectiveOffCenterFrustum({
|
|
1713
|
+
* left : -1.0,
|
|
1714
|
+
* right : 1.0,
|
|
1715
|
+
* top : 1.0,
|
|
1716
|
+
* bottom : -1.0,
|
|
1717
|
+
* near : 1.0,
|
|
1718
|
+
* far : 100.0
|
|
1719
|
+
* });
|
|
1720
|
+
*
|
|
1721
|
+
* @see PerspectiveFrustum
|
|
1722
|
+
*/
|
|
1723
|
+
constructor(options = {}) {
|
|
1724
|
+
this._cullingVolume = new CullingVolume([
|
|
1725
|
+
new Plane(),
|
|
1726
|
+
new Plane(),
|
|
1727
|
+
new Plane(),
|
|
1728
|
+
new Plane(),
|
|
1729
|
+
new Plane(),
|
|
1730
|
+
new Plane()
|
|
1731
|
+
]);
|
|
1732
|
+
this._perspectiveMatrix = new import_core11.Matrix4();
|
|
1733
|
+
this._infinitePerspective = new import_core11.Matrix4();
|
|
1734
|
+
const { near = 1, far = 5e8 } = options;
|
|
1735
|
+
this.left = options.left;
|
|
1736
|
+
this._left = void 0;
|
|
1737
|
+
this.right = options.right;
|
|
1738
|
+
this._right = void 0;
|
|
1739
|
+
this.top = options.top;
|
|
1740
|
+
this._top = void 0;
|
|
1741
|
+
this.bottom = options.bottom;
|
|
1742
|
+
this._bottom = void 0;
|
|
1743
|
+
this.near = near;
|
|
1744
|
+
this._near = near;
|
|
1745
|
+
this.far = far;
|
|
1746
|
+
this._far = far;
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Returns a duplicate of a PerspectiveOffCenterFrustum instance.
|
|
1750
|
+
* @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.
|
|
1751
|
+
* */
|
|
1752
|
+
clone() {
|
|
1753
|
+
return new _PerspectiveOffCenterFrustum({
|
|
1754
|
+
right: this.right,
|
|
1755
|
+
left: this.left,
|
|
1756
|
+
top: this.top,
|
|
1757
|
+
bottom: this.bottom,
|
|
1758
|
+
near: this.near,
|
|
1759
|
+
far: this.far
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
/**
|
|
1763
|
+
* Compares the provided PerspectiveOffCenterFrustum componentwise and returns
|
|
1764
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
1765
|
+
*
|
|
1766
|
+
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
1767
|
+
*/
|
|
1768
|
+
equals(other) {
|
|
1769
|
+
return other && other instanceof _PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Gets the perspective projection matrix computed from the view frustum.
|
|
1773
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
1774
|
+
* @type {Matrix4}
|
|
1775
|
+
*
|
|
1776
|
+
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
|
|
1777
|
+
*/
|
|
1778
|
+
get projectionMatrix() {
|
|
1779
|
+
this._update();
|
|
1780
|
+
return this._perspectiveMatrix;
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
1784
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
1785
|
+
* @type {Matrix4}
|
|
1786
|
+
*
|
|
1787
|
+
* @see PerspectiveOffCenterFrustum#projectionMatrix
|
|
1788
|
+
*/
|
|
1789
|
+
get infiniteProjectionMatrix() {
|
|
1790
|
+
this._update();
|
|
1791
|
+
return this._infinitePerspective;
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Creates a culling volume for this frustum.
|
|
1795
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
1796
|
+
*
|
|
1797
|
+
* @example
|
|
1798
|
+
* // Check if a bounding volume intersects the frustum.
|
|
1799
|
+
* const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
1800
|
+
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
1801
|
+
*/
|
|
1802
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1803
|
+
computeCullingVolume(position, direction2, up) {
|
|
1804
|
+
(0, import_core11.assert)(position, "position is required.");
|
|
1805
|
+
(0, import_core11.assert)(direction2, "direction is required.");
|
|
1806
|
+
(0, import_core11.assert)(up, "up is required.");
|
|
1807
|
+
const planes = this._cullingVolume.planes;
|
|
1808
|
+
up = scratchPlaneUpVector.copy(up).normalize();
|
|
1809
|
+
const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
|
|
1810
|
+
const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
|
|
1811
|
+
const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
|
|
1812
|
+
let normal = scratchPlaneNormal2;
|
|
1813
|
+
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
1814
|
+
planes[0].fromPointNormal(position, normal);
|
|
1815
|
+
normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
|
|
1816
|
+
planes[1].fromPointNormal(position, normal);
|
|
1817
|
+
normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
|
|
1818
|
+
planes[2].fromPointNormal(position, normal);
|
|
1819
|
+
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
1820
|
+
planes[3].fromPointNormal(position, normal);
|
|
1821
|
+
normal = new import_core11.Vector3().copy(direction2);
|
|
1822
|
+
planes[4].fromPointNormal(nearCenter, normal);
|
|
1823
|
+
normal.negate();
|
|
1824
|
+
planes[5].fromPointNormal(farCenter, normal);
|
|
1825
|
+
return this._cullingVolume;
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Returns the pixel's width and height in meters.
|
|
1829
|
+
*
|
|
1830
|
+
* @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.
|
|
1831
|
+
*
|
|
1832
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
1833
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
1834
|
+
*
|
|
1835
|
+
* @example
|
|
1836
|
+
* // Example 1
|
|
1837
|
+
* // Get the width and height of a pixel.
|
|
1838
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
1839
|
+
*
|
|
1840
|
+
* @example
|
|
1841
|
+
* // Example 2
|
|
1842
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
1843
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
1844
|
+
* const position = camera.position;
|
|
1845
|
+
* const direction = camera.direction;
|
|
1846
|
+
* const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
1847
|
+
* const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
1848
|
+
* const distance = Vector3.magnitude(toCenterProj);
|
|
1849
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
1850
|
+
*/
|
|
1851
|
+
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
1852
|
+
this._update();
|
|
1853
|
+
(0, import_core11.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
1854
|
+
(0, import_core11.assert)(drawingBufferWidth > 0);
|
|
1855
|
+
(0, import_core11.assert)(drawingBufferHeight > 0);
|
|
1856
|
+
(0, import_core11.assert)(distance > 0);
|
|
1857
|
+
(0, import_core11.assert)(result);
|
|
1858
|
+
const inverseNear = 1 / this.near;
|
|
1859
|
+
let tanTheta = this.top * inverseNear;
|
|
1860
|
+
const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
|
|
1861
|
+
tanTheta = this.right * inverseNear;
|
|
1862
|
+
const pixelWidth = 2 * distance * tanTheta / drawingBufferWidth;
|
|
1863
|
+
result.x = pixelWidth;
|
|
1864
|
+
result.y = pixelHeight;
|
|
1865
|
+
return result;
|
|
1866
|
+
}
|
|
1867
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1868
|
+
_update() {
|
|
1869
|
+
(0, import_core11.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));
|
|
1870
|
+
const { top, bottom, right, left, near, far } = this;
|
|
1871
|
+
if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
|
|
1872
|
+
(0, import_core11.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
|
|
1873
|
+
this._left = left;
|
|
1874
|
+
this._right = right;
|
|
1875
|
+
this._top = top;
|
|
1876
|
+
this._bottom = bottom;
|
|
1877
|
+
this._near = near;
|
|
1878
|
+
this._far = far;
|
|
1879
|
+
this._perspectiveMatrix = new import_core11.Matrix4().frustum({
|
|
1880
|
+
left,
|
|
1881
|
+
right,
|
|
1882
|
+
bottom,
|
|
1883
|
+
top,
|
|
1884
|
+
near,
|
|
1885
|
+
far
|
|
1886
|
+
});
|
|
1887
|
+
this._infinitePerspective = new import_core11.Matrix4().frustum({
|
|
1888
|
+
left,
|
|
1889
|
+
right,
|
|
1890
|
+
bottom,
|
|
1891
|
+
top,
|
|
1892
|
+
near,
|
|
1893
|
+
far: Infinity
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
};
|
|
1898
|
+
|
|
1899
|
+
// dist/culling/lib/perspective-frustum.js
|
|
1900
|
+
var import_core12 = require("@math.gl/core");
|
|
1901
|
+
var defined = (val) => val !== null && typeof val !== "undefined";
|
|
1902
|
+
var PerspectiveFrustum = class _PerspectiveFrustum {
|
|
1903
|
+
constructor(options = {}) {
|
|
1904
|
+
this._offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
1905
|
+
const { fov, aspectRatio, near = 1, far = 5e8, xOffset = 0, yOffset = 0 } = options;
|
|
1906
|
+
this.fov = fov;
|
|
1907
|
+
this.aspectRatio = aspectRatio;
|
|
1908
|
+
this.near = near;
|
|
1909
|
+
this.far = far;
|
|
1910
|
+
this.xOffset = xOffset;
|
|
1911
|
+
this.yOffset = yOffset;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Returns a duplicate of a PerspectiveFrustum instance.
|
|
1915
|
+
*/
|
|
1916
|
+
clone() {
|
|
1917
|
+
return new _PerspectiveFrustum({
|
|
1918
|
+
aspectRatio: this.aspectRatio,
|
|
1919
|
+
fov: this.fov,
|
|
1920
|
+
near: this.near,
|
|
1921
|
+
far: this.far
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Compares the provided PerspectiveFrustum componentwise and returns
|
|
1926
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
1927
|
+
*/
|
|
1928
|
+
equals(other) {
|
|
1929
|
+
if (!defined(other) || !(other instanceof _PerspectiveFrustum)) {
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
this._update();
|
|
1933
|
+
other._update();
|
|
1934
|
+
return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Gets the perspective projection matrix computed from the view this.
|
|
1938
|
+
*/
|
|
1939
|
+
get projectionMatrix() {
|
|
1940
|
+
this._update();
|
|
1941
|
+
return this._offCenterFrustum.projectionMatrix;
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
1945
|
+
*/
|
|
1946
|
+
get infiniteProjectionMatrix() {
|
|
1947
|
+
this._update();
|
|
1948
|
+
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Gets the angle of the vertical field of view, in radians.
|
|
1952
|
+
*/
|
|
1953
|
+
get fovy() {
|
|
1954
|
+
this._update();
|
|
1955
|
+
return this._fovy;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* @private
|
|
1959
|
+
*/
|
|
1960
|
+
get sseDenominator() {
|
|
1961
|
+
this._update();
|
|
1962
|
+
return this._sseDenominator;
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* Creates a culling volume for this this.ion.
|
|
1966
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
1967
|
+
*
|
|
1968
|
+
* @example
|
|
1969
|
+
* // Check if a bounding volume intersects the this.
|
|
1970
|
+
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
1971
|
+
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
1972
|
+
*/
|
|
1973
|
+
computeCullingVolume(position, direction2, up) {
|
|
1974
|
+
this._update();
|
|
1975
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* Returns the pixel's width and height in meters.
|
|
1979
|
+
* @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.
|
|
1980
|
+
*
|
|
1981
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
1982
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
1983
|
+
*
|
|
1984
|
+
* @example
|
|
1985
|
+
* // Example 1
|
|
1986
|
+
* // Get the width and height of a pixel.
|
|
1987
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* // Example 2
|
|
1991
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
1992
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
1993
|
+
* var position = camera.position;
|
|
1994
|
+
* var direction = camera.direction;
|
|
1995
|
+
* var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
1996
|
+
* var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
1997
|
+
* var distance = Vector3.magnitude(toCenterProj);
|
|
1998
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
1999
|
+
*/
|
|
2000
|
+
getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
|
|
2001
|
+
this._update();
|
|
2002
|
+
return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core12.Vector2());
|
|
2003
|
+
}
|
|
2004
|
+
// eslint-disable-next-line complexity, max-statements
|
|
2005
|
+
_update() {
|
|
2006
|
+
(0, import_core12.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
|
|
2007
|
+
const f = this._offCenterFrustum;
|
|
2008
|
+
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) {
|
|
2009
|
+
(0, import_core12.assert)(this.fov >= 0 && this.fov < Math.PI);
|
|
2010
|
+
(0, import_core12.assert)(this.aspectRatio > 0);
|
|
2011
|
+
(0, import_core12.assert)(this.near >= 0 && this.near < this.far);
|
|
2012
|
+
this._aspectRatio = this.aspectRatio;
|
|
2013
|
+
this._fov = this.fov;
|
|
2014
|
+
this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
|
|
2015
|
+
this._near = this.near;
|
|
2016
|
+
this._far = this.far;
|
|
2017
|
+
this._sseDenominator = 2 * Math.tan(0.5 * this._fovy);
|
|
2018
|
+
this._xOffset = this.xOffset;
|
|
2019
|
+
this._yOffset = this.yOffset;
|
|
2020
|
+
f.top = this.near * Math.tan(0.5 * this._fovy);
|
|
2021
|
+
f.bottom = -f.top;
|
|
2022
|
+
f.right = this.aspectRatio * f.top;
|
|
2023
|
+
f.left = -f.right;
|
|
2024
|
+
f.near = this.near;
|
|
2025
|
+
f.far = this.far;
|
|
2026
|
+
f.right += this.xOffset;
|
|
2027
|
+
f.left += this.xOffset;
|
|
2028
|
+
f.top += this.yOffset;
|
|
2029
|
+
f.bottom += this.yOffset;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
|
|
2034
|
+
// dist/culling/lib/algorithms/bounding-sphere-from-points.js
|
|
2035
|
+
var import_core13 = require("@math.gl/core");
|
|
2036
|
+
var fromPointsXMin = new import_core13.Vector3();
|
|
2037
|
+
var fromPointsYMin = new import_core13.Vector3();
|
|
2038
|
+
var fromPointsZMin = new import_core13.Vector3();
|
|
2039
|
+
var fromPointsXMax = new import_core13.Vector3();
|
|
2040
|
+
var fromPointsYMax = new import_core13.Vector3();
|
|
2041
|
+
var fromPointsZMax = new import_core13.Vector3();
|
|
2042
|
+
var fromPointsCurrentPos = new import_core13.Vector3();
|
|
2043
|
+
var fromPointsScratch = new import_core13.Vector3();
|
|
2044
|
+
var fromPointsRitterCenter = new import_core13.Vector3();
|
|
2045
|
+
var fromPointsMinBoxPt = new import_core13.Vector3();
|
|
2046
|
+
var fromPointsMaxBoxPt = new import_core13.Vector3();
|
|
2047
|
+
var fromPointsNaiveCenterScratch = new import_core13.Vector3();
|
|
2048
|
+
function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
|
|
2049
|
+
if (!positions || positions.length === 0) {
|
|
2050
|
+
return result.fromCenterRadius([0, 0, 0], 0);
|
|
2051
|
+
}
|
|
2052
|
+
const currentPos = fromPointsCurrentPos.copy(positions[0]);
|
|
2053
|
+
const xMin = fromPointsXMin.copy(currentPos);
|
|
2054
|
+
const yMin = fromPointsYMin.copy(currentPos);
|
|
2055
|
+
const zMin = fromPointsZMin.copy(currentPos);
|
|
2056
|
+
const xMax = fromPointsXMax.copy(currentPos);
|
|
2057
|
+
const yMax = fromPointsYMax.copy(currentPos);
|
|
2058
|
+
const zMax = fromPointsZMax.copy(currentPos);
|
|
2059
|
+
for (const position of positions) {
|
|
2060
|
+
currentPos.copy(position);
|
|
2061
|
+
const x = currentPos.x;
|
|
2062
|
+
const y = currentPos.y;
|
|
2063
|
+
const z = currentPos.z;
|
|
2064
|
+
if (x < xMin.x) {
|
|
2065
|
+
xMin.copy(currentPos);
|
|
2066
|
+
}
|
|
2067
|
+
if (x > xMax.x) {
|
|
2068
|
+
xMax.copy(currentPos);
|
|
2069
|
+
}
|
|
2070
|
+
if (y < yMin.y) {
|
|
2071
|
+
yMin.copy(currentPos);
|
|
2072
|
+
}
|
|
2073
|
+
if (y > yMax.y) {
|
|
2074
|
+
yMax.copy(currentPos);
|
|
2075
|
+
}
|
|
2076
|
+
if (z < zMin.z) {
|
|
2077
|
+
zMin.copy(currentPos);
|
|
2078
|
+
}
|
|
2079
|
+
if (z > zMax.z) {
|
|
2080
|
+
zMax.copy(currentPos);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
|
|
2084
|
+
const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
|
|
2085
|
+
const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
|
|
2086
|
+
let diameter1 = xMin;
|
|
2087
|
+
let diameter2 = xMax;
|
|
2088
|
+
let maxSpan = xSpan;
|
|
2089
|
+
if (ySpan > maxSpan) {
|
|
2090
|
+
maxSpan = ySpan;
|
|
2091
|
+
diameter1 = yMin;
|
|
2092
|
+
diameter2 = yMax;
|
|
2093
|
+
}
|
|
2094
|
+
if (zSpan > maxSpan) {
|
|
2095
|
+
maxSpan = zSpan;
|
|
2096
|
+
diameter1 = zMin;
|
|
2097
|
+
diameter2 = zMax;
|
|
2098
|
+
}
|
|
2099
|
+
const ritterCenter = fromPointsRitterCenter;
|
|
2100
|
+
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
|
|
2101
|
+
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
|
|
2102
|
+
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
|
|
2103
|
+
let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
|
|
2104
|
+
let ritterRadius = Math.sqrt(radiusSquared);
|
|
2105
|
+
const minBoxPt = fromPointsMinBoxPt;
|
|
2106
|
+
minBoxPt.x = xMin.x;
|
|
2107
|
+
minBoxPt.y = yMin.y;
|
|
2108
|
+
minBoxPt.z = zMin.z;
|
|
2109
|
+
const maxBoxPt = fromPointsMaxBoxPt;
|
|
2110
|
+
maxBoxPt.x = xMax.x;
|
|
2111
|
+
maxBoxPt.y = yMax.y;
|
|
2112
|
+
maxBoxPt.z = zMax.z;
|
|
2113
|
+
const naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5);
|
|
2114
|
+
let naiveRadius = 0;
|
|
2115
|
+
for (const position of positions) {
|
|
2116
|
+
currentPos.copy(position);
|
|
2117
|
+
const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
|
|
2118
|
+
if (r > naiveRadius) {
|
|
2119
|
+
naiveRadius = r;
|
|
2120
|
+
}
|
|
2121
|
+
const oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared();
|
|
2122
|
+
if (oldCenterToPointSquared > radiusSquared) {
|
|
2123
|
+
const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
|
|
2124
|
+
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
|
|
2125
|
+
radiusSquared = ritterRadius * ritterRadius;
|
|
2126
|
+
const oldToNew = oldCenterToPoint - ritterRadius;
|
|
2127
|
+
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
|
|
2128
|
+
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
|
|
2129
|
+
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
if (ritterRadius < naiveRadius) {
|
|
2133
|
+
ritterCenter.to(result.center);
|
|
2134
|
+
result.radius = ritterRadius;
|
|
2135
|
+
} else {
|
|
2136
|
+
naiveCenter.to(result.center);
|
|
2137
|
+
result.radius = naiveRadius;
|
|
2138
|
+
}
|
|
2139
|
+
return result;
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
2143
|
+
var import_core15 = require("@math.gl/core");
|
|
2144
|
+
|
|
2145
|
+
// dist/culling/lib/algorithms/compute-eigen-decomposition.js
|
|
2146
|
+
var import_core14 = require("@math.gl/core");
|
|
2147
|
+
var scratchMatrix = new import_core14.Matrix3();
|
|
2148
|
+
var scratchUnitary = new import_core14.Matrix3();
|
|
2149
|
+
var scratchDiagonal = new import_core14.Matrix3();
|
|
2150
|
+
var jMatrix = new import_core14.Matrix3();
|
|
2151
|
+
var jMatrixTranspose = new import_core14.Matrix3();
|
|
2152
|
+
function computeEigenDecomposition(matrix, result = {}) {
|
|
2153
|
+
const EIGEN_TOLERANCE = import_core14._MathUtils.EPSILON20;
|
|
2154
|
+
const EIGEN_MAX_SWEEPS = 10;
|
|
2155
|
+
let count = 0;
|
|
2156
|
+
let sweep = 0;
|
|
2157
|
+
const unitaryMatrix = scratchUnitary;
|
|
2158
|
+
const diagonalMatrix = scratchDiagonal;
|
|
2159
|
+
unitaryMatrix.identity();
|
|
2160
|
+
diagonalMatrix.copy(matrix);
|
|
2161
|
+
const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);
|
|
2162
|
+
while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {
|
|
2163
|
+
shurDecomposition(diagonalMatrix, jMatrix);
|
|
2164
|
+
jMatrixTranspose.copy(jMatrix).transpose();
|
|
2165
|
+
diagonalMatrix.multiplyRight(jMatrix);
|
|
2166
|
+
diagonalMatrix.multiplyLeft(jMatrixTranspose);
|
|
2167
|
+
unitaryMatrix.multiplyRight(jMatrix);
|
|
2168
|
+
if (++count > 2) {
|
|
2169
|
+
++sweep;
|
|
2170
|
+
count = 0;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
result.unitary = unitaryMatrix.toTarget(result.unitary);
|
|
2174
|
+
result.diagonal = diagonalMatrix.toTarget(result.diagonal);
|
|
2175
|
+
return result;
|
|
2176
|
+
}
|
|
2177
|
+
function computeFrobeniusNorm(matrix) {
|
|
2178
|
+
let norm = 0;
|
|
2179
|
+
for (let i = 0; i < 9; ++i) {
|
|
2180
|
+
const temp = matrix[i];
|
|
2181
|
+
norm += temp * temp;
|
|
2182
|
+
}
|
|
2183
|
+
return Math.sqrt(norm);
|
|
2184
|
+
}
|
|
2185
|
+
var rowVal = [1, 0, 0];
|
|
2186
|
+
var colVal = [2, 2, 1];
|
|
2187
|
+
function offDiagonalFrobeniusNorm(matrix) {
|
|
2188
|
+
let norm = 0;
|
|
2189
|
+
for (let i = 0; i < 3; ++i) {
|
|
2190
|
+
const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
|
|
2191
|
+
norm += 2 * temp * temp;
|
|
2192
|
+
}
|
|
2193
|
+
return Math.sqrt(norm);
|
|
2194
|
+
}
|
|
2195
|
+
function shurDecomposition(matrix, result) {
|
|
2196
|
+
const tolerance = import_core14._MathUtils.EPSILON15;
|
|
2197
|
+
let maxDiagonal = 0;
|
|
2198
|
+
let rotAxis = 1;
|
|
2199
|
+
for (let i = 0; i < 3; ++i) {
|
|
2200
|
+
const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);
|
|
2201
|
+
if (temp > maxDiagonal) {
|
|
2202
|
+
rotAxis = i;
|
|
2203
|
+
maxDiagonal = temp;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
const p = rowVal[rotAxis];
|
|
2207
|
+
const q = colVal[rotAxis];
|
|
2208
|
+
let c = 1;
|
|
2209
|
+
let s = 0;
|
|
2210
|
+
if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {
|
|
2211
|
+
const qq = matrix[scratchMatrix.getElementIndex(q, q)];
|
|
2212
|
+
const pp = matrix[scratchMatrix.getElementIndex(p, p)];
|
|
2213
|
+
const qp = matrix[scratchMatrix.getElementIndex(q, p)];
|
|
2214
|
+
const tau = (qq - pp) / 2 / qp;
|
|
2215
|
+
let t;
|
|
2216
|
+
if (tau < 0) {
|
|
2217
|
+
t = -1 / (-tau + Math.sqrt(1 + tau * tau));
|
|
2218
|
+
} else {
|
|
2219
|
+
t = 1 / (tau + Math.sqrt(1 + tau * tau));
|
|
2220
|
+
}
|
|
2221
|
+
c = 1 / Math.sqrt(1 + t * t);
|
|
2222
|
+
s = t * c;
|
|
2223
|
+
}
|
|
2224
|
+
import_core14.Matrix3.IDENTITY.to(result);
|
|
2225
|
+
result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
|
|
2226
|
+
result[scratchMatrix.getElementIndex(q, p)] = s;
|
|
2227
|
+
result[scratchMatrix.getElementIndex(p, q)] = -s;
|
|
2228
|
+
return result;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// dist/culling/lib/algorithms/bounding-box-from-points.js
|
|
2232
|
+
var scratchVector23 = new import_core15.Vector3();
|
|
2233
|
+
var scratchVector32 = new import_core15.Vector3();
|
|
2234
|
+
var scratchVector4 = new import_core15.Vector3();
|
|
2235
|
+
var scratchVector5 = new import_core15.Vector3();
|
|
2236
|
+
var scratchVector6 = new import_core15.Vector3();
|
|
2237
|
+
var scratchCovarianceResult = new import_core15.Matrix3();
|
|
2238
|
+
var scratchEigenResult = {
|
|
2239
|
+
diagonal: new import_core15.Matrix3(),
|
|
2240
|
+
unitary: new import_core15.Matrix3()
|
|
2241
|
+
};
|
|
2242
|
+
function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
|
|
2243
|
+
if (!positions || positions.length === 0) {
|
|
2244
|
+
result.halfAxes = new import_core15.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
2245
|
+
result.center = new import_core15.Vector3();
|
|
2246
|
+
return result;
|
|
2247
|
+
}
|
|
2248
|
+
const length = positions.length;
|
|
2249
|
+
const meanPoint = new import_core15.Vector3(0, 0, 0);
|
|
2250
|
+
for (const position of positions) {
|
|
2251
|
+
meanPoint.add(position);
|
|
2252
|
+
}
|
|
2253
|
+
const invLength = 1 / length;
|
|
2254
|
+
meanPoint.multiplyByScalar(invLength);
|
|
2255
|
+
let exx = 0;
|
|
2256
|
+
let exy = 0;
|
|
2257
|
+
let exz = 0;
|
|
2258
|
+
let eyy = 0;
|
|
2259
|
+
let eyz = 0;
|
|
2260
|
+
let ezz = 0;
|
|
2261
|
+
for (const position of positions) {
|
|
2262
|
+
const p = scratchVector23.copy(position).subtract(meanPoint);
|
|
2263
|
+
exx += p.x * p.x;
|
|
2264
|
+
exy += p.x * p.y;
|
|
2265
|
+
exz += p.x * p.z;
|
|
2266
|
+
eyy += p.y * p.y;
|
|
2267
|
+
eyz += p.y * p.z;
|
|
2268
|
+
ezz += p.z * p.z;
|
|
2269
|
+
}
|
|
2270
|
+
exx *= invLength;
|
|
2271
|
+
exy *= invLength;
|
|
2272
|
+
exz *= invLength;
|
|
2273
|
+
eyy *= invLength;
|
|
2274
|
+
eyz *= invLength;
|
|
2275
|
+
ezz *= invLength;
|
|
2276
|
+
const covarianceMatrix = scratchCovarianceResult;
|
|
2277
|
+
covarianceMatrix[0] = exx;
|
|
2278
|
+
covarianceMatrix[1] = exy;
|
|
2279
|
+
covarianceMatrix[2] = exz;
|
|
2280
|
+
covarianceMatrix[3] = exy;
|
|
2281
|
+
covarianceMatrix[4] = eyy;
|
|
2282
|
+
covarianceMatrix[5] = eyz;
|
|
2283
|
+
covarianceMatrix[6] = exz;
|
|
2284
|
+
covarianceMatrix[7] = eyz;
|
|
2285
|
+
covarianceMatrix[8] = ezz;
|
|
2286
|
+
const { unitary } = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
|
|
2287
|
+
const rotation = result.halfAxes.copy(unitary);
|
|
2288
|
+
let v1 = rotation.getColumn(0, scratchVector4);
|
|
2289
|
+
let v2 = rotation.getColumn(1, scratchVector5);
|
|
2290
|
+
let v3 = rotation.getColumn(2, scratchVector6);
|
|
2291
|
+
let u1 = -Number.MAX_VALUE;
|
|
2292
|
+
let u2 = -Number.MAX_VALUE;
|
|
2293
|
+
let u3 = -Number.MAX_VALUE;
|
|
2294
|
+
let l1 = Number.MAX_VALUE;
|
|
2295
|
+
let l2 = Number.MAX_VALUE;
|
|
2296
|
+
let l3 = Number.MAX_VALUE;
|
|
2297
|
+
for (const position of positions) {
|
|
2298
|
+
scratchVector23.copy(position);
|
|
2299
|
+
u1 = Math.max(scratchVector23.dot(v1), u1);
|
|
2300
|
+
u2 = Math.max(scratchVector23.dot(v2), u2);
|
|
2301
|
+
u3 = Math.max(scratchVector23.dot(v3), u3);
|
|
2302
|
+
l1 = Math.min(scratchVector23.dot(v1), l1);
|
|
2303
|
+
l2 = Math.min(scratchVector23.dot(v2), l2);
|
|
2304
|
+
l3 = Math.min(scratchVector23.dot(v3), l3);
|
|
2305
|
+
}
|
|
2306
|
+
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
2307
|
+
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
2308
|
+
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
2309
|
+
result.center.copy(v1).add(v2).add(v3);
|
|
2310
|
+
const scale = scratchVector32.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
2311
|
+
const scaleMatrix = new import_core15.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
2312
|
+
result.halfAxes.multiplyRight(scaleMatrix);
|
|
2313
|
+
return result;
|
|
2314
|
+
}
|
|
2315
|
+
function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAlignedBoundingBox()) {
|
|
2316
|
+
if (!positions || positions.length === 0) {
|
|
2317
|
+
result.minimum.set(0, 0, 0);
|
|
2318
|
+
result.maximum.set(0, 0, 0);
|
|
2319
|
+
result.center.set(0, 0, 0);
|
|
2320
|
+
result.halfDiagonal.set(0, 0, 0);
|
|
2321
|
+
return result;
|
|
2322
|
+
}
|
|
2323
|
+
let minimumX = positions[0][0];
|
|
2324
|
+
let minimumY = positions[0][1];
|
|
2325
|
+
let minimumZ = positions[0][2];
|
|
2326
|
+
let maximumX = positions[0][0];
|
|
2327
|
+
let maximumY = positions[0][1];
|
|
2328
|
+
let maximumZ = positions[0][2];
|
|
2329
|
+
for (const p of positions) {
|
|
2330
|
+
const x = p[0];
|
|
2331
|
+
const y = p[1];
|
|
2332
|
+
const z = p[2];
|
|
2333
|
+
minimumX = Math.min(x, minimumX);
|
|
2334
|
+
maximumX = Math.max(x, maximumX);
|
|
2335
|
+
minimumY = Math.min(y, minimumY);
|
|
2336
|
+
maximumY = Math.max(y, maximumY);
|
|
2337
|
+
minimumZ = Math.min(z, minimumZ);
|
|
2338
|
+
maximumZ = Math.max(z, maximumZ);
|
|
2339
|
+
}
|
|
2340
|
+
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
2341
|
+
result.maximum.set(maximumX, maximumY, maximumZ);
|
|
2342
|
+
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
|
|
2343
|
+
result.halfDiagonal.copy(result.maximum).subtract(result.center);
|
|
2344
|
+
return result;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// dist/culling/oriented-box-2d.js
|
|
2348
|
+
function intersectOrientedBoxes2D(first, second, epsilon = 0) {
|
|
2349
|
+
validateBox(first);
|
|
2350
|
+
validateBox(second);
|
|
2351
|
+
if (!Number.isFinite(epsilon) || epsilon < 0) {
|
|
2352
|
+
throw new RangeError("Box separation allowance must be finite and nonnegative");
|
|
2353
|
+
}
|
|
2354
|
+
const firstDirectionScale = Math.max(Math.abs(first.direction[0]), Math.abs(first.direction[1]));
|
|
2355
|
+
const secondDirectionScale = Math.max(Math.abs(second.direction[0]), Math.abs(second.direction[1]));
|
|
2356
|
+
const firstWidthX = first.direction[0] / firstDirectionScale;
|
|
2357
|
+
const firstWidthY = first.direction[1] / firstDirectionScale;
|
|
2358
|
+
const secondWidthX = second.direction[0] / secondDirectionScale;
|
|
2359
|
+
const secondWidthY = second.direction[1] / secondDirectionScale;
|
|
2360
|
+
const firstLength = Math.hypot(firstWidthX, firstWidthY);
|
|
2361
|
+
const secondLength = Math.hypot(secondWidthX, secondWidthY);
|
|
2362
|
+
const firstX = firstWidthX / firstLength;
|
|
2363
|
+
const firstY = firstWidthY / firstLength;
|
|
2364
|
+
const secondX = secondWidthX / secondLength;
|
|
2365
|
+
const secondY = secondWidthY / secondLength;
|
|
2366
|
+
const cosine = Math.min(1, Math.abs(firstX * secondX + firstY * secondY));
|
|
2367
|
+
const sine = Math.min(1, Math.abs(firstX * secondY - firstY * secondX));
|
|
2368
|
+
return overlapsOnAxis(first, second, firstX, firstY, first.halfSize[0], second.halfSize[0] * cosine, second.halfSize[1] * sine, epsilon) && overlapsOnAxis(first, second, -firstY, firstX, first.halfSize[1], second.halfSize[0] * sine, second.halfSize[1] * cosine, epsilon) && overlapsOnAxis(first, second, secondX, secondY, second.halfSize[0], first.halfSize[0] * cosine, first.halfSize[1] * sine, epsilon) && overlapsOnAxis(first, second, -secondY, secondX, second.halfSize[1], first.halfSize[0] * sine, first.halfSize[1] * cosine, epsilon);
|
|
2369
|
+
}
|
|
2370
|
+
function overlapsOnAxis(first, second, axisX, axisY, ownRadius, otherWidthRadius, otherHeightRadius, epsilon) {
|
|
2371
|
+
const displacementX = second.center[0] - first.center[0];
|
|
2372
|
+
const displacementY = second.center[1] - first.center[1];
|
|
2373
|
+
const projectionX = Number.isFinite(displacementX) ? displacementX * axisX : second.center[0] * axisX - first.center[0] * axisX;
|
|
2374
|
+
const projectionY = Number.isFinite(displacementY) ? displacementY * axisY : second.center[1] * axisY - first.center[1] * axisY;
|
|
2375
|
+
const scale = Math.max(ownRadius, otherWidthRadius, otherHeightRadius, epsilon, Number.isFinite(projectionX) ? Math.abs(projectionX) : Math.max(Math.abs(first.center[0] * axisX), Math.abs(second.center[0] * axisX)), Number.isFinite(projectionY) ? Math.abs(projectionY) : Math.max(Math.abs(first.center[1] * axisY), Math.abs(second.center[1] * axisY))) || 1;
|
|
2376
|
+
const normalizedX = Number.isFinite(projectionX) ? projectionX / scale : second.center[0] * axisX / scale - first.center[0] * axisX / scale;
|
|
2377
|
+
const normalizedY = Number.isFinite(projectionY) ? projectionY / scale : second.center[1] * axisY / scale - first.center[1] * axisY / scale;
|
|
2378
|
+
return Math.abs(normalizedX + normalizedY) <= ownRadius / scale + otherWidthRadius / scale + otherHeightRadius / scale + epsilon / scale;
|
|
2379
|
+
}
|
|
2380
|
+
function validateBox(box) {
|
|
2381
|
+
validateVector(box.center);
|
|
2382
|
+
validateVector(box.halfSize);
|
|
2383
|
+
validateVector(box.direction);
|
|
2384
|
+
if (box.halfSize[0] < 0 || box.halfSize[1] < 0) {
|
|
2385
|
+
throw new RangeError("Box half-sizes must be nonnegative");
|
|
2386
|
+
}
|
|
2387
|
+
if (box.direction[0] === 0 && box.direction[1] === 0) {
|
|
2388
|
+
throw new RangeError("Box direction must be nonzero");
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
function validateVector(vector) {
|
|
2392
|
+
if (vector.length !== 2 || !Number.isFinite(vector[0]) || !Number.isFinite(vector[1])) {
|
|
2393
|
+
throw new RangeError("Box vectors must have exactly two finite components");
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
// dist/culling/screen-ray.js
|
|
2398
|
+
var import_core16 = require("@math.gl/core");
|
|
2399
|
+
function unprojectScreenRay(inverseClipMatrix, viewport, pixel, depthRange = [-1, 1]) {
|
|
2400
|
+
const x = viewport.x ?? 0;
|
|
2401
|
+
const y = viewport.y ?? 0;
|
|
2402
|
+
if (inverseClipMatrix.length !== 16 || !Array.from(inverseClipMatrix).every(Number.isFinite) || ![x, y, viewport.width, viewport.height, ...pixel, ...depthRange].every(Number.isFinite) || viewport.width <= 0 || viewport.height <= 0 || pixel.length !== 2 || depthRange.length !== 2 || depthRange[0] === depthRange[1])
|
|
2403
|
+
return null;
|
|
2404
|
+
const matrix = new import_core16.Matrix4(Array.from(inverseClipMatrix));
|
|
2405
|
+
const determinant = matrix.determinant();
|
|
2406
|
+
if (!Number.isFinite(determinant) || determinant === 0)
|
|
2407
|
+
return null;
|
|
2408
|
+
const horizontal = 2 * (pixel[0] - x) / viewport.width - 1;
|
|
2409
|
+
const vertical = 1 - 2 * (pixel[1] - y) / viewport.height;
|
|
2410
|
+
const points = depthRange.map((depth) => matrix.transform([horizontal, vertical, depth, 1]));
|
|
2411
|
+
if (points.some((point2) => point2[3] === 0 || !point2.every(Number.isFinite)))
|
|
2412
|
+
return null;
|
|
2413
|
+
if (points[0][3] < 0 !== points[1][3] < 0)
|
|
2414
|
+
return null;
|
|
2415
|
+
const origin = [
|
|
2416
|
+
points[0][0] / points[0][3],
|
|
2417
|
+
points[0][1] / points[0][3],
|
|
2418
|
+
points[0][2] / points[0][3]
|
|
2419
|
+
];
|
|
2420
|
+
const direction2 = [
|
|
2421
|
+
points[1][0] / points[1][3] - origin[0],
|
|
2422
|
+
points[1][1] / points[1][3] - origin[1],
|
|
2423
|
+
points[1][2] / points[1][3] - origin[2]
|
|
2424
|
+
];
|
|
2425
|
+
const distance = Math.hypot(...direction2);
|
|
2426
|
+
return origin.every(Number.isFinite) && direction2.every(Number.isFinite) && Number.isFinite(distance) && distance > 0 ? { origin, direction: direction2 } : null;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
|
|
2430
|
+
var import_core17 = require("@math.gl/core");
|
|
2431
|
+
function getOrientedBoundingBoxQuaternion(box) {
|
|
2432
|
+
const x = new import_core17.Vector3(box.halfAxes.getColumn(0)).normalize();
|
|
2433
|
+
const y = new import_core17.Vector3(box.halfAxes.getColumn(1)).normalize();
|
|
2434
|
+
const z = new import_core17.Vector3(box.halfAxes.getColumn(2)).normalize();
|
|
2435
|
+
return new import_core17.Quaternion().fromMatrix3(new import_core17.Matrix3([...x, ...y, ...z]));
|
|
2436
|
+
}
|
|
2437
|
+
function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
|
|
2438
|
+
const halfAxes = new import_core17.Matrix3().fromQuaternion(quaternion);
|
|
2439
|
+
for (let column = 0; column < 3; column++) {
|
|
2440
|
+
for (let row = 0; row < 3; row++)
|
|
2441
|
+
halfAxes[column * 3 + row] *= halfSize[column];
|
|
2442
|
+
}
|
|
2443
|
+
result.center = new import_core17.Vector3(center);
|
|
2444
|
+
result.halfAxes = halfAxes;
|
|
2445
|
+
return result;
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// dist/culling/bounds.js
|
|
2449
|
+
function dimension(bounds) {
|
|
2450
|
+
const n = bounds[0].length;
|
|
2451
|
+
if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
|
|
2452
|
+
throw new RangeError("Expected 2D or 3D bounds without NaN");
|
|
2453
|
+
}
|
|
2454
|
+
const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
2455
|
+
if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
|
|
2456
|
+
throw new RangeError("Nonempty bounds must be finite");
|
|
2457
|
+
}
|
|
2458
|
+
return n;
|
|
2459
|
+
}
|
|
2460
|
+
function pair(a, b) {
|
|
2461
|
+
const n = dimension(a);
|
|
2462
|
+
if (dimension(b) !== n)
|
|
2463
|
+
throw new RangeError("Bounds dimensions must match");
|
|
2464
|
+
return n;
|
|
2465
|
+
}
|
|
2466
|
+
function point(p, n) {
|
|
2467
|
+
if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
|
|
2468
|
+
throw new RangeError("Expected a finite point of matching dimension");
|
|
2469
|
+
}
|
|
2470
|
+
function createEmptyBounds(dimension2) {
|
|
2471
|
+
if (dimension2 !== 2 && dimension2 !== 3)
|
|
2472
|
+
throw new RangeError("Expected dimension 2 or 3");
|
|
2473
|
+
return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
|
|
2474
|
+
}
|
|
2475
|
+
function isEmptyBounds(bounds) {
|
|
2476
|
+
return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
|
|
2477
|
+
}
|
|
2478
|
+
function boundsContainsPoint(bounds, p) {
|
|
2479
|
+
point(p, dimension(bounds));
|
|
2480
|
+
return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
|
|
2481
|
+
}
|
|
2482
|
+
function boundsContainsBounds(a, b) {
|
|
2483
|
+
const n = pair(a, b);
|
|
2484
|
+
return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
|
|
2485
|
+
}
|
|
2486
|
+
function boundsIntersect(a, b) {
|
|
2487
|
+
const n = pair(a, b);
|
|
2488
|
+
return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
|
|
2489
|
+
}
|
|
2490
|
+
function store(values, out = createEmptyBounds(values[0].length)) {
|
|
2491
|
+
if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
|
|
2492
|
+
throw new RangeError("Output bounds dimensions must match");
|
|
2493
|
+
}
|
|
2494
|
+
for (let j = 0; j < 2; j++)
|
|
2495
|
+
for (let i = 0; i < values[j].length; i++)
|
|
2496
|
+
out[j][i] = values[j][i];
|
|
2497
|
+
return out;
|
|
2498
|
+
}
|
|
2499
|
+
function unionBounds(a, b, out) {
|
|
2500
|
+
const n = pair(a, b);
|
|
2501
|
+
const values = createEmptyBounds(n);
|
|
2502
|
+
const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
|
|
2503
|
+
for (let i = 0; i < n; i++) {
|
|
2504
|
+
values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
|
|
2505
|
+
values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
|
|
2506
|
+
}
|
|
2507
|
+
return store(values, out);
|
|
2508
|
+
}
|
|
2509
|
+
function intersectBounds(a, b, out) {
|
|
2510
|
+
const n = pair(a, b), values = createEmptyBounds(n);
|
|
2511
|
+
if (boundsIntersect(a, b))
|
|
2512
|
+
for (let i = 0; i < n; i++) {
|
|
2513
|
+
values[0][i] = Math.max(a[0][i], b[0][i]);
|
|
2514
|
+
values[1][i] = Math.min(a[1][i], b[1][i]);
|
|
2515
|
+
}
|
|
2516
|
+
return store(values, out);
|
|
2517
|
+
}
|
|
2518
|
+
function expandBoundsByPoint(bounds, p, out) {
|
|
2519
|
+
point(p, dimension(bounds));
|
|
2520
|
+
return unionBounds(bounds, [p, p], out);
|
|
2521
|
+
}
|
|
2522
|
+
function expandBounds(bounds, padding, out) {
|
|
2523
|
+
if (!Number.isFinite(padding))
|
|
2524
|
+
throw new RangeError("Padding must be finite");
|
|
2525
|
+
const n = dimension(bounds), values = createEmptyBounds(n);
|
|
2526
|
+
if (!isEmptyBounds(bounds))
|
|
2527
|
+
for (let i = 0; i < n; i++) {
|
|
2528
|
+
values[0][i] = bounds[0][i] - padding;
|
|
2529
|
+
values[1][i] = bounds[1][i] + padding;
|
|
2530
|
+
}
|
|
2531
|
+
return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
|
|
2532
|
+
}
|
|
2533
|
+
function clampPointToBounds(bounds, p, out = new Array(p.length)) {
|
|
2534
|
+
point(p, dimension(bounds));
|
|
2535
|
+
if (out.length < p.length)
|
|
2536
|
+
throw new RangeError("Result buffer is too short");
|
|
2537
|
+
if (isEmptyBounds(bounds))
|
|
2538
|
+
return null;
|
|
2539
|
+
const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
|
|
2540
|
+
for (let i = 0; i < result.length; i++)
|
|
2541
|
+
out[i] = result[i];
|
|
2542
|
+
return out;
|
|
2543
|
+
}
|
|
2544
|
+
function radius(r) {
|
|
2545
|
+
if (!Number.isFinite(r) || r < 0)
|
|
2546
|
+
throw new RangeError("Radius must be finite and nonnegative");
|
|
2547
|
+
}
|
|
2548
|
+
function spheresIntersect(a, ar, b, br) {
|
|
2549
|
+
point(a, 3);
|
|
2550
|
+
point(b, 3);
|
|
2551
|
+
radius(ar);
|
|
2552
|
+
radius(br);
|
|
2553
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
|
|
2554
|
+
}
|
|
2555
|
+
function boundsIntersectSphere(bounds, center, r) {
|
|
2556
|
+
radius(r);
|
|
2557
|
+
const closest = clampPointToBounds(bounds, center);
|
|
2558
|
+
return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
|
|
2559
|
+
}
|
|
2560
|
+
//# sourceMappingURL=index.cjs.map
|