@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,170 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Matrix4} from '@math.gl/core';
|
|
6
|
+
import type {NumericArray} from '@math.gl/core';
|
|
7
|
+
|
|
8
|
+
/** A rigid panel attached to its parent by a revolute joint. */
|
|
9
|
+
export type HingePanel = {
|
|
10
|
+
/** Parent index in the input array; -1 for a root. Input order is arbitrary. */
|
|
11
|
+
parent: number;
|
|
12
|
+
/** Child-local to parent-local transform at zero angle; defaults to identity. */
|
|
13
|
+
restTransform?: Readonly<NumericArray>;
|
|
14
|
+
/** Hinge pivot in parent-local coordinates. Required for nonroots. */
|
|
15
|
+
pivot?: readonly [number, number, number];
|
|
16
|
+
/** Right-handed rotation axis in parent-local coordinates; normalized internally. */
|
|
17
|
+
axis?: readonly [number, number, number];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type Joint = {
|
|
21
|
+
parent: number;
|
|
22
|
+
rest: Matrix4;
|
|
23
|
+
pivot: number[];
|
|
24
|
+
negativePivot: number[];
|
|
25
|
+
axis: number[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Experimental rigid-panel kinematics, independent of mesh topology and rendering.
|
|
29
|
+
* Snapshots its inputs. Does not infer shared edges, solve closed loops or detect collisions.
|
|
30
|
+
*/
|
|
31
|
+
export class HingeTree {
|
|
32
|
+
readonly panelCount: number;
|
|
33
|
+
private readonly joints: Joint[];
|
|
34
|
+
private readonly order: number[];
|
|
35
|
+
private readonly angles: Float64Array;
|
|
36
|
+
private readonly local = new Matrix4();
|
|
37
|
+
private readonly world = new Matrix4();
|
|
38
|
+
private readonly root = new Matrix4();
|
|
39
|
+
|
|
40
|
+
constructor(panels: readonly HingePanel[]) {
|
|
41
|
+
this.panelCount = panels.length;
|
|
42
|
+
const children: number[][] = panels.map(() => []);
|
|
43
|
+
const order: number[] = [];
|
|
44
|
+
this.joints = panels.map((panel, index) => {
|
|
45
|
+
const {parent} = panel;
|
|
46
|
+
if (!Number.isInteger(parent) || parent < -1 || parent >= panels.length || parent === index) {
|
|
47
|
+
throw new RangeError('Invalid hinge parent index');
|
|
48
|
+
}
|
|
49
|
+
if (parent === -1) order.push(index);
|
|
50
|
+
else children[parent].push(index);
|
|
51
|
+
const rest = new Matrix4();
|
|
52
|
+
if (panel.restTransform !== undefined) {
|
|
53
|
+
validateRigidTransform(panel.restTransform);
|
|
54
|
+
rest.copy(panel.restTransform);
|
|
55
|
+
}
|
|
56
|
+
const pivot = parent === -1 ? [0, 0, 0] : copyVector(panel.pivot);
|
|
57
|
+
const axis = parent === -1 ? [1, 0, 0] : copyVector(panel.axis);
|
|
58
|
+
const length = Math.hypot(...axis);
|
|
59
|
+
if (!Number.isFinite(length) || length === 0) throw new RangeError('Invalid hinge axis');
|
|
60
|
+
for (let i = 0; i < 3; i++) axis[i] /= length;
|
|
61
|
+
return {
|
|
62
|
+
parent,
|
|
63
|
+
rest,
|
|
64
|
+
pivot,
|
|
65
|
+
negativePivot: pivot.map(value => -value),
|
|
66
|
+
axis
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
// Iterative traversal supports deep trees without consuming the call stack.
|
|
70
|
+
for (let i = 0; i < order.length; i++) {
|
|
71
|
+
for (const child of children[order[i]]) order.push(child);
|
|
72
|
+
}
|
|
73
|
+
if (order.length !== panels.length) throw new RangeError('Hinge parents contain a cycle');
|
|
74
|
+
this.order = order;
|
|
75
|
+
this.angles = new Float64Array(panels.length);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Evaluate one angle per panel in radians (root angles must be zero).
|
|
79
|
+
* Returns column-major matrices in input-panel order, 16 doubles per panel.
|
|
80
|
+
* rootTransform places the whole forest; omitted means identity.
|
|
81
|
+
* Output may alias the inputs: angles and root transform are snapshotted first.
|
|
82
|
+
* Finite inputs that overflow during composition throw; output may then be partial.
|
|
83
|
+
*/
|
|
84
|
+
evaluate(
|
|
85
|
+
angles: Readonly<NumericArray>,
|
|
86
|
+
output = new Float64Array(this.panelCount * 16),
|
|
87
|
+
rootTransform?: Readonly<NumericArray>
|
|
88
|
+
): Float64Array {
|
|
89
|
+
if (angles.length !== this.panelCount) throw new RangeError('Expected one angle per panel');
|
|
90
|
+
if (!(output instanceof Float64Array) || output.length !== this.panelCount * 16) {
|
|
91
|
+
throw new RangeError('Expected 16 Float64 values per panel');
|
|
92
|
+
}
|
|
93
|
+
for (let i = 0; i < angles.length; i++) {
|
|
94
|
+
if (!Number.isFinite(angles[i]) || (this.joints[i].parent === -1 && angles[i] !== 0)) {
|
|
95
|
+
throw new RangeError('Expected finite angles and zero root angles');
|
|
96
|
+
}
|
|
97
|
+
this.angles[i] = angles[i];
|
|
98
|
+
}
|
|
99
|
+
this.root.identity();
|
|
100
|
+
if (rootTransform !== undefined) {
|
|
101
|
+
validateRigidTransform(rootTransform);
|
|
102
|
+
this.root.copy(rootTransform);
|
|
103
|
+
}
|
|
104
|
+
for (const index of this.order) {
|
|
105
|
+
const joint = this.joints[index];
|
|
106
|
+
this.local.identity();
|
|
107
|
+
if (joint.parent !== -1) {
|
|
108
|
+
this.local
|
|
109
|
+
.translate(joint.pivot)
|
|
110
|
+
.rotateAxis(this.angles[index], joint.axis)
|
|
111
|
+
.translate(joint.negativePivot);
|
|
112
|
+
}
|
|
113
|
+
this.local.multiplyRight(joint.rest);
|
|
114
|
+
if (joint.parent === -1) this.world.copy(this.root);
|
|
115
|
+
else {
|
|
116
|
+
for (let i = 0; i < 16; i++) this.world[i] = output[joint.parent * 16 + i];
|
|
117
|
+
}
|
|
118
|
+
this.world.multiplyRight(this.local);
|
|
119
|
+
for (let i = 0; i < 16; i++) {
|
|
120
|
+
if (!Number.isFinite(this.world[i])) throw new RangeError('Hinge transform overflow');
|
|
121
|
+
output[index * 16 + i] = this.world[i];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return output;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function copyVector(vector?: readonly number[]): number[] {
|
|
129
|
+
if (
|
|
130
|
+
!vector ||
|
|
131
|
+
vector.length !== 3 ||
|
|
132
|
+
!Number.isFinite(vector[0]) ||
|
|
133
|
+
!Number.isFinite(vector[1]) ||
|
|
134
|
+
!Number.isFinite(vector[2])
|
|
135
|
+
) {
|
|
136
|
+
throw new RangeError('Expected a finite hinge pivot and axis');
|
|
137
|
+
}
|
|
138
|
+
return [...vector];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Accept proper rigid affine transforms, allowing numerical roundoff. */
|
|
142
|
+
function validateRigidTransform(matrix: Readonly<NumericArray>): void {
|
|
143
|
+
if (matrix.length !== 16) throw new RangeError('Expected a 4x4 rigid transform');
|
|
144
|
+
for (let i = 0; i < 16; i++) {
|
|
145
|
+
if (!Number.isFinite(matrix[i])) throw new RangeError('Expected a finite rigid transform');
|
|
146
|
+
}
|
|
147
|
+
const tolerance = 1e-6;
|
|
148
|
+
if (
|
|
149
|
+
Math.abs(matrix[3]) > tolerance ||
|
|
150
|
+
Math.abs(matrix[7]) > tolerance ||
|
|
151
|
+
Math.abs(matrix[11]) > tolerance ||
|
|
152
|
+
Math.abs(matrix[15] - 1) > tolerance
|
|
153
|
+
)
|
|
154
|
+
throw new RangeError('Expected an affine rigid transform');
|
|
155
|
+
for (let a = 0; a < 3; a++) {
|
|
156
|
+
for (let b = a; b < 3; b++) {
|
|
157
|
+
let dot = 0;
|
|
158
|
+
for (let row = 0; row < 3; row++) dot += matrix[a * 4 + row] * matrix[b * 4 + row];
|
|
159
|
+
if (Math.abs(dot - (a === b ? 1 : 0)) > tolerance) {
|
|
160
|
+
throw new RangeError('Rigid transforms cannot scale or shear');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const determinant =
|
|
165
|
+
matrix[0] * (matrix[5] * matrix[10] - matrix[6] * matrix[9]) -
|
|
166
|
+
matrix[4] * (matrix[1] * matrix[10] - matrix[2] * matrix[9]) +
|
|
167
|
+
matrix[8] * (matrix[1] * matrix[6] - matrix[2] * matrix[5]);
|
|
168
|
+
if (Math.abs(determinant - 1) > tolerance)
|
|
169
|
+
throw new RangeError('Rigid transforms cannot reflect');
|
|
170
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
export {
|
|
5
|
+
createPhotometricSampler,
|
|
6
|
+
integrateLuminousFlux,
|
|
7
|
+
resamplePhotometricProfile
|
|
8
|
+
} from './photometry';
|
|
9
|
+
export type {PhotometricSampler, PhotometricGrid, PhotometricResampleOptions} from './photometry';
|
|
10
|
+
export type {PhotometricProfile, PhotometricSymmetry} from './lighting-types';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Explicit azimuth extension rule; never inferred from a file or its metadata. */
|
|
6
|
+
export type PhotometricSymmetry = 'rotational' | 'quadrant' | 'bilateral' | 'none';
|
|
7
|
+
|
|
8
|
+
/** Format-independent polar/azimuth intensity measurements in degrees and candela. */
|
|
9
|
+
export type PhotometricProfile = {
|
|
10
|
+
/** Ordered polar angles in [0, 180], measured from an application-chosen pole. */
|
|
11
|
+
verticalAngles: ArrayLike<number>;
|
|
12
|
+
/** Ordered azimuth angles in [0, 360], relative to an application-chosen origin. */
|
|
13
|
+
horizontalAngles: ArrayLike<number>;
|
|
14
|
+
/** Candela samples, vertical angle varying fastest. */
|
|
15
|
+
intensities: ArrayLike<number>;
|
|
16
|
+
/** Uniform intensity multiplier; default 1. No lamp, ballast or file metadata is read. */
|
|
17
|
+
intensityScale?: number;
|
|
18
|
+
/** Explicit rotational, quadrant, bilateral or full-circle interpretation. */
|
|
19
|
+
symmetry: PhotometricSymmetry;
|
|
20
|
+
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {PhotometricProfile} from './lighting-types';
|
|
5
|
+
|
|
6
|
+
/** Samples a snapshotted polar/azimuth distribution in candela, using angles in degrees. */
|
|
7
|
+
export type PhotometricSampler = (verticalAngle: number, horizontalAngle: number) => number;
|
|
8
|
+
|
|
9
|
+
/** Options for a regular, renderer-independent angular grid. */
|
|
10
|
+
export type PhotometricResampleOptions = {
|
|
11
|
+
/** Samples from vertical 0 through 180 degrees, including both endpoints; default 181. */
|
|
12
|
+
verticalCount?: number;
|
|
13
|
+
/** Horizontal samples around [0, 360), excluding the duplicate seam; default 360. */
|
|
14
|
+
horizontalCount?: number;
|
|
15
|
+
/** Preserve candela or divide by the measured peak; default none. */
|
|
16
|
+
normalization?: 'none' | 'peak';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Regular angular samples without texture objects or renderer coordinate transforms. */
|
|
20
|
+
export type PhotometricGrid = {
|
|
21
|
+
/** Vertical samples per row. */
|
|
22
|
+
readonly width: number;
|
|
23
|
+
/** Horizontal rows. */
|
|
24
|
+
readonly height: number;
|
|
25
|
+
/** Row-major intensity samples, vertical angle varying fastest. */
|
|
26
|
+
readonly data: Float64Array;
|
|
27
|
+
/** Vertical sample coordinates in degrees. */
|
|
28
|
+
readonly verticalAngles: Float64Array;
|
|
29
|
+
/** Horizontal sample coordinates in degrees. */
|
|
30
|
+
readonly horizontalAngles: Float64Array;
|
|
31
|
+
/** Physical candela or peak-relative values. */
|
|
32
|
+
readonly unit: 'candela' | 'relative';
|
|
33
|
+
/** Measured peak in candela, before optional normalization. */
|
|
34
|
+
readonly peakCandela: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Internal immutable snapshot of the measured distribution. */
|
|
38
|
+
type PreparedPhotometricProfile = {
|
|
39
|
+
/** Measured vertical angles. */
|
|
40
|
+
verticalAngles: Float64Array;
|
|
41
|
+
/** Measured horizontal angles. */
|
|
42
|
+
horizontalAngles: Float64Array;
|
|
43
|
+
/** Scaled candela values. */
|
|
44
|
+
values: Float64Array;
|
|
45
|
+
/** Measured horizontal extent, or zero for rotational symmetry. */
|
|
46
|
+
horizontalSpan: number;
|
|
47
|
+
/** Largest scaled intensity. */
|
|
48
|
+
peak: number;
|
|
49
|
+
};
|
|
50
|
+
const DEGREES_TO_RADIANS = Math.PI / 180;
|
|
51
|
+
const MAX_GRID_SAMPLES = 4_194_304;
|
|
52
|
+
|
|
53
|
+
/** Creates a reusable bilinear sampler; later mutations of the source profile have no effect. */
|
|
54
|
+
export function createPhotometricSampler(profile: PhotometricProfile): PhotometricSampler {
|
|
55
|
+
const prepared = preparePhotometricProfile(profile);
|
|
56
|
+
return (verticalAngle, horizontalAngle) => {
|
|
57
|
+
if (
|
|
58
|
+
!Number.isFinite(verticalAngle) ||
|
|
59
|
+
verticalAngle < 0 ||
|
|
60
|
+
verticalAngle > 180 ||
|
|
61
|
+
!Number.isFinite(horizontalAngle)
|
|
62
|
+
) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Photometry: sampling requires a vertical angle in [0, 180] and finite horizontal angle'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return samplePreparedProfile(prepared, verticalAngle, horizontalAngle);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Integrates the piecewise bilinear angular distribution over solid angle, returning lumens. */
|
|
72
|
+
export function integrateLuminousFlux(profile: PhotometricProfile): number {
|
|
73
|
+
const prepared = preparePhotometricProfile(profile);
|
|
74
|
+
const {verticalAngles, horizontalAngles, values, horizontalSpan} = prepared;
|
|
75
|
+
const rows = new Float64Array(horizontalAngles.length);
|
|
76
|
+
for (let horizontalIndex = 0; horizontalIndex < rows.length; horizontalIndex++) {
|
|
77
|
+
for (let verticalIndex = 0; verticalIndex < verticalAngles.length - 1; verticalIndex++) {
|
|
78
|
+
const lowerAngle = verticalAngles[verticalIndex];
|
|
79
|
+
const upperAngle = verticalAngles[verticalIndex + 1];
|
|
80
|
+
const reflected = lowerAngle + upperAngle > 180;
|
|
81
|
+
const lower = reflected ? 180 - upperAngle : lowerAngle;
|
|
82
|
+
const upper = reflected ? 180 - lowerAngle : upperAngle;
|
|
83
|
+
const midpoint = ((lower + upper) / 2) * DEGREES_TO_RADIANS;
|
|
84
|
+
const halfWidth = ((upper - lower) / 2) * DEGREES_TO_RADIANS;
|
|
85
|
+
// Stable cos(h) - sin(h)/h, including very narrow angular intervals.
|
|
86
|
+
const squaredWidth = halfWidth * halfWidth;
|
|
87
|
+
const difference =
|
|
88
|
+
halfWidth < 0.001
|
|
89
|
+
? squaredWidth * (-1 / 3 + squaredWidth * (1 / 30 - squaredWidth / 840))
|
|
90
|
+
: Math.cos(halfWidth) - Math.sin(halfWidth) / halfWidth;
|
|
91
|
+
const sharedWeight = Math.sin(midpoint) * Math.sin(halfWidth);
|
|
92
|
+
const offsetWeight = Math.cos(midpoint) * difference;
|
|
93
|
+
const lowerWeight = Math.max(0, sharedWeight + offsetWeight);
|
|
94
|
+
const upperWeight = Math.max(0, sharedWeight - offsetWeight);
|
|
95
|
+
const offset = horizontalIndex * verticalAngles.length + verticalIndex;
|
|
96
|
+
rows[horizontalIndex] +=
|
|
97
|
+
values[offset] * (reflected ? upperWeight : lowerWeight) +
|
|
98
|
+
values[offset + 1] * (reflected ? lowerWeight : upperWeight);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let flux = 0;
|
|
102
|
+
if (horizontalSpan === 0) flux = rows[0] * 2 * Math.PI;
|
|
103
|
+
else {
|
|
104
|
+
for (let index = 0; index < rows.length - 1; index++) {
|
|
105
|
+
const angularWidth =
|
|
106
|
+
(horizontalAngles[index + 1] - horizontalAngles[index]) * DEGREES_TO_RADIANS;
|
|
107
|
+
flux += (rows[index] / 2 + rows[index + 1] / 2) * angularWidth;
|
|
108
|
+
}
|
|
109
|
+
flux *= 360 / horizontalSpan;
|
|
110
|
+
}
|
|
111
|
+
if (!Number.isFinite(flux)) throw new Error('Photometry: luminous flux overflow');
|
|
112
|
+
return flux;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Resamples photometry; no image decoding, world-axis conversion or GPU allocation occurs. */
|
|
116
|
+
export function resamplePhotometricProfile(
|
|
117
|
+
profile: PhotometricProfile,
|
|
118
|
+
options: PhotometricResampleOptions = {}
|
|
119
|
+
): PhotometricGrid {
|
|
120
|
+
const {verticalCount = 181, horizontalCount = 360, normalization = 'none'} = options;
|
|
121
|
+
if (
|
|
122
|
+
!Number.isSafeInteger(verticalCount) ||
|
|
123
|
+
verticalCount < 2 ||
|
|
124
|
+
!Number.isSafeInteger(horizontalCount) ||
|
|
125
|
+
horizontalCount < 1 ||
|
|
126
|
+
verticalCount * horizontalCount > MAX_GRID_SAMPLES ||
|
|
127
|
+
!['none', 'peak'].includes(normalization)
|
|
128
|
+
) {
|
|
129
|
+
throw new Error('Photometry: invalid resampling dimensions or normalization');
|
|
130
|
+
}
|
|
131
|
+
const prepared = preparePhotometricProfile(profile);
|
|
132
|
+
const verticalAngles = Float64Array.from(
|
|
133
|
+
{length: verticalCount},
|
|
134
|
+
(_, index) => (index * 180) / (verticalCount - 1)
|
|
135
|
+
);
|
|
136
|
+
const horizontalAngles = Float64Array.from(
|
|
137
|
+
{length: horizontalCount},
|
|
138
|
+
(_, index) => (index * 360) / horizontalCount
|
|
139
|
+
);
|
|
140
|
+
const data = new Float64Array(verticalCount * horizontalCount);
|
|
141
|
+
for (let horizontalIndex = 0; horizontalIndex < horizontalCount; horizontalIndex++) {
|
|
142
|
+
for (let verticalIndex = 0; verticalIndex < verticalCount; verticalIndex++) {
|
|
143
|
+
const intensity = samplePreparedProfile(
|
|
144
|
+
prepared,
|
|
145
|
+
verticalAngles[verticalIndex],
|
|
146
|
+
horizontalAngles[horizontalIndex]
|
|
147
|
+
);
|
|
148
|
+
data[horizontalIndex * verticalCount + verticalIndex] =
|
|
149
|
+
normalization === 'peak' ? (prepared.peak > 0 ? intensity / prepared.peak : 0) : intensity;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
width: verticalCount,
|
|
154
|
+
height: horizontalCount,
|
|
155
|
+
data,
|
|
156
|
+
verticalAngles,
|
|
157
|
+
horizontalAngles,
|
|
158
|
+
unit: normalization === 'peak' ? 'relative' : 'candela',
|
|
159
|
+
peakCandela: prepared.peak
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Validates and snapshots only the angular and intensity fields used by the calculations. */
|
|
164
|
+
function preparePhotometricProfile(profile: PhotometricProfile): PreparedPhotometricProfile {
|
|
165
|
+
const {verticalAngles, horizontalAngles, intensities, intensityScale = 1, symmetry} = profile;
|
|
166
|
+
if (
|
|
167
|
+
verticalAngles.length < 2 ||
|
|
168
|
+
horizontalAngles.length < 1 ||
|
|
169
|
+
intensities.length !== verticalAngles.length * horizontalAngles.length ||
|
|
170
|
+
!Number.isFinite(intensityScale) ||
|
|
171
|
+
intensityScale < 0
|
|
172
|
+
) {
|
|
173
|
+
throw new Error('Photometry: invalid calculation profile');
|
|
174
|
+
}
|
|
175
|
+
for (const [angles, maximum] of [
|
|
176
|
+
[verticalAngles, 180],
|
|
177
|
+
[horizontalAngles, 360]
|
|
178
|
+
] as const) {
|
|
179
|
+
for (let index = 0; index < angles.length; index++) {
|
|
180
|
+
if (
|
|
181
|
+
!Number.isFinite(angles[index]) ||
|
|
182
|
+
angles[index] < 0 ||
|
|
183
|
+
angles[index] > maximum ||
|
|
184
|
+
(index > 0 && angles[index] <= angles[index - 1])
|
|
185
|
+
)
|
|
186
|
+
throw new Error('Photometry: invalid calculation angles');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const first = horizontalAngles[0];
|
|
190
|
+
const last = horizontalAngles[horizontalAngles.length - 1];
|
|
191
|
+
const horizontalSpan = last - first;
|
|
192
|
+
const validSymmetry =
|
|
193
|
+
(symmetry === 'rotational' && horizontalAngles.length === 1) ||
|
|
194
|
+
(symmetry === 'quadrant' && horizontalAngles.length > 1 && first === 0 && last === 90) ||
|
|
195
|
+
(symmetry === 'bilateral' && horizontalAngles.length > 1 && horizontalSpan === 180) ||
|
|
196
|
+
(symmetry === 'none' && horizontalAngles.length > 1 && first === 0 && last === 360);
|
|
197
|
+
if (!validSymmetry) throw new Error('Photometry: symmetry does not match horizontal coverage');
|
|
198
|
+
let peak = 0;
|
|
199
|
+
const values = new Float64Array(intensities.length);
|
|
200
|
+
for (let index = 0; index < values.length; index++) {
|
|
201
|
+
const value = intensities[index];
|
|
202
|
+
const scaled = value * intensityScale;
|
|
203
|
+
if (!Number.isFinite(value) || value < 0 || !Number.isFinite(scaled))
|
|
204
|
+
throw new Error('Photometry: invalid calculation intensity');
|
|
205
|
+
values[index] = scaled;
|
|
206
|
+
peak = Math.max(peak, scaled);
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
verticalAngles: Float64Array.from(verticalAngles),
|
|
210
|
+
horizontalAngles: Float64Array.from(horizontalAngles),
|
|
211
|
+
values,
|
|
212
|
+
horizontalSpan,
|
|
213
|
+
peak
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Samples a validated snapshot, returning zero outside its measured vertical extent. */
|
|
218
|
+
function samplePreparedProfile(
|
|
219
|
+
profile: PreparedPhotometricProfile,
|
|
220
|
+
verticalAngle: number,
|
|
221
|
+
horizontalAngle: number
|
|
222
|
+
): number {
|
|
223
|
+
const {verticalAngles, horizontalAngles, values, horizontalSpan} = profile;
|
|
224
|
+
if (
|
|
225
|
+
verticalAngle < verticalAngles[0] ||
|
|
226
|
+
verticalAngle > verticalAngles[verticalAngles.length - 1]
|
|
227
|
+
)
|
|
228
|
+
return 0;
|
|
229
|
+
const verticalIndex = findLowerAngle(verticalAngles, verticalAngle);
|
|
230
|
+
const verticalWeight =
|
|
231
|
+
(verticalAngle - verticalAngles[verticalIndex]) /
|
|
232
|
+
(verticalAngles[verticalIndex + 1] - verticalAngles[verticalIndex]);
|
|
233
|
+
let horizontalIndex = 0;
|
|
234
|
+
let horizontalWeight = 0;
|
|
235
|
+
if (horizontalSpan > 0) {
|
|
236
|
+
const period = horizontalSpan === 360 ? 360 : horizontalSpan * 2;
|
|
237
|
+
let folded = (((horizontalAngle - horizontalAngles[0]) % period) + period) % period;
|
|
238
|
+
if (folded > horizontalSpan) folded = period - folded;
|
|
239
|
+
const measuredAngle = horizontalAngles[0] + folded;
|
|
240
|
+
horizontalIndex = findLowerAngle(horizontalAngles, measuredAngle);
|
|
241
|
+
horizontalWeight =
|
|
242
|
+
(measuredAngle - horizontalAngles[horizontalIndex]) /
|
|
243
|
+
(horizontalAngles[horizontalIndex + 1] - horizontalAngles[horizontalIndex]);
|
|
244
|
+
}
|
|
245
|
+
const lowerOffset = horizontalIndex * verticalAngles.length + verticalIndex;
|
|
246
|
+
const upperOffset = horizontalSpan === 0 ? lowerOffset : lowerOffset + verticalAngles.length;
|
|
247
|
+
const lowerValue =
|
|
248
|
+
values[lowerOffset] + (values[lowerOffset + 1] - values[lowerOffset]) * verticalWeight;
|
|
249
|
+
const upperValue =
|
|
250
|
+
values[upperOffset] + (values[upperOffset + 1] - values[upperOffset]) * verticalWeight;
|
|
251
|
+
return lowerValue + (upperValue - lowerValue) * horizontalWeight;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Finds the lower knot, keeping the final coordinate in the last interval. */
|
|
255
|
+
function findLowerAngle(angles: Float64Array, angle: number): number {
|
|
256
|
+
let lower = 0;
|
|
257
|
+
let upper = angles.length - 1;
|
|
258
|
+
while (upper - lower > 1) {
|
|
259
|
+
const midpoint = Math.floor((lower + upper) / 2);
|
|
260
|
+
if (angle < angles[midpoint]) upper = midpoint;
|
|
261
|
+
else lower = midpoint;
|
|
262
|
+
}
|
|
263
|
+
return Math.min(lower, angles.length - 2);
|
|
264
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {PrimitiveGeometryProps} from '../geometries/geometry-helpers';
|
|
5
|
+
import {ParametricGeometry, normalized} from './parametric-geometry';
|
|
6
|
+
export type LatheGeometryProps = PrimitiveGeometryProps & {
|
|
7
|
+
/** Ordered [radius, height] profile, with nonnegative radii. */
|
|
8
|
+
points: readonly (readonly [number, number])[];
|
|
9
|
+
segments?: number;
|
|
10
|
+
phiStart?: number;
|
|
11
|
+
phiLength?: number;
|
|
12
|
+
};
|
|
13
|
+
/** Revolves a piecewise-linear profile around Y; smooth profile normals, no end caps. */
|
|
14
|
+
export class LatheGeometry extends ParametricGeometry {
|
|
15
|
+
constructor(props: LatheGeometryProps) {
|
|
16
|
+
const {points, segments = 48, phiStart = 0, phiLength = Math.PI * 2} = props;
|
|
17
|
+
if (
|
|
18
|
+
!points ||
|
|
19
|
+
points.length < 2 ||
|
|
20
|
+
points.some(p => p.length !== 2 || !p.every(Number.isFinite) || p[0] < 0)
|
|
21
|
+
)
|
|
22
|
+
throw new RangeError('Lathe needs at least two finite [nonnegative radius, height] points');
|
|
23
|
+
if (
|
|
24
|
+
!Number.isFinite(phiStart) ||
|
|
25
|
+
!Number.isFinite(phiLength) ||
|
|
26
|
+
phiLength <= 0 ||
|
|
27
|
+
phiLength > Math.PI * 2
|
|
28
|
+
)
|
|
29
|
+
throw new RangeError('Invalid lathe angular sweep');
|
|
30
|
+
if (segments < 3) throw new RangeError('Lathe requires at least three angular segments');
|
|
31
|
+
const profile = points.map(p => [...p]);
|
|
32
|
+
const edgeNormals = profile.slice(1).map((p, i) => {
|
|
33
|
+
const dr = p[0] - profile[i][0],
|
|
34
|
+
dy = p[1] - profile[i][1];
|
|
35
|
+
if (dr === 0 && dy === 0) throw new RangeError('Consecutive profile points must differ');
|
|
36
|
+
return normalized([dy, -dr, 0]);
|
|
37
|
+
});
|
|
38
|
+
const profileNormals = profile.map((_, i) => {
|
|
39
|
+
const before = edgeNormals[Math.max(0, i - 1)],
|
|
40
|
+
after = edgeNormals[Math.min(i, edgeNormals.length - 1)];
|
|
41
|
+
return normalized(before.map((value, axis) => value + after[axis]));
|
|
42
|
+
});
|
|
43
|
+
const section = (v: number) => {
|
|
44
|
+
const coordinate = v * (profile.length - 1),
|
|
45
|
+
i = Math.min(profile.length - 2, Math.floor(coordinate));
|
|
46
|
+
return {i, t: coordinate - i};
|
|
47
|
+
};
|
|
48
|
+
super({
|
|
49
|
+
...props,
|
|
50
|
+
uSegments: segments,
|
|
51
|
+
vSegments: profile.length - 1,
|
|
52
|
+
periodicU: phiLength === Math.PI * 2,
|
|
53
|
+
sample: (u, v) => {
|
|
54
|
+
const {i, t} = section(v),
|
|
55
|
+
radius = profile[i][0] * (1 - t) + profile[i + 1][0] * t,
|
|
56
|
+
height = profile[i][1] * (1 - t) + profile[i + 1][1] * t,
|
|
57
|
+
theta = phiStart + u * phiLength;
|
|
58
|
+
return [radius * Math.cos(theta), height, -radius * Math.sin(theta)];
|
|
59
|
+
},
|
|
60
|
+
normal: (u, v) => {
|
|
61
|
+
const {i, t} = section(v),
|
|
62
|
+
n = profileNormals[i].map(
|
|
63
|
+
(value, axis) => value * (1 - t) + profileNormals[i + 1][axis] * t
|
|
64
|
+
),
|
|
65
|
+
theta = phiStart + u * phiLength;
|
|
66
|
+
return [n[0] * Math.cos(theta), n[1], -n[0] * Math.sin(theta)];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {Geometry} from '../lib/geometry';
|
|
5
|
+
import {assertSegments, type PrimitiveGeometryProps} from '../geometries/geometry-helpers';
|
|
6
|
+
|
|
7
|
+
export type SurfaceSampler = (u: number, v: number) => Readonly<ArrayLike<number>>;
|
|
8
|
+
export type ParametricGeometryProps = PrimitiveGeometryProps & {
|
|
9
|
+
/** Samples the normalized [0,1]² parameter domain. */
|
|
10
|
+
sample: SurfaceSampler;
|
|
11
|
+
/** Optional analytic normals; otherwise estimated from neighboring samples. */
|
|
12
|
+
normal?: SurfaceSampler;
|
|
13
|
+
uSegments?: number;
|
|
14
|
+
vSegments?: number;
|
|
15
|
+
/** Closed axes duplicate their first position/normal at UV 1. */
|
|
16
|
+
periodicU?: boolean;
|
|
17
|
+
periodicV?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Indexed surface grid. Front faces and normals follow ∂P/∂u × ∂P/∂v. */
|
|
21
|
+
export class ParametricGeometry extends Geometry {
|
|
22
|
+
constructor(props: ParametricGeometryProps) {
|
|
23
|
+
const {
|
|
24
|
+
sample,
|
|
25
|
+
normal,
|
|
26
|
+
uSegments = 32,
|
|
27
|
+
vSegments = 32,
|
|
28
|
+
periodicU = false,
|
|
29
|
+
periodicV = false
|
|
30
|
+
} = props;
|
|
31
|
+
assertSegments(uSegments, 'uSegments');
|
|
32
|
+
assertSegments(vSegments, 'vSegments');
|
|
33
|
+
const count = (uSegments + 1) * (vSegments + 1);
|
|
34
|
+
const indexCount = uSegments * vSegments * 6;
|
|
35
|
+
if (!Number.isSafeInteger(indexCount) || indexCount > 0xffffffff)
|
|
36
|
+
throw new RangeError('Surface exceeds 32-bit index-buffer length');
|
|
37
|
+
if (!Number.isSafeInteger(count) || count > 0xffffffff)
|
|
38
|
+
throw new RangeError('Surface exceeds 32-bit indexing');
|
|
39
|
+
const positions = new Float32Array(count * 3),
|
|
40
|
+
normals = new Float32Array(count * 3),
|
|
41
|
+
uvs = new Float32Array(count * 2);
|
|
42
|
+
const canonical = (value: number, periodic: boolean) =>
|
|
43
|
+
periodic ? ((value % 1) + 1) % 1 : Math.max(0, Math.min(1, value));
|
|
44
|
+
const evaluate = (u: number, v: number) =>
|
|
45
|
+
readVector(sample(canonical(u, periodicU), canonical(v, periodicV)));
|
|
46
|
+
// A small finite-difference step estimates smooth-surface normals independently
|
|
47
|
+
// of tessellation density. Open boundaries use one-sided differences.
|
|
48
|
+
const step = 1e-5;
|
|
49
|
+
let row = 0;
|
|
50
|
+
for (let j = 0; j <= vSegments; j++)
|
|
51
|
+
for (let i = 0; i <= uSegments; i++, row++) {
|
|
52
|
+
const u = i / uSegments,
|
|
53
|
+
v = j / vSegments;
|
|
54
|
+
const sampleU = canonical(u, periodicU),
|
|
55
|
+
sampleV = canonical(v, periodicV);
|
|
56
|
+
positions.set(evaluate(sampleU, sampleV), row * 3);
|
|
57
|
+
let n: number[];
|
|
58
|
+
if (normal) n = readVector(normal(sampleU, sampleV));
|
|
59
|
+
else {
|
|
60
|
+
const left = evaluate(sampleU - step, sampleV),
|
|
61
|
+
right = evaluate(sampleU + step, sampleV);
|
|
62
|
+
const below = evaluate(sampleU, sampleV - step),
|
|
63
|
+
above = evaluate(sampleU, sampleV + step);
|
|
64
|
+
const du = normalized(right.map((value, axis) => value - left[axis]));
|
|
65
|
+
const dv = normalized(above.map((value, axis) => value - below[axis]));
|
|
66
|
+
n = [
|
|
67
|
+
du[1] * dv[2] - du[2] * dv[1],
|
|
68
|
+
du[2] * dv[0] - du[0] * dv[2],
|
|
69
|
+
du[0] * dv[1] - du[1] * dv[0]
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
normals.set(normalized(n), row * 3);
|
|
73
|
+
uvs.set([u, v], row * 2);
|
|
74
|
+
}
|
|
75
|
+
for (const value of positions)
|
|
76
|
+
if (!Number.isFinite(value))
|
|
77
|
+
throw new RangeError('Positions must be representable as Float32');
|
|
78
|
+
const indices = count > 0xffff ? new Uint32Array(indexCount) : new Uint16Array(indexCount);
|
|
79
|
+
const stride = uSegments + 1;
|
|
80
|
+
let cursor = 0;
|
|
81
|
+
for (let j = 0; j < vSegments; j++)
|
|
82
|
+
for (let i = 0; i < uSegments; i++) {
|
|
83
|
+
const a = j * stride + i,
|
|
84
|
+
b = a + 1,
|
|
85
|
+
c = a + stride,
|
|
86
|
+
d = c + 1;
|
|
87
|
+
indices[cursor++] = a;
|
|
88
|
+
indices[cursor++] = b;
|
|
89
|
+
indices[cursor++] = d;
|
|
90
|
+
indices[cursor++] = a;
|
|
91
|
+
indices[cursor++] = d;
|
|
92
|
+
indices[cursor++] = c;
|
|
93
|
+
}
|
|
94
|
+
super({
|
|
95
|
+
id: props.id,
|
|
96
|
+
topology: 'triangle-list',
|
|
97
|
+
indices,
|
|
98
|
+
attributes: {
|
|
99
|
+
POSITION: {size: 3, value: positions},
|
|
100
|
+
NORMAL: {size: 3, value: normals},
|
|
101
|
+
TEXCOORD_0: {size: 2, value: uvs},
|
|
102
|
+
...props.attributes
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function readVector(value: Readonly<ArrayLike<number>>): number[] {
|
|
108
|
+
if (!value || value.length !== 3 || !Array.from(value).every(Number.isFinite))
|
|
109
|
+
throw new RangeError('Surface samples and normals must be finite triples');
|
|
110
|
+
return Array.from(value);
|
|
111
|
+
}
|
|
112
|
+
export function normalized(vector: number[]): number[] {
|
|
113
|
+
const scale = Math.max(...vector.map(Math.abs));
|
|
114
|
+
if (!scale) return [0, 0, 0];
|
|
115
|
+
const scaled = vector.map(value => value / scale),
|
|
116
|
+
length = Math.hypot(...scaled);
|
|
117
|
+
return scaled.map(value => (value === 0 ? 0 : value / length));
|
|
118
|
+
}
|