easy-three-utils 0.0.1

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 (166) hide show
  1. package/package.json +12 -0
  2. package/src/common/index.ts +24 -0
  3. package/src/common/useLine2.ts +87 -0
  4. package/src/common/useLoader.ts +184 -0
  5. package/src/common/useLocationCalculator.ts +145 -0
  6. package/src/common/useMark.ts +42 -0
  7. package/src/common/useTween.ts +86 -0
  8. package/src/core/basic/camera.ts +28 -0
  9. package/src/core/basic/clock.ts +11 -0
  10. package/src/core/basic/control.ts +32 -0
  11. package/src/core/basic/index.ts +35 -0
  12. package/src/core/basic/labelRenderer.ts +26 -0
  13. package/src/core/basic/light.ts +63 -0
  14. package/src/core/basic/renderer.ts +37 -0
  15. package/src/core/basic/scene.ts +11 -0
  16. package/src/core/basic/stats.ts +16 -0
  17. package/src/core/event.ts +74 -0
  18. package/src/core/index.ts +11 -0
  19. package/src/core/main.ts +389 -0
  20. package/src/draco/README.md +32 -0
  21. package/src/draco/draco_decoder.js +34 -0
  22. package/src/draco/draco_decoder.wasm +0 -0
  23. package/src/draco/draco_encoder.js +33 -0
  24. package/src/draco/draco_wasm_wrapper.js +117 -0
  25. package/src/draco/gltf/draco_decoder.js +33 -0
  26. package/src/draco/gltf/draco_decoder.wasm +0 -0
  27. package/src/draco/gltf/draco_encoder.js +33 -0
  28. package/src/draco/gltf/draco_wasm_wrapper.js +116 -0
  29. package/src/tileRenderer/base/Tile.d.ts +50 -0
  30. package/src/tileRenderer/base/TileBase.d.ts +76 -0
  31. package/src/tileRenderer/base/TileInternal.d.ts +36 -0
  32. package/src/tileRenderer/base/TilesRendererBase.d.ts +35 -0
  33. package/src/tileRenderer/base/TilesRendererBase.js +847 -0
  34. package/src/tileRenderer/base/Tileset.d.ts +66 -0
  35. package/src/tileRenderer/base/constants.d.ts +6 -0
  36. package/src/tileRenderer/base/constants.js +16 -0
  37. package/src/tileRenderer/base/loaders/B3DMLoaderBase.d.ts +18 -0
  38. package/src/tileRenderer/base/loaders/B3DMLoaderBase.js +85 -0
  39. package/src/tileRenderer/base/loaders/CMPTLoaderBase.d.ts +22 -0
  40. package/src/tileRenderer/base/loaders/CMPTLoaderBase.js +61 -0
  41. package/src/tileRenderer/base/loaders/I3DMLoaderBase.d.ts +21 -0
  42. package/src/tileRenderer/base/loaders/I3DMLoaderBase.js +130 -0
  43. package/src/tileRenderer/base/loaders/LoaderBase.d.ts +10 -0
  44. package/src/tileRenderer/base/loaders/LoaderBase.js +73 -0
  45. package/src/tileRenderer/base/loaders/PNTSLoaderBase.d.ts +17 -0
  46. package/src/tileRenderer/base/loaders/PNTSLoaderBase.js +82 -0
  47. package/src/tileRenderer/base/plugins/ImplicitTilingPlugin.js +12 -0
  48. package/src/tileRenderer/base/traverseFunctions.js +468 -0
  49. package/src/tileRenderer/gltf.js +144 -0
  50. package/src/tileRenderer/index.d.ts +41 -0
  51. package/src/tileRenderer/index.js +44 -0
  52. package/src/tileRenderer/plugins/README.md +578 -0
  53. package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.d.ts +2 -0
  54. package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.js +84 -0
  55. package/src/tileRenderer/plugins/base/SUBTREELoader.js +876 -0
  56. package/src/tileRenderer/plugins/index.d.ts +17 -0
  57. package/src/tileRenderer/plugins/index.js +17 -0
  58. package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.d.ts +9 -0
  59. package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.js +175 -0
  60. package/src/tileRenderer/plugins/three/DebugTilesPlugin.d.ts +29 -0
  61. package/src/tileRenderer/plugins/three/DebugTilesPlugin.js +677 -0
  62. package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.d.ts +18 -0
  63. package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.js +86 -0
  64. package/src/tileRenderer/plugins/three/GoogleAttributionsManager.js +62 -0
  65. package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.d.ts +5 -0
  66. package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.js +200 -0
  67. package/src/tileRenderer/plugins/three/ReorientationPlugin.d.ts +12 -0
  68. package/src/tileRenderer/plugins/three/ReorientationPlugin.js +136 -0
  69. package/src/tileRenderer/plugins/three/TileCompressionPlugin.d.ts +18 -0
  70. package/src/tileRenderer/plugins/three/TileCompressionPlugin.js +223 -0
  71. package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.d.ts +5 -0
  72. package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.js +87 -0
  73. package/src/tileRenderer/plugins/three/fade/FadeManager.js +370 -0
  74. package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.d.ts +9 -0
  75. package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.js +318 -0
  76. package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.d.ts +5 -0
  77. package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.js +27 -0
  78. package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.d.ts +30 -0
  79. package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.js +76 -0
  80. package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.d.ts +49 -0
  81. package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.js +147 -0
  82. package/src/tileRenderer/plugins/three/gltf/metadata/classes/ClassProperty.js +149 -0
  83. package/src/tileRenderer/plugins/three/gltf/metadata/classes/MeshFeatures.js +215 -0
  84. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyAttributeAccessor.js +107 -0
  85. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertySetAccessor.js +45 -0
  86. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTableAccessor.js +209 -0
  87. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTextureAccessor.js +244 -0
  88. package/src/tileRenderer/plugins/three/gltf/metadata/classes/StructuralMetadata.js +202 -0
  89. package/src/tileRenderer/plugins/three/gltf/metadata/math/Matrix2.js +55 -0
  90. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/ClassPropertyHelpers.js +495 -0
  91. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TexCoordUtilities.js +72 -0
  92. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TextureReadUtility.js +154 -0
  93. package/src/tileRenderer/plugins/three/objects/EllipsoidRegionHelper.js +186 -0
  94. package/src/tileRenderer/plugins/three/objects/SphereHelper.js +55 -0
  95. package/src/tileRenderer/r3f/README.md +238 -0
  96. package/src/tileRenderer/r3f/components/CameraControls.jsx +132 -0
  97. package/src/tileRenderer/r3f/components/CameraTransition.jsx +177 -0
  98. package/src/tileRenderer/r3f/components/CanvasDOMOverlay.jsx +54 -0
  99. package/src/tileRenderer/r3f/components/CompassGizmo.jsx +260 -0
  100. package/src/tileRenderer/r3f/components/TilesAttributionOverlay.jsx +110 -0
  101. package/src/tileRenderer/r3f/components/TilesRenderer.jsx +239 -0
  102. package/src/tileRenderer/r3f/index.jsx +6 -0
  103. package/src/tileRenderer/r3f/utilities/useForceUpdate.jsx +8 -0
  104. package/src/tileRenderer/r3f/utilities/useObjectDep.jsx +59 -0
  105. package/src/tileRenderer/r3f/utilities/useOptions.jsx +143 -0
  106. package/src/tileRenderer/three/DebugTilesRenderer.d.ts +28 -0
  107. package/src/tileRenderer/three/DebugTilesRenderer.js +58 -0
  108. package/src/tileRenderer/three/TilesGroup.d.ts +9 -0
  109. package/src/tileRenderer/three/TilesGroup.js +91 -0
  110. package/src/tileRenderer/three/TilesRenderer.d.ts +37 -0
  111. package/src/tileRenderer/three/TilesRenderer.js +1049 -0
  112. package/src/tileRenderer/three/controls/CameraTransitionManager.js +305 -0
  113. package/src/tileRenderer/three/controls/EnvironmentControls.js +1295 -0
  114. package/src/tileRenderer/three/controls/GlobeControls.js +684 -0
  115. package/src/tileRenderer/three/controls/PivotPointMesh.js +104 -0
  116. package/src/tileRenderer/three/controls/PointerTracker.js +257 -0
  117. package/src/tileRenderer/three/controls/utils.js +113 -0
  118. package/src/tileRenderer/three/loaders/B3DMLoader.d.ts +26 -0
  119. package/src/tileRenderer/three/loaders/B3DMLoader.js +85 -0
  120. package/src/tileRenderer/three/loaders/CMPTLoader.d.ts +19 -0
  121. package/src/tileRenderer/three/loaders/CMPTLoader.js +97 -0
  122. package/src/tileRenderer/three/loaders/GLTFExtensionLoader.d.ts +11 -0
  123. package/src/tileRenderer/three/loaders/GLTFExtensionLoader.js +68 -0
  124. package/src/tileRenderer/three/loaders/I3DMLoader.d.ts +26 -0
  125. package/src/tileRenderer/three/loaders/I3DMLoader.js +256 -0
  126. package/src/tileRenderer/three/loaders/PNTSLoader.d.ts +25 -0
  127. package/src/tileRenderer/three/loaders/PNTSLoader.js +202 -0
  128. package/src/tileRenderer/three/loaders/gltf/GLTFCesiumRTCExtension.js +12 -0
  129. package/src/tileRenderer/three/loaders/gltf/GLTFMeshFeaturesExtension.js +12 -0
  130. package/src/tileRenderer/three/loaders/gltf/GLTFStructuralMetadataExtension.js +12 -0
  131. package/src/tileRenderer/three/math/Ellipsoid.d.ts +31 -0
  132. package/src/tileRenderer/three/math/Ellipsoid.js +337 -0
  133. package/src/tileRenderer/three/math/EllipsoidRegion.d.ts +23 -0
  134. package/src/tileRenderer/three/math/EllipsoidRegion.js +178 -0
  135. package/src/tileRenderer/three/math/ExtendedFrustum.js +65 -0
  136. package/src/tileRenderer/three/math/GeoConstants.d.ts +4 -0
  137. package/src/tileRenderer/three/math/GeoConstants.js +5 -0
  138. package/src/tileRenderer/three/math/GeoUtils.d.ts +9 -0
  139. package/src/tileRenderer/three/math/GeoUtils.js +106 -0
  140. package/src/tileRenderer/three/math/OBB.js +179 -0
  141. package/src/tileRenderer/three/math/TileBoundingVolume.js +272 -0
  142. package/src/tileRenderer/three/plugins/CesiumIonAuthPlugin.js +12 -0
  143. package/src/tileRenderer/three/plugins/DebugTilesPlugin.js +26 -0
  144. package/src/tileRenderer/three/plugins/GoogleCloudAuthPlugin.js +12 -0
  145. package/src/tileRenderer/three/raycastTraverse.js +178 -0
  146. package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.d.ts +14 -0
  147. package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.js +21 -0
  148. package/src/tileRenderer/three/renderers/GoogleTilesRenderer.d.ts +43 -0
  149. package/src/tileRenderer/three/renderers/GoogleTilesRenderer.js +48 -0
  150. package/src/tileRenderer/three/utilities.js +54 -0
  151. package/src/tileRenderer/utilities/BatchTable.d.ts +24 -0
  152. package/src/tileRenderer/utilities/BatchTable.js +82 -0
  153. package/src/tileRenderer/utilities/BatchTableHierarchyExtension.js +127 -0
  154. package/src/tileRenderer/utilities/FeatureTable.d.ts +30 -0
  155. package/src/tileRenderer/utilities/FeatureTable.js +159 -0
  156. package/src/tileRenderer/utilities/LRUCache.d.ts +8 -0
  157. package/src/tileRenderer/utilities/LRUCache.js +385 -0
  158. package/src/tileRenderer/utilities/PriorityQueue.d.ts +16 -0
  159. package/src/tileRenderer/utilities/PriorityQueue.js +137 -0
  160. package/src/tileRenderer/utilities/arrayToString.js +7 -0
  161. package/src/tileRenderer/utilities/readMagicBytes.js +29 -0
  162. package/src/tileRenderer/utilities/rgb565torgb.js +22 -0
  163. package/src/tileRenderer/utilities/urlExtension.js +34 -0
  164. package/tsconfig.json +42 -0
  165. package/tsconfig.node.json +11 -0
  166. package/typings/three.d.ts +27 -0
