@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.2
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 +2124 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +31 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +25 -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.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/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 +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 +6105 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -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.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 +14 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +13 -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 +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/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 +12 -4
- package/src/culling/constants.ts +6 -0
- package/src/culling/index.ts +55 -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 +332 -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 +179 -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/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 +42 -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 +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/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,140 @@
|
|
|
1
|
+
/** Qualify a conservative subset of 3D mesh morphs, without time sampling.
|
|
2
|
+
* Input is an oriented, connected triangulated disk. Both endpoints share indices.
|
|
3
|
+
* Every triangle must retain positive XY orientation and the boundary must stay
|
|
4
|
+
* convex throughout linear vertex motion. Quadratic extrema test the full [0,1].
|
|
5
|
+
* This excludes holes, folded surfaces, most global globe meshes and curved vertex
|
|
6
|
+
* trajectories. It qualifies the piecewise-linear mesh, not its underlying smooth
|
|
7
|
+
* projection or a camera's approximation error. Floating-point margins reject
|
|
8
|
+
* near-degeneracy; this is not a formal interval-arithmetic certificate.
|
|
9
|
+
*/
|
|
10
|
+
export function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
|
|
11
|
+
const from = Array.from(mesh.positions), to = Array.from(targetPositions), indices = Array.from(mesh.indices), count = from.length / 3, maxChecks = options.maxChecks ?? 1000000;
|
|
12
|
+
if (!from.length ||
|
|
13
|
+
from.length % 3 ||
|
|
14
|
+
to.length !== from.length ||
|
|
15
|
+
!indices.length ||
|
|
16
|
+
indices.length % 3 ||
|
|
17
|
+
!from.every(Number.isFinite) ||
|
|
18
|
+
!to.every(Number.isFinite) ||
|
|
19
|
+
!indices.every(i => Number.isSafeInteger(i) && i >= 0 && i < count) ||
|
|
20
|
+
!Number.isSafeInteger(maxChecks) ||
|
|
21
|
+
maxChecks < 0)
|
|
22
|
+
throw new RangeError('Invalid surface transition mesh or budget');
|
|
23
|
+
let scale = 0;
|
|
24
|
+
for (const positions of [from, to])
|
|
25
|
+
for (let i = 0; i < indices.length; i += 3)
|
|
26
|
+
for (let j = 0; j < 3; j++) {
|
|
27
|
+
const a = indices[i + j] * 3, b = indices[i + ((j + 1) % 3)] * 3;
|
|
28
|
+
scale = Math.max(scale, Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1]));
|
|
29
|
+
}
|
|
30
|
+
const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
|
|
31
|
+
if (!Number.isFinite(margin) || margin <= 0)
|
|
32
|
+
throw new RangeError('Expected positive finite area margin');
|
|
33
|
+
let checks = 0;
|
|
34
|
+
const tick = () => {
|
|
35
|
+
if (++checks > maxChecks)
|
|
36
|
+
throw new RangeError('Surface qualification exceeded maxChecks');
|
|
37
|
+
};
|
|
38
|
+
const edges = new Map(), used = new Set(indices);
|
|
39
|
+
let minimum = Infinity;
|
|
40
|
+
const orientation = (a, b, c, t) => {
|
|
41
|
+
// Interpolate relative edges, avoiding cancellation from translating a patch
|
|
42
|
+
// across large world-coordinate origins before subtracting vertex positions.
|
|
43
|
+
const edge = (v, k) => (from[3 * v + k] - from[3 * a + k]) * (1 - t) + (to[3 * v + k] - to[3 * a + k]) * t;
|
|
44
|
+
return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
|
|
45
|
+
};
|
|
46
|
+
const minimumOrientation = (a, b, c) => {
|
|
47
|
+
tick();
|
|
48
|
+
return quadraticMinimum(t => orientation(a, b, c, t));
|
|
49
|
+
};
|
|
50
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
51
|
+
const tri = indices.slice(i, i + 3);
|
|
52
|
+
const area = minimumOrientation(tri[0], tri[1], tri[2]);
|
|
53
|
+
if (area < margin)
|
|
54
|
+
throw new RangeError('Triangle collapses or reverses during transition');
|
|
55
|
+
minimum = Math.min(minimum, area);
|
|
56
|
+
for (let j = 0; j < 3; j++) {
|
|
57
|
+
const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
|
|
58
|
+
if (edge) {
|
|
59
|
+
if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
|
|
60
|
+
throw new RangeError('Expected oriented manifold edges');
|
|
61
|
+
edge.faces++;
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
edges.set(key, { a, b, faces: 1 });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const next = new Map();
|
|
68
|
+
for (const edge of edges.values())
|
|
69
|
+
if (edge.faces === 1) {
|
|
70
|
+
if (next.has(edge.a))
|
|
71
|
+
throw new RangeError('Nonmanifold boundary');
|
|
72
|
+
next.set(edge.a, edge.b);
|
|
73
|
+
}
|
|
74
|
+
if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
|
|
75
|
+
throw new RangeError('Expected a triangulated disk without unused vertices');
|
|
76
|
+
const start = next.keys().next().value, boundary = [];
|
|
77
|
+
const visitedBoundary = new Set();
|
|
78
|
+
let v = start;
|
|
79
|
+
do {
|
|
80
|
+
if (visitedBoundary.has(v) || !next.has(v))
|
|
81
|
+
throw new RangeError('Expected one boundary cycle');
|
|
82
|
+
visitedBoundary.add(v);
|
|
83
|
+
boundary.push(v);
|
|
84
|
+
v = next.get(v);
|
|
85
|
+
} while (v !== start);
|
|
86
|
+
if (boundary.length !== next.size)
|
|
87
|
+
throw new RangeError('Multiple boundary cycles');
|
|
88
|
+
// Every boundary vertex stays left of each directed support edge. This allows
|
|
89
|
+
// collinear refinement vertices while rejecting a nonconvex or crossing outline.
|
|
90
|
+
for (let i = 0; i < boundary.length; i++) {
|
|
91
|
+
const a = boundary[i], b = boundary[(i + 1) % boundary.length];
|
|
92
|
+
// Distinct boundary vertices rule out multiple winding of a convex outline
|
|
93
|
+
// (a locally positive double-cover fan would otherwise pass support tests).
|
|
94
|
+
for (let j = i + 1; j < boundary.length; j++) {
|
|
95
|
+
tick();
|
|
96
|
+
const c = boundary[j];
|
|
97
|
+
const separation = quadraticMinimum(t => {
|
|
98
|
+
const dx = (from[3 * c] - from[3 * a]) * (1 - t) + (to[3 * c] - to[3 * a]) * t, dy = (from[3 * c + 1] - from[3 * a + 1]) * (1 - t) + (to[3 * c + 1] - to[3 * a + 1]) * t;
|
|
99
|
+
return dx * dx + dy * dy;
|
|
100
|
+
});
|
|
101
|
+
if (separation < margin)
|
|
102
|
+
throw new RangeError('Boundary vertices meet during transition');
|
|
103
|
+
}
|
|
104
|
+
for (const c of boundary)
|
|
105
|
+
if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
|
|
106
|
+
throw new RangeError('Boundary is not convex throughout transition');
|
|
107
|
+
}
|
|
108
|
+
// Euler characteristic plus one boundary is insufficient if a closed component
|
|
109
|
+
// is present. Explicitly require connectivity of the vertex graph.
|
|
110
|
+
const neighbors = Array.from({ length: count }, () => []);
|
|
111
|
+
for (const { a, b } of edges.values()) {
|
|
112
|
+
neighbors[a].push(b);
|
|
113
|
+
neighbors[b].push(a);
|
|
114
|
+
}
|
|
115
|
+
const seen = new Set([start]), queue = [start];
|
|
116
|
+
for (let i = 0; i < queue.length; i++)
|
|
117
|
+
for (const n of neighbors[queue[i]])
|
|
118
|
+
if (!seen.has(n)) {
|
|
119
|
+
seen.add(n);
|
|
120
|
+
queue.push(n);
|
|
121
|
+
}
|
|
122
|
+
if (seen.size !== count)
|
|
123
|
+
throw new RangeError('Disconnected surface mesh');
|
|
124
|
+
return {
|
|
125
|
+
scope: 'convex-xy-disk-linear',
|
|
126
|
+
minimumProjectedDoubleArea: minimum,
|
|
127
|
+
boundary: new Uint32Array(boundary)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function quadraticMinimum(value) {
|
|
131
|
+
const f = value(0), g = value(1), h = value(0.5), a = 2 * (f + g - 2 * h), b = g - f - a;
|
|
132
|
+
if (![f, g, h, a, b].every(Number.isFinite))
|
|
133
|
+
throw new RangeError('Nonfinite surface orientation polynomial');
|
|
134
|
+
const t = a > 0 ? -b / (2 * a) : -1;
|
|
135
|
+
const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
|
|
136
|
+
if (!Number.isFinite(result))
|
|
137
|
+
throw new RangeError('Nonfinite surface orientation');
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=qualify-surface-transition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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AC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;QACzC,MAAM,IAAI,UAAU,CAAC,0CAA0C,CAAC,CAAC;IACnE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAC;IACpF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Decodes a packed RGB565 value into 8-bit RGB components. */
|
|
2
|
+
export declare function decodeRGB565(rgb565: number, target?: number[]): number[];
|
|
3
|
+
/** Encodes 8-bit RGB components into a packed RGB565 value. */
|
|
4
|
+
export declare function encodeRGB565(rgb: ArrayLike<number>): number;
|
|
5
|
+
//# sourceMappingURL=rgb565.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb565.d.ts","sourceRoot":"","sources":["../../src/utils/rgb565.ts"],"names":[],"mappings":"AAIA,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,EAAc,GAAG,MAAM,EAAE,CAQnF;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAK3D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Decodes a packed RGB565 value into 8-bit RGB components. */
|
|
5
|
+
export function decodeRGB565(rgb565, target = [0, 0, 0]) {
|
|
6
|
+
const red = (rgb565 >> 11) & 31;
|
|
7
|
+
const green = (rgb565 >> 5) & 63;
|
|
8
|
+
const blue = rgb565 & 31;
|
|
9
|
+
target[0] = (red << 3) | (red >> 2);
|
|
10
|
+
target[1] = (green << 2) | (green >> 4);
|
|
11
|
+
target[2] = (blue << 3) | (blue >> 2);
|
|
12
|
+
return target;
|
|
13
|
+
}
|
|
14
|
+
/** Encodes 8-bit RGB components into a packed RGB565 value. */
|
|
15
|
+
export function encodeRGB565(rgb) {
|
|
16
|
+
const red = Math.round(clampByte(rgb[0] ?? 0) * (31 / 255));
|
|
17
|
+
const green = Math.round(clampByte(rgb[1] ?? 0) * (63 / 255));
|
|
18
|
+
const blue = Math.round(clampByte(rgb[2] ?? 0) * (31 / 255));
|
|
19
|
+
return (red << 11) | (green << 5) | blue;
|
|
20
|
+
}
|
|
21
|
+
function clampByte(value) {
|
|
22
|
+
return Math.max(0, Math.min(255, value));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=rgb565.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgb565.js","sourceRoot":"","sources":["../../src/utils/rgb565.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,SAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACvE,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,K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AC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/utils/typed-array-utils.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,SAAS,eAAe,EAAO,GAAG,UAAU,CAUrF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Concatenates the visible bytes of multiple typed-array or DataView instances. */
|
|
5
|
+
export function concatTypedArrays(arrays = []) {
|
|
6
|
+
const byteLength = arrays.reduce((length, array) => length + array.byteLength, 0);
|
|
7
|
+
const result = new Uint8Array(byteLength);
|
|
8
|
+
let byteOffset = 0;
|
|
9
|
+
for (const array of arrays) {
|
|
10
|
+
const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
11
|
+
result.set(bytes, byteOffset);
|
|
12
|
+
byteOffset += bytes.byteLength;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=typed-array-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-array-utils.js","sourceRoot":"","sources":["../../src/utils/typed-array-utils.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,oFAAoF;AACpF,MAAM,UAAU,iBAAiB,CAAC,SAAqC,EAAE;IACvE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAC/E,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAC9B,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "5.0.0-
|
|
9
|
+
"version": "5.0.0-beta.2",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"geometry",
|
|
12
12
|
"gltf",
|
|
@@ -27,14 +27,22 @@
|
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"import": "./dist/index.js",
|
|
29
29
|
"require": "./dist/index.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./culling": {
|
|
32
|
+
"types": "./dist/culling/index.d.ts",
|
|
33
|
+
"import": "./dist/culling/index.js",
|
|
34
|
+
"require": "./dist/culling/index.cjs"
|
|
30
35
|
}
|
|
31
36
|
},
|
|
32
37
|
"files": [
|
|
33
38
|
"dist",
|
|
34
|
-
"src"
|
|
39
|
+
"src",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"THIRD-PARTY-NOTICES.md"
|
|
35
42
|
],
|
|
36
43
|
"dependencies": {
|
|
37
|
-
"@math.gl/
|
|
44
|
+
"@math.gl/core": "5.0.0-beta.2"
|
|
38
45
|
},
|
|
39
|
-
"
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"gitHead": "506f4e5a18aec8d416b06ca5730f5f33b7926dfc"
|
|
40
48
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export type {CullingResult} from './constants';
|
|
6
|
+
|
|
7
|
+
export {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';
|
|
8
|
+
export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
|
|
9
|
+
export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
|
|
10
|
+
export {CullingVolume} from './lib/culling-volume';
|
|
11
|
+
export {Plane} from './lib/plane';
|
|
12
|
+
export {Ray} from './lib/ray';
|
|
13
|
+
|
|
14
|
+
export type {ImplicitShape, RayIntersection} from './lib/shapes/implicit-shape';
|
|
15
|
+
export {BoxShape} from './lib/shapes/box-shape';
|
|
16
|
+
export type {BoxShapeProps} from './lib/shapes/box-shape';
|
|
17
|
+
export {CapsuleShape} from './lib/shapes/capsule-shape';
|
|
18
|
+
export type {CapsuleShapeProps} from './lib/shapes/capsule-shape';
|
|
19
|
+
export {CylinderShape} from './lib/shapes/cylinder-shape';
|
|
20
|
+
export type {CylinderShapeProps} from './lib/shapes/cylinder-shape';
|
|
21
|
+
export {PlaneShape} from './lib/shapes/plane-shape';
|
|
22
|
+
export type {PlaneShapeProps} from './lib/shapes/plane-shape';
|
|
23
|
+
export {SphereShape} from './lib/shapes/sphere-shape';
|
|
24
|
+
export type {SphereShapeProps} from './lib/shapes/sphere-shape';
|
|
25
|
+
|
|
26
|
+
export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
|
|
27
|
+
export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
|
|
28
|
+
|
|
29
|
+
export {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';
|
|
30
|
+
export {
|
|
31
|
+
makeAxisAlignedBoundingBoxFromPoints,
|
|
32
|
+
makeOrientedBoundingBoxFromPoints
|
|
33
|
+
} from './lib/algorithms/bounding-box-from-points';
|
|
34
|
+
export {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';
|
|
35
|
+
|
|
36
|
+
export {intersectRayBounds, intersectRayTriangle, getClosestPointOnTriangle} from './queries';
|
|
37
|
+
export type {QueryPoint, TriangleRayHit} from './queries';
|
|
38
|
+
|
|
39
|
+
export {intersectOrientedBoxes2D} from './oriented-box-2d';
|
|
40
|
+
export type {OrientedBox2D} from './oriented-box-2d';
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
getOrientedBoundingBoxQuaternion,
|
|
44
|
+
makeOrientedBoundingBoxFromQuaternion
|
|
45
|
+
} from './lib/algorithms/oriented-bounding-box-quaternion';
|
|
46
|
+
|
|
47
|
+
// Public named exports. Implementations remain in independently tree-shakable files.
|
|
48
|
+
export {
|
|
49
|
+
validateQueryPoint,
|
|
50
|
+
validateQueryDistance,
|
|
51
|
+
normalizeQueryDirection,
|
|
52
|
+
getClosestPointsOnSegments,
|
|
53
|
+
getClosestPointsSegmentTriangle
|
|
54
|
+
} from './queries';
|
|
55
|
+
export type {SegmentClosestPoints, SegmentTriangleClosestPoints} from './queries';
|
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
|
|
7
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
8
|
+
// See ../../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
|
+
|
|
10
|
+
import {Vector3, Matrix3} from '@math.gl/core';
|
|
11
|
+
import {computeEigenDecomposition} from './compute-eigen-decomposition';
|
|
12
|
+
import {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';
|
|
13
|
+
import {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
|
|
14
|
+
|
|
15
|
+
const scratchVector2 = new Vector3();
|
|
16
|
+
|
|
17
|
+
const scratchVector3 = new Vector3();
|
|
18
|
+
|
|
19
|
+
const scratchVector4 = new Vector3();
|
|
20
|
+
|
|
21
|
+
const scratchVector5 = new Vector3();
|
|
22
|
+
|
|
23
|
+
const scratchVector6 = new Vector3();
|
|
24
|
+
|
|
25
|
+
const scratchCovarianceResult = new Matrix3();
|
|
26
|
+
|
|
27
|
+
const scratchEigenResult = {
|
|
28
|
+
diagonal: new Matrix3(),
|
|
29
|
+
unitary: new Matrix3()
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Computes an instance of an OrientedBoundingBox of the given positions.
|
|
34
|
+
*
|
|
35
|
+
* This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
|
|
36
|
+
* Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
|
|
37
|
+
*/
|
|
38
|
+
/* eslint-disable max-statements */
|
|
39
|
+
export function makeOrientedBoundingBoxFromPoints(
|
|
40
|
+
positions: number[][],
|
|
41
|
+
result: OrientedBoundingBox = new OrientedBoundingBox()
|
|
42
|
+
): OrientedBoundingBox {
|
|
43
|
+
if (!positions || positions.length === 0) {
|
|
44
|
+
result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
45
|
+
result.center = new Vector3();
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const length = positions.length;
|
|
50
|
+
const meanPoint = new Vector3(0, 0, 0);
|
|
51
|
+
for (const position of positions) {
|
|
52
|
+
meanPoint.add(position);
|
|
53
|
+
}
|
|
54
|
+
const invLength = 1.0 / length;
|
|
55
|
+
meanPoint.multiplyByScalar(invLength);
|
|
56
|
+
|
|
57
|
+
let exx = 0.0;
|
|
58
|
+
let exy = 0.0;
|
|
59
|
+
let exz = 0.0;
|
|
60
|
+
let eyy = 0.0;
|
|
61
|
+
let eyz = 0.0;
|
|
62
|
+
let ezz = 0.0;
|
|
63
|
+
|
|
64
|
+
for (const position of positions) {
|
|
65
|
+
const p = scratchVector2.copy(position).subtract(meanPoint);
|
|
66
|
+
exx += p.x * p.x;
|
|
67
|
+
exy += p.x * p.y;
|
|
68
|
+
exz += p.x * p.z;
|
|
69
|
+
eyy += p.y * p.y;
|
|
70
|
+
eyz += p.y * p.z;
|
|
71
|
+
ezz += p.z * p.z;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exx *= invLength;
|
|
75
|
+
exy *= invLength;
|
|
76
|
+
exz *= invLength;
|
|
77
|
+
eyy *= invLength;
|
|
78
|
+
eyz *= invLength;
|
|
79
|
+
ezz *= invLength;
|
|
80
|
+
|
|
81
|
+
const covarianceMatrix = scratchCovarianceResult;
|
|
82
|
+
covarianceMatrix[0] = exx;
|
|
83
|
+
covarianceMatrix[1] = exy;
|
|
84
|
+
covarianceMatrix[2] = exz;
|
|
85
|
+
covarianceMatrix[3] = exy;
|
|
86
|
+
covarianceMatrix[4] = eyy;
|
|
87
|
+
covarianceMatrix[5] = eyz;
|
|
88
|
+
covarianceMatrix[6] = exz;
|
|
89
|
+
covarianceMatrix[7] = eyz;
|
|
90
|
+
covarianceMatrix[8] = ezz;
|
|
91
|
+
|
|
92
|
+
const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
|
|
93
|
+
const rotation = result.halfAxes.copy(unitary);
|
|
94
|
+
|
|
95
|
+
let v1 = rotation.getColumn(0, scratchVector4);
|
|
96
|
+
let v2 = rotation.getColumn(1, scratchVector5);
|
|
97
|
+
let v3 = rotation.getColumn(2, scratchVector6);
|
|
98
|
+
|
|
99
|
+
let u1 = -Number.MAX_VALUE;
|
|
100
|
+
let u2 = -Number.MAX_VALUE;
|
|
101
|
+
let u3 = -Number.MAX_VALUE;
|
|
102
|
+
let l1 = Number.MAX_VALUE;
|
|
103
|
+
let l2 = Number.MAX_VALUE;
|
|
104
|
+
let l3 = Number.MAX_VALUE;
|
|
105
|
+
|
|
106
|
+
for (const position of positions) {
|
|
107
|
+
scratchVector2.copy(position);
|
|
108
|
+
|
|
109
|
+
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
110
|
+
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
111
|
+
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
112
|
+
|
|
113
|
+
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
114
|
+
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
115
|
+
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
119
|
+
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
120
|
+
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
121
|
+
|
|
122
|
+
result.center.copy(v1).add(v2).add(v3);
|
|
123
|
+
|
|
124
|
+
const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
125
|
+
const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
126
|
+
result.halfAxes.multiplyRight(scaleMatrix);
|
|
127
|
+
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
|
|
133
|
+
* finding the points spaced the farthest apart on the x, y, and z axes.
|
|
134
|
+
*/
|
|
135
|
+
export function makeAxisAlignedBoundingBoxFromPoints(
|
|
136
|
+
positions: readonly number[][],
|
|
137
|
+
result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()
|
|
138
|
+
): AxisAlignedBoundingBox {
|
|
139
|
+
if (!positions || positions.length === 0) {
|
|
140
|
+
result.minimum.set(0, 0, 0);
|
|
141
|
+
result.maximum.set(0, 0, 0);
|
|
142
|
+
result.center.set(0, 0, 0);
|
|
143
|
+
result.halfDiagonal.set(0, 0, 0);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let minimumX = positions[0][0];
|
|
148
|
+
let minimumY = positions[0][1];
|
|
149
|
+
let minimumZ = positions[0][2];
|
|
150
|
+
|
|
151
|
+
let maximumX = positions[0][0];
|
|
152
|
+
let maximumY = positions[0][1];
|
|
153
|
+
let maximumZ = positions[0][2];
|
|
154
|
+
|
|
155
|
+
for (const p of positions) {
|
|
156
|
+
const x = p[0];
|
|
157
|
+
const y = p[1];
|
|
158
|
+
const z = p[2];
|
|
159
|
+
|
|
160
|
+
minimumX = Math.min(x, minimumX);
|
|
161
|
+
maximumX = Math.max(x, maximumX);
|
|
162
|
+
minimumY = Math.min(y, minimumY);
|
|
163
|
+
maximumY = Math.max(y, maximumY);
|
|
164
|
+
minimumZ = Math.min(z, minimumZ);
|
|
165
|
+
maximumZ = Math.max(z, maximumZ);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
169
|
+
result.maximum.set(maximumX, maximumY, maximumZ);
|
|
170
|
+
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
|
|
171
|
+
result.halfDiagonal.copy(result.maximum).subtract(result.center);
|
|
172
|
+
|
|
173
|
+
return result;
|
|
174
|
+
}
|