@math.gl/geometry 5.0.0-alpha.9 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +97 -49
- package/README.md +16 -1
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/culling/constants.d.ts +3 -0
- package/dist/culling/constants.d.ts.map +1 -0
- package/dist/culling/constants.js +5 -0
- package/dist/culling/constants.js.map +1 -0
- package/dist/culling/index.cjs +2124 -0
- package/dist/culling/index.cjs.map +6 -0
- package/dist/culling/index.d.ts +31 -0
- package/dist/culling/index.d.ts.map +1 -0
- package/dist/culling/index.js +25 -0
- package/dist/culling/index.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
- package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
- package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
- package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +7 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +26 -0
- package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +116 -0
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
- package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
- package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +62 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +230 -0
- package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
- package/dist/culling/lib/culling-volume.d.ts +46 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -0
- package/dist/culling/lib/culling-volume.js +126 -0
- package/dist/culling/lib/culling-volume.js.map +1 -0
- package/dist/culling/lib/perspective-frustum.d.ts +153 -0
- package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-frustum.js +191 -0
- package/dist/culling/lib/perspective-frustum.js.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
- package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
- package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
- package/dist/culling/lib/plane.d.ts +35 -0
- package/dist/culling/lib/plane.d.ts.map +1 -0
- package/dist/culling/lib/plane.js +90 -0
- package/dist/culling/lib/plane.js.map +1 -0
- package/dist/culling/lib/ray.d.ts +13 -0
- package/dist/culling/lib/ray.d.ts.map +1 -0
- package/dist/culling/lib/ray.js +30 -0
- package/dist/culling/lib/ray.js.map +1 -0
- package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
- package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/box-shape.js +69 -0
- package/dist/culling/lib/shapes/box-shape.js.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
- package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/capsule-shape.js +151 -0
- package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
- package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
- package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
- package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/implicit-shape.js +142 -0
- package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
- package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/plane-shape.js +71 -0
- package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
- package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
- package/dist/culling/lib/shapes/sphere-shape.js +43 -0
- package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
- package/dist/culling/oriented-box-2d.d.ts +22 -0
- package/dist/culling/oriented-box-2d.d.ts.map +1 -0
- package/dist/culling/oriented-box-2d.js +86 -0
- package/dist/culling/oriented-box-2d.js.map +1 -0
- package/dist/culling/queries.d.ts +44 -0
- package/dist/culling/queries.d.ts.map +1 -0
- package/dist/culling/queries.js +259 -0
- package/dist/culling/queries.js.map +1 -0
- package/dist/curves/bezier-curves.d.ts +18 -0
- package/dist/curves/bezier-curves.d.ts.map +1 -0
- package/dist/curves/bezier-curves.js +54 -0
- package/dist/curves/bezier-curves.js.map +1 -0
- package/dist/curves/catmull-rom-curve.d.ts +15 -0
- package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
- package/dist/curves/catmull-rom-curve.js +77 -0
- package/dist/curves/catmull-rom-curve.js.map +1 -0
- package/dist/curves/curve-arc-length.d.ts +17 -0
- package/dist/curves/curve-arc-length.d.ts.map +1 -0
- package/dist/curves/curve-arc-length.js +58 -0
- package/dist/curves/curve-arc-length.js.map +1 -0
- package/dist/curves/curve.d.ts +23 -0
- package/dist/curves/curve.d.ts.map +1 -0
- package/dist/curves/curve.js +77 -0
- package/dist/curves/curve.js.map +1 -0
- package/dist/curves/hermite-curve.d.ts +9 -0
- package/dist/curves/hermite-curve.d.ts.map +1 -0
- package/dist/curves/hermite-curve.js +24 -0
- package/dist/curves/hermite-curve.js.map +1 -0
- package/dist/curves/index.d.ts +8 -0
- package/dist/curves/index.d.ts.map +1 -0
- package/dist/curves/index.js +9 -0
- package/dist/curves/index.js.map +1 -0
- package/dist/geometries/box-geometry.js +1 -1
- package/dist/geometries/box-geometry.js.map +1 -1
- package/dist/geometries/capsule-geometry.js +1 -1
- package/dist/geometries/capsule-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/geometry-helpers.js +1 -1
- package/dist/geometries/geometry-helpers.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/primitive-mesh-builder.d.ts +24 -0
- package/dist/geometries/primitive-mesh-builder.d.ts.map +1 -0
- package/dist/geometries/primitive-mesh-builder.js +74 -0
- package/dist/geometries/primitive-mesh-builder.js.map +1 -0
- package/dist/geometries/prism-geometry.d.ts +13 -0
- package/dist/geometries/prism-geometry.d.ts.map +1 -0
- package/dist/geometries/prism-geometry.js +34 -0
- package/dist/geometries/prism-geometry.js.map +1 -0
- package/dist/geometries/ring-geometry.d.ts +15 -0
- package/dist/geometries/ring-geometry.d.ts.map +1 -0
- package/dist/geometries/ring-geometry.js +64 -0
- package/dist/geometries/ring-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/surface-of-revolution.js +1 -1
- package/dist/geometries/surface-of-revolution.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +1 -1
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/index.cjs +6105 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/geometry-utils.js +1 -1
- package/dist/lib/geometry-utils.js.map +1 -1
- package/dist/lib/geometry.d.ts +1 -1
- package/dist/lib/geometry.d.ts.map +1 -1
- package/dist/lib/geometry.js +1 -1
- package/dist/lib/geometry.js.map +1 -1
- package/dist/lib/hinge-tree.d.ts +33 -0
- package/dist/lib/hinge-tree.d.ts.map +1 -0
- package/dist/lib/hinge-tree.js +144 -0
- package/dist/lib/hinge-tree.js.map +1 -0
- package/dist/parametric/lathe-geometry.d.ts +14 -0
- package/dist/parametric/lathe-geometry.d.ts.map +1 -0
- package/dist/parametric/lathe-geometry.js +48 -0
- package/dist/parametric/lathe-geometry.js.map +1 -0
- package/dist/parametric/parametric-geometry.d.ts +20 -0
- package/dist/parametric/parametric-geometry.d.ts.map +1 -0
- package/dist/parametric/parametric-geometry.js +88 -0
- package/dist/parametric/parametric-geometry.js.map +1 -0
- package/dist/parametric/torus-geometry.d.ts +19 -0
- package/dist/parametric/torus-geometry.d.ts.map +1 -0
- package/dist/parametric/torus-geometry.js +89 -0
- package/dist/parametric/torus-geometry.js.map +1 -0
- package/dist/parametric.d.ts +7 -0
- package/dist/parametric.d.ts.map +1 -0
- package/dist/parametric.js +7 -0
- package/dist/parametric.js.map +1 -0
- package/dist/polygon/clip-triangle-mesh.d.ts +41 -0
- package/dist/polygon/clip-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/clip-triangle-mesh.js +155 -0
- package/dist/polygon/clip-triangle-mesh.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts +24 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -0
- package/dist/polygon/cut-by-grid.js +221 -0
- package/dist/polygon/cut-by-grid.js.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
- package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
- package/dist/polygon/cut-by-mercator-bounds.js +149 -0
- package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
- package/dist/polygon/earcut.d.ts +13 -0
- package/dist/polygon/earcut.d.ts.map +1 -0
- package/dist/polygon/earcut.js +693 -0
- package/dist/polygon/earcut.js.map +1 -0
- package/dist/polygon/index.d.ts +14 -0
- package/dist/polygon/index.d.ts.map +1 -0
- package/dist/polygon/index.js +13 -0
- package/dist/polygon/index.js.map +1 -0
- package/dist/polygon/lineclip.d.ts +31 -0
- package/dist/polygon/lineclip.d.ts.map +1 -0
- package/dist/polygon/lineclip.js +184 -0
- package/dist/polygon/lineclip.js.map +1 -0
- package/dist/polygon/polygon-utils.d.ts +103 -0
- package/dist/polygon/polygon-utils.d.ts.map +1 -0
- package/dist/polygon/polygon-utils.js +155 -0
- package/dist/polygon/polygon-utils.js.map +1 -0
- package/dist/polygon/polygon.d.ts +41 -0
- package/dist/polygon/polygon.d.ts.map +1 -0
- package/dist/polygon/polygon.js +76 -0
- package/dist/polygon/polygon.js.map +1 -0
- package/dist/polygon/subdivide-polyline.d.ts +56 -0
- package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
- package/dist/polygon/subdivide-polyline.js +141 -0
- package/dist/polygon/subdivide-polyline.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +78 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.js +238 -0
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
- package/dist/polygon/utils.d.ts +5 -0
- package/dist/polygon/utils.d.ts.map +1 -0
- package/dist/polygon/utils.js +38 -0
- package/dist/polygon/utils.js.map +1 -0
- package/dist/spatial-index/box-index.d.ts +86 -0
- package/dist/spatial-index/box-index.d.ts.map +1 -0
- package/dist/spatial-index/box-index.js +335 -0
- package/dist/spatial-index/box-index.js.map +1 -0
- package/dist/spatial-index/index.d.ts +7 -0
- package/dist/spatial-index/index.d.ts.map +1 -0
- package/dist/spatial-index/index.js +6 -0
- package/dist/spatial-index/index.js.map +1 -0
- package/dist/spatial-index/triangle-bvh.d.ts +74 -0
- package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
- package/dist/spatial-index/triangle-bvh.js +221 -0
- package/dist/spatial-index/triangle-bvh.js.map +1 -0
- package/dist/utils/attribute-compression.d.ts +50 -0
- package/dist/utils/attribute-compression.d.ts.map +1 -0
- package/dist/utils/attribute-compression.js +186 -0
- package/dist/utils/attribute-compression.js.map +1 -0
- package/dist/utils/attribute-iterator.d.ts +8 -0
- package/dist/utils/attribute-iterator.d.ts.map +1 -0
- package/dist/utils/attribute-iterator.js +25 -0
- package/dist/utils/attribute-iterator.js.map +1 -0
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +4 -0
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
- package/dist/utils/compute-vertex-normals.js +54 -0
- package/dist/utils/compute-vertex-normals.js.map +1 -0
- package/dist/utils/constants.d.ts +52 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +39 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coordinates.d.ts +3 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +8 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/dist/utils/geometry.d.ts +20 -0
- package/dist/utils/geometry.d.ts.map +1 -0
- package/dist/utils/geometry.js +31 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/gl-type.d.ts +17 -0
- package/dist/utils/gl-type.d.ts.map +1 -0
- package/dist/utils/gl-type.js +69 -0
- package/dist/utils/gl-type.js.map +1 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
- package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
- package/dist/utils/interpolate-packed-attributes.js +192 -0
- package/dist/utils/interpolate-packed-attributes.js.map +1 -0
- package/dist/utils/mesh-processing.d.ts +18 -0
- package/dist/utils/mesh-processing.d.ts.map +1 -0
- package/dist/utils/mesh-processing.js +300 -0
- package/dist/utils/mesh-processing.js.map +1 -0
- package/dist/utils/primitive-iterator.d.ts +21 -0
- package/dist/utils/primitive-iterator.d.ts.map +1 -0
- package/dist/utils/primitive-iterator.js +117 -0
- package/dist/utils/primitive-iterator.js.map +1 -0
- package/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/dist/utils/rgb565.d.ts +5 -0
- package/dist/utils/rgb565.d.ts.map +1 -0
- package/dist/utils/rgb565.js +24 -0
- package/dist/utils/rgb565.js.map +1 -0
- package/dist/utils/typed-array-utils.d.ts +3 -0
- package/dist/utils/typed-array-utils.d.ts.map +1 -0
- package/dist/utils/typed-array-utils.js +16 -0
- package/dist/utils/typed-array-utils.js.map +1 -0
- package/package.json +12 -4
- package/src/culling/constants.ts +6 -0
- package/src/culling/index.ts +55 -0
- package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
- package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
- package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
- package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +32 -0
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
- package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
- package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
- package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +320 -0
- package/src/culling/lib/culling-volume.ts +163 -0
- package/src/culling/lib/perspective-frustum.ts +288 -0
- package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
- package/src/culling/lib/plane.ts +118 -0
- package/src/culling/lib/ray.ts +33 -0
- package/src/culling/lib/shapes/box-shape.ts +78 -0
- package/src/culling/lib/shapes/capsule-shape.ts +232 -0
- package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
- package/src/culling/lib/shapes/implicit-shape.ts +209 -0
- package/src/culling/lib/shapes/plane-shape.ts +78 -0
- package/src/culling/lib/shapes/sphere-shape.ts +60 -0
- package/src/culling/oriented-box-2d.ts +165 -0
- package/src/culling/queries.ts +332 -0
- package/src/curves/bezier-curves.ts +62 -0
- package/src/curves/catmull-rom-curve.ts +89 -0
- package/src/curves/curve-arc-length.ts +70 -0
- package/src/curves/curve.ts +96 -0
- package/src/curves/hermite-curve.ts +34 -0
- package/src/curves/index.ts +15 -0
- package/src/geometries/box-geometry.ts +1 -1
- package/src/geometries/capsule-geometry.ts +1 -1
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/geometry-helpers.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/primitive-mesh-builder.ts +84 -0
- package/src/geometries/prism-geometry.ts +57 -0
- package/src/geometries/ring-geometry.ts +102 -0
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/surface-of-revolution.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +1 -1
- package/src/index.ts +179 -1
- package/src/lib/geometry-utils.ts +2 -2
- package/src/lib/geometry.ts +2 -2
- package/src/lib/hinge-tree.ts +170 -0
- package/src/parametric/lathe-geometry.ts +70 -0
- package/src/parametric/parametric-geometry.ts +118 -0
- package/src/parametric/torus-geometry.ts +118 -0
- package/src/parametric.ts +9 -0
- package/src/polygon/clip-triangle-mesh.ts +218 -0
- package/src/polygon/cut-by-grid.ts +313 -0
- package/src/polygon/cut-by-mercator-bounds.ts +204 -0
- package/src/polygon/earcut.ts +859 -0
- package/src/polygon/index.ts +42 -0
- package/src/polygon/lineclip.ts +218 -0
- package/src/polygon/polygon-utils.ts +273 -0
- package/src/polygon/polygon.ts +105 -0
- package/src/polygon/subdivide-polyline.ts +223 -0
- package/src/polygon/subdivide-triangle-mesh.ts +342 -0
- package/src/polygon/utils.ts +50 -0
- package/src/spatial-index/box-index.ts +452 -0
- package/src/spatial-index/index.ts +20 -0
- package/src/spatial-index/triangle-bvh.ts +345 -0
- package/src/utils/attribute-compression.ts +234 -0
- package/src/utils/attribute-iterator.ts +28 -0
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +63 -0
- package/src/utils/constants.ts +42 -0
- package/src/utils/coordinates.ts +8 -0
- package/src/utils/geometry.ts +49 -0
- package/src/utils/gl-type.ts +87 -0
- package/src/utils/index.ts +55 -0
- package/src/utils/interpolate-packed-attributes.ts +284 -0
- package/src/utils/mesh-processing.ts +377 -0
- package/src/utils/primitive-iterator.ts +145 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/src/utils/rgb565.ts +26 -0
- package/src/utils/typed-array-utils.ts +16 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
|
|
7
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
8
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
|
+
|
|
10
|
+
// Note: This class is still an experimental export, mainly used by other test cases
|
|
11
|
+
// - It has not been fully adapted to math.gl conventions
|
|
12
|
+
// - Documentation has not been ported
|
|
13
|
+
|
|
14
|
+
import {NumericArray} from '@math.gl/core';
|
|
15
|
+
import {assert, Matrix4, Vector2} from '@math.gl/core';
|
|
16
|
+
import {PerspectiveOffCenterFrustum} from './perspective-off-center-frustum';
|
|
17
|
+
import {CullingVolume} from './culling-volume';
|
|
18
|
+
|
|
19
|
+
const defined = (val: unknown) => val !== null && typeof val !== 'undefined';
|
|
20
|
+
|
|
21
|
+
type PerspectiveFrustumOptions = {
|
|
22
|
+
/** The angle of the field of view (FOV), in radians. */
|
|
23
|
+
fov?: number;
|
|
24
|
+
/** The aspect ratio of the frustum's width to it's height. */
|
|
25
|
+
aspectRatio?: number;
|
|
26
|
+
/** The distance of the near plane. */
|
|
27
|
+
near?: number;
|
|
28
|
+
/** The distance of the far plane. */
|
|
29
|
+
far?: number;
|
|
30
|
+
/** The offset in the x direction. */
|
|
31
|
+
xOffset?: number;
|
|
32
|
+
/** The offset in the y direction. */
|
|
33
|
+
yOffset?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The viewing frustum is defined by 6 planes.
|
|
38
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
39
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
40
|
+
* plane from the origin/camera position.
|
|
41
|
+
*
|
|
42
|
+
* @alias PerspectiveFrustum
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var frustum = new PerspectiveFrustum({
|
|
46
|
+
* fov : Math.PI_OVER_THREE,
|
|
47
|
+
* aspectRatio : canvas.clientWidth / canvas.clientHeight
|
|
48
|
+
* near : 1.0,
|
|
49
|
+
* far : 1000.0
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* @see PerspectiveOffCenterFrustum
|
|
53
|
+
*/
|
|
54
|
+
export class PerspectiveFrustum {
|
|
55
|
+
private _offCenterFrustum = new PerspectiveOffCenterFrustum();
|
|
56
|
+
/**
|
|
57
|
+
* The angle of the field of view (FOV), in radians. This angle will be used
|
|
58
|
+
* as the horizontal FOV if the width is greater than the height, otherwise
|
|
59
|
+
* it will be the vertical FOV.
|
|
60
|
+
*/
|
|
61
|
+
fov?: number;
|
|
62
|
+
private _fov: number;
|
|
63
|
+
private _fovy: number;
|
|
64
|
+
private _sseDenominator: number;
|
|
65
|
+
/**
|
|
66
|
+
* The aspect ratio of the frustum's width to it's height.
|
|
67
|
+
*/
|
|
68
|
+
aspectRatio?: number;
|
|
69
|
+
private _aspectRatio: number;
|
|
70
|
+
/**
|
|
71
|
+
* The distance of the near plane.
|
|
72
|
+
* @default 1.0
|
|
73
|
+
*/
|
|
74
|
+
near: number;
|
|
75
|
+
private _near: number;
|
|
76
|
+
/**
|
|
77
|
+
* The distance of the far plane.
|
|
78
|
+
* @default 500000000.0
|
|
79
|
+
*/
|
|
80
|
+
far: number;
|
|
81
|
+
private _far: number;
|
|
82
|
+
/**
|
|
83
|
+
* Offsets the frustum in the x direction.
|
|
84
|
+
* @default 0.0
|
|
85
|
+
*/
|
|
86
|
+
xOffset: number;
|
|
87
|
+
private _xOffset: number;
|
|
88
|
+
/**
|
|
89
|
+
* Offsets the frustum in the y direction.
|
|
90
|
+
* @default 0.0
|
|
91
|
+
*/
|
|
92
|
+
yOffset: number;
|
|
93
|
+
private _yOffset: number;
|
|
94
|
+
|
|
95
|
+
constructor(options: PerspectiveFrustumOptions = {}) {
|
|
96
|
+
const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;
|
|
97
|
+
|
|
98
|
+
this.fov = fov;
|
|
99
|
+
this.aspectRatio = aspectRatio;
|
|
100
|
+
this.near = near;
|
|
101
|
+
this.far = far;
|
|
102
|
+
this.xOffset = xOffset;
|
|
103
|
+
this.yOffset = yOffset;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns a duplicate of a PerspectiveFrustum instance.
|
|
108
|
+
*/
|
|
109
|
+
clone(): PerspectiveFrustum {
|
|
110
|
+
return new PerspectiveFrustum({
|
|
111
|
+
aspectRatio: this.aspectRatio,
|
|
112
|
+
fov: this.fov,
|
|
113
|
+
near: this.near,
|
|
114
|
+
far: this.far
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Compares the provided PerspectiveFrustum componentwise and returns
|
|
120
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
121
|
+
*/
|
|
122
|
+
equals(other: PerspectiveFrustum): boolean {
|
|
123
|
+
if (!defined(other) || !(other instanceof PerspectiveFrustum)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this._update();
|
|
128
|
+
other._update();
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
this.fov === other.fov &&
|
|
132
|
+
this.aspectRatio === other.aspectRatio &&
|
|
133
|
+
this.near === other.near &&
|
|
134
|
+
this.far === other.far &&
|
|
135
|
+
this._offCenterFrustum.equals(other._offCenterFrustum)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the perspective projection matrix computed from the view this.
|
|
141
|
+
*/
|
|
142
|
+
get projectionMatrix(): Matrix4 {
|
|
143
|
+
this._update();
|
|
144
|
+
return this._offCenterFrustum.projectionMatrix;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
149
|
+
*/
|
|
150
|
+
get infiniteProjectionMatrix(): Matrix4 {
|
|
151
|
+
this._update();
|
|
152
|
+
return this._offCenterFrustum.infiniteProjectionMatrix;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Gets the angle of the vertical field of view, in radians.
|
|
157
|
+
*/
|
|
158
|
+
get fovy(): number {
|
|
159
|
+
this._update();
|
|
160
|
+
return this._fovy;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @private
|
|
165
|
+
*/
|
|
166
|
+
get sseDenominator(): number {
|
|
167
|
+
this._update();
|
|
168
|
+
return this._sseDenominator;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Creates a culling volume for this this.ion.
|
|
173
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // Check if a bounding volume intersects the this.
|
|
177
|
+
* var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
178
|
+
* var intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
179
|
+
*/
|
|
180
|
+
computeCullingVolume(
|
|
181
|
+
/** A Vector3 defines the eye position. */
|
|
182
|
+
position: Readonly<NumericArray>,
|
|
183
|
+
/** A Vector3 defines the view direction. */
|
|
184
|
+
direction: Readonly<NumericArray>,
|
|
185
|
+
/** A Vector3 defines the up direction. */
|
|
186
|
+
up: Readonly<NumericArray>
|
|
187
|
+
): CullingVolume {
|
|
188
|
+
this._update();
|
|
189
|
+
return this._offCenterFrustum.computeCullingVolume(position, direction, up);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Returns the pixel's width and height in meters.
|
|
194
|
+
* @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.
|
|
195
|
+
*
|
|
196
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
197
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* // Example 1
|
|
201
|
+
* // Get the width and height of a pixel.
|
|
202
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* // Example 2
|
|
206
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
207
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
208
|
+
* var position = camera.position;
|
|
209
|
+
* var direction = camera.direction;
|
|
210
|
+
* var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
211
|
+
* var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
212
|
+
* var distance = Vector3.magnitude(toCenterProj);
|
|
213
|
+
* var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
214
|
+
*/
|
|
215
|
+
getPixelDimensions(
|
|
216
|
+
/** The width of the drawing buffer. */
|
|
217
|
+
drawingBufferWidth: number,
|
|
218
|
+
/** The height of the drawing buffer. */
|
|
219
|
+
drawingBufferHeight: number,
|
|
220
|
+
/** The distance to the near plane in meters. */
|
|
221
|
+
distance: number,
|
|
222
|
+
/** The object onto which to store the result. */
|
|
223
|
+
result?: Vector2
|
|
224
|
+
): Vector2 {
|
|
225
|
+
this._update();
|
|
226
|
+
return this._offCenterFrustum.getPixelDimensions(
|
|
227
|
+
drawingBufferWidth,
|
|
228
|
+
drawingBufferHeight,
|
|
229
|
+
distance,
|
|
230
|
+
result || new Vector2()
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// eslint-disable-next-line complexity, max-statements
|
|
235
|
+
private _update(): void {
|
|
236
|
+
assert(
|
|
237
|
+
Number.isFinite(this.fov) &&
|
|
238
|
+
Number.isFinite(this.aspectRatio) &&
|
|
239
|
+
Number.isFinite(this.near) &&
|
|
240
|
+
Number.isFinite(this.far)
|
|
241
|
+
);
|
|
242
|
+
// 'fov, aspectRatio, near, or far parameters are not set.'
|
|
243
|
+
|
|
244
|
+
const f = this._offCenterFrustum;
|
|
245
|
+
|
|
246
|
+
if (
|
|
247
|
+
this.fov !== this._fov ||
|
|
248
|
+
this.aspectRatio !== this._aspectRatio ||
|
|
249
|
+
this.near !== this._near ||
|
|
250
|
+
this.far !== this._far ||
|
|
251
|
+
this.xOffset !== this._xOffset ||
|
|
252
|
+
this.yOffset !== this._yOffset
|
|
253
|
+
) {
|
|
254
|
+
assert(this.fov >= 0 && this.fov < Math.PI);
|
|
255
|
+
// throw new DeveloperError('fov must be in the range [0, PI).');
|
|
256
|
+
|
|
257
|
+
assert(this.aspectRatio > 0);
|
|
258
|
+
// throw new DeveloperError('aspectRatio must be positive.');
|
|
259
|
+
|
|
260
|
+
assert(this.near >= 0 && this.near < this.far);
|
|
261
|
+
// throw new DeveloperError('near must be greater than zero and less than far.');
|
|
262
|
+
|
|
263
|
+
this._aspectRatio = this.aspectRatio;
|
|
264
|
+
this._fov = this.fov;
|
|
265
|
+
this._fovy =
|
|
266
|
+
this.aspectRatio <= 1
|
|
267
|
+
? this.fov
|
|
268
|
+
: Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
|
|
269
|
+
this._near = this.near;
|
|
270
|
+
this._far = this.far;
|
|
271
|
+
this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
|
|
272
|
+
this._xOffset = this.xOffset;
|
|
273
|
+
this._yOffset = this.yOffset;
|
|
274
|
+
|
|
275
|
+
f.top = this.near * Math.tan(0.5 * this._fovy);
|
|
276
|
+
f.bottom = -f.top;
|
|
277
|
+
f.right = this.aspectRatio * f.top;
|
|
278
|
+
f.left = -f.right;
|
|
279
|
+
f.near = this.near;
|
|
280
|
+
f.far = this.far;
|
|
281
|
+
|
|
282
|
+
f.right += this.xOffset;
|
|
283
|
+
f.left += this.xOffset;
|
|
284
|
+
f.top += this.yOffset;
|
|
285
|
+
f.bottom += this.yOffset;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
|
|
4
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
5
|
+
// SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
|
|
6
|
+
|
|
7
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
8
|
+
// See ../../../LICENSE for the retained Cesium notice and Apache-2.0 terms.
|
|
9
|
+
|
|
10
|
+
// Note: This class is still an experimental export, mainly used by other test cases
|
|
11
|
+
// - It has not been fully adapted to math.gl conventions
|
|
12
|
+
// - Documentation has not been ported
|
|
13
|
+
|
|
14
|
+
import {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';
|
|
15
|
+
import {CullingVolume} from './culling-volume';
|
|
16
|
+
import {Plane} from './plane';
|
|
17
|
+
|
|
18
|
+
const scratchPlaneUpVector = new Vector3();
|
|
19
|
+
const scratchPlaneRightVector = new Vector3();
|
|
20
|
+
const scratchPlaneNearCenter = new Vector3();
|
|
21
|
+
const scratchPlaneFarCenter = new Vector3();
|
|
22
|
+
const scratchPlaneNormal = new Vector3();
|
|
23
|
+
|
|
24
|
+
type PerspectiveOffCenterFrustumOptions = {
|
|
25
|
+
left?: number;
|
|
26
|
+
right?: number;
|
|
27
|
+
top?: number;
|
|
28
|
+
bottom?: number;
|
|
29
|
+
near?: number;
|
|
30
|
+
far?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export class PerspectiveOffCenterFrustum {
|
|
34
|
+
/**
|
|
35
|
+
* Defines the left clipping plane.
|
|
36
|
+
* @type {Number}
|
|
37
|
+
* @default undefined
|
|
38
|
+
*/
|
|
39
|
+
left?: number;
|
|
40
|
+
private _left?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Defines the right clipping plane.
|
|
43
|
+
* @type {Number}
|
|
44
|
+
* @default undefined
|
|
45
|
+
*/
|
|
46
|
+
right?: number;
|
|
47
|
+
private _right?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Defines the top clipping plane.
|
|
50
|
+
* @type {Number}
|
|
51
|
+
* @default undefined
|
|
52
|
+
*/
|
|
53
|
+
top?: number;
|
|
54
|
+
private _top?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Defines the bottom clipping plane.
|
|
57
|
+
* @type {Number}
|
|
58
|
+
* @default undefined
|
|
59
|
+
*/
|
|
60
|
+
bottom?: number;
|
|
61
|
+
private _bottom?: number;
|
|
62
|
+
/**
|
|
63
|
+
* The distance of the near plane.
|
|
64
|
+
* @type {Number}
|
|
65
|
+
* @default 1.0
|
|
66
|
+
*/
|
|
67
|
+
near: number;
|
|
68
|
+
private _near: number;
|
|
69
|
+
/**
|
|
70
|
+
* The distance of the far plane.
|
|
71
|
+
* @type {Number}
|
|
72
|
+
* @default 500000000.0
|
|
73
|
+
*/
|
|
74
|
+
far: number;
|
|
75
|
+
private _far: number;
|
|
76
|
+
|
|
77
|
+
private _cullingVolume = new CullingVolume([
|
|
78
|
+
new Plane(),
|
|
79
|
+
new Plane(),
|
|
80
|
+
new Plane(),
|
|
81
|
+
new Plane(),
|
|
82
|
+
new Plane(),
|
|
83
|
+
new Plane()
|
|
84
|
+
]);
|
|
85
|
+
private _perspectiveMatrix = new Matrix4();
|
|
86
|
+
private _infinitePerspective = new Matrix4();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The viewing frustum is defined by 6 planes.
|
|
90
|
+
* Each plane is represented by a {@link Vector4} object, where the x, y, and z components
|
|
91
|
+
* define the unit vector normal to the plane, and the w component is the distance of the
|
|
92
|
+
* plane from the origin/camera position.
|
|
93
|
+
*
|
|
94
|
+
* @alias PerspectiveOffCenterFrustum
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* const frustum = new PerspectiveOffCenterFrustum({
|
|
98
|
+
* left : -1.0,
|
|
99
|
+
* right : 1.0,
|
|
100
|
+
* top : 1.0,
|
|
101
|
+
* bottom : -1.0,
|
|
102
|
+
* near : 1.0,
|
|
103
|
+
* far : 100.0
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* @see PerspectiveFrustum
|
|
107
|
+
*/
|
|
108
|
+
constructor(options: PerspectiveOffCenterFrustumOptions = {}) {
|
|
109
|
+
const {near = 1.0, far = 500000000.0} = options;
|
|
110
|
+
|
|
111
|
+
this.left = options.left;
|
|
112
|
+
this._left = undefined;
|
|
113
|
+
|
|
114
|
+
this.right = options.right;
|
|
115
|
+
this._right = undefined;
|
|
116
|
+
|
|
117
|
+
this.top = options.top;
|
|
118
|
+
this._top = undefined;
|
|
119
|
+
|
|
120
|
+
this.bottom = options.bottom;
|
|
121
|
+
this._bottom = undefined;
|
|
122
|
+
|
|
123
|
+
this.near = near;
|
|
124
|
+
this._near = near;
|
|
125
|
+
|
|
126
|
+
this.far = far;
|
|
127
|
+
this._far = far;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns a duplicate of a PerspectiveOffCenterFrustum instance.
|
|
132
|
+
* @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.
|
|
133
|
+
* */
|
|
134
|
+
clone(): PerspectiveOffCenterFrustum {
|
|
135
|
+
return new PerspectiveOffCenterFrustum({
|
|
136
|
+
right: this.right,
|
|
137
|
+
left: this.left,
|
|
138
|
+
top: this.top,
|
|
139
|
+
bottom: this.bottom,
|
|
140
|
+
near: this.near,
|
|
141
|
+
far: this.far
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Compares the provided PerspectiveOffCenterFrustum componentwise and returns
|
|
147
|
+
* <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
148
|
+
*
|
|
149
|
+
* @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
|
|
150
|
+
*/
|
|
151
|
+
equals(other: PerspectiveOffCenterFrustum): boolean {
|
|
152
|
+
return (
|
|
153
|
+
other &&
|
|
154
|
+
other instanceof PerspectiveOffCenterFrustum &&
|
|
155
|
+
this.right === other.right &&
|
|
156
|
+
this.left === other.left &&
|
|
157
|
+
this.top === other.top &&
|
|
158
|
+
this.bottom === other.bottom &&
|
|
159
|
+
this.near === other.near &&
|
|
160
|
+
this.far === other.far
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Gets the perspective projection matrix computed from the view frustum.
|
|
166
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
167
|
+
* @type {Matrix4}
|
|
168
|
+
*
|
|
169
|
+
* @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
|
|
170
|
+
*/
|
|
171
|
+
get projectionMatrix(): Matrix4 {
|
|
172
|
+
this._update();
|
|
173
|
+
return this._perspectiveMatrix;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
|
|
178
|
+
* @memberof PerspectiveOffCenterFrustum.prototype
|
|
179
|
+
* @type {Matrix4}
|
|
180
|
+
*
|
|
181
|
+
* @see PerspectiveOffCenterFrustum#projectionMatrix
|
|
182
|
+
*/
|
|
183
|
+
get infiniteProjectionMatrix(): Matrix4 {
|
|
184
|
+
this._update();
|
|
185
|
+
return this._infinitePerspective;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Creates a culling volume for this frustum.
|
|
190
|
+
* @returns {CullingVolume} A culling volume at the given position and orientation.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* // Check if a bounding volume intersects the frustum.
|
|
194
|
+
* const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
|
|
195
|
+
* const intersect = cullingVolume.computeVisibility(boundingVolume);
|
|
196
|
+
*/
|
|
197
|
+
// eslint-disable-next-line complexity, max-statements
|
|
198
|
+
computeCullingVolume(
|
|
199
|
+
/** A Vector3 defines the eye position. */
|
|
200
|
+
position: Readonly<NumericArray>,
|
|
201
|
+
/** A Vector3 defines the view direction. */
|
|
202
|
+
direction: Readonly<NumericArray>,
|
|
203
|
+
/** A Vector3 defines the up direction. */
|
|
204
|
+
up: Readonly<NumericArray>
|
|
205
|
+
): CullingVolume {
|
|
206
|
+
assert(position, 'position is required.');
|
|
207
|
+
assert(direction, 'direction is required.');
|
|
208
|
+
assert(up, 'up is required.');
|
|
209
|
+
|
|
210
|
+
const planes = this._cullingVolume.planes;
|
|
211
|
+
|
|
212
|
+
up = scratchPlaneUpVector.copy(up).normalize();
|
|
213
|
+
const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
|
|
214
|
+
|
|
215
|
+
const nearCenter = scratchPlaneNearCenter
|
|
216
|
+
.copy(direction)
|
|
217
|
+
.multiplyByScalar(this.near)
|
|
218
|
+
.add(position);
|
|
219
|
+
|
|
220
|
+
const farCenter = scratchPlaneFarCenter
|
|
221
|
+
.copy(direction)
|
|
222
|
+
.multiplyByScalar(this.far)
|
|
223
|
+
.add(position);
|
|
224
|
+
|
|
225
|
+
let normal = scratchPlaneNormal;
|
|
226
|
+
|
|
227
|
+
// Left plane computation
|
|
228
|
+
normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
|
|
229
|
+
|
|
230
|
+
planes[0].fromPointNormal(position, normal);
|
|
231
|
+
|
|
232
|
+
// Right plane computation
|
|
233
|
+
normal
|
|
234
|
+
.copy(right)
|
|
235
|
+
.multiplyByScalar(this.right)
|
|
236
|
+
.add(nearCenter)
|
|
237
|
+
.subtract(position)
|
|
238
|
+
.cross(up)
|
|
239
|
+
.negate();
|
|
240
|
+
|
|
241
|
+
planes[1].fromPointNormal(position, normal);
|
|
242
|
+
|
|
243
|
+
// Bottom plane computation
|
|
244
|
+
normal
|
|
245
|
+
.copy(up)
|
|
246
|
+
.multiplyByScalar(this.bottom)
|
|
247
|
+
.add(nearCenter)
|
|
248
|
+
.subtract(position)
|
|
249
|
+
.cross(right)
|
|
250
|
+
.negate();
|
|
251
|
+
|
|
252
|
+
planes[2].fromPointNormal(position, normal);
|
|
253
|
+
|
|
254
|
+
// Top plane computation
|
|
255
|
+
normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
|
|
256
|
+
|
|
257
|
+
planes[3].fromPointNormal(position, normal);
|
|
258
|
+
|
|
259
|
+
normal = new Vector3().copy(direction);
|
|
260
|
+
|
|
261
|
+
// Near plane computation
|
|
262
|
+
planes[4].fromPointNormal(nearCenter, normal);
|
|
263
|
+
|
|
264
|
+
// Far plane computation
|
|
265
|
+
normal.negate();
|
|
266
|
+
|
|
267
|
+
planes[5].fromPointNormal(farCenter, normal);
|
|
268
|
+
|
|
269
|
+
return this._cullingVolume;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Returns the pixel's width and height in meters.
|
|
274
|
+
*
|
|
275
|
+
* @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.
|
|
276
|
+
*
|
|
277
|
+
* @exception {DeveloperError} drawingBufferWidth must be greater than zero.
|
|
278
|
+
* @exception {DeveloperError} drawingBufferHeight must be greater than zero.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* // Example 1
|
|
282
|
+
* // Get the width and height of a pixel.
|
|
283
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* // Example 2
|
|
287
|
+
* // Get the width and height of a pixel if the near plane was set to 'distance'.
|
|
288
|
+
* // For example, get the size of a pixel of an image on a billboard.
|
|
289
|
+
* const position = camera.position;
|
|
290
|
+
* const direction = camera.direction;
|
|
291
|
+
* const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
|
|
292
|
+
* const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
|
|
293
|
+
* const distance = Vector3.magnitude(toCenterProj);
|
|
294
|
+
* const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
|
|
295
|
+
*/
|
|
296
|
+
getPixelDimensions(
|
|
297
|
+
/** The width of the drawing buffer. */
|
|
298
|
+
drawingBufferWidth: number,
|
|
299
|
+
/** The height of the drawing buffer. */
|
|
300
|
+
drawingBufferHeight: number,
|
|
301
|
+
/** The distance to the near plane in meters. */
|
|
302
|
+
distance: number,
|
|
303
|
+
/** The object onto which to store the result. */
|
|
304
|
+
result: Vector2
|
|
305
|
+
): Vector2 {
|
|
306
|
+
this._update();
|
|
307
|
+
|
|
308
|
+
assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
|
|
309
|
+
// 'Both drawingBufferWidth and drawingBufferHeight are required.'
|
|
310
|
+
assert(drawingBufferWidth > 0);
|
|
311
|
+
// 'drawingBufferWidth must be greater than zero.'
|
|
312
|
+
assert(drawingBufferHeight > 0);
|
|
313
|
+
// 'drawingBufferHeight must be greater than zero.'
|
|
314
|
+
assert(distance > 0);
|
|
315
|
+
// 'distance is required.');
|
|
316
|
+
assert(result);
|
|
317
|
+
// 'A result object is required.');
|
|
318
|
+
|
|
319
|
+
const inverseNear = 1.0 / this.near;
|
|
320
|
+
let tanTheta = this.top * inverseNear;
|
|
321
|
+
const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;
|
|
322
|
+
tanTheta = this.right * inverseNear;
|
|
323
|
+
const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;
|
|
324
|
+
|
|
325
|
+
result.x = pixelWidth;
|
|
326
|
+
result.y = pixelHeight;
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// eslint-disable-next-line complexity, max-statements
|
|
331
|
+
private _update() {
|
|
332
|
+
assert(
|
|
333
|
+
Number.isFinite(this.right) &&
|
|
334
|
+
Number.isFinite(this.left) &&
|
|
335
|
+
Number.isFinite(this.top) &&
|
|
336
|
+
Number.isFinite(this.bottom) &&
|
|
337
|
+
Number.isFinite(this.near) &&
|
|
338
|
+
Number.isFinite(this.far)
|
|
339
|
+
);
|
|
340
|
+
// throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
|
|
341
|
+
|
|
342
|
+
const {top, bottom, right, left, near, far} = this;
|
|
343
|
+
|
|
344
|
+
if (
|
|
345
|
+
top !== this._top ||
|
|
346
|
+
bottom !== this._bottom ||
|
|
347
|
+
left !== this._left ||
|
|
348
|
+
right !== this._right ||
|
|
349
|
+
near !== this._near ||
|
|
350
|
+
far !== this._far
|
|
351
|
+
) {
|
|
352
|
+
assert(
|
|
353
|
+
this.near > 0 && this.near < this.far,
|
|
354
|
+
'near must be greater than zero and less than far.'
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
this._left = left;
|
|
358
|
+
this._right = right;
|
|
359
|
+
this._top = top;
|
|
360
|
+
this._bottom = bottom;
|
|
361
|
+
this._near = near;
|
|
362
|
+
this._far = far;
|
|
363
|
+
this._perspectiveMatrix = new Matrix4().frustum({
|
|
364
|
+
left,
|
|
365
|
+
right,
|
|
366
|
+
bottom,
|
|
367
|
+
top,
|
|
368
|
+
near,
|
|
369
|
+
far
|
|
370
|
+
});
|
|
371
|
+
this._infinitePerspective = new Matrix4().frustum({
|
|
372
|
+
left,
|
|
373
|
+
right,
|
|
374
|
+
bottom,
|
|
375
|
+
top,
|
|
376
|
+
near,
|
|
377
|
+
far: Infinity
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|