itowns 2.44.3-next.40 → 2.44.3-next.42

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 (199) hide show
  1. package/README.md +3 -129
  2. package/package.json +16 -72
  3. package/CODING.md +0 -120
  4. package/CONTRIBUTING.md +0 -150
  5. package/CONTRIBUTORS.md +0 -56
  6. package/LICENSE.md +0 -44
  7. package/changelog.md +0 -1361
  8. package/dist/455.js +0 -2
  9. package/dist/455.js.map +0 -1
  10. package/dist/debug.js +0 -3
  11. package/dist/debug.js.LICENSE.txt +0 -13
  12. package/dist/debug.js.map +0 -1
  13. package/dist/itowns.js +0 -3
  14. package/dist/itowns.js.LICENSE.txt +0 -5
  15. package/dist/itowns.js.map +0 -1
  16. package/dist/itowns_lasparser.js +0 -2
  17. package/dist/itowns_lasparser.js.map +0 -1
  18. package/dist/itowns_lasworker.js +0 -2
  19. package/dist/itowns_lasworker.js.map +0 -1
  20. package/dist/itowns_potree2worker.js +0 -2
  21. package/dist/itowns_potree2worker.js.map +0 -1
  22. package/dist/itowns_widgets.js +0 -2
  23. package/dist/itowns_widgets.js.map +0 -1
  24. package/examples/.eslintrc.cjs +0 -35
  25. package/examples/jsm/.eslintrc.cjs +0 -38
  26. package/lib/Controls/FirstPersonControls.js +0 -308
  27. package/lib/Controls/FlyControls.js +0 -175
  28. package/lib/Controls/GlobeControls.js +0 -1179
  29. package/lib/Controls/PlanarControls.js +0 -1025
  30. package/lib/Controls/StateControl.js +0 -432
  31. package/lib/Controls/StreetControls.js +0 -392
  32. package/lib/Converter/Feature2Mesh.js +0 -614
  33. package/lib/Converter/Feature2Texture.js +0 -175
  34. package/lib/Converter/convertToTile.js +0 -70
  35. package/lib/Converter/textureConverter.js +0 -43
  36. package/lib/Core/3DTiles/C3DTBatchTable.js +0 -131
  37. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +0 -96
  38. package/lib/Core/3DTiles/C3DTBoundingVolume.js +0 -157
  39. package/lib/Core/3DTiles/C3DTExtensions.js +0 -97
  40. package/lib/Core/3DTiles/C3DTFeature.js +0 -110
  41. package/lib/Core/3DTiles/C3DTilesEnums.js +0 -20
  42. package/lib/Core/3DTiles/C3DTileset.js +0 -99
  43. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +0 -100
  44. package/lib/Core/AnimationPlayer.js +0 -142
  45. package/lib/Core/CopcNode.js +0 -174
  46. package/lib/Core/Deprecated/Undeprecator.js +0 -74
  47. package/lib/Core/EntwinePointTileNode.js +0 -126
  48. package/lib/Core/Feature.js +0 -489
  49. package/lib/Core/Geographic/CoordStars.js +0 -80
  50. package/lib/Core/Geographic/Coordinates.js +0 -331
  51. package/lib/Core/Geographic/Crs.js +0 -170
  52. package/lib/Core/Geographic/Extent.js +0 -550
  53. package/lib/Core/Geographic/GeoidGrid.js +0 -109
  54. package/lib/Core/Label.js +0 -222
  55. package/lib/Core/MainLoop.js +0 -209
  56. package/lib/Core/Math/Ellipsoid.js +0 -185
  57. package/lib/Core/Picking.js +0 -255
  58. package/lib/Core/PointCloudNode.js +0 -42
  59. package/lib/Core/Potree2Node.js +0 -206
  60. package/lib/Core/Potree2PointAttributes.js +0 -139
  61. package/lib/Core/PotreeNode.js +0 -101
  62. package/lib/Core/Prefab/Globe/Atmosphere.js +0 -295
  63. package/lib/Core/Prefab/Globe/GlobeLayer.js +0 -152
  64. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +0 -111
  65. package/lib/Core/Prefab/Globe/SkyShader.js +0 -78
  66. package/lib/Core/Prefab/GlobeView.js +0 -156
  67. package/lib/Core/Prefab/Planar/PlanarLayer.js +0 -59
  68. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +0 -72
  69. package/lib/Core/Prefab/PlanarView.js +0 -62
  70. package/lib/Core/Prefab/TileBuilder.js +0 -82
  71. package/lib/Core/Prefab/computeBufferTileGeometry.js +0 -248
  72. package/lib/Core/Scheduler/Cache.js +0 -17
  73. package/lib/Core/Scheduler/CancelledCommandException.js +0 -15
  74. package/lib/Core/Scheduler/Scheduler.js +0 -294
  75. package/lib/Core/Style.js +0 -660
  76. package/lib/Core/StyleOptions.js +0 -486
  77. package/lib/Core/System/Capabilities.js +0 -63
  78. package/lib/Core/Tile/Tile.js +0 -207
  79. package/lib/Core/Tile/TileGrid.js +0 -49
  80. package/lib/Core/TileGeometry.js +0 -124
  81. package/lib/Core/TileMesh.js +0 -108
  82. package/lib/Core/View.js +0 -1116
  83. package/lib/Layer/C3DTilesLayer.js +0 -459
  84. package/lib/Layer/ColorLayer.js +0 -154
  85. package/lib/Layer/CopcLayer.js +0 -63
  86. package/lib/Layer/ElevationLayer.js +0 -139
  87. package/lib/Layer/EntwinePointTileLayer.js +0 -71
  88. package/lib/Layer/FeatureGeometryLayer.js +0 -77
  89. package/lib/Layer/GeoidLayer.js +0 -80
  90. package/lib/Layer/GeometryLayer.js +0 -233
  91. package/lib/Layer/InfoLayer.js +0 -64
  92. package/lib/Layer/LabelLayer.js +0 -470
  93. package/lib/Layer/Layer.js +0 -335
  94. package/lib/Layer/LayerUpdateState.js +0 -89
  95. package/lib/Layer/LayerUpdateStrategy.js +0 -80
  96. package/lib/Layer/OGC3DTilesLayer.js +0 -543
  97. package/lib/Layer/OrientedImageLayer.js +0 -228
  98. package/lib/Layer/PointCloudLayer.js +0 -405
  99. package/lib/Layer/Potree2Layer.js +0 -171
  100. package/lib/Layer/PotreeLayer.js +0 -72
  101. package/lib/Layer/RasterLayer.js +0 -37
  102. package/lib/Layer/ReferencingLayerProperties.js +0 -62
  103. package/lib/Layer/TiledGeometryLayer.js +0 -459
  104. package/lib/Loader/LASLoader.js +0 -193
  105. package/lib/Loader/Potree2BrotliLoader.js +0 -261
  106. package/lib/Loader/Potree2Loader.js +0 -207
  107. package/lib/Main.js +0 -115
  108. package/lib/MainBundle.js +0 -4
  109. package/lib/Parser/B3dmParser.js +0 -174
  110. package/lib/Parser/CameraCalibrationParser.js +0 -94
  111. package/lib/Parser/GDFParser.js +0 -72
  112. package/lib/Parser/GTXParser.js +0 -75
  113. package/lib/Parser/GeoJsonParser.js +0 -212
  114. package/lib/Parser/GpxParser.js +0 -25
  115. package/lib/Parser/ISGParser.js +0 -71
  116. package/lib/Parser/KMLParser.js +0 -25
  117. package/lib/Parser/LASParser.js +0 -137
  118. package/lib/Parser/MapBoxUrlParser.js +0 -83
  119. package/lib/Parser/PntsParser.js +0 -131
  120. package/lib/Parser/Potree2BinParser.js +0 -92
  121. package/lib/Parser/PotreeBinParser.js +0 -106
  122. package/lib/Parser/PotreeCinParser.js +0 -29
  123. package/lib/Parser/ShapefileParser.js +0 -78
  124. package/lib/Parser/VectorTileParser.js +0 -215
  125. package/lib/Parser/XbilParser.js +0 -120
  126. package/lib/Parser/deprecated/LegacyGLTFLoader.js +0 -1386
  127. package/lib/Parser/iGLTFLoader.js +0 -168
  128. package/lib/Process/3dTilesProcessing.js +0 -304
  129. package/lib/Process/FeatureProcessing.js +0 -76
  130. package/lib/Process/LayeredMaterialNodeProcessing.js +0 -221
  131. package/lib/Process/ObjectRemovalHelper.js +0 -97
  132. package/lib/Process/handlerNodeError.js +0 -23
  133. package/lib/Provider/3dTilesProvider.js +0 -149
  134. package/lib/Provider/DataSourceProvider.js +0 -8
  135. package/lib/Provider/Fetcher.js +0 -233
  136. package/lib/Provider/PointCloudProvider.js +0 -45
  137. package/lib/Provider/TileProvider.js +0 -16
  138. package/lib/Provider/URLBuilder.js +0 -116
  139. package/lib/Renderer/Camera.js +0 -281
  140. package/lib/Renderer/Color.js +0 -56
  141. package/lib/Renderer/ColorLayersOrdering.js +0 -115
  142. package/lib/Renderer/CommonMaterial.js +0 -31
  143. package/lib/Renderer/Label2DRenderer.js +0 -192
  144. package/lib/Renderer/LayeredMaterial.js +0 -243
  145. package/lib/Renderer/OBB.js +0 -151
  146. package/lib/Renderer/OrientedImageCamera.js +0 -118
  147. package/lib/Renderer/OrientedImageMaterial.js +0 -167
  148. package/lib/Renderer/PointsMaterial.js +0 -485
  149. package/lib/Renderer/RasterTile.js +0 -208
  150. package/lib/Renderer/RenderMode.js +0 -31
  151. package/lib/Renderer/Shader/ShaderChunk.js +0 -160
  152. package/lib/Renderer/Shader/ShaderUtils.js +0 -47
  153. package/lib/Renderer/SphereHelper.js +0 -17
  154. package/lib/Renderer/WebXR.js +0 -51
  155. package/lib/Renderer/c3DEngine.js +0 -214
  156. package/lib/Source/C3DTilesGoogleSource.js +0 -74
  157. package/lib/Source/C3DTilesIonSource.js +0 -54
  158. package/lib/Source/C3DTilesSource.js +0 -30
  159. package/lib/Source/CopcSource.js +0 -126
  160. package/lib/Source/EntwinePointTileSource.js +0 -72
  161. package/lib/Source/FileSource.js +0 -188
  162. package/lib/Source/OGC3DTilesGoogleSource.js +0 -29
  163. package/lib/Source/OGC3DTilesIonSource.js +0 -34
  164. package/lib/Source/OGC3DTilesSource.js +0 -21
  165. package/lib/Source/OrientedImageSource.js +0 -59
  166. package/lib/Source/Potree2Source.js +0 -167
  167. package/lib/Source/PotreeSource.js +0 -82
  168. package/lib/Source/Source.js +0 -203
  169. package/lib/Source/TMSSource.js +0 -144
  170. package/lib/Source/VectorTilesSource.js +0 -182
  171. package/lib/Source/WFSSource.js +0 -170
  172. package/lib/Source/WMSSource.js +0 -168
  173. package/lib/Source/WMTSSource.js +0 -92
  174. package/lib/ThreeExtended/capabilities/WebGL.js +0 -69
  175. package/lib/ThreeExtended/libs/ktx-parse.module.js +0 -506
  176. package/lib/ThreeExtended/libs/zstddec.module.js +0 -29
  177. package/lib/ThreeExtended/loaders/DDSLoader.js +0 -200
  178. package/lib/ThreeExtended/loaders/DRACOLoader.js +0 -400
  179. package/lib/ThreeExtended/loaders/GLTFLoader.js +0 -2879
  180. package/lib/ThreeExtended/loaders/KTX2Loader.js +0 -709
  181. package/lib/ThreeExtended/math/ColorSpaces.js +0 -59
  182. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +0 -846
  183. package/lib/ThreeExtended/utils/WorkerPool.js +0 -70
  184. package/lib/Utils/CameraUtils.js +0 -555
  185. package/lib/Utils/DEMUtils.js +0 -350
  186. package/lib/Utils/FeaturesUtils.js +0 -156
  187. package/lib/Utils/Gradients.js +0 -16
  188. package/lib/Utils/OrientationUtils.js +0 -457
  189. package/lib/Utils/ThreeUtils.js +0 -115
  190. package/lib/Utils/gui/C3DTilesStyle.js +0 -215
  191. package/lib/Utils/gui/Main.js +0 -7
  192. package/lib/Utils/gui/Minimap.js +0 -154
  193. package/lib/Utils/gui/Navigation.js +0 -245
  194. package/lib/Utils/gui/Scale.js +0 -107
  195. package/lib/Utils/gui/Searchbar.js +0 -234
  196. package/lib/Utils/gui/Widget.js +0 -80
  197. package/lib/Utils/placeObjectOnGround.js +0 -136
  198. package/lib/Worker/LASLoaderWorker.js +0 -19
  199. package/lib/Worker/Potree2Worker.js +0 -21
