@math.gl/geometry 5.0.0-alpha.2 → 5.0.0-alpha.20
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 +16 -1
- package/THIRD-PARTY-NOTICES.md +18 -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/index.cjs +2014 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +29 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +23 -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 +116 -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 +46 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +126 -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 +13 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +30 -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.cjs +73 -0
- package/dist/culling/oriented-box-2d.cjs.map +6 -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.cjs +161 -0
- package/dist/culling/queries.cjs.map +6 -0
- package/dist/culling/queries.d.ts +20 -0
- package/dist/culling/queries.d.ts.map +1 -0
- package/dist/culling/queries.js +139 -0
- package/dist/culling/queries.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.cjs +293 -0
- package/dist/curves/index.cjs.map +6 -0
- package/dist/curves/index.d.ts +8 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +9 -0
- package/dist/curves/index.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 +290 -9
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -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/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.cjs +328 -0
- package/dist/parametric.cjs.map +6 -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/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 +627 -0
- package/dist/polygon/earcut.js.map +1 -0
- package/dist/polygon/index.cjs +1437 -0
- package/dist/polygon/index.cjs.map +6 -0
- package/dist/polygon/index.d.ts +12 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +12 -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/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 +68 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +228 -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.cjs +328 -0
- package/dist/spatial-index/box-index.cjs.map +6 -0
- package/dist/spatial-index/box-index.d.ts +65 -0
- package/dist/spatial-index/box-index.d.ts.map +1 -0
- package/dist/spatial-index/box-index.js +263 -0
- package/dist/spatial-index/box-index.js.map +1 -0
- package/dist/spatial-index/index.cjs +494 -0
- package/dist/spatial-index/index.cjs.map +6 -0
- package/dist/spatial-index/index.d.ts +5 -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 +53 -0
- package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
- package/dist/spatial-index/triangle-bvh.js +102 -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/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.cjs +965 -0
- package/dist/utils/index.cjs.map +6 -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.cjs +176 -0
- package/dist/utils/interpolate-packed-attributes.cjs.map +6 -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/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 +57 -4
- package/src/culling/constants.ts +6 -0
- package/src/culling/index.ts +45 -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 +153 -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 +163 -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 +33 -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 +155 -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 +15 -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 +10 -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/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/cut-by-grid.ts +313 -0
- package/src/polygon/cut-by-mercator-bounds.ts +204 -0
- package/src/polygon/earcut.ts +798 -0
- package/src/polygon/index.ts +35 -0
- package/src/polygon/lineclip.ts +218 -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 +322 -0
- package/src/polygon/utils.ts +50 -0
- package/src/spatial-index/box-index.ts +343 -0
- package/src/spatial-index/index.ts +18 -0
- package/src/spatial-index/triangle-bvh.ts +162 -0
- package/src/utils/attribute-compression.ts +234 -0
- package/src/utils/attribute-iterator.ts +28 -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/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Vector3, NumericArray } from '@math.gl/core';
|
|
2
|
+
import { Ray } from "./ray.js";
|
|
3
|
+
export declare class Plane {
|
|
4
|
+
readonly normal: Vector3;
|
|
5
|
+
distance: number;
|
|
6
|
+
constructor(normal?: Readonly<NumericArray>, distance?: number);
|
|
7
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
8
|
+
fromNormalDistance(normal: Readonly<NumericArray>, distance: number): this;
|
|
9
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
10
|
+
fromPointNormal(point: Readonly<NumericArray>, normal: Readonly<NumericArray>): this;
|
|
11
|
+
/** Creates a plane from the general equation */
|
|
12
|
+
fromCoefficients(a: number, b: number, c: number, d: number): this;
|
|
13
|
+
/** Duplicates a Plane instance. */
|
|
14
|
+
clone(): Plane;
|
|
15
|
+
/** Compares the provided Planes by normal and distance */
|
|
16
|
+
equals(right: Plane): boolean;
|
|
17
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
18
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
19
|
+
*/
|
|
20
|
+
getPointDistance(point: Readonly<NumericArray>): number;
|
|
21
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
22
|
+
transform(matrix4: Readonly<NumericArray>): this;
|
|
23
|
+
/** Projects a point onto the plane. */
|
|
24
|
+
projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;
|
|
25
|
+
projectPointOntoPlane(point: Readonly<NumericArray>, result?: readonly number[]): readonly number[];
|
|
26
|
+
/**
|
|
27
|
+
* Computes the intersection of a ray and this plane.
|
|
28
|
+
*
|
|
29
|
+
* @param {Ray} ray The ray.
|
|
30
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
31
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersection.
|
|
32
|
+
*/
|
|
33
|
+
intersectWithRay(ray: Ray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AAE,QAAQ,CAAC,YAAY,CAAC,EAC7B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE;IAWpB;;;;;;OAMG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAE,OAAuB,GAAG,OAAO,GAAG,SAAS;CAkBjF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
7
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
import { Vector3, equals, assert, _MathUtils } from '@math.gl/core';
|
|
10
|
+
const scratchPosition = new Vector3();
|
|
11
|
+
const scratchNormal = new Vector3();
|
|
12
|
+
// A plane in Hessian Normal Form
|
|
13
|
+
export class Plane {
|
|
14
|
+
constructor(normal = [0, 0, 1], distance = 0) {
|
|
15
|
+
this.normal = new Vector3();
|
|
16
|
+
this.distance = -0;
|
|
17
|
+
this.fromNormalDistance(normal, distance);
|
|
18
|
+
}
|
|
19
|
+
/** Creates a plane from a normal and a distance from the origin. */
|
|
20
|
+
fromNormalDistance(normal, distance) {
|
|
21
|
+
assert(Number.isFinite(distance));
|
|
22
|
+
this.normal.from(normal).normalize();
|
|
23
|
+
this.distance = distance;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/** Creates a plane from a normal and a point on the plane. */
|
|
27
|
+
fromPointNormal(point, normal) {
|
|
28
|
+
point = scratchPosition.from(point);
|
|
29
|
+
this.normal.from(normal).normalize();
|
|
30
|
+
const distance = -this.normal.dot(point);
|
|
31
|
+
this.distance = distance;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/** Creates a plane from the general equation */
|
|
35
|
+
fromCoefficients(a, b, c, d) {
|
|
36
|
+
this.normal.set(a, b, c);
|
|
37
|
+
assert(equals(this.normal.len(), 1));
|
|
38
|
+
this.distance = d;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/** Duplicates a Plane instance. */
|
|
42
|
+
clone() {
|
|
43
|
+
return new Plane(this.normal, this.distance);
|
|
44
|
+
}
|
|
45
|
+
/** Compares the provided Planes by normal and distance */
|
|
46
|
+
equals(right) {
|
|
47
|
+
return equals(this.distance, right.distance) && equals(this.normal, right.normal);
|
|
48
|
+
}
|
|
49
|
+
/** Computes the signed shortest distance of a point to a plane.
|
|
50
|
+
* The sign of the distance determines which side of the plane the point is on.
|
|
51
|
+
*/
|
|
52
|
+
getPointDistance(point) {
|
|
53
|
+
return this.normal.dot(point) + this.distance;
|
|
54
|
+
}
|
|
55
|
+
/** Transforms the plane by the given transformation matrix. */
|
|
56
|
+
transform(matrix4) {
|
|
57
|
+
const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
|
|
58
|
+
const point = this.normal.scale(-this.distance).transform(matrix4);
|
|
59
|
+
return this.fromPointNormal(point, normal);
|
|
60
|
+
}
|
|
61
|
+
projectPointOntoPlane(point, result = [0, 0, 0]) {
|
|
62
|
+
const scratchPoint = scratchPosition.from(point);
|
|
63
|
+
// projectedPoint = point - (normal.point + scale) * normal
|
|
64
|
+
const pointDistance = this.getPointDistance(scratchPoint);
|
|
65
|
+
const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
|
|
66
|
+
return scratchPoint.subtract(scaledNormal).to(result);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Computes the intersection of a ray and this plane.
|
|
70
|
+
*
|
|
71
|
+
* @param {Ray} ray The ray.
|
|
72
|
+
* @param {Vector3} [result] The object onto which to store the result.
|
|
73
|
+
* @returns {Vector3} The intersection point or undefined if there is no intersection.
|
|
74
|
+
*/
|
|
75
|
+
intersectWithRay(ray, result = new Vector3()) {
|
|
76
|
+
const origin = ray.origin;
|
|
77
|
+
const direction = ray.direction;
|
|
78
|
+
const normal = this.normal;
|
|
79
|
+
const denominator = normal.dot(direction);
|
|
80
|
+
if (Math.abs(denominator) < _MathUtils.EPSILON15) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const t = (-this.distance - normal.dot(origin)) / denominator;
|
|
84
|
+
if (t < 0) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return result.copy(direction).multiplyByScalar(t).add(origin);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=plane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane.js","sourceRoot":"","sources":["../../../src/culling/lib/plane.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oEAAoE;AACpE,4DAA4D;AAC5D,mHAAmH;AAEnH,2EAA2E;AAC3E,4EAA4E;AAE5E,oBAAoB;AACpB,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAgB,UAAU,EAAC,MAAM,eAAe,CAAC;AAGhF,MAAM,eAAe,GAAG,IAAI,OAAO,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,IAAI,OAAO,EAAE,CAAC;AAEpC,iCAAiC;AACjC,MAAM,OAAO,KAAK;IAIhB,YAAY,SAAiC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,WAAmB,CAAC;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,oEAAoE;IACpE,kBAAkB,CAAC,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AG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAE1C,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;YACjD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC;QAE9D,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACV,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Vector3 } from '@math.gl/core';
|
|
2
|
+
export declare class Ray {
|
|
3
|
+
origin: Vector3;
|
|
4
|
+
direction: Vector3;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
7
|
+
*
|
|
8
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
9
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
10
|
+
*/
|
|
11
|
+
constructor(origin?: Vector3, direction?: Vector3);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray.d.ts","sourceRoot":"","sources":["../../../src/culling/lib/ray.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAGtC,qBAAa,GAAG;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IAEnB;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO;CAUlD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
// This file is derived from the Cesium library under Apache 2 license
|
|
7
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
8
|
+
import { Vector3 } from '@math.gl/core';
|
|
9
|
+
/* Represents a ray that extends infinitely from the provided origin in the provided direction. */
|
|
10
|
+
export class Ray {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new ray that extends infinitely from the provided origin in the provided direction.
|
|
13
|
+
*
|
|
14
|
+
* @param [origin=Vector3] The origin of the ray.
|
|
15
|
+
* @param [direction=Vector3] The direction of the ray.
|
|
16
|
+
*/
|
|
17
|
+
constructor(origin, direction) {
|
|
18
|
+
if (origin)
|
|
19
|
+
origin = origin.clone();
|
|
20
|
+
else
|
|
21
|
+
origin = new Vector3();
|
|
22
|
+
if (direction)
|
|
23
|
+
direction = direction.clone().normalize();
|
|
24
|
+
else
|
|
25
|
+
direction = new Vector3();
|
|
26
|
+
this.origin = origin;
|
|
27
|
+
this.direction = direction;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=ray.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ray.js","sourceRoot":"","sources":["../../../src/culling/lib/ray.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oEAAoE;AACpE,4DAA4D;AAC5D,mHAAmH;AAEnH,sEAAsE;AACtE,4EAA4E;AAE5E,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,kGAAkG;AAClG,MAAM,OAAO,GAAG;IAId;;;;;OAKG;IACH,YAAY,MAAgB,EAAE,SAAmB;QAC/C,IAAI,MAAM;YAAE,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;;YAC/B,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAE5B,IAAI,SAAS;YAAE,SAAS,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,CAAC;;YACpD,SAAS,GAAG,IAAI,OAAO,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
|
|
2
|
+
export type BoxShapeProps = {
|
|
3
|
+
size?: readonly [number, number, number];
|
|
4
|
+
matrix?: readonly number[];
|
|
5
|
+
};
|
|
6
|
+
/** Analytic glTF box shape. */
|
|
7
|
+
export declare class BoxShape extends ImplicitShapeBase {
|
|
8
|
+
readonly type: "box";
|
|
9
|
+
readonly size: readonly [number, number, number];
|
|
10
|
+
private readonly halfSize;
|
|
11
|
+
constructor(props?: BoxShapeProps);
|
|
12
|
+
clone(): BoxShape;
|
|
13
|
+
equals(shape: ImplicitShape): boolean;
|
|
14
|
+
containsLocalPoint(point: readonly number[]): boolean;
|
|
15
|
+
distanceToLocalPoint(point: readonly number[]): number;
|
|
16
|
+
supportLocal(direction: readonly number[]): readonly number[];
|
|
17
|
+
intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=box-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box-shape.d.ts","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/box-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAC,4BAAyB;AAIlG,MAAM,MAAM,aAAa,GAAG;IAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAC,CAAC;AAEnG,+BAA+B;AAC/B,qBAAa,QAAS,SAAQ,iBAAiB;IAC7C,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAC/B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;gBAEjD,KAAK,GAAE,aAAkB;IAQrC,KAAK,IAAI,QAAQ;IAGR,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAO9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAGrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAGtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAG7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;CA+BpC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { ImplicitShapeBase } from "./implicit-shape.js";
|
|
5
|
+
const EPSILON = 1e-6;
|
|
6
|
+
/** Analytic glTF box shape. */
|
|
7
|
+
export class BoxShape extends ImplicitShapeBase {
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
super(props.matrix);
|
|
10
|
+
this.type = 'box';
|
|
11
|
+
this.size = props.size ? [...props.size] : [1, 1, 1];
|
|
12
|
+
if (this.size.some(value => !Number.isFinite(value) || value <= 0))
|
|
13
|
+
throw new Error('Box size values must be greater than zero');
|
|
14
|
+
this.halfSize = [this.size[0] / 2, this.size[1] / 2, this.size[2] / 2];
|
|
15
|
+
}
|
|
16
|
+
clone() {
|
|
17
|
+
return new BoxShape({ size: this.size, matrix: this.matrix });
|
|
18
|
+
}
|
|
19
|
+
equals(shape) {
|
|
20
|
+
return (shape instanceof BoxShape &&
|
|
21
|
+
super.equals(shape) &&
|
|
22
|
+
this.size.every((value, i) => value === shape.size[i]));
|
|
23
|
+
}
|
|
24
|
+
containsLocalPoint(point) {
|
|
25
|
+
return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
|
|
26
|
+
}
|
|
27
|
+
distanceToLocalPoint(point) {
|
|
28
|
+
return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
|
|
29
|
+
}
|
|
30
|
+
supportLocal(direction) {
|
|
31
|
+
return direction.map((value, i) => (value < 0 ? -this.halfSize[i] : this.halfSize[i]));
|
|
32
|
+
}
|
|
33
|
+
intersectLocalRay(origin, direction) {
|
|
34
|
+
let near = -Infinity;
|
|
35
|
+
let far = Infinity;
|
|
36
|
+
let nearAxis = 0;
|
|
37
|
+
let farAxis = 0;
|
|
38
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
39
|
+
if (Math.abs(direction[axis]) < 1e-15) {
|
|
40
|
+
if (Math.abs(origin[axis]) > this.halfSize[axis])
|
|
41
|
+
return undefined;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let t1 = (-this.halfSize[axis] - origin[axis]) / direction[axis];
|
|
45
|
+
let t2 = (this.halfSize[axis] - origin[axis]) / direction[axis];
|
|
46
|
+
if (t1 > t2)
|
|
47
|
+
[t1, t2] = [t2, t1];
|
|
48
|
+
if (t1 > near) {
|
|
49
|
+
near = t1;
|
|
50
|
+
nearAxis = axis;
|
|
51
|
+
}
|
|
52
|
+
if (t2 < far) {
|
|
53
|
+
far = t2;
|
|
54
|
+
farAxis = axis;
|
|
55
|
+
}
|
|
56
|
+
if (near > far)
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const distance = near >= 0 ? near : far;
|
|
60
|
+
if (distance < 0 || !Number.isFinite(distance))
|
|
61
|
+
return undefined;
|
|
62
|
+
const axis = near >= 0 ? nearAxis : farAxis;
|
|
63
|
+
const pointCoordinate = origin[axis] + distance * direction[axis];
|
|
64
|
+
const normal = [0, 0, 0];
|
|
65
|
+
normal[axis] = pointCoordinate < 0 ? -1 : 1;
|
|
66
|
+
return { distance, normal };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=box-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box-shape.js","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/box-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,iBAAiB,EAAgD,4BAAyB;AAElG,MAAM,OAAO,GAAG,IAAI,CAAC;AAIrB,+BAA+B;AAC/B,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAK7C,YAAY,QAAuB,EAAE;QACnC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QALb,SAAI,GAAG,KAAc,CAAC;QAM7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACrD,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,CAAC,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AG,GAAG,EAAE,CAAC;gBACT,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YACD,IAAI,IAAI,GAAG,GAAG;gBAAE,OAAO,SAAS,CAAC;QACnC,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QACxC,IAAI,QAAQ,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,SAAS,CAAC;QACjE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5C,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAClE,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
|
|
2
|
+
export type CapsuleShapeProps = {
|
|
3
|
+
height?: number;
|
|
4
|
+
radiusBottom?: number;
|
|
5
|
+
radiusTop?: number;
|
|
6
|
+
matrix?: readonly number[];
|
|
7
|
+
};
|
|
8
|
+
/** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
|
|
9
|
+
export declare class CapsuleShape extends ImplicitShapeBase {
|
|
10
|
+
readonly type: "capsule";
|
|
11
|
+
readonly height: number;
|
|
12
|
+
readonly radiusBottom: number;
|
|
13
|
+
readonly radiusTop: number;
|
|
14
|
+
constructor(props?: CapsuleShapeProps);
|
|
15
|
+
clone(): CapsuleShape;
|
|
16
|
+
equals(shape: ImplicitShape): boolean;
|
|
17
|
+
containsLocalPoint(point: readonly number[]): boolean;
|
|
18
|
+
distanceToLocalPoint(point: readonly number[]): number;
|
|
19
|
+
supportLocal(direction: readonly number[]): readonly number[];
|
|
20
|
+
intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
21
|
+
private getProfile;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=capsule-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule-shape.d.ts","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/capsule-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,iBAAiB,EAEjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,4BAAyB;AAI1B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,QAAQ,CAAC,IAAI,EAAG,SAAS,CAAU;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,GAAE,iBAAsB;IAazC,KAAK,IAAI,YAAY;IAQZ,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAS9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAgBrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAqCtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAe7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;IAwCnC,OAAO,CAAC,UAAU;CA4BnB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { closestDistanceToCircleArc2D, closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
|
|
5
|
+
const EPSILON = 1e-6;
|
|
6
|
+
/** Analytic glTF capsule: the convex hull of two spheres on the Y axis. */
|
|
7
|
+
export class CapsuleShape extends ImplicitShapeBase {
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
super(props.matrix);
|
|
10
|
+
this.type = 'capsule';
|
|
11
|
+
this.height = props.height ?? 1;
|
|
12
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
13
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
14
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
15
|
+
throw new Error('Capsule height must be greater than zero');
|
|
16
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
17
|
+
throw new Error('Capsule radii must be non-negative');
|
|
18
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
19
|
+
throw new Error('At least one capsule radius must be greater than zero');
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
return new CapsuleShape({
|
|
23
|
+
height: this.height,
|
|
24
|
+
radiusBottom: this.radiusBottom,
|
|
25
|
+
radiusTop: this.radiusTop,
|
|
26
|
+
matrix: this.matrix
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
equals(shape) {
|
|
30
|
+
return (shape instanceof CapsuleShape &&
|
|
31
|
+
super.equals(shape) &&
|
|
32
|
+
this.height === shape.height &&
|
|
33
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
34
|
+
this.radiusTop === shape.radiusTop);
|
|
35
|
+
}
|
|
36
|
+
containsLocalPoint(point) {
|
|
37
|
+
const profile = this.getProfile();
|
|
38
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
39
|
+
if (profile.sphere)
|
|
40
|
+
return (Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON);
|
|
41
|
+
if (point[1] < profile.bottom.y)
|
|
42
|
+
return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON;
|
|
43
|
+
if (point[1] > profile.top.y)
|
|
44
|
+
return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON;
|
|
45
|
+
const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
|
|
46
|
+
return (radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON);
|
|
47
|
+
}
|
|
48
|
+
distanceToLocalPoint(point) {
|
|
49
|
+
if (this.containsLocalPoint(point))
|
|
50
|
+
return 0;
|
|
51
|
+
const profile = this.getProfile();
|
|
52
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
53
|
+
if (profile.sphere)
|
|
54
|
+
return Math.max(0, Math.hypot(radial, point[1] - profile.sphere.center) - profile.sphere.radius);
|
|
55
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
56
|
+
const sideNormalY = -delta / this.height;
|
|
57
|
+
const bottomArc = closestDistanceToCircleArc2D(radial, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
|
|
58
|
+
const topArc = closestDistanceToCircleArc2D(radial, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
|
|
59
|
+
const side = closestDistanceToSegment2D(radial, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
|
|
60
|
+
return Math.min(bottomArc, topArc, side);
|
|
61
|
+
}
|
|
62
|
+
supportLocal(direction) {
|
|
63
|
+
const length = Math.hypot(...direction);
|
|
64
|
+
const unit = length ? direction.map(value => value / length) : [1, 0, 0];
|
|
65
|
+
const bottom = [
|
|
66
|
+
unit[0] * this.radiusBottom,
|
|
67
|
+
-this.height / 2 + unit[1] * this.radiusBottom,
|
|
68
|
+
unit[2] * this.radiusBottom
|
|
69
|
+
];
|
|
70
|
+
const top = [
|
|
71
|
+
unit[0] * this.radiusTop,
|
|
72
|
+
this.height / 2 + unit[1] * this.radiusTop,
|
|
73
|
+
unit[2] * this.radiusTop
|
|
74
|
+
];
|
|
75
|
+
return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
|
|
76
|
+
}
|
|
77
|
+
intersectLocalRay(origin, direction) {
|
|
78
|
+
const profile = this.getProfile();
|
|
79
|
+
if (profile.sphere)
|
|
80
|
+
return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
|
|
81
|
+
const candidates = [];
|
|
82
|
+
const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
|
|
83
|
+
const intercept = profile.bottom.radius - slope * profile.bottom.y;
|
|
84
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
85
|
+
const radialAlongRay = slope * direction[1];
|
|
86
|
+
for (const distance of solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
|
|
87
|
+
const y = origin[1] + distance * direction[1];
|
|
88
|
+
if (distance >= 0 && y >= profile.bottom.y - EPSILON && y <= profile.top.y + EPSILON) {
|
|
89
|
+
const x = origin[0] + distance * direction[0];
|
|
90
|
+
const z = origin[2] + distance * direction[2];
|
|
91
|
+
const radial = Math.hypot(x, z) || 1;
|
|
92
|
+
const normal = [x / radial, -slope, z / radial];
|
|
93
|
+
const length = Math.hypot(...normal);
|
|
94
|
+
candidates.push({ distance, normal: normal.map(value => value / length) });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
|
|
98
|
+
const y = origin[1] + bottomHit.distance * direction[1];
|
|
99
|
+
if (y <= profile.bottom.y + EPSILON)
|
|
100
|
+
candidates.push(bottomHit);
|
|
101
|
+
}
|
|
102
|
+
for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
|
|
103
|
+
const y = origin[1] + topHit.distance * direction[1];
|
|
104
|
+
if (y >= profile.top.y - EPSILON)
|
|
105
|
+
candidates.push(topHit);
|
|
106
|
+
}
|
|
107
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
108
|
+
}
|
|
109
|
+
getProfile() {
|
|
110
|
+
const delta = this.radiusTop - this.radiusBottom;
|
|
111
|
+
if (Math.abs(delta) >= this.height) {
|
|
112
|
+
const topWins = this.radiusTop >= this.radiusBottom;
|
|
113
|
+
return {
|
|
114
|
+
sphere: {
|
|
115
|
+
center: topWins ? this.height / 2 : -this.height / 2,
|
|
116
|
+
radius: topWins ? this.radiusTop : this.radiusBottom
|
|
117
|
+
},
|
|
118
|
+
bottom: { radius: 0, y: 0 },
|
|
119
|
+
top: { radius: 0, y: 0 }
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const sinSlope = delta / this.height;
|
|
123
|
+
const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
|
|
124
|
+
const normalY = -sinSlope;
|
|
125
|
+
return {
|
|
126
|
+
bottom: {
|
|
127
|
+
radius: this.radiusBottom * radialNormal,
|
|
128
|
+
y: -this.height / 2 + this.radiusBottom * normalY
|
|
129
|
+
},
|
|
130
|
+
top: { radius: this.radiusTop * radialNormal, y: this.height / 2 + this.radiusTop * normalY }
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function intersectSphere(origin, direction, centerY, radius) {
|
|
135
|
+
return intersectSphereRoots(origin, direction, centerY, radius)[0];
|
|
136
|
+
}
|
|
137
|
+
function intersectSphereRoots(origin, direction, centerY, radius) {
|
|
138
|
+
if (radius === 0)
|
|
139
|
+
return [];
|
|
140
|
+
const relative = [origin[0], origin[1] - centerY, origin[2]];
|
|
141
|
+
return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius)
|
|
142
|
+
.filter(distance => distance >= 0)
|
|
143
|
+
.map(distance => ({
|
|
144
|
+
distance,
|
|
145
|
+
normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
function dot(a, b) {
|
|
149
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=capsule-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capsule-shape.js","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/capsule-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,2EAA2E;AAC3E,MAAM,OAAO,YAAa,SAAQ,iBAAiB;IAMjD,YAAY,QAA2B,EAAE;QACvC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,SAAkB,CAAC;QAOjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,C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@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ImplicitShapeBase, type ImplicitShape, type LocalRayIntersection } from "./implicit-shape.js";
|
|
2
|
+
export type CylinderShapeProps = {
|
|
3
|
+
height?: number;
|
|
4
|
+
radiusBottom?: number;
|
|
5
|
+
radiusTop?: number;
|
|
6
|
+
matrix?: readonly number[];
|
|
7
|
+
};
|
|
8
|
+
/** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
|
|
9
|
+
export declare class CylinderShape extends ImplicitShapeBase {
|
|
10
|
+
readonly type: "cylinder";
|
|
11
|
+
readonly height: number;
|
|
12
|
+
readonly radiusBottom: number;
|
|
13
|
+
readonly radiusTop: number;
|
|
14
|
+
constructor(props?: CylinderShapeProps);
|
|
15
|
+
clone(): CylinderShape;
|
|
16
|
+
equals(shape: ImplicitShape): boolean;
|
|
17
|
+
containsLocalPoint(point: readonly number[]): boolean;
|
|
18
|
+
distanceToLocalPoint(point: readonly number[]): number;
|
|
19
|
+
supportLocal(direction: readonly number[]): readonly number[];
|
|
20
|
+
intersectLocalRay(origin: readonly number[], direction: readonly number[]): LocalRayIntersection | undefined;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cylinder-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cylinder-shape.d.ts","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,iBAAiB,EAEjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,4BAAyB;AAI1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,mFAAmF;AACnF,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,QAAQ,CAAC,IAAI,EAAG,UAAU,CAAU;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,GAAE,kBAAuB;IAa1C,KAAK,IAAI,aAAa;IAQb,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAS9C,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAOrD,oBAAoB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAgBtD,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;IAW7D,iBAAiB,CACf,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,oBAAoB,GAAG,SAAS;CAqCpC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import { closestDistanceToSegment2D, ImplicitShapeBase, solveQuadratic } from "./implicit-shape.js";
|
|
5
|
+
const EPSILON = 1e-6;
|
|
6
|
+
/** Analytic closed, Y-aligned glTF cylinder shape, including tapered cylinders. */
|
|
7
|
+
export class CylinderShape extends ImplicitShapeBase {
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
super(props.matrix);
|
|
10
|
+
this.type = 'cylinder';
|
|
11
|
+
this.height = props.height ?? 2;
|
|
12
|
+
this.radiusBottom = props.radiusBottom ?? 0.5;
|
|
13
|
+
this.radiusTop = props.radiusTop ?? 0.5;
|
|
14
|
+
if (!Number.isFinite(this.height) || this.height <= 0)
|
|
15
|
+
throw new Error('Cylinder height must be greater than zero');
|
|
16
|
+
if (![this.radiusBottom, this.radiusTop].every(value => Number.isFinite(value) && value >= 0))
|
|
17
|
+
throw new Error('Cylinder radii must be non-negative');
|
|
18
|
+
if (this.radiusBottom === 0 && this.radiusTop === 0)
|
|
19
|
+
throw new Error('At least one cylinder radius must be greater than zero');
|
|
20
|
+
}
|
|
21
|
+
clone() {
|
|
22
|
+
return new CylinderShape({
|
|
23
|
+
height: this.height,
|
|
24
|
+
radiusBottom: this.radiusBottom,
|
|
25
|
+
radiusTop: this.radiusTop,
|
|
26
|
+
matrix: this.matrix
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
equals(shape) {
|
|
30
|
+
return (shape instanceof CylinderShape &&
|
|
31
|
+
super.equals(shape) &&
|
|
32
|
+
this.height === shape.height &&
|
|
33
|
+
this.radiusBottom === shape.radiusBottom &&
|
|
34
|
+
this.radiusTop === shape.radiusTop);
|
|
35
|
+
}
|
|
36
|
+
containsLocalPoint(point) {
|
|
37
|
+
const half = this.height / 2;
|
|
38
|
+
if (point[1] < -half - EPSILON || point[1] > half + EPSILON)
|
|
39
|
+
return false;
|
|
40
|
+
const t = (point[1] + half) / this.height;
|
|
41
|
+
const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
|
|
42
|
+
return Math.hypot(point[0], point[2]) <= radius + EPSILON;
|
|
43
|
+
}
|
|
44
|
+
distanceToLocalPoint(point) {
|
|
45
|
+
if (this.containsLocalPoint(point))
|
|
46
|
+
return 0;
|
|
47
|
+
const radial = Math.hypot(point[0], point[2]);
|
|
48
|
+
const half = this.height / 2;
|
|
49
|
+
const side = closestDistanceToSegment2D(radial, point[1], this.radiusBottom, -half, this.radiusTop, half);
|
|
50
|
+
const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
|
|
51
|
+
const top = closestDistanceToSegment2D(radial, point[1], 0, half, this.radiusTop, half);
|
|
52
|
+
return Math.min(side, bottom, top);
|
|
53
|
+
}
|
|
54
|
+
supportLocal(direction) {
|
|
55
|
+
const radialLength = Math.hypot(direction[0], direction[2]);
|
|
56
|
+
const x = radialLength ? direction[0] / radialLength : 1;
|
|
57
|
+
const z = radialLength ? direction[2] / radialLength : 0;
|
|
58
|
+
const half = this.height / 2;
|
|
59
|
+
const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
|
|
60
|
+
const topValue = radialLength * this.radiusTop + direction[1] * half;
|
|
61
|
+
return topValue >= bottomValue
|
|
62
|
+
? [x * this.radiusTop, half, z * this.radiusTop]
|
|
63
|
+
: [x * this.radiusBottom, -half, z * this.radiusBottom];
|
|
64
|
+
}
|
|
65
|
+
intersectLocalRay(origin, direction) {
|
|
66
|
+
const half = this.height / 2;
|
|
67
|
+
const slope = (this.radiusTop - this.radiusBottom) / this.height;
|
|
68
|
+
const intercept = (this.radiusTop + this.radiusBottom) / 2;
|
|
69
|
+
const radialAtOrigin = intercept + slope * origin[1];
|
|
70
|
+
const radialAlongRay = slope * direction[1];
|
|
71
|
+
const candidates = [];
|
|
72
|
+
const roots = solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
|
|
73
|
+
for (const distance of roots) {
|
|
74
|
+
const y = origin[1] + distance * direction[1];
|
|
75
|
+
if (distance >= 0 && y >= -half - EPSILON && y <= half + EPSILON) {
|
|
76
|
+
const x = origin[0] + distance * direction[0];
|
|
77
|
+
const z = origin[2] + distance * direction[2];
|
|
78
|
+
const radial = Math.hypot(x, z) || 1;
|
|
79
|
+
const normal = [x / radial, -slope, z / radial];
|
|
80
|
+
const length = Math.hypot(...normal);
|
|
81
|
+
candidates.push({ distance, normal: normal.map(value => value / length) });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Math.abs(direction[1]) > 1e-15) {
|
|
85
|
+
for (const [y, radius, normalY] of [
|
|
86
|
+
[-half, this.radiusBottom, -1],
|
|
87
|
+
[half, this.radiusTop, 1]
|
|
88
|
+
]) {
|
|
89
|
+
const distance = (y - origin[1]) / direction[1];
|
|
90
|
+
const x = origin[0] + distance * direction[0];
|
|
91
|
+
const z = origin[2] + distance * direction[2];
|
|
92
|
+
if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON)
|
|
93
|
+
candidates.push({ distance, normal: [0, normalY, 0] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return candidates.sort((a, b) => a.distance - b.distance)[0];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=cylinder-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cylinder-shape.js","sourceRoot":"","sources":["../../../../src/culling/lib/shapes/cylinder-shape.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EAGf,4BAAyB;AAE1B,MAAM,OAAO,GAAG,IAAI,CAAC;AASrB,mFAAmF;AACnF,MAAM,OAAO,aAAc,SAAQ,iBAAiB;IAMlD,YAAY,QAA4B,EAAE;QACxC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QANb,SAAI,GAAG,UAAmB,CAAC;QAOlC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,GAAG,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC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