@@ -0,0 +1,337 @@
1
+ import { Vector3, Spherical, MathUtils, Ray, Matrix4, Sphere, Euler } from 'three';
2
+ import { swapToGeoFrame, latitudeToSphericalPhi } from './GeoUtils.js';
3
+
4
+ const _spherical = new Spherical();
5
+ const _norm = new Vector3();
6
+ const _vec = new Vector3();
7
+ const _vec2 = new Vector3();
8
+ const _vec3 = new Vector3();
9
+ const _matrix = new Matrix4();
10
+ const _matrix2 = new Matrix4();
11
+ const _sphere = new Sphere();
12
+ const _euler = new Euler();
13
+
14
+ const _vecX = new Vector3();
15
+ const _vecY = new Vector3();
16
+ const _vecZ = new Vector3();
17
+ const _pos = new Vector3();
18
+
19
+ const _ray = new Ray();
20
+
21
+ const EPSILON12 = 1e-12;
22
+ const CENTER_EPS = 0.1;
23
+
24
+ export const ENU_FRAME = 0;
25
+ export const CAMERA_FRAME = 1;
26
+ export const OBJECT_FRAME = 2;
27
+
28
+ export class Ellipsoid {
29
+
30
+ constructor( x = 1, y = 1, z = 1 ) {
31
+
32
+ this.radius = new Vector3( x, y, z );
33
+
34
+ }
35
+
36
+ intersectRay( ray, target ) {
37
+
38
+ _matrix.makeScale( ...this.radius ).invert();
39
+ _sphere.center.set( 0, 0, 0 );
40
+ _sphere.radius = 1;
41
+
42
+ _ray.copy( ray ).applyMatrix4( _matrix );
43
+ if ( _ray.intersectSphere( _sphere, target ) ) {
44
+
45
+ _matrix.makeScale( ...this.radius );
46
+ target.applyMatrix4( _matrix );
47
+ return target;
48
+
49
+ } else {
50
+
51
+ return null;
52
+
53
+ }
54
+
55
+ }
56
+
57
+ // returns a frame with Z indicating altitude
58
+ // Y pointing north
59
+ // X pointing east
60
+ getEastNorthUpFrame( lat, lon, target ) {
61
+
62
+ this.getEastNorthUpAxes( lat, lon, _vecX, _vecY, _vecZ, _pos );
63
+ return target.makeBasis( _vecX, _vecY, _vecZ ).setPosition( _pos );
64
+
65
+ }
66
+
67
+ getEastNorthUpAxes( lat, lon, vecEast, vecNorth, vecUp, point = _pos ) {
68
+
69
+ this.getCartographicToPosition( lat, lon, 0, point );
70
+ this.getCartographicToNormal( lat, lon, vecUp ); // up
71
+ vecEast.set( - point.y, point.x, 0 ).normalize(); // east
72
+ vecNorth.crossVectors( vecUp, vecEast ).normalize(); // north
73
+
74
+ }
75
+
76
+ getNorthernTangent( lat, lon, target, westTarget = _vec3 ) {
77
+
78
+ console.log( 'Ellipsoid: getNorthernTangent has been deprecated. Use getEastNorthUpAxes instead.' );
79
+
80
+ this.getEastNorthUpAxes( lat, lon, westTarget, target, _vecZ );
81
+ westTarget.multiplyScalar( - 1 );
82
+ return target;
83
+
84
+ }
85
+
86
+ // azimuth: measured off of true north, increasing towards "east"
87
+ // elevation: measured off of the horizon, increasing towards sky
88
+ // roll: rotation around northern axis
89
+ getAzElRollFromRotationMatrix( lat, lon, rotationMatrix, target, frame = ENU_FRAME ) {
90
+
91
+ // if working with a frame that is not the ENU_FRAME then multiply in the
92
+ // offset for a camera or object so "forward" and "up" are oriented correct
93
+ if ( frame === CAMERA_FRAME ) {
94
+
95
+ _euler.set( - Math.PI / 2, 0, 0, 'XYZ' );
96
+ _matrix2.makeRotationFromEuler( _euler ).premultiply( rotationMatrix );
97
+
98
+ } else if ( frame === OBJECT_FRAME ) {
99
+
100
+ _euler.set( - Math.PI / 2, 0, Math.PI, 'XYZ' );
101
+ _matrix2.makeRotationFromEuler( _euler ).premultiply( rotationMatrix );
102
+
103
+ } else {
104
+
105
+ _matrix2.copy( rotationMatrix );
106
+
107
+ }
108
+
109
+ this.getEastNorthUpFrame( lat, lon, _matrix ).invert();
110
+ _matrix2.premultiply( _matrix );
111
+ _euler.setFromRotationMatrix( _matrix2, 'ZXY' );
112
+
113
+ target.azimuth = - _euler.z;
114
+ target.elevation = _euler.x;
115
+ target.roll = _euler.y;
116
+ return target;
117
+
118
+ }
119
+
120
+ getRotationMatrixFromAzElRoll( lat, lon, az, el, roll, target, frame = ENU_FRAME ) {
121
+
122
+ this.getEastNorthUpFrame( lat, lon, _matrix );
123
+ _euler.set( el, roll, - az, 'ZXY' );
124
+
125
+ target
126
+ .makeRotationFromEuler( _euler )
127
+ .premultiply( _matrix )
128
+ .setPosition( 0, 0, 0 );
129
+
130
+ // Add in the orientation adjustment for objects and cameras so "forward" and "up" are oriented
131
+ // correctly
132
+ if ( frame === CAMERA_FRAME ) {
133
+
134
+ _euler.set( Math.PI / 2, 0, 0, 'XYZ' );
135
+ _matrix2.makeRotationFromEuler( _euler );
136
+ target.multiply( _matrix2 );
137
+
138
+ } else if ( frame === OBJECT_FRAME ) {
139
+
140
+ _euler.set( - Math.PI / 2, 0, Math.PI, 'XYZ' );
141
+ _matrix2.makeRotationFromEuler( _euler );
142
+ target.multiply( _matrix2 );
143
+
144
+ }
145
+
146
+ return target;
147
+
148
+ }
149
+
150
+ getCartographicToPosition( lat, lon, height, target ) {
151
+
152
+ // From Cesium function Ellipsoid.cartographicToCartesian
153
+ // https://github.com/CesiumGS/cesium/blob/665ec32e813d5d6fe906ec3e87187f6c38ed5e49/packages/engine/Source/Core/Ellipsoid.js#L396
154
+ this.getCartographicToNormal( lat, lon, _norm );
155
+
156
+ const radius = this.radius;
157
+ _vec.copy( _norm );
158
+ _vec.x *= radius.x ** 2;
159
+ _vec.y *= radius.y ** 2;
160
+ _vec.z *= radius.z ** 2;
161
+
162
+ const gamma = Math.sqrt( _norm.dot( _vec ) );
163
+ _vec.divideScalar( gamma );
164
+
165
+ return target.copy( _vec ).addScaledVector( _norm, height );
166
+
167
+ }
168
+
169
+ getPositionToCartographic( pos, target ) {
170
+
171
+ // From Cesium function Ellipsoid.cartesianToCartographic
172
+ // https://github.com/CesiumGS/cesium/blob/665ec32e813d5d6fe906ec3e87187f6c38ed5e49/packages/engine/Source/Core/Ellipsoid.js#L463
173
+ this.getPositionToSurfacePoint( pos, _vec );
174
+ this.getPositionToNormal( pos, _norm );
175
+
176
+ const heightDelta = _vec2.subVectors( pos, _vec );
177
+
178
+ target.lon = Math.atan2( _norm.y, _norm.x );
179
+ target.lat = Math.asin( _norm.z );
180
+ target.height = Math.sign( heightDelta.dot( pos ) ) * heightDelta.length();
181
+ return target;
182
+
183
+ }
184
+
185
+ getCartographicToNormal( lat, lon, target ) {
186
+
187
+ _spherical.set( 1, latitudeToSphericalPhi( lat ), lon );
188
+ target.setFromSpherical( _spherical ).normalize();
189
+
190
+ // swap frame from the three.js frame to the geo coord frame
191
+ swapToGeoFrame( target );
192
+ return target;
193
+
194
+ }
195
+
196
+ getPositionToNormal( pos, target ) {
197
+
198
+ const radius = this.radius;
199
+ target.copy( pos );
200
+ target.x /= radius.x ** 2;
201
+ target.y /= radius.y ** 2;
202
+ target.z /= radius.z ** 2;
203
+ target.normalize();
204
+
205
+ return target;
206
+
207
+ }
208
+
209
+ getPositionToSurfacePoint( pos, target ) {
210
+
211
+ // From Cesium function Ellipsoid.scaleToGeodeticSurface
212
+ // https://github.com/CesiumGS/cesium/blob/d11b746e5809ac115fcff65b7b0c6bdfe81dcf1c/packages/engine/Source/Core/scaleToGeodeticSurface.js#L25
213
+ const radius = this.radius;
214
+ const invRadiusSqX = 1 / ( radius.x ** 2 );
215
+ const invRadiusSqY = 1 / ( radius.y ** 2 );
216
+ const invRadiusSqZ = 1 / ( radius.z ** 2 );
217
+
218
+ const x2 = pos.x * pos.x * invRadiusSqX;
219
+ const y2 = pos.y * pos.y * invRadiusSqY;
220
+ const z2 = pos.z * pos.z * invRadiusSqZ;
221
+
222
+ // Compute the squared ellipsoid norm.
223
+ const squaredNorm = x2 + y2 + z2;
224
+ const ratio = Math.sqrt( 1.0 / squaredNorm );
225
+
226
+ // As an initial approximation, assume that the radial intersection is the projection point.
227
+ const intersection = _vec.copy( pos ).multiplyScalar( ratio );
228
+ if ( squaredNorm < CENTER_EPS ) {
229
+
230
+ return ! isFinite( ratio ) ? null : target.copy( intersection );
231
+
232
+ }
233
+
234
+ // Use the gradient at the intersection point in place of the true unit normal.
235
+ // The difference in magnitude will be absorbed in the multiplier.
236
+ const gradient = _vec2.set(
237
+ intersection.x * invRadiusSqX * 2.0,
238
+ intersection.y * invRadiusSqY * 2.0,
239
+ intersection.z * invRadiusSqZ * 2.0
240
+ );
241
+
242
+ // Compute the initial guess at the normal vector multiplier, lambda.
243
+ let lambda = ( 1.0 - ratio ) * pos.length() / ( 0.5 * gradient.length() );
244
+ let correction = 0.0;
245
+
246
+ let func, denominator;
247
+ let xMultiplier, yMultiplier, zMultiplier;
248
+ let xMultiplier2, yMultiplier2, zMultiplier2;
249
+ let xMultiplier3, yMultiplier3, zMultiplier3;
250
+
251
+ do {
252
+
253
+ lambda -= correction;
254
+
255
+ xMultiplier = 1.0 / ( 1.0 + lambda * invRadiusSqX );
256
+ yMultiplier = 1.0 / ( 1.0 + lambda * invRadiusSqY );
257
+ zMultiplier = 1.0 / ( 1.0 + lambda * invRadiusSqZ );
258
+
259
+ xMultiplier2 = xMultiplier * xMultiplier;
260
+ yMultiplier2 = yMultiplier * yMultiplier;
261
+ zMultiplier2 = zMultiplier * zMultiplier;
262
+
263
+ xMultiplier3 = xMultiplier2 * xMultiplier;
264
+ yMultiplier3 = yMultiplier2 * yMultiplier;
265
+ zMultiplier3 = zMultiplier2 * zMultiplier;
266
+
267
+ func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
268
+
269
+ // "denominator" here refers to the use of this expression in the velocity and acceleration
270
+ // computations in the sections to follow.
271
+ denominator =
272
+ x2 * xMultiplier3 * invRadiusSqX +
273
+ y2 * yMultiplier3 * invRadiusSqY +
274
+ z2 * zMultiplier3 * invRadiusSqZ;
275
+
276
+ const derivative = - 2.0 * denominator;
277
+ correction = func / derivative;
278
+
279
+ } while ( Math.abs( func ) > EPSILON12 );
280
+
281
+ return target.set(
282
+ pos.x * xMultiplier,
283
+ pos.y * yMultiplier,
284
+ pos.z * zMultiplier
285
+ );
286
+
287
+ }
288
+
289
+ calculateHorizonDistance( latitude, elevation ) {
290
+
291
+ // from https://aty.sdsu.edu/explain/atmos_refr/horizon.html
292
+ // OG = sqrt ( 2 R h + h2 ) .
293
+ const effectiveRadius = this.calculateEffectiveRadius( latitude );
294
+ return Math.sqrt( 2 * effectiveRadius * elevation + elevation ** 2 );
295
+
296
+ }
297
+
298
+ calculateEffectiveRadius( latitude ) {
299
+
300
+ // This radius represents the distance from the center of the ellipsoid to the surface along the normal at the given latitude.
301
+ // from https://en.wikipedia.org/wiki/Earth_radius#Prime_vertical
302
+ // N = a / sqrt(1 - e^2 * sin^2(phi))
303
+ const semiMajorAxis = this.radius.x;
304
+ const semiMinorAxis = this.radius.z;
305
+ const eSquared = 1 - ( semiMinorAxis ** 2 / semiMajorAxis ** 2 );
306
+ const phi = latitude * MathUtils.DEG2RAD;
307
+
308
+ const sinPhiSquared = Math.sin( phi ) ** 2;
309
+ const N = semiMajorAxis / Math.sqrt( 1 - eSquared * sinPhiSquared );
310
+ return N;
311
+
312
+ }
313
+
314
+ getPositionElevation( pos ) {
315
+
316
+ // logic from "getPositionToCartographic"
317
+ this.getPositionToSurfacePoint( pos, _vec );
318
+
319
+ const heightDelta = _vec2.subVectors( pos, _vec );
320
+ return Math.sign( heightDelta.dot( pos ) ) * heightDelta.length();
321
+
322
+ }
323
+
324
+ copy( source ) {
325
+
326
+ this.radius.copy( source.radius );
327
+ return this;
328
+
329
+ }
330
+
331
+ clone() {
332
+
333
+ return new this.constructor().copy( this );
334
+
335
+ }
336
+
337
+ }
@@ -0,0 +1,23 @@
1
+ import { Box3, Sphere, Matrix4 } from 'three';
2
+ import { Ellipsoid } from './Ellipsoid';
3
+
4
+ export class EllipsoidRegion extends Ellipsoid {
5
+
6
+ latStart: Number;
7
+ latEnd: Number;
8
+ lonStart: Number;
9
+ lonEnd: Number;
10
+ heightStart: Number;
11
+ heightEnd: Number;
12
+
13
+ constructor(
14
+ x: Number, y: Number, z: Number,
15
+ latStart: Number, latEnd: Number,
16
+ lonStart: Number, lonEnd: Number,
17
+ heightStart: Number, heightEnd: Number
18
+ );
19
+
20
+ getBoundingBox( box : Box3, matrix : Matrix4 );
21
+ getBoundingSphere( sphere : Sphere );
22
+
23
+ }
@@ -0,0 +1,178 @@
1
+ import { MathUtils, Matrix4 } from 'three';
2
+ import { Vector3 } from 'three';
3
+ import { Ellipsoid } from './Ellipsoid.js';
4
+
5
+ const PI = Math.PI;
6
+ const HALF_PI = PI / 2;
7
+
8
+ const _orthoX = new Vector3();
9
+ const _orthoY = new Vector3();
10
+ const _orthoZ = new Vector3();
11
+ const _invMatrix = new Matrix4();
12
+
13
+ let _poolIndex = 0;
14
+ const _pointsPool = [];
15
+ function getVector( usePool = false ) {
16
+
17
+ if ( ! usePool ) {
18
+
19
+ return new Vector3();
20
+
21
+ }
22
+
23
+ if ( ! _pointsPool[ _poolIndex ] ) {
24
+
25
+ _pointsPool[ _poolIndex ] = new Vector3();
26
+
27
+ }
28
+
29
+ _poolIndex ++;
30
+ return _pointsPool[ _poolIndex - 1 ];
31
+
32
+ }
33
+
34
+ function resetPool() {
35
+
36
+ _poolIndex = 0;
37
+
38
+ }
39
+
40
+ export class EllipsoidRegion extends Ellipsoid {
41
+
42
+ constructor(
43
+ x, y, z,
44
+ latStart = - HALF_PI, latEnd = HALF_PI,
45
+ lonStart = 0, lonEnd = 2 * PI,
46
+ heightStart = 0, heightEnd = 0
47
+ ) {
48
+
49
+ super( x, y, z );
50
+ this.latStart = latStart;
51
+ this.latEnd = latEnd;
52
+ this.lonStart = lonStart;
53
+ this.lonEnd = lonEnd;
54
+ this.heightStart = heightStart;
55
+ this.heightEnd = heightEnd;
56
+
57
+ }
58
+
59
+ _getPoints( usePool = false ) {
60
+
61
+ const {
62
+ latStart, latEnd,
63
+ lonStart, lonEnd,
64
+ heightStart, heightEnd,
65
+ } = this;
66
+
67
+ const midLat = MathUtils.mapLinear( 0.5, 0, 1, latStart, latEnd );
68
+ const midLon = MathUtils.mapLinear( 0.5, 0, 1, lonStart, lonEnd );
69
+
70
+ const lonOffset = Math.floor( lonStart / HALF_PI ) * HALF_PI;
71
+ const latlon = [
72
+ [ - PI / 2, 0 ],
73
+ [ PI / 2, 0 ],
74
+ [ 0, lonOffset ],
75
+ [ 0, lonOffset + PI / 2 ],
76
+ [ 0, lonOffset + PI ],
77
+ [ 0, lonOffset + 3 * PI / 2 ],
78
+
79
+ [ latStart, lonEnd ],
80
+ [ latEnd, lonEnd ],
81
+ [ latStart, lonStart ],
82
+ [ latEnd, lonStart ],
83
+
84
+ [ 0, lonStart ],
85
+ [ 0, lonEnd ],
86
+
87
+ [ midLat, midLon ],
88
+ [ latStart, midLon ],
89
+ [ latEnd, midLon ],
90
+ [ midLat, lonStart ],
91
+ [ midLat, lonEnd ],
92
+
93
+ ];
94
+
95
+ const target = [];
96
+ const total = latlon.length;
97
+
98
+ for ( let z = 0; z <= 1; z ++ ) {
99
+
100
+ const height = MathUtils.mapLinear( z, 0, 1, heightStart, heightEnd );
101
+ for ( let i = 0, l = total; i < l; i ++ ) {
102
+
103
+ const [ lat, lon ] = latlon[ i ];
104
+ if ( lat >= latStart && lat <= latEnd && lon >= lonStart && lon <= lonEnd ) {
105
+
106
+ const v = getVector( usePool );
107
+ target.push( v );
108
+ this.getCartographicToPosition( lat, lon, height, v );
109
+
110
+ }
111
+
112
+ }
113
+
114
+ }
115
+
116
+ return target;
117
+
118
+ }
119
+
120
+ getBoundingBox( box, matrix ) {
121
+
122
+ resetPool();
123
+
124
+ const {
125
+ latStart, latEnd,
126
+ lonStart, lonEnd,
127
+ } = this;
128
+
129
+ const latRange = latEnd - latStart;
130
+ if ( latRange < PI / 2 ) {
131
+
132
+ // get the midway point for the region
133
+ const midLat = MathUtils.mapLinear( 0.5, 0, 1, latStart, latEnd );
134
+ const midLon = MathUtils.mapLinear( 0.5, 0, 1, lonStart, lonEnd );
135
+
136
+ // get the frame matrix for the box - works well for smaller regions
137
+ this.getCartographicToNormal( midLat, midLon, _orthoZ );
138
+ _orthoY.set( 0, 0, 1 );
139
+ _orthoX.crossVectors( _orthoY, _orthoZ );
140
+ _orthoY.crossVectors( _orthoX, _orthoZ );
141
+ matrix.makeBasis( _orthoX, _orthoY, _orthoZ );
142
+
143
+ } else {
144
+
145
+ _orthoX.set( 1, 0, 0 );
146
+ _orthoY.set( 0, 1, 0 );
147
+ _orthoZ.set( 0, 0, 1 );
148
+ matrix.makeBasis( _orthoX, _orthoY, _orthoZ );
149
+
150
+ }
151
+
152
+ // transform the points into the local frame
153
+ _invMatrix.copy( matrix ).invert();
154
+
155
+ const points = this._getPoints( true );
156
+ for ( let i = 0, l = points.length; i < l; i ++ ) {
157
+
158
+ points[ i ].applyMatrix4( _invMatrix );
159
+
160
+ }
161
+
162
+ // init the box
163
+ box.makeEmpty();
164
+ box.setFromPoints( points );
165
+
166
+ }
167
+
168
+ getBoundingSphere( sphere, center ) {
169
+
170
+ resetPool();
171
+
172
+ const points = this._getPoints( true );
173
+ sphere.makeEmpty();
174
+ sphere.setFromPoints( points, center );
175
+
176
+ }
177
+
178
+ }
@@ -0,0 +1,65 @@
1
+ import { Frustum, Matrix3, Vector3 } from 'three';
2
+
3
+ const _mat3 = new Matrix3();
4
+
5
+ // Solve a system of equations to find the point where the three planes intersect
6
+ function findIntersectionPoint( plane1, plane2, plane3, target ) {
7
+
8
+ // Create the matrix A using the normals of the planes as rows
9
+ const A = _mat3.set(
10
+ plane1.normal.x, plane1.normal.y, plane1.normal.z,
11
+ plane2.normal.x, plane2.normal.y, plane2.normal.z,
12
+ plane3.normal.x, plane3.normal.y, plane3.normal.z
13
+ );
14
+
15
+ // Create the vector B using the constants of the planes
16
+ target.set( - plane1.constant, - plane2.constant, - plane3.constant );
17
+
18
+ // Solve for X by applying the inverse matrix to B
19
+ target.applyMatrix3( A.invert() );
20
+
21
+ return target;
22
+
23
+ }
24
+
25
+ class ExtendedFrustum extends Frustum {
26
+
27
+ constructor() {
28
+
29
+ super();
30
+ this.points = Array( 8 ).fill().map( () => new Vector3() );
31
+
32
+ }
33
+
34
+ setFromProjectionMatrix( m, coordinateSystem ) {
35
+
36
+ super.setFromProjectionMatrix( m, coordinateSystem );
37
+ this.calculateFrustumPoints();
38
+
39
+ }
40
+
41
+ calculateFrustumPoints() {
42
+
43
+ const { planes, points } = this;
44
+ const planeIntersections = [
45
+ [ planes[ 0 ], planes[ 3 ], planes[ 4 ] ], // Near top left
46
+ [ planes[ 1 ], planes[ 3 ], planes[ 4 ] ], // Near top right
47
+ [ planes[ 0 ], planes[ 2 ], planes[ 4 ] ], // Near bottom left
48
+ [ planes[ 1 ], planes[ 2 ], planes[ 4 ] ], // Near bottom right
49
+ [ planes[ 0 ], planes[ 3 ], planes[ 5 ] ], // Far top left
50
+ [ planes[ 1 ], planes[ 3 ], planes[ 5 ] ], // Far top right
51
+ [ planes[ 0 ], planes[ 2 ], planes[ 5 ] ], // Far bottom left
52
+ [ planes[ 1 ], planes[ 2 ], planes[ 5 ] ], // Far bottom right
53
+ ];
54
+
55
+ planeIntersections.forEach( ( planes, index ) => {
56
+
57
+ findIntersectionPoint( planes[ 0 ], planes[ 1 ], planes[ 2 ], points[ index ] );
58
+
59
+ } );
60
+
61
+ }
62
+
63
+ }
64
+
65
+ export { ExtendedFrustum };
@@ -0,0 +1,4 @@
1
+ import { Ellipsoid } from './Ellipsoid';
2
+
3
+ export const WGS84_ELLIPSOID : Ellipsoid;
4
+ export const LUNAR_ELLIPSOID : Ellipsoid;
@@ -0,0 +1,5 @@
1
+ import { WGS84_RADIUS, WGS84_HEIGHT, LUNAR_RADIUS, LUNAR_HEIGHT } from '../../base/constants.js';
2
+ import { Ellipsoid } from './Ellipsoid.js';
3
+
4
+ export const WGS84_ELLIPSOID = new Ellipsoid( WGS84_RADIUS, WGS84_RADIUS, WGS84_HEIGHT );
5
+ export const LUNAR_ELLIPSOID = new Ellipsoid( LUNAR_RADIUS, LUNAR_RADIUS, LUNAR_HEIGHT );
@@ -0,0 +1,9 @@
1
+ import { Vector3 } from 'three';
2
+
3
+ export function swapToGeoFrame( target : Vector3 ) : Vector3;
4
+
5
+ export function swapToThreeFrame( target : Vector3 ) : Vector3;
6
+
7
+ export function sphericalPhiToLatitude( phi : Number ) : Number;
8
+
9
+ export function latitudeToSphericalPhi( latitude : Number ) : Number;