@@ -1,101 +0,0 @@
1
- import * as THREE from 'three';
2
- import PointCloudNode from "./PointCloudNode.js";
3
-
4
- // Create an A(xis)A(ligned)B(ounding)B(ox) for the child `childIndex` of one aabb.
5
- // (PotreeConverter protocol builds implicit octree hierarchy by applying the same
6
- // subdivision algo recursively)
7
- const dHalfLength = new THREE.Vector3();
8
- class PotreeNode extends PointCloudNode {
9
- constructor() {
10
- let numPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
11
- let childrenBitField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
12
- let layer = arguments.length > 2 ? arguments[2] : undefined;
13
- super(numPoints, layer);
14
- this.childrenBitField = childrenBitField;
15
- this.id = '';
16
- this.depth = 0;
17
- this.baseurl = layer.source.baseurl;
18
- }
19
- add(node, indexChild, root) {
20
- super.add(node, indexChild);
21
- node.id = this.id + indexChild;
22
- node.depth = node.id.length;
23
- if (node.id.length % this.layer.hierarchyStepSize == 0) {
24
- node.baseurl = `${root.baseurl}/${node.id.substr(root.id.length)}`;
25
- } else {
26
- node.baseurl = root.baseurl;
27
- }
28
- }
29
- createChildAABB(node, childIndex) {
30
- // Code inspired from potree
31
- node.bbox.copy(this.bbox);
32
- this.bbox.getCenter(node.bbox.max);
33
- dHalfLength.copy(node.bbox.max).sub(this.bbox.min);
34
- if (childIndex === 1) {
35
- node.bbox.min.z += dHalfLength.z;
36
- node.bbox.max.z += dHalfLength.z;
37
- } else if (childIndex === 3) {
38
- node.bbox.min.z += dHalfLength.z;
39
- node.bbox.max.z += dHalfLength.z;
40
- node.bbox.min.y += dHalfLength.y;
41
- node.bbox.max.y += dHalfLength.y;
42
- } else if (childIndex === 0) {
43
- //
44
- } else if (childIndex === 2) {
45
- node.bbox.min.y += dHalfLength.y;
46
- node.bbox.max.y += dHalfLength.y;
47
- } else if (childIndex === 5) {
48
- node.bbox.min.z += dHalfLength.z;
49
- node.bbox.max.z += dHalfLength.z;
50
- node.bbox.min.x += dHalfLength.x;
51
- node.bbox.max.x += dHalfLength.x;
52
- } else if (childIndex === 7) {
53
- node.bbox.min.add(dHalfLength);
54
- node.bbox.max.add(dHalfLength);
55
- } else if (childIndex === 4) {
56
- node.bbox.min.x += dHalfLength.x;
57
- node.bbox.max.x += dHalfLength.x;
58
- } else if (childIndex === 6) {
59
- node.bbox.min.y += dHalfLength.y;
60
- node.bbox.max.y += dHalfLength.y;
61
- node.bbox.min.x += dHalfLength.x;
62
- node.bbox.max.x += dHalfLength.x;
63
- }
64
- }
65
- get octreeIsLoaded() {
66
- return !(this.childrenBitField && this.children.length === 0);
67
- }
68
- get url() {
69
- return `${this.baseurl}/r${this.id}.${this.layer.source.extension}`;
70
- }
71
- loadOctree() {
72
- const octreeUrl = `${this.baseurl}/r${this.id}.${this.layer.source.extensionOctree}`;
73
- return this.layer.source.fetcher(octreeUrl, this.layer.source.networkOptions).then(blob => {
74
- const view = new DataView(blob);
75
- const stack = [];
76
- let offset = 0;
77
- this.childrenBitField = view.getUint8(0);
78
- offset += 1;
79
- this.numPoints = view.getUint32(1, true);
80
- offset += 4;
81
- stack.push(this);
82
- while (stack.length && offset < blob.byteLength) {
83
- const snode = stack.shift();
84
- // look up 8 children
85
- for (let indexChild = 0; indexChild < 8; indexChild++) {
86
- // does snode have a #indexChild child ?
87
- if (snode.childrenBitField & 1 << indexChild && offset + 5 <= blob.byteLength) {
88
- const childrenBitField = view.getUint8(offset);
89
- offset += 1;
90
- const numPoints = view.getUint32(offset, true) || this.numPoints;
91
- offset += 4;
92
- const item = new PotreeNode(numPoints, childrenBitField, this.layer);
93
- snode.add(item, indexChild, this);
94
- stack.push(item);
95
- }
96
- }
97
- }
98
- });
99
- }
100
- }
101
- export default PotreeNode;
@@ -1,295 +0,0 @@
1
- import * as THREE from 'three';
2
- import GeometryLayer from "../../../Layer/GeometryLayer.js";
3
- import Coordinates from "../../Geographic/Coordinates.js";
4
- import { ellipsoidSizes } from "../../Math/Ellipsoid.js";
5
- import CoordStars from "../../Geographic/CoordStars.js";
6
- import Sky from "./SkyShader.js";
7
- /* babel-plugin-inline-import './Shaders/skyFS.glsl' */
8
- const skyFS = "uniform vec3 v3LightPos;\nuniform float g;\nuniform float g2;\n\nvarying vec3 v3Direction;\nvarying vec3 c0;\nvarying vec3 c1;\n\n// Calculates the Mie phase function\nfloat getMiePhase(float fCos, float fCos2, float g, float g2) {\n return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(1.0 + g2 - 2.0 * g * fCos, 1.5);\n}\n\n// Calculates the Rayleigh phase function\nfloat getRayleighPhase(float fCos2) {\n return 0.75 + 0.75 * fCos2;\n}\n\nvoid main (void) {\n float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);\n float fCos2 = fCos * fCos;\n\n vec3 color = getRayleighPhase(fCos2) * c0 + getMiePhase(fCos, fCos2, g, g2) * c1;\n\n gl_FragColor = vec4(color, 1.0);\n gl_FragColor.a = gl_FragColor.b;\n}";
9
- /* babel-plugin-inline-import './Shaders/skyVS.glsl' */
10
- const skyVS = "uniform vec3 v3LightPosition; // The direction vector to the light source\nuniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels\nuniform float fCameraHeight; // The camera's current height\nuniform float fCameraHeight2; // fCameraHeight^2\nuniform float fOuterRadius; // The outer (atmosphere) radius\nuniform float fOuterRadius2; // fOuterRadius^2\nuniform float fInnerRadius; // The inner (planetary) radius\nuniform float fInnerRadius2; // fInnerRadius^2\nuniform float fKrESun; // Kr * ESun\nuniform float fKmESun; // Km * ESun\nuniform float fKr4PI; // Kr * 4 * PI\nuniform float fKm4PI; // Km * 4 * PI\nuniform float fScale; // 1 / (fOuterRadius - fInnerRadius)\nuniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)\nuniform float fScaleOverScaleDepth; // fScale / fScaleDepth\n\nconst int nSamples = 3;\nconst float fSamples = 3.0;\n\nvarying vec3 v3Direction;\nvarying vec3 c0;\nvarying vec3 c1;\n\nfloat scale(float fCos) {\n float x = 1.0 - fCos;\n return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\nvoid main(void) {\n float lengthCamera = length(cameraPosition);\n float cameraHeight2 = lengthCamera * lengthCamera;\n\n // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n vec3 v3Ray = position - cameraPosition;\n float fFar = length(v3Ray);\n v3Ray /= fFar;\n\n // Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)\n float B = 2.0 * dot(cameraPosition, v3Ray);\n float C = cameraHeight2 - fOuterRadius2;\n float fDet = max(0.0, B*B - 4.0 * C);\n float fNear = 0.5 * (-B - sqrt(fDet));\n\n // Calculate the ray's starting position, then calculate its scattering offset\n vec3 v3Start = cameraPosition + v3Ray * fNear;\n fFar -= fNear;\n float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;\n float fStartDepth = exp(-1.0 / fScaleDepth);\n float fStartOffset = fStartDepth * scale(fStartAngle);\n\n // Initialize the scattering loop variables\n float fSampleLength = fFar / fSamples;\n float fScaledLength = fSampleLength * fScale;\n vec3 v3SampleRay = v3Ray * fSampleLength;\n vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;\n\n // Now loop through the sample rays\n vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);\n for(int i=0; i<nSamples; i++)\n {\n float fHeight = length(v3SamplePoint);\n float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));\n float fLightAngle = dot(v3LightPosition, v3SamplePoint) / fHeight;\n float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;\n float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));\n vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));\n\n v3FrontColor += v3Attenuate * (fDepth * fScaledLength);\n v3SamplePoint += v3SampleRay;\n }\n\n // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n c0 = v3FrontColor * (v3InvWavelength * fKrESun);\n c1 = v3FrontColor * fKmESun;\n v3Direction = cameraPosition - position;\n}";
11
- /* babel-plugin-inline-import './Shaders/groundFS.glsl' */
12
- const groundFS = "varying vec3 c0;\nvarying vec3 c1;\n\nvoid main (void) {\n\tgl_FragColor = vec4(c1, 1.0 - c0/4.);\n}";
13
- /* babel-plugin-inline-import './Shaders/groundVS.glsl' */
14
- const groundVS = "uniform vec3 v3LightPosition; // The direction vector to the light source\nuniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels\nuniform float fCameraHeight; // The camera's current height\nuniform float fCameraHeight2; // fCameraHeight^2\nuniform float fOuterRadius; // The outer (atmosphere) radius\nuniform float fOuterRadius2; // fOuterRadius^2\nuniform float fInnerRadius; // The inner (planetary) radius\nuniform float fInnerRadius2; // fInnerRadius^2\nuniform float fKrESun; // Kr * ESun\nuniform float fKmESun; // Km * ESun\nuniform float fKr4PI; // Kr * 4 * PI\nuniform float fKm4PI; // Km * 4 * PI\nuniform float fScale; // 1 / (fOuterRadius - fInnerRadius)\nuniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)\nuniform float fScaleOverScaleDepth; // fScale / fScaleDepth\n\nvarying vec3 c0;\nvarying vec3 c1;\n\nconst int nSamples = 3;\nconst float fSamples = 3.0;\n\nfloat scale(float fCos)\n{\n float x = 1.0 - fCos;\n return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\nvoid main(void) {\n\n float cameraHeight2 = length(cameraPosition) * length(cameraPosition);\n\n // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n vec3 v3Ray = position - cameraPosition;\n float fFar = length(v3Ray);\n v3Ray /= fFar;\n\n // Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)\n float B = 2.0 * dot(cameraPosition, v3Ray);\n float C = cameraHeight2 - fOuterRadius2;\n float fDet = max(0.0, B*B - 4.0 * C);\n float fNear = 0.5 * (-B - sqrt(fDet));\n\n // Calculate the ray's starting position, then calculate its scattering offset\n vec3 v3Start = cameraPosition + v3Ray * fNear;\n fFar -= fNear;\n float fDepth = exp((fInnerRadius - fOuterRadius) / fScaleDepth);\n float fCameraAngle = dot(-v3Ray, position) / length(position);\n float fLightAngle = dot(v3LightPosition, position) / length(position);\n float fCameraScale = scale(fCameraAngle);\n float fLightScale = scale(fLightAngle);\n float fCameraOffset = fDepth*fCameraScale;\n float fTemp = (fLightScale + fCameraScale);\n\n // Initialize the scattering loop variables\n float fSampleLength = fFar / fSamples;\n float fScaledLength = fSampleLength * fScale;\n vec3 v3SampleRay = v3Ray * fSampleLength;\n vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;\n\n // Now loop through the sample rays\n vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);\n vec3 v3Attenuate = vec3(0.0, 0.0, 0.0);\n for(int i=0; i<nSamples; i++)\n {\n float fHeight = length(v3SamplePoint);\n float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));\n float fScatter = fDepth*fTemp - fCameraOffset;\n v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));\n v3FrontColor += v3Attenuate * (fDepth * fScaledLength);\n v3SamplePoint += v3SampleRay;\n }\n\n // Calculate the attenuation factor for the ground\n c0 = v3Attenuate;\n c1 = v3FrontColor * (v3InvWavelength * fKrESun + fKmESun);\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
15
- /* babel-plugin-inline-import './Shaders/GlowFS.glsl' */
16
- const GlowFS = "#include <logdepthbuf_pars_fragment>\n\nuniform int atmoIN;\nvarying float intensity;\n\nvec4 glowColor = vec4(0.45, 0.74, 1. ,1.0);\n\nvoid main() {\n #include <logdepthbuf_fragment>\n gl_FragColor = glowColor * intensity;\n}\n\n";
17
- /* babel-plugin-inline-import './Shaders/GlowVS.glsl' */
18
- const GlowVS = "#include <common>\n#include <logdepthbuf_pars_vertex>\n\nuniform int atmoIN;\nvarying float intensity;\n\nvoid main()\n{\n vec3 normalES = normalize( normalMatrix * normal );\n vec3 normalCAMES = normalize( normalMatrix * cameraPosition );\n\n if(atmoIN == 0) {\n intensity = pow(0.666 - dot(normalES, normalCAMES), 4. );\n } else {\n intensity = pow( 1. - dot(normalES, normalCAMES), 0.8 );\n }\n\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n #include <logdepthbuf_vertex>\n}\n\n\n";
19
- const LIGHTING_POSITION = new THREE.Vector3(1, 0, 0);
20
- const v = new THREE.Vector3();
21
- const coordCam = new Coordinates('EPSG:4326');
22
- const coordGeoCam = new Coordinates('EPSG:4326');
23
- const skyBaseColor = new THREE.Color(0x93d5f8);
24
- const colorSky = new THREE.Color();
25
- const spaceColor = new THREE.Color(0x030508);
26
- const limitAlti = 600000;
27
- const mfogDistance = ellipsoidSizes.x * 160.0;
28
-
29
- /**
30
- * @extends GeometryLayer
31
- */
32
- class Atmosphere extends GeometryLayer {
33
- /**
34
- * It's layer to simulate Globe atmosphere.
35
- * There's 2 modes : simple and realistic (atmospheric-scattering).
36
- *
37
- * The atmospheric-scattering it is taken from :
38
- * * [Atmosphere Shader From Space (Atmospheric scattering)](http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html)
39
- * * [Accurate Atmospheric Scattering (NVIDIA GPU Gems 2)](https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering).
40
- *
41
- * @param {string} id - The id of the layer Atmosphere.
42
- * @param {Object} [options] - options layer.
43
- * @param {number} [options.Kr] - `Kr` is the rayleigh scattering constant.
44
- * @param {number} [options.Km] - `Km` is the Mie scattering constant.
45
- * @param {number} [options.ESun] - `ESun` is the brightness of the sun.
46
- * @param {number} [options.g] - constant `g` that affects the symmetry of the scattering.
47
- * @param {number} [options.innerRadius] - The inner (planetary) radius
48
- * @param {number} [options.outerRadius] - The outer (Atmosphere) radius
49
- * @param {number[]} [options.wavelength] - The constant is the `wavelength` (or color) of light.
50
- * @param {number} [options.scaleDepth] - The `scale depth` (i.e. the altitude at which the atmosphere's average density is found).
51
- * @param {number} [options.mieScaleDepth] - not used.
52
- */
53
- constructor() {
54
- let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'atmosphere';
55
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
56
- options.source = false;
57
- super(id, new THREE.Object3D(), options);
58
- this.isAtmosphere = true;
59
- const material = new THREE.ShaderMaterial({
60
- uniforms: {
61
- atmoIN: {
62
- type: 'i',
63
- value: 0
64
- },
65
- screenSize: {
66
- type: 'v2',
67
- value: new THREE.Vector2(window.innerWidth, window.innerHeight)
68
- } // Should be updated on screen resize...
69
- },
70
- vertexShader: GlowVS,
71
- fragmentShader: GlowFS,
72
- side: THREE.BackSide,
73
- blending: THREE.AdditiveBlending,
74
- transparent: true,
75
- wireframe: false
76
- });
77
- const sphereGeometry = new THREE.SphereGeometry(1, 64, 64);
78
- const basicAtmosphereOut = new THREE.Mesh(sphereGeometry, material);
79
- basicAtmosphereOut.scale.copy(ellipsoidSizes).multiplyScalar(1.14);
80
- this.basicAtmosphere = new THREE.Object3D();
81
- this.realisticAtmosphere = new THREE.Object3D();
82
- this.realisticAtmosphere.visible = false;
83
- this.object3d.add(this.basicAtmosphere);
84
- this.object3d.add(this.realisticAtmosphere);
85
- this.basicAtmosphere.add(basicAtmosphereOut);
86
- const materialAtmoIn = new THREE.ShaderMaterial({
87
- uniforms: {
88
- atmoIN: {
89
- type: 'i',
90
- value: 1
91
- },
92
- screenSize: {
93
- type: 'v2',
94
- value: new THREE.Vector2(window.innerWidth, window.innerHeight)
95
- } // Should be updated on screen resize...
96
- },
97
- vertexShader: GlowVS,
98
- fragmentShader: GlowFS,
99
- side: THREE.FrontSide,
100
- blending: THREE.AdditiveBlending,
101
- transparent: true,
102
- depthWrite: false
103
- });
104
- const basicAtmosphereIn = new THREE.Mesh(sphereGeometry, materialAtmoIn);
105
- basicAtmosphereIn.scale.copy(ellipsoidSizes).multiplyScalar(1.002);
106
- this.basicAtmosphere.add(basicAtmosphereIn);
107
- this.realisticLightingPosition = {
108
- x: -0.5,
109
- y: 0.0,
110
- z: 1.0
111
- };
112
- this.fog = {
113
- enable: true,
114
- distance: mfogDistance
115
- };
116
-
117
- // Atmosphere Shader From Space (Atmospheric scattering)
118
- // http://stainlessbeer.weebly.com/planets-9-atmospheric-scattering.html
119
- // https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering
120
- this.realisticAtmosphereInitParams = options.Kr ? options : {
121
- Kr: 0.0025,
122
- Km: 0.0015,
123
- ESun: 20.0,
124
- g: -0.950,
125
- innerRadius: 6400000,
126
- outerRadius: 6700000,
127
- wavelength: [0.650, 0.570, 0.475],
128
- scaleDepth: 0.25
129
- // mieScaleDepth: 0.1,
130
- };
131
- this.object3d.updateMatrixWorld();
132
- }
133
- update(context, layer, node) {
134
- // update uniforms
135
- node.material.fogDistance = this.fog.distance;
136
- node.material.lightingEnabled = this.realisticAtmosphere.visible;
137
- node.material.lightPosition = this.realisticLightingPosition;
138
- }
139
-
140
- // eslint-disable-next-line no-unused-vars
141
- preUpdate(context) {
142
- const cameraPosition = context.view.camera3D.position;
143
- if (this.fog.enable) {
144
- v.setFromMatrixPosition(context.view.tileLayer.object3d.matrixWorld);
145
- const len = v.distanceTo(cameraPosition);
146
- // Compute fog distance, this function makes it possible to have a shorter distance
147
- // when the camera approaches the ground
148
- this.fog.distance = mfogDistance * ((len - ellipsoidSizes.x * 0.99) * 0.25 / ellipsoidSizes.x) ** 1.5;
149
- } else {
150
- this.fog.distance = 10e10;
151
- }
152
- const renderer = context.view.mainLoop.gfxEngine.renderer;
153
- // get altitude camera
154
- coordCam.crs = context.view.referenceCrs;
155
- coordCam.setFromVector3(cameraPosition).as('EPSG:4326', coordGeoCam);
156
- const altitude = coordGeoCam.altitude;
157
-
158
- // If the camera altitude is below limitAlti,
159
- // we interpolate between the sky color and the space color
160
- if (altitude < limitAlti) {
161
- colorSky.copy(spaceColor).lerp(skyBaseColor, (limitAlti - altitude) / limitAlti);
162
- renderer.setClearColor(colorSky, renderer.getClearAlpha());
163
- } else {
164
- renderer.setClearColor(spaceColor, renderer.getClearAlpha());
165
- }
166
- }
167
-
168
- // default to non-realistic lightning
169
- _initRealisticLighning() {
170
- const atmosphere = this.realisticAtmosphereInitParams;
171
- const uniformsAtmosphere = {
172
- v3LightPosition: {
173
- value: LIGHTING_POSITION.clone().normalize()
174
- },
175
- v3InvWavelength: {
176
- value: new THREE.Vector3(1 / atmosphere.wavelength[0] ** 4, 1 / atmosphere.wavelength[1] ** 4, 1 / atmosphere.wavelength[2] ** 4)
177
- },
178
- fCameraHeight: {
179
- value: 0.0
180
- },
181
- fCameraHeight2: {
182
- value: 0.0
183
- },
184
- fInnerRadius: {
185
- value: atmosphere.innerRadius
186
- },
187
- fInnerRadius2: {
188
- value: atmosphere.innerRadius * atmosphere.innerRadius
189
- },
190
- fOuterRadius: {
191
- value: atmosphere.outerRadius
192
- },
193
- fOuterRadius2: {
194
- value: atmosphere.outerRadius * atmosphere.outerRadius
195
- },
196
- fKrESun: {
197
- value: atmosphere.Kr * atmosphere.ESun
198
- },
199
- fKmESun: {
200
- value: atmosphere.Km * atmosphere.ESun
201
- },
202
- fKr4PI: {
203
- value: atmosphere.Kr * 4.0 * Math.PI
204
- },
205
- fKm4PI: {
206
- value: atmosphere.Km * 4.0 * Math.PI
207
- },
208
- fScale: {
209
- value: 1 / (atmosphere.outerRadius - atmosphere.innerRadius)
210
- },
211
- fScaleDepth: {
212
- value: atmosphere.scaleDepth
213
- },
214
- fScaleOverScaleDepth: {
215
- value: 1 / (atmosphere.outerRadius - atmosphere.innerRadius) / atmosphere.scaleDepth
216
- },
217
- g: {
218
- value: atmosphere.g
219
- },
220
- g2: {
221
- value: atmosphere.g * atmosphere.g
222
- },
223
- nSamples: {
224
- value: 3
225
- },
226
- fSamples: {
227
- value: 3.0
228
- },
229
- tDisplacement: {
230
- value: new THREE.Texture()
231
- },
232
- tSkyboxDiffuse: {
233
- value: new THREE.Texture()
234
- },
235
- fNightScale: {
236
- value: 1.0
237
- }
238
- };
239
- const geometryAtmosphereIn = new THREE.SphereGeometry(atmosphere.innerRadius, 50, 50);
240
- const materialAtmosphereIn = new THREE.ShaderMaterial({
241
- uniforms: uniformsAtmosphere,
242
- vertexShader: groundVS,
243
- fragmentShader: groundFS,
244
- blending: THREE.AdditiveBlending,
245
- transparent: true,
246
- depthTest: false,
247
- depthWrite: false
248
- });
249
- const ground = new THREE.Mesh(geometryAtmosphereIn, materialAtmosphereIn);
250
- const geometryAtmosphereOut = new THREE.SphereGeometry(atmosphere.outerRadius, 196, 196);
251
- const materialAtmosphereOut = new THREE.ShaderMaterial({
252
- uniforms: uniformsAtmosphere,
253
- vertexShader: skyVS,
254
- fragmentShader: skyFS,
255
- transparent: true,
256
- side: THREE.BackSide
257
- });
258
- const sky = new THREE.Mesh(geometryAtmosphereOut, materialAtmosphereOut);
259
- const skyDome = new Sky();
260
- skyDome.frustumCulled = false;
261
- this.realisticAtmosphere.add(ground);
262
- this.realisticAtmosphere.add(sky);
263
- this.realisticAtmosphere.add(skyDome);
264
- const effectController = {
265
- turbidity: 10,
266
- reileigh: 2,
267
- mieCoefficient: 0.005,
268
- mieDirectionalG: 0.8,
269
- luminance: 1,
270
- inclination: 0.49,
271
- // elevation / inclination
272
- azimuth: 0.25,
273
- // Facing front,
274
- sun: !true
275
- };
276
- skyDome.material.uniforms.turbidity.value = effectController.turbidity;
277
- skyDome.material.uniforms.reileigh.value = effectController.reileigh;
278
- skyDome.material.uniforms.luminance.value = effectController.luminance;
279
- skyDome.material.uniforms.mieCoefficient.value = effectController.mieCoefficient;
280
- skyDome.material.uniforms.mieDirectionalG.value = effectController.mieDirectionalG;
281
- skyDome.material.uniforms.up.value = new THREE.Vector3(); // no more necessary, estimate normal from cam..
282
- }
283
- setRealisticOn(bool) {
284
- if (bool) {
285
- if (!this.realisticAtmosphere.children.length) {
286
- this._initRealisticLighning();
287
- }
288
- this.realisticLightingPosition = CoordStars.getSunPositionInScene(new Date().getTime(), 48.85, 2.35).normalize();
289
- this.realisticAtmosphere.children.forEach(obj => obj.material.uniforms.v3LightPosition.value.copy(this.realisticLightingPosition));
290
- }
291
- this.basicAtmosphere.visible = !bool;
292
- this.realisticAtmosphere.visible = bool;
293
- }
294
- }
295
- export default Atmosphere;
@@ -1,152 +0,0 @@
1
- import * as THREE from 'three';
2
- import TiledGeometryLayer from "../../../Layer/TiledGeometryLayer.js";
3
- import { ellipsoidSizes } from "../../Math/Ellipsoid.js";
4
- import { globalExtentTMS, schemeTiles } from "../../Tile/TileGrid.js";
5
- import { GlobeTileBuilder } from "./GlobeTileBuilder.js";
6
-
7
- // matrix to convert sphere to ellipsoid
8
- const worldToScaledEllipsoid = new THREE.Matrix4();
9
- // camera's position in worldToScaledEllipsoid system
10
- const cameraPosition = new THREE.Vector3();
11
- let magnitudeSquared = 0.0;
12
-
13
- // vectors for operation purpose
14
- const scaledHorizonCullingPoint = new THREE.Vector3();
15
-
16
- /**
17
- * @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
18
- * GlobeLayer. Default is true. You should not change this, as it is used
19
- * internally for optimisation.
20
- *
21
- * @extends TiledGeometryLayer
22
- */
23
- class GlobeLayer extends TiledGeometryLayer {
24
- /**
25
- * A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
26
- * specific method for updating and subdivising its grid.
27
- *
28
- * @param {string} id - The id of the layer, that should be unique. It is
29
- * not mandatory, but an error will be emitted if this layer is added a
30
- * {@link View} that already has a layer going by that id.
31
- * @param {THREE.Object3D} [object3d=THREE.Group] - The object3d used to
32
- * contain the geometry of the TiledGeometryLayer. It is usually a
33
- * `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
34
- * @param {Object} [config] - Optional configuration, all elements in it
35
- * will be merged as is in the layer. For example, if the configuration
36
- * contains three elements `name, protocol, extent`, these elements will be
37
- * available using `layer.name` or something else depending on the property
38
- * name.
39
- * @param {number} [config.minSubdivisionLevel=2] - Minimum subdivision
40
- * level for this tiled layer.
41
- * @param {number} [config.maxSubdivisionLevel=18] - Maximum subdivision
42
- * level for this tiled layer.
43
- * @param {number} [config.sseSubdivisionThreshold=1] - Threshold level for
44
- * the SSE.
45
- *
46
- * @throws {Error} `object3d` must be a valid `THREE.Object3d`.
47
- */
48
- constructor(id, object3d) {
49
- let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
50
- const {
51
- minSubdivisionLevel = 2,
52
- maxSubdivisionLevel = 19,
53
- ...tiledConfig
54
- } = config;
55
-
56
- // Configure tiles
57
- const scheme = schemeTiles.get('EPSG:4326');
58
- const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);
59
-
60
- // Supported tile matrix set for color/elevation layer
61
- const tileMatrixSets = ['EPSG:4326', 'EPSG:3857'];
62
- const uvCount = tileMatrixSets.length;
63
- const builder = new GlobeTileBuilder({
64
- uvCount
65
- });
66
- super(id, object3d || new THREE.Group(), schemeTile, builder, {
67
- tileMatrixSets,
68
- ...tiledConfig
69
- });
70
- this.isGlobeLayer = true;
71
- this.options.defaultPickingRadius = 5;
72
- this.minSubdivisionLevel = minSubdivisionLevel;
73
- this.maxSubdivisionLevel = maxSubdivisionLevel;
74
- this.extent = this.schemeTile[0].clone();
75
- for (let i = 1; i < this.schemeTile.length; i++) {
76
- this.extent.union(this.schemeTile[i]);
77
- }
78
-
79
- // We're going to use the method described here:
80
- // https://cesiumjs.org/2013/04/25/Horizon-culling/
81
- // This method assumes that the globe is a unit sphere at 0,0,0 so
82
- // we setup a world-to-scaled-ellipsoid matrix4
83
- worldToScaledEllipsoid.copy(this.object3d.matrixWorld).invert();
84
- worldToScaledEllipsoid.premultiply(new THREE.Matrix4().makeScale(1 / ellipsoidSizes.x, 1 / ellipsoidSizes.y, 1 / ellipsoidSizes.z));
85
- }
86
- preUpdate(context, changeSources) {
87
- // pre-horizon culling
88
- cameraPosition.copy(context.camera.camera3D.position).applyMatrix4(worldToScaledEllipsoid);
89
- magnitudeSquared = cameraPosition.lengthSq() - 1.0;
90
- return super.preUpdate(context, changeSources);
91
- }
92
- countColorLayersTextures() {
93
- let occupancy = 0;
94
- for (var _len = arguments.length, layers = new Array(_len), _key = 0; _key < _len; _key++) {
95
- layers[_key] = arguments[_key];
96
- }
97
- for (const layer of layers) {
98
- const crs = layer.crs || layer.source.crs;
99
- // 'EPSG:3857' occupies the maximum 3 textures on tiles
100
- // 'EPSG:4326' occupies 1 textures on tile
101
- occupancy += crs == 'EPSG:3857' ? 3 : 1;
102
- }
103
- return occupancy;
104
- }
105
- subdivision(context, layer, node) {
106
- if (node.level == 5) {
107
- const row = node.getExtentsByProjection('EPSG:4326')[0].row;
108
- if (row == 31 || row == 0) {
109
- // doesn't subdivise the pole
110
- return false;
111
- }
112
- }
113
- return super.subdivision(context, layer, node);
114
- }
115
- culling(node, camera) {
116
- if (super.culling(node, camera)) {
117
- return true;
118
- }
119
- if (node.level < this.minSubdivisionLevel) {
120
- return false;
121
- }
122
- return GlobeLayer.horizonCulling(node.horizonCullingPointElevationScaled);
123
- }
124
- static horizonCulling(point) {
125
- // see https://cesiumjs.org/2013/04/25/Horizon-culling/
126
- scaledHorizonCullingPoint.copy(point).applyMatrix4(worldToScaledEllipsoid);
127
- scaledHorizonCullingPoint.sub(cameraPosition);
128
- const vtMagnitudeSquared = scaledHorizonCullingPoint.lengthSq();
129
- const dot = -scaledHorizonCullingPoint.dot(cameraPosition);
130
- const isOccluded = magnitudeSquared < 0 ? dot > 0 : magnitudeSquared < dot && magnitudeSquared < dot * dot / vtMagnitudeSquared;
131
- return isOccluded;
132
- }
133
- computeTileZoomFromDistanceCamera(distance, camera) {
134
- const preSinus = this.sizeDiagonalTexture * (this.sseSubdivisionThreshold * 0.5) / camera._preSSE / ellipsoidSizes.x;
135
- let sinus = distance * preSinus;
136
- let zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);
137
- const delta = Math.PI / 2 ** zoom;
138
- const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
139
- // adjust with bounding sphere rayon
140
- sinus = (distance - circleChord * 0.5) * preSinus;
141
- zoom = Math.log(Math.PI / (2.0 * Math.asin(sinus))) / Math.log(2);
142
- return isNaN(zoom) ? 0 : Math.round(zoom);
143
- }
144
- computeDistanceCameraFromTileZoom(zoom, camera) {
145
- const delta = Math.PI / 2 ** zoom;
146
- const circleChord = 2.0 * ellipsoidSizes.x * Math.sin(delta * 0.5);
147
- const radius = circleChord * 0.5;
148
- const error = radius / this.sizeDiagonalTexture;
149
- return camera._preSSE * error / (this.sseSubdivisionThreshold * 0.5) + radius;
150
- }
151
- }
152
- export default GlobeLayer;
@@ -1,111 +0,0 @@
1
- import * as THREE from 'three';
2
- import Coordinates from "../../Geographic/Coordinates.js";
3
- import Extent from "../../Geographic/Extent.js";
4
- const PI_OV_FOUR = Math.PI / 4;
5
- const INV_TWO_PI = 1.0 / (Math.PI * 2);
6
- const axisZ = new THREE.Vector3(0, 0, 1);
7
- const axisY = new THREE.Vector3(0, 1, 0);
8
- const quatToAlignLongitude = new THREE.Quaternion();
9
- const quatToAlignLatitude = new THREE.Quaternion();
10
- const quatNormalToZ = new THREE.Quaternion();
11
-
12
- /** Transforms a WGS84 latitude into a usable texture offset. */
13
- function WGS84ToOneSubY(latitude) {
14
- return 1.0 - (0.5 - Math.log(Math.tan(PI_OV_FOUR + THREE.MathUtils.degToRad(latitude) * 0.5)) * INV_TWO_PI);
15
- }
16
-
17
- /** Specialized parameters for the [GlobeTileBuilder]. */
18
-
19
- /**
20
- * TileBuilder implementation for the purpose of generating globe (or more
21
- * precisely ellipsoidal) tile arrangements.
22
- */
23
- export class GlobeTileBuilder {
24
- static _crs = 'EPSG:4978';
25
- static _computeExtraOffset(params) {
26
- const t = WGS84ToOneSubY(params.coordinates.latitude) * params.nbRow;
27
- return (!isFinite(t) ? 0 : t) - params.deltaUV1;
28
- }
29
-
30
- /**
31
- * Buffer holding information about the tile/vertex currently being
32
- * processed.
33
- */
34
-
35
- get crs() {
36
- return GlobeTileBuilder._crs;
37
- }
38
- constructor(options) {
39
- this._transform = {
40
- coords: [new Coordinates('EPSG:4326', 0, 0), new Coordinates('EPSG:4326', 0, 0)],
41
- position: new THREE.Vector3(),
42
- dimension: new THREE.Vector2()
43
- };
44
-
45
- // UV: Normalized coordinates (from degree) on the entire tile
46
- // EPSG:4326
47
- // Offset: Float row coordinate from Pseudo mercator coordinates
48
- // EPSG:3857
49
- if (options.uvCount > 1) {
50
- this.computeExtraOffset = GlobeTileBuilder._computeExtraOffset;
51
- }
52
- }
53
- prepare(params) {
54
- const nbRow = 2 ** (params.level + 1.0);
55
- let st1 = WGS84ToOneSubY(params.extent.south);
56
- if (!isFinite(st1)) {
57
- st1 = 0;
58
- }
59
- const start = st1 % (1.0 / nbRow);
60
- const newParams = {
61
- nbRow,
62
- deltaUV1: (st1 - start) * nbRow,
63
- // transformation to align tile's normal to z axis
64
- quatNormalToZ: quatNormalToZ.setFromAxisAngle(axisY, -(Math.PI * 0.5 - THREE.MathUtils.degToRad(params.extent.center().latitude))),
65
- // let's avoid building too much temp objects
66
- coordinates: new Coordinates(this.crs)
67
- };
68
- params.extent.planarDimensions(this._transform.dimension);
69
- return {
70
- ...params,
71
- ...newParams
72
- };
73
- }
74
- center(extent) {
75
- return extent.center(this._transform.coords[0]).as(this.crs, this._transform.coords[1]).toVector3();
76
- }
77
- vertexPosition(coordinates) {
78
- return this._transform.coords[0].setFromValues(coordinates.x, coordinates.y).as(this.crs, this._transform.coords[1]).toVector3(this._transform.position);
79
- }
80
- vertexNormal() {
81
- return this._transform.coords[1].geodesicNormal;
82
- }
83
- uProject(u, extent) {
84
- return extent.west + u * this._transform.dimension.x;
85
- }
86
- vProject(v, extent) {
87
- return extent.south + v * this._transform.dimension.y;
88
- }
89
- computeShareableExtent(extent) {
90
- // NOTE: It should be possible to take advantage of equatorial plane
91
- // symmetry, for which we'd have to reverse the tile's UVs.
92
- // This would halve the memory requirement when viewing a full globe,
93
- // but that case is not that relevant for iTowns' usual use cases and
94
- // the globe mesh memory usage is already inconsequential.
95
- const sizeLongitude = Math.abs(extent.west - extent.east) / 2;
96
- const shareableExtent = new Extent(extent.crs, -sizeLongitude, sizeLongitude, extent.south, extent.north);
97
-
98
- // Compute rotation to transform the tile to position on the ellispoid.
99
- // This transformation takes the parents' transformation into account.
100
- const rotLon = THREE.MathUtils.degToRad(extent.west - shareableExtent.west);
101
- const rotLat = THREE.MathUtils.degToRad(90 - extent.center(this._transform.coords[0]).latitude);
102
- quatToAlignLongitude.setFromAxisAngle(axisZ, rotLon);
103
- quatToAlignLatitude.setFromAxisAngle(axisY, rotLat);
104
- quatToAlignLongitude.multiply(quatToAlignLatitude);
105
- return {
106
- shareableExtent,
107
- quaternion: quatToAlignLongitude.clone(),
108
- position: this.center(extent)
109
- };
110
- }
111
- }