@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +97 -49
- package/README.md +77 -1
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/color/color-lut-types.d.ts +16 -0
- package/dist/color/color-lut-types.d.ts.map +1 -0
- package/dist/color/color-lut-types.js +5 -0
- package/dist/color/color-lut-types.js.map +1 -0
- package/dist/color/index.cjs +132 -0
- package/dist/color/index.cjs.map +6 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/sample-lut.d.ts +13 -0
- package/dist/color/sample-lut.d.ts.map +1 -0
- package/dist/color/sample-lut.js +132 -0
- package/dist/color/sample-lut.js.map +1 -0
- package/dist/culling/bounds.d.ts +20 -0
- package/dist/culling/bounds.d.ts.map +1 -0
- package/dist/culling/bounds.js +121 -0
- package/dist/culling/bounds.js.map +1 -0
- package/dist/culling/constants.d.ts +3 -0
- package/dist/culling/constants.d.ts.map +1 -0
- package/dist/culling/constants.js +5 -0
- package/dist/culling/constants.js.map +1 -0
- package/dist/culling/frustum-planes.d.ts +5 -0
- package/dist/culling/frustum-planes.d.ts.map +1 -0
- package/dist/culling/frustum-planes.js +37 -0
- package/dist/culling/frustum-planes.js.map +1 -0
- package/dist/culling/geometric-queries.d.ts +34 -0
- package/dist/culling/geometric-queries.d.ts.map +1 -0
- package/dist/culling/geometric-queries.js +208 -0
- package/dist/culling/geometric-queries.js.map +1 -0
- package/dist/culling/index.cjs +2560 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +37 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +29 -0
- package/dist/culling/index.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +133 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/culling/lib/culling-volume.d.ts +49 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +133 -0
- package/dist/culling/lib/culling-volume.js.map +1 -0
- package/dist/culling/lib/perspective-frustum.d.ts +153 -0
- package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-frustum.js +191 -0
- package/dist/culling/lib/perspective-frustum.js.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
- package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/culling/lib/plane.d.ts +35 -0
- package/dist/culling/lib/plane.d.ts.map +1 -0
- package/dist/culling/lib/plane.js +90 -0
- package/dist/culling/lib/plane.js.map +1 -0
- package/dist/culling/lib/ray.d.ts +18 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +51 -0
- package/dist/culling/lib/ray.js.map +1 -0
- package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
- package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/box-shape.js +69 -0
- package/dist/culling/lib/shapes/box-shape.js.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.js +151 -0
- package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
- package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.js +142 -0
- package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.js +71 -0
- package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.js +43 -0
- package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
- package/dist/culling/oriented-box-2d.d.ts +22 -0
- package/dist/culling/oriented-box-2d.d.ts.map +1 -0
- package/dist/culling/oriented-box-2d.js +86 -0
- package/dist/culling/oriented-box-2d.js.map +1 -0
- package/dist/culling/queries.d.ts +44 -0
- package/dist/culling/queries.d.ts.map +1 -0
- package/dist/culling/queries.js +259 -0
- package/dist/culling/queries.js.map +1 -0
- package/dist/culling/screen-ray.d.ts +22 -0
- package/dist/culling/screen-ray.d.ts.map +1 -0
- package/dist/culling/screen-ray.js +55 -0
- package/dist/culling/screen-ray.js.map +1 -0
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/bezier-curves.d.ts +18 -0
- package/dist/curves/bezier-curves.d.ts.map +1 -0
- package/dist/curves/bezier-curves.js +54 -0
- package/dist/curves/bezier-curves.js.map +1 -0
- package/dist/curves/catmull-rom-curve.d.ts +15 -0
- package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
- package/dist/curves/catmull-rom-curve.js +77 -0
- package/dist/curves/catmull-rom-curve.js.map +1 -0
- package/dist/curves/curve-arc-length.d.ts +17 -0
- package/dist/curves/curve-arc-length.d.ts.map +1 -0
- package/dist/curves/curve-arc-length.js +58 -0
- package/dist/curves/curve-arc-length.js.map +1 -0
- package/dist/curves/curve.d.ts +23 -0
- package/dist/curves/curve.d.ts.map +1 -0
- package/dist/curves/curve.js +77 -0
- package/dist/curves/curve.js.map +1 -0
- package/dist/curves/hermite-curve.d.ts +9 -0
- package/dist/curves/hermite-curve.d.ts.map +1 -0
- package/dist/curves/hermite-curve.js +24 -0
- package/dist/curves/hermite-curve.js.map +1 -0
- package/dist/curves/index.d.ts +12 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +11 -0
- package/dist/curves/index.js.map +1 -0
- package/dist/curves/parallel-transport.d.ts +12 -0
- package/dist/curves/parallel-transport.d.ts.map +1 -0
- package/dist/curves/parallel-transport.js +83 -0
- package/dist/curves/parallel-transport.js.map +1 -0
- package/dist/geometries/box-geometry.js +1 -1
- package/dist/geometries/box-geometry.js.map +1 -1
- package/dist/geometries/capsule-geometry.js +1 -1
- package/dist/geometries/capsule-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/geometry-helpers.js +1 -1
- package/dist/geometries/geometry-helpers.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
- package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
- package/dist/geometries/primitive-mesh-builder.js +74 -0
- package/dist/geometries/primitive-mesh-builder.js.map +1 -0
- package/dist/geometries/prism-geometry.d.ts +13 -0
- package/dist/geometries/prism-geometry.d.ts.map +1 -0
- package/dist/geometries/prism-geometry.js +34 -0
- package/dist/geometries/prism-geometry.js.map +1 -0
- package/dist/geometries/ring-geometry.d.ts +15 -0
- package/dist/geometries/ring-geometry.d.ts.map +1 -0
- package/dist/geometries/ring-geometry.js +64 -0
- package/dist/geometries/ring-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/surface-of-revolution.js +1 -1
- package/dist/geometries/surface-of-revolution.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +1 -1
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/index.cjs +6993 -37
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/geometry-utils.js +1 -1
- package/dist/lib/geometry-utils.js.map +1 -1
- package/dist/lib/geometry.d.ts +1 -1
- package/dist/lib/geometry.d.ts.map +1 -1
- package/dist/lib/geometry.js +1 -1
- package/dist/lib/geometry.js.map +1 -1
- package/dist/lib/hinge-tree.d.ts +33 -0
- package/dist/lib/hinge-tree.d.ts.map +1 -0
- package/dist/lib/hinge-tree.js +144 -0
- package/dist/lib/hinge-tree.js.map +1 -0
- package/dist/lighting/index.cjs +175 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +5 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lighting-types.d.ts +16 -0
- package/dist/lighting/lighting-types.d.ts.map +1 -0
- package/dist/lighting/lighting-types.js +5 -0
- package/dist/lighting/lighting-types.js.map +1 -0
- package/dist/lighting/photometry.d.ts +36 -0
- package/dist/lighting/photometry.d.ts.map +1 -0
- package/dist/lighting/photometry.js +181 -0
- package/dist/lighting/photometry.js.map +1 -0
- package/dist/parametric/lathe-geometry.d.ts +14 -0
- package/dist/parametric/lathe-geometry.d.ts.map +1 -0
- package/dist/parametric/lathe-geometry.js +48 -0
- package/dist/parametric/lathe-geometry.js.map +1 -0
- package/dist/parametric/parametric-geometry.d.ts +20 -0
- package/dist/parametric/parametric-geometry.d.ts.map +1 -0
- package/dist/parametric/parametric-geometry.js +88 -0
- package/dist/parametric/parametric-geometry.js.map +1 -0
- package/dist/parametric/torus-geometry.d.ts +19 -0
- package/dist/parametric/torus-geometry.d.ts.map +1 -0
- package/dist/parametric/torus-geometry.js +89 -0
- package/dist/parametric/torus-geometry.js.map +1 -0
- package/dist/parametric.d.ts +7 -0
- package/dist/parametric.d.ts.map +1 -0
- package/dist/parametric.js +7 -0
- package/dist/parametric.js.map +1 -0
- package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
- package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/clip-triangle-mesh.js +155 -0
- package/dist/polygon/clip-triangle-mesh.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts +24 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -0
- package/dist/polygon/cut-by-grid.js +221 -0
- package/dist/polygon/cut-by-grid.js.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.js +149 -0
- package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
- package/dist/polygon/earcut.d.ts +13 -0
- package/dist/polygon/earcut.d.ts.map +1 -0
- package/dist/polygon/earcut.js +693 -0
- package/dist/polygon/earcut.js.map +1 -0
- package/dist/polygon/index.d.ts +16 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +14 -0
- package/dist/polygon/index.js.map +1 -0
- package/dist/polygon/lineclip.d.ts +31 -0
- package/dist/polygon/lineclip.d.ts.map +1 -0
- package/dist/polygon/lineclip.js +184 -0
- package/dist/polygon/lineclip.js.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.js +285 -0
- package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
- package/dist/polygon/polygon-utils.d.ts +103 -0
- package/dist/polygon/polygon-utils.d.ts.map +1 -0
- package/dist/polygon/polygon-utils.js +155 -0
- package/dist/polygon/polygon-utils.js.map +1 -0
- package/dist/polygon/polygon.d.ts +41 -0
- package/dist/polygon/polygon.d.ts.map +1 -0
- package/dist/polygon/polygon.js +76 -0
- package/dist/polygon/polygon.js.map +1 -0
- package/dist/polygon/subdivide-polyline.d.ts +56 -0
- package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
- package/dist/polygon/subdivide-polyline.js +141 -0
- package/dist/polygon/subdivide-polyline.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +238 -0
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
- package/dist/polygon/utils.d.ts +5 -0
- package/dist/polygon/utils.d.ts.map +1 -0
- package/dist/polygon/utils.js +38 -0
- package/dist/polygon/utils.js.map +1 -0
- package/dist/spatial-index/box-index.d.ts +86 -0
- package/dist/spatial-index/box-index.d.ts.map +1 -0
- package/dist/spatial-index/box-index.js +335 -0
- package/dist/spatial-index/box-index.js.map +1 -0
- package/dist/spatial-index/index.d.ts +7 -0
- package/dist/spatial-index/index.d.ts.map +1 -0
- package/dist/spatial-index/index.js +6 -0
- package/dist/spatial-index/index.js.map +1 -0
- package/dist/spatial-index/triangle-bvh.d.ts +74 -0
- package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
- package/dist/spatial-index/triangle-bvh.js +221 -0
- package/dist/spatial-index/triangle-bvh.js.map +1 -0
- package/dist/utils/attribute-compression.d.ts +50 -0
- package/dist/utils/attribute-compression.d.ts.map +1 -0
- package/dist/utils/attribute-compression.js +186 -0
- package/dist/utils/attribute-compression.js.map +1 -0
- package/dist/utils/attribute-iterator.d.ts +8 -0
- package/dist/utils/attribute-iterator.d.ts.map +1 -0
- package/dist/utils/attribute-iterator.js +25 -0
- package/dist/utils/attribute-iterator.js.map +1 -0
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +4 -0
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
- package/dist/utils/compute-vertex-normals.js +54 -0
- package/dist/utils/compute-vertex-normals.js.map +1 -0
- package/dist/utils/constants.d.ts +52 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +39 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coordinates.d.ts +3 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +8 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/dist/utils/geometry.d.ts +20 -0
- package/dist/utils/geometry.d.ts.map +1 -0
- package/dist/utils/geometry.js +31 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/gl-type.d.ts +17 -0
- package/dist/utils/gl-type.d.ts.map +1 -0
- package/dist/utils/gl-type.js +69 -0
- package/dist/utils/gl-type.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
- package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
- package/dist/utils/interpolate-packed-attributes.js +192 -0
- package/dist/utils/interpolate-packed-attributes.js.map +1 -0
- package/dist/utils/mesh-processing.d.ts +18 -0
- package/dist/utils/mesh-processing.d.ts.map +1 -0
- package/dist/utils/mesh-processing.js +300 -0
- package/dist/utils/mesh-processing.js.map +1 -0
- package/dist/utils/primitive-iterator.d.ts +21 -0
- package/dist/utils/primitive-iterator.d.ts.map +1 -0
- package/dist/utils/primitive-iterator.js +117 -0
- package/dist/utils/primitive-iterator.js.map +1 -0
- package/dist/utils/project-bounds.d.ts +44 -0
- package/dist/utils/project-bounds.d.ts.map +1 -0
- package/dist/utils/project-bounds.js +93 -0
- package/dist/utils/project-bounds.js.map +1 -0
- package/dist/utils/project-texture-coordinates.d.ts +19 -0
- package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
- package/dist/utils/project-texture-coordinates.js +49 -0
- package/dist/utils/project-texture-coordinates.js.map +1 -0
- package/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/dist/utils/rgb565.d.ts +5 -0
- package/dist/utils/rgb565.d.ts.map +1 -0
- package/dist/utils/rgb565.js +24 -0
- package/dist/utils/rgb565.js.map +1 -0
- package/dist/utils/typed-array-utils.d.ts +3 -0
- package/dist/utils/typed-array-utils.d.ts.map +1 -0
- package/dist/utils/typed-array-utils.js +16 -0
- package/dist/utils/typed-array-utils.js.map +1 -0
- package/package.json +24 -4
- package/src/color/color-lut-types.ts +19 -0
- package/src/color/index.ts +6 -0
- package/src/color/sample-lut.ts +175 -0
- package/src/culling/bounds.ts +152 -0
- package/src/culling/constants.ts +6 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +93 -0
- package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
- package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
- package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
- package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +171 -0
- package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
- package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
- package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
- package/src/culling/lib/culling-volume.ts +171 -0
- package/src/culling/lib/perspective-frustum.ts +288 -0
- package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
- package/src/culling/lib/plane.ts +118 -0
- package/src/culling/lib/ray.ts +54 -0
- package/src/culling/lib/shapes/box-shape.ts +78 -0
- package/src/culling/lib/shapes/capsule-shape.ts +232 -0
- package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
- package/src/culling/lib/shapes/implicit-shape.ts +209 -0
- package/src/culling/lib/shapes/plane-shape.ts +78 -0
- package/src/culling/lib/shapes/sphere-shape.ts +60 -0
- package/src/culling/oriented-box-2d.ts +165 -0
- package/src/culling/queries.ts +332 -0
- package/src/culling/screen-ray.ts +75 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/bezier-curves.ts +62 -0
- package/src/curves/catmull-rom-curve.ts +89 -0
- package/src/curves/curve-arc-length.ts +70 -0
- package/src/curves/curve.ts +96 -0
- package/src/curves/hermite-curve.ts +34 -0
- package/src/curves/index.ts +19 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/geometries/box-geometry.ts +1 -1
- package/src/geometries/capsule-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/geometry-helpers.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/primitive-mesh-builder.ts +84 -0
- package/src/geometries/prism-geometry.ts +57 -0
- package/src/geometries/ring-geometry.ts +102 -0
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/surface-of-revolution.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +1 -1
- package/src/index.ts +226 -1
- package/src/lib/geometry-utils.ts +2 -2
- package/src/lib/geometry.ts +2 -2
- package/src/lib/hinge-tree.ts +170 -0
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
- package/src/parametric/lathe-geometry.ts +70 -0
- package/src/parametric/parametric-geometry.ts +118 -0
- package/src/parametric/torus-geometry.ts +118 -0
- package/src/parametric.ts +9 -0
- package/src/polygon/clip-triangle-mesh.ts +218 -0
- package/src/polygon/cut-by-grid.ts +313 -0
- package/src/polygon/cut-by-mercator-bounds.ts +204 -0
- package/src/polygon/earcut.ts +859 -0
- package/src/polygon/index.ts +48 -0
- package/src/polygon/lineclip.ts +218 -0
- package/src/polygon/pole-of-inaccessibility.ts +330 -0
- package/src/polygon/polygon-utils.ts +273 -0
- package/src/polygon/polygon.ts +105 -0
- package/src/polygon/subdivide-polyline.ts +223 -0
- package/src/polygon/subdivide-triangle-mesh.ts +342 -0
- package/src/polygon/utils.ts +50 -0
- package/src/spatial-index/box-index.ts +452 -0
- package/src/spatial-index/index.ts +20 -0
- package/src/spatial-index/triangle-bvh.ts +345 -0
- package/src/utils/attribute-compression.ts +234 -0
- package/src/utils/attribute-iterator.ts +28 -0
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +63 -0
- package/src/utils/constants.ts +42 -0
- package/src/utils/coordinates.ts +8 -0
- package/src/utils/geometry.ts +49 -0
- package/src/utils/gl-type.ts +87 -0
- package/src/utils/index.ts +55 -0
- package/src/utils/interpolate-packed-attributes.ts +284 -0
- package/src/utils/mesh-processing.ts +377 -0
- package/src/utils/primitive-iterator.ts +145 -0
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/src/utils/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getClosestPointOnTriangle,
|
|
7
|
+
getClosestPointsSegmentTriangle,
|
|
8
|
+
intersectRayTriangle,
|
|
9
|
+
normalizeQueryDirection,
|
|
10
|
+
validateQueryPoint,
|
|
11
|
+
type QueryPoint
|
|
12
|
+
} from '../culling/queries';
|
|
13
|
+
import {
|
|
14
|
+
BoxIndex,
|
|
15
|
+
type IndexQueryBudget,
|
|
16
|
+
type IndexQueryResult,
|
|
17
|
+
type SearchIndexOptions
|
|
18
|
+
} from './box-index';
|
|
19
|
+
|
|
20
|
+
export type TriangleBVHOptions = {
|
|
21
|
+
/** Packed xyz vertices. Copied at construction. */
|
|
22
|
+
positions: ArrayLike<number>;
|
|
23
|
+
/** Triangle-list vertex indices. Omit for non-indexed triangles. */
|
|
24
|
+
indices?: ArrayLike<number>;
|
|
25
|
+
leafSize?: number;
|
|
26
|
+
};
|
|
27
|
+
export type TriangleQueryResult = {
|
|
28
|
+
index: number;
|
|
29
|
+
distance: number;
|
|
30
|
+
point: [number, number, number];
|
|
31
|
+
};
|
|
32
|
+
export type TriangleRayResult = TriangleQueryResult & {barycentric: [number, number, number]};
|
|
33
|
+
export type TriangleSegmentResult = TriangleQueryResult & {
|
|
34
|
+
segmentPoint: [number, number, number];
|
|
35
|
+
segmentFraction: number;
|
|
36
|
+
};
|
|
37
|
+
export type TriangleNearestOptions = {maxDistance?: number; filter?: (index: number) => boolean};
|
|
38
|
+
|
|
39
|
+
/** Optional application constraints for the nearest accepted triangle intersection. */
|
|
40
|
+
export type TriangleRayOptions = {
|
|
41
|
+
/** Inclusive Euclidean distance limit in input-coordinate units; defaults to Infinity. */
|
|
42
|
+
maxDistance?: number;
|
|
43
|
+
/** Ignore triangles facing away from the ray; defaults to false. */
|
|
44
|
+
backfaceCulling?: boolean;
|
|
45
|
+
/** Exclude an original triangle index before running its exact intersection kernel. */
|
|
46
|
+
filter?: (index: number) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Accept or reject an exact hit using its point and original-order barycentric weights.
|
|
49
|
+
* Rejected hits do not shorten the search: a valid surface behind a hole can still win.
|
|
50
|
+
* Called only for candidates that could improve the current accepted result, not all hits.
|
|
51
|
+
* Treat the detached candidate as immutable; traversal order is unspecified.
|
|
52
|
+
*/
|
|
53
|
+
acceptHit?: (
|
|
54
|
+
hit: Readonly<Omit<TriangleRayResult, 'point' | 'barycentric'>> & {
|
|
55
|
+
readonly point: readonly [number, number, number];
|
|
56
|
+
readonly barycentric: readonly [number, number, number];
|
|
57
|
+
}
|
|
58
|
+
) => boolean;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Static triangle-list BVH. index is the original triangle number, not a vertex index. */
|
|
62
|
+
export class TriangleBVH {
|
|
63
|
+
readonly size: number;
|
|
64
|
+
private readonly positions: Float64Array;
|
|
65
|
+
private readonly indices: Uint32Array;
|
|
66
|
+
private readonly boxes: BoxIndex;
|
|
67
|
+
|
|
68
|
+
constructor(options: TriangleBVHOptions) {
|
|
69
|
+
if (options.positions.length % 3) throw new RangeError('Positions must be packed xyz');
|
|
70
|
+
this.positions = Float64Array.from(options.positions);
|
|
71
|
+
for (const value of this.positions) {
|
|
72
|
+
if (!Number.isFinite(value)) throw new RangeError('Positions must be finite');
|
|
73
|
+
}
|
|
74
|
+
const source = options.indices ?? Array.from({length: this.positions.length / 3}, (_, i) => i);
|
|
75
|
+
if (source.length % 3) throw new RangeError('Indices must form triangles');
|
|
76
|
+
this.indices = new Uint32Array(source.length);
|
|
77
|
+
for (let i = 0; i < source.length; i++) {
|
|
78
|
+
if (
|
|
79
|
+
!Number.isSafeInteger(source[i]) ||
|
|
80
|
+
source[i] < 0 ||
|
|
81
|
+
source[i] >= this.positions.length / 3 ||
|
|
82
|
+
source[i] > 0xffffffff
|
|
83
|
+
) {
|
|
84
|
+
throw new RangeError('Triangle index is out of bounds');
|
|
85
|
+
}
|
|
86
|
+
this.indices[i] = source[i];
|
|
87
|
+
}
|
|
88
|
+
this.size = this.indices.length / 3;
|
|
89
|
+
const bounds = new Float64Array(this.size * 6);
|
|
90
|
+
for (let i = 0; i < this.size; i++) {
|
|
91
|
+
const [a, b, c] = this.triangle(i);
|
|
92
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
93
|
+
bounds[i * 6 + axis] = Math.min(a[axis], b[axis], c[axis]);
|
|
94
|
+
bounds[i * 6 + axis + 3] = Math.max(a[axis], b[axis], c[axis]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.boxes = new BoxIndex({bounds, dimension: 3, leafSize: options.leafSize});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Bounds candidates only; does not imply exact triangle/box overlap. */
|
|
101
|
+
search(minimum: QueryPoint, maximum: QueryPoint): number[] {
|
|
102
|
+
return this.boxes.search(minimum, maximum);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
searchQuery(
|
|
106
|
+
minimum: QueryPoint,
|
|
107
|
+
maximum: QueryPoint,
|
|
108
|
+
options: SearchIndexOptions = {}
|
|
109
|
+
): IndexQueryResult<number[]> {
|
|
110
|
+
return this.boxes.searchQuery(minimum, maximum, options);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Nearest accepted exact hit; application rejection never clips away later candidates. */
|
|
114
|
+
intersectRay(
|
|
115
|
+
origin: QueryPoint,
|
|
116
|
+
direction: QueryPoint,
|
|
117
|
+
options: TriangleRayOptions = {}
|
|
118
|
+
): TriangleRayResult | null {
|
|
119
|
+
return this.intersectRayQuery(origin, direction, {...options, maxWork: Infinity}).result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
intersectRayQuery(
|
|
123
|
+
origin: QueryPoint,
|
|
124
|
+
direction: QueryPoint,
|
|
125
|
+
options: TriangleRayOptions & IndexQueryBudget = {}
|
|
126
|
+
): IndexQueryResult<TriangleRayResult | null> {
|
|
127
|
+
validateQueryPoint(origin, 3);
|
|
128
|
+
const unit = normalizeQueryDirection(direction, 3);
|
|
129
|
+
let result: TriangleRayResult | null = null;
|
|
130
|
+
const query = this.boxes.intersectRayQuery(origin, direction, {
|
|
131
|
+
maxWork: options.maxWork,
|
|
132
|
+
maxDistance: options.maxDistance,
|
|
133
|
+
filter: options.filter,
|
|
134
|
+
intersectItem: (index, maximum) => {
|
|
135
|
+
const [a, b, c] = this.triangle(index);
|
|
136
|
+
const hit = intersectRayTriangle(origin, unit, a, b, c, {
|
|
137
|
+
backfaceCulling: options.backfaceCulling,
|
|
138
|
+
maxT: maximum
|
|
139
|
+
});
|
|
140
|
+
if (
|
|
141
|
+
hit &&
|
|
142
|
+
(!result ||
|
|
143
|
+
hit.t < result.distance ||
|
|
144
|
+
(hit.t === result.distance && index < result.index))
|
|
145
|
+
) {
|
|
146
|
+
const candidateHit: TriangleRayResult = {
|
|
147
|
+
index,
|
|
148
|
+
distance: hit.t,
|
|
149
|
+
point: [
|
|
150
|
+
origin[0] + hit.t * unit[0],
|
|
151
|
+
origin[1] + hit.t * unit[1],
|
|
152
|
+
origin[2] + hit.t * unit[2]
|
|
153
|
+
],
|
|
154
|
+
barycentric: hit.barycentric
|
|
155
|
+
};
|
|
156
|
+
if (!options.acceptHit || options.acceptHit(candidateHit)) {
|
|
157
|
+
result = candidateHit;
|
|
158
|
+
return hit.t;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return {...query, result};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
nearest(point: QueryPoint, options: TriangleNearestOptions = {}): TriangleQueryResult | null {
|
|
168
|
+
return this.nearestQuery(point, {...options, maxWork: Infinity}).result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
nearestQuery(
|
|
172
|
+
point: QueryPoint,
|
|
173
|
+
options: TriangleNearestOptions & IndexQueryBudget = {}
|
|
174
|
+
): IndexQueryResult<TriangleQueryResult | null> {
|
|
175
|
+
let candidate: TriangleQueryResult | null = null;
|
|
176
|
+
const query = this.boxes.nearestQuery(point, {
|
|
177
|
+
...options,
|
|
178
|
+
distanceToItem: index => {
|
|
179
|
+
const closest = getClosestPointOnTriangle(point, ...this.triangle(index));
|
|
180
|
+
const distance = Math.hypot(
|
|
181
|
+
point[0] - closest[0],
|
|
182
|
+
point[1] - closest[1],
|
|
183
|
+
point[2] - closest[2]
|
|
184
|
+
);
|
|
185
|
+
if (
|
|
186
|
+
!candidate ||
|
|
187
|
+
distance < candidate.distance ||
|
|
188
|
+
(distance === candidate.distance && index < candidate.index)
|
|
189
|
+
)
|
|
190
|
+
candidate = {index, distance, point: closest};
|
|
191
|
+
return distance;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
// Reuse the winning refinement rather than running an extra kernel outside the budget.
|
|
195
|
+
return {...query, result: query.result ? candidate : null};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** All triangle contacts with a closed sphere, sorted by original index (not distance).
|
|
199
|
+
* Uses closest points on faces, edges and vertices. No contact manifold reduction.
|
|
200
|
+
*/
|
|
201
|
+
intersectSphere(
|
|
202
|
+
center: QueryPoint,
|
|
203
|
+
radius: number,
|
|
204
|
+
options: SearchIndexOptions = {}
|
|
205
|
+
): IndexQueryResult<TriangleQueryResult[]> {
|
|
206
|
+
validateQueryPoint(center, 3);
|
|
207
|
+
if (!Number.isFinite(radius) || radius < 0)
|
|
208
|
+
throw new RangeError('Sphere radius must be finite and nonnegative');
|
|
209
|
+
const minimum: number[] = [],
|
|
210
|
+
maximum: number[] = [];
|
|
211
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
212
|
+
// Outward allowance keeps the broad phase from dropping roundoff-sized tangencies.
|
|
213
|
+
// The exact kernel below still uses the caller's unmodified radius.
|
|
214
|
+
const padding =
|
|
215
|
+
8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius));
|
|
216
|
+
minimum.push(center[axis] - radius - padding);
|
|
217
|
+
maximum.push(center[axis] + radius + padding);
|
|
218
|
+
}
|
|
219
|
+
const hits = new Map<number, TriangleQueryResult>();
|
|
220
|
+
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
221
|
+
...options,
|
|
222
|
+
filter: index => {
|
|
223
|
+
if (options.filter && !options.filter(index)) return false;
|
|
224
|
+
const point = getClosestPointOnTriangle(center, ...this.triangle(index));
|
|
225
|
+
const distance = Math.hypot(
|
|
226
|
+
center[0] - point[0],
|
|
227
|
+
center[1] - point[1],
|
|
228
|
+
center[2] - point[2]
|
|
229
|
+
);
|
|
230
|
+
if (!point.every(Number.isFinite) || !Number.isFinite(distance))
|
|
231
|
+
throw new RangeError('Sphere query arithmetic overflow');
|
|
232
|
+
if (distance > radius) return false;
|
|
233
|
+
hits.set(index, {index, distance, point});
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
return {...query, result: query.result.map(index => hits.get(index)!)};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Minimum Euclidean distance along the whole closed segment, not first intersection. */
|
|
241
|
+
nearestSegment(
|
|
242
|
+
start: QueryPoint,
|
|
243
|
+
end: QueryPoint,
|
|
244
|
+
options: TriangleNearestOptions = {}
|
|
245
|
+
): TriangleSegmentResult | null {
|
|
246
|
+
return this.nearestSegmentQuery(start, end, {...options, maxWork: Infinity}).result;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
nearestSegmentQuery(
|
|
250
|
+
start: QueryPoint,
|
|
251
|
+
end: QueryPoint,
|
|
252
|
+
options: TriangleNearestOptions & IndexQueryBudget = {}
|
|
253
|
+
): IndexQueryResult<TriangleSegmentResult | null> {
|
|
254
|
+
const {minimum, maximum} = segmentBounds(start, end);
|
|
255
|
+
let candidate: TriangleSegmentResult | null = null;
|
|
256
|
+
const query = this.boxes.nearestBoxQuery(minimum, maximum, {
|
|
257
|
+
...options,
|
|
258
|
+
distanceToItem: index => {
|
|
259
|
+
const closest = this.segmentClosest(index, start, end);
|
|
260
|
+
if (
|
|
261
|
+
!candidate ||
|
|
262
|
+
closest.distance < candidate.distance ||
|
|
263
|
+
(closest.distance === candidate.distance && index < candidate.index)
|
|
264
|
+
)
|
|
265
|
+
candidate = closest;
|
|
266
|
+
return closest.distance;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
return {...query, result: query.result ? candidate : null};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Closed capsule overlap, with one closest pair per accepted triangle.
|
|
273
|
+
* A straight translating sphere covers this volume, but segmentFraction is not first-impact time.
|
|
274
|
+
*/
|
|
275
|
+
intersectCapsule(
|
|
276
|
+
start: QueryPoint,
|
|
277
|
+
end: QueryPoint,
|
|
278
|
+
radius: number,
|
|
279
|
+
options: SearchIndexOptions = {}
|
|
280
|
+
): IndexQueryResult<TriangleSegmentResult[]> {
|
|
281
|
+
if (!Number.isFinite(radius) || radius < 0)
|
|
282
|
+
throw new RangeError('Capsule radius must be finite and nonnegative');
|
|
283
|
+
const {minimum, maximum} = segmentBounds(start, end, radius);
|
|
284
|
+
const hits = new Map<number, TriangleSegmentResult>();
|
|
285
|
+
const query = this.boxes.searchQuery(minimum, maximum, {
|
|
286
|
+
...options,
|
|
287
|
+
filter: index => {
|
|
288
|
+
if (options.filter && !options.filter(index)) return false;
|
|
289
|
+
const closest = this.segmentClosest(index, start, end);
|
|
290
|
+
if (closest.distance > radius) return false;
|
|
291
|
+
hits.set(index, closest);
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return {...query, result: query.result.map(index => hits.get(index)!)};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private segmentClosest(index: number, start: QueryPoint, end: QueryPoint): TriangleSegmentResult {
|
|
299
|
+
const closest = getClosestPointsSegmentTriangle(start, end, ...this.triangle(index));
|
|
300
|
+
return {
|
|
301
|
+
index,
|
|
302
|
+
distance: closest.distance,
|
|
303
|
+
point: closest.trianglePoint,
|
|
304
|
+
segmentPoint: closest.segmentPoint,
|
|
305
|
+
segmentFraction: closest.segmentFraction
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private triangle(index: number): [Float64Array, Float64Array, Float64Array] {
|
|
310
|
+
const vertex = (i: number): Float64Array => {
|
|
311
|
+
const start = this.indices[index * 3 + i] * 3;
|
|
312
|
+
return this.positions.subarray(start, start + 3);
|
|
313
|
+
};
|
|
314
|
+
return [vertex(0), vertex(1), vertex(2)];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function segmentBounds(
|
|
319
|
+
start: QueryPoint,
|
|
320
|
+
end: QueryPoint,
|
|
321
|
+
radius?: number
|
|
322
|
+
): {minimum: number[]; maximum: number[]} {
|
|
323
|
+
validateQueryPoint(start, 3);
|
|
324
|
+
validateQueryPoint(end, 3);
|
|
325
|
+
for (let axis = 0; axis < 3; axis++)
|
|
326
|
+
if (!Number.isFinite(end[axis] - start[axis]))
|
|
327
|
+
throw new RangeError('Segment coordinate span overflow');
|
|
328
|
+
const minimum: number[] = [],
|
|
329
|
+
maximum: number[] = [];
|
|
330
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
331
|
+
// Capsule broad-phase padding only; nearest lower bounds need no expansion.
|
|
332
|
+
const padding =
|
|
333
|
+
radius === undefined
|
|
334
|
+
? 0
|
|
335
|
+
: radius +
|
|
336
|
+
8 *
|
|
337
|
+
Math.max(
|
|
338
|
+
Number.MIN_VALUE,
|
|
339
|
+
Number.EPSILON * Math.max(Math.abs(start[axis]), Math.abs(end[axis]), radius)
|
|
340
|
+
);
|
|
341
|
+
minimum.push(Math.min(start[axis], end[axis]) - padding);
|
|
342
|
+
maximum.push(Math.max(start[axis], end[axis]) + padding);
|
|
343
|
+
}
|
|
344
|
+
return {minimum, maximum};
|
|
345
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
|
|
7
|
+
// Derived from Cesium under the Apache 2.0 license.
|
|
8
|
+
// https://github.com/CesiumGS/cesium/blob/main/LICENSE.md
|
|
9
|
+
|
|
10
|
+
import {Vector2, Vector3, assert, clamp, _MathUtils} from '@math.gl/core';
|
|
11
|
+
|
|
12
|
+
type Vector4 = {x: number; y: number; z: number; w: number};
|
|
13
|
+
|
|
14
|
+
const RIGHT_SHIFT = 1 / 256;
|
|
15
|
+
const LEFT_SHIFT = 256;
|
|
16
|
+
const scratchVector2 = new Vector2();
|
|
17
|
+
const scratchVector3 = new Vector3();
|
|
18
|
+
const scratchEncodeVector2 = new Vector2();
|
|
19
|
+
const octEncodeScratch = new Vector2();
|
|
20
|
+
const uint8ForceArray = new Uint8Array(1);
|
|
21
|
+
|
|
22
|
+
function forceUint8(value: number): number {
|
|
23
|
+
uint8ForceArray[0] = value;
|
|
24
|
+
return uint8ForceArray[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fromSNorm(value: number, rangeMaximum = 255): number {
|
|
28
|
+
return (clamp(value, 0, rangeMaximum) / rangeMaximum) * 2 - 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toSNorm(value: number, rangeMaximum = 255): number {
|
|
32
|
+
return Math.round((clamp(value, -1, 1) * 0.5 + 0.5) * rangeMaximum);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function signNotZero(value: number): number {
|
|
36
|
+
return value < 0 ? -1 : 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Encodes a normalized vector into two SNORM values following octahedral encoding.
|
|
41
|
+
*
|
|
42
|
+
* @param vector Normalized vector to encode.
|
|
43
|
+
* @param rangeMaximum Maximum value of the SNORM range.
|
|
44
|
+
* @param result Target for the two encoded components.
|
|
45
|
+
*/
|
|
46
|
+
export function octEncodeInRange(vector: Vector3, rangeMaximum: number, result: Vector2): Vector2 {
|
|
47
|
+
assert(vector);
|
|
48
|
+
assert(result);
|
|
49
|
+
scratchVector3.from(vector);
|
|
50
|
+
assert(Math.abs(scratchVector3.magnitudeSquared() - 1) <= _MathUtils.EPSILON6);
|
|
51
|
+
|
|
52
|
+
const denominator = Math.abs(vector.x) + Math.abs(vector.y) + Math.abs(vector.z);
|
|
53
|
+
result.x = vector.x / denominator;
|
|
54
|
+
result.y = vector.y / denominator;
|
|
55
|
+
|
|
56
|
+
if (vector.z < 0) {
|
|
57
|
+
const x = result.x;
|
|
58
|
+
const y = result.y;
|
|
59
|
+
result.x = (1 - Math.abs(y)) * signNotZero(x);
|
|
60
|
+
result.y = (1 - Math.abs(x)) * signNotZero(y);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
result.x = toSNorm(result.x, rangeMaximum);
|
|
64
|
+
result.y = toSNorm(result.y, rangeMaximum);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Encodes a normalized vector into two 8-bit octahedral components. */
|
|
69
|
+
export function octEncode(vector: Vector3, result: Vector2): Vector2 {
|
|
70
|
+
return octEncodeInRange(vector, 255, result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Encodes a normalized vector into four 8-bit octahedral components. */
|
|
74
|
+
export function octEncodeToVector4(vector: Vector3, result: Vector4): Vector4 {
|
|
75
|
+
octEncodeInRange(vector, 65535, octEncodeScratch);
|
|
76
|
+
result.x = forceUint8(octEncodeScratch.x * RIGHT_SHIFT);
|
|
77
|
+
result.y = forceUint8(octEncodeScratch.x);
|
|
78
|
+
result.z = forceUint8(octEncodeScratch.y * RIGHT_SHIFT);
|
|
79
|
+
result.w = forceUint8(octEncodeScratch.y);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Decodes two SNORM octahedral components into a normalized vector.
|
|
85
|
+
*
|
|
86
|
+
* @param x First encoded component.
|
|
87
|
+
* @param y Second encoded component.
|
|
88
|
+
* @param rangeMaximum Maximum value of the SNORM range.
|
|
89
|
+
* @param result Target for the decoded vector.
|
|
90
|
+
*/
|
|
91
|
+
export function octDecodeInRange(
|
|
92
|
+
x: number,
|
|
93
|
+
y: number,
|
|
94
|
+
rangeMaximum: number,
|
|
95
|
+
result: Vector3
|
|
96
|
+
): Vector3 {
|
|
97
|
+
assert(result);
|
|
98
|
+
if (x < 0 || x > rangeMaximum || y < 0 || y > rangeMaximum) {
|
|
99
|
+
throw new Error(`x and y must be unsigned normalized integers between 0 and ${rangeMaximum}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
result.x = fromSNorm(x, rangeMaximum);
|
|
103
|
+
result.y = fromSNorm(y, rangeMaximum);
|
|
104
|
+
result.z = 1 - (Math.abs(result.x) + Math.abs(result.y));
|
|
105
|
+
|
|
106
|
+
if (result.z < 0) {
|
|
107
|
+
const oldX = result.x;
|
|
108
|
+
result.x = (1 - Math.abs(result.y)) * signNotZero(oldX);
|
|
109
|
+
result.y = (1 - Math.abs(oldX)) * signNotZero(result.y);
|
|
110
|
+
}
|
|
111
|
+
return result.normalize();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Decodes two 8-bit octahedral components into a normalized vector. */
|
|
115
|
+
export function octDecode(x: number, y: number, result: Vector3): Vector3 {
|
|
116
|
+
return octDecodeInRange(x, y, 255, result);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Decodes four 8-bit octahedral components into a normalized vector. */
|
|
120
|
+
export function octDecodeFromVector4(encoded: Vector4, result: Vector3): Vector3 {
|
|
121
|
+
assert(encoded);
|
|
122
|
+
assert(result);
|
|
123
|
+
const {x, y, z, w} = encoded;
|
|
124
|
+
if (x < 0 || x > 255 || y < 0 || y > 255 || z < 0 || z > 255 || w < 0 || w > 255) {
|
|
125
|
+
throw new Error('x, y, z, and w must be unsigned normalized integers between 0 and 255');
|
|
126
|
+
}
|
|
127
|
+
return octDecodeInRange(x * LEFT_SHIFT + y, z * LEFT_SHIFT + w, 65535, result);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Packs an octahedrally encoded two-component vector into one number. */
|
|
131
|
+
export function octPackFloat(encoded: Vector2): number {
|
|
132
|
+
scratchVector2.from(encoded);
|
|
133
|
+
return 256 * scratchVector2.x + scratchVector2.y;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Encodes a normalized vector into an octahedral representation packed into one number. */
|
|
137
|
+
export function octEncodeFloat(vector: Vector3): number {
|
|
138
|
+
octEncode(vector, scratchEncodeVector2);
|
|
139
|
+
return octPackFloat(scratchEncodeVector2);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Decodes an octahedral representation packed into one number. */
|
|
143
|
+
export function octDecodeFloat(value: number, result: Vector3): Vector3 {
|
|
144
|
+
assert(Number.isFinite(value));
|
|
145
|
+
const temporary = value / 256;
|
|
146
|
+
const x = Math.floor(temporary);
|
|
147
|
+
const y = (temporary - x) * 256;
|
|
148
|
+
return octDecode(x, y, result);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Packs three normalized vectors into two numeric octahedral values. */
|
|
152
|
+
export function octPack(
|
|
153
|
+
vector1: Vector3,
|
|
154
|
+
vector2: Vector3,
|
|
155
|
+
vector3: Vector3,
|
|
156
|
+
result: Vector2
|
|
157
|
+
): Vector2 {
|
|
158
|
+
assert(vector1);
|
|
159
|
+
assert(vector2);
|
|
160
|
+
assert(vector3);
|
|
161
|
+
assert(result);
|
|
162
|
+
const encoded1 = octEncodeFloat(vector1);
|
|
163
|
+
const encoded2 = octEncodeFloat(vector2);
|
|
164
|
+
const encoded3 = octEncode(vector3, scratchEncodeVector2);
|
|
165
|
+
result.x = 65536 * encoded3.x + encoded1;
|
|
166
|
+
result.y = 65536 * encoded3.y + encoded2;
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Decodes three normalized vectors packed by {@link octPack}. */
|
|
171
|
+
export function octUnpack(
|
|
172
|
+
packed: Vector2,
|
|
173
|
+
vector1: Vector3,
|
|
174
|
+
vector2: Vector3,
|
|
175
|
+
vector3: Vector3
|
|
176
|
+
): void {
|
|
177
|
+
let temporary = packed.x / 65536;
|
|
178
|
+
const x = Math.floor(temporary);
|
|
179
|
+
const encodedFloat1 = (temporary - x) * 65536;
|
|
180
|
+
temporary = packed.y / 65536;
|
|
181
|
+
const y = Math.floor(temporary);
|
|
182
|
+
const encodedFloat2 = (temporary - y) * 65536;
|
|
183
|
+
octDecodeFloat(encodedFloat1, vector1);
|
|
184
|
+
octDecodeFloat(encodedFloat2, vector2);
|
|
185
|
+
octDecode(x, y, vector3);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Packs two normalized texture coordinates into one number with 12 bits per component. */
|
|
189
|
+
export function compressTextureCoordinates(textureCoordinates: Vector2): number {
|
|
190
|
+
const x = (textureCoordinates.x * 4095) | 0;
|
|
191
|
+
const y = (textureCoordinates.y * 4095) | 0;
|
|
192
|
+
return 4096 * x + y;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Decompresses texture coordinates packed by {@link compressTextureCoordinates}. */
|
|
196
|
+
export function decompressTextureCoordinates(compressed: number, result: Vector2): Vector2 {
|
|
197
|
+
const temporary = compressed / 4096;
|
|
198
|
+
const x = Math.floor(temporary);
|
|
199
|
+
result.x = x / 4095;
|
|
200
|
+
result.y = (compressed - x * 4096) / 4095;
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Decodes delta- and ZigZag-encoded vertex buffers in place. */
|
|
205
|
+
export function zigZagDeltaDecode(
|
|
206
|
+
uBuffer: Uint16Array,
|
|
207
|
+
vBuffer: Uint16Array,
|
|
208
|
+
heightBuffer?: Uint16Array | number[]
|
|
209
|
+
): void {
|
|
210
|
+
assert(uBuffer);
|
|
211
|
+
assert(vBuffer);
|
|
212
|
+
assert(uBuffer.length === vBuffer.length);
|
|
213
|
+
if (heightBuffer) {
|
|
214
|
+
assert(uBuffer.length === heightBuffer.length);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let u = 0;
|
|
218
|
+
let v = 0;
|
|
219
|
+
let height = 0;
|
|
220
|
+
for (let index = 0; index < uBuffer.length; index++) {
|
|
221
|
+
u += zigZagDecode(uBuffer[index]);
|
|
222
|
+
v += zigZagDecode(vBuffer[index]);
|
|
223
|
+
uBuffer[index] = u;
|
|
224
|
+
vBuffer[index] = v;
|
|
225
|
+
if (heightBuffer) {
|
|
226
|
+
height += zigZagDecode(heightBuffer[index]);
|
|
227
|
+
heightBuffer[index] = height;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function zigZagDecode(value: number): number {
|
|
233
|
+
return (value >> 1) ^ -(value & 1);
|
|
234
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {TypedArray, TypedArrayConstructor} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Iterates over the fixed-size elements of a typed array.
|
|
9
|
+
*
|
|
10
|
+
* For performance, each iteration reuses the same typed-array view-sized value.
|
|
11
|
+
*/
|
|
12
|
+
export function* makeAttributeIterator(values: TypedArray, size: number): Iterable<TypedArray> {
|
|
13
|
+
if (!Number.isInteger(size) || size <= 0) {
|
|
14
|
+
throw new Error('Attribute size must be a positive integer');
|
|
15
|
+
}
|
|
16
|
+
if (values.length % size !== 0) {
|
|
17
|
+
throw new Error('Attribute length must be divisible by its size');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ArrayType = values.constructor as TypedArrayConstructor;
|
|
21
|
+
const element = new ArrayType(size);
|
|
22
|
+
for (let index = 0; index < values.length; index += size) {
|
|
23
|
+
for (let componentIndex = 0; componentIndex < size; componentIndex++) {
|
|
24
|
+
element[componentIndex] = values[index + componentIndex]!;
|
|
25
|
+
}
|
|
26
|
+
yield element;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {AttributeInterpolationProvenance} from './interpolate-packed-attributes';
|
|
5
|
+
|
|
6
|
+
/** Compose child→intermediate and intermediate→original barycentric provenance.
|
|
7
|
+
* Interpolate attributes only after composition, avoiding repeated integer rounding.
|
|
8
|
+
* More than three distinct contributors rejects: this contract describes source
|
|
9
|
+
* triangles, not arbitrary sparse blending. Zero-weight indices are ignored.
|
|
10
|
+
*/
|
|
11
|
+
export function composeAttributeProvenance(
|
|
12
|
+
parent: AttributeInterpolationProvenance,
|
|
13
|
+
child: AttributeInterpolationProvenance,
|
|
14
|
+
options: {maxVertices?: number} = {}
|
|
15
|
+
): {sourceVertexIndices: Uint32Array; sourceVertexWeights: Float64Array} {
|
|
16
|
+
const limit = options.maxVertices ?? 65536;
|
|
17
|
+
if (!Number.isSafeInteger(limit) || limit < 0 || limit > 0xffffffff)
|
|
18
|
+
throw new RangeError('Invalid provenance vertex limit');
|
|
19
|
+
validate(parent);
|
|
20
|
+
validate(child, parent.sourceVertexIndices.length / 3);
|
|
21
|
+
if (child.sourceVertexIndices.length / 3 > limit)
|
|
22
|
+
throw new RangeError('Provenance composition exceeded maxVertices');
|
|
23
|
+
const indices = new Uint32Array(child.sourceVertexIndices.length);
|
|
24
|
+
const weights = new Float64Array(indices.length);
|
|
25
|
+
for (let vertex = 0; vertex < indices.length / 3; vertex++) {
|
|
26
|
+
const contributors = new Map<number, number>();
|
|
27
|
+
for (let j = 0; j < 3; j++) {
|
|
28
|
+
const weight = child.sourceVertexWeights[3 * vertex + j];
|
|
29
|
+
if (!weight) continue;
|
|
30
|
+
const intermediate = child.sourceVertexIndices[3 * vertex + j];
|
|
31
|
+
for (let k = 0; k < 3; k++) {
|
|
32
|
+
const w = weight * parent.sourceVertexWeights[3 * intermediate + k];
|
|
33
|
+
if (!w) continue;
|
|
34
|
+
const index = parent.sourceVertexIndices[3 * intermediate + k];
|
|
35
|
+
contributors.set(index, (contributors.get(index) ?? 0) + w);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (contributors.size > 3)
|
|
39
|
+
throw new RangeError('Composed vertex spans multiple source triangles');
|
|
40
|
+
const sum = Array.from(contributors.values()).reduce((a, b) => a + b, 0);
|
|
41
|
+
let slot = 3 * vertex;
|
|
42
|
+
for (const [index, weight] of contributors) {
|
|
43
|
+
indices[slot] = index;
|
|
44
|
+
weights[slot++] = weight / sum;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {sourceVertexIndices: indices, sourceVertexWeights: weights};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function validate(p: AttributeInterpolationProvenance, count = 0x100000000) {
|
|
51
|
+
if (
|
|
52
|
+
!Number.isSafeInteger(p.sourceVertexIndices.length) ||
|
|
53
|
+
p.sourceVertexIndices.length < 0 ||
|
|
54
|
+
p.sourceVertexIndices.length % 3 ||
|
|
55
|
+
p.sourceVertexIndices.length !== p.sourceVertexWeights.length
|
|
56
|
+
)
|
|
57
|
+
throw new RangeError('Invalid provenance lengths');
|
|
58
|
+
for (let i = 0; i < p.sourceVertexIndices.length; i += 3) {
|
|
59
|
+
let sum = 0;
|
|
60
|
+
for (let j = 0; j < 3; j++) {
|
|
61
|
+
const w = p.sourceVertexWeights[i + j],
|
|
62
|
+
index = p.sourceVertexIndices[i + j];
|
|
63
|
+
if (
|
|
64
|
+
!Number.isFinite(w) ||
|
|
65
|
+
w < 0 ||
|
|
66
|
+
w > 1 ||
|
|
67
|
+
(w > 0 && (!Number.isSafeInteger(index) || index < 0 || index >= count))
|
|
68
|
+
)
|
|
69
|
+
throw new RangeError('Invalid provenance contributor');
|
|
70
|
+
sum += w;
|
|
71
|
+
}
|
|
72
|
+
if (Math.abs(sum - 1) > 1e-10) throw new RangeError('Provenance weights must sum to one');
|
|
73
|
+
}
|
|
74
|
+
}
|