@math.gl/geometry 5.0.0-alpha.17 → 5.0.0-alpha.19

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.
Files changed (294) hide show
  1. package/README.md +7 -1
  2. package/dist/culling/constants.d.ts +3 -0
  3. package/dist/culling/constants.d.ts.map +1 -0
  4. package/dist/culling/constants.js +5 -0
  5. package/dist/culling/constants.js.map +1 -0
  6. package/dist/culling/index.cjs +2022 -0
  7. package/dist/culling/index.cjs.map +6 -0
  8. package/dist/culling/index.d.ts +28 -0
  9. package/dist/culling/index.d.ts.map +1 -0
  10. package/dist/culling/index.js +22 -0
  11. package/dist/culling/index.js.map +1 -0
  12. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
  13. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
  14. package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
  15. package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
  16. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
  17. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
  18. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
  19. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
  20. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
  21. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
  22. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
  23. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
  24. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
  25. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
  26. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +116 -0
  27. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
  28. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
  29. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
  30. package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
  31. package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
  32. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
  33. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
  34. package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
  35. package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
  36. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +68 -0
  37. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
  38. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +259 -0
  39. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
  40. package/dist/culling/lib/culling-volume.d.ts +46 -0
  41. package/dist/culling/lib/culling-volume.d.ts.map +1 -0
  42. package/dist/culling/lib/culling-volume.js +126 -0
  43. package/dist/culling/lib/culling-volume.js.map +1 -0
  44. package/dist/culling/lib/perspective-frustum.d.ts +153 -0
  45. package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
  46. package/dist/culling/lib/perspective-frustum.js +191 -0
  47. package/dist/culling/lib/perspective-frustum.js.map +1 -0
  48. package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
  49. package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
  50. package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
  51. package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
  52. package/dist/culling/lib/plane.d.ts +35 -0
  53. package/dist/culling/lib/plane.d.ts.map +1 -0
  54. package/dist/culling/lib/plane.js +90 -0
  55. package/dist/culling/lib/plane.js.map +1 -0
  56. package/dist/culling/lib/ray.d.ts +13 -0
  57. package/dist/culling/lib/ray.d.ts.map +1 -0
  58. package/dist/culling/lib/ray.js +30 -0
  59. package/dist/culling/lib/ray.js.map +1 -0
  60. package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
  61. package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
  62. package/dist/culling/lib/shapes/box-shape.js +69 -0
  63. package/dist/culling/lib/shapes/box-shape.js.map +1 -0
  64. package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
  65. package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
  66. package/dist/culling/lib/shapes/capsule-shape.js +151 -0
  67. package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
  68. package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
  69. package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
  70. package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
  71. package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
  72. package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
  73. package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
  74. package/dist/culling/lib/shapes/implicit-shape.js +142 -0
  75. package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
  76. package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
  77. package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
  78. package/dist/culling/lib/shapes/plane-shape.js +71 -0
  79. package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
  80. package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
  81. package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
  82. package/dist/culling/lib/shapes/sphere-shape.js +43 -0
  83. package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
  84. package/dist/culling/oriented-box-2d.cjs +73 -0
  85. package/dist/culling/oriented-box-2d.cjs.map +6 -0
  86. package/dist/culling/oriented-box-2d.d.ts +22 -0
  87. package/dist/culling/oriented-box-2d.d.ts.map +1 -0
  88. package/dist/culling/oriented-box-2d.js +86 -0
  89. package/dist/culling/oriented-box-2d.js.map +1 -0
  90. package/dist/culling/queries.cjs +161 -0
  91. package/dist/culling/queries.cjs.map +6 -0
  92. package/dist/culling/queries.d.ts +20 -0
  93. package/dist/culling/queries.d.ts.map +1 -0
  94. package/dist/culling/queries.js +139 -0
  95. package/dist/culling/queries.js.map +1 -0
  96. package/dist/curves/bezier-curves.d.ts +18 -0
  97. package/dist/curves/bezier-curves.d.ts.map +1 -0
  98. package/dist/curves/bezier-curves.js +54 -0
  99. package/dist/curves/bezier-curves.js.map +1 -0
  100. package/dist/curves/catmull-rom-curve.d.ts +15 -0
  101. package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
  102. package/dist/curves/catmull-rom-curve.js +77 -0
  103. package/dist/curves/catmull-rom-curve.js.map +1 -0
  104. package/dist/curves/curve-arc-length.d.ts +17 -0
  105. package/dist/curves/curve-arc-length.d.ts.map +1 -0
  106. package/dist/curves/curve-arc-length.js +58 -0
  107. package/dist/curves/curve-arc-length.js.map +1 -0
  108. package/dist/curves/curve.d.ts +23 -0
  109. package/dist/curves/curve.d.ts.map +1 -0
  110. package/dist/curves/curve.js +77 -0
  111. package/dist/curves/curve.js.map +1 -0
  112. package/dist/curves/hermite-curve.d.ts +9 -0
  113. package/dist/curves/hermite-curve.d.ts.map +1 -0
  114. package/dist/curves/hermite-curve.js +24 -0
  115. package/dist/curves/hermite-curve.js.map +1 -0
  116. package/dist/curves/index.cjs +293 -0
  117. package/dist/curves/index.cjs.map +6 -0
  118. package/dist/curves/index.d.ts +8 -0
  119. package/dist/curves/index.d.ts.map +1 -0
  120. package/dist/curves/index.js +9 -0
  121. package/dist/curves/index.js.map +1 -0
  122. package/dist/lib/geometry.d.ts +1 -1
  123. package/dist/lib/geometry.d.ts.map +1 -1
  124. package/dist/polygon/cut-by-grid.d.ts +24 -0
  125. package/dist/polygon/cut-by-grid.d.ts.map +1 -0
  126. package/dist/polygon/cut-by-grid.js +221 -0
  127. package/dist/polygon/cut-by-grid.js.map +1 -0
  128. package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
  129. package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
  130. package/dist/polygon/cut-by-mercator-bounds.js +149 -0
  131. package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
  132. package/dist/polygon/earcut.d.ts +13 -0
  133. package/dist/polygon/earcut.d.ts.map +1 -0
  134. package/dist/polygon/earcut.js +627 -0
  135. package/dist/polygon/earcut.js.map +1 -0
  136. package/dist/polygon/index.cjs +1414 -0
  137. package/dist/polygon/index.cjs.map +6 -0
  138. package/dist/polygon/index.d.ts +12 -0
  139. package/dist/polygon/index.d.ts.map +1 -0
  140. package/dist/polygon/index.js +12 -0
  141. package/dist/polygon/index.js.map +1 -0
  142. package/dist/polygon/lineclip.d.ts +31 -0
  143. package/dist/polygon/lineclip.d.ts.map +1 -0
  144. package/dist/polygon/lineclip.js +184 -0
  145. package/dist/polygon/lineclip.js.map +1 -0
  146. package/dist/polygon/polygon-utils.d.ts +103 -0
  147. package/dist/polygon/polygon-utils.d.ts.map +1 -0
  148. package/dist/polygon/polygon-utils.js +155 -0
  149. package/dist/polygon/polygon-utils.js.map +1 -0
  150. package/dist/polygon/polygon.d.ts +41 -0
  151. package/dist/polygon/polygon.d.ts.map +1 -0
  152. package/dist/polygon/polygon.js +76 -0
  153. package/dist/polygon/polygon.js.map +1 -0
  154. package/dist/polygon/subdivide-polyline.d.ts +42 -0
  155. package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
  156. package/dist/polygon/subdivide-polyline.js +109 -0
  157. package/dist/polygon/subdivide-polyline.js.map +1 -0
  158. package/dist/polygon/subdivide-triangle-mesh.d.ts +68 -0
  159. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  160. package/dist/polygon/subdivide-triangle-mesh.js +228 -0
  161. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
  162. package/dist/polygon/utils.d.ts +5 -0
  163. package/dist/polygon/utils.d.ts.map +1 -0
  164. package/dist/polygon/utils.js +38 -0
  165. package/dist/polygon/utils.js.map +1 -0
  166. package/dist/spatial-index/box-index.cjs +328 -0
  167. package/dist/spatial-index/box-index.cjs.map +6 -0
  168. package/dist/spatial-index/box-index.d.ts +65 -0
  169. package/dist/spatial-index/box-index.d.ts.map +1 -0
  170. package/dist/spatial-index/box-index.js +263 -0
  171. package/dist/spatial-index/box-index.js.map +1 -0
  172. package/dist/spatial-index/index.cjs +494 -0
  173. package/dist/spatial-index/index.cjs.map +6 -0
  174. package/dist/spatial-index/index.d.ts +5 -0
  175. package/dist/spatial-index/index.d.ts.map +1 -0
  176. package/dist/spatial-index/index.js +6 -0
  177. package/dist/spatial-index/index.js.map +1 -0
  178. package/dist/spatial-index/triangle-bvh.d.ts +53 -0
  179. package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
  180. package/dist/spatial-index/triangle-bvh.js +102 -0
  181. package/dist/spatial-index/triangle-bvh.js.map +1 -0
  182. package/dist/utils/attribute-compression.d.ts +50 -0
  183. package/dist/utils/attribute-compression.d.ts.map +1 -0
  184. package/dist/utils/attribute-compression.js +186 -0
  185. package/dist/utils/attribute-compression.js.map +1 -0
  186. package/dist/utils/attribute-iterator.d.ts +8 -0
  187. package/dist/utils/attribute-iterator.d.ts.map +1 -0
  188. package/dist/utils/attribute-iterator.js +25 -0
  189. package/dist/utils/attribute-iterator.js.map +1 -0
  190. package/dist/utils/compute-vertex-normals.d.ts +4 -0
  191. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  192. package/dist/utils/compute-vertex-normals.js +54 -0
  193. package/dist/utils/compute-vertex-normals.js.map +1 -0
  194. package/dist/utils/constants.d.ts +52 -0
  195. package/dist/utils/constants.d.ts.map +1 -0
  196. package/dist/utils/constants.js +39 -0
  197. package/dist/utils/constants.js.map +1 -0
  198. package/dist/utils/coordinates.d.ts +3 -0
  199. package/dist/utils/coordinates.d.ts.map +1 -0
  200. package/dist/utils/coordinates.js +8 -0
  201. package/dist/utils/coordinates.js.map +1 -0
  202. package/dist/utils/geometry.d.ts +20 -0
  203. package/dist/utils/geometry.d.ts.map +1 -0
  204. package/dist/utils/geometry.js +31 -0
  205. package/dist/utils/geometry.js.map +1 -0
  206. package/dist/utils/gl-type.d.ts +17 -0
  207. package/dist/utils/gl-type.d.ts.map +1 -0
  208. package/dist/utils/gl-type.js +69 -0
  209. package/dist/utils/gl-type.js.map +1 -0
  210. package/dist/utils/index.cjs +965 -0
  211. package/dist/utils/index.cjs.map +6 -0
  212. package/dist/utils/index.d.ts +18 -0
  213. package/dist/utils/index.d.ts.map +1 -0
  214. package/dist/utils/index.js +16 -0
  215. package/dist/utils/index.js.map +1 -0
  216. package/dist/utils/interpolate-packed-attributes.cjs +176 -0
  217. package/dist/utils/interpolate-packed-attributes.cjs.map +6 -0
  218. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  219. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  220. package/dist/utils/interpolate-packed-attributes.js +192 -0
  221. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  222. package/dist/utils/mesh-processing.d.ts +18 -0
  223. package/dist/utils/mesh-processing.d.ts.map +1 -0
  224. package/dist/utils/mesh-processing.js +300 -0
  225. package/dist/utils/mesh-processing.js.map +1 -0
  226. package/dist/utils/primitive-iterator.d.ts +21 -0
  227. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  228. package/dist/utils/primitive-iterator.js +117 -0
  229. package/dist/utils/primitive-iterator.js.map +1 -0
  230. package/dist/utils/rgb565.d.ts +5 -0
  231. package/dist/utils/rgb565.d.ts.map +1 -0
  232. package/dist/utils/rgb565.js +24 -0
  233. package/dist/utils/rgb565.js.map +1 -0
  234. package/dist/utils/typed-array-utils.d.ts +3 -0
  235. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  236. package/dist/utils/typed-array-utils.js +16 -0
  237. package/dist/utils/typed-array-utils.js.map +1 -0
  238. package/package.json +49 -3
  239. package/src/culling/constants.ts +6 -0
  240. package/src/culling/index.ts +40 -0
  241. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  242. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  243. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  244. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
  245. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  246. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  247. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +355 -0
  248. package/src/culling/lib/culling-volume.ts +163 -0
  249. package/src/culling/lib/perspective-frustum.ts +288 -0
  250. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  251. package/src/culling/lib/plane.ts +118 -0
  252. package/src/culling/lib/ray.ts +33 -0
  253. package/src/culling/lib/shapes/box-shape.ts +78 -0
  254. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  255. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  256. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  257. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  258. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  259. package/src/culling/oriented-box-2d.ts +165 -0
  260. package/src/culling/queries.ts +155 -0
  261. package/src/curves/bezier-curves.ts +62 -0
  262. package/src/curves/catmull-rom-curve.ts +89 -0
  263. package/src/curves/curve-arc-length.ts +70 -0
  264. package/src/curves/curve.ts +96 -0
  265. package/src/curves/hermite-curve.ts +34 -0
  266. package/src/curves/index.ts +15 -0
  267. package/src/lib/geometry-utils.ts +1 -1
  268. package/src/lib/geometry.ts +1 -1
  269. package/src/polygon/cut-by-grid.ts +313 -0
  270. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  271. package/src/polygon/earcut.ts +798 -0
  272. package/src/polygon/index.ts +31 -0
  273. package/src/polygon/lineclip.ts +218 -0
  274. package/src/polygon/polygon-utils.ts +273 -0
  275. package/src/polygon/polygon.ts +105 -0
  276. package/src/polygon/subdivide-polyline.ts +160 -0
  277. package/src/polygon/subdivide-triangle-mesh.ts +322 -0
  278. package/src/polygon/utils.ts +50 -0
  279. package/src/spatial-index/box-index.ts +343 -0
  280. package/src/spatial-index/index.ts +18 -0
  281. package/src/spatial-index/triangle-bvh.ts +162 -0
  282. package/src/utils/attribute-compression.ts +234 -0
  283. package/src/utils/attribute-iterator.ts +28 -0
  284. package/src/utils/compute-vertex-normals.ts +63 -0
  285. package/src/utils/constants.ts +42 -0
  286. package/src/utils/coordinates.ts +8 -0
  287. package/src/utils/geometry.ts +49 -0
  288. package/src/utils/gl-type.ts +87 -0
  289. package/src/utils/index.ts +55 -0
  290. package/src/utils/interpolate-packed-attributes.ts +284 -0
  291. package/src/utils/mesh-processing.ts +377 -0
  292. package/src/utils/primitive-iterator.ts +145 -0
  293. package/src/utils/rgb565.ts +26 -0
  294. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,259 @@
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
+ import { Vector3, Matrix3, Quaternion } from '@math.gl/core';
7
+ import { BoundingSphere } from "./bounding-sphere.js";
8
+ const scratchVector3 = new Vector3();
9
+ const scratchOffset = new Vector3();
10
+ const scratchVectorU = new Vector3();
11
+ const scratchVectorV = new Vector3();
12
+ const scratchVectorW = new Vector3();
13
+ const scratchCorner = new Vector3();
14
+ const scratchToCenter = new Vector3();
15
+ const MATRIX3 = {
16
+ COLUMN0ROW0: 0,
17
+ COLUMN0ROW1: 1,
18
+ COLUMN0ROW2: 2,
19
+ COLUMN1ROW0: 3,
20
+ COLUMN1ROW1: 4,
21
+ COLUMN1ROW2: 5,
22
+ COLUMN2ROW0: 6,
23
+ COLUMN2ROW1: 7,
24
+ COLUMN2ROW2: 8
25
+ };
26
+ /**
27
+ * An OrientedBoundingBox of some object is a closed and convex cuboid.
28
+ * It can provide a tighter bounding volume than `BoundingSphere` or
29
+ * `AxisAlignedBoundingBox` in many cases.
30
+ */
31
+ export class OrientedBoundingBox {
32
+ constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
33
+ this.center = new Vector3().from(center);
34
+ this.halfAxes = new Matrix3(halfAxes);
35
+ }
36
+ /** Returns an array with three halfSizes for the bounding box */
37
+ get halfSize() {
38
+ const xAxis = this.halfAxes.getColumn(0);
39
+ const yAxis = this.halfAxes.getColumn(1);
40
+ const zAxis = this.halfAxes.getColumn(2);
41
+ return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];
42
+ }
43
+ /** Returns a quaternion describing the orientation of the bounding box */
44
+ get quaternion() {
45
+ const xAxis = this.halfAxes.getColumn(0);
46
+ const yAxis = this.halfAxes.getColumn(1);
47
+ const zAxis = this.halfAxes.getColumn(2);
48
+ const normXAxis = new Vector3(xAxis).normalize();
49
+ const normYAxis = new Vector3(yAxis).normalize();
50
+ const normZAxis = new Vector3(zAxis).normalize();
51
+ return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));
52
+ }
53
+ /**
54
+ * Create OrientedBoundingBox from quaternion based OBB,
55
+ */
56
+ fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
57
+ const quaternionObject = new Quaternion(quaternion);
58
+ const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);
59
+ directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
60
+ directionsMatrix[1] = directionsMatrix[1] * halfSize[0];
61
+ directionsMatrix[2] = directionsMatrix[2] * halfSize[0];
62
+ directionsMatrix[3] = directionsMatrix[3] * halfSize[1];
63
+ directionsMatrix[4] = directionsMatrix[4] * halfSize[1];
64
+ directionsMatrix[5] = directionsMatrix[5] * halfSize[1];
65
+ directionsMatrix[6] = directionsMatrix[6] * halfSize[2];
66
+ directionsMatrix[7] = directionsMatrix[7] * halfSize[2];
67
+ directionsMatrix[8] = directionsMatrix[8] * halfSize[2];
68
+ this.center = new Vector3().from(center);
69
+ this.halfAxes = directionsMatrix;
70
+ return this;
71
+ }
72
+ /** Duplicates a OrientedBoundingBox instance. */
73
+ clone() {
74
+ return new OrientedBoundingBox(this.center, this.halfAxes);
75
+ }
76
+ /** Compares the provided OrientedBoundingBox component wise and returns */
77
+ equals(right) {
78
+ return (this === right ||
79
+ (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes)));
80
+ }
81
+ /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
82
+ getBoundingSphere(result = new BoundingSphere()) {
83
+ const halfAxes = this.halfAxes;
84
+ const u = halfAxes.getColumn(0, scratchVectorU);
85
+ const v = halfAxes.getColumn(1, scratchVectorV);
86
+ const w = halfAxes.getColumn(2, scratchVectorW);
87
+ // Calculate "corner" vector
88
+ const cornerVector = scratchVector3.copy(u).add(v).add(w);
89
+ result.center.copy(this.center);
90
+ result.radius = cornerVector.magnitude();
91
+ return result;
92
+ }
93
+ /** Determines which side of a plane the oriented bounding box is located. */
94
+ intersectPlane(plane) {
95
+ const center = this.center;
96
+ const normal = plane.normal;
97
+ const halfAxes = this.halfAxes;
98
+ const normalX = normal.x;
99
+ const normalY = normal.y;
100
+ const normalZ = normal.z;
101
+ // Plane is used as if it is its normal; the first three components are assumed to be normalized
102
+ const radEffective = Math.abs(normalX * halfAxes[MATRIX3.COLUMN0ROW0] +
103
+ normalY * halfAxes[MATRIX3.COLUMN0ROW1] +
104
+ normalZ * halfAxes[MATRIX3.COLUMN0ROW2]) +
105
+ Math.abs(normalX * halfAxes[MATRIX3.COLUMN1ROW0] +
106
+ normalY * halfAxes[MATRIX3.COLUMN1ROW1] +
107
+ normalZ * halfAxes[MATRIX3.COLUMN1ROW2]) +
108
+ Math.abs(normalX * halfAxes[MATRIX3.COLUMN2ROW0] +
109
+ normalY * halfAxes[MATRIX3.COLUMN2ROW1] +
110
+ normalZ * halfAxes[MATRIX3.COLUMN2ROW2]);
111
+ const distanceToPlane = normal.dot(center) + plane.distance;
112
+ if (distanceToPlane <= -radEffective) {
113
+ // The entire box is on the negative side of the plane normal
114
+ return 'outside';
115
+ }
116
+ else if (distanceToPlane >= radEffective) {
117
+ // The entire box is on the positive side of the plane normal
118
+ return 'inside';
119
+ }
120
+ return 'intersecting';
121
+ }
122
+ /** Computes the estimated distance from the closest point on a bounding box to a point. */
123
+ distanceTo(point) {
124
+ return Math.sqrt(this.distanceSquaredTo(point));
125
+ }
126
+ /**
127
+ * Computes the estimated distance squared from the closest point
128
+ * on a bounding box to a point.
129
+ * See Geometric Tools for Computer Graphics 10.4.2
130
+ */
131
+ distanceSquaredTo(point) {
132
+ // Computes the estimated distance squared from the
133
+ // closest point on a bounding box to a point.
134
+ // See Geometric Tools for Computer Graphics 10.4.2
135
+ const offset = scratchOffset.from(point).subtract(this.center);
136
+ const halfAxes = this.halfAxes;
137
+ const u = halfAxes.getColumn(0, scratchVectorU);
138
+ const v = halfAxes.getColumn(1, scratchVectorV);
139
+ const w = halfAxes.getColumn(2, scratchVectorW);
140
+ const uHalf = u.magnitude();
141
+ const vHalf = v.magnitude();
142
+ const wHalf = w.magnitude();
143
+ u.normalize();
144
+ v.normalize();
145
+ w.normalize();
146
+ let distanceSquared = 0.0;
147
+ let d;
148
+ d = Math.abs(offset.dot(u)) - uHalf;
149
+ if (d > 0) {
150
+ distanceSquared += d * d;
151
+ }
152
+ d = Math.abs(offset.dot(v)) - vHalf;
153
+ if (d > 0) {
154
+ distanceSquared += d * d;
155
+ }
156
+ d = Math.abs(offset.dot(w)) - wHalf;
157
+ if (d > 0) {
158
+ distanceSquared += d * d;
159
+ }
160
+ return distanceSquared;
161
+ }
162
+ /**
163
+ * The distances calculated by the vector from the center of the bounding box
164
+ * to position projected onto direction.
165
+ *
166
+ * - If you imagine the infinite number of planes with normal direction,
167
+ * this computes the smallest distance to the closest and farthest planes
168
+ * from `position` that intersect the bounding box.
169
+ *
170
+ * @param position The position to calculate the distance from.
171
+ * @param direction The direction from position.
172
+ * @param result An Interval (array of length 2) to store the nearest and farthest distances.
173
+ * @returns Interval (array of length 2) with nearest and farthest distances
174
+ * on the bounding box from position in direction.
175
+ */
176
+ // eslint-disable-next-line max-statements
177
+ computePlaneDistances(position, direction, result = [-0, -0]) {
178
+ let minDist = Number.POSITIVE_INFINITY;
179
+ let maxDist = Number.NEGATIVE_INFINITY;
180
+ const center = this.center;
181
+ const halfAxes = this.halfAxes;
182
+ const u = halfAxes.getColumn(0, scratchVectorU);
183
+ const v = halfAxes.getColumn(1, scratchVectorV);
184
+ const w = halfAxes.getColumn(2, scratchVectorW);
185
+ // project first corner
186
+ const corner = scratchCorner.copy(u).add(v).add(w).add(center);
187
+ const toCenter = scratchToCenter.copy(corner).subtract(position);
188
+ let mag = direction.dot(toCenter);
189
+ minDist = Math.min(mag, minDist);
190
+ maxDist = Math.max(mag, maxDist);
191
+ // project second corner
192
+ corner.copy(center).add(u).add(v).subtract(w);
193
+ toCenter.copy(corner).subtract(position);
194
+ mag = direction.dot(toCenter);
195
+ minDist = Math.min(mag, minDist);
196
+ maxDist = Math.max(mag, maxDist);
197
+ // project third corner
198
+ corner.copy(center).add(u).subtract(v).add(w);
199
+ toCenter.copy(corner).subtract(position);
200
+ mag = direction.dot(toCenter);
201
+ minDist = Math.min(mag, minDist);
202
+ maxDist = Math.max(mag, maxDist);
203
+ // project fourth corner
204
+ corner.copy(center).add(u).subtract(v).subtract(w);
205
+ toCenter.copy(corner).subtract(position);
206
+ mag = direction.dot(toCenter);
207
+ minDist = Math.min(mag, minDist);
208
+ maxDist = Math.max(mag, maxDist);
209
+ // project fifth corner
210
+ center.copy(corner).subtract(u).add(v).add(w);
211
+ toCenter.copy(corner).subtract(position);
212
+ mag = direction.dot(toCenter);
213
+ minDist = Math.min(mag, minDist);
214
+ maxDist = Math.max(mag, maxDist);
215
+ // project sixth corner
216
+ center.copy(corner).subtract(u).add(v).subtract(w);
217
+ toCenter.copy(corner).subtract(position);
218
+ mag = direction.dot(toCenter);
219
+ minDist = Math.min(mag, minDist);
220
+ maxDist = Math.max(mag, maxDist);
221
+ // project seventh corner
222
+ center.copy(corner).subtract(u).subtract(v).add(w);
223
+ toCenter.copy(corner).subtract(position);
224
+ mag = direction.dot(toCenter);
225
+ minDist = Math.min(mag, minDist);
226
+ maxDist = Math.max(mag, maxDist);
227
+ // project eighth corner
228
+ center.copy(corner).subtract(u).subtract(v).subtract(w);
229
+ toCenter.copy(corner).subtract(position);
230
+ mag = direction.dot(toCenter);
231
+ minDist = Math.min(mag, minDist);
232
+ maxDist = Math.max(mag, maxDist);
233
+ result[0] = minDist;
234
+ result[1] = maxDist;
235
+ return result;
236
+ }
237
+ /**
238
+ * Applies a 4x4 affine transformation matrix to a bounding sphere.
239
+ * @param transform The transformation matrix to apply to the bounding sphere.
240
+ * @returns itself, i.e. the modified BoundingVolume.
241
+ */
242
+ transform(transformation) {
243
+ this.center.transformAsPoint(transformation);
244
+ const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
245
+ xAxis.transformAsPoint(transformation);
246
+ const yAxis = this.halfAxes.getColumn(1, scratchVectorV);
247
+ yAxis.transformAsPoint(transformation);
248
+ const zAxis = this.halfAxes.getColumn(2, scratchVectorW);
249
+ zAxis.transformAsPoint(transformation);
250
+ this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);
251
+ return this;
252
+ }
253
+ getTransform() {
254
+ // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);
255
+ // return modelMatrix;
256
+ throw new Error('not implemented');
257
+ }
258
+ }
259
+ //# sourceMappingURL=oriented-bounding-box.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oriented-bounding-box.js","sourceRoot":"","sources":["../../../../src/culling/lib/bounding-volumes/oriented-bounding-box.ts"],"names":[],"mappings":"AAAA,UAAU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AAC;QACzD,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;QAEvC,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY;QACV,iHAAiH;QACjH,sBAAsB;QACtB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,46 @@
1
+ import type { CullingResult } from "../constants.js";
2
+ import { Plane } from "./plane.js";
3
+ import type { BoundingVolume } from "./bounding-volumes/bounding-volume.js";
4
+ import type { BoundingSphere } from "./bounding-volumes/bounding-sphere.js";
5
+ /** A culling volume defined by planes. */
6
+ export declare class CullingVolume {
7
+ /**
8
+ * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
9
+ * represents the case where the object bounding volume is entirely outside the culling volume.
10
+ */
11
+ static MASK_OUTSIDE: number;
12
+ /**
13
+ * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
14
+ * represents the case where the object bounding volume is entirely inside the culling volume.
15
+ */
16
+ static MASK_INSIDE: number;
17
+ /**
18
+ * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
19
+ * represents the case where the object bounding volume (may) intersect all planes of the culling volume.
20
+ */
21
+ static MASK_INDETERMINATE: number;
22
+ /** Array of clipping planes. */
23
+ readonly planes: Plane[];
24
+ /**
25
+ * Create a new `CullingVolume` bounded by an array of clipping planed
26
+ * @param planes Array of clipping planes.
27
+ * */
28
+ constructor(planes?: Plane[]);
29
+ /**
30
+ * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
31
+ * The planes are aligned to the x, y, and z axes in world coordinates.
32
+ */
33
+ fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume;
34
+ /** Determines whether a bounding volume intersects the culling volume. */
35
+ computeVisibility(boundingVolume: BoundingVolume): CullingResult;
36
+ /**
37
+ * Determines whether a bounding volume intersects the culling volume.
38
+ *
39
+ * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
40
+ * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
41
+ * the parent (and therefore this) volume is completely inside plane[planeIndex]
42
+ * and that plane check can be skipped.
43
+ */
44
+ computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number;
45
+ }
46
+ //# sourceMappingURL=culling-volume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"culling-volume.d.ts","sourceRoot":"","sources":["../../../src/culling/lib/culling-volume.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAC,aAAa,EAAC,wBAAqB;AAChD,OAAO,EAAC,KAAK,EAAC,mBAAgB;AAC9B,OAAO,KAAK,EAAC,cAAc,EAAC,8CAA2C;AACvE,OAAO,KAAK,EAAC,cAAc,EAAC,8CAA2C;AASvE,0CAA0C;AAC1C,qBAAa,aAAa;IACxB;;;OAGG;IACH,MAAM,CAAC,YAAY,SAAc;IAEjC;;;OAGG;IACH,MAAM,CAAC,WAAW,SAAc;IAEhC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,SAAc;IAEvC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAEzB;;;SAGK;gBACO,MAAM,GAAE,KAAK,EAAO;IAIhC;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa;IAsCjE,0EAA0E;IAC1E,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa;IAsBhE;;;;;;;OAOG;IACH,8BAA8B,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;CAmChG"}
@@ -0,0 +1,126 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
6
+ // This file is derived from the Cesium math library under Apache 2 license
7
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
8
+ /* eslint-disable */
9
+ import { Vector3, assert } from '@math.gl/core';
10
+ import { Plane } from "./plane.js";
11
+ // X, Y, Z Unit vectors
12
+ const faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];
13
+ const scratchPlaneCenter = new Vector3();
14
+ const scratchPlaneNormal = new Vector3();
15
+ // const scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);
16
+ /** A culling volume defined by planes. */
17
+ export class CullingVolume {
18
+ /**
19
+ * Create a new `CullingVolume` bounded by an array of clipping planed
20
+ * @param planes Array of clipping planes.
21
+ * */
22
+ constructor(planes = []) {
23
+ this.planes = planes;
24
+ }
25
+ /**
26
+ * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.
27
+ * The planes are aligned to the x, y, and z axes in world coordinates.
28
+ */
29
+ fromBoundingSphere(boundingSphere) {
30
+ this.planes.length = 2 * faces.length;
31
+ const center = boundingSphere.center;
32
+ const radius = boundingSphere.radius;
33
+ let planeIndex = 0;
34
+ for (const faceNormal of faces) {
35
+ let plane0 = this.planes[planeIndex];
36
+ let plane1 = this.planes[planeIndex + 1];
37
+ if (!plane0) {
38
+ plane0 = this.planes[planeIndex] = new Plane();
39
+ }
40
+ if (!plane1) {
41
+ plane1 = this.planes[planeIndex + 1] = new Plane();
42
+ }
43
+ const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
44
+ // const plane0Distance = -faceNormal.dot(plane0Center);
45
+ plane0.fromPointNormal(plane0Center, faceNormal);
46
+ const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
47
+ const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
48
+ // const plane1Distance = -negatedFaceNormal.dot(plane1Center);
49
+ plane1.fromPointNormal(plane1Center, negatedFaceNormal);
50
+ planeIndex += 2;
51
+ }
52
+ return this;
53
+ }
54
+ /** Determines whether a bounding volume intersects the culling volume. */
55
+ computeVisibility(boundingVolume) {
56
+ // const planes = this.planes;
57
+ let intersect = 'inside';
58
+ for (const plane of this.planes) {
59
+ const result = boundingVolume.intersectPlane(plane);
60
+ switch (result) {
61
+ case 'outside':
62
+ // We are done
63
+ return 'outside';
64
+ case 'intersecting':
65
+ // If no other intersection is outside, return INTERSECTING
66
+ intersect = 'intersecting';
67
+ break;
68
+ default:
69
+ }
70
+ }
71
+ return intersect;
72
+ }
73
+ /**
74
+ * Determines whether a bounding volume intersects the culling volume.
75
+ *
76
+ * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling
77
+ * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then
78
+ * the parent (and therefore this) volume is completely inside plane[planeIndex]
79
+ * and that plane check can be skipped.
80
+ */
81
+ computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
82
+ assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
83
+ if (parentPlaneMask === CullingVolume.MASK_OUTSIDE ||
84
+ parentPlaneMask === CullingVolume.MASK_INSIDE) {
85
+ // parent is completely outside or completely inside, so this child is as well.
86
+ return parentPlaneMask;
87
+ }
88
+ // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.
89
+ // (Because if there are fewer than 31 planes, the upper bits wont be changed.)
90
+ let mask = CullingVolume.MASK_INSIDE;
91
+ const planes = this.planes;
92
+ for (let k = 0; k < this.planes.length; ++k) {
93
+ // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.
94
+ const flag = k < 31 ? 1 << k : 0;
95
+ if (k < 31 && (parentPlaneMask & flag) === 0) {
96
+ // boundingVolume is known to be INSIDE this plane.
97
+ continue;
98
+ }
99
+ const plane = planes[k];
100
+ const result = boundingVolume.intersectPlane(plane);
101
+ if (result === 'outside') {
102
+ return CullingVolume.MASK_OUTSIDE;
103
+ }
104
+ else if (result === 'intersecting') {
105
+ mask |= flag;
106
+ }
107
+ }
108
+ return mask;
109
+ }
110
+ }
111
+ /**
112
+ * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value
113
+ * represents the case where the object bounding volume is entirely outside the culling volume.
114
+ */
115
+ CullingVolume.MASK_OUTSIDE = 0xffffffff;
116
+ /**
117
+ * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
118
+ * represents the case where the object bounding volume is entirely inside the culling volume.
119
+ */
120
+ CullingVolume.MASK_INSIDE = 0x00000000;
121
+ /**
122
+ * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value
123
+ * represents the case where the object bounding volume (may) intersect all planes of the culling volume.
124
+ */
125
+ CullingVolume.MASK_INDETERMINATE = 0x7fffffff;
126
+ //# sourceMappingURL=culling-volume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"culling-volume.js","sourceRoot":"","sources":["../../../src/culling/lib/culling-volume.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,8CAA8C;AAC9C,oEAAoE;AACpE,4DAA4D;AAC5D,mHAAmH;AAEnH,2EAA2E;AAC3E,4FAA4F;AAE5F,oBAAoB;AACpB,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAC,KAAK,EAAC,mBAAgB;AAI9B,uBAAuB;AACvB,MAAM,KAAK,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,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,CAAC,MAAM,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YAC5C,0HAA0H;YAC1H,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC7C,mDAAmD;gBACnD,SAAS;YACX,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,MAAM,MAAM,GAAG,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,OAAO,aAAa,CAAC,YAAY,CAAC;YACpC,CAAC;iBAAM,IAAI,MAAM,KAAK,cAAc,EAAE,CAAC;gBACrC,IAAI,IAAI,IAAI,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;;AAxID;;;GAGG;AACI,0BAAY,GAAG,UAAU,CAAC;AAEjC;;;GAGG;AACI,yBAAW,GAAG,UAAU,CAAC;AAEhC;;;GAGG;AACI,gCAAkB,GAAG,UAAU,CAAC"}
@@ -0,0 +1,153 @@
1
+ import { NumericArray } from '@math.gl/core/types';
2
+ import { Matrix4, Vector2 } from '@math.gl/core';
3
+ import { CullingVolume } from "./culling-volume.js";
4
+ type PerspectiveFrustumOptions = {
5
+ /** The angle of the field of view (FOV), in radians. */
6
+ fov?: number;
7
+ /** The aspect ratio of the frustum's width to it's height. */
8
+ aspectRatio?: number;
9
+ /** The distance of the near plane. */
10
+ near?: number;
11
+ /** The distance of the far plane. */
12
+ far?: number;
13
+ /** The offset in the x direction. */
14
+ xOffset?: number;
15
+ /** The offset in the y direction. */
16
+ yOffset?: number;
17
+ };
18
+ /**
19
+ * The viewing frustum is defined by 6 planes.
20
+ * Each plane is represented by a {@link Vector4} object, where the x, y, and z components
21
+ * define the unit vector normal to the plane, and the w component is the distance of the
22
+ * plane from the origin/camera position.
23
+ *
24
+ * @alias PerspectiveFrustum
25
+ *
26
+ * @example
27
+ * var frustum = new PerspectiveFrustum({
28
+ * fov : Math.PI_OVER_THREE,
29
+ * aspectRatio : canvas.clientWidth / canvas.clientHeight
30
+ * near : 1.0,
31
+ * far : 1000.0
32
+ * });
33
+ *
34
+ * @see PerspectiveOffCenterFrustum
35
+ */
36
+ export declare class PerspectiveFrustum {
37
+ private _offCenterFrustum;
38
+ /**
39
+ * The angle of the field of view (FOV), in radians. This angle will be used
40
+ * as the horizontal FOV if the width is greater than the height, otherwise
41
+ * it will be the vertical FOV.
42
+ */
43
+ fov?: number;
44
+ private _fov;
45
+ private _fovy;
46
+ private _sseDenominator;
47
+ /**
48
+ * The aspect ratio of the frustum's width to it's height.
49
+ */
50
+ aspectRatio?: number;
51
+ private _aspectRatio;
52
+ /**
53
+ * The distance of the near plane.
54
+ * @default 1.0
55
+ */
56
+ near: number;
57
+ private _near;
58
+ /**
59
+ * The distance of the far plane.
60
+ * @default 500000000.0
61
+ */
62
+ far: number;
63
+ private _far;
64
+ /**
65
+ * Offsets the frustum in the x direction.
66
+ * @default 0.0
67
+ */
68
+ xOffset: number;
69
+ private _xOffset;
70
+ /**
71
+ * Offsets the frustum in the y direction.
72
+ * @default 0.0
73
+ */
74
+ yOffset: number;
75
+ private _yOffset;
76
+ constructor(options?: PerspectiveFrustumOptions);
77
+ /**
78
+ * Returns a duplicate of a PerspectiveFrustum instance.
79
+ */
80
+ clone(): PerspectiveFrustum;
81
+ /**
82
+ * Compares the provided PerspectiveFrustum componentwise and returns
83
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
84
+ */
85
+ equals(other: PerspectiveFrustum): boolean;
86
+ /**
87
+ * Gets the perspective projection matrix computed from the view this.
88
+ */
89
+ get projectionMatrix(): Matrix4;
90
+ /**
91
+ * The perspective projection matrix computed from the view frustum with an infinite far plane.
92
+ */
93
+ get infiniteProjectionMatrix(): Matrix4;
94
+ /**
95
+ * Gets the angle of the vertical field of view, in radians.
96
+ */
97
+ get fovy(): number;
98
+ /**
99
+ * @private
100
+ */
101
+ get sseDenominator(): number;
102
+ /**
103
+ * Creates a culling volume for this this.ion.
104
+ * @returns {CullingVolume} A culling volume at the given position and orientation.
105
+ *
106
+ * @example
107
+ * // Check if a bounding volume intersects the this.
108
+ * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
109
+ * var intersect = cullingVolume.computeVisibility(boundingVolume);
110
+ */
111
+ computeCullingVolume(
112
+ /** A Vector3 defines the eye position. */
113
+ position: Readonly<NumericArray>,
114
+ /** A Vector3 defines the view direction. */
115
+ direction: Readonly<NumericArray>,
116
+ /** A Vector3 defines the up direction. */
117
+ up: Readonly<NumericArray>): CullingVolume;
118
+ /**
119
+ * Returns the pixel's width and height in meters.
120
+ * @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.
121
+ *
122
+ * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
123
+ * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
124
+ *
125
+ * @example
126
+ * // Example 1
127
+ * // Get the width and height of a pixel.
128
+ * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
129
+ *
130
+ * @example
131
+ * // Example 2
132
+ * // Get the width and height of a pixel if the near plane was set to 'distance'.
133
+ * // For example, get the size of a pixel of an image on a billboard.
134
+ * var position = camera.position;
135
+ * var direction = camera.direction;
136
+ * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
137
+ * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
138
+ * var distance = Vector3.magnitude(toCenterProj);
139
+ * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
140
+ */
141
+ getPixelDimensions(
142
+ /** The width of the drawing buffer. */
143
+ drawingBufferWidth: number,
144
+ /** The height of the drawing buffer. */
145
+ drawingBufferHeight: number,
146
+ /** The distance to the near plane in meters. */
147
+ distance: number,
148
+ /** The object onto which to store the result. */
149
+ result?: Vector2): Vector2;
150
+ private _update;
151
+ }
152
+ export {};
153
+ //# sourceMappingURL=perspective-frustum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perspective-frustum.d.ts","sourceRoot":"","sources":["../../../src/culling/lib/perspective-frustum.ts"],"names":[],"mappings":"AAaA,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAS,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAI/C,KAAK,yBAAyB,GAAG;IAC/B,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,iBAAiB,CAAqC;IAC9D;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,eAAe,CAAS;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,YA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